diff --git a/app/Http/Controllers/Api/WebsitesController.php b/app/Http/Controllers/Api/WebsitesController.php index a7552b58..4194a1aa 100644 --- a/app/Http/Controllers/Api/WebsitesController.php +++ b/app/Http/Controllers/Api/WebsitesController.php @@ -17,12 +17,11 @@ class WebsitesController extends Controller { /** * 获取面板网站 - * @param Website $website * @return JsonResponse */ - public function getList(Website $website): JsonResponse + public function getList(): JsonResponse { - $website_lists = $website->query()->get(); + $website_lists = Website::query()->get(); // 判空 if ($website_lists->isEmpty()) { return response()->json([ @@ -75,7 +74,7 @@ class WebsitesController extends Controller $credentials['status'] = 1; $domain = trim($credentials['domain']); // 入库 - Website::create($credentials); + Website::query()->create($credentials); // 创建网站目录 shell_exec("mkdir -p " . $credentials['path']); // 创建index.html @@ -83,7 +82,7 @@ class WebsitesController extends Controller // 写入到index.html $index_html = << - + 耗子Linux面板 @@ -181,7 +180,7 @@ EOF; shell_exec('echo "" > /www/server/vhost/rewrite/' . $credentials['name'] . '.conf'); shell_exec('echo "" > /www/server/vhost/ssl/' . $credentials['name'] . '.pem'); shell_exec('echo "" > /www/server/vhost/ssl/' . $credentials['name'] . '.key'); - shell_exec("/etc/init.d/nginx reload"); + shell_exec("systemctl reload nginx"); // 创建数据库 if ($credentials['db']) { @@ -189,7 +188,8 @@ EOF; $password = Setting::query()->where('name', 'mysql_root_password')->value('value'); shell_exec("/www/server/mysql/bin/mysql -u root -p" . $password . " -e \"CREATE DATABASE IF NOT EXISTS " . $credentials['db_name'] . " DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;\" 2>&1"); shell_exec("/www/server/mysql/bin/mysql -u root -p" . $password . " -e \"CREATE USER '" . $credentials['db_username'] . "'@'localhost' IDENTIFIED BY '" . $credentials['db_password'] . "';\""); - shell_exec("/www/server/mysql/bin/mysql -u root -p" . $password . " -e \"GRANT ALL PRIVILEGES ON " . $credentials['db_name'] . ".* TO '" . $credentials['db_username'] . "'@'localhost' IDENTIFIED BY '" . $credentials['db_password'] . "';\""); + shell_exec("/www/server/mysql/bin/mysql -u root -p" . $password . " -e \"GRANT ALL PRIVILEGES ON " . $credentials['db_name'] . ".* TO '" . $credentials['db_username'] . "'@'localhost';\""); + shell_exec("/www/server/mysql/bin/mysql -u root -p" . $password . " -e \"flush privileges;\""); } } $res['code'] = 0; @@ -200,13 +200,14 @@ EOF; /** * 删除面板网站 - * @return + * @param Request $request + * @return JsonResponse */ - public function delete_website() + public function delete(Request $request): JsonResponse { - $name = Request::param('name'); + $name = $request->input('name'); // 从数据库删除 - Db::table('website')->where('name', $name)->delete(); + Website::query()->where('name', $name)->delete(); // 删除站点目录 shell_exec("rm -rf /www/wwwroot/$name"); // 删除nginx配置 @@ -219,7 +220,7 @@ EOF; $res['code'] = 0; $res['msg'] = 'success'; - return json($res); + return response()->json($res); } /** @@ -242,12 +243,13 @@ EOF; /** * 获取面板网站设置 - * @return + * @param Request $request + * @return JsonResponse */ - public function get_website_settings() + public function getSiteSettings(Request $request): JsonResponse { - $name = Request::param('name'); - $website = Db::table('website')->where('name', $name)->find(); + $name = $request->input('name'); + $website = Website::query()->where('name', $name)->first(); // 通过name读取相应的nginx配置 $nginx_config = file_get_contents('/www/server/vhost/' . $name . '.conf'); // 从nginx配置中port标记位提取全部端口 @@ -302,17 +304,18 @@ EOF; $res['code'] = 0; $res['msg'] = 'success'; $res['data'] = $website; - return json($res); + return response()->json($res); } /** * 保存网站设置 - * @return + * @param Request $request + * @return JsonResponse */ - public function save_website_settings() + public function saveSiteSettings(Request $request): JsonResponse { // 获取前端传递过来的数据 - $config = Request::param('config'); + $config = $request->input('config'); $res['code'] = 0; $res['msg'] = 'success'; @@ -321,7 +324,7 @@ EOF; $config_raw = shell_exec('cat /www/server/vhost/' . $config['name'] . '.conf'); if (trim($config_raw) != trim($config['config_raw'])) { file_put_contents('/www/server/vhost/' . $config['name'] . '.conf', $config['config_raw']); - return json($res); + return response()->json($res); } // 域名 @@ -404,7 +407,7 @@ EOF; } // 如果PHP版本不一致,则更新PHP版本 - $php_old = DB::table('website')->where('name', $config['name'])->value('php'); + $php_old = Website::query()->where('name', $config['name'])->value('php'); if ($config['php'] != $php_old) { $php_config_old = $this->cut('# php标记位开始', '# php标记位结束', $config_raw); $php_config_new = PHP_EOL; @@ -419,30 +422,31 @@ EOL; } // 将数据入库 - DB::table('website')->where('name', $config['name'])->update(['php' => $config['php']]); - DB::table('website')->where('name', $config['name'])->update(['ssl' => $config['ssl']]); + Website::query()->where('name', $config['name'])->update(['php' => $config['php']]); + Website::query()->where('name', $config['name'])->update(['ssl' => $config['ssl']]); file_put_contents('/www/server/vhost/' . $config['name'] . '.conf', $config_raw); file_put_contents('/www/server/vhost/rewrite/' . $config['name'] . '.conf', $config['rewrite_raw']); - shell_exec('/etc/init.d/nginx reload'); - return json($res); + shell_exec('systemctl reload nginx'); + return response()->json($res); } /** * 清理网站日志 - * @return + * @param Request $request + * @return JsonResponse */ - public function clean_website_log() + public function cleanSiteLog(Request $request): JsonResponse { - $name = Request::param('name'); + $name = $request->input('name'); shell_exec('echo "" > /www/wwwlogs/' . $name . '.log'); $res['code'] = 0; $res['msg'] = 'success'; - return json($res); + return response()->json($res); } // 裁剪字符串 - private function cut($begin, $end, $str) + private function cut($begin, $end, $str): string { $b = mb_strpos($str, $begin) + mb_strlen($begin); $e = mb_strpos($str, $end) - $b; diff --git a/plugins/Openresty/Controllers/OpenrestyController.php b/plugins/Openresty/Controllers/OpenrestyController.php index b0135e09..96479735 100755 --- a/plugins/Openresty/Controllers/OpenrestyController.php +++ b/plugins/Openresty/Controllers/OpenrestyController.php @@ -21,12 +21,12 @@ class OpenrestyController extends Controller public function status() { - $command = '/etc/init.d/nginx status'; + $command = 'systemctl status nginx'; $result = shell_exec($command); $res['code'] = 0; $res['msg'] = 'success'; - if (str_contains($result, 'stopped')) { + if (str_contains($result, 'inactive')) { $res['data'] = 'stopped'; } else { $res['data'] = 'running'; @@ -49,7 +49,7 @@ class OpenrestyController extends Controller return response()->json($res); } - $command2 = '/etc/init.d/nginx restart'; + $command2 = 'systemctl restart nginx'; $result2 = shell_exec($command2); if (str_contains($result2, 'done')) { $res['data'] = 'OpenResty已重启'; @@ -71,7 +71,7 @@ class OpenrestyController extends Controller return response()->json($res); } - $command2 = '/etc/init.d/nginx reload'; + $command2 = 'systemctl reload nginx'; $result2 = shell_exec($command2); if (str_contains($result2, 'done')) { $res['data'] = 'OpenResty已重载'; @@ -112,7 +112,7 @@ class OpenrestyController extends Controller return response()->json($res); } else { // 测试成功,则重载OpenResty - $reload = shell_exec('/etc/init.d/nginx reload'); + shell_exec('systemctl reload nginx'); $res['data'] = 'OpenResty主配置已保存'; return response()->json($res); } diff --git a/plugins/Openresty/views/index.blade.php b/plugins/Openresty/views/index.blade.php index 80b5680e..ab429c46 100755 --- a/plugins/Openresty/views/index.blade.php +++ b/plugins/Openresty/views/index.blade.php @@ -29,7 +29,7 @@ Date: 2022-11-02
-
此处修改的是OpenResty主配置文件,如果你不了解各参数的含义,请不要随意修改!
+
此处修改的是OpenResty主配置文件,如果你不了解各参数的含义,请不要随意修改!
提示:Ctrl+F 搜索关键字,Ctrl+S 保存,Ctrl+H 查找替换!
/etc/init.d/nginx start以启动OpenResty!' + content: '面板的正常访问依赖OpenResty,因此不支持在面板启动OpenResty,如您确需操作,请在SSH执行systemctl start nginx以启动OpenResty!' }); }); $('#openresty-stop').click(function () { @@ -179,7 +179,7 @@ Date: 2022-11-02 , skin: 'layui-anim layui-anim-upbit' , - content: '面板的正常访问依赖OpenResty,因此不支持在面板停止OpenResty,如您确需操作,请在SSH执行/etc/init.d/nginx stop以停止OpenResty!' + content: '面板的正常访问依赖OpenResty,因此不支持在面板停止OpenResty,如您确需操作,请在SSH执行systemctl stop nginx以停止OpenResty!' }); }); $('#openresty-restart').click(function () {