diff --git a/app/common.php b/app/common.php index 3eaba98..60f6407 100644 --- a/app/common.php +++ b/app/common.php @@ -30,7 +30,7 @@ function get_curl(string $url, $post = 0, $referer = 0, $cookie = 0, $header = 0 $response = $client->post($url, [ 'form_params' => $post, 'headers' => $header, - 'verify' => false + 'verify' => false, ]); } @@ -83,7 +83,7 @@ function dstrpos($string, $arr) function checkmobile() { $useragent = strtolower($_SERVER['HTTP_USER_AGENT']); - $ualist = array('android', 'midp', 'nokia', 'mobile', 'iphone', 'ipod', 'blackberry', 'windows phone'); + $ualist = ['android', 'midp', 'nokia', 'mobile', 'iphone', 'ipod', 'blackberry', 'windows phone']; if ((dstrpos($useragent, $ualist) || strexists($_SERVER['HTTP_ACCEPT'], "VND.WAP") || strexists($_SERVER['HTTP_VIA'], "wap"))) { return true; } else { @@ -104,7 +104,7 @@ function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) $string_length = strlen($string); $result = ''; $box = range(0, 255); - $rndkey = array(); + $rndkey = []; for ($i = 0; $i <= 255; $i++) { $rndkey[$i] = ord($cryptkey[$i % $key_length]); } @@ -256,7 +256,7 @@ function config_set($key, $value) function getMillisecond() { - list($s1, $s2) = explode(' ', microtime()); + [$s1, $s2] = explode(' ', microtime()); return (int)sprintf('%.0f', (floatval($s1) + floatval($s2)) * 1000); } @@ -287,3 +287,42 @@ function convert_second($s) } } } + +function check_proxy($url, $proxy_server, $proxy_port, $type, $proxy_user, $proxy_pwd) +{ + if ($type == 'https') { + $proxy_type = CURLPROXY_HTTPS; + } elseif ($type == 'sock4') { + $proxy_type = CURLPROXY_SOCKS4; + } elseif ($type == 'sock5') { + $proxy_type = CURLPROXY_SOCKS5; + } else { + $proxy_type = CURLPROXY_HTTP; + } + $options = [ + CURLOPT_PROXYTYPE => $proxy_type, + CURLOPT_PROXYAUTH => CURLAUTH_BASIC, + CURLOPT_PROXY => $proxy_server, + CURLOPT_PROXYUSERPWD => !empty($proxy_user) && !empty($proxy_pwd) ? $proxy_user . ':' . $proxy_pwd : '', + CURLOPT_PROXYPORT => $proxy_port, + ]; + $client = new Client([ + 'curl' => $options, + 'timeout' => 3, + 'verify' => false, + 'headers' => [ + 'user-agent' => 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36', + ], + ]); + try { + $response = $client->request('GET', $url); + } catch (\GuzzleHttp\Exception\RequestException $e) { + throw new Exception($e->getMessage()); + } + $httpCode = $response->getStatusCode(); + if ($httpCode >= 200 && $httpCode < 400) { + return true; + } else { + throw new Exception('HTTP状态码异常:' . $httpCode); + } +} diff --git a/app/controller/Dmonitor.php b/app/controller/Dmonitor.php index 180c27c..45014c1 100644 --- a/app/controller/Dmonitor.php +++ b/app/controller/Dmonitor.php @@ -284,6 +284,26 @@ class Dmonitor extends BaseController } } + public function proxytest() + { + if (!checkPermission(2)) return $this->alert('error', '无权限'); + $proxy_server = $this->request->post('proxy_server'); + $proxy_port = $this->request->post('proxy_port'); + $proxy_user = $this->request->post('proxy_user'); + $proxy_pwd = $this->request->post('proxy_pwd'); + $proxy_type = $this->request->post('proxy_type'); + try { + check_proxy('https://dl.amh.sh/ip.htm', $proxy_server, $proxy_port, $proxy_type, $proxy_user, $proxy_pwd); + } catch (Exception $e) { + try { + check_proxy('https://myip.ipip.net/', $proxy_server, $proxy_port, $proxy_type, $proxy_user, $proxy_pwd); + } catch (Exception $e) { + return json(['code' => -1, 'msg' => $e->getMessage()]); + } + } + return json(['code' => 0]); + } + public function clean() { if (!checkPermission(2)) { diff --git a/app/controller/Install.php b/app/controller/Install.php index 853e435..f5cfe63 100644 --- a/app/controller/Install.php +++ b/app/controller/Install.php @@ -16,15 +16,15 @@ class Install extends BaseController if (file_exists(app()->getRootPath() . '.env')) { return '当前已经安装成功,如果需要重新安装,请手动删除根目录.env文件'; } - if (Request::isPost()) { - $mysql_host = Request::post('mysql_host'); - $mysql_port = intval(Request::post('mysql_port', '3306')); - $mysql_user = Request::post('mysql_user', null, 'trim'); - $mysql_pwd = Request::post('mysql_pwd', null, 'trim'); - $mysql_name = Request::post('mysql_name', null, 'trim'); - $mysql_prefix = Request::post('mysql_prefix', 'cloud_', 'trim'); - $admin_username = Request::post('admin_username', null, 'trim'); - $admin_password = Request::post('admin_password', null, 'trim'); + if ($this->request->isPost()) { + $mysql_host = $this->request->post('mysql_host'); + $mysql_port = intval($this->request->post('mysql_port', '3306')); + $mysql_user = $this->request->post('mysql_user', null, 'trim'); + $mysql_pwd = $this->request->post('mysql_pwd', null, 'trim'); + $mysql_name = $this->request->post('mysql_name', null, 'trim'); + $mysql_prefix = $this->request->post('mysql_prefix', 'cloud_', 'trim'); + $admin_username = $this->request->post('admin_username', null, 'trim'); + $admin_password = $this->request->post('admin_password', null, 'trim'); if (!$mysql_host || !$mysql_user || !$mysql_pwd || !$mysql_name || !$admin_username || !$admin_password) { return json(['code' => 0, 'msg' => '必填项不能为空']); diff --git a/app/view/dmonitor/proxyset.html b/app/view/dmonitor/proxyset.html index 119a3f3..cb3047f 100644 --- a/app/view/dmonitor/proxyset.html +++ b/app/view/dmonitor/proxyset.html @@ -2,128 +2,109 @@ {block name="title"}容灾切换代理设置{/block} {block name="main"}