包含订阅信息的客户端下载方式

Anankke_dev
GeekQu 7 years ago
parent cf4b62966c
commit 2db61fb807

@ -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);
}
}

@ -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;
}
}

@ -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')
];
}

@ -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);
}
}

@ -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;
}

@ -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'] = '';

@ -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 () {

@ -0,0 +1 @@
请将已解压的客户端存放在对应文件夹中

@ -0,0 +1,3 @@
尊敬的用户您好:
如您在使用上遇到问题,请注意在我们的网站上查询相关的教程或联系我们。

@ -0,0 +1,3 @@
尊敬的用户您好:
如您在使用上遇到问题,请注意在我们的网站上查询相关的教程或联系我们。

@ -0,0 +1,3 @@
尊敬的用户您好:
如您在使用上遇到问题,请注意在我们的网站上查询相关的教程或联系我们。

@ -467,7 +467,7 @@ table tr td:first-child {
<div class="card-inner">
<div class="tab-content">
<div class="tab-pane fade {if $ssr_prefer}active in{/if}" id="all_ssr_client">
<p><i class="icon icon-lg">laptop_windows</i> Windows:下载 <a href="/ssr-download/ssr-win.7z" target="_blank">ShadowsocksRR Windows</a> 或 <a href="/ssr-download/SSTap.7z" target="_blank">SSTap</a></p>
<p><i class="icon icon-lg">laptop_windows</i> Windows:下载 <a href="{if $config['subscribe_client']!='true'}/ssr-download/ssr-win.7z{else}/user/getPcClient?type=ssr-win{/if}" target="_blank">ShadowsocksRR Windows</a> 或 <a href="/ssr-download/SSTap.7z" target="_blank">SSTap</a></p>
<p><i class="icon icon-lg">laptop_mac</i> macOS:<a href="/ssr-download/ssr-mac.dmg" target="_blank">下载 ShadowsocksX-NG-R8</a></p>
<p><i class="icon icon-lg">laptop_windows</i> Linux(GUI):<a href="/ssr-download/ssr-linux.AppImage" target="_blank">下载 Electron SSR</a></p>
<p><i class="icon icon-lg">android</i> Android:下载 <a href="/ssr-download/ssrr-android.apk">SSRR</a> 或 <a href="/ssr-download/ssr-android.apk">SSR</a></p>
@ -475,7 +475,7 @@ table tr td:first-child {
<p><i class="icon icon-lg">router</i> Koolshare 固件路由器/软路由:前往 <a href="https://github.com/hq450/fancyss_history_package" target="_blank">FancySS 下载页面</a></p>
</div>
<div class="tab-pane fade {if !$ssr_prefer}active in{/if}" id="all_ss_client">
<p><i class="icon icon-lg">laptop_windows</i> Windows:下载 <a href="/ssr-download/ssd-win.7z" target="_blank">SSD Windows</a>,<a href="/ssr-download/ss-win.zip" target="_blank">Shadowsocks Windows</a> 或 <a href="/ssr-download/SSTap.7z" target="_blank">SSTap</a></p>
<p><i class="icon icon-lg">laptop_windows</i> Windows:下载 <a href="{if $config['subscribe_client']!='true'}/ssr-download/ssd-win.7z{else}/user/getPcClient?type=ssd-win{/if}" target="_blank">SSD Windows</a>,<a href="{if $config['subscribe_client']!='true'}/ssr-download/ss-win.zip{else}/user/getPcClient?type=ss-win{/if}" target="_blank">Shadowsocks Windows</a> 或 <a href="/ssr-download/SSTap.7z" target="_blank">SSTap</a></p>
<p><i class="icon icon-lg">laptop_mac</i> macOS:<a href="/ssr-download/ss-mac.zip" target="_blank">下载 ShadowsocksX-NG</a></p>
<p><i class="icon icon-lg">laptop_windows</i> Linux(GUI):<a href="/ssr-download/ssr-linux.AppImage" target="_blank">下载 Electron SSR</a></p>
<p><i class="icon icon-lg">android</i> Android:下载 <a href="/ssr-download/ss-android.apk">Shadowsocks Android</a> 或 <a href="/ssr-download/ssd-android.apk">SSD Android</a>。如果需要启用混淆还需要下载 <a href="/ssr-download/ss-android-obfs.apk">Simple-Obfs 混淆插件</a>。</p>

Loading…
Cancel
Save