diff --git a/route_adm.go b/route_adm.go index 0844caa..f32e092 100644 --- a/route_adm.go +++ b/route_adm.go @@ -167,10 +167,10 @@ func setWebRoute_adm(web *c.CiyWebServer) { "restorage": admin.Login_restorage, }, "manage": { - "init": admin.Manage_init, - "favadd": admin.Manage_favadd, - "favdel": admin.Manage_favdel, - "setssh": admin.Manage_setssh, + "init": admin.Index_init, + "favadd": admin.Index_favadd, + "favdel": admin.Index_favdel, + "setssh": admin.Index_setssh, }, "upload": { "upload": admin.Upload_upload, diff --git a/web/admin/cemap/cemap.html b/web/admin/cemap/cemap.html index 756ae27..1744227 100644 --- a/web/admin/cemap/cemap.html +++ b/web/admin/cemap/cemap.html @@ -94,7 +94,7 @@ - + -
- - 选择语言 - - -
-

Ciyon SaaS总控台

-
-
- 管理员登录 -
-
-
- -
- -
+
+ +
+
+
    + -
    - -
    - -
    -
    -
    - -
    - -
    -
    -
    - 演示账号: 12345678901
    - 密码: 123654
    -
    - 移动端演示
    - -
    -
    - +
  • + + + + + +
  • +
  • + + +
  • +
-
+ +
+
+ + +
+
+
+ +
+
+ + + + + + +
+
+
    +
+
+
+ + + + + + +
+
+ +
+
+
+
+
+
+
- -
-
-
© 2024 众产®
- - - + + + + diff --git a/web/admin/manage.php b/web/admin/index.php similarity index 99% rename from web/admin/manage.php rename to web/admin/index.php index 44a056c..dd43012 100644 --- a/web/admin/manage.php +++ b/web/admin/index.php @@ -2,7 +2,7 @@ namespace web\admin; -class manage { +class index { public static function json_init() { global $db; $rsuser = verifyfast(); diff --git a/web/admin/login.html b/web/admin/login.html new file mode 100644 index 0000000..cd6c067 --- /dev/null +++ b/web/admin/login.html @@ -0,0 +1,179 @@ + + + + + 管理员登录 + + + + + + + + + + +
+ + 选择语言 + + +
+

CiyDAO 总控台

+
+
+ 管理员登录 +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+
+
+ +
+
+
© 2024 众产®
+ + + + + + + \ No newline at end of file diff --git a/web/admin/manage.html b/web/admin/manage.html deleted file mode 100644 index da1e842..0000000 --- a/web/admin/manage.html +++ /dev/null @@ -1,998 +0,0 @@ - - - - - Ciyon - - - - - - - - - - -
- -
-
- -
- -
-
- - -
-
-
- -
-
- - - - - - -
-
-
    -
-
-
- - - - - - -
-
- -
-
-
-
-
-
-
-
- - - - - - - - \ No newline at end of file diff --git a/web/ambap/upload.php b/web/ambap/upload.php index 0327d69..891f476 100644 --- a/web/ambap/upload.php +++ b/web/ambap/upload.php @@ -28,7 +28,7 @@ class upload { return errjson('没有文件上传'); $file = reset($_FILES); if ($file['error'] > 0) - return errjson('上传参数出错:' . $file['error']); + return errjson(\ciy\upload::UploadError($file['error'])); list($name, $extfile) = \ciy\upload::Fileext($path); if ($uploadcfg['checkext'] == 'exts') { if (!in_array($extfile, $uploadcfg['exts'])) diff --git a/web/jscss/ciy.js b/web/jscss/ciy.js index 41d9274..6c89f0c 100644 --- a/web/jscss/ciy.js +++ b/web/jscss/ciy.js @@ -1049,10 +1049,8 @@ ciyfn.callfunc = function (funcname, post, successfunc, opn) { //opn showload,m if (typeof (successfunc) == 'function') successfunc(json, xhr); } else if (json.code == 2) { - if (top.ciy_vars.baseurl) - top.location.href = '/' + top.ciy_vars.baseurl; - else - top.location.href = '/'; + if (top.ciy_vars.loginurl) + top.location.href = '/' + top.ciy_vars.loginurl; } else if (json.code == 3) { document.body.innerHTML = '

' + json.errmsg + '

'; } else { diff --git a/web/jscss/ciycmp.js b/web/jscss/ciycmp.js index 09ca6fd..ee941ba 100644 --- a/web/jscss/ciycmp.js +++ b/web/jscss/ciycmp.js @@ -112,7 +112,7 @@ ciyfn.file_uploads = function (maxcount, files, opn, fn) { var postdata = new FormData(); postdata.append('file', gfile, gfile.name); var xhr = new XMLHttpRequest(); - xhr.open("POST", opn.action + "upload.upload&pathfile=" + pathfile, true); + xhr.open("POST", opn.action + ".upload&pathfile=" + pathfile, true); xhr.setRequestHeader(ciy_vars.tokenfield, ciyfn.getstorage('_' + ciy_vars.tokenfield)); xhr.setRequestHeader("X-Custom-Header", "CustomValue"); xhr.onload = function () { @@ -145,7 +145,7 @@ ciyfn.file_uploads = function (maxcount, files, opn, fn) { }; xhr.send(postdata); } else { - ciyfn.callfunc(opn.action + "upload.s3&pathfile=" + pathfile + "&storselect=" + opn.stor, {}, function (json) { + ciyfn.callfunc(opn.action + ".s3&pathfile=" + pathfile + "&storselect=" + opn.stor, {}, function (json) { var xhr = new XMLHttpRequest(); xhr.upload.addEventListener("progress", function (N) { if (N.lengthComputable) { @@ -1133,7 +1133,7 @@ ciycmpfunc.ciyupload = function (opn) { // v2 opn.showwh = opn.showwh || opn.dom.attr('showwh') || '100px'; //显示宽高 opn.action = opn.action || opn.dom.attr('action'); if (!opn.action) { - opn.action = "/z/?func=" + ciy_vars.baseurl; + opn.action = "/z/?func=" + ciy_vars.uploadurl; } var now = new Date(); opn.path = opn.path || opn.dom.attr('path') || 'nopath'; diff --git a/web/jscss/ciycmp2.js b/web/jscss/ciycmp2.js index b43ac1d..1982d63 100644 --- a/web/jscss/ciycmp2.js +++ b/web/jscss/ciycmp2.js @@ -810,7 +810,7 @@ ciycmpfunc.ciymarkdown = function (opn) { opn.watertext = opn.watertext || opn.dom.attr('watertext') || ''; opn.action = opn.action || opn.dom.attr('action'); if (!opn.action) { - opn.action = "/z/?func=" + ciy_vars.baseurl; + opn.action = "/z/?func=" + ciy_vars.uploadurl; } var now = new Date(); opn.path = opn.path || opn.dom.attr('path') || 'nopath'; diff --git a/zciyphp/comm.php b/zciyphp/comm.php index 09b996a..34717b2 100644 --- a/zciyphp/comm.php +++ b/zciyphp/comm.php @@ -57,7 +57,7 @@ * file_down URL文件下载保存 * fileext 获取文件扩展名,如jpg */ -if(isset($_SERVER['HTTP_CIY_TIMEOUT'])) +if (isset($_SERVER['HTTP_CIY_TIMEOUT'])) set_time_limit((int)$_SERVER['HTTP_CIY_TIMEOUT'] + 10); error_reporting(E_ALL); //0禁用错误输出;E_ALL打开错误输出 date_default_timezone_set('Asia/Shanghai'); @@ -217,6 +217,17 @@ function isweixin() { return true; return false; } +function getcciycheck($num) { + $checksum = 0; + for ($i = 15; $i > 0; $i--) { + $nibble = ($num >> (4 * $i)) & 0xF; + $checksum ^= $nibble; + } + return $checksum; +} +function iscciy($num) { + return getcciycheck($num) == ($num & 0xf); +} function idcard($str) { $str = strtoupper(trim($str)); if (empty($str)) diff --git a/zciyphp/dbmongo.php b/zciyphp/dbmongo.php new file mode 100644 index 0000000..93e2622 --- /dev/null +++ b/zciyphp/dbmongo.php @@ -0,0 +1,369 @@ +collection = 'movies'; + $cmd->pageno = 1; + + $count = -1; + $rows = $mongo->get($cmd, $count); + if ($rows === false) + return clog($mongo->error); + clog($count); + foreach ($rows as $row) { + clog($row); + } + return; + * + */ + +namespace ciy; + +class dbmongo { + private $dbpst; + private $linkdb; + private $session; + private $database; + private $lastinsertid; + private $isTransaction; + public $error; + function __construct($dbpst = '') { + $this->linkdb = false; + $this->dbpst = $dbpst; + $this->isTransaction = false; + $this->error = ''; + } + + private function errdata($errmsg, $ret = false) { + $this->error = $errmsg; + return $ret; + } + + private function connect() { + if ($this->linkdb !== false) + return $this->linkdb; + $cfg = webini('mongodb' . $this->dbpst); + if (is_string($cfg)) + return $cfg; + + try { + $uriOptions = []; + $driverOptions = []; + $this->linkdb = new \MongoDB\Driver\Manager( + $cfg['uri'], + $uriOptions, + $driverOptions + ); + + $pingCommand = new \MongoDB\Driver\Command(['ping' => 1]); + $this->linkdb->executeCommand('admin', $pingCommand); + $this->database = $cfg['name']; + return $this->linkdb; + } catch (\Exception $e) { + return 'MongoDB connection failed: ' . $e->getMessage(); + } + } + private function getTransactionOptions($defaultOptions = null): array { + if ($this->isTransaction && $this->session) { + return ['session' => $this->session]; + } + + return $defaultOptions ? ['writeConcern' => $defaultOptions] : []; + } + + /** + * 获取查询的第一条数据 + * + * @param \stdClass $params 查询参数 + * - collection: string 集合名 + * - filter: array 查询条件 (可选) + * - options: array 查询选项 (可选) + * @return array|false 查询结果或false表示失败 + */ + public function getone(\stdClass $params) { + try { + $link = $this->connect(); + if (is_string($link)) + return $link; + $params->options = $params->options ?? []; + $params->options['limit'] = 1; + $params->filter = $params->filter ?? []; + $query = new \MongoDB\Driver\Query($params->filter, $params->options); + $cursor = $link->executeQuery( + "{$this->database}.{$params->collection}", + $query, + $this->getTransactionOptions() + ); + foreach ($cursor as $document) { + return $document; + } + return null; + } catch (\Exception $e) { + return $this->errdata('Query getone failed: ' . $e->getMessage()); + } + } + + /** + * 获取查询的多条数据(带分页) + * + * @param \stdClass $params 查询参数 + * - collection: string 集合名 + * - filter: array 查询条件 (可选) + * - options: array 查询选项 (可选) + * - pageno: int 页码 (默认1) + * - pagecount: int 每页数量 (默认10) + * @return \stdClass|false 包含数据和总数量的对象或false表示失败 + */ + public function get(\stdClass $params, &$rowcount = -1) { + try { + $link = $this->connect(); + if (is_string($link)) + return $link; + $params->filter = $params->filter ?? new \stdClass(); + $params->options = $params->options ?? []; + $params->pageno = $params->pageno ?? 1; + $params->pagecount = $params->pagecount ?? 10; + + if ($rowcount == -1) { + $countCommand = new \MongoDB\Driver\Command([ + 'count' => $params->collection, + 'query' => $params->filter + ]); + $countResult = $link->executeCommand($this->database, $countCommand, $this->getTransactionOptions()); + $rowcount = $countResult->toArray()[0]->n ?? 0; + } + + $params->options['skip'] = ($params->pageno - 1) * $params->pagecount; + $params->options['limit'] = $params->pagecount; + + // 执行查询 + $query = new \MongoDB\Driver\Query($params->filter, $params->options); + $cursor = $link->executeQuery( + "{$this->database}.{$params->collection}", + $query, + $this->getTransactionOptions() + ); + return $cursor; + } catch (\Exception $e) { + return $this->errdata('Query get failed: ' . $e->getMessage()); + } + } + + /** + * 插入数据 + * + * @param \stdClass $params 插入参数 + * - collection: string 集合名 + * - document: array 要插入的文档 + * - options: array 插入选项 (可选) + * @return int|false 插入数量或false表示失败 + */ + public function insert(\stdClass $params) { + if (empty($params->document) || !is_array($params->document)) { + return $this->errdata('Document must be provided and must be an array'); + } + + try { + $link = $this->connect(); + if (is_string($link)) + return $link; + $bulk = new \MongoDB\Driver\BulkWrite(); + $this->lastinsertid = $bulk->insert($params->document); + + $writeConcern = new \MongoDB\Driver\WriteConcern(\MongoDB\Driver\WriteConcern::MAJORITY, 1000); + $writeResult = $link->executeBulkWrite("{$this->database}.{$params->collection}", $bulk, $this->getTransactionOptions($writeConcern)); + + if ($writeResult === false) { + return $this->errdata('Write Error'); + } + + return $writeResult->getInsertedCount(); + } catch (\Exception $e) { + return $this->errdata('Insert operation failed: ' . $e->getMessage()); + } + } + + public function insert_id() { + return $this->lastinsertid; + } + + /** + * 更新数据 + * + * @param \stdClass $params 更新参数 + * - collection: string 集合名 + * - filter: array 查询条件 + * - update: array 更新操作 + * - options: array 更新选项 (可选) + * @return int|false 更新的文档数量或false表示失败 + */ + public function update(\stdClass $params) { + if (empty($params->filter) || !is_array($params->filter)) { + return $this->errdata('Filter must be provided and must be an array'); + } + + if (empty($params->update) || !is_array($params->update)) { + return $this->errdata('Update must be provided and must be an array'); + } + + try { + $link = $this->connect(); + if (is_string($link)) + return $link; + $bulk = new \MongoDB\Driver\BulkWrite(); + + $params->options = $params->options ?? []; + if (!isset($params->options['multi'])) { + $params->options['multi'] = false; + } + $bulk->update($params->filter, $params->update, $params->options); + $writeConcern = new \MongoDB\Driver\WriteConcern(\MongoDB\Driver\WriteConcern::MAJORITY, 1000); + $writeResult = $link->executeBulkWrite("{$this->database}.{$params->collection}", $bulk, $this->getTransactionOptions($writeConcern)); + + if ($writeResult === false) { + return $this->errdata('Write Error'); + } + return $writeResult->getModifiedCount(); + } catch (\Exception $e) { + return $this->errdata('Update operation failed: ' . $e->getMessage()); + } + } + + /** + * 删除数据 + * + * @param \stdClass $params 删除参数 + * - collection: string 集合名 + * - filter: array 查询条件 + * - options: array 删除选项 (可选) + * @return int|false 删除的文档数量或false表示失败 + */ + public function delete(\stdClass $params) { + if (empty($params->filter) || !is_array($params->filter)) { + return $this->errdata('Filter must be provided and must be an array'); + } + + try { + $link = $this->connect(); + if (is_string($link)) + return $link; + $bulk = new \MongoDB\Driver\BulkWrite(); + + $params->options = $params->options ?? []; + if (!isset($params->options['limit'])) { + $params->options['limit'] = false; + } + + $bulk->delete($params->filter, $params->options); + + $writeConcern = new \MongoDB\Driver\WriteConcern(\MongoDB\Driver\WriteConcern::MAJORITY, 1000); + $writeResult = $link->executeBulkWrite("{$this->database}.{$params->collection}", $bulk, $this->getTransactionOptions($writeConcern)); + + if ($writeResult === false) { + return $this->errdata('Write Error'); + } + return $writeResult->getDeletedCount(); + } catch (\Exception $e) { + return $this->errdata('Delete operation failed: ' . $e->getMessage()); + } + } + + /** + * 开始事务 + * @return bool 是否成功 + */ + public function begin() { + if ($this->isTransaction) { + return $this->errdata('Transaction already started'); + } + + try { + $link = $this->connect(); + if (is_string($link)) + return $link; + $this->session = $link->startSession(); + $this->session->startTransaction(); + $this->isTransaction = true; + return true; + } catch (\Exception $e) { + return $this->errdata('Failed to start transaction: ' . $e->getMessage()); + } + } + + /** + * 提交事务 + * @return bool 是否成功 + */ + public function commit() { + if (!$this->isTransaction) { + return $this->errdata('No active transaction to commit'); + } + + try { + $this->session->commitTransaction(); + $this->session->endSession(); + $this->isTransaction = false; + return true; + } catch (\Exception $e) { + $this->isTransaction = false; + return $this->errdata('Failed to commit transaction: ' . $e->getMessage()); + } + } + + /** + * 回滚事务 + * @return bool 是否成功 + */ + public function rollback() { + if (!$this->isTransaction) { + return $this->errdata('No active transaction to rollback'); + } + + try { + $this->session->abortTransaction(); + $this->session->endSession(); + $this->isTransaction = false; + return true; + } catch (\Exception $e) { + $this->isTransaction = false; + return $this->errdata('Failed to rollback transaction: ' . $e->getMessage()); + } + } + public function tran($func) { + if (!($func instanceof \Closure)) { + $this->error = '没有传递正确的闭包函数'; + return false; + } + $this->begin(); + $ret = false; + try { + $ret = $func(); + } catch (\Exception $ex) { + $ret = false; + $this->error = $ex->getMessage(); + } + if ($ret === false) + $this->rollback(); + else + $this->commit(); + return $ret; + } +}