diff --git a/app/Controllers/LinkController.php b/app/Controllers/LinkController.php index 67765a97..94b6a95a 100644 --- a/app/Controllers/LinkController.php +++ b/app/Controllers/LinkController.php @@ -10,6 +10,7 @@ use App\Models\Smartline; use App\Utils\ConfRender; use App\Utils\Tools; use App\Utils\URL; +use App\Services\Config; /** * HomeController @@ -194,4 +195,274 @@ class LinkController extends BaseController ); return $render->fetch('clash.tpl'); } + + public static function getSSPcConf($user) + { + $proxy = []; + $items = URL::getAllItems($user, 0, 1); + 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 = []; + $items = URL::getAllItems($user, 0, 0); + 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 + ]; + } + $config = [ + 'configs' => $proxy, + 'index' => 0, + 'random' => true, + 'sysProxyMode' => 1, + 'shareOverLan' => false, + 'localPort' => 1080, + 'localAuthPassword' => Tools::genRandomChar(26), + 'dnsServer' => '', + 'reconnectTimes' => 2, + 'balanceAlgorithm' => 'LowException', + 'randomInGroup' => false, + 'TTL' => 0, + 'connectTimeout' => 5, + 'proxyRuleMode' => 2, + 'proxyEnable' => false, + 'pacDirectGoProxy' => false, + 'proxyType' => 0, + 'proxyHost' => '', + 'proxyPort' => 0, + 'proxyAuthUser' => '', + 'proxyAuthPass' => '', + 'proxyUserAgent' => '', + 'authUser' => '', + 'authPass' => '', + 'autoBan' => false, + 'sameHostForSameTarget' => false, + 'keepVisitTime' => 180, + 'isHideTips' => false, + 'nodeFeedAutoUpdate' => true, + 'serverSubscribes' => [ + [ + 'URL' => (Config::get('subUrl') . self::GenerateSSRSubCode($user->id, 0) . '?mu=0'), + 'Group' => Config::get('appName'), + 'LastUpdateTime' => 0 + ] + ], + 'token' => [], + 'portMap' => [] + ]; + + return json_encode($config, JSON_PRETTY_PRINT); + } + + public static function getSSDPcConf($user) + { + $id = 1; + $proxy = []; + $items = URL::getAllItems($user, 0, 1); + 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' => (Config::get('subUrl') . self::GenerateSSRSubCode($user->id, 0) . '?mu=3') + ]; + $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' => (Config::get('subUrl') . self::GenerateSSRSubCode($user->id, 0) . '?mu=3'), + 'plugin' => $plugin, + 'plugin_options' => $plugin_opts, + 'plugin_arguments' => '', + 'use_proxy' => false + ] + ] + ]; + + return json_encode($config, JSON_PRETTY_PRINT); + } } diff --git a/app/Controllers/UserController.php b/app/Controllers/UserController.php index 1b6ba2d9..00b9e311 100755 --- a/app/Controllers/UserController.php +++ b/app/Controllers/UserController.php @@ -1833,4 +1833,62 @@ class UserController extends BaseController ], $expire_in); return $response->withStatus(302)->withHeader('Location', $local); } + + /** + * 获取包含订阅信息的客户端压缩档 + * + * @param Request $request + * @param Response $response + * @param array $args + */ + public function getPcClient($request, $response, $args) + { + $zipArc = new \ZipArchive(); + $user_token = LinkController::GenerateSSRSubCode($this->user->id, 0); + $type = trim($request->getQueryParams()['type']); + // 临时文件存放路径 + $temp_file_path = '../storage/'; + // 客户端文件存放路径 + $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'; + $content = LinkController::getSSRPcConf($this->user); + $client_path .= $type . '/'; + break; + default: + return 'gg'; + } + // 文件存在则先删除 + if (is_file($temp_file_path)) { + unlink($temp_file_path); + } + // 超链接文件内容 + $site_url_content = '[InternetShortcut]' . PHP_EOL . 'URL=' . Config::get('baseUrl'); + // 创建 zip 并添加内容 + $zipArc->open($temp_file_path, \ZipArchive::CREATE); + $zipArc->addFromString($user_config_file_name, $content); + $zipArc->addFromString('点击访问_' . Config::get('appName') . '.url', $site_url_content); + Tools::folderToZip($client_path, $zipArc, strlen($client_path)); + $zipArc->close(); + + $newResponse = $response->withHeader('Content-type', ' application/octet-stream')->withHeader('Content-Disposition', ' attachment; filename=' . $type . '.zip'); + $newResponse->write(file_get_contents($temp_file_path)); + unlink($temp_file_path); + + return $newResponse; + } } diff --git a/app/Services/Config.php b/app/Services/Config.php index ea319f35..984cb004 100755 --- a/app/Services/Config.php +++ b/app/Services/Config.php @@ -45,7 +45,8 @@ class Config 'enable_kill' => self::get('enable_kill'), 'custom_invite_price' => self::get('custom_invite_price'), 'captcha_provider' => self::get('captcha_provider'), - 'enable_email_verify' => self::get('enable_email_verify') + 'enable_email_verify' => self::get('enable_email_verify'), + 'subscribe_client' => self::get('subscribe_client') ]; } diff --git a/app/Utils/Tools.php b/app/Utils/Tools.php index 1677d0b9..7436e7cd 100644 --- a/app/Utils/Tools.php +++ b/app/Utils/Tools.php @@ -531,4 +531,31 @@ class Tools } return $item; } + + /** + * Add files and sub-directories in a folder to zip file. + * + * @param string $folder + * @param ZipArchive $zipFile + * @param int $exclusiveLength Number of text to be exclusived from the file path. + */ + public static function folderToZip($folder, &$zipFile, $exclusiveLength) + { + $handle = opendir($folder); + while (false !== $f = readdir($handle)) { + if ($f != '.' && $f != '..') { + $filePath = "$folder/$f"; + // Remove prefix from file path before add to zip. + $localPath = substr($filePath, $exclusiveLength); + if (is_file($filePath)) { + $zipFile->addFile($filePath, $localPath); + } elseif (is_dir($filePath)) { + // Add sub-directory. + $zipFile->addEmptyDir($localPath); + self::folderToZip($filePath, $zipFile, $exclusiveLength); + } + } + } + closedir($handle); + } } diff --git a/app/Utils/URL.php b/app/Utils/URL.php index 35af3bbc..cf1c37b3 100644 --- a/app/Utils/URL.php +++ b/app/Utils/URL.php @@ -574,6 +574,9 @@ class URL if ($mu_port != 0 && Config::get('mergeSub') != 'true') { $return_array['group'] .= ' - 单端口'; } + $return_array['ratio'] = ($relay_rule != null + ? $node->traffic_rate + $relay_rule->dist_node()->traffic_rate + : $node->traffic_rate); return $return_array; } diff --git a/config/.config.example.php b/config/.config.example.php index 2339ae7f..97ed59b2 100644 --- a/config/.config.example.php +++ b/config/.config.example.php @@ -284,6 +284,7 @@ $_ENV['db_charset'] = 'utf8'; $_ENV['db_collation'] = 'utf8_general_ci'; $_ENV['db_prefix'] = ''; $_ENV['muKeyList'] = [' ']; //多 key 列表 +$_ENV['subscribe_client'] = 'false'; //下载协议客户端时附带节点和订阅信息 #aws $_ENV['aws_access_key_id'] = ''; diff --git a/config/routes.php b/config/routes.php index 773c9eb5..02f03fb5 100755 --- a/config/routes.php +++ b/config/routes.php @@ -145,6 +145,9 @@ $app->group('/user', function () { // Crypto Payment - BTC, ETH, EOS, BCH, LTC etch $this->post('/payment/bitpay/purchase', App\Services\BitPayment::class . ':purchase'); $this->get('/payment/bitpay/return', App\Services\BitPayment::class . ':returnHTML'); + + // getPcClient + $this->get('/getPcClient', App\Controllers\UserController::class . ':getPcClient'); })->add(new Auth()); $app->group('/payment', function () { diff --git a/resources/clients/README.txt b/resources/clients/README.txt new file mode 100644 index 00000000..ff1c06b2 --- /dev/null +++ b/resources/clients/README.txt @@ -0,0 +1 @@ +请将已解压的客户端存放在对应文件夹中 diff --git a/resources/clients/ss-win/使用注意.txt b/resources/clients/ss-win/使用注意.txt new file mode 100644 index 00000000..b3c8491e --- /dev/null +++ b/resources/clients/ss-win/使用注意.txt @@ -0,0 +1,3 @@ +尊敬的用户您好: + + 如您在使用上遇到问题,请注意在我们的网站上查询相关的教程或联系我们。 \ No newline at end of file diff --git a/resources/clients/ssd-win/使用注意.txt b/resources/clients/ssd-win/使用注意.txt new file mode 100644 index 00000000..b3c8491e --- /dev/null +++ b/resources/clients/ssd-win/使用注意.txt @@ -0,0 +1,3 @@ +尊敬的用户您好: + + 如您在使用上遇到问题,请注意在我们的网站上查询相关的教程或联系我们。 \ No newline at end of file diff --git a/resources/clients/ssr-win/使用注意.txt b/resources/clients/ssr-win/使用注意.txt new file mode 100644 index 00000000..b3c8491e --- /dev/null +++ b/resources/clients/ssr-win/使用注意.txt @@ -0,0 +1,3 @@ +尊敬的用户您好: + + 如您在使用上遇到问题,请注意在我们的网站上查询相关的教程或联系我们。 \ No newline at end of file diff --git a/resources/views/material/user/index.tpl b/resources/views/material/user/index.tpl index c3d792f0..356fa6a9 100644 --- a/resources/views/material/user/index.tpl +++ b/resources/views/material/user/index.tpl @@ -467,7 +467,7 @@ table tr td:first-child {
-

laptop_windows Windows:下载 ShadowsocksRR Windows 或 SSTap

+

laptop_windows Windows:下载 ShadowsocksRR Windows 或 SSTap

laptop_mac macOS:下载 ShadowsocksX-NG-R8

laptop_windows Linux(GUI):下载 Electron SSR

android Android:下载 SSRR 或 SSR

@@ -475,7 +475,7 @@ table tr td:first-child {

router Koolshare 固件路由器/软路由:前往 FancySS 下载页面

-

laptop_windows Windows:下载 SSD Windows,Shadowsocks Windows 或 SSTap

+

laptop_windows Windows:下载 SSD Windows,Shadowsocks Windows 或 SSTap

laptop_mac macOS:下载 ShadowsocksX-NG

laptop_windows Linux(GUI):下载 Electron SSR

android Android:下载 Shadowsocks Android 或 SSD Android。如果需要启用混淆还需要下载 Simple-Obfs 混淆插件。