Skip to content

Commit

Permalink
Merge pull request #2169 from sspanel-uim/dev
Browse files Browse the repository at this point in the history
Dev 20230918
  • Loading branch information
M1Screw authored Sep 18, 2023
2 parents 8fdefab + 42868ec commit b192603
Show file tree
Hide file tree
Showing 67 changed files with 548 additions and 413 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@ SSPanel UIM 是一款专为 Shadowsocks / V2Ray / Trojan 协议设计的多用
- 集成 支付宝当面付,Stripe 银行卡,彩虹易支付 等多种支付系统
- 支持多种邮件服务,内置队列功能,无需第三方组件即可使用
- 内置基于 Bootstrap 5 的 tabler 主题,模板引擎支持
- 支持 Shadowsocks 2022,Shadowsocks AEAD,Trojan-Go 等最新代理协议
- 通用订阅接口,一键 json/clash/sip008 格式订阅下发
- 支持 Shadowsocks 2022,TUIC 等最新代理协议
- 通用订阅接口,一键 json/clash/sip008/sing-box 格式订阅下发
- 自定义节点配置,模块化订阅系统,支持多种传统订阅模式
- 重构的商店系统,支持多种计费模式,包括但不限于包年包月,按量计费,接入类型计费等
- 重构的定时任务系统,再也不需要麻烦地配置 crontab,一个命令即可完成所有定时任务
- 重构的定时任务系统,再也不需要麻烦地配置 crontab,一个命令即可完成所有定时任务

## 安装

SSPanel UIM 的需要以下程序才能正常的安装和运行:

- Git
- Nginx(必须使用 HTTPS/HTTPS is REQUIRED)
- PHP 8.1+ (推荐开启 OPcache & JIT /OPcache & JIT is highly recommended)
- MariaDB 10.6+(关闭严格模式,不兼容 MySQL/Disable strict mode, DO NOT USE MYSQL
- PHP 8.1+ (强烈推荐开启 OPcache /OPcache is highly recommended)
- MariaDB 10.6+(关闭严格模式,不兼容 MySQL/Disable strict mode, DO NOT USE MySQL
- Redis 7.0+

我们推荐用户在开始使用之前有一定程度的 PHP 和 Linux 使用知识,能够至少正确识别使用中所出现的问题并在 issue 中提供所需的信息。
Expand Down
2 changes: 1 addition & 1 deletion app/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@
$group->post('/users/aliveip', App\Controllers\WebAPI\UserController::class . ':addAliveIp');
$group->post('/users/detectlog', App\Controllers\WebAPI\UserController::class . ':addDetectLog');
// 审计 & 杂七杂八的功能
$group->get('/func/detect_rules', App\Controllers\WebAPI\FuncController::class . ':getDetectLogs');
$group->get('/func/detect_rules', App\Controllers\WebAPI\FuncController::class . ':getDetectRules');
$group->get('/func/ping', App\Controllers\WebAPI\FuncController::class . ':ping');
})->add(new NodeToken());

Expand Down
12 changes: 6 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions config/appprofile.example.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
'server' => 'dnspod',
],
],
'final' => 'cloudflare',
'strategy' => 'prefer_ipv6',
],
'inbounds' => [
Expand Down
14 changes: 7 additions & 7 deletions resources/views/tabler/admin/index.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
<div class="col-sm-12 col-md-6">
<div class="card">
<div class="card-header">
<h3 class="card-title">{$sts->getTotalUser()} 位用户的签到情况</h3>
<h3 class="card-title">{$total_user} 位用户的签到情况</h3>
</div>
<div class="card-body">
<div id="check-in"></div>
Expand All @@ -119,7 +119,7 @@
<div class="col-sm-12 col-md-6">
<div class="card">
<div class="card-header">
<h3 class="card-title">{$sts->getTotalNodes()} 个服务器的在线情况</h3>
<h3 class="card-title">{$total_node} 个服务器的在线情况</h3>
</div>
<div class="card-body">
<div id="node-online"></div>
Expand Down Expand Up @@ -167,7 +167,7 @@
fill: {
opacity: 1,
},
series: [{$sts->getTotalUser()-$sts->getCheckinUser()}, {$sts->getCheckinUser()-$sts->getTodayCheckinUser()}, {$sts->getTodayCheckinUser()}],
series: [{$total_user-$checkin_user}, {$checkin_user-$today_checkin_user}, {$today_checkin_user}],
labels: ["没有签到", "曾经签到", "今日签到"],
grid: {
strokeDashArray: 3,
Expand Down Expand Up @@ -207,7 +207,7 @@
fill: {
opacity: 1,
},
series: [{$sts->getAliveNodes()}, {$sts->getTotalNodes()-$sts->getAliveNodes()}],
series: [{$alive_node}, {$total_node-$alive_node}],
labels: ["在线", "离线"],
grid: {
strokeDashArray: 2,
Expand Down Expand Up @@ -247,7 +247,7 @@
fill: {
opacity: 1,
},
series: [{$sts->getInactiveUser()}, {$sts->getActiveUser()}],
series: [{$inactive_user}, {$active_user}],
labels: ["闲置账户", "活动账户"],
grid: {
strokeDashArray: 4,
Expand Down Expand Up @@ -287,8 +287,8 @@
fill: {
opacity: 1,
},
series: [{$sts->getRawGbTodayTrafficUsage()}, {$sts->getRawGbLastTrafficUsage()}, {$sts->getRawGbUnusedTrafficUsage()}],
labels: ["今日已用({$sts->getTodayTrafficUsage()})", "过去已用({$sts->getLastTrafficUsage()})", "剩余流量({$sts->getUnusedTrafficUsage()})"],
series: [{$raw_today_traffic}, {$raw_last_traffic}, {$raw_unused_traffic}],
labels: ["今日已用({$today_traffic})", "过去已用({$last_traffic})", "剩余流量({$unused_traffic})"],
grid: {
strokeDashArray: 3,
},
Expand Down
134 changes: 81 additions & 53 deletions src/Command/ClientDownload.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
namespace App\Command;

use App\Services\Cloudflare;
use Exception;
use App\Utils\Tools;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use function file_exists;
use function file_get_contents;
use function file_put_contents;
Expand All @@ -26,19 +27,15 @@
final class ClientDownload extends Command
{
public string $description = '├─=: php xcat ClientDownload - 定时更新客户端' . PHP_EOL;

private $client;

/**
* 保存基本路径
*/
private Client $client;
private string $basePath = BASE_PATH . '/';
private array $version;

/**
* 下载配置
* @return void
*
* @throws GuzzleException
*/
private $version;

public function boot(): void
{
$this->client = new Client();
Expand Down Expand Up @@ -67,6 +64,12 @@ public function boot(): void

/**
* 下载远程文件
*
* @param string $fileName
* @param string $savePath
* @param string $url
*
* @return bool
*/
private function getSourceFile(string $fileName, string $savePath, string $url): bool
{
Expand All @@ -81,14 +84,14 @@ private function getSourceFile(string $fileName, string $savePath, string $url):
echo '- 下载 ' . $fileName . ' 成功,正在保存...' . PHP_EOL;
$result = file_put_contents($savePath . $fileName, $request->getBody()->getContents());

if ($result === false) {
if (! $result) {
echo '- 保存 ' . $fileName . '' . $savePath . ' 失败。' . PHP_EOL;
} else {
echo '- 保存 ' . $fileName . '' . $savePath . ' 成功。' . PHP_EOL;
}

return true;
} catch (Exception $e) {
} catch (GuzzleException $e) {
echo '- 下载 ' . $fileName . ' 失败...' . PHP_EOL;
echo $e->getMessage() . PHP_EOL;

Expand All @@ -98,21 +101,33 @@ private function getSourceFile(string $fileName, string $savePath, string $url):

/**
* 获取 GitHub 常规 Release
*
* @param string $repo
*
* @return string
*
* @throws GuzzleException
*/
private function getLatestReleaseTagName(string $repo): string
{
$url = 'https://api.github.com/repos/' . $repo . '/releases/latest' .
($_ENV['github_access_token'] !== '' ? '?access_token=' . $_ENV['github_access_token'] : '');
$request = $this->client->get($url);

return (string) json_decode(
return json_decode(
$request->getBody()->getContents(),
true
)['tag_name'];
}

/**
* 获取 GitHub Pre-Release
*
* @param string $repo
*
* @return string
*
* @throws GuzzleException
*/
private function getLatestPreReleaseTagName(string $repo): string
{
Expand All @@ -124,15 +139,7 @@ private function getLatestPreReleaseTagName(string $repo): string
true
)[0];

return (string) $latest['tag_name'];
}

/**
* 判断是否 JSON
*/
private function isJson(string $string): bool
{
return json_decode($string, true) !== false;
return $latest['tag_name'];
}

/**
Expand All @@ -147,6 +154,7 @@ private function getLocalVersions(): array

if (! is_file($filePath)) {
echo '本地软体版本库 LocalClientVersion.json 不存在,创建文件中...' . PHP_EOL;

$result = file_put_contents(
$filePath,
json_encode(
Expand All @@ -155,15 +163,16 @@ private function getLocalVersions(): array
]
)
);
if ($result === false) {

if (! $result) {
echo 'LocalClientVersion.json 创建失败,脚本中止。' . PHP_EOL;
exit(0);
}
}

$fileContent = file_get_contents($filePath);

if (! $this->isJson($fileContent)) {
if (! Tools::isJson($fileContent)) {
echo 'LocalClientVersion.json 文件格式异常,脚本中止。' . PHP_EOL;
exit(0);
}
Expand All @@ -173,31 +182,65 @@ private function getLocalVersions(): array

/**
* 储存本地软体版本库
*
* @param array $versions
*
* @return void
*/
private function setLocalVersions(array $versions): void
{
$fileName = 'LocalClientVersion.json';
$filePath = BASE_PATH . '/storage/' . $fileName;
(bool) file_put_contents(

file_put_contents(
$filePath,
json_encode(
$versions
)
);
}

/**
* @param $name
* @param $taskName
* @param $tagName
*
* @return array|string
*/
private static function getNames($name, $taskName, $tagName): array|string
{
return str_replace(
[
'%taskName%',
'%tagName%',
'%tagName1%',
],
[
$taskName,
$tagName,
substr($tagName, 1),
],
$name
);
}

/**
* @param array $task
*
* @return void
*
* @throws GuzzleException
*/
private function getSoft(array $task): void
{
$savePath = $this->basePath . $task['savePath'];
echo '====== ' . $task['name'] . ' 开始 ======' . PHP_EOL;

$tagMethod = match ($task['tagMethod']) {
'github_pre_release' => 'getLatestPreReleaseTagName',
default => 'getLatestReleaseTagName',
$tagName = match ($task['tagMethod']) {
'github_pre_release' => self::getLatestPreReleaseTagName($task['gitRepo']),
default => self::getLatestReleaseTagName($task['gitRepo']),
};

$tagName = $this->$tagMethod($task['gitRepo']);

if (! isset($this->version[$task['name']])) {
echo '- 本地不存在 ' . $task['name'] . ',检测到当前最新版本为 ' . $tagName . PHP_EOL;
} else {
Expand All @@ -211,33 +254,18 @@ private function getSoft(array $task): void
}

$this->version[$task['name']] = $tagName;
$nameFunction = static function ($name) use ($task, $tagName) {
return str_replace(
[
'%taskName%',
'%tagName%',
'%tagName1%',
],
[
$task['name'],
$tagName,
substr($tagName, 1),
],
$name
);
};

foreach ($task['downloads'] as $download) {
$fileName = $nameFunction(($download['saveName'] !== '' ? $download['saveName'] : $download['sourceName']));
$sourceName = $nameFunction($download['sourceName']);
$fileName = $download['saveName'] !== '' ? $download['saveName'] : $download['sourceName'];
$fileName = self::getNames($fileName, $task['name'], $tagName);
$sourceName = self::getNames($download['sourceName'], $task['name'], $tagName);
$filePath = $savePath . $fileName;

if (is_file($filePath)) {
echo '- 正在删除旧版本文件...' . PHP_EOL;
if (! unlink($filePath)) {
echo '- 删除旧版本文件失败,此任务跳过,请检查权限' . PHP_EOL;
continue;
}
echo '- 正在删除旧版本文件...' . PHP_EOL;

if (! unlink($filePath)) {
echo '- 删除旧版本文件失败,此任务跳过,请检查权限' . PHP_EOL;
continue;
}

$downloadUrl = 'https://github.com/' . $task['gitRepo'] .
Expand Down
Loading

0 comments on commit b192603

Please sign in to comment.