From 640e8f44820ce27a830fcba6fede757374148ead Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E9=87=91=E5=8B=87?= Date: Tue, 11 Jul 2023 07:28:39 +0000 Subject: [PATCH] * Use helper::setcookie. --- framework/base/helper.class.php | 32 +++++++++++++++++++++++++++++++ framework/base/router.class.php | 6 +++--- framework/control.class.php | 4 ++-- framework/helper.class.php | 25 ------------------------ framework/zand/composer.json | 2 +- framework/zand/response.class.php | 4 ++-- framework/zand/router.class.php | 4 +++- module/caselib/control.php | 8 ++++---- module/doc/control.php | 4 ++-- module/file/model.php | 2 +- module/mr/control.php | 2 +- module/mr/model.php | 2 +- module/project/model.php | 2 +- module/qa/model.php | 2 +- module/repo/control.php | 12 ++++++------ module/repo/model.php | 2 +- module/sso/control.php | 4 ++-- module/testsuite/model.php | 2 +- module/testtask/control.php | 10 +++++----- module/testtask/model.php | 2 +- module/tree/model.php | 2 +- module/user/control.php | 10 ++++++---- module/user/model.php | 6 +++--- module/webhook/control.php | 4 ++-- www/.rr.yaml | 14 +++++++------- www/worker.php | 28 ++++++++++++++++++++++++++- 26 files changed, 116 insertions(+), 79 deletions(-) diff --git a/framework/base/helper.class.php b/framework/base/helper.class.php index 581eb01d3a..f1fa7da202 100644 --- a/framework/base/helper.class.php +++ b/framework/base/helper.class.php @@ -803,6 +803,38 @@ class baseHelper return null; } + /** + * Send a cookie. + * + * @param string $name + * @param string $value + * @param int|null $expire + * @param string|null $path + * @param string $domain + * @param bool|null $secure + * @param bool $httponly + * @static + * @access public + * @return bool + */ + public static function setcookie(string $name, string $value = '', int $expire = null, string $path = null, string $domain = '', bool $secure = null, bool $httponly = true) + { + global $config, $app; + + if($expire === null) $expire = $config->cookieLife; + if($path === null) $path = $config->webRoot; + if($secure === null) $secure = $config->cookieSecure; + + if(isset($app->worker)) + { + $app->worker->response->setCookie($name, $value, $expire, $path, $domain, $secure, $httponly); + } + else + { + return setcookie($name, $value, $expire, $path, $domain, $secure, $httponly); + } + } + /** * 设置状态码。 * Set status code. diff --git a/framework/base/router.class.php b/framework/base/router.class.php index dba016bfd7..d75514584b 100644 --- a/framework/base/router.class.php +++ b/framework/base/router.class.php @@ -1210,7 +1210,7 @@ class baseRouter $this->clientLang = $this->config->default->lang; } - setcookie('lang', (string) $this->clientLang, array('expires' => $this->config->cookieLife, 'path' => (string) $this->config->webRoot, 'domain' => '', 'secure' => $this->config->cookieSecure, 'httponly' => false)); + helper::setcookie('lang', (string) $this->clientLang, $this->config->cookieLife, (string) $this->config->webRoot, '', $this->config->cookieSecure, false); if(!isset($_COOKIE['lang'])) $_COOKIE['lang'] = $this->clientLang; return true; @@ -1264,7 +1264,7 @@ class baseRouter $this->clientTheme = $this->config->default->theme; } - setcookie('theme', (string) $this->clientTheme, array('expires' => $this->config->cookieLife, 'path' => (string) $this->config->webRoot, 'domain' => '', 'secure' => $this->config->cookieSecure, 'httponly' => false)); + helper::setcookie('theme', (string) $this->clientTheme, $this->config->cookieLife, (string) $this->config->webRoot, '', $this->config->cookieSecure, false); if(!isset($_COOKIE['theme'])) $_COOKIE['theme'] = $this->clientTheme; return true; @@ -1290,7 +1290,7 @@ class baseRouter $this->clientDevice = ($mobile->isMobile() and !$mobile->isTablet()) ? 'mobile' : 'desktop'; } - setcookie('device', $this->clientDevice, array('expires' => $this->config->cookieLife, 'path' => (string) $this->config->webRoot, 'domain' => '', 'secure' => $this->config->cookieSecure, 'httponly' => true)); + helper::setcookie('device', $this->clientDevice, $this->config->cookieLife, (string) $this->config->webRoot, '', $this->config->cookieSecure, true); if(!isset($_COOKIE['device'])) $_COOKIE['device'] = $this->clientDevice; return $this->clientDevice; diff --git a/framework/control.class.php b/framework/control.class.php index 8039e915c1..a9956d67a8 100644 --- a/framework/control.class.php +++ b/framework/control.class.php @@ -635,7 +635,7 @@ class control extends baseControl } /** - * Call the functions declared in the tao files. + * Call the functions declared in the zen files. * * @param string $method * @param array $arguments @@ -653,7 +653,7 @@ class control extends baseControl } /** - * Call the static functions declared in the tao files. + * Call the static functions declared in the zen files. * * @param string $method * @param array $arguments diff --git a/framework/helper.class.php b/framework/helper.class.php index 9e47100e68..c0544f2eaf 100644 --- a/framework/helper.class.php +++ b/framework/helper.class.php @@ -357,31 +357,6 @@ class helper extends baseHelper return $dateInterval; } - /** - * Send a cookie. - * - * @param string $name - * @param string $value - * @param int|null $expire - * @param string|null $path - * @param string $domain - * @param bool|null $secure - * @param bool $httponly - * @static - * @access public - * @return bool - */ - public static function setcookie(string $name, string $value = '', int $expire = null, string $path = null, string $domain = '', bool $secure = null, bool $httponly = true) - { - global $config; - - if($expire === null) $expire = $config->cookieLife; - if($path === null) $path = $config->webRoot; - if($secure === null) $secure = $config->cookieSecure; - - return setcookie($name, $value, $expire, $path, $domain, $secure, $httponly); - } - /** * 转换类型。 * Convert the type. diff --git a/framework/zand/composer.json b/framework/zand/composer.json index abea986fa2..af23355351 100644 --- a/framework/zand/composer.json +++ b/framework/zand/composer.json @@ -2,7 +2,7 @@ "require": { "spiral/roadrunner": "v2.0", "nyholm/psr7": "^1.8", - "spiral/roadrunner-jobs": "^2.0", + "spiral/roadrunner-jobs": "^3.0", "spiral/goridge": "^3.2", "spiral/roadrunner-kv": "^3.0" } diff --git a/framework/zand/response.class.php b/framework/zand/response.class.php index 3ad2984229..db0c67b940 100644 --- a/framework/zand/response.class.php +++ b/framework/zand/response.class.php @@ -259,13 +259,13 @@ class zandResponse implements ResponseInterface $this->stream = Stream::create($body); } - public function setCookie(string $name, string $value, $expire, ?string $path = null, ?string $domain = null, ?bool $secure = null, ?bool $httpOnly = null, ?string $sameSite = null): static + public function setCookie(string $name, string $value, ?int $expire, ?string $path = null, ?string $domain = null, ?bool $secure = null, ?bool $httpOnly = null, ?string $sameSite = null): static { $headerValue = sprintf('%s=%s; path=%s; SameSite=%s', $name, urlencode($value), $path ?? ($domain ? '/' : $this->cookiePath), $sameSite ?? 'Lax'); if($expire) { - $headerValue .= '; Expires='.(date('D, d M Y H:i:s T', strtotime($expire))); + $headerValue .= '; Expires='.(date('D, d M Y H:i:s T', $expire)); } $cookieDomain = $domain ?? $this->cookieDomain; diff --git a/framework/zand/router.class.php b/framework/zand/router.class.php index 876b0640aa..22656ef24b 100644 --- a/framework/zand/router.class.php +++ b/framework/zand/router.class.php @@ -100,6 +100,8 @@ class zandRouter extends router $this->methodName = NULL; $this->rawModule = NULL; $this->rawMethod = NULL; + $this->params = NULL; + $this->user = NULL; self::$loadedConfigs = array(); self::$loadedLangs = array(); @@ -423,7 +425,7 @@ class zandSession */ public function gc($maxlifetime) { - $this->dao->delete(TABLE_SESSION)->where('timestamp')->lt(time() - intval($maxlifetime))->exec(); + $this->dao->delete()->from(TABLE_SESSION)->where('timestamp')->lt(time() - intval($maxlifetime))->exec(); return true; } } diff --git a/module/caselib/control.php b/module/caselib/control.php index 22d0f4ef55..6d2ef3a19d 100644 --- a/module/caselib/control.php +++ b/module/caselib/control.php @@ -152,14 +152,14 @@ class caselib extends control /* Set menu. */ $libID = $this->caselib->saveLibState($libID, $libraries); - setcookie('preCaseLibID', $libID, $this->config->cookieLife, $this->config->webRoot, '', $this->config->cookieSecure, true); + helper::setcookie('preCaseLibID', $libID, $this->config->cookieLife, $this->config->webRoot, '', $this->config->cookieSecure, true); if($this->cookie->preCaseLibID != $libID) { $_COOKIE['libCaseModule'] = 0; - setcookie('libCaseModule', 0, 0, $this->config->webRoot, '', $this->config->cookieSecure, true); + helper::setcookie('libCaseModule', 0, 0, $this->config->webRoot, '', $this->config->cookieSecure, true); } - if($browseType == 'bymodule') setcookie('libCaseModule', (int)$param, 0, $this->config->webRoot, '', $this->config->cookieSecure, true); + if($browseType == 'bymodule') helper::setcookie('libCaseModule', (int)$param, 0, $this->config->webRoot, '', $this->config->cookieSecure, true); if($browseType != 'bymodule') $this->session->set('libBrowseType', $browseType); $moduleID = ($browseType == 'bymodule') ? (int)$param : ($browseType == 'bysearch' ? 0 : ($this->cookie->libCaseModule ? $this->cookie->libCaseModule : 0)); $queryID = ($browseType == 'bysearch') ? (int)$param : 0; @@ -224,7 +224,7 @@ class caselib extends control if(!empty($_POST)) { $this->loadModel('testcase'); - setcookie('lastLibCaseModule', (int)$this->post->module, $this->config->cookieLife, $this->config->webRoot, '', $this->config->cookieSecure, false); + helper::setcookie('lastLibCaseModule', (int)$this->post->module, $this->config->cookieLife, $this->config->webRoot, '', $this->config->cookieSecure, false); $case = form::data($this->config->testcase->form->create)->add('lib', $libID)->get(); diff --git a/module/doc/control.php b/module/doc/control.php index 6955b5ec69..381484ba5d 100755 --- a/module/doc/control.php +++ b/module/doc/control.php @@ -380,7 +380,7 @@ class doc extends control $libID = $this->post->lib; $moduleID = $this->post->module; if(empty($libID) and strpos($this->post->module, '_') !== false) list($libID, $moduleID) = explode('_', $this->post->module); - setcookie('lastDocModule', $moduleID, $this->config->cookieLife, $this->config->webRoot, '', $this->config->cookieSecure, true); + helper::setcookie('lastDocModule', $moduleID, $this->config->cookieLife, $this->config->webRoot, '', $this->config->cookieSecure, true); $docResult = $this->doc->create(); if(!$docResult or dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); @@ -1043,7 +1043,7 @@ class doc extends control { $this->loadModel('file'); if(empty($viewType)) $viewType = !empty($_COOKIE['docFilesViewType']) ? $this->cookie->docFilesViewType : 'list'; - setcookie('docFilesViewType', $viewType, $this->config->cookieLife, $this->config->webRoot, '', $this->config->cookieSecure, true); + helper::setcookie('docFilesViewType', $viewType, $this->config->cookieLife, $this->config->webRoot, '', $this->config->cookieSecure, true); $objects = $this->doc->getOrderedObjects($type, 'nomerge', $objectID); list($libs, $libID, $object, $objectID, $objectDropdown) = $this->doc->setMenuByType($type, $objectID, 0); diff --git a/module/file/model.php b/module/file/model.php index 40e5b2a185..29e57df294 100755 --- a/module/file/model.php +++ b/module/file/model.php @@ -1068,7 +1068,7 @@ class fileModel extends model for($i = 0; $i < $obLevel; $i++) ob_end_clean(); /* Set the downloading cookie, thus the export form page can use it to judge whether to close the window or not. */ - setcookie('downloading', 1, 0, $this->config->webRoot, '', $this->config->cookieSecure, false); + helper::setcookie('downloading', 1, 0, $this->config->webRoot, '', $this->config->cookieSecure, false); /* Only download upload file that is in zentao. */ if($type == 'file' and stripos($content, $this->savePath) !== 0) helper::end(); diff --git a/module/mr/control.php b/module/mr/control.php index eabfd40656..127a9842ba 100644 --- a/module/mr/control.php +++ b/module/mr/control.php @@ -448,7 +448,7 @@ class mr extends control if($this->post->arrange) { $arrange = $this->post->arrange; - setcookie('arrange', $arrange); + helper::setcookie('arrange', $arrange); } if($this->post->encoding) $encoding = $this->post->encoding; } diff --git a/module/mr/model.php b/module/mr/model.php index 30b02853d3..c5c1d8391a 100644 --- a/module/mr/model.php +++ b/module/mr/model.php @@ -1530,7 +1530,7 @@ class mrModel extends model { $bugID = $this->dao->lastInsertID(); $this->loadModel('file')->updateObjectID($this->post->uid, $bugID, 'bug'); - setcookie("repoPairs[$repoID]", $data->product); + helper::setcookie("repoPairs[$repoID]", $data->product); $bugInfo = array(); $bugInfo['result'] = 'success'; diff --git a/module/project/model.php b/module/project/model.php index da7636a15f..83e754d3ce 100755 --- a/module/project/model.php +++ b/module/project/model.php @@ -117,7 +117,7 @@ class projectModel extends model } } - setcookie('lastProject', (string)$this->session->project, $this->config->cookieLife, $this->config->webRoot, '', $this->config->cookieSecure, true); + helper::setcookie('lastProject', (string)$this->session->project, $this->config->cookieLife, $this->config->webRoot, '', $this->config->cookieSecure, true); return $this->session->project; } diff --git a/module/qa/model.php b/module/qa/model.php index 20f0b2da2f..83ff1862aa 100644 --- a/module/qa/model.php +++ b/module/qa/model.php @@ -30,7 +30,7 @@ class qaModel extends model } $branch = ($this->cookie->preBranch !== '' and $branch === '') ? $this->cookie->preBranch : $branch; - setcookie('preBranch', $branch, $this->config->cookieLife, $this->config->webRoot, '', $this->config->cookieSecure, true); + helper::setcookie('preBranch', $branch, $this->config->cookieLife, $this->config->webRoot, '', $this->config->cookieSecure, true); $product = $this->loadModel('product')->getByID($productID); if($product and $product->type != 'normal') $this->lang->product->branch = sprintf($this->lang->product->branch, $this->lang->product->branchName[$product->type]); diff --git a/module/repo/control.php b/module/repo/control.php index 24d121c114..da13f3e77f 100644 --- a/module/repo/control.php +++ b/module/repo/control.php @@ -633,7 +633,7 @@ class repo extends control } } - if($this->cookie->repoRefresh) setcookie('repoRefresh', 0, 0, $this->config->webRoot, '', $this->config->cookieSecure, true); + if($this->cookie->repoRefresh) helper::setcookie('repoRefresh', 0, 0, $this->config->webRoot, '', $this->config->cookieSecure, true); /* Synchronous commit only in root path. */ if(in_array($repo->SCM, $this->config->repo->gitTypeList) and empty($path) and $infos and empty($revisions)) $this->locate($this->repo->createLink('showSyncCommit', "repoID=$repoID&objectID=$objectID&branch=" . helper::safe64Encode(base64_encode($this->cookie->repoBranch)))); @@ -860,7 +860,7 @@ class repo extends control if($this->post->arrange) { $arrange = $this->post->arrange; - setcookie('arrange', $arrange); + helper::setcookie('arrange', $arrange); } if($this->post->encoding) $encoding = $this->post->encoding; if($this->post->isBranchOrTag) $isBranchOrTag = $this->post->isBranchOrTag; @@ -1449,7 +1449,7 @@ class repo extends control } $this->repo->setRepoBranch($branchID); - setcookie("syncBranch", $branchID, 0, $this->config->webRoot, '', $this->config->cookieSecure, true); + helper::setcookie("syncBranch", $branchID, 0, $this->config->webRoot, '', $this->config->cookieSecure, true); } } @@ -1483,7 +1483,7 @@ class repo extends control if($branchID) $this->repo->saveExistCommits4Branch($repo->id, $branchID); $branchID = reset($branches); - setcookie("syncBranch", $branchID, 0, $this->config->webRoot, '', $this->config->cookieSecure, true); + helper::setcookie("syncBranch", $branchID, 0, $this->config->webRoot, '', $this->config->cookieSecure, true); if($branchID) $this->repo->fixCommit($repoID); } @@ -1518,7 +1518,7 @@ class repo extends control $this->scm->setEngine($repo); $this->repo->setRepoBranch($branch); - setcookie("syncBranch", $branch, 0, $this->config->webRoot, '', $this->config->cookieSecure, true); + helper::setcookie("syncBranch", $branch, 0, $this->config->webRoot, '', $this->config->cookieSecure, true); $latestInDB = $this->dao->select('t1.*')->from(TABLE_REPOHISTORY)->alias('t1') ->leftJoin(TABLE_REPOBRANCH)->alias('t2')->on('t1.id=t2.revision') @@ -1539,7 +1539,7 @@ class repo extends control { if($branch) $this->repo->saveExistCommits4Branch($repo->id, $branch); - setcookie("syncBranch", $branch, 0, $this->config->webRoot, '', $this->config->cookieSecure, true); + helper::setcookie("syncBranch", $branch, 0, $this->config->webRoot, '', $this->config->cookieSecure, true); $this->repo->markSynced($repoID); return print('finish'); } diff --git a/module/repo/model.php b/module/repo/model.php index debb51bee5..d631273270 100644 --- a/module/repo/model.php +++ b/module/repo/model.php @@ -1328,7 +1328,7 @@ class repoModel extends model */ public function setRepoBranch($branch) { - setcookie("repoBranch", $branch, 0, $this->config->webRoot, '', $this->config->cookieSecure); + helper::setcookie("repoBranch", $branch, 0, $this->config->webRoot, '', $this->config->cookieSecure); $_COOKIE['repoBranch'] = $branch; } diff --git a/module/sso/control.php b/module/sso/control.php index a283b095fe..deffb6a655 100644 --- a/module/sso/control.php +++ b/module/sso/control.php @@ -156,8 +156,8 @@ class sso extends control if($this->get->status == 'success') { session_destroy(); - setcookie('za', false); - setcookie('zp', false); + helper::setcookie('za', false); + helper::setcookie('zp', false); $this->locate($this->createLink('user', 'login')); } $this->locate($this->createLink('user', 'logout')); diff --git a/module/testsuite/model.php b/module/testsuite/model.php index 9823104815..4b4faaf8bd 100644 --- a/module/testsuite/model.php +++ b/module/testsuite/model.php @@ -32,7 +32,7 @@ class testsuiteModel extends model return; } - setcookie("lastProduct", $productID, $this->config->cookieLife, $this->config->webRoot, '', $this->config->cookieSecure, true); + helper::setcookie("lastProduct", $productID, $this->config->cookieLife, $this->config->webRoot, '', $this->config->cookieSecure, true); $currentProduct = $this->product->getById($productID); $dropMenuLink = helper::createLink('product', 'ajaxGetDropMenu', "objectID=$productID&module=$currentModule&method=$currentMethod&extra=$extra"); diff --git a/module/testtask/control.php b/module/testtask/control.php index fa689f9ae6..49530b9a50 100644 --- a/module/testtask/control.php +++ b/module/testtask/control.php @@ -508,7 +508,7 @@ class testtask extends control { $this->testtask->setMenu($this->products, $productID, $task->branch, $taskID); } - setcookie('preTaskID', $taskID, $this->config->cookieLife, $this->config->webRoot, '', $this->config->cookieSecure, true); + helper::setcookie('preTaskID', $taskID, $this->config->cookieLife, $this->config->webRoot, '', $this->config->cookieSecure, true); /* Determines whether an object is editable. */ $canBeChanged = common::canBeChanged('testtask', $task); @@ -516,10 +516,10 @@ class testtask extends control if($this->cookie->preTaskID != $taskID) { $_COOKIE['taskCaseModule'] = 0; - setcookie('taskCaseModule', 0, 0, $this->config->webRoot, '', $this->config->cookieSecure, true); + helper::setcookie('taskCaseModule', 0, 0, $this->config->webRoot, '', $this->config->cookieSecure, true); } - if($browseType == 'bymodule') setcookie('taskCaseModule', (int)$param, 0, $this->config->webRoot, '', $this->config->cookieSecure, true); + if($browseType == 'bymodule') helper::setcookie('taskCaseModule', (int)$param, 0, $this->config->webRoot, '', $this->config->cookieSecure, true); if($browseType != 'bymodule') $this->session->set('taskCaseBrowseType', $browseType); if($browseType == 'bysuite') $suiteName = $this->loadModel('testsuite')->getById($param)->name; @@ -678,7 +678,7 @@ class testtask extends control $this->app->loadLang('execution'); $this->app->loadLang('task'); $this->session->set('caseList', $this->app->getURI(true), 'qa'); - setcookie('taskCaseModule', 0, 0, $this->config->webRoot, '', $this->config->cookieSecure, true); + helper::setcookie('taskCaseModule', 0, 0, $this->config->webRoot, '', $this->config->cookieSecure, true); /* Get task and product info, set menu. */ $groupBy = empty($groupBy) ? 'story' : $groupBy; @@ -1252,7 +1252,7 @@ class testtask extends control else { /* set cookie for ajax load caselist when close colorbox. */ - setcookie('selfClose', 1, 0, $this->config->webRoot, '', $this->config->cookieSecure, false); + helper::setcookie('selfClose', 1, 0, $this->config->webRoot, '', $this->config->cookieSecure, false); if($preAndNext->next and $this->app->tab != 'my') { diff --git a/module/testtask/model.php b/module/testtask/model.php index 1507d49a2d..3b465d3e2b 100755 --- a/module/testtask/model.php +++ b/module/testtask/model.php @@ -2406,7 +2406,7 @@ class testtaskModel extends model } $branch = ($this->cookie->preBranch !== '' and $branch === '') ? $this->cookie->preBranch : $branch; - setcookie('preBranch', $branch, $this->config->cookieLife, $this->config->webRoot, '', $this->config->cookieSecure, true); + helper::setcookie('preBranch', $branch, $this->config->cookieLife, $this->config->webRoot, '', $this->config->cookieSecure, true); $product = $this->loadModel('product')->getById($productID); if($product and $product->type != 'normal') $this->lang->product->branch = sprintf($this->lang->product->branch, $this->lang->product->branchName[$product->type]); diff --git a/module/tree/model.php b/module/tree/model.php index 836eebf4f6..e971012654 100644 --- a/module/tree/model.php +++ b/module/tree/model.php @@ -2074,7 +2074,7 @@ class treeModel extends model break; } if(strpos($this->session->{$module->type . 'List'}, 'param=' . $moduleID)) $this->session->set($module->type . 'List', str_replace('param=' . $moduleID, 'param=0', $this->session->{$module->type . 'List'})); - if($cookieName) setcookie($cookieName, 0, time() - 3600, $this->config->webRoot, '', $this->config->cookieSecure, true); + if($cookieName) helper::setcookie($cookieName, 0, time() - 3600, $this->config->webRoot, '', $this->config->cookieSecure, true); return true; } diff --git a/module/user/control.php b/module/user/control.php index e1b51b26cf..4546f6fa6b 100755 --- a/module/user/control.php +++ b/module/user/control.php @@ -973,7 +973,7 @@ class user extends control } else { - setcookie('tab', false, time(), $this->config->webRoot); + helper::setcookie('tab', false, time(), $this->config->webRoot); $loginExpired = !(preg_match("/(m=|\/)(index)(&f=|-)(index)(&|-|\.)?/", strtolower($this->referer), $output) or $this->referer == $this->config->webRoot or empty($this->referer) or preg_match("/\/www\/$/", strtolower($this->referer), $output)); $this->loadModel('misc'); @@ -1044,9 +1044,11 @@ class user extends control public function logout($referer = 0) { if(isset($this->app->user->id)) $this->loadModel('action')->create('user', $this->app->user->id, 'logout'); - setcookie('za', false, time() - 3600, $this->config->webRoot); - setcookie('zp', false, time() - 3600, $this->config->webRoot); - setcookie('tab', false, time() - 3600, $this->config->webRoot); + helper::setcookie('za', false, time() - 3600, $this->config->webRoot); + helper::setcookie('zp', false, time() - 3600, $this->config->webRoot); + helper::setcookie('tab', false, time() - 3600, $this->config->webRoot); + + $_SESSION = array(); session_destroy(); if($this->app->getViewType() == 'json') return print(json_encode(array('status' => 'success'))); diff --git a/module/user/model.php b/module/user/model.php index 798f3df4ff..d0ed338bc4 100644 --- a/module/user/model.php +++ b/module/user/model.php @@ -1180,9 +1180,9 @@ class userModel extends model */ public function keepLogin($user) { - setcookie('keepLogin', 'on', $this->config->cookieLife, $this->config->webRoot, '', $this->config->cookieSecure, true); - setcookie('za', $user->account, $this->config->cookieLife, $this->config->webRoot, '', $this->config->cookieSecure, true); - setcookie('zp', sha1($user->account . $user->password . $this->server->request_time), $this->config->cookieLife, $this->config->webRoot, '', $this->config->cookieSecure, true); + helper::setcookie('keepLogin', 'on', $this->config->cookieLife, $this->config->webRoot, '', $this->config->cookieSecure, true); + helper::setcookie('za', $user->account, $this->config->cookieLife, $this->config->webRoot, '', $this->config->cookieSecure, true); + helper::setcookie('zp', sha1($user->account . $user->password . $this->server->request_time), $this->config->cookieLife, $this->config->webRoot, '', $this->config->cookieSecure, true); } /** diff --git a/module/webhook/control.php b/module/webhook/control.php index e4a84caed6..921bb53f63 100644 --- a/module/webhook/control.php +++ b/module/webhook/control.php @@ -41,7 +41,7 @@ class webhook extends control $pager = new pager($recTotal, $recPerPage, $pageID); /* Unset selectedDepts cookie. */ - setcookie('selectedDepts', '', 0, $this->config->webRoot, '', $this->config->cookieSecure, true); + helper::setcookie('selectedDepts', '', 0, $this->config->webRoot, '', $this->config->cookieSecure, true); $this->view->title = $this->lang->webhook->api . $this->lang->colon . $this->lang->webhook->list; $this->view->webhooks = $this->webhook->getList($orderBy, $pager); @@ -188,7 +188,7 @@ class webhook extends control /* Get selected depts. */ if($this->get->selectedDepts) { - setcookie('selectedDepts', $this->get->selectedDepts, 0, $this->config->webRoot, '', $this->config->cookieSecure, true); + helper::setcookie('selectedDepts', $this->get->selectedDepts, 0, $this->config->webRoot, '', $this->config->cookieSecure, true); $_COOKIE['selectedDepts'] = $this->get->selectedDepts; } $selectedDepts = $this->cookie->selectedDepts ? $this->cookie->selectedDepts : ''; diff --git a/www/.rr.yaml b/www/.rr.yaml index 2c6473606d..bbe6f68520 100644 --- a/www/.rr.yaml +++ b/www/.rr.yaml @@ -1,12 +1,12 @@ version: "3" - #service: - # cron_schedule: - # command: php cron.php - # process_num: 1 - # exec_timeout: 0 - # restart_sec: 1 - # relay: pipes +service: + cron_schedule: + command: php cron.php + process_num: 1 + exec_timeout: 0 + restart_sec: 1 + relay: pipes server: command: php worker.php diff --git a/www/worker.php b/www/worker.php index 2f96b86e02..7f9f7b14dd 100644 --- a/www/worker.php +++ b/www/worker.php @@ -27,6 +27,8 @@ if($_SERVER['RR_MODE'] === 'jobs') if($type == 'zentao') { + ob_start(); + parse_str($cmd, $params); if(!isset($params['moduleName']) || !isset($params['methodName'])) continue; @@ -35,9 +37,11 @@ if($_SERVER['RR_MODE'] === 'jobs') $app->moduleName = $params['moduleName']; $app->methodName = $params['methodName']; + $app->rawModule = $params['moduleName']; + $app->rawMethod = $params['methodName']; $app->setControlFile(); $app->loadModule(); - $output = ob_get_contents(); + $output = ob_get_clean(); $app->closeRequest(); } @@ -46,6 +50,9 @@ if($_SERVER['RR_MODE'] === 'jobs') exec($cmd, $output, $return); if($output) $output = implode("\n", $output); } + + $log = date('H:m:s') . "task " . $id . " executed,\ncommand: $cmd.\nreturn : $return.\noutput : $output\n"; + logCron($app->getLogRoot(), $log); } $task->complete(); @@ -125,3 +132,22 @@ else $app->closeRequest(); } } + +/** + * Log cron. + * + * @param string $log + * @access public + * @return void + */ +function logCron($root, $log) +{ + if(!is_writable($root)) return false; + + $file = $root . 'cron.' . date('Ymd') . '.log.php'; + if(!is_file($file)) $log = "