diff --git a/config/zentaopms.php b/config/zentaopms.php index 93653e0281..219001cc18 100644 --- a/config/zentaopms.php +++ b/config/zentaopms.php @@ -220,6 +220,7 @@ $config->openMethods[] = 'sso.gettodolist'; $config->openMethods[] = 'sso.login'; $config->openMethods[] = 'sso.logout'; $config->openMethods[] = 'upgrade.ajaxupdatefile'; +$config->openMethods[] = 'upgrade.safedelete'; $config->openMethods[] = 'user.forgetpassword'; $config->openMethods[] = 'user.login'; $config->openMethods[] = 'user.refreshrandom'; diff --git a/module/common/model.php b/module/common/model.php index 6692db43d6..99dd75028b 100644 --- a/module/common/model.php +++ b/module/common/model.php @@ -1113,6 +1113,8 @@ class commonModel extends model if($this->app->getModuleName() == 'upgrade' and $this->session->upgrading) return false; + if($this->app->getModuleName() == 'upgrade' && $this->app->getMethodName() == 'safedelete') return false; + $statusFile = $this->app->getAppRoot() . 'www' . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'ok.txt'; return (!is_file($statusFile) or (time() - filemtime($statusFile)) > $this->config->safeFileTimeout) ? $statusFile : false; } diff --git a/module/upgrade/control.php b/module/upgrade/control.php index 9cf4a77674..2667db3f50 100644 --- a/module/upgrade/control.php +++ b/module/upgrade/control.php @@ -811,6 +811,32 @@ class upgrade extends control $this->display(); } + /** + * 删除安装和升级文件。 + * Safe delete install and upgrade files. + * + * @access public + * @return void + */ + public function safeDelete() + { + $files = []; + $wwwRoot = $this->app->getWwwRoot(); + foreach(['install', 'upgrade'] as $file) + { + if(is_file($wwwRoot . $file . '.php')) $files[] = $wwwRoot . $file . '.php'; + } + + if($files) + { + $command = 'rm -f ' . implode(' ', $files); + $tips = $this->lang->upgrade->safeDeleteFile . ' ' . $this->lang->upgrade->execCommand; + return $this->displayCommand($command, $tips); + } + + $this->locate($this->config->webRoot); + } + /** * 定时任务:处理内置关联关系。 * AJAX: Process object relation. diff --git a/module/upgrade/js/setstatusfile.ui.js b/module/upgrade/js/setstatusfile.ui.js index 88169749e2..ab45f13ba7 100644 --- a/module/upgrade/js/setstatusfile.ui.js +++ b/module/upgrade/js/setstatusfile.ui.js @@ -2,10 +2,10 @@ function confirmStatusFile(event) { if($(event.target).prop('checked')) { - $('#confirm').removeClass('disabled').attr('href', $.createLink('upgrade', 'index')); + $('#confirm').removeClass('disabled').attr('onclick', 'loadCurrentPage()'); } else { - $('#confirm').addClass('disabled').removeAttr('href'); + $('#confirm').addClass('disabled').removeAttr('onclick'); } } diff --git a/module/upgrade/lang/en.php b/module/upgrade/lang/en.php index c74be2ecb4..b44a2bf152 100644 --- a/module/upgrade/lang/en.php +++ b/module/upgrade/lang/en.php @@ -60,6 +60,7 @@ $lang->upgrade->createWinFile = 'Open command line and execute touch %s in the command line'; $lang->upgrade->deleteStatusFile = 'Or delete %s and create ok.txt and leave it blank.'; $lang->upgrade->confirmStatusFile = 'I have read and done as instructed above.'; +$lang->upgrade->safeDeleteFile = 'For system security, the files need to be deleted.'; $lang->upgrade->selectVersion = 'Version'; $lang->upgrade->copyCommand = 'Copy'; diff --git a/module/upgrade/lang/zh-cn.php b/module/upgrade/lang/zh-cn.php index d79e61c6d0..b0a7fe569b 100644 --- a/module/upgrade/lang/zh-cn.php +++ b/module/upgrade/lang/zh-cn.php @@ -60,6 +60,7 @@ $lang->upgrade->createWinFile = '打开命令行,执行 touch %s'; $lang->upgrade->deleteStatusFile = '或者删除 %s 这个文件,重新创建一个 ok.txt 文件,不需要内容。'; $lang->upgrade->confirmStatusFile = '我已经仔细阅读上面提示且完成上述工作'; +$lang->upgrade->safeDeleteFile = '为了系统安全,需要删除文件。'; $lang->upgrade->selectVersion = '选择版本'; $lang->upgrade->copyCommand = '复制命令'; diff --git a/module/upgrade/ui/command.html.php b/module/upgrade/ui/command.html.php index 33bd3530ce..e054dc4ae2 100644 --- a/module/upgrade/ui/command.html.php +++ b/module/upgrade/ui/command.html.php @@ -48,7 +48,7 @@ div div ( setClass('text-warning'), - $lang->upgrade->execCommand + $tips ), row ( diff --git a/module/upgrade/zen.php b/module/upgrade/zen.php index 17bad18de9..7632a490f8 100644 --- a/module/upgrade/zen.php +++ b/module/upgrade/zen.php @@ -1125,15 +1125,16 @@ class upgradeZen extends upgrade * Display command. * * @param string $command + * @param string $tips * @access protected * @return void */ - protected function displayCommand(string $command): void + protected function displayCommand(string $command, string $tips = ''): void { $this->view->title = $this->lang->upgrade->common; $this->view->result = 'fail'; $this->view->command = $command; - + $this->view->tips = $tips ?: $this->lang->upgrade->execCommand; $this->display('upgrade', 'command'); } diff --git a/www/index.php b/www/index.php index 75390925cd..e9465bae73 100644 --- a/www/index.php +++ b/www/index.php @@ -49,31 +49,6 @@ $handler = static function () /* Check the request is getconfig or not. */ if(isset($_GET['mode']) and $_GET['mode'] == 'getconfig') die(helper::removeUTF8Bom($app->exportConfig())); - /* Remove install.php and upgrade.php. */ - if(file_exists('install.php') or file_exists('upgrade.php')) - { - if(!empty($config->inContainer) && !isset($_SESSION['installing'])) - { - if(file_exists('install.php')) unlink('install.php'); - if(file_exists('upgrade.php')) unlink('upgrade.php'); - } - else - { - $undeletedFiles = array(); - if(file_exists('install.php')) $undeletedFiles[] = 'install.php'; - if(file_exists('upgrade.php')) $undeletedFiles[] = 'upgrade.php'; - $wwwDir = dirname(__FILE__); - if($undeletedFiles) - { - echo " -
"; - echo "
安全起见,请删除 {$wwwDir} 目录下的 " . join(' 和 ', $undeletedFiles) . " 文件。
"; - echo "
Please remove " . join(' and ', $undeletedFiles) . " under $wwwDir dir for security reason.
"; - die("
"); - } - } - } - if(!empty($_GET['display']) && $_GET['display'] == 'card') $config->default->view = 'xhtml'; try @@ -87,6 +62,25 @@ $handler = static function () $isClient = strpos($_SERVER['HTTP_USER_AGENT'], 'xuanxuan') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'uni-app') !== false; if($app->getViewType() != 'json' && session_id() != $app->sessionID && !$isClient) helper::restartSession($app->sessionID); + /* Remove install.php and upgrade.php. */ + $wwwDir = dirname(__FILE__); + if(file_exists("{$wwwDir}/install.php") || file_exists("{$wwwDir}/upgrade.php")) + { + if(!empty($config->inContainer) && !isset($_SESSION['installing'])) + { + if(file_exists('install.php')) unlink('install.php'); + if(file_exists('upgrade.php')) unlink('upgrade.php'); + } + else + { + if($app->getModuleName() != 'upgrade' && $app->getMethodName() != 'safedelete') + { + $url = helper::createLink('upgrade', 'safeDelete'); + die(header("location: $url")); + } + } + } + $app->loadModule(); } catch (EndResponseException $endResponseException)