From b24f68098e62a0220e5d59ecdf2e3aaea49f9b63 Mon Sep 17 00:00:00 2001 From: GeekQu Date: Thu, 24 Oct 2019 10:21:18 +0800 Subject: [PATCH] ss && ssd --- app/Controllers/LinkController.php | 239 +++++++++++++++++++++++-- app/Controllers/UserController.php | 12 ++ app/Utils/URL.php | 4 + resources/clients/ss-win/使用注意.txt | 3 + resources/clients/ssd-win/使用注意.txt | 3 + resources/clients/ssr-win/使用注意.txt | 3 + 6 files changed, 249 insertions(+), 15 deletions(-) create mode 100644 resources/clients/ss-win/使用注意.txt create mode 100644 resources/clients/ssd-win/使用注意.txt create mode 100644 resources/clients/ssr-win/使用注意.txt diff --git a/app/Controllers/LinkController.php b/app/Controllers/LinkController.php index df032934..6d756754 100644 --- a/app/Controllers/LinkController.php +++ b/app/Controllers/LinkController.php @@ -960,6 +960,90 @@ class LinkController extends BaseController return base64_encode($return); } + public static function getSSPcConf($user) + { + $proxy = []; + $items = array_merge( + URL::getAllItems($user, 0, 1, 0), + URL::getAllItems($user, 1, 1, 0) + ); + foreach ($items as $item) { + $proxy_plugin = ''; + $proxy_plugin_opts = ''; + if ($item['obfs'] == 'v2ray' || in_array($item['obfs'], Config::getSupportParam('ss_obfs'))) { + if ($item['obfs'] == 'v2ray') { + $proxy_plugin .= 'v2ray'; + } else { + $proxy_plugin .= 'obfs-local'; + } + if (strpos($item['obfs'], 'http') !== false) { + $proxy_plugin_opts .= 'obfs=http'; + } elseif (strpos($item['obfs'], 'tls') !== false) { + $proxy_plugin_opts .= 'obfs=tls'; + } else { + $proxy_plugin_opts .= 'v2ray;' . $item['obfs_param']; + } + if ($item['obfs_param'] != '' && $item['obfs'] != 'v2ray') { + $proxy_plugin_opts .= ';obfs-host=' . $item['obfs_param']; + } + } + $proxy[] = [ + 'remarks' => $item['remark'], + 'server' => $item['address'], + 'server_port' => $item['port'], + 'method' => $item['method'], + 'password' => $item['passwd'], + 'timeout' => 5, + 'plugin' => $proxy_plugin, + 'plugin_opts' => $proxy_plugin_opts + ]; + } + $config = [ + 'configs' => $proxy, + 'strategy' => null, + 'index' => 0, + 'global' => false, + 'enabled' => true, + 'shareOverLan' => false, + 'isDefault' => false, + 'localPort' => 1080, + 'portableMode' => true, + 'pacUrl' => null, + 'useOnlinePac' => false, + 'secureLocalPac' => true, + 'availabilityStatistics' => false, + 'autoCheckUpdate' => true, + 'checkPreRelease' => false, + 'isVerboseLogging' => false, + 'logViewer' => [ + 'topMost' => false, + 'wrapText' => false, + 'toolbarShown' => false, + 'Font' => 'Consolas, 8pt', + 'BackgroundColor' => 'Black', + 'TextColor' => 'White' + ], + 'proxy' => [ + 'useProxy' => false, + 'proxyType' => 0, + 'proxyServer' => '', + 'proxyPort' => 0, + 'proxyTimeout' => 3 + ], + 'hotkey' => [ + 'SwitchSystemProxy' => '', + 'SwitchSystemProxyMode' => '', + 'SwitchAllowLan' => '', + 'ShowLogs' => '', + 'ServerMoveUp' => '', + 'ServerMoveDown' => '', + 'RegHotkeysAtStartup' => false + ] + ]; + + return json_encode($config, JSON_PRETTY_PRINT); + } + public static function getSSRPcConf($user) { $proxy = []; @@ -969,21 +1053,21 @@ class LinkController extends BaseController ); foreach ($items as $item) { $proxy[] = [ - "remarks" => $item['remark'], - "server" => $item['address'], - "server_port" => $item['port'], - "method" => $item['method'], - "obfs" => $item['obfs'], - "obfsparam" => $item['obfs_param'], - "remarks_base64" => base64_encode($item['remark']), - "password" => $item['passwd'], - "tcp_over_udp" => false, - "udp_over_tcp" => false, - "group" => Config::get('appName'), - "protocol" => $item['protocol'], - "protocolparam" => $item['protocol_param'], - "obfs_udp" => false, - "enable" => true + 'remarks' => $item['remark'], + 'server' => $item['address'], + 'server_port' => $item['port'], + 'method' => $item['method'], + 'obfs' => $item['obfs'], + 'obfsparam' => $item['obfs_param'], + 'remarks_base64' => base64_encode($item['remark']), + 'password' => $item['passwd'], + 'tcp_over_udp' => false, + 'udp_over_tcp' => false, + 'group' => Config::get('appName'), + 'protocol' => $item['protocol'], + 'protocolparam' => $item['protocol_param'], + 'obfs_udp' => false, + 'enable' => true ]; } $config = [ @@ -1030,6 +1114,131 @@ class LinkController extends BaseController return json_encode($config, JSON_PRETTY_PRINT); } + public static function getSSDPcConf($user) + { + $id = 1; + $proxy = []; + $items = array_merge( + URL::getAllItems($user, 0, 1, 0), + URL::getAllItems($user, 1, 1, 0) + ); + foreach ($items as $item) { + $proxy_plugin = ''; + $proxy_plugin_opts = ''; + if ($item['obfs'] == 'v2ray' || in_array($item['obfs'], Config::getSupportParam('ss_obfs'))) { + if ($item['obfs'] == 'v2ray') { + $proxy_plugin .= 'v2ray'; + } else { + $proxy_plugin .= 'simple-obfs'; + } + if (strpos($item['obfs'], 'http') !== false) { + $proxy_plugin_opts .= 'obfs=http'; + } elseif (strpos($item['obfs'], 'tls') !== false) { + $proxy_plugin_opts .= 'obfs=tls'; + } else { + $proxy_plugin_opts .= 'v2ray;' . $item['obfs_param']; + } + if ($item['obfs_param'] != '' && $item['obfs'] != 'v2ray') { + $proxy_plugin_opts .= ';obfs-host=' . $item['obfs_param']; + } + } + $proxy[] = [ + 'remarks' => $item['remark'], + 'server' => $item['address'], + 'server_port' => $item['port'], + 'password' => $item['passwd'], + 'method' => $item['method'], + 'plugin' => $proxy_plugin, + 'plugin_opts' => $proxy_plugin_opts, + 'plugin_args' => '', + 'timeout' => 5, + 'id' => $id, + 'ratio' => $item['ratio'], + 'subscription_url' => self::getSubinfo($user, 0)['ssd'] + ]; + $id++; + } + $plugin = ''; + $plugin_opts = ''; + if ($user->obfs == 'v2ray' || in_array($user->obfs, Config::getSupportParam('ss_obfs'))) { + if ($user->obfs == 'v2ray') { + $plugin .= 'v2ray'; + } else { + $plugin .= 'simple-obfs'; + } + if (strpos($user->obfs, 'http') !== false) { + $plugin_opts .= 'obfs=http'; + } elseif (strpos($user->obfs, 'tls') !== false) { + $plugin_opts .= 'obfs=tls'; + } else { + $plugin_opts .= 'v2ray;' . $user->obfs_param; + } + if ($user->obfs_param != '' && $user->obfs != 'v2ray') { + $plugin_opts .= ';obfs-host=' . $user->obfs_param; + } + } + $config = [ + 'configs' => $proxy, + 'strategy' => null, + 'index' => 0, + 'global' => false, + 'enabled' => true, + 'shareOverLan' => false, + 'isDefault' => false, + 'localPort' => 1080, + 'portableMode' => true, + 'pacUrl' => null, + 'useOnlinePac' => false, + 'secureLocalPac' => true, + 'availabilityStatistics' => false, + 'autoCheckUpdate' => true, + 'checkPreRelease' => false, + 'isVerboseLogging' => false, + 'logViewer' => [ + 'topMost' => false, + 'wrapText' => false, + 'toolbarShown' => false, + 'Font' => 'Consolas, 8pt', + 'BackgroundColor' => 'Black', + 'TextColor' => 'White' + ], + 'proxy' => [ + 'useProxy' => false, + 'proxyType' => 0, + 'proxyServer' => '', + 'proxyPort' => 0, + 'proxyTimeout' => 3 + ], + 'hotkey' => [ + 'SwitchSystemProxy' => '', + 'SwitchSystemProxyMode' => '', + 'SwitchAllowLan' => '', + 'ShowLogs' => '', + 'ServerMoveUp' => '', + 'ServerMoveDown' => '', + 'RegHotkeysAtStartup' => false + ], + 'subscriptions' => [ + [ + 'airport' => Config::get('appName'), + 'encryption' => $user->method, + 'password' => $user->passwd, + 'port' => $user->port, + 'expiry' => $user->class_expire, + 'traffic_used' => Tools::flowToGB($user->u + $user->d), + 'traffic_total' => Tools::flowToGB($user->transfer_enable), + 'url' => self::getSubinfo($user, 0)['ssd'], + 'plugin' => $plugin, + 'plugin_options' => $plugin_opts, + 'plugin_arguments' => '', + 'use_proxy' => false + ] + ] + ]; + + return json_encode($config, JSON_PRETTY_PRINT); + } + /** * 通用订阅,ssr & v2rayn * diff --git a/app/Controllers/UserController.php b/app/Controllers/UserController.php index db7316c2..dbfc56a7 100644 --- a/app/Controllers/UserController.php +++ b/app/Controllers/UserController.php @@ -1925,6 +1925,18 @@ class UserController extends BaseController // 客户端文件存放路径 $client_path = '../resources/clients/'; switch ($type) { + case 'ss-win': + $temp_file_path .= $type . '_' . $user_token . '.zip'; + $user_config_file_name = 'gui-config.json'; + $content = LinkController::getSSPcConf($this->user); + $client_path .= $type . '/'; + break; + case 'ssd-win': + $temp_file_path .= $type . '_' . $user_token . '.zip'; + $user_config_file_name = 'gui-config.json'; + $content = LinkController::getSSDPcConf($this->user); + $client_path .= $type . '/'; + break; case 'ssr-win': $temp_file_path .= $type . '_' . $user_token . '.zip'; $user_config_file_name = 'gui-config.json'; diff --git a/app/Utils/URL.php b/app/Utils/URL.php index f1cf0198..4dffb2e7 100644 --- a/app/Utils/URL.php +++ b/app/Utils/URL.php @@ -746,6 +746,10 @@ class URL : $node_name); $return_array['class'] = $node->node_class; $return_array['group'] = Config::get('appName'); + $return_array['ratio'] = ($relay_rule != null + ? $node->traffic_rate + $relay_rule->dist_node()->traffic_rate + : $node->traffic_rate); + return $return_array; } diff --git a/resources/clients/ss-win/使用注意.txt b/resources/clients/ss-win/使用注意.txt new file mode 100644 index 00000000..8574e0ed --- /dev/null +++ b/resources/clients/ss-win/使用注意.txt @@ -0,0 +1,3 @@ +尊敬的用户您好: + + 如您在使用上遇到问题,请注意在我们的网站上查询相关的教程或联系我们。 diff --git a/resources/clients/ssd-win/使用注意.txt b/resources/clients/ssd-win/使用注意.txt new file mode 100644 index 00000000..8574e0ed --- /dev/null +++ b/resources/clients/ssd-win/使用注意.txt @@ -0,0 +1,3 @@ +尊敬的用户您好: + + 如您在使用上遇到问题,请注意在我们的网站上查询相关的教程或联系我们。 diff --git a/resources/clients/ssr-win/使用注意.txt b/resources/clients/ssr-win/使用注意.txt new file mode 100644 index 00000000..8574e0ed --- /dev/null +++ b/resources/clients/ssr-win/使用注意.txt @@ -0,0 +1,3 @@ +尊敬的用户您好: + + 如您在使用上遇到问题,请注意在我们的网站上查询相关的教程或联系我们。