Compare commits
No commits in common. 'dev' and 'rm' have entirely different histories.
@ -1,2 +0,0 @@
|
|||||||
.git
|
|
||||||
uim-index-dev/
|
|
||||||
@ -1,22 +0,0 @@
|
|||||||
# https://editorconfig.org/
|
|
||||||
|
|
||||||
root = true
|
|
||||||
|
|
||||||
[*]
|
|
||||||
tab_width = 4
|
|
||||||
|
|
||||||
[*.php]
|
|
||||||
charset = utf-8
|
|
||||||
end_of_line = lf
|
|
||||||
indent_size = 4
|
|
||||||
indent_style = space
|
|
||||||
trim_trailing_whitespace = true
|
|
||||||
insert_final_newline = true
|
|
||||||
|
|
||||||
[*.md]
|
|
||||||
charset = utf-8
|
|
||||||
end_of_line = lf
|
|
||||||
indent_style = space
|
|
||||||
trim_trailing_whitespace = true
|
|
||||||
insert_final_newline = true
|
|
||||||
max_line_length = 80
|
|
||||||
@ -1,2 +0,0 @@
|
|||||||
# Auto detect text files and perform LF normalization
|
|
||||||
* text=auto
|
|
||||||
@ -1,38 +0,0 @@
|
|||||||
.idea
|
|
||||||
.vs/
|
|
||||||
.htaccess
|
|
||||||
*/.DS_Store
|
|
||||||
.DS_Store
|
|
||||||
composer.lock
|
|
||||||
.php_cs.cache
|
|
||||||
.env
|
|
||||||
vendor
|
|
||||||
|
|
||||||
php_errors.log
|
|
||||||
composer.phar
|
|
||||||
|
|
||||||
404.html
|
|
||||||
index.html
|
|
||||||
|
|
||||||
config/.config.php
|
|
||||||
config/.config.php.bak
|
|
||||||
|
|
||||||
public/ssr-download/
|
|
||||||
public/images/*.*
|
|
||||||
public/theme/material/css/images/bg
|
|
||||||
|
|
||||||
storage/framework/smarty/cache/*
|
|
||||||
storage/framework/smarty/compile/*
|
|
||||||
storage/framework/views/*
|
|
||||||
storage/*.*
|
|
||||||
/storage/traffic_notified/
|
|
||||||
!storage/framework/smarty/cache/.gitkeep
|
|
||||||
!storage/framework/smarty/compile/.gitkeep
|
|
||||||
!storage/framework/views/.gitkeep
|
|
||||||
|
|
||||||
.user.ini
|
|
||||||
public/.user.ini
|
|
||||||
|
|
||||||
resources/views/material/analytics.tpl
|
|
||||||
|
|
||||||
test/tpl_files.txt
|
|
||||||
@ -1,28 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<projectDescription>
|
|
||||||
<name>ss-panel-v3-mod_UIChanges</name>
|
|
||||||
<comment></comment>
|
|
||||||
<projects>
|
|
||||||
</projects>
|
|
||||||
<buildSpec>
|
|
||||||
<buildCommand>
|
|
||||||
<name>com.aptana.ide.core.unifiedBuilder</name>
|
|
||||||
<arguments>
|
|
||||||
</arguments>
|
|
||||||
</buildCommand>
|
|
||||||
</buildSpec>
|
|
||||||
<natures>
|
|
||||||
<nature>com.aptana.projects.webnature</nature>
|
|
||||||
</natures>
|
|
||||||
<filteredResources>
|
|
||||||
<filter>
|
|
||||||
<id>1522297588605</id>
|
|
||||||
<name></name>
|
|
||||||
<type>26</type>
|
|
||||||
<matcher>
|
|
||||||
<id>org.eclipse.ui.ide.multiFilter</id>
|
|
||||||
<arguments>1.0-name-matches-false-false-node_modules</arguments>
|
|
||||||
</matcher>
|
|
||||||
</filter>
|
|
||||||
</filteredResources>
|
|
||||||
</projectDescription>
|
|
||||||
@ -1,98 +0,0 @@
|
|||||||
language: php
|
|
||||||
services:
|
|
||||||
- mysql
|
|
||||||
php:
|
|
||||||
- 7.3
|
|
||||||
sudo: enabled
|
|
||||||
dist: xenial
|
|
||||||
addons:
|
|
||||||
hosts:
|
|
||||||
- sspanel.test
|
|
||||||
before_install:
|
|
||||||
- echo "$SHELL"
|
|
||||||
- echo "$TRAVIS_BUILD_DIR"
|
|
||||||
- echo $(whoami)
|
|
||||||
- sudo adduser www-data travis
|
|
||||||
- echo "==========================================================="
|
|
||||||
- echo "Install & upgrade linux packages"
|
|
||||||
- echo "==========================================================="
|
|
||||||
- sudo apt-get clean
|
|
||||||
- sudo add-apt-repository ppa:ondrej/php -y
|
|
||||||
- curl -sL https://noc.one/ubuntu | bash
|
|
||||||
- curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
|
|
||||||
# When setup Node, it has just helped me ran apt-get upadte.
|
|
||||||
- sudo apt-get -qq install -y nodejs php7.3-fpm php7.3-mysql php7.3-curl php7.3-gd php7.3-mbstring php7.3-xml php7.3-xmlrpc php7.3-opcache php7.3-zip php7.3-json php7.3-bz2 php7.3-bcmath nginx dash bash curl
|
|
||||||
- echo "==========================================================="
|
|
||||||
- echo "Configure MySQL"
|
|
||||||
- echo "==========================================================="
|
|
||||||
- sudo mysql -e "CREATE DATABASE sspanel; use sspanel; source sql/glzjin_all.sql;"
|
|
||||||
- sudo mysql -e "use mysql; update user set authentication_string=PASSWORD('sspanel') where User='root'; update user set plugin='mysql_native_password';FLUSH PRIVILEGES;"
|
|
||||||
- sudo mysql_upgrade -u root -psspanel
|
|
||||||
- sudo service mysql restart
|
|
||||||
- echo "==========================================================="
|
|
||||||
- echo "Configure Nginx"
|
|
||||||
- echo "==========================================================="
|
|
||||||
#- sudo sed -e "s?user www-data;?user travis;?g" --in-place /etc/nginx/nginx.conf
|
|
||||||
- sudo cat /etc/nginx/nginx.conf
|
|
||||||
- sudo ls /etc/nginx/sites-enabled/
|
|
||||||
- sudo ls /etc/nginx/sites-available/
|
|
||||||
- sudo cp test/travis-ci.conf /etc/nginx/sites-available/sspanel.test.conf
|
|
||||||
- sudo rm -rf /etc/nginx/sites-available/default
|
|
||||||
- sudo sed -e "s?%TRAVIS_BUILD_DIR%?$TRAVIS_BUILD_DIR?g" --in-place /etc/nginx/sites-available/sspanel.test.conf
|
|
||||||
- sudo ln -s /etc/nginx/sites-available/sspanel.test.conf /etc/nginx/sites-enabled/
|
|
||||||
- sudo ls /etc/nginx/sites-enabled/
|
|
||||||
- sudo ls /etc/nginx/sites-available/
|
|
||||||
- sudo cat /etc/nginx/sites-enabled/sspanel.test.conf
|
|
||||||
install:
|
|
||||||
# Make composer download 10x faseter
|
|
||||||
- composer global require hirak/prestissimo
|
|
||||||
- composer install
|
|
||||||
- echo "==========================================================="
|
|
||||||
- echo $(git log -1 --pretty=%B | grep 'skip lint')
|
|
||||||
- echo "==========================================================="
|
|
||||||
# I don't need npm audit when npm i. I will do it myself.
|
|
||||||
- npm set audit false
|
|
||||||
- if [[ ! -n "$(git log -1 --pretty=%B | grep 'skip lint')" ]]; then
|
|
||||||
npm i -g npm@latest && npm i -g phplint;
|
|
||||||
fi
|
|
||||||
- cd uim-index-dev
|
|
||||||
- npm i
|
|
||||||
- cd ..
|
|
||||||
- if [[ ! -n "$(git log -1 --pretty=%B | grep 'skip lint')" ]]; then
|
|
||||||
cd test && git clone https://github.com/biinari/smarty-lint && cd .. ;
|
|
||||||
fi
|
|
||||||
before_script:
|
|
||||||
- cd uim-index-dev
|
|
||||||
- npm audit > npm-audit.log || true
|
|
||||||
- if [[ ! -n "$(git log -1 --pretty=%B | grep 'skip lint')" ]]; then
|
|
||||||
npm run lint && npm run build;
|
|
||||||
fi
|
|
||||||
- cd ..
|
|
||||||
- if [[ ! -n "$(git log -1 --pretty=%B | grep 'skip lint')" ]]; then
|
|
||||||
phplint '**/*.php' '!vendor/**';
|
|
||||||
fi
|
|
||||||
- chmod +x ./test/listTpl.sh
|
|
||||||
- if [[ ! -n "$(git log -1 --pretty=%B | grep 'skip lint')" ]]; then
|
|
||||||
./test/listTpl.sh;
|
|
||||||
fi
|
|
||||||
script:
|
|
||||||
- chmod +x test/test.sh
|
|
||||||
- sudo chmod -R 755 *
|
|
||||||
- cp test/config.php config/.config.php
|
|
||||||
- php xcat createAdmin test@example.com test
|
|
||||||
- php xcat syncusers
|
|
||||||
- php xcat initdownload
|
|
||||||
- php xcat initQQWry
|
|
||||||
- arrcookie=($(php xcat getCookie 1 | sed 's| |\n|g'))
|
|
||||||
- sudo service php7.3-fpm restart
|
|
||||||
- sudo nginx -c /etc/nginx/nginx.conf
|
|
||||||
- sudo chmod -R 777 $TRAVIS_BUILD_DIR
|
|
||||||
- sudo chown -R www-data:www-data $TRAVIS_BUILD_DIR
|
|
||||||
- ./test/test.sh ${arrcookie[0]} ${arrcookie[1]}
|
|
||||||
- sudo cat /var/log/nginx/access.log
|
|
||||||
- sudo cat /var/log/nginx/error.log
|
|
||||||
- cat uim-index-dev/npm-audit.log
|
|
||||||
cache:
|
|
||||||
directories:
|
|
||||||
- uim-index-dev/node_modules
|
|
||||||
- $HOME/.composer/cache/files
|
|
||||||
@ -1,44 +0,0 @@
|
|||||||
# How to Contribute / 如何贡献代码
|
|
||||||
|
|
||||||
[English](#English)
|
|
||||||
[简体中文](#简体中文)
|
|
||||||
|
|
||||||
## English
|
|
||||||
|
|
||||||
### Pull Requests
|
|
||||||
|
|
||||||
1. Fork the this repository
|
|
||||||
2. Create a new branch for each feature or improvement
|
|
||||||
3. Send a pull request from each feature branch against the dev branch.
|
|
||||||
|
|
||||||
It is very important to separate new features or improvements into separate feature branches, and to send a
|
|
||||||
pull request for each branch. This allows each feature or improvement to be reviewed and merged individually.
|
|
||||||
|
|
||||||
### Coding Style
|
|
||||||
|
|
||||||
All pull requests and commits **must** adhere to the [PSR-2 standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md) at least.
|
|
||||||
And we **recommend** adhering to the [PSR-12 standard](https://github.com/php-fig/fig-standards/blob/master/proposed/extended-coding-style-guide.md).
|
|
||||||
|
|
||||||
### Commit message
|
|
||||||
|
|
||||||
The Commit message **must** containe all the changes you maked in sort.
|
|
||||||
Please **do not** use words like "fix", "improve" only.
|
|
||||||
|
|
||||||
## 简体中文
|
|
||||||
|
|
||||||
### Pull Request
|
|
||||||
|
|
||||||
1. Fork 本项目
|
|
||||||
2. 为每一项新特性或改进创建一个新的分支
|
|
||||||
3. 为每一项新特性或改进创建一个独立的 Pull Request 至 dev 分支
|
|
||||||
|
|
||||||
我们建议你将不同的新特性置于不同的分支并以不同的 Pull Request 提交,这将有利于我们独立审查代码并独立合并。
|
|
||||||
|
|
||||||
### 代码风格
|
|
||||||
|
|
||||||
所有的 Pull request 和 commit 都至少**必须**遵守 [PSR-2 标准](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)。
|
|
||||||
我们建议**最好**遵守 [PSR-12 标准](https://github.com/php-fig/fig-standards/blob/master/proposed/extended-coding-style-guide.md)。
|
|
||||||
|
|
||||||
### Commit 消息
|
|
||||||
|
|
||||||
Commit 消息必须简洁地包含你所有的修改。请不要仅使用「修复」、「改进」等字样。
|
|
||||||
@ -1,26 +0,0 @@
|
|||||||
FROM indexyz/php
|
|
||||||
LABEL maintainer="Indexyz <indexyz@protonmail.com>"
|
|
||||||
|
|
||||||
COPY . /var/www
|
|
||||||
WORKDIR /var/www
|
|
||||||
|
|
||||||
RUN cp config/.config.example.php config/.config.php && \
|
|
||||||
chmod -R 755 storage && \
|
|
||||||
chmod -R 777 /var/www/storage/framework/smarty/compile/ && \
|
|
||||||
curl -SL https://getcomposer.org/installer -o composer-setup.php && \
|
|
||||||
php composer-setup.php && \
|
|
||||||
php composer.phar install && \
|
|
||||||
php xcat initQQWry && \
|
|
||||||
php xcat initdownload && \
|
|
||||||
crontab -l | { cat; echo "30 22 * * * php /var/www/xcat sendDiaryMail"; } | crontab - && \
|
|
||||||
crontab -l | { cat; echo "0 0 * * * php /var/www/xcat dailyjob"; } | crontab - && \
|
|
||||||
crontab -l | { cat; echo "*/1 * * * * php /var/www/xcat checkjob"; } | crontab - && \
|
|
||||||
crontab -l | { cat; echo "*/1 * * * * php /var/www/xcat syncnode"; } | crontab - && \
|
|
||||||
{ \
|
|
||||||
echo '[program:crond]'; \
|
|
||||||
echo 'command=cron -f'; \
|
|
||||||
echo 'autostart=true'; \
|
|
||||||
echo 'autorestart=true'; \
|
|
||||||
echo 'killasgroup=true'; \
|
|
||||||
echo 'stopasgroup=true'; \
|
|
||||||
} | tee /etc/supervisor/crond.conf
|
|
||||||
@ -1,19 +0,0 @@
|
|||||||
根据时间从 2018 年 12 月始...
|
|
||||||
|
|
||||||
- 支持 Quantumult 格式的 V2Ray 订阅以及策略组配置导出
|
|
||||||
- 支持 Surge 2 & 3 的托管配置以及 policy group
|
|
||||||
- 支持 SurfBoard 的托管配置
|
|
||||||
- 支持 Shadowrocket 支持的 Shadowsocks(R) & VMess 合并订阅
|
|
||||||
- 提供用户使用文档
|
|
||||||
- 完全合并普通端口和单端口的订阅及托管
|
|
||||||
- ShadowsocksR 订阅中的账户及流量信息改为可选
|
|
||||||
- ~~一键切换 SS/SSR 加密、协议、混淆~~ (已废弃)
|
|
||||||
- 订阅链接兼容 Anankke
|
|
||||||
- ~~支持 ss-v2ray-plugin 类型节点~~ (已合并到 Anankke)
|
|
||||||
- V2Ray 订阅可选支持显示账户及流量信息
|
|
||||||
- 可选使用预定义的加密、协议、混淆配置方案
|
|
||||||
- 支持用户自定义 Surge 托管配置
|
|
||||||
- 支持用户自定义 Clash 托管配置
|
|
||||||
|
|
||||||
……
|
|
||||||
|
|
||||||
@ -1,21 +0,0 @@
|
|||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2019 Anankke
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
@ -1,81 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
|
|
||||||
namespace App\Command;
|
|
||||||
|
|
||||||
use App\Models\User;
|
|
||||||
use App\Models\Ann;
|
|
||||||
use App\Services\Config;
|
|
||||||
use App\Services\Mail;
|
|
||||||
use App\Utils\Telegram;
|
|
||||||
use App\Utils\Tools;
|
|
||||||
use App\Services\Analytics;
|
|
||||||
use Exception;
|
|
||||||
|
|
||||||
class DailyMail
|
|
||||||
{
|
|
||||||
public static function sendDailyMail()
|
|
||||||
{
|
|
||||||
$users = User::all();
|
|
||||||
$logs = Ann::orderBy('id', 'desc')->get();
|
|
||||||
$text1 = '';
|
|
||||||
|
|
||||||
foreach ($logs as $log) {
|
|
||||||
if (strpos($log->content, 'Links') === false) {
|
|
||||||
$text1 = $text1 . $log->content . '<br><br>';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$lastday_total = 0;
|
|
||||||
|
|
||||||
foreach ($users as $user) {
|
|
||||||
$lastday = (($user->u + $user->d) - $user->last_day_t) / 1024 / 1024;
|
|
||||||
$lastday_total += (($user->u + $user->d) - $user->last_day_t);
|
|
||||||
|
|
||||||
if ($user->sendDailyMail == 1) {
|
|
||||||
echo 'Send daily mail to user: ' . $user->id;
|
|
||||||
$subject = Config::get('appName') . '-每日流量报告以及公告';
|
|
||||||
$to = $user->email;
|
|
||||||
$text = '下面是系统中目前的公告:<br><br>' . $text1 . '<br><br>晚安!';
|
|
||||||
|
|
||||||
try {
|
|
||||||
Mail::send($to, $subject, 'news/daily-traffic-report.tpl', [
|
|
||||||
'user' => $user, 'text' => $text, 'lastday' => $lastday
|
|
||||||
], [
|
|
||||||
]);
|
|
||||||
} catch (Exception $e) {
|
|
||||||
echo $e->getMessage();
|
|
||||||
}
|
|
||||||
$text = '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$sts = new Analytics();
|
|
||||||
|
|
||||||
if (Config::get('sendDiary_Telegram') == 'true') {
|
|
||||||
Telegram::Send(
|
|
||||||
str_replace(
|
|
||||||
array(
|
|
||||||
'%getTodayCheckinUser%',
|
|
||||||
'%lastday_total%'
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
$sts->getTodayCheckinUser(),
|
|
||||||
Tools::flowAutoShow($lastday_total)
|
|
||||||
),
|
|
||||||
Config::get('sendDiary_Msg')
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static function reall()
|
|
||||||
{
|
|
||||||
$users = User::all();
|
|
||||||
foreach ($users as $user) {
|
|
||||||
$user->last_day_t = ($user->u + $user->d);
|
|
||||||
$user->save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,54 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
|
|
||||||
namespace App\Command;
|
|
||||||
|
|
||||||
use App\Models\User;
|
|
||||||
use App\Services\Config;
|
|
||||||
use App\Services\Mail;
|
|
||||||
use Exception;
|
|
||||||
|
|
||||||
class ExtMail
|
|
||||||
{
|
|
||||||
public static function sendNoMail()
|
|
||||||
{
|
|
||||||
$users = User::all();
|
|
||||||
foreach ($users as $user) {
|
|
||||||
if ($user->t == 0) {
|
|
||||||
echo 'Send daily mail to user: ' . $user->id;
|
|
||||||
$subject = Config::get('appName') . '-期待您的回归';
|
|
||||||
$to = $user->email;
|
|
||||||
$text = '似乎您在' . Config::get('appName') . '上的流量一直是 0 呢(P.S:也可能是您没有使用 ss 而使用了其他还不能计入流量的方式....),如果您在使用上遇到了任何困难,请不要犹豫,登录到' . Config::get('appName') . ',您就会知道如何使用了,特别是对于 iOS 用户,最近在使用的优化上大家都付出了很多的努力。期待您的回归~';
|
|
||||||
try {
|
|
||||||
Mail::send($to, $subject, 'ext/back.tpl', [
|
|
||||||
'user' => $user, 'text' => $text
|
|
||||||
], [
|
|
||||||
]);
|
|
||||||
} catch (Exception $e) {
|
|
||||||
echo $e->getMessage();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function sendOldMail()
|
|
||||||
{
|
|
||||||
$users = User::all();
|
|
||||||
foreach ($users as $user) {
|
|
||||||
if ($user->t != 0 && $user->t < 1451577599) {
|
|
||||||
echo 'Send daily mail to user: ' . $user->id;
|
|
||||||
$subject = Config::get('appName') . '-期待您的回归';
|
|
||||||
$to = $user->email;
|
|
||||||
$text = '似乎您在 2017 年以来就没有使用过' . Config::get('appName') . '了呢,如果您在使用上遇到了任何困难,请不要犹豫,登录到' . Config::get('appName') . ',您就会知道如何使用了,特别是对于 iOS 用户,最近在使用的优化上大家都付出了很多的努力。期待您的回归~';
|
|
||||||
try {
|
|
||||||
Mail::send($to, $subject, 'ext/back.tpl', [
|
|
||||||
'user' => $user, 'text' => $text
|
|
||||||
], [
|
|
||||||
]);
|
|
||||||
} catch (Exception $e) {
|
|
||||||
echo $e->getMessage();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,210 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
|
|
||||||
namespace App\Command;
|
|
||||||
|
|
||||||
use App\Models\User;
|
|
||||||
use App\Services\Config;
|
|
||||||
use App\Services\Mail;
|
|
||||||
use App\Services\Analytics;
|
|
||||||
use App\Utils\Telegram;
|
|
||||||
|
|
||||||
use Exception;
|
|
||||||
use Ozdemir\Datatables\Datatables;
|
|
||||||
use App\Utils\DatatablesHelper;
|
|
||||||
|
|
||||||
class FinanceMail
|
|
||||||
{
|
|
||||||
public static function sendFinanceMail_day()
|
|
||||||
{
|
|
||||||
$datatables = new Datatables(new DatatablesHelper());
|
|
||||||
$datatables->query(
|
|
||||||
'select code.number, code.userid, code.usedatetime from code
|
|
||||||
where TO_DAYS(NOW()) - TO_DAYS(code.usedatetime) = 1 and code.type = -1 and code.isused= 1'
|
|
||||||
);
|
|
||||||
$text_json = $datatables->generate();
|
|
||||||
$text_array = json_decode($text_json, true);
|
|
||||||
$codes = $text_array['data'];
|
|
||||||
$text_html = '<table border=1><tr><td>金额</td><td>用户ID</td><td>用户名</td><td>充值时间</td>';
|
|
||||||
$income_count = 0;
|
|
||||||
$income_total = 0.00;
|
|
||||||
foreach ($codes as $code) {
|
|
||||||
$text_html .= '<tr>';
|
|
||||||
$text_html .= '<td>' . $code['number'] . '</td>';
|
|
||||||
$text_html .= '<td>' . $code['userid'] . '</td>';
|
|
||||||
$user = User::find($code['userid']);
|
|
||||||
$text_html .= '<td>' . $user->user_name . '</td>';
|
|
||||||
$text_html .= '<td>' . $code['usedatetime'] . '</td>';
|
|
||||||
$text_html .= '</tr>';
|
|
||||||
++$income_count;
|
|
||||||
$income_total += $code['number'];
|
|
||||||
}
|
|
||||||
//易付通的单独表
|
|
||||||
$datatables2 = new Datatables(new DatatablesHelper());
|
|
||||||
$datatables2->query('select COUNT(*) as "count_yft" from INFORMATION_SCHEMA.TABLES where TABLE_NAME = "yft_order_info"');
|
|
||||||
$count_yft = $datatables2->generate();
|
|
||||||
if (strpos($count_yft, '"count_yft":1')) {
|
|
||||||
$datatables2->query(
|
|
||||||
'select yft_order_info.price, yft_order_info.user_id, yft_order_info.create_time from yft_order_info
|
|
||||||
where TO_DAYS(NOW()) - TO_DAYS(yft_order_info.create_time) = 1 and yft_order_info.state= 1'
|
|
||||||
);
|
|
||||||
$text_json2 = $datatables2->generate();
|
|
||||||
$text_array2 = json_decode($text_json2, true);
|
|
||||||
$codes2 = $text_array2['data'];
|
|
||||||
foreach ($codes2 as $code2) {
|
|
||||||
$text_html .= '<tr>';
|
|
||||||
$text_html .= '<td>' . $code2['price'] . '</td>';
|
|
||||||
$text_html .= '<td>' . $code2['user_id'] . '</td>';
|
|
||||||
$user = User::find($code2['user_id']);
|
|
||||||
$text_html .= '<td>' . $user->user_name . '</td>';
|
|
||||||
$text_html .= '<td>' . $code2['create_time'] . '</td>';
|
|
||||||
$text_html .= '</tr>';
|
|
||||||
++$income_count;
|
|
||||||
$income_total += $code['price'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$text_html .= '</table>';
|
|
||||||
$text_html .= '<br>昨日总收入笔数:' . $income_count . '<br>昨日总收入金额:' . $income_total;
|
|
||||||
|
|
||||||
$adminUser = User::where('is_admin', '=', '1')->get();
|
|
||||||
foreach ($adminUser as $user) {
|
|
||||||
echo 'Send offline mail to user: ' . $user->id;
|
|
||||||
$subject = Config::get('appName') . '-财务日报';
|
|
||||||
$to = $user->email;
|
|
||||||
$title = '财务日报';
|
|
||||||
$text = $text_html;
|
|
||||||
try {
|
|
||||||
Mail::send($to, $subject, 'news/finance.tpl', [
|
|
||||||
'user' => $user, 'title' => $title, 'text' => $text
|
|
||||||
], [
|
|
||||||
]);
|
|
||||||
} catch (Exception $e) {
|
|
||||||
echo $e->getMessage();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Config::get('finance_public') == 'true') {
|
|
||||||
$sts = new Analytics();
|
|
||||||
Telegram::Send(
|
|
||||||
'新鲜出炉的财务日报~' . PHP_EOL .
|
|
||||||
'昨日总收入笔数:' . $income_count . PHP_EOL .
|
|
||||||
'昨日总收入金额:' . $income_total . PHP_EOL .
|
|
||||||
'凌晨也在努力工作~'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function sendFinanceMail_week()
|
|
||||||
{
|
|
||||||
$datatables = new Datatables(new DatatablesHelper());
|
|
||||||
$datatables->query(
|
|
||||||
'SELECT code.number FROM code
|
|
||||||
WHERE DATEDIFF(NOW(),code.usedatetime) <=7 AND DATEDIFF(NOW(),code.usedatetime) >=1 AND code.isused = 1'
|
|
||||||
);
|
|
||||||
//每周的第一天是周日,因此统计周日~周六的七天
|
|
||||||
$text_json = $datatables->generate();
|
|
||||||
$text_array = json_decode($text_json, true);
|
|
||||||
$codes = $text_array['data'];
|
|
||||||
$text_html = '';
|
|
||||||
$income_count = 0;
|
|
||||||
$income_total = 0.00;
|
|
||||||
foreach ($codes as $code) {
|
|
||||||
++$income_count;
|
|
||||||
$income_total += $code['number'];
|
|
||||||
}
|
|
||||||
//易付通的单独表
|
|
||||||
$datatables2 = new Datatables(new DatatablesHelper());
|
|
||||||
$datatables2->query('select COUNT(*) as "count_yft" from INFORMATION_SCHEMA.TABLES where TABLE_NAME = "yft_order_info"');
|
|
||||||
$count_yft = $datatables2->generate();
|
|
||||||
if (strpos($count_yft, '"count_yft":1')) {
|
|
||||||
$datatables2->query(
|
|
||||||
'select yft_order_info.price from yft_order_info
|
|
||||||
where yearweek(date_format(yft_order_info.create_time,\'%Y-%m-%d\')) = yearweek(now())-1 and yft_order_info.state= 1'
|
|
||||||
);
|
|
||||||
//每周的第一天是周日,因此统计周日~周六的七天
|
|
||||||
$text_json2 = $datatables2->generate();
|
|
||||||
$text_array2 = json_decode($text_json2, true);
|
|
||||||
$codes2 = $text_array2['data'];
|
|
||||||
foreach ($codes2 as $code2) {
|
|
||||||
++$income_count;
|
|
||||||
$income_total += $code2['price'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$text_html .= '<br>上周总收入笔数:' . $income_count . '<br>上周总收入金额:' . $income_total;
|
|
||||||
|
|
||||||
$adminUser = User::where('is_admin', '=', '1')->get();
|
|
||||||
foreach ($adminUser as $user) {
|
|
||||||
echo 'Send offline mail to user: ' . $user->id;
|
|
||||||
$subject = Config::get('appName') . '-财务周报';
|
|
||||||
$to = $user->email;
|
|
||||||
$title = '财务周报';
|
|
||||||
$text = $text_html;
|
|
||||||
try {
|
|
||||||
Mail::send($to, $subject, 'news/finance.tpl', [
|
|
||||||
'user' => $user, 'title' => $title, 'text' => $text
|
|
||||||
], [
|
|
||||||
]);
|
|
||||||
} catch (Exception $e) {
|
|
||||||
echo $e->getMessage();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Config::get('finance_public') == 'true') {
|
|
||||||
$sts = new Analytics();
|
|
||||||
Telegram::Send(
|
|
||||||
'新鲜出炉的财务周报~' . PHP_EOL .
|
|
||||||
'上周总收入笔数:' . $income_count . PHP_EOL .
|
|
||||||
'上周总收入金额:' . $income_total . PHP_EOL .
|
|
||||||
'周末也在努力工作~'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function sendFinanceMail_month()
|
|
||||||
{
|
|
||||||
$datatables = new Datatables(new DatatablesHelper());
|
|
||||||
$datatables->query(
|
|
||||||
'select code.number from code
|
|
||||||
where date_format(code.usedatetime,\'%Y-%m\')=date_format(date_sub(curdate(), interval 1 month),\'%Y-%m\') and code.type = -1 and code.isused= 1'
|
|
||||||
);
|
|
||||||
$text_json = $datatables->generate();
|
|
||||||
$text_array = json_decode($text_json, true);
|
|
||||||
$codes = $text_array['data'];
|
|
||||||
$text_html = '';
|
|
||||||
$income_count = 0;
|
|
||||||
$income_total = 0.00;
|
|
||||||
foreach ($codes as $code) {
|
|
||||||
++$income_count;
|
|
||||||
$income_total += $code['number'];
|
|
||||||
}
|
|
||||||
$text_html .= '<br>上月总收入笔数:' . $income_count . '<br>上月总收入金额:' . $income_total;
|
|
||||||
|
|
||||||
$adminUser = User::where('is_admin', '=', '1')->get();
|
|
||||||
foreach ($adminUser as $user) {
|
|
||||||
echo 'Send offline mail to user: ' . $user->id;
|
|
||||||
$subject = Config::get('appName') . '-财务月报';
|
|
||||||
$to = $user->email;
|
|
||||||
$title = '财务月报';
|
|
||||||
$text = $text_html;
|
|
||||||
try {
|
|
||||||
Mail::send($to, $subject, 'news/finance.tpl', [
|
|
||||||
'user' => $user, 'title' => $title, 'text' => $text
|
|
||||||
], [
|
|
||||||
]);
|
|
||||||
} catch (Exception $e) {
|
|
||||||
echo $e->getMessage();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Config::get('finance_public') == 'true') {
|
|
||||||
$sts = new Analytics();
|
|
||||||
Telegram::Send(
|
|
||||||
'新鲜出炉的财务月报~' . PHP_EOL .
|
|
||||||
'上月总收入笔数:' . $income_count . PHP_EOL .
|
|
||||||
'上月总收入金额:' . $income_total . PHP_EOL .
|
|
||||||
'月初也在努力工作~'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
File diff suppressed because it is too large
Load Diff
@ -1,224 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
|
|
||||||
namespace App\Command;
|
|
||||||
|
|
||||||
use App\Models\User;
|
|
||||||
use App\Models\Node;
|
|
||||||
use App\Models\RadiusRadPostauth;
|
|
||||||
use App\Models\RadiusRadAcct;
|
|
||||||
use App\Models\RadiusNas;
|
|
||||||
use App\Services\Config;
|
|
||||||
use App\Services\Mail;
|
|
||||||
use App\Models\TrafficLog;
|
|
||||||
use App\Utils\Tools;
|
|
||||||
use App\Utils\Radius;
|
|
||||||
use App\Utils\Da;
|
|
||||||
use Exception;
|
|
||||||
|
|
||||||
class SyncRadius
|
|
||||||
{
|
|
||||||
public static function synclogin()
|
|
||||||
{
|
|
||||||
if (Config::get('enable_radius') == 'false') {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$tempuserbox = array();
|
|
||||||
$users = User::all();
|
|
||||||
foreach ($users as $user) {
|
|
||||||
$email = $user->email;
|
|
||||||
$email = Radius::GetUserName($email);
|
|
||||||
$tempuserbox[$email] = $user->id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*$tempnodebox=array();
|
|
||||||
$nodes = Node::all();
|
|
||||||
foreach($nodes as $node){
|
|
||||||
if(strpos($node->name,"Shadowsocks")!=FALSE)
|
|
||||||
{
|
|
||||||
$ip=gethostbyname($node->server);
|
|
||||||
$tempnodebox[$ip]=$node->id;
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
|
|
||||||
$logs = RadiusRadPostauth::where('authdate', '<', date('Y-m-d H:i:s'))->where('authdate', '>', date('Y-m-d H:i:s', time() - 60))->get();
|
|
||||||
|
|
||||||
foreach ($logs as $log) {
|
|
||||||
if (isset($tempuserbox[$log->username])) {
|
|
||||||
$traffic = new TrafficLog();
|
|
||||||
$traffic->user_id = $tempuserbox[$log->username];
|
|
||||||
$traffic->u = 0;
|
|
||||||
$traffic->d = 10000;
|
|
||||||
$traffic->node_id = 1;
|
|
||||||
$traffic->rate = 1;
|
|
||||||
$traffic->traffic = Tools::flowAutoShow(10000);
|
|
||||||
$traffic->log_time = time();
|
|
||||||
$traffic->save();
|
|
||||||
|
|
||||||
$user = User::find($tempuserbox[$log->username]);
|
|
||||||
$user->t = time();
|
|
||||||
$user->u += 0;
|
|
||||||
$user->d += 10000;
|
|
||||||
$user->save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*$stmt = $db->query("SELECT * FROM `radacct` WHERE `acctstoptime`<'".date("Y-m-d H:i:s")."' AND `acctstoptime`>'".date("Y-m-d H:i:s",time()-60)."'");
|
|
||||||
$result = $stmt->fetchAll();
|
|
||||||
|
|
||||||
foreach($result as $row)
|
|
||||||
{
|
|
||||||
$traffic = new TrafficLog();
|
|
||||||
$traffic->user_id = $tempuserbox[$row["username"]];
|
|
||||||
$traffic->u = $row["acctinputoctets"];
|
|
||||||
$traffic->d = $row["acctoutputoctets"];
|
|
||||||
$traffic->node_id = 150;
|
|
||||||
$traffic->rate = 1;
|
|
||||||
$traffic->traffic = Tools::flowAutoShow(($row["acctinputoctets"]+$row["acctoutputoctets"])/1024/1024);
|
|
||||||
$traffic->log_time = time();
|
|
||||||
$traffic->save();
|
|
||||||
|
|
||||||
$user->t = time();
|
|
||||||
$user->u = $user->u + $row["acctinputoctets"];
|
|
||||||
$user->d = $user->d + $row["acctoutputoctets"];
|
|
||||||
$user->save();
|
|
||||||
} */
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static function syncvpn()
|
|
||||||
{
|
|
||||||
if (Config::get('radius_db_host') == '') {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$tempuserbox = array();
|
|
||||||
$users = User::all();
|
|
||||||
foreach ($users as $user) {
|
|
||||||
$email = $user->email;
|
|
||||||
$email = Radius::GetUserName($email);
|
|
||||||
$tempuserbox[$email] = $user->id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*$tempnodebox=array();
|
|
||||||
$nodes = Node::all();
|
|
||||||
foreach($nodes as $node){
|
|
||||||
if(strpos($node->name,"Shadowsocks")!=FALSE)
|
|
||||||
{
|
|
||||||
$ip=gethostbyname($node->server);
|
|
||||||
$tempnodebox[$ip]=$node->id;
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
/*$stmt = $db->query("SELECT * FROM `radpostauth` WHERE `authdate`<'".date("Y-m-d H:i:s")."' AND`authdate`>'".date("Y-m-d H:i:s",time()-60)."'");
|
|
||||||
$result = $stmt->fetchAll();
|
|
||||||
|
|
||||||
foreach($result as $row)
|
|
||||||
{
|
|
||||||
//if($row["pass"]!="")
|
|
||||||
{
|
|
||||||
$traffic = new TrafficLog();
|
|
||||||
$traffic->user_id = $tempuserbox[$row["username"]];
|
|
||||||
$traffic->u = 0;
|
|
||||||
$traffic->d = 10000;
|
|
||||||
$traffic->node_id = 149;
|
|
||||||
$traffic->rate = 1;
|
|
||||||
$traffic->traffic = Tools::flowAutoShow(10000);
|
|
||||||
$traffic->log_time = time();
|
|
||||||
$traffic->save();
|
|
||||||
|
|
||||||
$user->t = time();
|
|
||||||
$user->u = $user->u + 0;
|
|
||||||
$user->d = $user->d + 10000;
|
|
||||||
$user->save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
$logs = RadiusRadAcct::where('acctstoptime', '<', date('Y-m-d H:i:s'))->where('acctstoptime', '>', date('Y-m-d H:i:s', time() - 60))->get();
|
|
||||||
|
|
||||||
foreach ($logs as $log) {
|
|
||||||
$traffic = new TrafficLog();
|
|
||||||
$traffic->user_id = $tempuserbox[$log->username];
|
|
||||||
$traffic->u = $log->acctinputoctets;
|
|
||||||
$traffic->d = $log->acctoutputoctets;
|
|
||||||
$traffic->node_id = 2;
|
|
||||||
$traffic->rate = 1;
|
|
||||||
$traffic->traffic = Tools::flowAutoShow($log->acctinputoctets + $log->acctoutputoctets);
|
|
||||||
$traffic->log_time = time();
|
|
||||||
$traffic->save();
|
|
||||||
|
|
||||||
$user = User::find($tempuserbox[$log->username]);
|
|
||||||
$user->t = time();
|
|
||||||
$user->u += $log->acctinputoctets;
|
|
||||||
$user->d += $log->acctoutputoctets;
|
|
||||||
$user->save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function syncusers()
|
|
||||||
{
|
|
||||||
$users = User::all();
|
|
||||||
foreach ($users as $user) {
|
|
||||||
Radius::Add($user, $user->passwd);
|
|
||||||
|
|
||||||
echo 'Send sync mail to user: ' . $user->id;
|
|
||||||
$subject = Config::get('appName') . '-密码更新通知';
|
|
||||||
$to = $user->email;
|
|
||||||
$text = '您好,为了保证密码系统的统一,刚刚系统已经将您 vpn 等连接方式的用户名已经重置为:' . Radius::GetUserName($user->email) . ',密码自动重置为您 ss 的密码:' . $user->passwd . ' 了,以后您修改 ss 密码就会自动修改 vpn 等连接方式的密码了,感谢您的支持。 ';
|
|
||||||
try {
|
|
||||||
Mail::send($to, $subject, 'password/vpn.tpl', [
|
|
||||||
'user' => $user, 'text' => $text
|
|
||||||
], [
|
|
||||||
]);
|
|
||||||
} catch (Exception $e) {
|
|
||||||
echo $e->getMessage();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function syncnas()
|
|
||||||
{
|
|
||||||
if (Config::get('radius_db_host') != '') {
|
|
||||||
$md5txt = '';
|
|
||||||
|
|
||||||
$nases = RadiusNas::all();
|
|
||||||
|
|
||||||
foreach ($nases as $nas) {
|
|
||||||
//if($row["pass"]!="")
|
|
||||||
{
|
|
||||||
$md5txt = $md5txt . $nas->id . $nas->nasname . $nas->shortname . $nas->secret . $nas->description;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$md5 = MD5($md5txt);
|
|
||||||
|
|
||||||
|
|
||||||
$oldmd5 = file_get_contents(BASE_PATH . '/storage/nas.md5');
|
|
||||||
|
|
||||||
if ($oldmd5 != $md5) {
|
|
||||||
//Restart radius
|
|
||||||
$myfile = fopen(BASE_PATH . '/storage/nas.md5', 'wb+') or die('Unable to open file!');
|
|
||||||
echo('Restarting...');
|
|
||||||
system('/bin/bash /sbin/service radiusd restart', $retval);
|
|
||||||
echo($retval);
|
|
||||||
$txt = $md5;
|
|
||||||
fwrite($myfile, $txt);
|
|
||||||
fclose($myfile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$Nodes = Node::where('sort', 0)->where('node_ip', '<>', '')->where('node_ip', '<>', 'NULL')->get();
|
|
||||||
foreach ($Nodes as $Node) {
|
|
||||||
if (file_exists('/usr/local/psionic/portsentry/portsentry.ignore')) {
|
|
||||||
$content = file_get_contents('/usr/local/psionic/portsentry/portsentry.ignore');
|
|
||||||
if (strpos($content, $Node->node_ip) === false) {
|
|
||||||
file_put_contents('/usr/local/psionic/portsentry/portsentry.ignore', "\n" . $Node->node_ip . '/32', FILE_APPEND);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,372 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Command;
|
|
||||||
|
|
||||||
/***
|
|
||||||
* Class XCat
|
|
||||||
* @package App\Command
|
|
||||||
*/
|
|
||||||
|
|
||||||
use App\Models\User;
|
|
||||||
use App\Models\Relay;
|
|
||||||
use App\Services\Gateway\ChenPay;
|
|
||||||
use App\Utils\Hash;
|
|
||||||
use App\Utils\Tools;
|
|
||||||
use App\Utils\Discord;
|
|
||||||
use App\Services\Config;
|
|
||||||
|
|
||||||
use App\Utils\GA;
|
|
||||||
use App\Models\Node;
|
|
||||||
use App\Utils\DNSoverHTTPS;
|
|
||||||
use Exception;
|
|
||||||
use TelegramBot\Api\BotApi;
|
|
||||||
|
|
||||||
class XCat
|
|
||||||
{
|
|
||||||
public $argv;
|
|
||||||
|
|
||||||
public function __construct($argv)
|
|
||||||
{
|
|
||||||
$this->argv = $argv;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function boot()
|
|
||||||
{
|
|
||||||
switch ($this->argv[1]) {
|
|
||||||
case ('alipay'):
|
|
||||||
return (new ChenPay())->AliPayListen();
|
|
||||||
case ('wxpay'):
|
|
||||||
return (new ChenPay())->WxPayListen();
|
|
||||||
case ('createAdmin'):
|
|
||||||
return $this->createAdmin();
|
|
||||||
case ('resetTraffic'):
|
|
||||||
return $this->resetTraffic();
|
|
||||||
case ('setDiscord'):
|
|
||||||
return Discord::set();
|
|
||||||
case ('setTelegram'):
|
|
||||||
return $this->setTelegram();
|
|
||||||
case ('initQQWry'):
|
|
||||||
return $this->initQQWry();
|
|
||||||
case ('sendDiaryMail'):
|
|
||||||
return DailyMail::sendDailyMail();
|
|
||||||
case ('sendFinanceMail_day'):
|
|
||||||
return FinanceMail::sendFinanceMail_day();
|
|
||||||
case ('sendFinanceMail_week'):
|
|
||||||
return FinanceMail::sendFinanceMail_week();
|
|
||||||
case ('sendFinanceMail_month'):
|
|
||||||
return FinanceMail::sendFinanceMail_month();
|
|
||||||
case ('reall'):
|
|
||||||
return DailyMail::reall();
|
|
||||||
case ('syncusers'):
|
|
||||||
return SyncRadius::syncusers();
|
|
||||||
case ('synclogin'):
|
|
||||||
return SyncRadius::synclogin();
|
|
||||||
case ('syncvpn'):
|
|
||||||
return SyncRadius::syncvpn();
|
|
||||||
case ('nousers'):
|
|
||||||
return ExtMail::sendNoMail();
|
|
||||||
case ('oldusers'):
|
|
||||||
return ExtMail::sendOldMail();
|
|
||||||
case ('syncnode'):
|
|
||||||
return Job::syncnode();
|
|
||||||
case ('syncnasnode'):
|
|
||||||
return Job::syncnasnode();
|
|
||||||
case ('detectGFW'):
|
|
||||||
return Job::detectGFW();
|
|
||||||
case ('syncnas'):
|
|
||||||
return SyncRadius::syncnas();
|
|
||||||
case ('dailyjob'):
|
|
||||||
return Job::DailyJob();
|
|
||||||
case ('checkjob'):
|
|
||||||
return Job::CheckJob();
|
|
||||||
case ('userga'):
|
|
||||||
return Job::UserGa();
|
|
||||||
case ('backup'):
|
|
||||||
return Job::backup(false);
|
|
||||||
case ('backupfull'):
|
|
||||||
return Job::backup(true);
|
|
||||||
case ('initdownload'):
|
|
||||||
return $this->initdownload();
|
|
||||||
case ('initdocuments'):
|
|
||||||
return $this->initdocuments();
|
|
||||||
case ('updatedownload'):
|
|
||||||
return Job::updatedownload();
|
|
||||||
case ('cleanRelayRule'):
|
|
||||||
return $this->cleanRelayRule();
|
|
||||||
case ('resetPort'):
|
|
||||||
return $this->resetPort();
|
|
||||||
case ('resetAllPort'):
|
|
||||||
return $this->resetAllPort();
|
|
||||||
case ('update'):
|
|
||||||
return Update::update($this);
|
|
||||||
case ('sendDailyUsageByTG'):
|
|
||||||
return $this->sendDailyUsageByTG();
|
|
||||||
case ('npmbuild'):
|
|
||||||
return $this->npmbuild();
|
|
||||||
case ('getCookie'):
|
|
||||||
return $this->getCookie();
|
|
||||||
case ('iptest'):
|
|
||||||
return $this->iptest();
|
|
||||||
default:
|
|
||||||
return $this->defaultAction();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function defaultAction()
|
|
||||||
{
|
|
||||||
echo(PHP_EOL . '用法: php xcat [选项]' . PHP_EOL);
|
|
||||||
echo('常用选项:' . PHP_EOL);
|
|
||||||
echo(' createAdmin - 创建管理员帐号' . PHP_EOL);
|
|
||||||
echo(' setDiscord - 设置 Discord 机器人' . PHP_EOL);
|
|
||||||
echo(' setTelegram - 设置 Telegram 机器人' . PHP_EOL);
|
|
||||||
echo(' cleanRelayRule - 清除所有中转规则' . PHP_EOL);
|
|
||||||
echo(' resetPort - 重置单个用户端口' . PHP_EOL);
|
|
||||||
echo(' resetAllPort - 重置所有用户端口' . PHP_EOL);
|
|
||||||
echo(' initdownload - 下载 SSR 程序至服务器' . PHP_EOL);
|
|
||||||
echo(' initdocuments - 下载用户使用文档至服务器' . PHP_EOL);
|
|
||||||
echo(' initQQWry - 下载 IP 解析库' . PHP_EOL);
|
|
||||||
echo(' resetTraffic - 重置所有用户流量' . PHP_EOL);
|
|
||||||
echo(' update - 更新并迁移配置' . PHP_EOL);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function resetPort()
|
|
||||||
{
|
|
||||||
fwrite(STDOUT, '请输入用户id: ');
|
|
||||||
$user = User::Where('id', '=', trim(fgets(STDIN)))->first();
|
|
||||||
$origin_port = $user->port;
|
|
||||||
|
|
||||||
$user->port = Tools::getAvPort();
|
|
||||||
|
|
||||||
$relay_rules = Relay::where('user_id', $user->id)->where('port', $origin_port)->get();
|
|
||||||
foreach ($relay_rules as $rule) {
|
|
||||||
$rule->port = $user->port;
|
|
||||||
$rule->save();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($user->save()) {
|
|
||||||
echo "重置成功!\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function resetAllPort()
|
|
||||||
{
|
|
||||||
$users = User::all();
|
|
||||||
foreach ($users as $user) {
|
|
||||||
$origin_port = $user->port;
|
|
||||||
$user->port = Tools::getAvPort();
|
|
||||||
echo '$origin_port=' . $origin_port . '&$user->port=' . $user->port . "\n";
|
|
||||||
$user->save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function cleanRelayRule()
|
|
||||||
{
|
|
||||||
$rules = Relay::all();
|
|
||||||
foreach ($rules as $rule) {
|
|
||||||
echo($rule->id . "\n");
|
|
||||||
if ($rule->source_node_id == 0) {
|
|
||||||
echo($rule->id . "被删除!\n");
|
|
||||||
$rule->delete();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$ruleset = Relay::where('user_id', $rule->user_id)->orwhere('user_id', 0)->get();
|
|
||||||
$maybe_rule_id = Tools::has_conflict_rule($rule, $ruleset, $rule->id);
|
|
||||||
if ($maybe_rule_id != 0) {
|
|
||||||
echo($rule->id . "被删除!\n");
|
|
||||||
$rule->delete();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function initdownload()
|
|
||||||
{
|
|
||||||
system('git clone --depth=3 https://github.com/xcxnig/ssr-download.git ' . BASE_PATH . '/public/ssr-download/ && git gc', $ret);
|
|
||||||
echo $ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function initdocuments()
|
|
||||||
{
|
|
||||||
system('git clone https://github.com/GeekQu/PANEL_DOC.git ' . BASE_PATH . "/public/docs/", $ret);
|
|
||||||
echo $ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function createAdmin()
|
|
||||||
{
|
|
||||||
if (count($this->argv) === 2) {
|
|
||||||
echo 'add admin/ 创建管理员帐号.....';
|
|
||||||
// ask for input
|
|
||||||
fwrite(STDOUT, 'Enter your email/输入管理员邮箱: ');
|
|
||||||
// get input
|
|
||||||
$email = trim(fgets(STDIN));
|
|
||||||
// write input back
|
|
||||||
fwrite(STDOUT, "Enter password for: $email / 为 $email 添加密码: ");
|
|
||||||
$passwd = trim(fgets(STDIN));
|
|
||||||
echo "Email: $email, Password: $passwd! ";
|
|
||||||
fwrite(STDOUT, "Press [y] to create admin..... 按下[Y]确认来确认创建管理员账户..... \n");
|
|
||||||
$y = trim(fgets(STDIN));
|
|
||||||
} elseif (count($this->argv) === 4) {
|
|
||||||
[, , $email, $passwd] = $this->argv;
|
|
||||||
$y = 'y';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strtolower($y) == 'y') {
|
|
||||||
echo 'start create admin account';
|
|
||||||
// create admin user
|
|
||||||
// do reg user
|
|
||||||
$user = new User();
|
|
||||||
$user->user_name = 'admin';
|
|
||||||
$user->email = $email;
|
|
||||||
$user->pass = Hash::passwordHash($passwd);
|
|
||||||
$user->passwd = Tools::genRandomChar(6);
|
|
||||||
$user->port = Tools::getLastPort() + 1;
|
|
||||||
$user->t = 0;
|
|
||||||
$user->u = 0;
|
|
||||||
$user->d = 0;
|
|
||||||
$user->transfer_enable = Tools::toGB(Config::get('defaultTraffic'));
|
|
||||||
$user->invite_num = Config::get('inviteNum');
|
|
||||||
$user->ref_by = 0;
|
|
||||||
$user->is_admin = 1;
|
|
||||||
$user->expire_in = date('Y-m-d H:i:s', time() + Config::get('user_expire_in_default') * 86400);
|
|
||||||
$user->reg_date = date('Y-m-d H:i:s');
|
|
||||||
$user->money = 0;
|
|
||||||
$user->im_type = 1;
|
|
||||||
$user->im_value = '';
|
|
||||||
$user->class = 0;
|
|
||||||
$user->plan = 'A';
|
|
||||||
$user->node_speedlimit = 0;
|
|
||||||
$user->theme = Config::get('theme');
|
|
||||||
|
|
||||||
$ga = new GA();
|
|
||||||
$secret = $ga->createSecret();
|
|
||||||
$user->ga_token = $secret;
|
|
||||||
$user->ga_enable = 0;
|
|
||||||
|
|
||||||
if ($user->save()) {
|
|
||||||
echo "Successful/添加成功!\n";
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
echo '添加失败';
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
echo 'cancel';
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function resetTraffic()
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
User::where('enable', 1)->update([
|
|
||||||
'd' => 0,
|
|
||||||
'u' => 0,
|
|
||||||
'last_day_t' => 0,
|
|
||||||
]);
|
|
||||||
} catch (Exception $e) {
|
|
||||||
echo $e->getMessage();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return 'reset traffic successful';
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setTelegram()
|
|
||||||
{
|
|
||||||
$bot = new BotApi(Config::get('telegram_token'));
|
|
||||||
$ch= curl_init();
|
|
||||||
curl_setopt ($ch, CURLOPT_URL, sprintf('https://api.telegram.org/bot%s/deleteWebhook', Config::get('telegram_token')));
|
|
||||||
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
||||||
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 5);
|
|
||||||
$deleteWebhookReturn = json_decode(curl_exec($ch));
|
|
||||||
curl_close($ch);
|
|
||||||
if ($deleteWebhookReturn->ok && $deleteWebhookReturn->result && $bot->setWebhook(Config::get('baseUrl') . '/telegram_callback?token=' . Config::get('telegram_request_token')) == 1) {
|
|
||||||
echo('设置成功!' . PHP_EOL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function initQQWry()
|
|
||||||
{
|
|
||||||
echo('开始下载纯真 IP 数据库....');
|
|
||||||
$qqwry = file_get_contents('https://qqwry.mirror.noc.one/QQWry.Dat?from=sspanel_uim');
|
|
||||||
if ($qqwry != '') {
|
|
||||||
$fp = fopen(BASE_PATH . '/storage/qqwry.dat', 'wb');
|
|
||||||
if ($fp) {
|
|
||||||
fwrite($fp, $qqwry);
|
|
||||||
fclose($fp);
|
|
||||||
echo('纯真 IP 数据库下载成功!');
|
|
||||||
} else {
|
|
||||||
echo('纯真 IP 数据库保存失败!');
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
echo('下载失败!请重试,或在 https://github.com/SukkaW/qqwry-mirror/issues/new 反馈!');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function sendDailyUsageByTG()
|
|
||||||
{
|
|
||||||
$bot = new BotApi(Config::get('telegram_token'));
|
|
||||||
$users = User::where('telegram_id', '>', 0)->get();
|
|
||||||
foreach ($users as $user) {
|
|
||||||
$u = $user->u;
|
|
||||||
$d = $user->d;
|
|
||||||
$last_day_t = $user->last_day_t;
|
|
||||||
$transfer_enable = $user->transfer_enable;
|
|
||||||
$reply_message = '您当前的流量状况:' . PHP_EOL .
|
|
||||||
sprintf(
|
|
||||||
'今天已使用 %s %s%%',
|
|
||||||
$user->TodayusedTraffic(),
|
|
||||||
number_format(($u + $d - $last_day_t) / $transfer_enable * 100, 2)
|
|
||||||
) . PHP_EOL .
|
|
||||||
sprintf(
|
|
||||||
'今天前已使用 %s %s%%',
|
|
||||||
$user->LastusedTraffic(),
|
|
||||||
number_format($last_day_t / $transfer_enable * 100, 2)
|
|
||||||
) . PHP_EOL .
|
|
||||||
sprintf(
|
|
||||||
'剩余 %s %s%%',
|
|
||||||
$user->unusedTraffic(),
|
|
||||||
number_format(($transfer_enable - ($u + $d)) / $transfer_enable * 100, 2)
|
|
||||||
);
|
|
||||||
$bot->sendMessage(
|
|
||||||
$user->get_user_attributes('telegram_id'),
|
|
||||||
$reply_message,
|
|
||||||
$parseMode = null,
|
|
||||||
$disablePreview = false,
|
|
||||||
$replyToMessageId = null
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function npmbuild(){
|
|
||||||
chdir(BASE_PATH . '/uim-index-dev');
|
|
||||||
system('npm install');
|
|
||||||
system('npm run build');
|
|
||||||
system('cp -u ../public/vuedist/index.html ../resources/views/material/index.tpl');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function iptest()
|
|
||||||
{
|
|
||||||
$nodes = Node::all();
|
|
||||||
foreach ($nodes as $node) {
|
|
||||||
$ip = "";
|
|
||||||
$server = "";
|
|
||||||
if (in_array($node->sort, array(0, 1, 10, 11, 12, 13))) {
|
|
||||||
$server_list = explode(";", $node->server);
|
|
||||||
$server = $server_list[0];
|
|
||||||
if (!Tools::is_ip($server)) {
|
|
||||||
$ip = DNSoverHTTPS::gethostbyName($server); // returns a collection of DNS A Records
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($server!="" and $ip !="") {
|
|
||||||
echo "Server: ".$server." ip address: ".$ip."\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getCookie()
|
|
||||||
{
|
|
||||||
if (count($this->argv) === 3) {
|
|
||||||
$user = User::find($this->argv[2]);
|
|
||||||
$expire_in = 86400 + time();
|
|
||||||
echo Hash::cookieHash($user->pass, $expire_in) . ' ' . $expire_in;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,76 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Controllers\Admin;
|
|
||||||
|
|
||||||
use App\Models\Auto;
|
|
||||||
use App\Controllers\AdminController;
|
|
||||||
use Ozdemir\Datatables\Datatables;
|
|
||||||
use App\Utils\DatatablesHelper;
|
|
||||||
|
|
||||||
class AutoController extends AdminController
|
|
||||||
{
|
|
||||||
public function index($request, $response, $args)
|
|
||||||
{
|
|
||||||
$table_config['total_column'] = array('id' => 'ID',
|
|
||||||
'datetime' => '时间', 'type' => '类型', 'value' => '内容');
|
|
||||||
$table_config['default_show_column'] = array('op', 'id',
|
|
||||||
'datetime', 'type', 'value');
|
|
||||||
$table_config['ajax_url'] = 'auto/ajax';
|
|
||||||
return $this->view()->assign('table_config', $table_config)->display('admin/auto/index.tpl');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function create($request, $response, $args)
|
|
||||||
{
|
|
||||||
return $this->view()->display('admin/auto/add.tpl');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function add($request, $response, $args)
|
|
||||||
{
|
|
||||||
$auto = new Auto();
|
|
||||||
$auto->datetime = time();
|
|
||||||
$auto->value = $request->getParam('content');
|
|
||||||
$auto->sign = $request->getParam('sign');
|
|
||||||
$auto->type = 1;
|
|
||||||
|
|
||||||
if (!$auto->save()) {
|
|
||||||
$rs['ret'] = 0;
|
|
||||||
$rs['msg'] = '添加失败';
|
|
||||||
return $response->getBody()->write(json_encode($rs));
|
|
||||||
}
|
|
||||||
$rs['ret'] = 1;
|
|
||||||
$rs['msg'] = '添加成功';
|
|
||||||
return $response->getBody()->write(json_encode($rs));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function delete($request, $response, $args)
|
|
||||||
{
|
|
||||||
$id = $request->getParam('id');
|
|
||||||
$auto = Auto::find($id);
|
|
||||||
if (!$auto->delete()) {
|
|
||||||
$rs['ret'] = 0;
|
|
||||||
$rs['msg'] = '删除失败';
|
|
||||||
return $response->getBody()->write(json_encode($rs));
|
|
||||||
}
|
|
||||||
$rs['ret'] = 1;
|
|
||||||
$rs['msg'] = '删除成功';
|
|
||||||
return $response->getBody()->write(json_encode($rs));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function ajax($request, $response, $args)
|
|
||||||
{
|
|
||||||
$datatables = new Datatables(new DatatablesHelper());
|
|
||||||
$datatables->query('Select id,datetime,type,value from auto');
|
|
||||||
|
|
||||||
$datatables->edit('datetime', static function ($data) {
|
|
||||||
return date('Y-m-d H:i:s', $data['datetime']);
|
|
||||||
});
|
|
||||||
|
|
||||||
$datatables->edit('type', static function ($data) {
|
|
||||||
return $data['type'] == 1 ? '命令下发' : '命令被执行';
|
|
||||||
});
|
|
||||||
|
|
||||||
$body = $response->getBody();
|
|
||||||
$body->write($datatables->generate());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,146 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Controllers\Admin;
|
|
||||||
|
|
||||||
use App\Models\Code;
|
|
||||||
use App\Models\User;
|
|
||||||
use App\Controllers\AdminController;
|
|
||||||
use App\Utils\Tools;
|
|
||||||
use App\Services\Auth;
|
|
||||||
|
|
||||||
use Ozdemir\Datatables\Datatables;
|
|
||||||
use App\Utils\DatatablesHelper;
|
|
||||||
|
|
||||||
class CodeController extends AdminController
|
|
||||||
{
|
|
||||||
public function index($request, $response, $args)
|
|
||||||
{
|
|
||||||
$table_config['total_column'] = array('id' => 'ID', 'code' => '内容',
|
|
||||||
'type' => '类型', 'number' => '操作',
|
|
||||||
'isused' => '是否已经使用', 'userid' => '用户ID',
|
|
||||||
'user_name' => '用户名', 'usedatetime' => '使用时间');
|
|
||||||
$table_config['default_show_column'] = array();
|
|
||||||
foreach ($table_config['total_column'] as $column => $value) {
|
|
||||||
$table_config['default_show_column'][] = $column;
|
|
||||||
}
|
|
||||||
$table_config['ajax_url'] = 'code/ajax';
|
|
||||||
return $this->view()->assign('table_config', $table_config)->display('admin/code/index.tpl');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function create($request, $response, $args)
|
|
||||||
{
|
|
||||||
return $this->view()->display('admin/code/add.tpl');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function donate_create($request, $response, $args)
|
|
||||||
{
|
|
||||||
return $this->view()->display('admin/code/add_donate.tpl');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function add($request, $response, $args)
|
|
||||||
{
|
|
||||||
$n = $request->getParam('amount');
|
|
||||||
$type = $request->getParam('type');
|
|
||||||
$number = $request->getParam('number');
|
|
||||||
|
|
||||||
if (Tools::isInt($n) == false) {
|
|
||||||
$rs['ret'] = 0;
|
|
||||||
$rs['msg'] = '非法请求';
|
|
||||||
return $response->getBody()->write(json_encode($rs));
|
|
||||||
}
|
|
||||||
|
|
||||||
for ($i = 0; $i < $n; $i++) {
|
|
||||||
$char = Tools::genRandomChar(32);
|
|
||||||
$code = new Code();
|
|
||||||
$code->code = time() . $char;
|
|
||||||
$code->type = -1;
|
|
||||||
$code->number = $number;
|
|
||||||
$code->userid = 0;
|
|
||||||
$code->usedatetime = '1989:06:04 02:30:00';
|
|
||||||
$code->save();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
$rs['ret'] = 1;
|
|
||||||
$rs['msg'] = '充值码添加成功';
|
|
||||||
return $response->getBody()->write(json_encode($rs));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function donate_add($request, $response, $args)
|
|
||||||
{
|
|
||||||
$amount = $request->getParam('amount');
|
|
||||||
$type = $request->getParam('type');
|
|
||||||
$text = $request->getParam('code');
|
|
||||||
|
|
||||||
$code = new Code();
|
|
||||||
$code->code = $text;
|
|
||||||
$code->type = $type;
|
|
||||||
$code->number = $amount;
|
|
||||||
$code->userid = Auth::getUser()->id;
|
|
||||||
$code->isused = 1;
|
|
||||||
$code->usedatetime = date('Y:m:d H:i:s');
|
|
||||||
|
|
||||||
$code->save();
|
|
||||||
|
|
||||||
$rs['ret'] = 1;
|
|
||||||
$rs['msg'] = '添加成功';
|
|
||||||
return $response->getBody()->write(json_encode($rs));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function ajax_code($request, $response, $args)
|
|
||||||
{
|
|
||||||
$datatables = new Datatables(new DatatablesHelper());
|
|
||||||
$datatables->query('Select code.id,code.code,code.type,code.number,code.isused,code.userid,code.userid as user_name,code.usedatetime from code');
|
|
||||||
|
|
||||||
$datatables->edit('number', static function ($data) {
|
|
||||||
switch ($data['type']) {
|
|
||||||
case -1:
|
|
||||||
return '充值 ' . $data['number'] . ' 元';
|
|
||||||
|
|
||||||
case -2:
|
|
||||||
return '支出 ' . $data['number'] . ' 元';
|
|
||||||
|
|
||||||
default:
|
|
||||||
return '已经废弃';
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$datatables->edit('isused', static function ($data) {
|
|
||||||
return $data['isused'] == 1 ? '已使用' : '未使用';
|
|
||||||
});
|
|
||||||
|
|
||||||
$datatables->edit('userid', static function ($data) {
|
|
||||||
return $data['userid'] == 0 ? '未使用' : $data['userid'];
|
|
||||||
});
|
|
||||||
|
|
||||||
$datatables->edit('user_name', static function ($data) {
|
|
||||||
$user = User::find($data['user_name']);
|
|
||||||
if ($user == null) {
|
|
||||||
return '未使用';
|
|
||||||
}
|
|
||||||
|
|
||||||
return $user->user_name;
|
|
||||||
});
|
|
||||||
|
|
||||||
$datatables->edit('type', static function ($data) {
|
|
||||||
switch ($data['type']) {
|
|
||||||
case -1:
|
|
||||||
return '充值金额';
|
|
||||||
|
|
||||||
case -2:
|
|
||||||
return '财务支出';
|
|
||||||
|
|
||||||
default:
|
|
||||||
return '已经废弃';
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$datatables->edit('usedatetime', static function ($data) {
|
|
||||||
return $data['usedatetime'] > '2000-1-1 0:0:0' ? $data['usedatetime'] : '未使用';
|
|
||||||
});
|
|
||||||
|
|
||||||
$body = $response->getBody();
|
|
||||||
$body->write($datatables->generate());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,43 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Controllers\Admin;
|
|
||||||
|
|
||||||
use App\Controllers\AdminController;
|
|
||||||
use Ozdemir\Datatables\Datatables;
|
|
||||||
use App\Utils\DatatablesHelper;
|
|
||||||
|
|
||||||
class DetectBanLogController extends AdminController
|
|
||||||
{
|
|
||||||
public function index($request, $response, $args)
|
|
||||||
{
|
|
||||||
$table_config['total_column'] = array("id" => "ID", "user_id" => "用户ID",
|
|
||||||
"user_name" => "用户名", "email" => "用户邮箱",
|
|
||||||
"detect_number" => "违规次数", "ban_time" => "封禁时长(分钟)",
|
|
||||||
"start_time" => "统计开始时间", "end_time" => "统计结束以及封禁开始时间",
|
|
||||||
"ban_end_time" => "封禁结束时间", "all_detect_number" => "累计违规次数");
|
|
||||||
$table_config['default_show_column'] = array();
|
|
||||||
foreach ($table_config['total_column'] as $column => $value) {
|
|
||||||
array_push($table_config['default_show_column'], $column);
|
|
||||||
}
|
|
||||||
$table_config['ajax_url'] = 'ban/ajax';
|
|
||||||
return $this->view()->assign('table_config', $table_config)->display('admin/detect/ban.tpl');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function ajax_log($request, $response, $args)
|
|
||||||
{
|
|
||||||
$datatables = new Datatables(new DatatablesHelper());
|
|
||||||
$datatables->query('Select detect_ban_log.id,detect_ban_log.user_id,detect_ban_log.user_name,detect_ban_log.email,detect_ban_log.detect_number,detect_ban_log.ban_time,detect_ban_log.start_time,detect_ban_log.end_time,detect_ban_log.all_detect_number,detect_ban_log.end_time as ban_end_time from detect_ban_log');
|
|
||||||
$datatables->edit('start_time', function ($data) {
|
|
||||||
return date('Y-m-d H:i:s', $data['start_time']);
|
|
||||||
});
|
|
||||||
$datatables->edit('end_time', function ($data) {
|
|
||||||
return date('Y-m-d H:i:s', $data['end_time']);
|
|
||||||
});
|
|
||||||
$datatables->edit('ban_end_time', function ($data) {
|
|
||||||
return date('Y-m-d H:i:s', $data['ban_end_time']+$data['ban_time']*60);
|
|
||||||
});
|
|
||||||
|
|
||||||
$body = $response->getBody();
|
|
||||||
$body->write($datatables->generate());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,148 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Controllers\Admin;
|
|
||||||
|
|
||||||
use App\Models\DetectRule;
|
|
||||||
use App\Utils\Telegram;
|
|
||||||
use App\Controllers\AdminController;
|
|
||||||
|
|
||||||
use Ozdemir\Datatables\Datatables;
|
|
||||||
use App\Utils\DatatablesHelper;
|
|
||||||
|
|
||||||
class DetectController extends AdminController
|
|
||||||
{
|
|
||||||
public function index($request, $response, $args)
|
|
||||||
{
|
|
||||||
$table_config['total_column'] = array('op' => '操作', 'id' => 'ID', 'name' => '名称',
|
|
||||||
'text' => '介绍', 'regex' => '正则表达式',
|
|
||||||
'type' => '类型');
|
|
||||||
$table_config['default_show_column'] = array();
|
|
||||||
foreach ($table_config['total_column'] as $column => $value) {
|
|
||||||
$table_config['default_show_column'][] = $column;
|
|
||||||
}
|
|
||||||
$table_config['ajax_url'] = 'detect/ajax';
|
|
||||||
return $this->view()->assign('table_config', $table_config)->display('admin/detect/index.tpl');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function log($request, $response, $args)
|
|
||||||
{
|
|
||||||
$table_config['total_column'] = array('id' => 'ID', 'user_id' => '用户ID',
|
|
||||||
'user_name' => '用户名', 'node_id' => '节点ID',
|
|
||||||
'node_name' => '节点名', 'rule_id' => '规则ID',
|
|
||||||
'rule_name' => '规则名', 'rule_text' => '规则描述',
|
|
||||||
'rule_regex' => '规则正则表达式', 'rule_type' => '规则类型',
|
|
||||||
'datetime' => '时间');
|
|
||||||
$table_config['default_show_column'] = array();
|
|
||||||
foreach ($table_config['total_column'] as $column => $value) {
|
|
||||||
$table_config['default_show_column'][] = $column;
|
|
||||||
}
|
|
||||||
$table_config['ajax_url'] = 'log/ajax';
|
|
||||||
return $this->view()->assign('table_config', $table_config)->display('admin/detect/log.tpl');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function create($request, $response, $args)
|
|
||||||
{
|
|
||||||
return $this->view()->display('admin/detect/add.tpl');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function add($request, $response, $args)
|
|
||||||
{
|
|
||||||
$rule = new DetectRule();
|
|
||||||
$rule->name = $request->getParam('name');
|
|
||||||
$rule->text = $request->getParam('text');
|
|
||||||
$rule->regex = $request->getParam('regex');
|
|
||||||
$rule->type = $request->getParam('type');
|
|
||||||
|
|
||||||
if (!$rule->save()) {
|
|
||||||
$rs['ret'] = 0;
|
|
||||||
$rs['msg'] = '添加失败';
|
|
||||||
return $response->getBody()->write(json_encode($rs));
|
|
||||||
}
|
|
||||||
|
|
||||||
Telegram::SendMarkdown('有新的审计规则:' . $rule->name);
|
|
||||||
|
|
||||||
$rs['ret'] = 1;
|
|
||||||
$rs['msg'] = '添加成功';
|
|
||||||
return $response->getBody()->write(json_encode($rs));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function edit($request, $response, $args)
|
|
||||||
{
|
|
||||||
$id = $args['id'];
|
|
||||||
$rule = DetectRule::find($id);
|
|
||||||
return $this->view()->assign('rule', $rule)->display('admin/detect/edit.tpl');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function update($request, $response, $args)
|
|
||||||
{
|
|
||||||
$id = $args['id'];
|
|
||||||
$rule = DetectRule::find($id);
|
|
||||||
|
|
||||||
$rule->name = $request->getParam('name');
|
|
||||||
$rule->text = $request->getParam('text');
|
|
||||||
$rule->regex = $request->getParam('regex');
|
|
||||||
$rule->type = $request->getParam('type');
|
|
||||||
|
|
||||||
if (!$rule->save()) {
|
|
||||||
$rs['ret'] = 0;
|
|
||||||
$rs['msg'] = '修改失败';
|
|
||||||
return $response->getBody()->write(json_encode($rs));
|
|
||||||
}
|
|
||||||
|
|
||||||
Telegram::SendMarkdown('规则更新:' . PHP_EOL . $request->getParam('name'));
|
|
||||||
|
|
||||||
$rs['ret'] = 1;
|
|
||||||
$rs['msg'] = '修改成功';
|
|
||||||
return $response->getBody()->write(json_encode($rs));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function delete($request, $response, $args)
|
|
||||||
{
|
|
||||||
$id = $request->getParam('id');
|
|
||||||
$rule = DetectRule::find($id);
|
|
||||||
if (!$rule->delete()) {
|
|
||||||
$rs['ret'] = 0;
|
|
||||||
$rs['msg'] = '删除失败';
|
|
||||||
return $response->getBody()->write(json_encode($rs));
|
|
||||||
}
|
|
||||||
$rs['ret'] = 1;
|
|
||||||
$rs['msg'] = '删除成功';
|
|
||||||
return $response->getBody()->write(json_encode($rs));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function ajax_rule($request, $response, $args)
|
|
||||||
{
|
|
||||||
$datatables = new Datatables(new DatatablesHelper());
|
|
||||||
$datatables->query('Select id as op,id,name,text,regex,type from detect_list');
|
|
||||||
|
|
||||||
$datatables->edit('op', static function ($data) {
|
|
||||||
return '<a class="btn btn-brand" href="/admin/detect/' . $data['id'] . '/edit">编辑</a>
|
|
||||||
<a class="btn btn-brand-accent" id="delete" value="' . $data['id'] . '" href="javascript:void(0);" onClick="delete_modal_show(\'' . $data['id'] . '\')">删除</a>';
|
|
||||||
});
|
|
||||||
|
|
||||||
$datatables->edit('type', static function ($data) {
|
|
||||||
return $data['type'] == 1 ? '数据包明文匹配' : '数据包十六进制匹配';
|
|
||||||
});
|
|
||||||
|
|
||||||
$body = $response->getBody();
|
|
||||||
$body->write($datatables->generate());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function ajax_log($request, $response, $args)
|
|
||||||
{
|
|
||||||
$datatables = new Datatables(new DatatablesHelper());
|
|
||||||
$datatables->query('Select detect_log.id,user_id,user.user_name,node_id,node.name as node_name,list.id as rule_id,list.name as rule_name,list.text as rule_text,list.regex as rule_regex,list.type as rule_type,detect_log.datetime from detect_log,user,ss_node as node,detect_list as list where user.id=detect_log.user_id and node.id = detect_log.node_id and list.id = detect_log.list_id');
|
|
||||||
|
|
||||||
$datatables->edit('rule_type', static function ($data) {
|
|
||||||
return $data['rule_type'] == 1 ? '数据包明文匹配' : '数据包十六进制匹配';
|
|
||||||
});
|
|
||||||
|
|
||||||
$datatables->edit('datetime', static function ($data) {
|
|
||||||
return date('Y-m-d H:i:s', $data['datetime']);
|
|
||||||
});
|
|
||||||
|
|
||||||
$body = $response->getBody();
|
|
||||||
$body->write($datatables->generate());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,190 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Controllers\Admin;
|
|
||||||
|
|
||||||
use App\Models\BlockIp;
|
|
||||||
use App\Models\UnblockIp;
|
|
||||||
use App\Models\Node;
|
|
||||||
use App\Controllers\AdminController;
|
|
||||||
use App\Utils\QQWry;
|
|
||||||
use App\Utils\Tools;
|
|
||||||
use App\Services\Auth;
|
|
||||||
|
|
||||||
use Ozdemir\Datatables\Datatables;
|
|
||||||
use App\Utils\DatatablesHelper;
|
|
||||||
|
|
||||||
class IpController extends AdminController
|
|
||||||
{
|
|
||||||
public function index($request, $response, $args)
|
|
||||||
{
|
|
||||||
$table_config['total_column'] = array('id' => 'ID', 'userid' => '用户ID',
|
|
||||||
'user_name' => '用户名', 'ip' => 'IP',
|
|
||||||
'location' => '归属地', 'datetime' => '时间', 'type' => '类型');
|
|
||||||
$table_config['default_show_column'] = array();
|
|
||||||
foreach ($table_config['total_column'] as $column => $value) {
|
|
||||||
$table_config['default_show_column'][] = $column;
|
|
||||||
}
|
|
||||||
$table_config['ajax_url'] = 'login/ajax';
|
|
||||||
return $this->view()->assign('table_config', $table_config)->display('admin/ip/login.tpl');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function alive($request, $response, $args)
|
|
||||||
{
|
|
||||||
$table_config['total_column'] = array('id' => 'ID', 'userid' => '用户ID',
|
|
||||||
'user_name' => '用户名', 'nodeid' => '节点ID',
|
|
||||||
'node_name' => '节点名', 'ip' => 'IP',
|
|
||||||
'location' => '归属地', 'datetime' => '时间', 'is_node' => '是否为中转连接');
|
|
||||||
$table_config['default_show_column'] = array();
|
|
||||||
foreach ($table_config['total_column'] as $column => $value) {
|
|
||||||
$table_config['default_show_column'][] = $column;
|
|
||||||
}
|
|
||||||
$table_config['ajax_url'] = 'alive/ajax';
|
|
||||||
return $this->view()->assign('table_config', $table_config)->display('admin/ip/alive.tpl');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function block($request, $response, $args)
|
|
||||||
{
|
|
||||||
$table_config['total_column'] = array('id' => 'ID',
|
|
||||||
'name' => '节点名称', 'ip' => 'IP',
|
|
||||||
'location' => '归属地', 'datetime' => '时间');
|
|
||||||
$table_config['default_show_column'] = array();
|
|
||||||
foreach ($table_config['total_column'] as $column => $value) {
|
|
||||||
$table_config['default_show_column'][] = $column;
|
|
||||||
}
|
|
||||||
$table_config['ajax_url'] = 'block/ajax';
|
|
||||||
return $this->view()->assign('table_config', $table_config)->display('admin/ip/block.tpl');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function unblock($request, $response, $args)
|
|
||||||
{
|
|
||||||
$table_config['total_column'] = array('id' => 'ID', 'userid' => '用户ID',
|
|
||||||
'user_name' => '用户名', 'ip' => 'IP',
|
|
||||||
'location' => '归属地', 'datetime' => '时间');
|
|
||||||
$table_config['default_show_column'] = array();
|
|
||||||
foreach ($table_config['total_column'] as $column => $value) {
|
|
||||||
$table_config['default_show_column'][] = $column;
|
|
||||||
}
|
|
||||||
$table_config['ajax_url'] = 'unblock/ajax';
|
|
||||||
return $this->view()->assign('table_config', $table_config)->display('admin/ip/unblock.tpl');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function doUnblock($request, $response, $args)
|
|
||||||
{
|
|
||||||
$ip = $request->getParam('ip');
|
|
||||||
|
|
||||||
$user = Auth::getUser();
|
|
||||||
$BIP = BlockIp::where('ip', $ip)->get();
|
|
||||||
foreach ($BIP as $bi) {
|
|
||||||
$bi->delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
$UIP = new UnblockIp();
|
|
||||||
$UIP->userid = $user->id;
|
|
||||||
$UIP->ip = $ip;
|
|
||||||
$UIP->datetime = time();
|
|
||||||
$UIP->save();
|
|
||||||
|
|
||||||
|
|
||||||
$res['ret'] = 1;
|
|
||||||
$res['msg'] = '发送解封命令解封 ' . $ip . ' 成功';
|
|
||||||
return $this->echoJson($response, $res);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function ajax_block($request, $response, $args)
|
|
||||||
{
|
|
||||||
$datatables = new Datatables(new DatatablesHelper());
|
|
||||||
$datatables->query('Select blockip.id,node.name,blockip.ip,blockip.ip as location,datetime from blockip,ss_node as node WHERE blockip.nodeid = node.id');
|
|
||||||
|
|
||||||
$datatables->edit('datetime', static function ($data) {
|
|
||||||
return date('Y-m-d H:i:s', $data['datetime']);
|
|
||||||
});
|
|
||||||
|
|
||||||
$iplocation = new QQWry();
|
|
||||||
|
|
||||||
$datatables->edit('location', static function ($data) use ($iplocation) {
|
|
||||||
$location = $iplocation->getlocation($data['location']);
|
|
||||||
return iconv('gbk', 'utf-8//IGNORE', $location['country'] . $location['area']);
|
|
||||||
});
|
|
||||||
|
|
||||||
$body = $response->getBody();
|
|
||||||
$body->write($datatables->generate());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function ajax_unblock($request, $response, $args)
|
|
||||||
{
|
|
||||||
$datatables = new Datatables(new DatatablesHelper());
|
|
||||||
$datatables->query('Select unblockip.id,userid,user.user_name,unblockip.ip,unblockip.ip as location,datetime from unblockip,user WHERE unblockip.userid = user.id');
|
|
||||||
|
|
||||||
$datatables->edit('datetime', static function ($data) {
|
|
||||||
return date('Y-m-d H:i:s', $data['datetime']);
|
|
||||||
});
|
|
||||||
|
|
||||||
$iplocation = new QQWry();
|
|
||||||
|
|
||||||
$datatables->edit('location', static function ($data) use ($iplocation) {
|
|
||||||
$location = $iplocation->getlocation($data['location']);
|
|
||||||
return iconv('gbk', 'utf-8//IGNORE', $location['country'] . $location['area']);
|
|
||||||
});
|
|
||||||
|
|
||||||
$body = $response->getBody();
|
|
||||||
$body->write($datatables->generate());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function ajax_login($request, $response, $args)
|
|
||||||
{
|
|
||||||
$datatables = new Datatables(new DatatablesHelper());
|
|
||||||
$datatables->query('Select login_ip.id,login_ip.userid,user.user_name,login_ip.ip,login_ip.ip as location,login_ip.datetime,login_ip.type from login_ip,user WHERE login_ip.userid = user.id');
|
|
||||||
|
|
||||||
$datatables->edit('datetime', static function ($data) {
|
|
||||||
return date('Y-m-d H:i:s', $data['datetime']);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
$iplocation = new QQWry();
|
|
||||||
$datatables->edit('location', static function ($data) use ($iplocation) {
|
|
||||||
$location = $iplocation->getlocation($data['location']);
|
|
||||||
return iconv('gbk', 'utf-8//IGNORE', $location['country'] . $location['area']);
|
|
||||||
});
|
|
||||||
|
|
||||||
$datatables->edit('type', static function ($data) {
|
|
||||||
return $data['type'] == 0 ? '成功' : '失败';
|
|
||||||
});
|
|
||||||
|
|
||||||
$body = $response->getBody();
|
|
||||||
$body->write($datatables->generate());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function ajax_alive($request, $response, $args)
|
|
||||||
{
|
|
||||||
$datatables = new Datatables(new DatatablesHelper());
|
|
||||||
$datatables->query('Select alive_ip.id,alive_ip.userid,user.user_name,alive_ip.nodeid,ss_node.name as node_name,alive_ip.ip,alive_ip.ip as location,alive_ip.datetime,alive_ip.id as is_node from alive_ip,user,ss_node WHERE alive_ip.userid = user.id and alive_ip.nodeid = ss_node.id and `datetime` > UNIX_TIMESTAMP() - 60');
|
|
||||||
|
|
||||||
$datatables->edit('datetime', static function ($data) {
|
|
||||||
return date('Y-m-d H:i:s', $data['datetime']);
|
|
||||||
});
|
|
||||||
|
|
||||||
$iplocation = new QQWry();
|
|
||||||
|
|
||||||
$datatables->edit('ip', static function ($data) {
|
|
||||||
return Tools::getRealIp($data['ip']);
|
|
||||||
});
|
|
||||||
|
|
||||||
$datatables->edit('is_node', static function ($data) {
|
|
||||||
$is_node = Node::where('node_ip', Tools::getRealIp($data['ip']))->first();
|
|
||||||
if ($is_node) {
|
|
||||||
return '是';
|
|
||||||
}
|
|
||||||
|
|
||||||
return '否';
|
|
||||||
});
|
|
||||||
|
|
||||||
$datatables->edit('location', static function ($data) use ($iplocation) {
|
|
||||||
$location = $iplocation->getlocation(Tools::getRealIp($data['location']));
|
|
||||||
return iconv('gbk', 'utf-8//IGNORE', $location['country'] . $location['area']);
|
|
||||||
});
|
|
||||||
|
|
||||||
$body = $response->getBody();
|
|
||||||
$body->write($datatables->generate());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,381 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Controllers\Admin;
|
|
||||||
|
|
||||||
use App\Models\Relay;
|
|
||||||
use App\Models\Node;
|
|
||||||
use App\Models\User;
|
|
||||||
use App\Utils\Tools;
|
|
||||||
use App\Services\Auth;
|
|
||||||
use App\Controllers\AdminController;
|
|
||||||
use ArrayObject;
|
|
||||||
use Ozdemir\Datatables\Datatables;
|
|
||||||
use App\Utils\DatatablesHelper;
|
|
||||||
|
|
||||||
class RelayController extends AdminController
|
|
||||||
{
|
|
||||||
public function index($request, $response, $args)
|
|
||||||
{
|
|
||||||
$table_config['total_column'] = array('op' => '操作', 'id' => 'ID', 'user_id' => '用户ID',
|
|
||||||
'user_name' => '用户名', 'source_node_name' => '起源节点',
|
|
||||||
'dist_node_name' => '目标节点', 'port' => '端口', 'priority' => '优先级');
|
|
||||||
$table_config['default_show_column'] = array();
|
|
||||||
foreach ($table_config['total_column'] as $column => $value) {
|
|
||||||
$table_config['default_show_column'][] = $column;
|
|
||||||
}
|
|
||||||
$table_config['ajax_url'] = 'relay/ajax';
|
|
||||||
return $this->view()->assign('table_config', $table_config)->display('admin/relay/index.tpl');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function create($request, $response, $args)
|
|
||||||
{
|
|
||||||
$user = Auth::getUser();
|
|
||||||
$source_nodes = Node::where(
|
|
||||||
static function ($query) {
|
|
||||||
$query->Where('sort', 10)
|
|
||||||
->orWhere('sort', 12);
|
|
||||||
}
|
|
||||||
)->orderBy('name')->get();
|
|
||||||
foreach ($source_nodes as $node) {
|
|
||||||
if ($node->sort == 12) {
|
|
||||||
$node->name .= ' 正在使用V2ray后端 ';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$dist_nodes = Node::where(
|
|
||||||
static function ($query) {
|
|
||||||
$query->Where('sort', 0)
|
|
||||||
->orWhere('sort', 10)
|
|
||||||
->orWhere('sort', 11)
|
|
||||||
->orWhere('sort', 12);
|
|
||||||
}
|
|
||||||
)->orderBy('name')->get();
|
|
||||||
|
|
||||||
foreach ($dist_nodes as $node) {
|
|
||||||
if ($node->sort == 11 || $node->sort == 12) {
|
|
||||||
$node_explode = Tools::v2Array($node->server);
|
|
||||||
$node->name = $node->name . ' 如果是V2ray后端 请设置成 ' . $node_explode['port'];
|
|
||||||
} else {
|
|
||||||
$node->name .= ' 如果是V2ray后端 请不要设置,用户页面设置 ';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->view()->assign('source_nodes', $source_nodes)->assign('dist_nodes', $dist_nodes)->display('admin/relay/add.tpl');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function add($request, $response, $args)
|
|
||||||
{
|
|
||||||
$dist_node_id = $request->getParam('dist_node');
|
|
||||||
$source_node_id = $request->getParam('source_node');
|
|
||||||
$port = $request->getParam('port');
|
|
||||||
$priority = $request->getParam('priority');
|
|
||||||
$user_id = $request->getParam('user_id');
|
|
||||||
|
|
||||||
$source_node = Node::where('id', $source_node_id)->first();
|
|
||||||
if ($source_node == null) {
|
|
||||||
$rs['ret'] = 0;
|
|
||||||
$rs['msg'] = '起源节点错误。';
|
|
||||||
return $response->getBody()->write(json_encode($rs));
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($source_node->sort == 12) {
|
|
||||||
$rules = Relay::Where('source_node_id', $source_node_id)->get();
|
|
||||||
if (count($rules) > 0) {
|
|
||||||
$rs['ret'] = 0;
|
|
||||||
$rs['msg'] = 'v2ray中转一个起点一个rule';
|
|
||||||
return $response->getBody()->write(json_encode($rs));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$dist_node = Node::where('id', $dist_node_id)->first();
|
|
||||||
if ($dist_node == null) {
|
|
||||||
$rs['ret'] = 0;
|
|
||||||
$rs['msg'] = '目标节点错误。';
|
|
||||||
return $response->getBody()->write(json_encode($rs));
|
|
||||||
}
|
|
||||||
|
|
||||||
$rule = new Relay();
|
|
||||||
$rule->user_id = $user_id;
|
|
||||||
$rule->dist_node_id = $dist_node_id;
|
|
||||||
|
|
||||||
$dist_node_ip = Tools::getRelayNodeIp($source_node, $dist_node);
|
|
||||||
$rule->dist_ip = $dist_node_ip;
|
|
||||||
|
|
||||||
$rule->source_node_id = $source_node_id;
|
|
||||||
$rule->port = $port;
|
|
||||||
$rule->priority = $priority;
|
|
||||||
|
|
||||||
if ($user_id == 0) {
|
|
||||||
$ruleset = Relay::all();
|
|
||||||
} else {
|
|
||||||
$ruleset = Relay::where('user_id', $user_id)->orwhere('user_id', 0)->get();
|
|
||||||
}
|
|
||||||
$maybe_rule_id = Tools::has_conflict_rule($rule, $ruleset, 0, $rule->source_node_id);
|
|
||||||
if ($maybe_rule_id != 0) {
|
|
||||||
$rs['ret'] = 0;
|
|
||||||
$rs['msg'] = '您即将添加的规则与规则 ID:' . $maybe_rule_id . ' 冲突!';
|
|
||||||
if ($maybe_rule_id == -1) {
|
|
||||||
$rs['msg'] = '您即将添加的规则可能会造成冲突!';
|
|
||||||
}
|
|
||||||
return $response->getBody()->write(json_encode($rs));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$rule->save()) {
|
|
||||||
$rs['ret'] = 0;
|
|
||||||
$rs['msg'] = '添加失败';
|
|
||||||
return $response->getBody()->write(json_encode($rs));
|
|
||||||
}
|
|
||||||
|
|
||||||
$rs['ret'] = 1;
|
|
||||||
$rs['msg'] = '添加成功';
|
|
||||||
return $response->getBody()->write(json_encode($rs));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function edit($request, $response, $args)
|
|
||||||
{
|
|
||||||
$id = $args['id'];
|
|
||||||
|
|
||||||
$user = Auth::getUser();
|
|
||||||
$rule = Relay::where('id', $id)->first();
|
|
||||||
|
|
||||||
if ($rule == null) {
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
$source_nodes = Node::where(
|
|
||||||
static function ($query) {
|
|
||||||
$query->Where('sort', 10)
|
|
||||||
->orWhere('sort', 12);
|
|
||||||
}
|
|
||||||
)->orderBy('name')->get();
|
|
||||||
foreach ($source_nodes as $node) {
|
|
||||||
if ($node->sort == 12) {
|
|
||||||
$node->name .= ' 正在使用V2ray后端 ';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$dist_nodes = Node::where(
|
|
||||||
static function ($query) {
|
|
||||||
$query->Where('sort', 0)
|
|
||||||
->orWhere('sort', 10)
|
|
||||||
->orWhere('sort', 11)
|
|
||||||
->orWhere('sort', 12);
|
|
||||||
}
|
|
||||||
)->orderBy('name')->get();
|
|
||||||
|
|
||||||
foreach ($dist_nodes as $node) {
|
|
||||||
if ($node->sort == 11 || $node->sort == 12) {
|
|
||||||
$node_explode = Tools::v2Array($node->server);
|
|
||||||
$node->name = $node->name . ' 如果是V2ray后端 请设置成' . $node_explode['port'];
|
|
||||||
} else {
|
|
||||||
$node->name .= ' 如果是V2ray后端 请不要设置,用户页面设置 ';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->view()->assign('rule', $rule)->assign('source_nodes', $source_nodes)->assign('dist_nodes', $dist_nodes)->display('admin/relay/edit.tpl');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function update($request, $response, $args)
|
|
||||||
{
|
|
||||||
$id = $args['id'];
|
|
||||||
$rule = Relay::where('id', $id)->first();
|
|
||||||
|
|
||||||
if ($rule == null) {
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
$dist_node_id = $request->getParam('dist_node');
|
|
||||||
$source_node_id = $request->getParam('source_node');
|
|
||||||
$port = $request->getParam('port');
|
|
||||||
$user_id = $request->getParam('user_id');
|
|
||||||
$priority = $request->getParam('priority');
|
|
||||||
|
|
||||||
$source_node = Node::where('id', $source_node_id)->first();
|
|
||||||
if ($source_node == null && $source_node_id != 0) {
|
|
||||||
$rs['ret'] = 0;
|
|
||||||
$rs['msg'] = '起源节点 ID 错误。';
|
|
||||||
return $response->getBody()->write(json_encode($rs));
|
|
||||||
}
|
|
||||||
|
|
||||||
$dist_node = Node::where('id', $dist_node_id)->first();
|
|
||||||
if ($dist_node == null) {
|
|
||||||
$rs['ret'] = 0;
|
|
||||||
$rs['msg'] = '目标节点 ID 错误。';
|
|
||||||
return $response->getBody()->write(json_encode($rs));
|
|
||||||
}
|
|
||||||
|
|
||||||
$rule->user_id = $user_id;
|
|
||||||
$rule->dist_node_id = $dist_node_id;
|
|
||||||
|
|
||||||
$dist_node_ip = Tools::getRelayNodeIp($source_node, $dist_node);
|
|
||||||
$rule->dist_ip = $dist_node_ip;
|
|
||||||
|
|
||||||
$rule->source_node_id = $source_node_id;
|
|
||||||
$rule->port = $port;
|
|
||||||
$rule->priority = $priority;
|
|
||||||
|
|
||||||
if ($user_id == 0) {
|
|
||||||
$ruleset = Relay::all();
|
|
||||||
} else {
|
|
||||||
$ruleset = Relay::where('user_id', $user_id)->orwhere('user_id', 0)->get();
|
|
||||||
}
|
|
||||||
$maybe_rule_id = Tools::has_conflict_rule($rule, $ruleset, $rule->id, $rule->source_node_id);
|
|
||||||
if ($maybe_rule_id != 0) {
|
|
||||||
$rs['ret'] = 0;
|
|
||||||
$rs['msg'] = '您即将添加的规则与规则 ID:' . $maybe_rule_id . ' 冲突!';
|
|
||||||
if ($maybe_rule_id == -1) {
|
|
||||||
$rs['msg'] = '您即将添加的规则可能会造成冲突!';
|
|
||||||
}
|
|
||||||
return $response->getBody()->write(json_encode($rs));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (!$rule->save()) {
|
|
||||||
$rs['ret'] = 0;
|
|
||||||
$rs['msg'] = '修改失败';
|
|
||||||
return $response->getBody()->write(json_encode($rs));
|
|
||||||
}
|
|
||||||
|
|
||||||
$rs['ret'] = 1;
|
|
||||||
$rs['msg'] = '修改成功';
|
|
||||||
return $response->getBody()->write(json_encode($rs));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function delete($request, $response, $args)
|
|
||||||
{
|
|
||||||
$id = $request->getParam('id');
|
|
||||||
$user = Auth::getUser();
|
|
||||||
$rule = Relay::where('id', $id)->first();
|
|
||||||
|
|
||||||
if ($rule == null) {
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$rule->delete()) {
|
|
||||||
$rs['ret'] = 0;
|
|
||||||
$rs['msg'] = '删除失败';
|
|
||||||
return $response->getBody()->write(json_encode($rs));
|
|
||||||
}
|
|
||||||
$rs['ret'] = 1;
|
|
||||||
$rs['msg'] = '删除成功';
|
|
||||||
return $response->getBody()->write(json_encode($rs));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function path_search($request, $response, $args)
|
|
||||||
{
|
|
||||||
$uid = $args['id'];
|
|
||||||
|
|
||||||
$user = User::find($uid);
|
|
||||||
|
|
||||||
if ($user == null) {
|
|
||||||
$pathset = new ArrayObject();
|
|
||||||
return $this->view()->assign('pathset', $pathset)->display('admin/relay/search.tpl');
|
|
||||||
}
|
|
||||||
|
|
||||||
$nodes = Node::where(
|
|
||||||
static function ($query) use ($user) {
|
|
||||||
$query->Where('node_group', '=', $user->node_group)
|
|
||||||
->orWhere('node_group', '=', 0);
|
|
||||||
}
|
|
||||||
)->where(
|
|
||||||
static function ($query) {
|
|
||||||
$query->Where('sort', 10)
|
|
||||||
->orWhere('sort', 12);
|
|
||||||
}
|
|
||||||
)->where('node_class', '<=', $user->class)->orderBy('name')->get();
|
|
||||||
|
|
||||||
$pathset = new ArrayObject();
|
|
||||||
|
|
||||||
$relay_rules = Relay::where('user_id', $user->id)->orwhere('user_id', 0)->get();
|
|
||||||
$mu_nodes = Node::where('sort', 9)->where('node_class', '<=', $user->class)->where('type', '1')->where(
|
|
||||||
static function ($query) use ($user) {
|
|
||||||
$query->where('node_group', '=', $user->node_group)
|
|
||||||
->orWhere('node_group', '=', 0);
|
|
||||||
}
|
|
||||||
)->get();
|
|
||||||
|
|
||||||
foreach ($nodes as $node) {
|
|
||||||
if ($node->mu_only == 0) {
|
|
||||||
$relay_rule = Tools::pick_out_relay_rule($node->id, $user->port, $relay_rules);
|
|
||||||
|
|
||||||
if ($relay_rule != null) {
|
|
||||||
$pathset = Tools::insertPathRule($relay_rule, $pathset, $user->port);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($node->custom_rss == 1) {
|
|
||||||
foreach ($mu_nodes as $mu_node) {
|
|
||||||
$mu_user = User::where('port', '=', $mu_node->server)->first();
|
|
||||||
|
|
||||||
if ($mu_user == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!($mu_user->class >= $node->node_class && ($node->node_group == 0 || $node->node_group == $mu_user->node_group))) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($mu_user->is_multi_user != 2) {
|
|
||||||
$relay_rule = Tools::pick_out_relay_rule($node->id, $mu_user->port, $relay_rules);
|
|
||||||
|
|
||||||
if ($relay_rule != null) {
|
|
||||||
$pathset = Tools::insertPathRule($relay_rule, $pathset, $mu_user->port);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($pathset as $path) {
|
|
||||||
foreach ($pathset as $index => $single_path) {
|
|
||||||
if ($path != $single_path && $path->port == $single_path->port) {
|
|
||||||
if ($single_path->end_node->id == $path->begin_node->id) {
|
|
||||||
$path->begin_node = $single_path->begin_node;
|
|
||||||
if ($path->begin_node->isNodeAccessable() == false) {
|
|
||||||
$path->path = '<font color="#FF0000">' . $single_path->begin_node->name . '</font>' . ' → ' . $path->path;
|
|
||||||
$path->status = '阻断';
|
|
||||||
} else {
|
|
||||||
$path->path = $single_path->begin_node->name . ' → ' . $path->path;
|
|
||||||
$path->status = '通畅';
|
|
||||||
}
|
|
||||||
|
|
||||||
$pathset->offsetUnset($index);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($path->end_node->id == $single_path->begin_node->id) {
|
|
||||||
$path->end_node = $single_path->end_node;
|
|
||||||
if ($single_path->end_node->isNodeAccessable() == false) {
|
|
||||||
$path->path = $path->path . ' → ' . '<font color="#FF0000">' . $single_path->end_node->name . '</font>';
|
|
||||||
$path->status = '阻断';
|
|
||||||
} else {
|
|
||||||
$path->path = $path->path . ' → ' . $single_path->end_node->name;
|
|
||||||
}
|
|
||||||
|
|
||||||
$pathset->offsetUnset($index);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->view()->assign('pathset', $pathset)->display('admin/relay/search.tpl');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function ajax_relay($request, $response, $args)
|
|
||||||
{
|
|
||||||
$datatables = new Datatables(new DatatablesHelper());
|
|
||||||
$datatables->query('Select relay.id as op,relay.id,relay.user_id,user.user_name,source_node.name as source_node_name,dist_node.name as dist_node_name,relay.port,relay.priority from relay,user,ss_node as source_node,ss_node as dist_node WHERE (relay.user_id = user.id or relay.user_id = 0) and source_node.id = relay.source_node_id and dist_node.id = relay.dist_node_id group by id');
|
|
||||||
|
|
||||||
$datatables->edit('op', static function ($data) {
|
|
||||||
return '<a class="btn btn-brand" href="/admin/relay/' . $data['id'] . '/edit">编辑</a>
|
|
||||||
<a class="btn btn-brand-accent" id="delete" value="' . $data['id'] . '" href="javascript:void(0);" onClick="delete_modal_show(\'' . $data['id'] . '\')">删除</a>';
|
|
||||||
});
|
|
||||||
|
|
||||||
$datatables->edit('user_name', static function ($data) {
|
|
||||||
return ($data['user_id'] == 0 ? '全体用户' : $data['user_name']);
|
|
||||||
});
|
|
||||||
|
|
||||||
$body = $response->getBody();
|
|
||||||
$body->write($datatables->generate());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,311 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Controllers\Admin;
|
|
||||||
|
|
||||||
use App\Models\Shop;
|
|
||||||
use App\Models\Bought;
|
|
||||||
use App\Controllers\AdminController;
|
|
||||||
use App\Services\Config;
|
|
||||||
use Ozdemir\Datatables\Datatables;
|
|
||||||
use App\Utils\DatatablesHelper;
|
|
||||||
|
|
||||||
class ShopController extends AdminController
|
|
||||||
{
|
|
||||||
public function index($request, $response, $args)
|
|
||||||
{
|
|
||||||
$table_config['total_column'] = array('op' => '操作', 'id' => 'ID', 'name' => '商品名称',
|
|
||||||
'price' => '价格', 'content' => '商品内容',
|
|
||||||
'auto_renew' => '自动续费', 'auto_reset_bandwidth' => '续费时是否重置流量',
|
|
||||||
'status' => '状态', 'period_sales' => '周期销量');
|
|
||||||
$table_config['default_show_column'] = array();
|
|
||||||
foreach ($table_config['total_column'] as $column => $value) {
|
|
||||||
$table_config['default_show_column'][] = $column;
|
|
||||||
}
|
|
||||||
$table_config['ajax_url'] = 'shop/ajax';
|
|
||||||
return $this->view()->assign('table_config', $table_config)->display('admin/shop/index.tpl');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function create($request, $response, $args)
|
|
||||||
{
|
|
||||||
return $this->view()->display('admin/shop/create.tpl');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function add($request, $response, $args)
|
|
||||||
{
|
|
||||||
$shop = new Shop();
|
|
||||||
$shop->name = $request->getParam('name');
|
|
||||||
$shop->price = $request->getParam('price');
|
|
||||||
$shop->auto_renew = $request->getParam('auto_renew');
|
|
||||||
$shop->auto_reset_bandwidth = $request->getParam('auto_reset_bandwidth');
|
|
||||||
|
|
||||||
$content = array();
|
|
||||||
if ($request->getParam('bandwidth') != 0) {
|
|
||||||
$content['bandwidth'] = $request->getParam('bandwidth');
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($request->getParam('expire') != 0) {
|
|
||||||
$content['expire'] = $request->getParam('expire');
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($request->getParam('class') != 0) {
|
|
||||||
$content['class'] = $request->getParam('class');
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($request->getParam('class_expire') != 0) {
|
|
||||||
$content['class_expire'] = $request->getParam('class_expire');
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($request->getParam('reset') != 0) {
|
|
||||||
$content['reset'] = $request->getParam('reset');
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($request->getParam('reset_value') != 0) {
|
|
||||||
$content['reset_value'] = $request->getParam('reset_value');
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($request->getParam('reset_exp') != 0) {
|
|
||||||
$content['reset_exp'] = $request->getParam('reset_exp');
|
|
||||||
}
|
|
||||||
|
|
||||||
//if ($request->getParam('speedlimit')!=0) {
|
|
||||||
$content['speedlimit'] = $request->getParam('speedlimit');
|
|
||||||
//}
|
|
||||||
|
|
||||||
//if ($request->getParam('connector')!=0) {
|
|
||||||
$content['connector'] = $request->getParam('connector');
|
|
||||||
//}
|
|
||||||
|
|
||||||
if ($request->getParam('content_extra') != '') {
|
|
||||||
$content['content_extra'] = $request->getParam('content_extra');
|
|
||||||
}
|
|
||||||
|
|
||||||
$shop->content = json_encode($content);
|
|
||||||
|
|
||||||
|
|
||||||
if (!$shop->save()) {
|
|
||||||
$rs['ret'] = 0;
|
|
||||||
$rs['msg'] = '添加失败';
|
|
||||||
return $response->getBody()->write(json_encode($rs));
|
|
||||||
}
|
|
||||||
$rs['ret'] = 1;
|
|
||||||
$rs['msg'] = '添加成功';
|
|
||||||
return $response->getBody()->write(json_encode($rs));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function edit($request, $response, $args)
|
|
||||||
{
|
|
||||||
$id = $args['id'];
|
|
||||||
$shop = Shop::find($id);
|
|
||||||
return $this->view()->assign('shop', $shop)->display('admin/shop/edit.tpl');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function update($request, $response, $args)
|
|
||||||
{
|
|
||||||
$id = $args['id'];
|
|
||||||
$shop = Shop::find($id);
|
|
||||||
|
|
||||||
$shop->name = $request->getParam('name');
|
|
||||||
$shop->price = $request->getParam('price');
|
|
||||||
$shop->auto_renew = $request->getParam('auto_renew');
|
|
||||||
|
|
||||||
if ($shop->auto_reset_bandwidth == 1 && $request->getParam('auto_reset_bandwidth') == 0) {
|
|
||||||
$boughts = Bought::where('shopid', $id)->get();
|
|
||||||
|
|
||||||
foreach ($boughts as $bought) {
|
|
||||||
$bought->renew = 0;
|
|
||||||
$bought->save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$shop->auto_reset_bandwidth = $request->getParam('auto_reset_bandwidth');
|
|
||||||
$shop->status = 1;
|
|
||||||
|
|
||||||
$content = array();
|
|
||||||
if ($request->getParam('bandwidth') != 0) {
|
|
||||||
$content['bandwidth'] = $request->getParam('bandwidth');
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($request->getParam('expire') != 0) {
|
|
||||||
$content['expire'] = $request->getParam('expire');
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($request->getParam('class') != 0) {
|
|
||||||
$content['class'] = $request->getParam('class');
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($request->getParam('class_expire') != 0) {
|
|
||||||
$content['class_expire'] = $request->getParam('class_expire');
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($request->getParam('reset') != 0) {
|
|
||||||
$content['reset'] = $request->getParam('reset');
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($request->getParam('reset_value') != 0) {
|
|
||||||
$content['reset_value'] = $request->getParam('reset_value');
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($request->getParam('reset_exp') != 0) {
|
|
||||||
$content['reset_exp'] = $request->getParam('reset_exp');
|
|
||||||
}
|
|
||||||
|
|
||||||
//if ($request->getParam('speedlimit')!=0) {
|
|
||||||
$content['speedlimit'] = $request->getParam('speedlimit');
|
|
||||||
//}
|
|
||||||
|
|
||||||
//if ($request->getParam('connector')!=0) {
|
|
||||||
$content['connector'] = $request->getParam('connector');
|
|
||||||
//}
|
|
||||||
|
|
||||||
if ($request->getParam('content_extra') != '') {
|
|
||||||
$content['content_extra'] = $request->getParam('content_extra');
|
|
||||||
}
|
|
||||||
|
|
||||||
$shop->content = json_encode($content);
|
|
||||||
|
|
||||||
if (!$shop->save()) {
|
|
||||||
$rs['ret'] = 0;
|
|
||||||
$rs['msg'] = '保存失败';
|
|
||||||
return $response->getBody()->write(json_encode($rs));
|
|
||||||
}
|
|
||||||
$rs['ret'] = 1;
|
|
||||||
$rs['msg'] = '保存成功';
|
|
||||||
return $response->getBody()->write(json_encode($rs));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function deleteGet($request, $response, $args)
|
|
||||||
{
|
|
||||||
$id = $request->getParam('id');
|
|
||||||
$shop = Shop::find($id);
|
|
||||||
$shop->status = 0;
|
|
||||||
if (!$shop->save()) {
|
|
||||||
$rs['ret'] = 0;
|
|
||||||
$rs['msg'] = '下架失败';
|
|
||||||
return $response->getBody()->write(json_encode($rs));
|
|
||||||
}
|
|
||||||
|
|
||||||
$boughts = Bought::where('shopid', $id)->get();
|
|
||||||
|
|
||||||
foreach ($boughts as $bought) {
|
|
||||||
$bought->renew = 0;
|
|
||||||
$bought->save();
|
|
||||||
}
|
|
||||||
|
|
||||||
$rs['ret'] = 1;
|
|
||||||
$rs['msg'] = '下架成功';
|
|
||||||
return $response->getBody()->write(json_encode($rs));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function bought($request, $response, $args)
|
|
||||||
{
|
|
||||||
$table_config['total_column'] = array('op' => '操作', 'id' => 'ID',
|
|
||||||
'datetime' => '购买日期', 'content' => '内容',
|
|
||||||
'price' => '价格', 'user_id' => '用户ID',
|
|
||||||
'user_name' => '用户名', 'renew' => '自动续费时间',
|
|
||||||
'auto_reset_bandwidth' => '续费时是否重置流量');
|
|
||||||
$table_config['default_show_column'] = array();
|
|
||||||
foreach ($table_config['total_column'] as $column => $value) {
|
|
||||||
$table_config['default_show_column'][] = $column;
|
|
||||||
}
|
|
||||||
$table_config['ajax_url'] = 'bought/ajax';
|
|
||||||
return $this->view()->assign('table_config', $table_config)->display('admin/shop/bought.tpl');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function deleteBoughtGet($request, $response, $args)
|
|
||||||
{
|
|
||||||
$id = $request->getParam('id');
|
|
||||||
$shop = Bought::find($id);
|
|
||||||
$shop->renew = 0;
|
|
||||||
if (!$shop->save()) {
|
|
||||||
$rs['ret'] = 0;
|
|
||||||
$rs['msg'] = '退订失败';
|
|
||||||
return $response->getBody()->write(json_encode($rs));
|
|
||||||
}
|
|
||||||
$rs['ret'] = 1;
|
|
||||||
$rs['msg'] = '退订成功';
|
|
||||||
return $response->getBody()->write(json_encode($rs));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function ajax_shop($request, $response, $args)
|
|
||||||
{
|
|
||||||
$datatables = new Datatables(new DatatablesHelper());
|
|
||||||
$datatables->query('Select id as op,id,name,price,content,auto_renew,auto_reset_bandwidth,status,id as period_sales from shop');
|
|
||||||
|
|
||||||
$datatables->edit('op', static function ($data) {
|
|
||||||
return '<a class="btn btn-brand" href="/admin/shop/' . $data['id'] . '/edit">编辑</a>
|
|
||||||
<a class="btn btn-brand-accent" ' . ($data['status'] == 0 ? 'disabled' : 'id="row_delete_' . $data['id'] . '" href="javascript:void(0);" onClick="delete_modal_show(\'' . $data['id'] . '\')"') . '>下架</a>';
|
|
||||||
});
|
|
||||||
|
|
||||||
$datatables->edit('content', static function ($data) {
|
|
||||||
$shop = Shop::find($data['id']);
|
|
||||||
return $shop->content();
|
|
||||||
});
|
|
||||||
|
|
||||||
$datatables->edit('auto_renew', static function ($data) {
|
|
||||||
if ($data['auto_renew'] == 0) {
|
|
||||||
return '不自动续费';
|
|
||||||
}
|
|
||||||
|
|
||||||
return $data['auto_renew'] . ' 天后续费';
|
|
||||||
});
|
|
||||||
|
|
||||||
$datatables->edit('auto_reset_bandwidth', static function ($data) {
|
|
||||||
return $data['auto_reset_bandwidth'] == 0 ? '不自动重置' : '自动重置';
|
|
||||||
});
|
|
||||||
|
|
||||||
$datatables->edit('status', static function ($data) {
|
|
||||||
return $data['status'] == 1 ? '上架' : '下架';
|
|
||||||
});
|
|
||||||
|
|
||||||
$datatables->edit('period_sales', static function ($data) {
|
|
||||||
$shop = Shop::find($data['id']);
|
|
||||||
$period = Config::get('sales_period');
|
|
||||||
|
|
||||||
if ($period == 'expire') {
|
|
||||||
$period = json_decode($shop->content, true)['class_expire'];
|
|
||||||
}
|
|
||||||
|
|
||||||
$period = $period * 24 * 60 * 60;
|
|
||||||
$sales = Bought::where('shopid', $shop->id)->where('datetime', '>', time() - $period)->count();
|
|
||||||
return $sales;
|
|
||||||
});
|
|
||||||
|
|
||||||
$body = $response->getBody();
|
|
||||||
$body->write($datatables->generate());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function ajax_bought($request, $response, $args)
|
|
||||||
{
|
|
||||||
$datatables = new Datatables(new DatatablesHelper());
|
|
||||||
$datatables->query('Select bought.id as op,bought.id as id,bought.datetime,shop.id as content,bought.price,user.id as user_id,user.user_name,renew,shop.auto_reset_bandwidth from bought,user,shop where bought.shopid = shop.id and bought.userid = user.id');
|
|
||||||
|
|
||||||
$datatables->edit('op', static function ($data) {
|
|
||||||
return '<a class="btn btn-brand-accent" ' . ($data['renew'] == 0 ? 'disabled' : ' id="row_delete_' . $data['id'] . '" href="javascript:void(0);" onClick="delete_modal_show(\'' . $data['id'] . '\')"') . '>中止</a>';
|
|
||||||
});
|
|
||||||
|
|
||||||
$datatables->edit('content', static function ($data) {
|
|
||||||
$shop = Shop::find($data['content']);
|
|
||||||
return $shop->content();
|
|
||||||
});
|
|
||||||
|
|
||||||
$datatables->edit('renew', static function ($data) {
|
|
||||||
if ($data['renew'] == 0) {
|
|
||||||
return '不自动续费';
|
|
||||||
}
|
|
||||||
|
|
||||||
return date('Y-m-d H:i:s', $data['renew']) . ' 续费';
|
|
||||||
});
|
|
||||||
|
|
||||||
$datatables->edit('auto_reset_bandwidth', static function ($data) {
|
|
||||||
return $data['auto_reset_bandwidth'] == 0 ? '不自动重置' : '自动重置';
|
|
||||||
});
|
|
||||||
|
|
||||||
$datatables->edit('datetime', static function ($data) {
|
|
||||||
return date('Y-m-d H:i:s', $data['datetime']);
|
|
||||||
});
|
|
||||||
|
|
||||||
$body = $response->getBody();
|
|
||||||
$body->write($datatables->generate());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,41 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Controllers\Admin;
|
|
||||||
|
|
||||||
use App\Controllers\AdminController;
|
|
||||||
use App\Utils\QQWry;
|
|
||||||
|
|
||||||
use Ozdemir\Datatables\Datatables;
|
|
||||||
use App\Utils\DatatablesHelper;
|
|
||||||
|
|
||||||
class SubscribeLogController extends AdminController
|
|
||||||
{
|
|
||||||
public function index($request, $response, $args)
|
|
||||||
{
|
|
||||||
$table_config['total_column'] = array('id' => 'ID', 'user_name' => '用户名',
|
|
||||||
'user_id' => '用户ID', 'email' => '用户邮箱', 'subscribe_type' => '类型',
|
|
||||||
'request_ip' => 'IP', 'location' => '归属地', 'request_time' => '时间',
|
|
||||||
'request_user_agent' => 'User-Agent');
|
|
||||||
$table_config['default_show_column'] = array();
|
|
||||||
foreach ($table_config['total_column'] as $column => $value) {
|
|
||||||
$table_config['default_show_column'][] = $column;
|
|
||||||
}
|
|
||||||
$table_config['ajax_url'] = 'subscribe/ajax';
|
|
||||||
return $this->view()->assign('table_config', $table_config)->display('admin/subscribe.tpl');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function ajax_subscribe_log($request, $response, $args)
|
|
||||||
{
|
|
||||||
$datatables = new Datatables(new DatatablesHelper());
|
|
||||||
$datatables->query('Select user_subscribe_log.id,user_subscribe_log.user_name,user_subscribe_log.user_id,user_subscribe_log.email,user_subscribe_log.subscribe_type,user_subscribe_log.request_ip,user_subscribe_log.request_ip as location,user_subscribe_log.request_time,user_subscribe_log.request_user_agent from user_subscribe_log');
|
|
||||||
|
|
||||||
$iplocation = new QQWry();
|
|
||||||
$datatables->edit('location', static function ($data) use ($iplocation) {
|
|
||||||
$location = $iplocation->getlocation($data['location']);
|
|
||||||
return iconv('gbk', 'utf-8//IGNORE', $location['country'] . $location['area']);
|
|
||||||
});
|
|
||||||
|
|
||||||
$body = $response->getBody();
|
|
||||||
$body->write($datatables->generate());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,125 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Controllers\Admin;
|
|
||||||
|
|
||||||
use App\Models\Ticket;
|
|
||||||
use App\Models\User;
|
|
||||||
|
|
||||||
use Exception;
|
|
||||||
use voku\helper\AntiXSS;
|
|
||||||
use App\Services\Auth;
|
|
||||||
|
|
||||||
use App\Services\Mail;
|
|
||||||
use App\Services\Config;
|
|
||||||
|
|
||||||
use Ozdemir\Datatables\Datatables;
|
|
||||||
use App\Utils\DatatablesHelper;
|
|
||||||
|
|
||||||
use App\Controllers\AdminController;
|
|
||||||
|
|
||||||
class TicketController extends AdminController
|
|
||||||
{
|
|
||||||
public function index($request, $response, $args)
|
|
||||||
{
|
|
||||||
$table_config['total_column'] = array('op' => '操作', 'id' => 'ID',
|
|
||||||
'datetime' => '时间', 'title' => '标题', 'userid' => '用户ID',
|
|
||||||
'user_name' => '用户名', 'status' => '状态');
|
|
||||||
$table_config['default_show_column'] = array('op', 'id',
|
|
||||||
'datetime', 'title', 'userid', 'user_name', 'status');
|
|
||||||
$table_config['ajax_url'] = 'ticket/ajax';
|
|
||||||
return $this->view()->assign('table_config', $table_config)->display('admin/ticket/index.tpl');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function update($request, $response, $args)
|
|
||||||
{
|
|
||||||
$id = $args['id'];
|
|
||||||
$content = $request->getParam('content');
|
|
||||||
$status = $request->getParam('status');
|
|
||||||
|
|
||||||
|
|
||||||
if ($content == '' || $status == '') {
|
|
||||||
$res['ret'] = 0;
|
|
||||||
$res['msg'] = '请填全';
|
|
||||||
return $this->echoJson($response, $res);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strpos($content, 'admin') != false || strpos($content, 'user') != false) {
|
|
||||||
$res['ret'] = 0;
|
|
||||||
$res['msg'] = '请求中有不正当的词语。';
|
|
||||||
return $this->echoJson($response, $res);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
$ticket_main = Ticket::where('id', '=', $id)->where('rootid', '=', 0)->first();
|
|
||||||
|
|
||||||
//if($status==1&&$ticket_main->status!=$status)
|
|
||||||
{
|
|
||||||
$adminUser = User::where('id', '=', $ticket_main->userid)->get();
|
|
||||||
foreach ($adminUser as $user) {
|
|
||||||
$subject = Config::get('appName') . '-工单被回复';
|
|
||||||
$to = $user->email;
|
|
||||||
$text = '您好,有人回复了<a href="' . Config::get('baseUrl') . '/user/ticket/' . $ticket_main->id . '/view">工单</a>,请您查看。';
|
|
||||||
try {
|
|
||||||
Mail::send($to, $subject, 'news/warn.tpl', [
|
|
||||||
'user' => $user, 'text' => $text
|
|
||||||
], [
|
|
||||||
]);
|
|
||||||
} catch (Exception $e) {
|
|
||||||
echo $e->getMessage();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$antiXss = new AntiXSS();
|
|
||||||
|
|
||||||
$ticket = new Ticket();
|
|
||||||
$ticket->title = $antiXss->xss_clean($ticket_main->title);
|
|
||||||
$ticket->content = $antiXss->xss_clean($content);
|
|
||||||
$ticket->rootid = $ticket_main->id;
|
|
||||||
$ticket->userid = Auth::getUser()->id;
|
|
||||||
$ticket->datetime = time();
|
|
||||||
$ticket_main->status = $status;
|
|
||||||
|
|
||||||
$ticket_main->save();
|
|
||||||
$ticket->save();
|
|
||||||
|
|
||||||
$res['ret'] = 1;
|
|
||||||
$res['msg'] = '提交成功';
|
|
||||||
return $this->echoJson($response, $res);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function show($request, $response, $args)
|
|
||||||
{
|
|
||||||
$id = $args['id'];
|
|
||||||
|
|
||||||
$pageNum = $request->getQueryParams()['page'] ?? 1;
|
|
||||||
|
|
||||||
|
|
||||||
$ticketset = Ticket::where('id', $id)->orWhere('rootid', '=', $id)->orderBy('datetime', 'desc')->paginate(5, ['*'], 'page', $pageNum);
|
|
||||||
$ticketset->setPath('/admin/ticket/' . $id . '/view');
|
|
||||||
|
|
||||||
return $this->view()->assign('ticketset', $ticketset)->assign('id', $id)->display('admin/ticket/view.tpl');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function ajax($request, $response, $args)
|
|
||||||
{
|
|
||||||
$datatables = new Datatables(new DatatablesHelper());
|
|
||||||
$datatables->query('Select ticket.id as op,ticket.id,ticket.datetime,ticket.title,ticket.userid,user.user_name,ticket.status from ticket,user where ticket.userid = user.id and ticket.rootid = 0');
|
|
||||||
|
|
||||||
$datatables->edit('op', static function ($data) {
|
|
||||||
return '<a class="btn btn-brand" href="/admin/ticket/' . $data['id'] . '/view">查看</a>';
|
|
||||||
});
|
|
||||||
|
|
||||||
$datatables->edit('datetime', static function ($data) {
|
|
||||||
return date('Y-m-d H:i:s', $data['datetime']);
|
|
||||||
});
|
|
||||||
|
|
||||||
$datatables->edit('status', static function ($data) {
|
|
||||||
return $data['status'] == 1 ? '开启' : '关闭';
|
|
||||||
});
|
|
||||||
|
|
||||||
$body = $response->getBody();
|
|
||||||
$body->write($datatables->generate());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,162 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Controllers;
|
|
||||||
|
|
||||||
use App\Models\Node;
|
|
||||||
use App\Models\User;
|
|
||||||
use App\Services\Factory;
|
|
||||||
use App\Services\Config;
|
|
||||||
use App\Utils\Tools;
|
|
||||||
use App\Utils\Hash;
|
|
||||||
use App\Utils\Helper;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ApiController
|
|
||||||
*/
|
|
||||||
class ApiController extends BaseController
|
|
||||||
{
|
|
||||||
public function index()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public function token($request, $response, $args)
|
|
||||||
{
|
|
||||||
$accessToken = $id = $args['token'];
|
|
||||||
$storage = Factory::createTokenStorage();
|
|
||||||
$token = $storage->get($accessToken);
|
|
||||||
if ($token == null) {
|
|
||||||
$res['ret'] = 0;
|
|
||||||
$res['msg'] = 'token is null';
|
|
||||||
return $this->echoJson($response, $res);
|
|
||||||
}
|
|
||||||
$res['ret'] = 1;
|
|
||||||
$res['msg'] = 'ok';
|
|
||||||
$res['data'] = $token;
|
|
||||||
return $this->echoJson($response, $res);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function newToken($request, $response, $args)
|
|
||||||
{
|
|
||||||
// $data = $request->post('sdf');
|
|
||||||
$email = $request->getParam('email');
|
|
||||||
|
|
||||||
$email = strtolower($email);
|
|
||||||
$passwd = $request->getParam('passwd');
|
|
||||||
|
|
||||||
// Handle Login
|
|
||||||
$user = User::where('email', '=', $email)->first();
|
|
||||||
|
|
||||||
if ($user == null) {
|
|
||||||
$res['ret'] = 0;
|
|
||||||
$res['msg'] = '401 邮箱或者密码错误';
|
|
||||||
return $this->echoJson($response, $res);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Hash::checkPassword($user->pass, $passwd)) {
|
|
||||||
$res['ret'] = 0;
|
|
||||||
$res['msg'] = '402 邮箱或者密码错误';
|
|
||||||
return $this->echoJson($response, $res);
|
|
||||||
}
|
|
||||||
$tokenStr = Tools::genToken();
|
|
||||||
$storage = Factory::createTokenStorage();
|
|
||||||
$expireTime = time() + 3600 * 24 * 7;
|
|
||||||
if ($storage->store($tokenStr, $user, $expireTime)) {
|
|
||||||
$res['ret'] = 1;
|
|
||||||
$res['msg'] = 'ok';
|
|
||||||
$res['data']['token'] = $tokenStr;
|
|
||||||
$res['data']['user_id'] = $user->id;
|
|
||||||
return $this->echoJson($response, $res);
|
|
||||||
}
|
|
||||||
$res['ret'] = 0;
|
|
||||||
$res['msg'] = 'system error';
|
|
||||||
return $this->echoJson($response, $res);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function node($request, $response, $args)
|
|
||||||
{
|
|
||||||
$accessToken = Helper::getParam($request, 'access_token');
|
|
||||||
$storage = Factory::createTokenStorage();
|
|
||||||
$token = $storage->get($accessToken);
|
|
||||||
$user = User::find($token->userId);
|
|
||||||
$nodes = Node::where('sort', 0)->where('type', '1')->where(
|
|
||||||
static function ($query) use ($user) {
|
|
||||||
$query->where('node_group', '=', $user->node_group)
|
|
||||||
->orWhere('node_group', '=', 0);
|
|
||||||
}
|
|
||||||
)->orderBy('name')->get();
|
|
||||||
|
|
||||||
$mu_nodes = Node::where('sort', 9)->where('node_class', '<=', $user->class)->where('type', '1')->where(
|
|
||||||
static function ($query) use ($user) {
|
|
||||||
$query->where('node_group', '=', $user->node_group)
|
|
||||||
->orWhere('node_group', '=', 0);
|
|
||||||
}
|
|
||||||
)->orderBy('name')->get();
|
|
||||||
|
|
||||||
$temparray = array();
|
|
||||||
foreach ($nodes as $node) {
|
|
||||||
if ($node->mu_only == 0) {
|
|
||||||
$temparray[] = array('remarks' => $node->name,
|
|
||||||
'server' => $node->server,
|
|
||||||
'server_port' => $user->port,
|
|
||||||
'method' => $node->custom_method == 1 ? $user->method : $node->method,
|
|
||||||
'obfs' => str_replace('_compatible', '', (($node->custom_rss == 1 && !($user->obfs == 'plain' && $user->protocol == 'origin')) ? $user->obfs : 'plain')),
|
|
||||||
'obfsparam' => ($node->custom_rss == 1 && !($user->obfs == 'plain' && $user->protocol == 'origin')) ? $user->obfs_param : '',
|
|
||||||
'remarks_base64' => base64_encode($node->name),
|
|
||||||
'password' => $user->passwd,
|
|
||||||
'tcp_over_udp' => false,
|
|
||||||
'udp_over_tcp' => false,
|
|
||||||
'group' => Config::get('appName'),
|
|
||||||
'protocol' => str_replace('_compatible', '', (($node->custom_rss == 1 && !($user->obfs == 'plain' && $user->protocol == 'origin')) ? $user->protocol : 'origin')),
|
|
||||||
'obfs_udp' => false,
|
|
||||||
'enable' => true);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($node->custom_rss == 1) {
|
|
||||||
foreach ($mu_nodes as $mu_node) {
|
|
||||||
$mu_user = User::where('port', '=', $mu_node->server)->first();
|
|
||||||
$mu_user->obfs_param = $user->getMuMd5();
|
|
||||||
|
|
||||||
$temparray[] = array('remarks' => $node->name . '- ' . $mu_node->server . ' 单端口',
|
|
||||||
'server' => $node->server,
|
|
||||||
'server_port' => $mu_user->port,
|
|
||||||
'method' => $mu_user->method,
|
|
||||||
'group' => Config::get('appName'),
|
|
||||||
'obfs' => str_replace('_compatible', '', (($node->custom_rss == 1 && !($mu_user->obfs == 'plain' && $mu_user->protocol == 'origin')) ? $mu_user->obfs : 'plain')),
|
|
||||||
'obfsparam' => ($node->custom_rss == 1 && !($mu_user->obfs == 'plain' && $mu_user->protocol == 'origin')) ? $mu_user->obfs_param : '',
|
|
||||||
'remarks_base64' => base64_encode($node->name . '- ' . $mu_node->server . ' 单端口'),
|
|
||||||
'password' => $mu_user->passwd,
|
|
||||||
'tcp_over_udp' => false,
|
|
||||||
'udp_over_tcp' => false,
|
|
||||||
'protocol' => str_replace('_compatible', '', (($node->custom_rss == 1 && !($mu_user->obfs == 'plain' && $mu_user->protocol == 'origin')) ? $mu_user->protocol : 'origin')),
|
|
||||||
'obfs_udp' => false,
|
|
||||||
'enable' => true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$res['ret'] = 1;
|
|
||||||
$res['msg'] = 'ok';
|
|
||||||
$res['data'] = $temparray;
|
|
||||||
return $this->echoJson($response, $res);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function userInfo($request, $response, $args)
|
|
||||||
{
|
|
||||||
$id = $args['id'];
|
|
||||||
$accessToken = Helper::getParam($request, 'access_token');
|
|
||||||
$storage = Factory::createTokenStorage();
|
|
||||||
$token = $storage->get($accessToken);
|
|
||||||
if ($id != $token->userId) {
|
|
||||||
$res['ret'] = 0;
|
|
||||||
$res['msg'] = 'access denied';
|
|
||||||
return $this->echoJson($response, $res);
|
|
||||||
}
|
|
||||||
$user = User::find($token->userId);
|
|
||||||
$user->pass = null;
|
|
||||||
$data = $user;
|
|
||||||
$res['ret'] = 1;
|
|
||||||
$res['msg'] = 'ok';
|
|
||||||
$res['data'] = $data;
|
|
||||||
return $this->echoJson($response, $res);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,52 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Controllers;
|
|
||||||
|
|
||||||
use App\Models\User;
|
|
||||||
use App\Services\View;
|
|
||||||
use App\Services\Auth;
|
|
||||||
use Smarty;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* BaseController
|
|
||||||
*/
|
|
||||||
class BaseController
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var Smarty
|
|
||||||
*/
|
|
||||||
protected $view;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var User
|
|
||||||
*/
|
|
||||||
protected $user;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Construct page renderer
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->view = View::getSmarty();
|
|
||||||
$this->user = Auth::getUser();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get smarty
|
|
||||||
*
|
|
||||||
* @return Smarty
|
|
||||||
*/
|
|
||||||
public function view()
|
|
||||||
{
|
|
||||||
return $this->view;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @param $response
|
|
||||||
* @param $res
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function echoJson($response, $res)
|
|
||||||
{
|
|
||||||
return $response->getBody()->write(json_encode($res));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,71 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* Created by PhpStorm.
|
|
||||||
* User: kaguya
|
|
||||||
* Date: 2018/06/30
|
|
||||||
* Time: 21:40
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace App\Controllers\Client;
|
|
||||||
|
|
||||||
|
|
||||||
use App\Controllers\BaseController;
|
|
||||||
use App\Controllers\LinkController;
|
|
||||||
use App\Models\Ann;
|
|
||||||
use App\Models\User;
|
|
||||||
use App\Services\Auth;
|
|
||||||
use App\Services\Config;
|
|
||||||
use App\Services\Factory;
|
|
||||||
use App\Utils\Helper;
|
|
||||||
|
|
||||||
class ClientApiController extends BaseController
|
|
||||||
{
|
|
||||||
public function GetAnnouncement($request, $response, $args)
|
|
||||||
{
|
|
||||||
$accessToken = Helper::getParam($request, 'access_token');
|
|
||||||
$storage = Factory::createTokenStorage();
|
|
||||||
$token = $storage->get($accessToken);
|
|
||||||
$user = User::find($token->userId);
|
|
||||||
$Anns = Ann::orderBy('date', 'desc')->first();
|
|
||||||
$res['ret'] = 1;
|
|
||||||
$res['msg'] = 'ok';
|
|
||||||
$res['data'] = $Anns;
|
|
||||||
return $this->echoJson($response, $res);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function Redirect($request, $response, $args)
|
|
||||||
{
|
|
||||||
$user = Auth::getUser();
|
|
||||||
$url = $request->getQueryParams()['target'];
|
|
||||||
if (!$user->isLogin) {
|
|
||||||
$accessToken = Helper::getParam($request, 'access_token');
|
|
||||||
$storage = Factory::createTokenStorage();
|
|
||||||
$token = $storage->get($accessToken);
|
|
||||||
if ($token == null) {
|
|
||||||
$res['ret'] = 0;
|
|
||||||
$res['msg'] = 'token is null';
|
|
||||||
return $this->echoJson($response, $res);
|
|
||||||
}
|
|
||||||
$user = User::find($token->userId);
|
|
||||||
$time = 3600 * 24;
|
|
||||||
Auth::login($user->id, $time);
|
|
||||||
}
|
|
||||||
return $response->withRedirect($url);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function GetSubLink($request, $response, $args)
|
|
||||||
{
|
|
||||||
$accessToken = Helper::getParam($request, 'access_token');
|
|
||||||
$sub = (Helper::getParam($request, 'sub') != ''
|
|
||||||
? Helper::getParam($request, 'sub')
|
|
||||||
: 1);
|
|
||||||
$storage = Factory::createTokenStorage();
|
|
||||||
$token = $storage->get($accessToken);
|
|
||||||
$user = User::find($token->userId);
|
|
||||||
$ssr_sub_token = LinkController::GenerateSSRSubCode($user->id, 0);
|
|
||||||
$res['ret'] = 1;
|
|
||||||
$res['msg'] = 'ok';
|
|
||||||
$res['data'] = Config::get('subUrl') . $ssr_sub_token . '?sub=' . $sub;
|
|
||||||
return $this->echoJson($response, $res);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,575 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 部分应用自定义配置
|
|
||||||
*
|
|
||||||
* PHP version 7.2+
|
|
||||||
*
|
|
||||||
* @category GeekQu
|
|
||||||
* @package App/Controllers/ConfController
|
|
||||||
* @author GeekQu <iloves@live.com>
|
|
||||||
* @license MIT https://github.com/GeekQu/ss-panel-v3-mod_Uim/blob/dev/LICENSE
|
|
||||||
* @link https://github.com/GeekQu
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace App\Controllers;
|
|
||||||
|
|
||||||
use App\Models\User;
|
|
||||||
use App\Services\Config;
|
|
||||||
use App\Utils\ConfRender;
|
|
||||||
use Symfony\Component\Yaml\Yaml;
|
|
||||||
use Symfony\Component\Yaml\Exception\ParseException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ConfController
|
|
||||||
*
|
|
||||||
* @category GeekQu
|
|
||||||
* @package App/Controllers/ConfController
|
|
||||||
* @author GeekQu <iloves@live.com>
|
|
||||||
* @license MIT https://github.com/GeekQu/ss-panel-v3-mod_Uim/blob/dev/LICENSE
|
|
||||||
* @link https://github.com/GeekQu
|
|
||||||
*/
|
|
||||||
class ConfController extends BaseController
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* YAML 转数组
|
|
||||||
*
|
|
||||||
* @param string $Content YAML 字符串
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function YAML2Array($Content)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
return Yaml::parse($Content);
|
|
||||||
} catch (ParseException $exception) {
|
|
||||||
return printf('无法解析 YAML 字符串: %s', $exception->getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 从远端自定义配置文件生成 Surge 托管配置
|
|
||||||
*
|
|
||||||
* @param object $User 用户
|
|
||||||
* @param string $AllProxys Surge 格式的全部节点
|
|
||||||
* @param array $Nodes 全部节点数组
|
|
||||||
* @param string $SourceContent 远程配置内容
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function getSurgeConfs($User, $AllProxys, $Nodes, $Configs, $local = false)
|
|
||||||
{
|
|
||||||
$General = self::getSurgeConfGeneral($Configs['General']);
|
|
||||||
$Proxys = (isset($Configs['Proxy'])
|
|
||||||
? self::getSurgeConfProxy($Configs['Proxy'])
|
|
||||||
: '');
|
|
||||||
|
|
||||||
if (isset($Configs['Proxy Group'])) {
|
|
||||||
$Configs['ProxyGroup'] = $Configs['Proxy Group'];
|
|
||||||
}
|
|
||||||
$ProxyGroups = self::getSurgeConfProxyGroup(
|
|
||||||
$Nodes,
|
|
||||||
$Configs['ProxyGroup']
|
|
||||||
);
|
|
||||||
$ProxyGroup = self::getSurgeProxyGroup2String($ProxyGroups);
|
|
||||||
|
|
||||||
$Rule = self::getSurgeConfRule($Configs['Rule'], $local);
|
|
||||||
$Conf = '#!MANAGED-CONFIG '
|
|
||||||
. Config::get('baseUrl') . $_SERVER['REQUEST_URI'] .
|
|
||||||
"\n\n#---------------------------------------------------#" .
|
|
||||||
"\n## 上次更新于:" . date("Y-m-d h:i:s") .
|
|
||||||
"\n#---------------------------------------------------#" .
|
|
||||||
"\n\n[General]"
|
|
||||||
. $General .
|
|
||||||
"\n\n[Proxy]\n"
|
|
||||||
. $AllProxys . $Proxys .
|
|
||||||
"\n\n[Proxy Group]"
|
|
||||||
. $ProxyGroup .
|
|
||||||
"\n\n[Rule]\n"
|
|
||||||
. $Rule;
|
|
||||||
|
|
||||||
return $Conf;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Surge 配置中的 General
|
|
||||||
*
|
|
||||||
* @param array $General Surge General 定义
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function getSurgeConfGeneral($General)
|
|
||||||
{
|
|
||||||
$return = '';
|
|
||||||
if (count($General) != 0) {
|
|
||||||
foreach ($General as $key => $value) {
|
|
||||||
$return .= "\n$key = $value";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Surge 配置中的 Proxy
|
|
||||||
*
|
|
||||||
* @param array $Proxys 自定义配置中的额外 Proxy
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function getSurgeConfProxy($Proxys)
|
|
||||||
{
|
|
||||||
$return = '';
|
|
||||||
if (count($Proxys) != 0) {
|
|
||||||
foreach ($Proxys as $value) {
|
|
||||||
if (!preg_match('/(\[General|Replica|Proxy|Proxy\sGroup|Rule|Host|URL\sRewrite|Header\sRewrite|MITM|Script\])/', $value)) {
|
|
||||||
$return .= "\n$value";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Surge 配置中的 ProxyGroup
|
|
||||||
*
|
|
||||||
* @param array $Nodes 全部节点数组
|
|
||||||
* @param array $ProxyGroups Surge 策略组定义
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public static function getSurgeConfProxyGroup($Nodes, $ProxyGroups)
|
|
||||||
{
|
|
||||||
$return = [];
|
|
||||||
foreach ($ProxyGroups as $ProxyGroup) {
|
|
||||||
if (in_array($ProxyGroup['type'], ['select', 'url-test', 'fallback'])) {
|
|
||||||
$proxies = [];
|
|
||||||
if (
|
|
||||||
isset($ProxyGroup['content']['left-proxies'])
|
|
||||||
&& count($ProxyGroup['content']['left-proxies']) != 0
|
|
||||||
) {
|
|
||||||
$proxies = $ProxyGroup['content']['left-proxies'];
|
|
||||||
}
|
|
||||||
foreach ($Nodes as $item) {
|
|
||||||
$item = self::getMatchProxy($item, $ProxyGroup);
|
|
||||||
if ($item !== null && !in_array($item['remark'], $proxies)) {
|
|
||||||
$proxies[] = $item['remark'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (isset($ProxyGroup['content']['right-proxies'])) {
|
|
||||||
$proxies = array_merge($proxies, $ProxyGroup['content']['right-proxies']);
|
|
||||||
}
|
|
||||||
$ProxyGroup['proxies'] = $proxies;
|
|
||||||
}
|
|
||||||
$return[] = $ProxyGroup;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取匹配的节点
|
|
||||||
*
|
|
||||||
* @param array $Proxy 节点
|
|
||||||
* @param array $Rule 匹配规则
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public static function getMatchProxy($Proxy, $Rule)
|
|
||||||
{
|
|
||||||
$return = null;
|
|
||||||
switch (true) {
|
|
||||||
case (isset($Rule['content']['class'])):
|
|
||||||
if ($Proxy['class'] == $Rule['content']['class']) {
|
|
||||||
if (isset($Rule['content']['regex'])) {
|
|
||||||
if (preg_match('/' . $Rule['content']['regex'] . '/i', $Proxy['remark'])) {
|
|
||||||
$return = $Proxy;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$return = $Proxy;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case (isset($Rule['content']['noclass'])):
|
|
||||||
if ($Proxy['class'] != $Rule['content']['noclass']) {
|
|
||||||
if (isset($Rule['content']['regex'])) {
|
|
||||||
if (preg_match('/' . $Rule['content']['regex'] . '/i', $Proxy['remark'])) {
|
|
||||||
$return = $Proxy;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$return = $Proxy;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case (!isset($Rule['content']['class'])
|
|
||||||
&& !isset($Rule['content']['noclass'])
|
|
||||||
&& isset($Rule['content']['regex'])
|
|
||||||
&& preg_match('/' . $Rule['content']['regex'] . '/i', $Proxy['remark'])
|
|
||||||
):
|
|
||||||
$return = $Proxy;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Surge ProxyGroup 去除无用策略组
|
|
||||||
*
|
|
||||||
* @param array $ProxyGroups 策略组
|
|
||||||
* @param array $checks 要检查的策略组名
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public static function fixSurgeProxyGroup($ProxyGroups, $checks)
|
|
||||||
{
|
|
||||||
if (count($checks) == 0) {
|
|
||||||
return $ProxyGroups;
|
|
||||||
}
|
|
||||||
$clean_names = [];
|
|
||||||
$newProxyGroups = [];
|
|
||||||
foreach ($ProxyGroups as $ProxyGroup) {
|
|
||||||
if (in_array($ProxyGroup['name'], $checks) && count($ProxyGroup['proxies']) == 0) {
|
|
||||||
$clean_names[] = $ProxyGroup['name'];
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$newProxyGroups[] = $ProxyGroup;
|
|
||||||
}
|
|
||||||
if (count($clean_names) >= 1) {
|
|
||||||
$ProxyGroups = $newProxyGroups;
|
|
||||||
$newProxyGroups = [];
|
|
||||||
foreach ($ProxyGroups as $ProxyGroup) {
|
|
||||||
if (!in_array($ProxyGroup['name'], $checks) && $ProxyGroup['type'] != 'ssid') {
|
|
||||||
$newProxies = [];
|
|
||||||
foreach ($ProxyGroup['proxies'] as $proxie) {
|
|
||||||
if (!in_array($proxie, $clean_names)) {
|
|
||||||
$newProxies[] = $proxie;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$ProxyGroup['proxies'] = $newProxies;
|
|
||||||
}
|
|
||||||
$newProxyGroups[] = $ProxyGroup;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $newProxyGroups;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Surge ProxyGroup 转字符串
|
|
||||||
*
|
|
||||||
* @param array $ProxyGroups Surge 策略组定义
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function getSurgeProxyGroup2String($ProxyGroups)
|
|
||||||
{
|
|
||||||
$return = '';
|
|
||||||
foreach ($ProxyGroups as $ProxyGroup) {
|
|
||||||
$str = '';
|
|
||||||
if (in_array($ProxyGroup['type'], ['select', 'url-test', 'fallback'])) {
|
|
||||||
$proxies = implode(', ', $ProxyGroup['proxies']);
|
|
||||||
if (in_array($ProxyGroup['type'], ['url-test', 'fallback'])) {
|
|
||||||
$str .= ($ProxyGroup['name']
|
|
||||||
. ' = '
|
|
||||||
. $ProxyGroup['type']
|
|
||||||
. ', '
|
|
||||||
. $proxies
|
|
||||||
. ', url = ' . $ProxyGroup['url']
|
|
||||||
. ', interval = ' . $ProxyGroup['interval']);
|
|
||||||
} else {
|
|
||||||
$str .= ($ProxyGroup['name']
|
|
||||||
. ' = '
|
|
||||||
. $ProxyGroup['type']
|
|
||||||
. ', '
|
|
||||||
. $proxies);
|
|
||||||
}
|
|
||||||
} elseif ($ProxyGroup['type'] == 'ssid') {
|
|
||||||
$wifi = '';
|
|
||||||
foreach ($ProxyGroup['content'] as $key => $value) {
|
|
||||||
$wifi .= ', "' . $key . '" = ' . $value;
|
|
||||||
}
|
|
||||||
$cellular = (isset($ProxyGroup['cellular'])
|
|
||||||
? ', cellular = ' . $ProxyGroup['cellular']
|
|
||||||
: '');
|
|
||||||
$str .= ($ProxyGroup['name']
|
|
||||||
. ' = '
|
|
||||||
. $ProxyGroup['type']
|
|
||||||
. ', default = '
|
|
||||||
. $ProxyGroup['default']
|
|
||||||
. $cellular
|
|
||||||
. $wifi);
|
|
||||||
} else {
|
|
||||||
$str .= '';
|
|
||||||
}
|
|
||||||
$return .= "\n$str";
|
|
||||||
}
|
|
||||||
return $return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Surge 配置中的 Rule
|
|
||||||
*
|
|
||||||
* @param array $Rules Surge 规则加载地址
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function getSurgeConfRule($Rules, $local)
|
|
||||||
{
|
|
||||||
// 加载本地规则文件
|
|
||||||
if ($local) {
|
|
||||||
$render = ConfRender::getTemplateRender();
|
|
||||||
return $render->fetch(trim($Rules['source']));
|
|
||||||
}
|
|
||||||
|
|
||||||
// 加载远程规则文件
|
|
||||||
$return = '';
|
|
||||||
if (isset($Rules['source']) && $Rules['source'] != '') {
|
|
||||||
$sourceURL = trim($Rules['source']);
|
|
||||||
// 远程规则仅支持 github 以及 gitlab
|
|
||||||
if (preg_match('/^https:\/\/((gist\.)?github\.com|raw\.githubusercontent\.com|gitlab\.com)/i', $sourceURL)) {
|
|
||||||
$return = @file_get_contents($sourceURL);
|
|
||||||
if (!$return) {
|
|
||||||
$return = ('// 远程规则加载失败'
|
|
||||||
. PHP_EOL
|
|
||||||
. 'GEOIP,CN,DIRECT'
|
|
||||||
. PHP_EOL
|
|
||||||
. 'FINAL,DIRECT,dns-failed');
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$return = ('// 远程规则仅支持 github 以及 gitlab'
|
|
||||||
. PHP_EOL
|
|
||||||
. 'GEOIP,CN,DIRECT'
|
|
||||||
. PHP_EOL
|
|
||||||
. 'FINAL,DIRECT,dns-failed');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 从远端自定义配置文件生成 Clash 配置
|
|
||||||
*
|
|
||||||
* @param object $User 用户
|
|
||||||
* @param array $AllProxys 全部节点数组
|
|
||||||
* @param string $SourceContent 远程配置内容
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function getClashConfs($User, $AllProxys, $Configs, $local = false)
|
|
||||||
{
|
|
||||||
if (isset($Configs['Proxy']) || count($Configs['Proxy']) != 0) {
|
|
||||||
$tmpProxys = array_merge($AllProxys, $Configs['Proxy']);
|
|
||||||
} else {
|
|
||||||
$tmpProxys = $AllProxys;
|
|
||||||
}
|
|
||||||
$Proxys = [];
|
|
||||||
foreach ($tmpProxys as $Proxy) {
|
|
||||||
unset($Proxy['class']);
|
|
||||||
$Proxys[] = $Proxy;
|
|
||||||
}
|
|
||||||
$tmp = self::getClashConfGeneral($Configs['General']);
|
|
||||||
$tmp['Proxy'] = $Proxys;
|
|
||||||
if (isset($Configs['ProxyGroup'])) {
|
|
||||||
$tmp['Proxy Group'] = self::getClashConfProxyGroup(
|
|
||||||
$AllProxys,
|
|
||||||
$Configs['ProxyGroup']
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
$tmp['Proxy Group'] = self::getClashConfProxyGroup(
|
|
||||||
$AllProxys,
|
|
||||||
$Configs['Proxy Group']
|
|
||||||
);
|
|
||||||
}
|
|
||||||
$Conf = '#!MANAGED-CONFIG '
|
|
||||||
. Config::get('baseUrl') . $_SERVER['REQUEST_URI'] .
|
|
||||||
"\n\n#---------------------------------------------------#" .
|
|
||||||
"\n## 上次更新于:" . date("Y-m-d h:i:s") .
|
|
||||||
"\n#---------------------------------------------------#" .
|
|
||||||
"\n\n"
|
|
||||||
. Yaml::dump($tmp, 4, 2) .
|
|
||||||
"\n\n"
|
|
||||||
. self::getClashConfRule($Configs['Rule'], $local);
|
|
||||||
|
|
||||||
return $Conf;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Clash 配置中的 General
|
|
||||||
*
|
|
||||||
* @param array $General Clash General 定义
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public static function getClashConfGeneral($General)
|
|
||||||
{
|
|
||||||
if (count($General) != 0) {
|
|
||||||
foreach ($General as $key) {
|
|
||||||
if (in_array(
|
|
||||||
$key,
|
|
||||||
[
|
|
||||||
'Proxy',
|
|
||||||
'Proxy Group',
|
|
||||||
'Rule'
|
|
||||||
]
|
|
||||||
)) {
|
|
||||||
unset($key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $General;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Clash 配置中的 ProxyGroup
|
|
||||||
*
|
|
||||||
* @param array $Nodes 全部节点数组
|
|
||||||
* @param array $ProxyGroups Clash 策略组定义
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public static function getClashConfProxyGroup($Nodes, $ProxyGroups)
|
|
||||||
{
|
|
||||||
$return = [];
|
|
||||||
foreach ($ProxyGroups as $ProxyGroup) {
|
|
||||||
$tmp = [];
|
|
||||||
if (in_array($ProxyGroup['type'], ['select', 'url-test', 'fallback', 'load-balance'])) {
|
|
||||||
$proxies = [];
|
|
||||||
if (
|
|
||||||
isset($ProxyGroup['content']['left-proxies'])
|
|
||||||
&& count($ProxyGroup['content']['left-proxies']) != 0
|
|
||||||
) {
|
|
||||||
$proxies = $ProxyGroup['content']['left-proxies'];
|
|
||||||
}
|
|
||||||
foreach ($Nodes as $item) {
|
|
||||||
$item['remark'] = $item['name'];
|
|
||||||
$item = self::getMatchProxy($item, $ProxyGroup);
|
|
||||||
if ($item !== null && !in_array($item['name'], $proxies)) {
|
|
||||||
$proxies[] = $item['name'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (isset($ProxyGroup['content']['right-proxies'])) {
|
|
||||||
$proxies = array_merge($proxies, $ProxyGroup['content']['right-proxies']);
|
|
||||||
}
|
|
||||||
$tmp = [
|
|
||||||
'name' => $ProxyGroup['name'],
|
|
||||||
'type' => $ProxyGroup['type'],
|
|
||||||
'proxies' => $proxies
|
|
||||||
];
|
|
||||||
if ($ProxyGroup['type'] != 'select') {
|
|
||||||
$tmp['url'] = $ProxyGroup['url'];
|
|
||||||
$tmp['interval'] = $ProxyGroup['interval'];
|
|
||||||
}
|
|
||||||
$return[] = $tmp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Clash 配置中的 Rule
|
|
||||||
*
|
|
||||||
* @param array $Rules Clash 规则加载地址
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function getClashConfRule($Rules, $local)
|
|
||||||
{
|
|
||||||
// 加载本地规则文件
|
|
||||||
if ($local) {
|
|
||||||
$render = ConfRender::getTemplateRender();
|
|
||||||
return $render->fetch(trim($Rules['source']));
|
|
||||||
}
|
|
||||||
|
|
||||||
// 加载远程规则文件
|
|
||||||
$return = ('Rule:' . PHP_EOL);
|
|
||||||
if (isset($Rules['source']) && $Rules['source'] != '') {
|
|
||||||
$sourceURL = trim($Rules['source']);
|
|
||||||
// 远程规则仅支持 github 以及 gitlab
|
|
||||||
if (preg_match('/^https:\/\/((gist\.)?github\.com|raw\.githubusercontent\.com|gitlab\.com)/i', $sourceURL)) {
|
|
||||||
$sourceContent = @file_get_contents($sourceURL);
|
|
||||||
if (!$sourceContent) {
|
|
||||||
$return .= ('// 远程规则加载失败'
|
|
||||||
. PHP_EOL
|
|
||||||
. 'GEOIP,CN,DIRECT'
|
|
||||||
. PHP_EOL
|
|
||||||
. 'MATCH,DIRECT');
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
$sourceRule = Yaml::parse($sourceContent);
|
|
||||||
} catch (ParseException $exception) {
|
|
||||||
$sourceRule['error'] = printf('无法解析 YAML 字符串: %s', $exception->getMessage());
|
|
||||||
}
|
|
||||||
if (isset($sourceRule['error']) || !isset($sourceRule['Rule'])) {
|
|
||||||
$return .= $sourceContent;
|
|
||||||
} else {
|
|
||||||
$return .= Yaml::dump($sourceRule['Rule'], 4, 2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$return .= ('// 远程规则仅支持 github 以及 gitlab'
|
|
||||||
. PHP_EOL
|
|
||||||
. 'GEOIP,CN,DIRECT'
|
|
||||||
. PHP_EOL
|
|
||||||
. 'MATCH,DIRECT');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Clash ProxyGroup 去除无用策略组
|
|
||||||
*
|
|
||||||
* @param array $ProxyGroups 策略组
|
|
||||||
* @param array $checks 要检查的策略组名
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public static function fixClashProxyGroup($ProxyGroups, $checks)
|
|
||||||
{
|
|
||||||
if (count($checks) == 0) {
|
|
||||||
return $ProxyGroups;
|
|
||||||
}
|
|
||||||
$clean_names = [];
|
|
||||||
$newProxyGroups = [];
|
|
||||||
foreach ($ProxyGroups as $ProxyGroup) {
|
|
||||||
if (in_array($ProxyGroup['name'], $checks) && count($ProxyGroup['proxies']) == 0) {
|
|
||||||
$clean_names[] = $ProxyGroup['name'];
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$newProxyGroups[] = $ProxyGroup;
|
|
||||||
}
|
|
||||||
if (count($clean_names) >= 1) {
|
|
||||||
$ProxyGroups = $newProxyGroups;
|
|
||||||
$newProxyGroups = [];
|
|
||||||
foreach ($ProxyGroups as $ProxyGroup) {
|
|
||||||
if (!in_array($ProxyGroup['name'], $checks)) {
|
|
||||||
$newProxies = [];
|
|
||||||
foreach ($ProxyGroup['proxies'] as $proxie) {
|
|
||||||
if (!in_array($proxie, $clean_names)) {
|
|
||||||
$newProxies[] = $proxie;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$ProxyGroup['proxies'] = $newProxies;
|
|
||||||
}
|
|
||||||
$newProxyGroups[] = $ProxyGroup;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $newProxyGroups;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Clash ProxyGroup 转字符串
|
|
||||||
*
|
|
||||||
* @param array $ProxyGroups ProxyGroup
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function getClashProxyGroup2String($ProxyGroups)
|
|
||||||
{
|
|
||||||
return Yaml::dump($ProxyGroups, 4, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 待续 Quantumult...
|
|
||||||
}
|
|
||||||
@ -1,259 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Controllers;
|
|
||||||
|
|
||||||
use App\Models\InviteCode;
|
|
||||||
use App\Services\Auth;
|
|
||||||
use App\Services\Config;
|
|
||||||
use App\Utils\AliPay;
|
|
||||||
use App\Utils\TelegramSessionManager;
|
|
||||||
use App\Utils\TelegramProcess;
|
|
||||||
use App\Utils\Spay_tool;
|
|
||||||
use App\Utils\Geetest;
|
|
||||||
use App\Utils\Tools;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* HomeController
|
|
||||||
*/
|
|
||||||
class HomeController extends BaseController
|
|
||||||
{
|
|
||||||
public function index()
|
|
||||||
{
|
|
||||||
$GtSdk = null;
|
|
||||||
$recaptcha_sitekey = null;
|
|
||||||
if (Config::get('captcha_provider') != '') {
|
|
||||||
switch (Config::get('captcha_provider')) {
|
|
||||||
case 'recaptcha':
|
|
||||||
$recaptcha_sitekey = Config::get('recaptcha_sitekey');
|
|
||||||
break;
|
|
||||||
case 'geetest':
|
|
||||||
$uid = time() . random_int(1, 10000);
|
|
||||||
$GtSdk = Geetest::get($uid);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Config::get('enable_telegram') == 'true') {
|
|
||||||
$login_text = TelegramSessionManager::add_login_session();
|
|
||||||
$login = explode('|', $login_text);
|
|
||||||
$login_token = $login[0];
|
|
||||||
$login_number = $login[1];
|
|
||||||
} else {
|
|
||||||
$login_token = '';
|
|
||||||
$login_number = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Config::get('newIndex') != 'true' && Config::get('theme') == 'material') {
|
|
||||||
return $this->view()->display('indexold.tpl');
|
|
||||||
} else {
|
|
||||||
return $this->view()
|
|
||||||
->assign('geetest_html', $GtSdk)
|
|
||||||
->assign('login_token', $login_token)
|
|
||||||
->assign('login_number', $login_number)
|
|
||||||
->assign('telegram_bot', Config::get('telegram_bot'))
|
|
||||||
->assign('enable_logincaptcha', Config::get('enable_login_captcha'))
|
|
||||||
->assign('enable_regcaptcha', Config::get('enable_reg_captcha'))
|
|
||||||
->assign('base_url', Config::get('baseUrl'))
|
|
||||||
->assign('recaptcha_sitekey', $recaptcha_sitekey)
|
|
||||||
->display('index.tpl');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function indexold()
|
|
||||||
{
|
|
||||||
return $this->view()->display('indexold.tpl');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function code()
|
|
||||||
{
|
|
||||||
$codes = InviteCode::where('user_id', '=', '0')->take(10)->get();
|
|
||||||
return $this->view()->assign('codes', $codes)->display('code.tpl');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function down()
|
|
||||||
{ }
|
|
||||||
|
|
||||||
public function tos()
|
|
||||||
{
|
|
||||||
return $this->view()->display('tos.tpl');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function staff()
|
|
||||||
{
|
|
||||||
return $this->view()->display('staff.tpl');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function telegram($request, $response, $args)
|
|
||||||
{
|
|
||||||
$token = $request->getQueryParams()['token'] ?? '';
|
|
||||||
|
|
||||||
if ($token == Config::get('telegram_request_token')) {
|
|
||||||
TelegramProcess::process();
|
|
||||||
} else {
|
|
||||||
echo ('不正确请求!');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function page404($request, $response, $args)
|
|
||||||
{
|
|
||||||
return $this->view()->display('404.tpl');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function page405($request, $response, $args)
|
|
||||||
{
|
|
||||||
return $this->view()->display('405.tpl');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function page500($request, $response, $args)
|
|
||||||
{
|
|
||||||
return $this->view()->display('500.tpl');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getOrderList($request, $response, $args)
|
|
||||||
{
|
|
||||||
$key = $request->getParam('key');
|
|
||||||
if (!$key || $key != Config::get('key')) {
|
|
||||||
$res['ret'] = 0;
|
|
||||||
$res['msg'] = '错误';
|
|
||||||
return $response->getBody()->write(json_encode($res));
|
|
||||||
}
|
|
||||||
return $response->getBody()->write(json_encode(['data' => AliPay::getList()]));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setOrder($request, $response, $args)
|
|
||||||
{
|
|
||||||
$key = $request->getParam('key');
|
|
||||||
$sn = $request->getParam('sn');
|
|
||||||
$url = $request->getParam('url');
|
|
||||||
if (!$key || $key != Config::get('key')) {
|
|
||||||
$res['ret'] = 0;
|
|
||||||
$res['msg'] = '错误';
|
|
||||||
return $response->getBody()->write(json_encode($res));
|
|
||||||
}
|
|
||||||
return $response->getBody()->write(json_encode(['res' => AliPay::setOrder($sn, $url)]));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getDocCenter($request, $response, $args)
|
|
||||||
{
|
|
||||||
$user = Auth::getUser();
|
|
||||||
if (!$user->isLogin && Config::get('enable_documents') != 'true') {
|
|
||||||
$newResponse = $response->withStatus(302)->withHeader('Location', '/');
|
|
||||||
return $newResponse;
|
|
||||||
}
|
|
||||||
$basePath = Config::get('remote_documents') == 'true' ? Config::get('documents_source') : '/docs/GeekQu';
|
|
||||||
return $this->view()
|
|
||||||
->assign('appName', Config::get('documents_name'))
|
|
||||||
->assign('basePath', $basePath)
|
|
||||||
->display('doc/index.tpl');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getSubLink($request, $response, $args)
|
|
||||||
{
|
|
||||||
$user = Auth::getUser();
|
|
||||||
if (!$user->isLogin) {
|
|
||||||
return $msg = '!> ₍₍ ◝(・ω・)◟ ⁾⁾ 您没有登录噢,[点击此处登录](/auth/login \':ignore target=_blank\') 之后再刷新就阔以了啦';
|
|
||||||
} else {
|
|
||||||
$subInfo = LinkController::getSubinfo($user, 0);
|
|
||||||
switch ($request->getParam('type')) {
|
|
||||||
case 'ssr':
|
|
||||||
$msg = [
|
|
||||||
'**订阅链接:**',
|
|
||||||
'```',
|
|
||||||
$subInfo['ssr'] . '&extend=1',
|
|
||||||
'```'
|
|
||||||
];
|
|
||||||
break;
|
|
||||||
case 'v2ray':
|
|
||||||
$msg = [
|
|
||||||
'**订阅链接:**',
|
|
||||||
'```',
|
|
||||||
$subInfo['v2ray'] . '&extend=1',
|
|
||||||
'```'
|
|
||||||
];
|
|
||||||
break;
|
|
||||||
case 'ssd':
|
|
||||||
$msg = [
|
|
||||||
'**订阅链接:**',
|
|
||||||
'```',
|
|
||||||
$subInfo['ssd'],
|
|
||||||
'```'
|
|
||||||
];
|
|
||||||
break;
|
|
||||||
case 'clash':
|
|
||||||
$msg = [
|
|
||||||
'**订阅链接:**[[点击下载配置]](' . $subInfo['clash'] . ')',
|
|
||||||
'```',
|
|
||||||
$subInfo['clash'],
|
|
||||||
'```'
|
|
||||||
];
|
|
||||||
break;
|
|
||||||
case 'surge':
|
|
||||||
$msg = [
|
|
||||||
'**Surge Version 2.x 托管配置链接:**[[iOS 点击此处一键添加]](surge:///install-config?url=' . urlencode($subInfo['surge2']) . ')',
|
|
||||||
'```',
|
|
||||||
$subInfo['surge2'],
|
|
||||||
'```',
|
|
||||||
'**Surge Version 3.x 托管配置链接:**[[iOS 点击此处一键添加]](surge3:///install-config?url=' . urlencode($subInfo['surge3']) . ')',
|
|
||||||
'```',
|
|
||||||
$subInfo['surge3'],
|
|
||||||
'```'
|
|
||||||
];
|
|
||||||
break;
|
|
||||||
case 'kitsunebi':
|
|
||||||
$msg = [
|
|
||||||
'**包含 ss、v2ray 的合并订阅链接:**',
|
|
||||||
'```',
|
|
||||||
$subInfo['kitsunebi'] . '&extend=1',
|
|
||||||
'```'
|
|
||||||
];
|
|
||||||
break;
|
|
||||||
case 'surfboard':
|
|
||||||
$msg = [
|
|
||||||
'**托管配置链接:**',
|
|
||||||
'```',
|
|
||||||
$subInfo['surfboard'],
|
|
||||||
'```'
|
|
||||||
];
|
|
||||||
break;
|
|
||||||
case 'quantumult_sub':
|
|
||||||
$msg = [
|
|
||||||
'**ssr 订阅链接:**[[iOS 点击此处一键添加]](quantumult://configuration?server=' . Tools::base64_url_encode($subInfo['ssr']) . ')',
|
|
||||||
'```',
|
|
||||||
$subInfo['ssr'],
|
|
||||||
'```',
|
|
||||||
'**V2ray 订阅链接:**[[iOS 点击此处一键添加]](quantumult://configuration?server=' . Tools::base64_url_encode($subInfo['quantumult_v2']) . ')',
|
|
||||||
'```',
|
|
||||||
$subInfo['quantumult_v2'],
|
|
||||||
'```'
|
|
||||||
];
|
|
||||||
break;
|
|
||||||
case 'quantumult_conf':
|
|
||||||
$msg = [
|
|
||||||
'**导入 ss、ssr、v2ray 以及分流规则的配置链接:**',
|
|
||||||
'```',
|
|
||||||
$subInfo['quantumult_sub'],
|
|
||||||
'```',
|
|
||||||
'**导入类似 Surge、Clash 使用自定义策略组的配置链接:**',
|
|
||||||
'```',
|
|
||||||
$subInfo['quantumult_conf'],
|
|
||||||
'```'
|
|
||||||
];
|
|
||||||
break;
|
|
||||||
case 'shadowrocket':
|
|
||||||
$msg = [
|
|
||||||
'**包含 ss、ssr、v2ray 的合并订阅链接:**[[iOS 点击此处一键添加]](sub://' . base64_encode($subInfo['shadowrocket']) . ')',
|
|
||||||
'```',
|
|
||||||
$subInfo['shadowrocket'],
|
|
||||||
'```'
|
|
||||||
];
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
$msg = [
|
|
||||||
'获取失败了呢...,请联系管理员。'
|
|
||||||
];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return implode(PHP_EOL, $msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
File diff suppressed because it is too large
Load Diff
@ -1,311 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Controllers\Mod_Mu;
|
|
||||||
|
|
||||||
use App\Models\DetectRule;
|
|
||||||
use App\Models\Relay;
|
|
||||||
use App\Models\BlockIp;
|
|
||||||
use App\Models\UnblockIp;
|
|
||||||
use App\Models\Speedtest;
|
|
||||||
use App\Models\Node;
|
|
||||||
use App\Models\Auto;
|
|
||||||
use App\Models\User;
|
|
||||||
use App\Controllers\BaseController;
|
|
||||||
use App\Utils\Tools;
|
|
||||||
use App\Services\Config;
|
|
||||||
|
|
||||||
class FuncController extends BaseController
|
|
||||||
{
|
|
||||||
public function ping($request, $response, $args)
|
|
||||||
{
|
|
||||||
$res = [
|
|
||||||
'ret' => 1,
|
|
||||||
'data' => 'pong'
|
|
||||||
];
|
|
||||||
return $this->echoJson($response, $res);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function get_detect_logs($request, $response, $args)
|
|
||||||
{
|
|
||||||
$rules = DetectRule::all();
|
|
||||||
|
|
||||||
$res = [
|
|
||||||
'ret' => 1,
|
|
||||||
'data' => $rules
|
|
||||||
];
|
|
||||||
return $this->echoJson($response, $res);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function get_dis_node_info($nodeid)
|
|
||||||
{
|
|
||||||
$node = Node::where('id', $nodeid)->first();
|
|
||||||
if ($node == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $node;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function get_relay_rules($request, $response, $args)
|
|
||||||
{
|
|
||||||
$params = $request->getQueryParams();
|
|
||||||
$node_id = $params['node_id'];
|
|
||||||
if ($node_id == '0') {
|
|
||||||
$node = Node::where('node_ip', $_SERVER['REMOTE_ADDR'])->first();
|
|
||||||
$node_id = $node->id;
|
|
||||||
} else {
|
|
||||||
$node = Node::where('id', $node_id)->first();
|
|
||||||
}
|
|
||||||
$rules = Relay::Where('source_node_id', $node_id)->get();
|
|
||||||
if (count($rules) > 0) {
|
|
||||||
if ($rules[0]['dist_node_id'] == -1) {
|
|
||||||
$server = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Config::get('relay_port_migration') == 'true') {
|
|
||||||
foreach ($rules as $rule) {
|
|
||||||
$dis = $this->get_dis_node_info($rule['dist_node_id']);
|
|
||||||
if ($dis != null) {
|
|
||||||
$rule['source_node_sort'] = $node->sort;
|
|
||||||
$rule['dist_node_sort'] = $dis->sort;
|
|
||||||
if (in_array($dis->sort, [0, 10])) {
|
|
||||||
$dis_server = explode(';', $dis->server);
|
|
||||||
$rule['dist_node_server'] = $dis_server[0];
|
|
||||||
} else {
|
|
||||||
$rule['dist_node_server'] = $dis->server;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (in_array($dis->sort, [0, 10]) && strpos($dis->server, ';') !== false && $dis->mu_only != -1) {
|
|
||||||
$muPort = Tools::get_MuOutPortArray($dis->server);
|
|
||||||
$user = User::where('port', '=', $rule['port'])->first();
|
|
||||||
if ($user != null) {
|
|
||||||
if ($user->is_multi_user != 0) {
|
|
||||||
if ($muPort['type'] == 0) {
|
|
||||||
if (in_array($rule['port'], array_keys($muPort['port']))) {
|
|
||||||
$rule['port'] = $muPort['port'][$rule['port']];
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$rule['port'] = ($rule['port'] + $muPort['type']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
$rule['source_node_sort'] = $node->sort;
|
|
||||||
$rule['dist_node_sort'] = null;
|
|
||||||
$rule['dist_node_server'] = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
foreach ($rules as $rule) {
|
|
||||||
$dis = $this->get_dis_node_info($rule['dist_node_id']);
|
|
||||||
if ($dis != null) {
|
|
||||||
$rule['source_node_sort'] = $node->sort;
|
|
||||||
$rule['dist_node_sort'] = $dis->sort;
|
|
||||||
$rule['dist_node_server'] = $dis->server;
|
|
||||||
} else {
|
|
||||||
$rule['source_node_sort'] = $node->sort;
|
|
||||||
$rule['dist_node_sort'] = null;
|
|
||||||
$rule['dist_node_server'] = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$res = [
|
|
||||||
'ret' => 1,
|
|
||||||
'data' => $rules,
|
|
||||||
];
|
|
||||||
} else {
|
|
||||||
$res = [
|
|
||||||
'ret' => 1,
|
|
||||||
'data' => array(),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->echoJson($response, $res);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function get_blockip($request, $response, $args)
|
|
||||||
{
|
|
||||||
$block_ips = BlockIp::Where('datetime', '>', time() - 60)->get();
|
|
||||||
|
|
||||||
$res = [
|
|
||||||
'ret' => 1,
|
|
||||||
'data' => $block_ips
|
|
||||||
];
|
|
||||||
return $this->echoJson($response, $res);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function get_unblockip($request, $response, $args)
|
|
||||||
{
|
|
||||||
$unblock_ips = UnblockIp::Where('datetime', '>', time() - 60)->get();
|
|
||||||
|
|
||||||
$res = [
|
|
||||||
'ret' => 1,
|
|
||||||
'data' => $unblock_ips
|
|
||||||
];
|
|
||||||
return $this->echoJson($response, $res);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function addBlockIp($request, $response, $args)
|
|
||||||
{
|
|
||||||
$params = $request->getQueryParams();
|
|
||||||
|
|
||||||
$data = $request->getParam('data');
|
|
||||||
$node_id = $params['node_id'];
|
|
||||||
if ($node_id == '0') {
|
|
||||||
$node = Node::where('node_ip', $_SERVER['REMOTE_ADDR'])->first();
|
|
||||||
$node_id = $node->id;
|
|
||||||
}
|
|
||||||
$node = Node::find($node_id);
|
|
||||||
if ($node == null) {
|
|
||||||
$res = [
|
|
||||||
'ret' => 0
|
|
||||||
];
|
|
||||||
return $this->echoJson($response, $res);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (count($data) > 0) {
|
|
||||||
foreach ($data as $log) {
|
|
||||||
$ip = $log['ip'];
|
|
||||||
|
|
||||||
$exist_ip = BlockIp::where('ip', $ip)->first();
|
|
||||||
if ($exist_ip != null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// log
|
|
||||||
$ip_block = new BlockIp();
|
|
||||||
$ip_block->ip = $ip;
|
|
||||||
$ip_block->nodeid = $node_id;
|
|
||||||
$ip_block->datetime = time();
|
|
||||||
$ip_block->save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$res = [
|
|
||||||
'ret' => 1,
|
|
||||||
'data' => 'ok',
|
|
||||||
];
|
|
||||||
return $this->echoJson($response, $res);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function addSpeedtest($request, $response, $args)
|
|
||||||
{
|
|
||||||
$params = $request->getQueryParams();
|
|
||||||
|
|
||||||
$data = $request->getParam('data');
|
|
||||||
$node_id = $params['node_id'];
|
|
||||||
if ($node_id == '0') {
|
|
||||||
$node = Node::where('node_ip', $_SERVER['REMOTE_ADDR'])->first();
|
|
||||||
$node_id = $node->id;
|
|
||||||
}
|
|
||||||
$node = Node::find($node_id);
|
|
||||||
if ($node == null) {
|
|
||||||
$res = [
|
|
||||||
'ret' => 0
|
|
||||||
];
|
|
||||||
return $this->echoJson($response, $res);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (count($data) > 0) {
|
|
||||||
foreach ($data as $log) {
|
|
||||||
// log
|
|
||||||
$speedtest_log = new Speedtest();
|
|
||||||
$speedtest_log->telecomping = $log['telecomping'];
|
|
||||||
$speedtest_log->telecomeupload = $log['telecomeupload'];
|
|
||||||
$speedtest_log->telecomedownload = $log['telecomedownload'];
|
|
||||||
|
|
||||||
$speedtest_log->unicomping = $log['unicomping'];
|
|
||||||
$speedtest_log->unicomupload = $log['unicomupload'];
|
|
||||||
$speedtest_log->unicomdownload = $log['unicomdownload'];
|
|
||||||
|
|
||||||
$speedtest_log->cmccping = $log['cmccping'];
|
|
||||||
$speedtest_log->cmccupload = $log['cmccupload'];
|
|
||||||
$speedtest_log->cmccdownload = $log['cmccdownload'];
|
|
||||||
$speedtest_log->nodeid = $node_id;
|
|
||||||
$speedtest_log->datetime = time();
|
|
||||||
$speedtest_log->save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$res = [
|
|
||||||
'ret' => 1,
|
|
||||||
'data' => 'ok',
|
|
||||||
];
|
|
||||||
return $this->echoJson($response, $res);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function get_autoexec($request, $response, $args)
|
|
||||||
{
|
|
||||||
$params = $request->getQueryParams();
|
|
||||||
|
|
||||||
$node_id = $params['node_id'];
|
|
||||||
if ($node_id == '0') {
|
|
||||||
$node = Node::where('node_ip', $_SERVER['REMOTE_ADDR'])->first();
|
|
||||||
$node_id = $node->id;
|
|
||||||
}
|
|
||||||
$node = Node::find($node_id);
|
|
||||||
if ($node == null) {
|
|
||||||
$res = [
|
|
||||||
'ret' => 0
|
|
||||||
];
|
|
||||||
return $this->echoJson($response, $res);
|
|
||||||
}
|
|
||||||
|
|
||||||
$autos_raw = Auto::where('datetime', '>', time() - 60)->where('type', '1')->get();
|
|
||||||
|
|
||||||
$autos = array();
|
|
||||||
|
|
||||||
foreach ($autos_raw as $auto_raw) {
|
|
||||||
$has_exec = Auto::where('sign', $node_id . '-' . $auto_raw->id)->where('type', '2')->first();
|
|
||||||
if ($has_exec == null) {
|
|
||||||
$autos[] = $auto_raw;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$res = [
|
|
||||||
'ret' => 1,
|
|
||||||
'data' => $autos,
|
|
||||||
];
|
|
||||||
return $this->echoJson($response, $res);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function addAutoexec($request, $response, $args)
|
|
||||||
{
|
|
||||||
$params = $request->getQueryParams();
|
|
||||||
|
|
||||||
$data = $request->getParam('data');
|
|
||||||
$node_id = $params['node_id'];
|
|
||||||
if ($node_id == '0') {
|
|
||||||
$node = Node::where('node_ip', $_SERVER['REMOTE_ADDR'])->first();
|
|
||||||
$node_id = $node->id;
|
|
||||||
}
|
|
||||||
$node = Node::find($node_id);
|
|
||||||
if ($node == null) {
|
|
||||||
$res = [
|
|
||||||
'ret' => 0
|
|
||||||
];
|
|
||||||
return $this->echoJson($response, $res);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (count($data) > 0) {
|
|
||||||
foreach ($data as $log) {
|
|
||||||
// log
|
|
||||||
$auto_log = new Auto();
|
|
||||||
$auto_log->value = $log['value'];
|
|
||||||
$auto_log->sign = $log['sign'];
|
|
||||||
$auto_log->type = $log['type'];
|
|
||||||
$auto_log->datetime = time();
|
|
||||||
$auto_log->save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$res = [
|
|
||||||
'ret' => 1,
|
|
||||||
'data' => 'ok',
|
|
||||||
];
|
|
||||||
return $this->echoJson($response, $res);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,126 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
|
|
||||||
namespace App\Controllers\Mod_Mu;
|
|
||||||
|
|
||||||
use App\Controllers\BaseController;
|
|
||||||
use App\Models\NodeInfoLog;
|
|
||||||
use App\Models\Node;
|
|
||||||
use App\Services\Config;
|
|
||||||
|
|
||||||
class NodeController extends BaseController
|
|
||||||
{
|
|
||||||
public function info($request, $response, $args)
|
|
||||||
{
|
|
||||||
$node_id = $args['id'];
|
|
||||||
if ($node_id == '0') {
|
|
||||||
$node = Node::where('node_ip', $_SERVER['REMOTE_ADDR'])->first();
|
|
||||||
$node_id = $node->id;
|
|
||||||
}
|
|
||||||
$load = $request->getParam('load');
|
|
||||||
$uptime = $request->getParam('uptime');
|
|
||||||
$log = new NodeInfoLog();
|
|
||||||
$log->node_id = $node_id;
|
|
||||||
$log->load = $load;
|
|
||||||
$log->uptime = $uptime;
|
|
||||||
$log->log_time = time();
|
|
||||||
if (!$log->save()) {
|
|
||||||
$res = [
|
|
||||||
'ret' => 0,
|
|
||||||
'data' => 'update failed',
|
|
||||||
];
|
|
||||||
return $this->echoJson($response, $res);
|
|
||||||
}
|
|
||||||
$res = [
|
|
||||||
'ret' => 1,
|
|
||||||
'data' => 'ok',
|
|
||||||
];
|
|
||||||
return $this->echoJson($response, $res);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function get_info($request, $response, $args)
|
|
||||||
{
|
|
||||||
$node_id = $args['id'];
|
|
||||||
if ($node_id == '0') {
|
|
||||||
$node = Node::where('node_ip', $_SERVER['REMOTE_ADDR'])->first();
|
|
||||||
$node_id = $node->id;
|
|
||||||
}
|
|
||||||
$node = Node::find($node_id);
|
|
||||||
if ($node == null) {
|
|
||||||
$res = [
|
|
||||||
'ret' => 0
|
|
||||||
];
|
|
||||||
return $this->echoJson($response, $res);
|
|
||||||
}
|
|
||||||
if (in_array($node->sort, [0, 10])) {
|
|
||||||
$node_explode = explode(';', $node->server);
|
|
||||||
$node_server = $node_explode[0];
|
|
||||||
} else {
|
|
||||||
$node_server = $node->server;
|
|
||||||
}
|
|
||||||
$res = [
|
|
||||||
'ret' => 1,
|
|
||||||
'data' => [
|
|
||||||
'node_group' => $node->node_group,
|
|
||||||
'node_class' => $node->node_class,
|
|
||||||
'node_speedlimit' => $node->node_speedlimit,
|
|
||||||
'traffic_rate' => $node->traffic_rate,
|
|
||||||
'mu_only' => $node->mu_only,
|
|
||||||
'sort' => $node->sort,
|
|
||||||
'server' => $node_server,
|
|
||||||
'type' => 'ss-panel-v3-mod_Uim'
|
|
||||||
],
|
|
||||||
];
|
|
||||||
return $this->echoJson($response, $res);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function get_all_info($request, $response, $args)
|
|
||||||
{
|
|
||||||
$nodes = Node::where('node_ip', '<>', null)->where(
|
|
||||||
static function ($query) {
|
|
||||||
$query->where('sort', '=', 0)
|
|
||||||
->orWhere('sort', '=', 10)
|
|
||||||
->orWhere('sort', '=', 12)
|
|
||||||
->orWhere('sort', '=', 13);
|
|
||||||
}
|
|
||||||
)->get();
|
|
||||||
$res = [
|
|
||||||
'ret' => 1,
|
|
||||||
'data' => $nodes
|
|
||||||
];
|
|
||||||
return $this->echoJson($response, $res);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getConfig($request, $response, $args)
|
|
||||||
{
|
|
||||||
$data = $request->getParsedBody();
|
|
||||||
switch ($data['type']) {
|
|
||||||
case ('database'):
|
|
||||||
$db_config = Config::getDbConfig();
|
|
||||||
$db_config['host'] = $this->getServerIP();
|
|
||||||
$res = [
|
|
||||||
'ret' => 1,
|
|
||||||
'data' => $db_config,
|
|
||||||
];
|
|
||||||
break;
|
|
||||||
case ('webapi'):
|
|
||||||
$webapiConfig = [];
|
|
||||||
#todo
|
|
||||||
}
|
|
||||||
return $this->echoJson($response, $res);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function getServerIP()
|
|
||||||
{
|
|
||||||
if (isset($_SERVER)) {
|
|
||||||
if ($_SERVER['SERVER_ADDR']) {
|
|
||||||
$serverIP = $_SERVER['SERVER_ADDR'];
|
|
||||||
} else {
|
|
||||||
$serverIP = $_SERVER['LOCAL_ADDR'];
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$serverIP = getenv('SERVER_ADDR');
|
|
||||||
}
|
|
||||||
return $serverIP;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,423 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Controllers\Mod_Mu;
|
|
||||||
|
|
||||||
use App\Models\Node;
|
|
||||||
use App\Models\TrafficLog;
|
|
||||||
use App\Models\User;
|
|
||||||
use App\Models\NodeOnlineLog;
|
|
||||||
use App\Models\Ip;
|
|
||||||
use App\Models\DetectLog;
|
|
||||||
use App\Models\DetectBanLog;
|
|
||||||
use App\Controllers\BaseController;
|
|
||||||
use App\Services\Config;
|
|
||||||
use App\Utils\Tools;
|
|
||||||
use App\Utils\URL;
|
|
||||||
|
|
||||||
class UserController extends BaseController
|
|
||||||
{
|
|
||||||
// User List
|
|
||||||
public function index($request, $response, $args)
|
|
||||||
{
|
|
||||||
$params = $request->getQueryParams();
|
|
||||||
|
|
||||||
$node_id = $params['node_id'];
|
|
||||||
$node = new Node();
|
|
||||||
if ($node_id == '0') {
|
|
||||||
$node = Node::where('node_ip', $_SERVER['REMOTE_ADDR'])->first();
|
|
||||||
$node_id = $node->id;
|
|
||||||
} else {
|
|
||||||
$node = Node::where('id', '=', $node_id)->first();
|
|
||||||
if ($node == null) {
|
|
||||||
$res = [
|
|
||||||
'ret' => 0
|
|
||||||
];
|
|
||||||
return $this->echoJson($response, $res);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$node->node_heartbeat = time();
|
|
||||||
$node->save();
|
|
||||||
|
|
||||||
// 节点流量耗尽则返回 null
|
|
||||||
if (($node->node_bandwidth_limit != 0) && $node->node_bandwidth_limit < $node->node_bandwidth) {
|
|
||||||
$users = null;
|
|
||||||
|
|
||||||
$res = [
|
|
||||||
'ret' => 1,
|
|
||||||
'data' => $users
|
|
||||||
];
|
|
||||||
return $this->echoJson($response, $res);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (in_array($node->sort, [0, 10]) && $node->mu_only != -1) {
|
|
||||||
$mu_port_migration = Config::get('mu_port_migration');
|
|
||||||
} else {
|
|
||||||
$mu_port_migration = 'false';
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* 1. 请不要把管理员作为单端口承载用户
|
|
||||||
* 2. 请不要把真实用户作为单端口承载用户
|
|
||||||
*/
|
|
||||||
$users_raw = User::where(
|
|
||||||
static function ($query) use ($node, $mu_port_migration) {
|
|
||||||
if ($mu_port_migration == 'true') {
|
|
||||||
$query->where(
|
|
||||||
static function ($query1) use ($node) {
|
|
||||||
if ($node->node_group != 0) {
|
|
||||||
$query1->where('class', '>=', $node->node_class)
|
|
||||||
->where('node_group', '=', $node->node_group)
|
|
||||||
->where('is_multi_user', '=', 0)
|
|
||||||
->where('is_admin', 0);
|
|
||||||
} else {
|
|
||||||
$query1->where('class', '>=', $node->node_class)
|
|
||||||
->where('is_multi_user', '=', 0)
|
|
||||||
->where('is_admin', 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
$query->where(
|
|
||||||
static function ($query1) use ($node) {
|
|
||||||
if ($node->node_group != 0) {
|
|
||||||
$query1->where('class', '>=', $node->node_class)
|
|
||||||
->where('node_group', '=', $node->node_group);
|
|
||||||
} else {
|
|
||||||
$query1->where('class', '>=', $node->node_class);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)->orwhere('is_admin', 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)->where('enable', 1)->where("detect_ban", 0)->where('expire_in', '>', date('Y-m-d H:i:s'))->get();
|
|
||||||
|
|
||||||
// 单端口承载用户
|
|
||||||
if ($mu_port_migration == 'true') {
|
|
||||||
$mu_users_raw = User::where(
|
|
||||||
static function ($query) use ($node) {
|
|
||||||
$query->where(
|
|
||||||
static function ($query1) use ($node) {
|
|
||||||
if ($node->node_group != 0) {
|
|
||||||
$query1->where('class', '>=', $node->node_class)
|
|
||||||
->where('node_group', '=', $node->node_group)
|
|
||||||
->where('is_multi_user', '>', 0);
|
|
||||||
} else {
|
|
||||||
$query1->where('class', '>=', $node->node_class)
|
|
||||||
->where('is_multi_user', '>', 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)->orwhere('is_admin', 1);
|
|
||||||
}
|
|
||||||
)->where('enable', 1)->where("detect_ban", 0)->where('expire_in', '>', date('Y-m-d H:i:s'))->get();
|
|
||||||
|
|
||||||
$muPort = Tools::get_MuOutPortArray($node->server);
|
|
||||||
if ($muPort['type'] == 0) {
|
|
||||||
foreach ($mu_users_raw as $user_raw) {
|
|
||||||
if ($user_raw->is_multi_user != 0 && in_array($user_raw->port, array_keys($muPort['port']))) {
|
|
||||||
$user_raw->port = $muPort['port'][$user_raw->port];
|
|
||||||
}
|
|
||||||
$users_raw[] = $user_raw;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
foreach ($mu_users_raw as $user_raw) {
|
|
||||||
if ($user_raw->is_multi_user != 0) {
|
|
||||||
$user_raw->port = ($user_raw->port + $muPort['type']);
|
|
||||||
}
|
|
||||||
$users_raw[] = $user_raw;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$key_list = array('email', 'method', 'obfs', 'obfs_param', 'protocol', 'protocol_param',
|
|
||||||
'forbidden_ip', 'forbidden_port', 'node_speedlimit', 'disconnect_ip',
|
|
||||||
'is_multi_user', 'id', 'port', 'passwd', 'u', 'd');
|
|
||||||
|
|
||||||
$users = array();
|
|
||||||
|
|
||||||
if (Config::get('keep_connect') == 'true') {
|
|
||||||
foreach ($users_raw as $user_raw) {
|
|
||||||
if ($user_raw->transfer_enable > $user_raw->u + $user_raw->d) {
|
|
||||||
$user_raw = Tools::keyFilter($user_raw, $key_list);
|
|
||||||
$user_raw->uuid = $user_raw->getUuid();
|
|
||||||
$users[] = $user_raw;
|
|
||||||
} else {
|
|
||||||
// 流量耗尽用户限速至 1Mbps
|
|
||||||
$user_raw = Tools::keyFilter($user_raw, $key_list);
|
|
||||||
$user_raw->uuid = $user_raw->getUuid();
|
|
||||||
$user_raw->node_speedlimit = 1;
|
|
||||||
$users[] = $user_raw;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
foreach ($users_raw as $user_raw) {
|
|
||||||
if ($user_raw->transfer_enable > $user_raw->u + $user_raw->d) {
|
|
||||||
$user_raw = Tools::keyFilter($user_raw, $key_list);
|
|
||||||
$user_raw->uuid = $user_raw->getUuid();
|
|
||||||
$users[] = $user_raw;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$res = [
|
|
||||||
'ret' => 1,
|
|
||||||
'data' => $users
|
|
||||||
];
|
|
||||||
return $this->echoJson($response, $res);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update Traffic
|
|
||||||
public function addTraffic($request, $response, $args)
|
|
||||||
{
|
|
||||||
$params = $request->getQueryParams();
|
|
||||||
|
|
||||||
$data = $request->getParam('data');
|
|
||||||
$this_time_total_bandwidth = 0;
|
|
||||||
$node_id = $params['node_id'];
|
|
||||||
if ($node_id == '0') {
|
|
||||||
$node = Node::where('node_ip', $_SERVER['REMOTE_ADDR'])->first();
|
|
||||||
$node_id = $node->id;
|
|
||||||
}
|
|
||||||
$node = Node::find($node_id);
|
|
||||||
|
|
||||||
if ($node == null) {
|
|
||||||
$res = [
|
|
||||||
'ret' => 0
|
|
||||||
];
|
|
||||||
return $this->echoJson($response, $res);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (count($data) > 0) {
|
|
||||||
foreach ($data as $log) {
|
|
||||||
$u = $log['u'];
|
|
||||||
$d = $log['d'];
|
|
||||||
$user_id = $log['user_id'];
|
|
||||||
|
|
||||||
$user = User::find($user_id);
|
|
||||||
|
|
||||||
if ($user == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$user->t = time();
|
|
||||||
$user->u += $u * $node->traffic_rate;
|
|
||||||
$user->d += $d * $node->traffic_rate;
|
|
||||||
$this_time_total_bandwidth += $u + $d;
|
|
||||||
if (!$user->save()) {
|
|
||||||
$res = [
|
|
||||||
'ret' => 0,
|
|
||||||
'data' => 'update failed',
|
|
||||||
];
|
|
||||||
return $this->echoJson($response, $res);
|
|
||||||
}
|
|
||||||
|
|
||||||
// log
|
|
||||||
$traffic = new TrafficLog();
|
|
||||||
$traffic->user_id = $user_id;
|
|
||||||
$traffic->u = $u;
|
|
||||||
$traffic->d = $d;
|
|
||||||
$traffic->node_id = $node_id;
|
|
||||||
$traffic->rate = $node->traffic_rate;
|
|
||||||
$traffic->traffic = Tools::flowAutoShow(($u + $d) * $node->traffic_rate);
|
|
||||||
$traffic->log_time = time();
|
|
||||||
$traffic->save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$node->node_bandwidth += $this_time_total_bandwidth;
|
|
||||||
$node->save();
|
|
||||||
|
|
||||||
$online_log = new NodeOnlineLog();
|
|
||||||
$online_log->node_id = $node_id;
|
|
||||||
$online_log->online_user = count($data);
|
|
||||||
$online_log->log_time = time();
|
|
||||||
$online_log->save();
|
|
||||||
|
|
||||||
$res = [
|
|
||||||
'ret' => 1,
|
|
||||||
'data' => 'ok',
|
|
||||||
];
|
|
||||||
return $this->echoJson($response, $res);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function addAliveIp($request, $response, $args)
|
|
||||||
{
|
|
||||||
$params = $request->getQueryParams();
|
|
||||||
|
|
||||||
$data = $request->getParam('data');
|
|
||||||
$node_id = $params['node_id'];
|
|
||||||
if ($node_id == '0') {
|
|
||||||
$node = Node::where('node_ip', $_SERVER['REMOTE_ADDR'])->first();
|
|
||||||
$node_id = $node->id;
|
|
||||||
}
|
|
||||||
$node = Node::find($node_id);
|
|
||||||
|
|
||||||
if ($node == null) {
|
|
||||||
$res = [
|
|
||||||
'ret' => 0
|
|
||||||
];
|
|
||||||
return $this->echoJson($response, $res);
|
|
||||||
}
|
|
||||||
if (count($data) > 0) {
|
|
||||||
foreach ($data as $log) {
|
|
||||||
$ip = $log['ip'];
|
|
||||||
$userid = $log['user_id'];
|
|
||||||
|
|
||||||
// log
|
|
||||||
$ip_log = new Ip();
|
|
||||||
$ip_log->userid = $userid;
|
|
||||||
$ip_log->nodeid = $node_id;
|
|
||||||
$ip_log->ip = $ip;
|
|
||||||
$ip_log->datetime = time();
|
|
||||||
$ip_log->save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$res = [
|
|
||||||
'ret' => 1,
|
|
||||||
'data' => 'ok',
|
|
||||||
];
|
|
||||||
return $this->echoJson($response, $res);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function addDetectLog($request, $response, $args)
|
|
||||||
{
|
|
||||||
$params = $request->getQueryParams();
|
|
||||||
|
|
||||||
$data = $request->getParam('data');
|
|
||||||
$node_id = $params['node_id'];
|
|
||||||
if ($node_id == '0') {
|
|
||||||
$node = Node::where('node_ip', $_SERVER['REMOTE_ADDR'])->first();
|
|
||||||
$node_id = $node->id;
|
|
||||||
}
|
|
||||||
$node = Node::find($node_id);
|
|
||||||
|
|
||||||
if ($node == null) {
|
|
||||||
$res = [
|
|
||||||
'ret' => 0
|
|
||||||
];
|
|
||||||
return $this->echoJson($response, $res);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Config::get('enable_auto_detect_ban') == 'true') {
|
|
||||||
$detect_Users = array();
|
|
||||||
if (count($data) > 0) {
|
|
||||||
foreach ($data as $log) {
|
|
||||||
$list_id = $log['list_id'];
|
|
||||||
$user_id = $log['user_id'];
|
|
||||||
|
|
||||||
// log
|
|
||||||
$detect_log = new DetectLog();
|
|
||||||
$detect_log->user_id = $user_id;
|
|
||||||
$detect_log->list_id = $list_id;
|
|
||||||
$detect_log->node_id = $node_id;
|
|
||||||
$detect_log->datetime = time();
|
|
||||||
$detect_log->save();
|
|
||||||
|
|
||||||
$User = User::find($user_id);
|
|
||||||
if ($User == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!in_array($user_id, $detect_Users)) {
|
|
||||||
$detect_Users[] = $user_id;
|
|
||||||
}
|
|
||||||
$User->all_detect_number++;
|
|
||||||
$User->save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (count($detect_Users) > 0) {
|
|
||||||
self::DetectBan($detect_Users);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (count($data) > 0) {
|
|
||||||
foreach ($data as $log) {
|
|
||||||
$list_id = $log['list_id'];
|
|
||||||
$user_id = $log['user_id'];
|
|
||||||
|
|
||||||
// log
|
|
||||||
$detect_log = new DetectLog();
|
|
||||||
$detect_log->user_id = $user_id;
|
|
||||||
$detect_log->list_id = $list_id;
|
|
||||||
$detect_log->node_id = $node_id;
|
|
||||||
$detect_log->datetime = time();
|
|
||||||
$detect_log->save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$res = [
|
|
||||||
'ret' => 1,
|
|
||||||
'data' => 'ok',
|
|
||||||
];
|
|
||||||
return $this->echoJson($response, $res);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function DetectBan($detect_Users)
|
|
||||||
{
|
|
||||||
foreach ($detect_Users as $user_id) {
|
|
||||||
$User = User::find($user_id);
|
|
||||||
if ($User == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if ($User->detect_ban == 1 || ($User->is_admin && Config::get('auto_detect_ban_allow_admin') == 'true') || in_array($User->id, Config::get('auto_detect_ban_allow_users'))) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (Config::get('auto_detect_ban_type') == '1') {
|
|
||||||
$last_DetectBanLog = DetectBanLog::where('user_id', $user_id)->orderBy("id", "desc")->first();
|
|
||||||
$last_all_detect_number = (
|
|
||||||
$last_DetectBanLog == null
|
|
||||||
? 0
|
|
||||||
: (int) $last_DetectBanLog->all_detect_number
|
|
||||||
);
|
|
||||||
$detect_number = ($User->all_detect_number - $last_all_detect_number);
|
|
||||||
if ($detect_number >= Config::get('auto_detect_ban_number')) {
|
|
||||||
$last_detect_ban_time = $User->last_detect_ban_time;
|
|
||||||
$end_time = date('Y-m-d H:i:s');
|
|
||||||
$User->detect_ban = 1;
|
|
||||||
$User->last_detect_ban_time = $end_time;
|
|
||||||
$User->save();
|
|
||||||
$DetectBanLog = new DetectBanLog();
|
|
||||||
$DetectBanLog->user_name = $User->user_name;
|
|
||||||
$DetectBanLog->user_id = $User->id;
|
|
||||||
$DetectBanLog->email = $User->email;
|
|
||||||
$DetectBanLog->detect_number = $detect_number;
|
|
||||||
$DetectBanLog->ban_time = Config::get('auto_detect_ban_time');
|
|
||||||
$DetectBanLog->start_time = strtotime($last_detect_ban_time);
|
|
||||||
$DetectBanLog->end_time = strtotime($end_time);
|
|
||||||
$DetectBanLog->all_detect_number = $User->all_detect_number;
|
|
||||||
$DetectBanLog->save();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$number = $User->all_detect_number;
|
|
||||||
$tmp = 0;
|
|
||||||
foreach (Config::get('auto_detect_ban') as $key => $value) {
|
|
||||||
if ($number >= $key) {
|
|
||||||
if ($key >= $tmp) {
|
|
||||||
$tmp = $key;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($tmp != 0) {
|
|
||||||
if (Config::get('auto_detect_ban')[$tmp]['type'] == 'kill') {
|
|
||||||
$User->kill_user();
|
|
||||||
} else {
|
|
||||||
$last_detect_ban_time = $User->last_detect_ban_time;
|
|
||||||
$end_time = date('Y-m-d H:i:s');
|
|
||||||
$User->detect_ban = 1;
|
|
||||||
$User->last_detect_ban_time = $end_time;
|
|
||||||
$User->save();
|
|
||||||
$DetectBanLog = new DetectBanLog();
|
|
||||||
$DetectBanLog->user_name = $User->user_name;
|
|
||||||
$DetectBanLog->user_id = $User->id;
|
|
||||||
$DetectBanLog->email = $User->email;
|
|
||||||
$DetectBanLog->detect_number = $number;
|
|
||||||
$DetectBanLog->ban_time = Config::get('auto_detect_ban')[$tmp]['time'];
|
|
||||||
$DetectBanLog->start_time = strtotime('1989-06-04 00:05:00');
|
|
||||||
$DetectBanLog->end_time = strtotime($end_time);
|
|
||||||
$DetectBanLog->all_detect_number = $number;
|
|
||||||
$DetectBanLog->save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,57 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
|
|
||||||
namespace App\Controllers\Mu;
|
|
||||||
|
|
||||||
use App\Controllers\BaseController;
|
|
||||||
use App\Models\NodeOnlineLog;
|
|
||||||
use App\Models\NodeInfoLog;
|
|
||||||
|
|
||||||
class NodeController extends BaseController
|
|
||||||
{
|
|
||||||
public function onlineUserLog($request, $response, $args)
|
|
||||||
{
|
|
||||||
$node_id = $args['id'];
|
|
||||||
$count = $request->getParam('count');
|
|
||||||
$log = new NodeOnlineLog();
|
|
||||||
$log->node_id = $node_id;
|
|
||||||
$log->online_user = $count;
|
|
||||||
$log->log_time = time();
|
|
||||||
if (!$log->save()) {
|
|
||||||
$res = [
|
|
||||||
'ret' => 0,
|
|
||||||
'msg' => 'update failed',
|
|
||||||
];
|
|
||||||
return $this->echoJson($response, $res);
|
|
||||||
}
|
|
||||||
$res = [
|
|
||||||
'ret' => 1,
|
|
||||||
'msg' => 'ok',
|
|
||||||
];
|
|
||||||
return $this->echoJson($response, $res);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function info($request, $response, $args)
|
|
||||||
{
|
|
||||||
$node_id = $args['id'];
|
|
||||||
$load = $request->getParam('load');
|
|
||||||
$uptime = $request->getParam('uptime');
|
|
||||||
$log = new NodeInfoLog();
|
|
||||||
$log->node_id = $node_id;
|
|
||||||
$log->load = $load;
|
|
||||||
$log->uptime = $uptime;
|
|
||||||
$log->log_time = time();
|
|
||||||
if (!$log->save()) {
|
|
||||||
$res = [
|
|
||||||
'ret' => 0,
|
|
||||||
'msg' => 'update failed',
|
|
||||||
];
|
|
||||||
return $this->echoJson($response, $res);
|
|
||||||
}
|
|
||||||
$res = [
|
|
||||||
'ret' => 1,
|
|
||||||
'msg' => 'ok',
|
|
||||||
];
|
|
||||||
return $this->echoJson($response, $res);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,122 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Controllers\Mu;
|
|
||||||
|
|
||||||
use App\Models\Node;
|
|
||||||
use App\Models\TrafficLog;
|
|
||||||
use App\Models\User;
|
|
||||||
use App\Controllers\BaseController;
|
|
||||||
use App\Utils\Tools;
|
|
||||||
|
|
||||||
class UserController extends BaseController
|
|
||||||
{
|
|
||||||
// User List
|
|
||||||
public function index($request, $response, $args)
|
|
||||||
{
|
|
||||||
$node = Node::where('node_ip', '=', $_SERVER['REMOTE_ADDR'])->where(
|
|
||||||
static function ($query) {
|
|
||||||
$query->where('sort', '=', 0)
|
|
||||||
->orWhere('sort', '=', 10)->orWhere('sort', '=', 12);
|
|
||||||
}
|
|
||||||
)->first();
|
|
||||||
$node->node_heartbeat = time();
|
|
||||||
$node->save();
|
|
||||||
|
|
||||||
if ($node->node_group != 0) {
|
|
||||||
$users_raw = User::where(
|
|
||||||
static function ($query) use ($node) {
|
|
||||||
$query->where(
|
|
||||||
static function ($query1) use ($node) {
|
|
||||||
$query1->where('class', '>=', $node->node_class)
|
|
||||||
->where('node_group', '=', $node->node_group);
|
|
||||||
}
|
|
||||||
)->orwhere('is_admin', 1);
|
|
||||||
}
|
|
||||||
)
|
|
||||||
->where('enable', 1)->where('expire_in', '>', date('Y-m-d H:i:s'))->get();
|
|
||||||
} else {
|
|
||||||
$users_raw = User::where(
|
|
||||||
static function ($query) use ($node) {
|
|
||||||
$query->where(
|
|
||||||
static function ($query1) use ($node) {
|
|
||||||
$query1->where('class', '>=', $node->node_class);
|
|
||||||
}
|
|
||||||
)->orwhere('is_admin', 1);
|
|
||||||
}
|
|
||||||
)->where('enable', 1)->where('expire_in', '>', date('Y-m-d H:i:s'))->get();
|
|
||||||
}
|
|
||||||
if (($node->node_bandwidth_limit != 0) && $node->node_bandwidth_limit < $node->node_bandwidth) {
|
|
||||||
$users = null;
|
|
||||||
|
|
||||||
$res = [
|
|
||||||
'ret' => 1,
|
|
||||||
'data' => $users
|
|
||||||
];
|
|
||||||
return $this->echoJson($response, $res);
|
|
||||||
}
|
|
||||||
|
|
||||||
$key_list = array('method', 'id', 'port', 'passwd', 'u', 'd', 'enable',
|
|
||||||
't', 'transfer_enable', 'switch', 'email');
|
|
||||||
|
|
||||||
$users_output = array();
|
|
||||||
|
|
||||||
foreach ($users_raw as $user_raw) {
|
|
||||||
if ($user_raw->transfer_enable > $user_raw->u + $user_raw->d) {
|
|
||||||
$user_raw = Tools::keyFilter($user_raw, $key_list);
|
|
||||||
$users_output[] = $user_raw;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$res = [
|
|
||||||
'ret' => 1,
|
|
||||||
'msg' => 'ok',
|
|
||||||
'data' => $users_output
|
|
||||||
];
|
|
||||||
return $this->echoJson($response, $res);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update Traffic
|
|
||||||
public function addTraffic($request, $response, $args)
|
|
||||||
{
|
|
||||||
$id = $args['id'];
|
|
||||||
$u = $request->getParam('u');
|
|
||||||
$d = $request->getParam('d');
|
|
||||||
$nodeId = $request->getParam('node_id');
|
|
||||||
$node = Node::find($nodeId);
|
|
||||||
|
|
||||||
$node->node_bandwidth = $node->node_bandwidth + $d + $u;
|
|
||||||
|
|
||||||
$node->save();
|
|
||||||
|
|
||||||
|
|
||||||
$rate = $node->traffic_rate;
|
|
||||||
$user = User::find($id);
|
|
||||||
|
|
||||||
$user->t = time();
|
|
||||||
$user->u += ($u * $rate);
|
|
||||||
$user->d += ($d * $rate);
|
|
||||||
if (!$user->save()) {
|
|
||||||
$res = [
|
|
||||||
'ret' => 0,
|
|
||||||
'msg' => 'update failed',
|
|
||||||
];
|
|
||||||
//return $this->echoJson($response, $res);
|
|
||||||
}
|
|
||||||
// log
|
|
||||||
$traffic = new TrafficLog();
|
|
||||||
$traffic->user_id = $id;
|
|
||||||
$traffic->u = $u;
|
|
||||||
$traffic->d = $d;
|
|
||||||
$traffic->node_id = $nodeId;
|
|
||||||
$traffic->rate = $rate;
|
|
||||||
$traffic->traffic = Tools::flowAutoShow(($u + $d) * $rate);
|
|
||||||
$traffic->log_time = time();
|
|
||||||
$traffic->save();
|
|
||||||
|
|
||||||
$res = [
|
|
||||||
'ret' => 1,
|
|
||||||
'msg' => 'ok',
|
|
||||||
];
|
|
||||||
return $this->echoJson($response, $res);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,98 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Controllers;
|
|
||||||
|
|
||||||
use App\Models\User;
|
|
||||||
use App\Models\PasswordReset;
|
|
||||||
use App\Services\Password;
|
|
||||||
use App\Utils\Hash;
|
|
||||||
|
|
||||||
/***
|
|
||||||
* Class Password
|
|
||||||
* @package App\Controllers
|
|
||||||
* 密码重置
|
|
||||||
*/
|
|
||||||
class PasswordController extends BaseController
|
|
||||||
{
|
|
||||||
public function reset()
|
|
||||||
{
|
|
||||||
return $this->view()->display('password/reset.tpl');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function handleReset($request, $response, $args)
|
|
||||||
{
|
|
||||||
$email = $request->getParam('email');
|
|
||||||
// check limit
|
|
||||||
|
|
||||||
// send email
|
|
||||||
$user = User::where('email', $email)->first();
|
|
||||||
if ($user == null) {
|
|
||||||
$rs['ret'] = 0;
|
|
||||||
$rs['msg'] = '此邮箱不存在.';
|
|
||||||
return $response->getBody()->write(json_encode($rs));
|
|
||||||
}
|
|
||||||
$rs['ret'] = 1;
|
|
||||||
$rs['msg'] = '重置邮件已经发送,请检查邮箱.';
|
|
||||||
if (Password::sendResetEmail($email)) {
|
|
||||||
$res['msg'] = '邮件发送失败,请联系网站管理员。';
|
|
||||||
}
|
|
||||||
|
|
||||||
return $response->getBody()->write(json_encode($rs));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function token($request, $response, $args)
|
|
||||||
{
|
|
||||||
$token = $args['token'];
|
|
||||||
return $this->view()->assign('token', $token)->display('password/token.tpl');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function handleToken($request, $response, $args)
|
|
||||||
{
|
|
||||||
$tokenStr = $args['token'];
|
|
||||||
$password = $request->getParam('password');
|
|
||||||
$repasswd = $request->getParam('repasswd');
|
|
||||||
|
|
||||||
if ($password != $repasswd) {
|
|
||||||
$res['ret'] = 0;
|
|
||||||
$res['msg'] = '两次输入不符合';
|
|
||||||
return $response->getBody()->write(json_encode($res));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strlen($password) < 8) {
|
|
||||||
$res['ret'] = 0;
|
|
||||||
$res['msg'] = '密码太短啦';
|
|
||||||
return $response->getBody()->write(json_encode($res));
|
|
||||||
}
|
|
||||||
|
|
||||||
// check token
|
|
||||||
$token = PasswordReset::where('token', $tokenStr)->orderBy('id', 'desc')->first();
|
|
||||||
if ($token == null || $token->expire_time < time()) {
|
|
||||||
$rs['ret'] = 0;
|
|
||||||
$rs['msg'] = '链接已经失效,请重新获取';
|
|
||||||
return $response->getBody()->write(json_encode($rs));
|
|
||||||
}
|
|
||||||
|
|
||||||
$user = User::where('email', $token->email)->first();
|
|
||||||
if ($user == null) {
|
|
||||||
$rs['ret'] = 0;
|
|
||||||
$rs['msg'] = '链接已经失效,请重新获取';
|
|
||||||
return $response->getBody()->write(json_encode($rs));
|
|
||||||
}
|
|
||||||
|
|
||||||
// reset password
|
|
||||||
$hashPassword = Hash::passwordHash($password);
|
|
||||||
$user->pass = $hashPassword;
|
|
||||||
$user->ga_enable = 0;
|
|
||||||
if (!$user->save()) {
|
|
||||||
$rs['ret'] = 0;
|
|
||||||
$rs['msg'] = '重置失败,请重试';
|
|
||||||
return $response->getBody()->write(json_encode($rs));
|
|
||||||
}
|
|
||||||
$rs['ret'] = 1;
|
|
||||||
$rs['msg'] = '重置成功';
|
|
||||||
|
|
||||||
$user->clean_link();
|
|
||||||
|
|
||||||
return $response->getBody()->write(json_encode($rs));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,505 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Controllers;
|
|
||||||
|
|
||||||
use App\Models\Relay;
|
|
||||||
use App\Models\Node;
|
|
||||||
use App\Models\User;
|
|
||||||
use App\Services\Auth;
|
|
||||||
use App\Utils\Tools;
|
|
||||||
use App\Services\Config;
|
|
||||||
use ArrayObject;
|
|
||||||
|
|
||||||
class RelayController extends UserController
|
|
||||||
{
|
|
||||||
public function index($request, $response, $args)
|
|
||||||
{
|
|
||||||
$pageNum = 1;
|
|
||||||
$user = Auth::getUser();
|
|
||||||
if (isset($request->getQueryParams()['page'])) {
|
|
||||||
$pageNum = $request->getQueryParams()['page'];
|
|
||||||
}
|
|
||||||
$logs = Relay::where('user_id', $user->id)->orwhere('user_id', 0)->paginate(15, ['*'], 'page', $pageNum);
|
|
||||||
$logs->setPath('/user/relay');
|
|
||||||
|
|
||||||
$is_relay_able = Tools::is_protocol_relay($user);
|
|
||||||
|
|
||||||
//链路表部分
|
|
||||||
|
|
||||||
$nodes = Node::where(
|
|
||||||
static function ($query) use ($user) {
|
|
||||||
$query->Where('node_group', '=', $user->node_group)
|
|
||||||
->orWhere('node_group', '=', 0);
|
|
||||||
}
|
|
||||||
)->where('type', 1)->where(
|
|
||||||
static function ($query) {
|
|
||||||
$query->Where('sort', 10)
|
|
||||||
->orWhere('sort', 12);
|
|
||||||
}
|
|
||||||
)->where('node_class', '<=', $user->class)->orderBy('name')->get();
|
|
||||||
|
|
||||||
$pathset = new ArrayObject();
|
|
||||||
|
|
||||||
$relay_rules = Relay::where('user_id', $user->id)->orwhere('user_id', 0)->get();
|
|
||||||
$mu_nodes = Node::where('sort', 9)->where('node_class', '<=', $user->class)->where('type', '1')->where(
|
|
||||||
static function ($query) use ($user) {
|
|
||||||
$query->where('node_group', '=', $user->node_group)
|
|
||||||
->orWhere('node_group', '=', 0);
|
|
||||||
}
|
|
||||||
)->get();
|
|
||||||
|
|
||||||
foreach ($nodes as $node) {
|
|
||||||
if ($node->mu_only == 0) {
|
|
||||||
$relay_rule = Tools::pick_out_relay_rule($node->id, $user->port, $relay_rules);
|
|
||||||
|
|
||||||
if ($relay_rule != null) {
|
|
||||||
$pathset = Tools::insertPathRule($relay_rule, $pathset, $user->port);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($node->custom_rss == 1) {
|
|
||||||
foreach ($mu_nodes as $mu_node) {
|
|
||||||
$mu_user = User::where('port', '=', $mu_node->server)->first();
|
|
||||||
|
|
||||||
if ($mu_user == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!($mu_user->class >= $node->node_class && ($node->node_group == 0 || $node->node_group == $mu_user->node_group))) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($mu_user->is_multi_user != 2) {
|
|
||||||
$relay_rule = Tools::pick_out_relay_rule($node->id, $mu_user->port, $relay_rules);
|
|
||||||
|
|
||||||
if ($relay_rule != null) {
|
|
||||||
$pathset = Tools::insertPathRule($relay_rule, $pathset, $mu_user->port);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($pathset as $path) {
|
|
||||||
foreach ($pathset as $index => $single_path) {
|
|
||||||
if ($path != $single_path && $path->port == $single_path->port) {
|
|
||||||
if ($single_path->end_node->id == $path->begin_node->id) {
|
|
||||||
$path->begin_node = $single_path->begin_node;
|
|
||||||
if ($path->begin_node->isNodeAccessable() == false) {
|
|
||||||
$path->path = '<font color="#FF0000">' . $single_path->begin_node->name . '</font>' . ' → ' . $path->path;
|
|
||||||
$path->status = '阻断';
|
|
||||||
} else {
|
|
||||||
$path->path = $single_path->begin_node->name . ' → ' . $path->path;
|
|
||||||
$path->status = '通畅';
|
|
||||||
}
|
|
||||||
|
|
||||||
$pathset->offsetUnset($index);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($path->end_node->id == $single_path->begin_node->id) {
|
|
||||||
$path->end_node = $single_path->end_node;
|
|
||||||
if ($single_path->end_node->isNodeAccessable() == false) {
|
|
||||||
$path->path = $path->path . ' → ' . '<font color="#FF0000">' . $single_path->end_node->name . '</font>';
|
|
||||||
$path->status = '阻断';
|
|
||||||
} else {
|
|
||||||
$path->path = $path->path . ' → ' . $single_path->end_node->name;
|
|
||||||
}
|
|
||||||
|
|
||||||
$pathset->offsetUnset($index);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->view()->assign('rules', $logs)->assign('relay_able_protocol_list', Config::getSupportParam('relay_able_protocol'))->assign('is_relay_able', $is_relay_able)->assign('pathset', $pathset)->display('user/relay/index.tpl');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function create($request, $response, $args)
|
|
||||||
{
|
|
||||||
$user = Auth::getUser();
|
|
||||||
$source_nodes = Node::where(
|
|
||||||
static function ($query) use ($user) {
|
|
||||||
$query->Where('node_group', '=', $user->node_group)
|
|
||||||
->orWhere('node_group', '=', 0);
|
|
||||||
}
|
|
||||||
)->where('type', 1)->where(
|
|
||||||
static function ($query) {
|
|
||||||
$query->Where('sort', 10)
|
|
||||||
->orWhere('sort', 12);
|
|
||||||
}
|
|
||||||
)->where('node_class', '<=', $user->class)->orderBy('name')->get();
|
|
||||||
foreach ($source_nodes as $node) {
|
|
||||||
if ($node->sort == 12) {
|
|
||||||
$node->name .= ' 正在使用V2ray后端 ';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$dist_nodes = Node::where(
|
|
||||||
static function ($query) use ($user) {
|
|
||||||
$query->Where('node_group', '=', $user->node_group)
|
|
||||||
->orWhere('node_group', '=', 0);
|
|
||||||
}
|
|
||||||
)->where('type', 1)->where(
|
|
||||||
static function ($query) {
|
|
||||||
$query->Where('sort', 0)
|
|
||||||
->orWhere('sort', 10)
|
|
||||||
->orWhere('sort', 11)
|
|
||||||
->orWhere('sort', 12);
|
|
||||||
}
|
|
||||||
)->where('node_class', '<=', $user->class)->orderBy('name')->get();
|
|
||||||
|
|
||||||
$ports_raw = Node::where(
|
|
||||||
static function ($query) use ($user) {
|
|
||||||
$query->Where('node_group', '=', $user->node_group)
|
|
||||||
->orWhere('node_group', '=', 0);
|
|
||||||
}
|
|
||||||
)->where('type', 1)->where('sort', 9)->where('node_class', '<=', $user->class)->orderBy('name')->get();
|
|
||||||
|
|
||||||
$ports = array();
|
|
||||||
foreach ($ports_raw as $port_raw) {
|
|
||||||
$mu_user = User::where('port', $port_raw->server)->first();
|
|
||||||
if ($mu_user->is_multi_user == 1) {
|
|
||||||
$ports[] = $port_raw->server;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($dist_nodes as $node) {
|
|
||||||
if ($node->sort == 11 || $node->sort == 12) {
|
|
||||||
$node_explode = Tools::v2Array($node->server);
|
|
||||||
$ports[] = $node_explode['port'];
|
|
||||||
$node->name = $node->name . ' 如果是V2ray后端 请设置成 ' . $node_explode['port'];
|
|
||||||
} else {
|
|
||||||
$node->name = $node->name . ' 如果是V2ray后端 请设置成 ' . $user->port;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$ports[] = $user->port;
|
|
||||||
$ports = array_unique($ports);
|
|
||||||
return $this->view()->assign('source_nodes', $source_nodes)->assign('dist_nodes', $dist_nodes)->assign('ports', $ports)->display('user/relay/add.tpl');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function add($request, $response, $args)
|
|
||||||
{
|
|
||||||
$user = Auth::getUser();
|
|
||||||
|
|
||||||
$dist_node_id = $request->getParam('dist_node');
|
|
||||||
$source_node_id = $request->getParam('source_node');
|
|
||||||
$port = $request->getParam('port');
|
|
||||||
$priority = $request->getParam('priority');
|
|
||||||
|
|
||||||
$source_node = Node::where('id', $source_node_id)->where(
|
|
||||||
static function ($query) use ($user) {
|
|
||||||
$query->Where('node_group', '=', $user->node_group)
|
|
||||||
->orWhere('node_group', '=', 0);
|
|
||||||
}
|
|
||||||
)->where('type', 1)->where(
|
|
||||||
static function ($query) {
|
|
||||||
$query->Where('sort', 10)
|
|
||||||
->orWhere('sort', 12);
|
|
||||||
}
|
|
||||||
)->where('node_class', '<=', $user->class)->first();
|
|
||||||
if ($source_node == null) {
|
|
||||||
$rs['ret'] = 0;
|
|
||||||
$rs['msg'] = '起源节点错误';
|
|
||||||
return $response->getBody()->write(json_encode($rs));
|
|
||||||
}
|
|
||||||
if ($source_node->sort == 12) {
|
|
||||||
$rules = Relay::Where('source_node_id', $source_node_id)->get();
|
|
||||||
foreach ($rules as $rule) {
|
|
||||||
if ($rule['user_id'] == 0 || $rule['user_id'] = $user->id) {
|
|
||||||
$rs['ret'] = 0;
|
|
||||||
$rs['msg'] = 'v2ray中转一个起点一个rule';
|
|
||||||
return $response->getBody()->write(json_encode($rs));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$dist_node = Node::where('id', $dist_node_id)->where(
|
|
||||||
static function ($query) use ($user) {
|
|
||||||
$query->Where('node_group', '=', $user->node_group)
|
|
||||||
->orWhere('node_group', '=', 0);
|
|
||||||
}
|
|
||||||
)->where('type', 1)->where(
|
|
||||||
static function ($query) {
|
|
||||||
$query->Where('sort', 0)
|
|
||||||
->orWhere('sort', 10)
|
|
||||||
->orWhere('sort', 11)
|
|
||||||
->orWhere('sort', 12);
|
|
||||||
}
|
|
||||||
)->where('node_class', '<=', $user->class)->first();
|
|
||||||
|
|
||||||
if ($dist_node_id == -1) {
|
|
||||||
$dist_node = new Node();
|
|
||||||
$dist_node->id = -1;
|
|
||||||
$dist_node->node_ip = '0.0.0.0';
|
|
||||||
$dist_node->sort = 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($dist_node == null) {
|
|
||||||
$rs['ret'] = 0;
|
|
||||||
$rs['msg'] = '目标节点错误';
|
|
||||||
return $response->getBody()->write(json_encode($rs));
|
|
||||||
}
|
|
||||||
|
|
||||||
$port_raw = Node::where('server', $port)->where(
|
|
||||||
static function ($query) use ($user) {
|
|
||||||
$query->Where('node_group', '=', $user->node_group)
|
|
||||||
->orWhere('node_group', '=', 0);
|
|
||||||
}
|
|
||||||
)->where('type', 1)->where('sort', 9)->where('node_class', '<=', $user->class)->first();
|
|
||||||
$v2ray_port_raw = '';
|
|
||||||
if ($dist_node->sort == 12 || $dist_node->sort == 11) {
|
|
||||||
$node_explode = Tools::v2Array($dist_node->server);
|
|
||||||
$v2ray_port_raw = $node_explode['port'];
|
|
||||||
}
|
|
||||||
if (($port_raw == null && $port != $user->port && $v2ray_port_raw == '') || ($v2ray_port_raw != '' && ($port != $user->port && $port != $v2ray_port_raw))) {
|
|
||||||
$rs['ret'] = 0;
|
|
||||||
$rs['msg'] = '端口错误';
|
|
||||||
return $response->getBody()->write(json_encode($rs));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Tools::is_protocol_relay($user)) {
|
|
||||||
$rs['ret'] = 0;
|
|
||||||
$rs['msg'] = "为了中转的稳定,您需要在<a href='/user/edit'>资料编辑</a>处设置协议为 auth_aes128_md5 或 auth_aes128_sha1 后方可设置中转规则!";
|
|
||||||
return $response->getBody()->write(json_encode($rs));
|
|
||||||
}
|
|
||||||
|
|
||||||
$rule = new Relay();
|
|
||||||
$rule->user_id = $user->id;
|
|
||||||
$rule->dist_node_id = $dist_node_id;
|
|
||||||
|
|
||||||
$dist_node_ip = Tools::getRelayNodeIp($source_node, $dist_node);
|
|
||||||
$rule->dist_ip = $dist_node_ip;
|
|
||||||
|
|
||||||
$rule->source_node_id = $source_node_id;
|
|
||||||
$rule->port = $port;
|
|
||||||
$rule->priority = min($priority, 99998);
|
|
||||||
|
|
||||||
$ruleset = Relay::where('user_id', $user->id)->orwhere('user_id', 0)->get();
|
|
||||||
$maybe_rule_id = Tools::has_conflict_rule($rule, $ruleset, 0, $rule->source_node_id);
|
|
||||||
if ($maybe_rule_id != 0) {
|
|
||||||
$rs['ret'] = 0;
|
|
||||||
$rs['msg'] = '您即将添加的规则与规则 ID:' . $maybe_rule_id . ' 冲突!';
|
|
||||||
if ($maybe_rule_id == -1) {
|
|
||||||
$rs['msg'] = '您即将添加的规则可能会造成冲突!';
|
|
||||||
}
|
|
||||||
return $response->getBody()->write(json_encode($rs));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$rule->save()) {
|
|
||||||
$rs['ret'] = 0;
|
|
||||||
$rs['msg'] = '添加失败';
|
|
||||||
return $response->getBody()->write(json_encode($rs));
|
|
||||||
}
|
|
||||||
|
|
||||||
$rs['ret'] = 1;
|
|
||||||
$rs['msg'] = '添加成功';
|
|
||||||
return $response->getBody()->write(json_encode($rs));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function edit($request, $response, $args)
|
|
||||||
{
|
|
||||||
$id = $args['id'];
|
|
||||||
|
|
||||||
$user = Auth::getUser();
|
|
||||||
$rule = Relay::where('id', $id)->where('user_id', $user->id)->first();
|
|
||||||
|
|
||||||
if ($rule == null) {
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
$user = Auth::getUser();
|
|
||||||
$source_nodes = Node::where(
|
|
||||||
static function ($query) use ($user) {
|
|
||||||
$query->Where('node_group', '=', $user->node_group)
|
|
||||||
->orWhere('node_group', '=', 0);
|
|
||||||
}
|
|
||||||
)->where('type', 1)->where(
|
|
||||||
static function ($query) {
|
|
||||||
$query->Where('sort', 10)
|
|
||||||
->orWhere('sort', 12);
|
|
||||||
}
|
|
||||||
)->where('node_class', '<=', $user->class)->orderBy('name')->get();
|
|
||||||
foreach ($source_nodes as $node) {
|
|
||||||
if ($node->sort == 12) {
|
|
||||||
$node->name .= ' 正在使用V2ray后端 ';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$dist_nodes = Node::where(
|
|
||||||
static function ($query) use ($user) {
|
|
||||||
$query->Where('node_group', '=', $user->node_group)
|
|
||||||
->orWhere('node_group', '=', 0);
|
|
||||||
}
|
|
||||||
)->where('type', 1)->where(
|
|
||||||
static function ($query) {
|
|
||||||
$query->Where('sort', 0)
|
|
||||||
->orWhere('sort', 10)
|
|
||||||
->orWhere('sort', 11)
|
|
||||||
->orWhere('sort', 12);
|
|
||||||
}
|
|
||||||
)->where('node_class', '<=', $user->class)->orderBy('name')->get();
|
|
||||||
|
|
||||||
$ports_raw = Node::where(
|
|
||||||
static function ($query) use ($user) {
|
|
||||||
$query->Where('node_group', '=', $user->node_group)
|
|
||||||
->orWhere('node_group', '=', 0);
|
|
||||||
}
|
|
||||||
)->where('type', 1)->where('sort', 9)->where('node_class', '<=', $user->class)->orderBy('name')->get();
|
|
||||||
|
|
||||||
$ports = array();
|
|
||||||
foreach ($ports_raw as $port_raw) {
|
|
||||||
$mu_user = User::where('port', $port_raw->server)->first();
|
|
||||||
if ($mu_user->is_multi_user == 1) {
|
|
||||||
$ports[] = $port_raw->server;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
foreach ($dist_nodes as $node) {
|
|
||||||
if ($node->sort == 11 || $node->sort == 12) {
|
|
||||||
$node_explode = Tools::v2Array($node->server);
|
|
||||||
$ports[] = $node_explode['port'];
|
|
||||||
$node->name = $node->name . ' 如果是V2ray后端 请设置成: ' . $node_explode['port'];
|
|
||||||
} else {
|
|
||||||
$node->name = $node->name . ' 如果是V2ray后端 请设置成 ' . $user->port;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$ports[] = $user->port;
|
|
||||||
$ports = array_unique($ports);
|
|
||||||
return $this->view()->assign('rule', $rule)->assign('source_nodes', $source_nodes)->assign('dist_nodes', $dist_nodes)->assign('ports', $ports)->display('user/relay/edit.tpl');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function update($request, $response, $args)
|
|
||||||
{
|
|
||||||
$id = $args['id'];
|
|
||||||
$user = Auth::getUser();
|
|
||||||
$rule = Relay::where('id', $id)->where('user_id', $user->id)->first();
|
|
||||||
|
|
||||||
if ($rule == null) {
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
$dist_node_id = $request->getParam('dist_node');
|
|
||||||
$source_node_id = $request->getParam('source_node');
|
|
||||||
$port = $request->getParam('port');
|
|
||||||
$priority = $request->getParam('priority');
|
|
||||||
|
|
||||||
$source_node = Node::where('id', $source_node_id)->where(
|
|
||||||
static function ($query) use ($user) {
|
|
||||||
$query->Where('node_group', '=', $user->node_group)
|
|
||||||
->orWhere('node_group', '=', 0);
|
|
||||||
}
|
|
||||||
)->where('type', 1)->where(
|
|
||||||
static function ($query) {
|
|
||||||
$query->Where('sort', 10)
|
|
||||||
->orWhere('sort', 12);
|
|
||||||
}
|
|
||||||
)->where('node_class', '<=', $user->class)->first();
|
|
||||||
if ($source_node == null) {
|
|
||||||
$rs['ret'] = 0;
|
|
||||||
$rs['msg'] = '起源节点错误';
|
|
||||||
return $response->getBody()->write(json_encode($rs));
|
|
||||||
}
|
|
||||||
|
|
||||||
$dist_node = Node::where('id', $dist_node_id)->where(
|
|
||||||
static function ($query) use ($user) {
|
|
||||||
$query->Where('node_group', '=', $user->node_group)
|
|
||||||
->orWhere('node_group', '=', 0);
|
|
||||||
}
|
|
||||||
)->where('type', 1)->where(
|
|
||||||
static function ($query) {
|
|
||||||
$query->Where('sort', 0)
|
|
||||||
->orWhere('sort', 10)
|
|
||||||
->orWhere('sort', 11)
|
|
||||||
->orWhere('sort', 12);
|
|
||||||
}
|
|
||||||
)->where('node_class', '<=', $user->class)->first();
|
|
||||||
|
|
||||||
if ($dist_node_id == -1) {
|
|
||||||
$dist_node = new Node();
|
|
||||||
$dist_node->id = -1;
|
|
||||||
$dist_node->node_ip = '0.0.0.0';
|
|
||||||
$dist_node->sort = 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($dist_node == null) {
|
|
||||||
$rs['ret'] = 0;
|
|
||||||
$rs['msg'] = '目标节点错误';
|
|
||||||
return $response->getBody()->write(json_encode($rs));
|
|
||||||
}
|
|
||||||
|
|
||||||
$port_raw = Node::where('server', $port)->where(
|
|
||||||
static function ($query) use ($user) {
|
|
||||||
$query->Where('node_group', '=', $user->node_group)
|
|
||||||
->orWhere('node_group', '=', 0);
|
|
||||||
}
|
|
||||||
)->where('type', 1)->where('sort', 9)->where('node_class', '<=', $user->class)->first();
|
|
||||||
$v2ray_port_raw = '';
|
|
||||||
if ($dist_node->sort == 12 || $dist_node->sort == 11) {
|
|
||||||
$node_explode = Tools::v2Array($dist_node->server);
|
|
||||||
$v2ray_port_raw = $node_explode['port'];
|
|
||||||
}
|
|
||||||
if (($port_raw == null && $port != $user->port && $v2ray_port_raw == '') || ($v2ray_port_raw != '' && ($port != $user->port && $port != $v2ray_port_raw))) {
|
|
||||||
$rs['ret'] = 0;
|
|
||||||
$rs['msg'] = '端口错误';
|
|
||||||
return $response->getBody()->write(json_encode($rs));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Tools::is_protocol_relay($user)) {
|
|
||||||
$rs['ret'] = 0;
|
|
||||||
$rs['msg'] = "为了中转的稳定,您需要在<a href='/user/edit'>资料编辑</a>处设置协议为 auth_aes128_md5 或 auth_aes128_sha1 后方可设置中转规则!";
|
|
||||||
return $response->getBody()->write(json_encode($rs));
|
|
||||||
}
|
|
||||||
|
|
||||||
$rule->user_id = $user->id;
|
|
||||||
$rule->dist_node_id = $dist_node_id;
|
|
||||||
|
|
||||||
$dist_node_ip = Tools::getRelayNodeIp($source_node, $dist_node);
|
|
||||||
$rule->dist_ip = $dist_node_ip;
|
|
||||||
|
|
||||||
$rule->source_node_id = $source_node_id;
|
|
||||||
$rule->port = $port;
|
|
||||||
$rule->priority = min($priority, 99998);
|
|
||||||
|
|
||||||
$ruleset = Relay::where('user_id', $user->id)->orwhere('user_id', 0)->get();
|
|
||||||
$maybe_rule_id = Tools::has_conflict_rule($rule, $ruleset, $rule->id, $rule->source_node_id);
|
|
||||||
if ($maybe_rule_id != 0) {
|
|
||||||
$rs['ret'] = 0;
|
|
||||||
$rs['msg'] = '您即将添加的规则与规则 ID:' . $maybe_rule_id . ' 冲突!';
|
|
||||||
if ($maybe_rule_id == -1) {
|
|
||||||
$rs['msg'] = '您即将添加的规则可能会造成冲突!';
|
|
||||||
}
|
|
||||||
return $response->getBody()->write(json_encode($rs));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$rule->save()) {
|
|
||||||
$rs['ret'] = 0;
|
|
||||||
$rs['msg'] = '修改失败';
|
|
||||||
return $response->getBody()->write(json_encode($rs));
|
|
||||||
}
|
|
||||||
|
|
||||||
$rs['ret'] = 1;
|
|
||||||
$rs['msg'] = '修改成功';
|
|
||||||
return $response->getBody()->write(json_encode($rs));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function delete($request, $response, $args)
|
|
||||||
{
|
|
||||||
$id = $request->getParam('id');
|
|
||||||
$user = Auth::getUser();
|
|
||||||
$rule = Relay::where('id', $id)->where('user_id', $user->id)->first();
|
|
||||||
|
|
||||||
if ($rule == null) {
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$rule->delete()) {
|
|
||||||
$rs['ret'] = 0;
|
|
||||||
$rs['msg'] = '删除失败';
|
|
||||||
return $response->getBody()->write(json_encode($rs));
|
|
||||||
}
|
|
||||||
$rs['ret'] = 1;
|
|
||||||
$rs['msg'] = '删除成功';
|
|
||||||
return $response->getBody()->write(json_encode($rs));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,20 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
|
|
||||||
namespace App\Controllers;
|
|
||||||
|
|
||||||
use Gregwar\Captcha\CaptchaBuilder;
|
|
||||||
|
|
||||||
class ResController
|
|
||||||
{
|
|
||||||
public function captcha($request, $response, $args)
|
|
||||||
{
|
|
||||||
$id = $args['id'];
|
|
||||||
$builder = new CaptchaBuilder();
|
|
||||||
$builder->build();
|
|
||||||
//$builder->getPhrase();
|
|
||||||
$newResponse = $response->withHeader('Content-type', ' image/jpeg');//->getBody()->write($builder->output());
|
|
||||||
$newResponse->getBody()->write($builder->output());
|
|
||||||
return $newResponse;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
File diff suppressed because it is too large
Load Diff
@ -1,440 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Controllers;
|
|
||||||
|
|
||||||
use App\Models\InviteCode;
|
|
||||||
use App\Models\User;
|
|
||||||
use App\Models\Code;
|
|
||||||
use App\Models\Payback;
|
|
||||||
use App\Models\Ann;
|
|
||||||
use App\Models\Shop;
|
|
||||||
use App\Services\Auth;
|
|
||||||
use App\Services\Config;
|
|
||||||
use App\Utils\AliPay;
|
|
||||||
use App\Utils\Tools;
|
|
||||||
use App\Utils\TelegramSessionManager;
|
|
||||||
use App\Utils\Spay_tool;
|
|
||||||
use App\Utils\Geetest;
|
|
||||||
|
|
||||||
use App\Utils\URL;
|
|
||||||
use App\Models\Node;
|
|
||||||
use App\Models\Relay;
|
|
||||||
|
|
||||||
class VueController extends BaseController
|
|
||||||
{
|
|
||||||
public function getGlobalConfig($request, $response, $args)
|
|
||||||
{
|
|
||||||
$GtSdk = null;
|
|
||||||
$recaptcha_sitekey = null;
|
|
||||||
$user = $this->user;
|
|
||||||
if (Config::get('captcha_provider') != '') {
|
|
||||||
switch (Config::get('captcha_provider')) {
|
|
||||||
case 'recaptcha':
|
|
||||||
$recaptcha_sitekey = Config::get('recaptcha_sitekey');
|
|
||||||
break;
|
|
||||||
case 'geetest':
|
|
||||||
$uid = time() . random_int(1, 10000);
|
|
||||||
$GtSdk = Geetest::get($uid);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Config::get('enable_telegram') == 'true') {
|
|
||||||
$login_text = TelegramSessionManager::add_login_session();
|
|
||||||
$login = explode('|', $login_text);
|
|
||||||
$login_token = $login[0];
|
|
||||||
$login_number = $login[1];
|
|
||||||
} else {
|
|
||||||
$login_token = '';
|
|
||||||
$login_number = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
$res['globalConfig'] = array(
|
|
||||||
'geetest_html' => $GtSdk,
|
|
||||||
'login_token' => $login_token,
|
|
||||||
'login_number' => $login_number,
|
|
||||||
'telegram_bot' => Config::get('telegram_bot'),
|
|
||||||
'enable_logincaptcha' => Config::get('enable_login_captcha'),
|
|
||||||
'enable_regcaptcha' => Config::get('enable_reg_captcha'),
|
|
||||||
'enable_checkin_captcha' => Config::get('enable_checkin_captcha'),
|
|
||||||
'base_url' => Config::get('baseUrl'),
|
|
||||||
'recaptcha_sitekey' => $recaptcha_sitekey,
|
|
||||||
'captcha_provider' => Config::get('captcha_provider'),
|
|
||||||
'jump_delay' => Config::get('jump_delay'),
|
|
||||||
'register_mode' => Config::get('register_mode'),
|
|
||||||
'enable_email_verify' => Config::get('enable_email_verify'),
|
|
||||||
'appName' => Config::get('appName'),
|
|
||||||
'dateY' => date('Y'),
|
|
||||||
'isLogin' => $user->isLogin,
|
|
||||||
'enable_telegram' => Config::get('enable_telegram'),
|
|
||||||
'enable_mylivechat' => Config::get('enable_mylivechat'),
|
|
||||||
'payment_type' => Config::get('payment_system'),
|
|
||||||
);
|
|
||||||
|
|
||||||
$res['ret'] = 1;
|
|
||||||
|
|
||||||
return $response->getBody()->write(json_encode($res));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function vuelogout($request, $response, $args)
|
|
||||||
{
|
|
||||||
Auth::logout();
|
|
||||||
$res['ret'] = 1;
|
|
||||||
return $response->getBody()->write(json_encode($res));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getUserInfo($request, $response, $args)
|
|
||||||
{
|
|
||||||
$user = $this->user;
|
|
||||||
|
|
||||||
if (!$user->isLogin) {
|
|
||||||
$res['ret'] = -1;
|
|
||||||
return $response->getBody()->write(json_encode($res));
|
|
||||||
}
|
|
||||||
|
|
||||||
$pre_user = URL::cloneUser($user);
|
|
||||||
$user->ssr_url_all = URL::getAllUrl($pre_user, 0, 0);
|
|
||||||
$user->ssr_url_all_mu = URL::getAllUrl($pre_user, 1, 0);
|
|
||||||
$user->ss_url_all = URL::getAllUrl($pre_user, 0, 2);
|
|
||||||
$ssinfo = URL::getSSConnectInfo($pre_user);
|
|
||||||
$user->ssd_url_all = URL::getAllSSDUrl($ssinfo);
|
|
||||||
$user->isAbleToCheckin = $user->isAbleToCheckin();
|
|
||||||
$ssr_sub_token = LinkController::GenerateSSRSubCode($this->user->id, 0);
|
|
||||||
$GtSdk = null;
|
|
||||||
$recaptcha_sitekey = null;
|
|
||||||
if (Config::get('captcha_provider') != '') {
|
|
||||||
switch (Config::get('captcha_provider')) {
|
|
||||||
case 'recaptcha':
|
|
||||||
$recaptcha_sitekey = Config::get('recaptcha_sitekey');
|
|
||||||
break;
|
|
||||||
case 'geetest':
|
|
||||||
$uid = time() . random_int(1, 10000);
|
|
||||||
$GtSdk = Geetest::get($uid);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$Ann = Ann::orderBy('date', 'desc')->first();
|
|
||||||
$display_ios_class = Config::get('display_ios_class');
|
|
||||||
$ios_account = Config::get('ios_account');
|
|
||||||
$ios_password = Config::get('ios_password');
|
|
||||||
$mergeSub = Config::get('mergeSub');
|
|
||||||
$subUrl = Config::get('subUrl');
|
|
||||||
$baseUrl = Config::get('baseUrl');
|
|
||||||
$user['online_ip_count'] = $user->online_ip_count();
|
|
||||||
|
|
||||||
$res['info'] = array(
|
|
||||||
'user' => $user,
|
|
||||||
'ssrSubToken' => $ssr_sub_token,
|
|
||||||
'displayIosClass' => $display_ios_class,
|
|
||||||
'iosAccount' => $ios_account,
|
|
||||||
'iosPassword' => $ios_password,
|
|
||||||
'mergeSub' => $mergeSub,
|
|
||||||
'subUrl' => $subUrl,
|
|
||||||
'baseUrl' => $baseUrl,
|
|
||||||
'ann' => $Ann,
|
|
||||||
'recaptchaSitekey' => $recaptcha_sitekey,
|
|
||||||
'GtSdk' => $GtSdk,
|
|
||||||
);
|
|
||||||
|
|
||||||
$res['ret'] = 1;
|
|
||||||
|
|
||||||
return $response->getBody()->write(json_encode($res));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getUserInviteInfo($request, $response, $args)
|
|
||||||
{
|
|
||||||
$user = $this->user;
|
|
||||||
|
|
||||||
if (!$user->isLogin) {
|
|
||||||
$res['ret'] = -1;
|
|
||||||
return $response->getBody()->write(json_encode($res));
|
|
||||||
}
|
|
||||||
|
|
||||||
$code = InviteCode::where('user_id', $user->id)->first();
|
|
||||||
if ($code == null) {
|
|
||||||
$user->addInviteCode();
|
|
||||||
$code = InviteCode::where('user_id', $user->id)->first();
|
|
||||||
}
|
|
||||||
|
|
||||||
$pageNum = $request->getParam('current');
|
|
||||||
|
|
||||||
$paybacks = Payback::where('ref_by', $user->id)->orderBy('id', 'desc')->paginate(15, ['*'], 'page', $pageNum);
|
|
||||||
if (!$paybacks_sum = Payback::where('ref_by', $user->id)->sum('ref_get')) {
|
|
||||||
$paybacks_sum = 0;
|
|
||||||
}
|
|
||||||
$paybacks->setPath('/#/user/panel');
|
|
||||||
|
|
||||||
$res['inviteInfo'] = array(
|
|
||||||
'code' => $code,
|
|
||||||
'paybacks' => $paybacks,
|
|
||||||
'paybacks_sum' => $paybacks_sum,
|
|
||||||
'invite_num' => $user->invite_num,
|
|
||||||
'invitePrice' => Config::get('invite_price'),
|
|
||||||
'customPrice' => Config::get('custom_invite_price'),
|
|
||||||
'invite_gift' => Config::get('invite_gift'),
|
|
||||||
'invite_get_money' => Config::get('invite_get_money'),
|
|
||||||
'code_payback' => Config::get('code_payback'),
|
|
||||||
);
|
|
||||||
|
|
||||||
$res['ret'] = 1;
|
|
||||||
|
|
||||||
return $response->getBody()->write(json_encode($res));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getUserShops($request, $response, $args)
|
|
||||||
{
|
|
||||||
$user = $this->user;
|
|
||||||
|
|
||||||
if (!$user->isLogin) {
|
|
||||||
$res['ret'] = -1;
|
|
||||||
return $response->getBody()->write(json_encode($res));
|
|
||||||
}
|
|
||||||
|
|
||||||
$shops = Shop::where('status', 1)->orderBy('name')->get();
|
|
||||||
|
|
||||||
$res['arr'] = array(
|
|
||||||
'shops' => $shops,
|
|
||||||
);
|
|
||||||
$res['ret'] = 1;
|
|
||||||
|
|
||||||
return $response->getBody()->write(json_encode($res));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getAllResourse($request, $response, $args)
|
|
||||||
{
|
|
||||||
$user = $this->user;
|
|
||||||
|
|
||||||
if (!$user->isLogin) {
|
|
||||||
$res['ret'] = -1;
|
|
||||||
return $response->getBody()->write(json_encode($res));
|
|
||||||
}
|
|
||||||
|
|
||||||
$res['resourse'] = array(
|
|
||||||
'money' => $user->money,
|
|
||||||
'class' => $user->class,
|
|
||||||
'class_expire' => $user->class_expire,
|
|
||||||
'expire_in' => $user->expire_in,
|
|
||||||
'online_ip_count' => $user->online_ip_count(),
|
|
||||||
'node_speedlimit' => $user->node_speedlimit,
|
|
||||||
'node_connector' => $user->node_connector,
|
|
||||||
);
|
|
||||||
$res['ret'] = 1;
|
|
||||||
|
|
||||||
return $response->getBody()->write(json_encode($res));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getNewSubToken($request, $response, $args)
|
|
||||||
{
|
|
||||||
$user = $this->user;
|
|
||||||
|
|
||||||
if (!$user->isLogin) {
|
|
||||||
$res['ret'] = -1;
|
|
||||||
return $response->getBody()->write(json_encode($res));
|
|
||||||
}
|
|
||||||
|
|
||||||
$user->clean_link();
|
|
||||||
$ssr_sub_token = LinkController::GenerateSSRSubCode($this->user->id, 0);
|
|
||||||
|
|
||||||
$res['arr'] = array(
|
|
||||||
'ssr_sub_token' => $ssr_sub_token,
|
|
||||||
);
|
|
||||||
|
|
||||||
$res['ret'] = 1;
|
|
||||||
|
|
||||||
return $response->getBody()->write(json_encode($res));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getNewInviteCode($request, $response, $args)
|
|
||||||
{
|
|
||||||
$user = $this->user;
|
|
||||||
|
|
||||||
if (!$user->isLogin) {
|
|
||||||
$res['ret'] = -1;
|
|
||||||
return $response->getBody()->write(json_encode($res));
|
|
||||||
}
|
|
||||||
|
|
||||||
$user->clear_inviteCodes();
|
|
||||||
$code = InviteCode::where('user_id', $this->user->id)->first();
|
|
||||||
if ($code == null) {
|
|
||||||
$this->user->addInviteCode();
|
|
||||||
$code = InviteCode::where('user_id', $this->user->id)->first();
|
|
||||||
}
|
|
||||||
|
|
||||||
$res['arr'] = array(
|
|
||||||
'code' => $code,
|
|
||||||
);
|
|
||||||
|
|
||||||
$res['ret'] = 1;
|
|
||||||
|
|
||||||
return $response->getBody()->write(json_encode($res));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getTransfer($request, $response, $args)
|
|
||||||
{
|
|
||||||
$user = $this->user;
|
|
||||||
|
|
||||||
if (!$user->isLogin) {
|
|
||||||
$res['ret'] = -1;
|
|
||||||
return $response->getBody()->write(json_encode($res));
|
|
||||||
}
|
|
||||||
|
|
||||||
$res['arr'] = array(
|
|
||||||
'todayUsedTraffic' => $user->TodayusedTraffic(),
|
|
||||||
'lastUsedTraffic' => $user->LastusedTraffic(),
|
|
||||||
'unUsedTraffic' => $user->unusedTraffic(),
|
|
||||||
);
|
|
||||||
|
|
||||||
$res['ret'] = 1;
|
|
||||||
|
|
||||||
return $response->getBody()->write(json_encode($res));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getCaptcha($request, $response, $args)
|
|
||||||
{
|
|
||||||
$GtSdk = null;
|
|
||||||
$recaptcha_sitekey = null;
|
|
||||||
if (Config::get('captcha_provider') != '') {
|
|
||||||
switch (Config::get('captcha_provider')) {
|
|
||||||
case 'recaptcha':
|
|
||||||
$recaptcha_sitekey = Config::get('recaptcha_sitekey');
|
|
||||||
$res['recaptchaKey'] = $recaptcha_sitekey;
|
|
||||||
break;
|
|
||||||
case 'geetest':
|
|
||||||
$uid = time() . random_int(1, 10000);
|
|
||||||
$GtSdk = Geetest::get($uid);
|
|
||||||
$res['GtSdk'] = $GtSdk;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$res['respon'] = 1;
|
|
||||||
return $response->getBody()->write(json_encode($res));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getChargeLog($request, $response, $args)
|
|
||||||
{
|
|
||||||
$user = $this->user;
|
|
||||||
|
|
||||||
if (!$user->isLogin) {
|
|
||||||
$res['ret'] = -1;
|
|
||||||
return $response->getBody()->write(json_encode($res));
|
|
||||||
}
|
|
||||||
|
|
||||||
$pageNum = $request->getParam('current');
|
|
||||||
|
|
||||||
$codes = Code::where('type', '<>', '-2')->where('userid', '=', $user->id)->orderBy('id', 'desc')->paginate(15, ['*'], 'page', $pageNum);
|
|
||||||
$codes->setPath('/#/user/code');
|
|
||||||
|
|
||||||
$res['codes'] = $codes;
|
|
||||||
$res['ret'] = 1;
|
|
||||||
|
|
||||||
return $response->getBody()->write(json_encode($res));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getNodeList($request, $response, $args)
|
|
||||||
{
|
|
||||||
$user = Auth::getUser();
|
|
||||||
|
|
||||||
if (!$this->user->isLogin) {
|
|
||||||
$res['ret'] = -1;
|
|
||||||
return $response->getBody()->write(json_encode($res));
|
|
||||||
}
|
|
||||||
|
|
||||||
$nodes = Node::where('type', 1)->orderBy('node_class')->orderBy('name')->get();
|
|
||||||
$relay_rules = Relay::where('user_id', $this->user->id)->orwhere('user_id', 0)->orderBy('id', 'asc')->get();
|
|
||||||
if (!Tools::is_protocol_relay($user)) {
|
|
||||||
$relay_rules = array();
|
|
||||||
}
|
|
||||||
|
|
||||||
$array_nodes = array();
|
|
||||||
$nodes_muport = array();
|
|
||||||
|
|
||||||
foreach ($nodes as $node) {
|
|
||||||
if ($node->node_group != $user->node_group && $node->node_group != 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if ($node->sort == 9) {
|
|
||||||
$mu_user = User::where('port', '=', $node->server)->first();
|
|
||||||
$mu_user->obfs_param = $this->user->getMuMd5();
|
|
||||||
$nodes_muport[] = array('server' => $node, 'user' => $mu_user);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$array_node = array();
|
|
||||||
|
|
||||||
$array_node['id'] = $node->id;
|
|
||||||
$array_node['class'] = $node->node_class;
|
|
||||||
$array_node['name'] = $node->name;
|
|
||||||
if ($this->user->class < $node->node_class) {
|
|
||||||
$array_node['server'] = '***.***.***.***';
|
|
||||||
} elseif ($node->sort == 13) {
|
|
||||||
$server = Tools::ssv2Array($node->server);
|
|
||||||
$array_node['server'] = $server['add'];
|
|
||||||
} else {
|
|
||||||
$array_node['server'] = $node->server;
|
|
||||||
}
|
|
||||||
|
|
||||||
$array_node['sort'] = $node->sort;
|
|
||||||
$array_node['info'] = $node->info;
|
|
||||||
$array_node['mu_only'] = $node->mu_only;
|
|
||||||
$array_node['group'] = $node->node_group;
|
|
||||||
|
|
||||||
$array_node['raw_node'] = $node;
|
|
||||||
$regex = Config::get('flag_regex');
|
|
||||||
$matches = array();
|
|
||||||
preg_match($regex, $node->name, $matches);
|
|
||||||
if (isset($matches[0])) {
|
|
||||||
$array_node['flag'] = $matches[0] . '.png';
|
|
||||||
} else {
|
|
||||||
$array_node['flag'] = 'unknown.png';
|
|
||||||
}
|
|
||||||
|
|
||||||
$node_online = $node->isNodeOnline();
|
|
||||||
if ($node_online === null) {
|
|
||||||
$array_node['online'] = 0;
|
|
||||||
} elseif ($node_online === true) {
|
|
||||||
$array_node['online'] = 1;
|
|
||||||
} elseif ($node_online === false) {
|
|
||||||
$array_node['online'] = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (in_array($node->sort, array(0, 7, 8, 10, 11, 12, 13))) {
|
|
||||||
$array_node['online_user'] = $node->getOnlineUserCount();
|
|
||||||
} else {
|
|
||||||
$array_node['online_user'] = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
$nodeLoad = $node->getNodeLoad();
|
|
||||||
if (isset($nodeLoad[0]['load'])) {
|
|
||||||
$array_node['latest_load'] = (explode(' ', $nodeLoad[0]['load']))[0] * 100;
|
|
||||||
} else {
|
|
||||||
$array_node['latest_load'] = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
$array_node['traffic_used'] = (int)Tools::flowToGB($node->node_bandwidth);
|
|
||||||
$array_node['traffic_limit'] = (int)Tools::flowToGB($node->node_bandwidth_limit);
|
|
||||||
if ($node->node_speedlimit == 0.0) {
|
|
||||||
$array_node['bandwidth'] = 0;
|
|
||||||
} elseif ($node->node_speedlimit >= 1024.00) {
|
|
||||||
$array_node['bandwidth'] = round($node->node_speedlimit / 1024.00, 1) . 'Gbps';
|
|
||||||
} else {
|
|
||||||
$array_node['bandwidth'] = $node->node_speedlimit . 'Mbps';
|
|
||||||
}
|
|
||||||
|
|
||||||
$array_node['traffic_rate'] = $node->traffic_rate;
|
|
||||||
$array_node['status'] = $node->status;
|
|
||||||
|
|
||||||
$array_nodes[] = $array_node;
|
|
||||||
}
|
|
||||||
|
|
||||||
$res['nodeinfo'] = array(
|
|
||||||
'nodes' => $array_nodes,
|
|
||||||
'nodes_muport' => $nodes_muport,
|
|
||||||
'relay_rules' => $relay_rules,
|
|
||||||
'user' => $user,
|
|
||||||
'tools' => new Tools(),
|
|
||||||
);
|
|
||||||
$res['ret'] = 1;
|
|
||||||
|
|
||||||
return $response->getBody()->write(json_encode($res));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,28 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Middleware;
|
|
||||||
|
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
|
||||||
use Psr\Http\Message\ResponseInterface;
|
|
||||||
use App\Services\Auth as AuthService;
|
|
||||||
|
|
||||||
class Admin
|
|
||||||
{
|
|
||||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $next)
|
|
||||||
{
|
|
||||||
//$response->getBody()->write('BEFORE');
|
|
||||||
$user = AuthService::getUser();
|
|
||||||
if (!$user->isLogin) {
|
|
||||||
$newResponse = $response->withStatus(302)->withHeader('Location', '/auth/login');
|
|
||||||
return $newResponse;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$user->isAdmin()) {
|
|
||||||
$newResponse = $response->withStatus(302)->withHeader('Location', '/user');
|
|
||||||
return $newResponse;
|
|
||||||
}
|
|
||||||
|
|
||||||
$response = $next($request, $response);
|
|
||||||
return $response;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,38 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Middleware;
|
|
||||||
|
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
|
||||||
use Psr\Http\Message\ResponseInterface;
|
|
||||||
use App\Services\Factory;
|
|
||||||
use App\Utils\Helper;
|
|
||||||
|
|
||||||
class Api
|
|
||||||
{
|
|
||||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $next)
|
|
||||||
{
|
|
||||||
$accessToken = Helper::getParam($request, 'access_token');
|
|
||||||
if ($accessToken == null) {
|
|
||||||
$res['ret'] = 0;
|
|
||||||
$res['msg'] = 'token is null';
|
|
||||||
$response->getBody()->write(json_encode($res));
|
|
||||||
return $response;
|
|
||||||
}
|
|
||||||
$storage = Factory::createTokenStorage();
|
|
||||||
$token = $storage->get($accessToken);
|
|
||||||
if ($token == null) {
|
|
||||||
$res['ret'] = 0;
|
|
||||||
$res['msg'] = 'token is null';
|
|
||||||
$response->getBody()->write(json_encode($res));
|
|
||||||
return $response;
|
|
||||||
}
|
|
||||||
if ($token->expireTime < time()) {
|
|
||||||
$res['ret'] = 0;
|
|
||||||
$res['msg'] = 'token is expire';
|
|
||||||
$response->getBody()->write(json_encode($res));
|
|
||||||
return $response;
|
|
||||||
}
|
|
||||||
$response = $next($request, $response);
|
|
||||||
return $response;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,26 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Middleware;
|
|
||||||
|
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
|
||||||
use Psr\Http\Message\ResponseInterface;
|
|
||||||
use App\Services\Auth as AuthService;
|
|
||||||
|
|
||||||
class Auth
|
|
||||||
{
|
|
||||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $next)
|
|
||||||
{
|
|
||||||
$user = AuthService::getUser();
|
|
||||||
if (!$user->isLogin) {
|
|
||||||
$newResponse = $response->withStatus(302)->withHeader('Location', '/auth/login');
|
|
||||||
return $newResponse;
|
|
||||||
}
|
|
||||||
$enablePages = array('/user/disable', '/user/backtoadmin', '/user/logout');
|
|
||||||
if ($user->enable == 0 && !in_array($_SERVER['REQUEST_URI'], $enablePages)) {
|
|
||||||
$newResponse = $response->withStatus(302)->withHeader('Location', '/user/disable');
|
|
||||||
return $newResponse;
|
|
||||||
}
|
|
||||||
$response = $next($request, $response);
|
|
||||||
return $response;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,20 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Middleware;
|
|
||||||
|
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
|
||||||
use Psr\Http\Message\ResponseInterface;
|
|
||||||
use App\Services\Auth as AuthService;
|
|
||||||
|
|
||||||
class Guest
|
|
||||||
{
|
|
||||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $next)
|
|
||||||
{
|
|
||||||
$user = AuthService::getUser();
|
|
||||||
if ($user->isLogin) {
|
|
||||||
return $response->withStatus(302)->withHeader('Location', '/user');
|
|
||||||
}
|
|
||||||
$response = $next($request, $response);
|
|
||||||
return $response;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,51 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
|
|
||||||
namespace App\Middleware;
|
|
||||||
|
|
||||||
use App\Services\Config;
|
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
|
||||||
use Psr\Http\Message\ResponseInterface;
|
|
||||||
use App\Utils\Helper;
|
|
||||||
use App\Models\Node;
|
|
||||||
|
|
||||||
class Mod_Mu
|
|
||||||
{
|
|
||||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $next)
|
|
||||||
{
|
|
||||||
$key = Helper::getParam($request, 'key');
|
|
||||||
if ($key === null) {
|
|
||||||
$res['ret'] = 0;
|
|
||||||
$res['data'] = 'null';
|
|
||||||
$response->getBody()->write(json_encode($res));
|
|
||||||
return $response;
|
|
||||||
}
|
|
||||||
|
|
||||||
$auth = false;
|
|
||||||
$keys = Config::getMuKey();
|
|
||||||
foreach ($keys as $k) {
|
|
||||||
if ($key == $k) {
|
|
||||||
$auth = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$node = Node::where('node_ip', 'LIKE', $_SERVER['REMOTE_ADDR'] . '%')->first();
|
|
||||||
if ($node == null && $_SERVER['REMOTE_ADDR'] != '127.0.0.1') {
|
|
||||||
$res['ret'] = 0;
|
|
||||||
$res['data'] = 'token or source is invalid, Your ip address is ' . $_SERVER['REMOTE_ADDR'];
|
|
||||||
$response->getBody()->write(json_encode($res));
|
|
||||||
return $response;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($auth == false) {
|
|
||||||
$res['ret'] = 0;
|
|
||||||
$res['data'] = 'token or source is invalid';
|
|
||||||
$response->getBody()->write(json_encode($res));
|
|
||||||
return $response;
|
|
||||||
}
|
|
||||||
|
|
||||||
$response = $next($request, $response);
|
|
||||||
return $response;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,51 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
|
|
||||||
namespace App\Middleware;
|
|
||||||
|
|
||||||
use App\Services\Config;
|
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
|
||||||
use Psr\Http\Message\ResponseInterface;
|
|
||||||
use App\Utils\Helper;
|
|
||||||
use App\Models\Node;
|
|
||||||
|
|
||||||
class Mu
|
|
||||||
{
|
|
||||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $next)
|
|
||||||
{
|
|
||||||
$key = Helper::getParam($request, 'key');
|
|
||||||
if ($key === null) {
|
|
||||||
$res['ret'] = 0;
|
|
||||||
$res['msg'] = 'key is null';
|
|
||||||
$response->getBody()->write(json_encode($res));
|
|
||||||
return $response;
|
|
||||||
}
|
|
||||||
|
|
||||||
$auth = false;
|
|
||||||
$keyset = explode(',', Config::get('muKey'));
|
|
||||||
foreach ($keyset as $sinkey) {
|
|
||||||
if ($key == $sinkey) {
|
|
||||||
$auth = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($auth == false) {
|
|
||||||
$res['ret'] = 0;
|
|
||||||
$res['msg'] = 'token or source is invalid';
|
|
||||||
$response->getBody()->write(json_encode($res));
|
|
||||||
return $response;
|
|
||||||
}
|
|
||||||
|
|
||||||
$node = Node::where('node_ip', 'LIKE', $_SERVER['REMOTE_ADDR'] . '%')->first();
|
|
||||||
if ($node == null && $_SERVER['REMOTE_ADDR'] != '127.0.0.1') {
|
|
||||||
$res['ret'] = 0;
|
|
||||||
$res['msg'] = 'token or source is invalid';
|
|
||||||
$response->getBody()->write(json_encode($res));
|
|
||||||
return $response;
|
|
||||||
}
|
|
||||||
|
|
||||||
$response = $next($request, $response);
|
|
||||||
return $response;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,12 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Ann Model
|
|
||||||
*/
|
|
||||||
class Ann extends Model
|
|
||||||
{
|
|
||||||
protected $connection = 'default';
|
|
||||||
protected $table = 'announcement';
|
|
||||||
}
|
|
||||||
@ -1,20 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
class Auto extends Model
|
|
||||||
{
|
|
||||||
protected $connection = 'default';
|
|
||||||
protected $table = 'auto';
|
|
||||||
|
|
||||||
|
|
||||||
public function datetime()
|
|
||||||
{
|
|
||||||
return date('Y-m-d H:i:s', $this->attributes['datetime']);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function content()
|
|
||||||
{
|
|
||||||
return str_replace(PHP_EOL, '<br>', $this->attributes['value']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,21 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
class BlockIp extends Model
|
|
||||||
{
|
|
||||||
protected $connection = 'default';
|
|
||||||
protected $table = 'blockip';
|
|
||||||
|
|
||||||
|
|
||||||
public function node()
|
|
||||||
{
|
|
||||||
return Node::where('id', $this->attributes['nodeid'])->first();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function time()
|
|
||||||
{
|
|
||||||
return date('Y-m-d H:i:s', $this->attributes['datetime']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,35 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
class Bought extends Model
|
|
||||||
{
|
|
||||||
protected $connection = 'default';
|
|
||||||
protected $table = 'bought';
|
|
||||||
|
|
||||||
public function renew_date()
|
|
||||||
{
|
|
||||||
return date('Y-m-d H:i:s', $this->attributes['renew']);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function datetime()
|
|
||||||
{
|
|
||||||
return date('Y-m-d H:i:s', $this->attributes['datetime']);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function user()
|
|
||||||
{
|
|
||||||
$user = User::where('id', $this->attributes['userid'])->first();
|
|
||||||
if ($user == null) {
|
|
||||||
self::where('id', '=', $this->attributes['id'])->delete();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $user;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function shop()
|
|
||||||
{
|
|
||||||
return Shop::where('id', $this->attributes['shopid'])->first();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,10 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
class CheckInLog
|
|
||||||
{
|
|
||||||
protected $connection = 'default';
|
|
||||||
protected $table = 'ss_checkin_log';
|
|
||||||
}
|
|
||||||
@ -1,18 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Code Model
|
|
||||||
*/
|
|
||||||
class Code extends Model
|
|
||||||
{
|
|
||||||
protected $connection = 'default';
|
|
||||||
protected $table = 'code';
|
|
||||||
|
|
||||||
|
|
||||||
public function user()
|
|
||||||
{
|
|
||||||
return User::where('id', $this->attributes['userid'])->first();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,9 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
class Config extends Model
|
|
||||||
{
|
|
||||||
protected $connection = 'default';
|
|
||||||
protected $table = 'config';
|
|
||||||
}
|
|
||||||
@ -1,31 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
class Coupon extends Model
|
|
||||||
{
|
|
||||||
protected $connection = 'default';
|
|
||||||
protected $table = 'coupon';
|
|
||||||
|
|
||||||
public function expire()
|
|
||||||
{
|
|
||||||
return date('Y-m-d H:i:s', $this->attributes['expire']);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function order($shop)
|
|
||||||
{
|
|
||||||
if ($this->attributes['shop'] == '') {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
$shop_array = explode(',', $this->attributes['shop']);
|
|
||||||
|
|
||||||
foreach ($shop_array as $shopid) {
|
|
||||||
if ($shopid == $shop) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,9 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
class DetectBanLog extends Model
|
|
||||||
{
|
|
||||||
protected $connection = "default";
|
|
||||||
protected $table = "detect_ban_log";
|
|
||||||
}
|
|
||||||
@ -1,42 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
class DetectLog extends Model
|
|
||||||
{
|
|
||||||
protected $connection = 'default';
|
|
||||||
protected $table = 'detect_log';
|
|
||||||
|
|
||||||
public function DetectRule()
|
|
||||||
{
|
|
||||||
$rule = DetectRule::where('id', $this->attributes['list_id'])->first();
|
|
||||||
if ($rule == null) {
|
|
||||||
self::where('id', '=', $this->attributes['id'])->delete();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $rule;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function User()
|
|
||||||
{
|
|
||||||
$user = User::where('id', $this->attributes['user_id'])->first();
|
|
||||||
if ($user == null) {
|
|
||||||
self::where('id', '=', $this->attributes['id'])->delete();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $user;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function Node()
|
|
||||||
{
|
|
||||||
$node = Node::where('id', $this->attributes['node_id'])->first();
|
|
||||||
if ($node == null) {
|
|
||||||
self::where('id', '=', $this->attributes['id'])->delete();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $node;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,12 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* DetectLog Model
|
|
||||||
*/
|
|
||||||
class DetectRule extends Model
|
|
||||||
{
|
|
||||||
protected $connection = 'default';
|
|
||||||
protected $table = 'detect_list';
|
|
||||||
}
|
|
||||||
@ -1,12 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Disconnect Model
|
|
||||||
*/
|
|
||||||
class Disconnect extends Model
|
|
||||||
{
|
|
||||||
protected $connection = 'default';
|
|
||||||
protected $table = 'disconnect_ip';
|
|
||||||
}
|
|
||||||
@ -1,12 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* EmailVerify Model
|
|
||||||
*/
|
|
||||||
class EmailVerify extends Model
|
|
||||||
{
|
|
||||||
protected $connection = 'default';
|
|
||||||
protected $table = 'email_verify';
|
|
||||||
}
|
|
||||||
@ -1,12 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* InviteCode Model
|
|
||||||
*/
|
|
||||||
class InviteCode extends Model
|
|
||||||
{
|
|
||||||
protected $connection = 'default';
|
|
||||||
protected $table = 'ss_invite_code';
|
|
||||||
}
|
|
||||||
@ -1,40 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Ip Model
|
|
||||||
*/
|
|
||||||
class Ip extends Model
|
|
||||||
{
|
|
||||||
protected $connection = 'default';
|
|
||||||
protected $table = 'alive_ip';
|
|
||||||
|
|
||||||
public function user()
|
|
||||||
{
|
|
||||||
$user = User::where('id', $this->attributes['userid'])->first();
|
|
||||||
if ($user == null) {
|
|
||||||
self::where('id', '=', $this->attributes['id'])->delete();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $user;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function Node()
|
|
||||||
{
|
|
||||||
$node = Node::where('id', $this->attributes['nodeid'])->first();
|
|
||||||
if ($node == null) {
|
|
||||||
self::where('id', '=', $this->attributes['id'])->delete();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $node;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function ip()
|
|
||||||
{
|
|
||||||
return str_replace('::ffff:', '', $this->attributes['ip']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,9 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
class Link extends Model
|
|
||||||
{
|
|
||||||
protected $connection = 'default';
|
|
||||||
protected $table = 'link';
|
|
||||||
}
|
|
||||||
@ -1,28 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Ip Model
|
|
||||||
*/
|
|
||||||
class LoginIp extends Model
|
|
||||||
{
|
|
||||||
protected $connection = 'default';
|
|
||||||
protected $table = 'login_ip';
|
|
||||||
|
|
||||||
public function user()
|
|
||||||
{
|
|
||||||
$user = User::where('id', $this->attributes['userid'])->first();
|
|
||||||
if ($user == null) {
|
|
||||||
self::where('id', '=', $this->attributes['id'])->delete();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $user;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function datetime()
|
|
||||||
{
|
|
||||||
return date('Y-m-d H:i:s', $this->attributes['datetime']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,13 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model as EloquentMedel;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Base Model
|
|
||||||
*/
|
|
||||||
class Model extends EloquentMedel
|
|
||||||
{
|
|
||||||
public $timestamps = false;
|
|
||||||
}
|
|
||||||
@ -1,175 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Node Model
|
|
||||||
*/
|
|
||||||
|
|
||||||
use App\Utils\Tools;
|
|
||||||
use App\Utils\DNSoverHTTPS;
|
|
||||||
class Node extends Model
|
|
||||||
{
|
|
||||||
protected $connection = 'default';
|
|
||||||
protected $table = 'ss_node';
|
|
||||||
|
|
||||||
protected $casts = [
|
|
||||||
'node_speedlimit' => 'float',
|
|
||||||
'traffic_rate' => 'float',
|
|
||||||
'mu_only' => 'int',
|
|
||||||
'sort' => 'int',
|
|
||||||
];
|
|
||||||
|
|
||||||
public function getLastNodeInfoLog()
|
|
||||||
{
|
|
||||||
$id = $this->attributes['id'];
|
|
||||||
$log = NodeInfoLog::where('node_id', $id)->orderBy('id', 'desc')->first();
|
|
||||||
if ($log == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return $log;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getNodeUptime()
|
|
||||||
{
|
|
||||||
$log = $this->getLastNodeInfoLog();
|
|
||||||
if ($log == null) {
|
|
||||||
return '暂无数据';
|
|
||||||
}
|
|
||||||
return Tools::secondsToTime((int)$log->uptime);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function getNodeUpRate()
|
|
||||||
{
|
|
||||||
$id = $this->attributes['id'];
|
|
||||||
$log = NodeOnlineLog::where('node_id', $id)->where('log_time', '>=', time() - 86400)->count();
|
|
||||||
|
|
||||||
return $log / 1440;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getNodeLoad()
|
|
||||||
{
|
|
||||||
$id = $this->attributes['id'];
|
|
||||||
$log = NodeInfoLog::where('node_id', $id)->orderBy(
|
|
||||||
'id',
|
|
||||||
'desc'
|
|
||||||
)->whereRaw('`log_time`%1800<60')->limit(48)->get();
|
|
||||||
return $log;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getNodeAlive()
|
|
||||||
{
|
|
||||||
$id = $this->attributes['id'];
|
|
||||||
$log = NodeOnlineLog::where('node_id', $id)->orderBy(
|
|
||||||
'id',
|
|
||||||
'desc'
|
|
||||||
)->whereRaw('`log_time`%1800<60')->limit(48)->get();
|
|
||||||
return $log;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getOnlineUserCount()
|
|
||||||
{
|
|
||||||
$id = $this->attributes['id'];
|
|
||||||
$log = NodeOnlineLog::where('node_id', $id)->where('log_time', '>', time() - 300)->orderBy(
|
|
||||||
'id',
|
|
||||||
'desc'
|
|
||||||
)->first();
|
|
||||||
if ($log == null) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return $log->online_user;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getSpeedtest()
|
|
||||||
{
|
|
||||||
$id = $this->attributes['id'];
|
|
||||||
$log = Speedtest::where('nodeid', $id)->orderBy('datetime', 'desc')->first();
|
|
||||||
if ($log == null) {
|
|
||||||
return '暂无数据';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return '电信延迟:' . $log->telecomping . ' 下载:' . $log->telecomeupload . ' 上传:' . $log->telecomedownload . '<br>
|
|
||||||
联通延迟:' . $log->unicomping . ' 下载:' . $log->unicomupload . ' 上传:' . $log->unicomdownload . '<br>
|
|
||||||
移动延迟:' . $log->cmccping . ' 下载:' . $log->cmccupload . ' 上传:' . $log->cmccdownload . '<br>定时测试,仅供参考';
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getSpeedtestResult()
|
|
||||||
{
|
|
||||||
$id = $this->attributes['id'];
|
|
||||||
$log = Speedtest::where('nodeid', $id)->orderBy('id', 'desc')->limit(48)->get();
|
|
||||||
if ($log == null) {
|
|
||||||
return '暂无数据';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return $log;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getTrafficFromLogs()
|
|
||||||
{
|
|
||||||
$id = $this->attributes['id'];
|
|
||||||
|
|
||||||
$traffic = TrafficLog::where('node_id', $id)->sum('u') + TrafficLog::where('node_id', $id)->sum('d');
|
|
||||||
|
|
||||||
if ($traffic == 0) {
|
|
||||||
return '暂无数据';
|
|
||||||
}
|
|
||||||
|
|
||||||
return Tools::flowAutoShow($traffic);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function isNodeOnline()
|
|
||||||
{
|
|
||||||
$delay = 300;
|
|
||||||
if ($this->attributes['node_heartbeat'] === 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!in_array($this->attributes['sort'], [0, 7, 8, 10, 11, 12, 13])) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->attributes['node_heartbeat'] > time() - $delay) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function isNodeTrafficOut()
|
|
||||||
{
|
|
||||||
$node_bandwidth = $this->attributes['node_bandwidth'];
|
|
||||||
$node_bandwidth_limit = $this->attributes['node_bandwidth_limit'];
|
|
||||||
|
|
||||||
return !($node_bandwidth_limit == 0 || $node_bandwidth < $node_bandwidth_limit);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function isNodeAccessable()
|
|
||||||
{
|
|
||||||
return $this->isNodeTrafficOut() == false && $this->isNodeOnline() == true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function changeNodeIp($server_name)
|
|
||||||
{
|
|
||||||
$ip = gethostbyname($server_name);
|
|
||||||
if ($ip=="127.0.0.1"){
|
|
||||||
$ip = DNSoverHTTPS::gethostbyName($server_name);
|
|
||||||
}
|
|
||||||
$node_id = $this->attributes['id'];
|
|
||||||
|
|
||||||
if ($ip == '') {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->attributes['node_ip'] = $ip;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getNodeIp()
|
|
||||||
{
|
|
||||||
$node_ip_str = $this->attributes['node_ip'];
|
|
||||||
$node_ip_array = explode(',', $node_ip_str);
|
|
||||||
return $node_ip_array[0];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,22 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
class NodeInfoLog extends Model
|
|
||||||
{
|
|
||||||
protected $connection = 'default';
|
|
||||||
protected $table = 'ss_node_info';
|
|
||||||
|
|
||||||
public function getNodeLoad()
|
|
||||||
{
|
|
||||||
$load = $this->attributes['load'];
|
|
||||||
$exp = explode(' ', $load);
|
|
||||||
return $exp[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getTime()
|
|
||||||
{
|
|
||||||
$time = $this->attributes['log_time'];
|
|
||||||
return date('Y-m-d H:i:s', $time);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,10 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
class NodeOnlineLog extends Model
|
|
||||||
{
|
|
||||||
protected $connection = 'default';
|
|
||||||
protected $table = 'ss_node_online_log';
|
|
||||||
}
|
|
||||||
@ -1,9 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
class PasswordReset extends Model
|
|
||||||
{
|
|
||||||
protected $connection = 'default';
|
|
||||||
protected $table = 'ss_password_reset';
|
|
||||||
}
|
|
||||||
@ -1,20 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
class Payback extends Model
|
|
||||||
{
|
|
||||||
protected $connection = 'default';
|
|
||||||
protected $table = 'payback';
|
|
||||||
|
|
||||||
public function user()
|
|
||||||
{
|
|
||||||
$user = User::where('id', $this->attributes['userid'])->first();
|
|
||||||
if ($user == null) {
|
|
||||||
Bought::where('id', '=', $this->attributes['id'])->delete();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $user;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,9 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
class Paylist extends Model
|
|
||||||
{
|
|
||||||
protected $connection = 'default';
|
|
||||||
protected $table = 'paylist';
|
|
||||||
}
|
|
||||||
@ -1,9 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
class RadiusBan extends Model
|
|
||||||
{
|
|
||||||
protected $connection = 'default';
|
|
||||||
protected $table = 'radius_ban';
|
|
||||||
}
|
|
||||||
@ -1,9 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
class RadiusNas extends Model
|
|
||||||
{
|
|
||||||
protected $connection = 'radius';
|
|
||||||
protected $table = 'nas';
|
|
||||||
}
|
|
||||||
@ -1,9 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
class RadiusRadAcct extends Model
|
|
||||||
{
|
|
||||||
protected $connection = 'radius';
|
|
||||||
protected $table = 'radacct';
|
|
||||||
}
|
|
||||||
@ -1,9 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
class RadiusRadCheck extends Model
|
|
||||||
{
|
|
||||||
protected $connection = 'radius';
|
|
||||||
protected $table = 'radcheck';
|
|
||||||
}
|
|
||||||
@ -1,9 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
class RadiusRadPostauth extends Model
|
|
||||||
{
|
|
||||||
protected $connection = 'radius';
|
|
||||||
protected $table = 'radpostauth';
|
|
||||||
}
|
|
||||||
@ -1,9 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
class RadiusRadUserGroup extends Model
|
|
||||||
{
|
|
||||||
protected $connection = 'radius';
|
|
||||||
protected $table = 'radusergroup';
|
|
||||||
}
|
|
||||||
@ -1,49 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* DetectLog Model
|
|
||||||
*/
|
|
||||||
class Relay extends Model
|
|
||||||
{
|
|
||||||
protected $connection = 'default';
|
|
||||||
protected $table = 'relay';
|
|
||||||
|
|
||||||
public function User()
|
|
||||||
{
|
|
||||||
$user = User::where('id', $this->attributes['user_id'])->first();
|
|
||||||
if ($user == null) {
|
|
||||||
self::where('id', '=', $this->attributes['id'])->delete();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $user;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function Source_Node()
|
|
||||||
{
|
|
||||||
$node = Node::where('id', $this->attributes['source_node_id'])->first();
|
|
||||||
if ($node == null && $this->attributes['source_node_id'] != 0) {
|
|
||||||
self::where('id', '=', $this->attributes['id'])->delete();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $node;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function Dist_Node()
|
|
||||||
{
|
|
||||||
if ($this->attributes['dist_node_id'] == -1) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$node = Node::where('id', $this->attributes['dist_node_id'])->first();
|
|
||||||
if ($node == null) {
|
|
||||||
self::where('id', '=', $this->attributes['id'])->delete();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $node;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,12 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Node Model
|
|
||||||
*/
|
|
||||||
class Role extends Model
|
|
||||||
{
|
|
||||||
protected $connection = 'default';
|
|
||||||
protected $table = 'user_role';
|
|
||||||
}
|
|
||||||
@ -1,187 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
use App\Services\Config;
|
|
||||||
|
|
||||||
class Shop extends Model
|
|
||||||
{
|
|
||||||
protected $connection = 'default';
|
|
||||||
protected $table = 'shop';
|
|
||||||
|
|
||||||
public function content()
|
|
||||||
{
|
|
||||||
$content = json_decode($this->attributes['content'], true);
|
|
||||||
$content_text = '';
|
|
||||||
$i = 0;
|
|
||||||
foreach ($content as $key => $value) {
|
|
||||||
switch ($key) {
|
|
||||||
case 'bandwidth':
|
|
||||||
$content_text .= '添加流量 ' . $value . ' G ';
|
|
||||||
break;
|
|
||||||
case 'expire':
|
|
||||||
$content_text .= ', 为账号的有效期添加 ' . $value . ' 天 ';
|
|
||||||
break;
|
|
||||||
case 'class':
|
|
||||||
$content_text .= ', 为账号升级为等级 ' . $value . ' , 有效期 ' . $content['class_expire'] . ' 天 ';
|
|
||||||
break;
|
|
||||||
case 'reset':
|
|
||||||
$content_text .= ', 在 ' . $content['reset_exp'] . ' 天内 ,每 ' . $value . ' 天重置流量为 ' . $content['reset_value'] . ' G ';
|
|
||||||
break;
|
|
||||||
case 'speedlimit':
|
|
||||||
if ($value == 0) {
|
|
||||||
$content_text .= ', 用户端口不限速 ';
|
|
||||||
} else {
|
|
||||||
$content_text .= ', 用户端口限速变为' . $value . ' Mbps ';
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'connector':
|
|
||||||
if ($value == 0) {
|
|
||||||
$content_text .= ', 用户IP不限制';
|
|
||||||
} else {
|
|
||||||
$content_text .= ', 用户IP限制变为 ' . $value . ' 个';
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$content_text = rtrim($content_text, ',');
|
|
||||||
|
|
||||||
return $content_text;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function bandwidth()
|
|
||||||
{
|
|
||||||
$content = json_decode($this->attributes['content']);
|
|
||||||
return $content->bandwidth ?? 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function expire()
|
|
||||||
{
|
|
||||||
$content = json_decode($this->attributes['content']);
|
|
||||||
return $content->expire ?? 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function reset()
|
|
||||||
{
|
|
||||||
$content = json_decode($this->attributes['content']);
|
|
||||||
return $content->reset ?? 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function reset_value()
|
|
||||||
{
|
|
||||||
$content = json_decode($this->attributes['content']);
|
|
||||||
return $content->reset_value ?? 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function reset_exp()
|
|
||||||
{
|
|
||||||
$content = json_decode($this->attributes['content']);
|
|
||||||
return $content->reset_exp ?? 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function content_extra()
|
|
||||||
{
|
|
||||||
$content = json_decode($this->attributes['content']);
|
|
||||||
if (isset($content->content_extra)) {
|
|
||||||
$content_extra = $content->content_extra;
|
|
||||||
$content_extra = explode(';', $content_extra);
|
|
||||||
$content_extra_new = array();
|
|
||||||
foreach ($content_extra as $innerContent) {
|
|
||||||
if (false === strpos($innerContent, '-')) {
|
|
||||||
$innerContent = 'check-' . $innerContent;
|
|
||||||
}
|
|
||||||
$innerContent = explode('-', $innerContent);
|
|
||||||
$content_extra_new[] = $innerContent;
|
|
||||||
}
|
|
||||||
$content_extra = $content_extra_new;
|
|
||||||
return $content_extra;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function user_class()
|
|
||||||
{
|
|
||||||
$content = json_decode($this->attributes['content']);
|
|
||||||
return $content->class ?? 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function class_expire()
|
|
||||||
{
|
|
||||||
$content = json_decode($this->attributes['content']);
|
|
||||||
return $content->class_expire ?? 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function speedlimit()
|
|
||||||
{
|
|
||||||
$content = json_decode($this->attributes['content']);
|
|
||||||
return $content->speedlimit ?? 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function connector()
|
|
||||||
{
|
|
||||||
$content = json_decode($this->attributes['content']);
|
|
||||||
return $content->connector ?? 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function buy($user, $is_renew = 0)
|
|
||||||
{
|
|
||||||
$content = json_decode($this->attributes['content'], true);
|
|
||||||
$content_text = '';
|
|
||||||
|
|
||||||
foreach ($content as $key => $value) {
|
|
||||||
switch ($key) {
|
|
||||||
case 'bandwidth':
|
|
||||||
if ($is_renew == 0) {
|
|
||||||
if (Config::get('enable_bought_reset') == 'true') {
|
|
||||||
$user->transfer_enable = $value * 1024 * 1024 * 1024;
|
|
||||||
$user->u = 0;
|
|
||||||
$user->d = 0;
|
|
||||||
$user->last_day_t = 0;
|
|
||||||
} else {
|
|
||||||
$user->transfer_enable += $value * 1024 * 1024 * 1024;
|
|
||||||
}
|
|
||||||
} elseif ($this->attributes['auto_reset_bandwidth'] == 1) {
|
|
||||||
$user->transfer_enable = $value * 1024 * 1024 * 1024;
|
|
||||||
$user->u = 0;
|
|
||||||
$user->d = 0;
|
|
||||||
$user->last_day_t = 0;
|
|
||||||
} else {
|
|
||||||
$user->transfer_enable += $value * 1024 * 1024 * 1024;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'expire':
|
|
||||||
if (time() > strtotime($user->expire_in)) {
|
|
||||||
$user->expire_in = date('Y-m-d H:i:s', time() + $value * 86400);
|
|
||||||
} else {
|
|
||||||
$user->expire_in = date('Y-m-d H:i:s', strtotime($user->expire_in) + $value * 86400);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'class':
|
|
||||||
if (Config::get('enable_bought_extend') == 'true') {
|
|
||||||
if ($user->class == $value) {
|
|
||||||
$user->class_expire = date('Y-m-d H:i:s', strtotime($user->class_expire) + $content['class_expire'] * 86400);
|
|
||||||
} else {
|
|
||||||
$user->class_expire = date('Y-m-d H:i:s', time() + $content['class_expire'] * 86400);
|
|
||||||
}
|
|
||||||
$user->class = $value;
|
|
||||||
} else {
|
|
||||||
$user->class = $value;
|
|
||||||
$user->class_expire = date('Y-m-d H:i:s', time() + $content['class_expire'] * 86400);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 'speedlimit':
|
|
||||||
$user->node_speedlimit = $value;
|
|
||||||
break;
|
|
||||||
case 'connector':
|
|
||||||
$user->node_connector = $value;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$user->save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,79 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
class Speedtest extends Model
|
|
||||||
{
|
|
||||||
protected $connection = 'default';
|
|
||||||
protected $table = 'speedtest';
|
|
||||||
|
|
||||||
public function node()
|
|
||||||
{
|
|
||||||
return Node::find($this->attributes['nodeid']);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function getTelecomPing()
|
|
||||||
{
|
|
||||||
$load = $this->attributes['telecomping'];
|
|
||||||
$exp = explode(' ', $load);
|
|
||||||
return $exp[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getUnicomPing()
|
|
||||||
{
|
|
||||||
$load = $this->attributes['unicomping'];
|
|
||||||
$exp = explode(' ', $load);
|
|
||||||
return $exp[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getCmccPing()
|
|
||||||
{
|
|
||||||
$load = $this->attributes['cmccping'];
|
|
||||||
$exp = explode(' ', $load);
|
|
||||||
return $exp[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function getTelecomUpload()
|
|
||||||
{
|
|
||||||
$load = $this->attributes['telecomeupload'];
|
|
||||||
$exp = explode(' ', $load);
|
|
||||||
return $exp[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getTelecomDownload()
|
|
||||||
{
|
|
||||||
$load = $this->attributes['telecomedownload'];
|
|
||||||
$exp = explode(' ', $load);
|
|
||||||
return $exp[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getUnicomUpload()
|
|
||||||
{
|
|
||||||
$load = $this->attributes['unicomupload'];
|
|
||||||
$exp = explode(' ', $load);
|
|
||||||
return $exp[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getUnicomDownload()
|
|
||||||
{
|
|
||||||
$load = $this->attributes['unicomdownload'];
|
|
||||||
$exp = explode(' ', $load);
|
|
||||||
return $exp[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getCmccDownload()
|
|
||||||
{
|
|
||||||
$load = $this->attributes['cmccdownload'];
|
|
||||||
$exp = explode(' ', $load);
|
|
||||||
return $exp[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getCmccUpload()
|
|
||||||
{
|
|
||||||
$load = $this->attributes['cmccupload'];
|
|
||||||
$exp = explode(' ', $load);
|
|
||||||
return $exp[0];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,28 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* TelegramSession Model
|
|
||||||
*/
|
|
||||||
class TelegramSession extends Model
|
|
||||||
{
|
|
||||||
protected $connection = 'default';
|
|
||||||
protected $table = 'telegram_session';
|
|
||||||
|
|
||||||
public function datetime()
|
|
||||||
{
|
|
||||||
return date('Y-m-d H:i:s', $this->attributes['datetime']);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function User()
|
|
||||||
{
|
|
||||||
$user = User::where('id', $this->attributes['user_id'])->first();
|
|
||||||
if ($user == null) {
|
|
||||||
Ticket::where('id', '=', $this->attributes['id'])->delete();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $user;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,28 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Ticket Model
|
|
||||||
*/
|
|
||||||
class Ticket extends Model
|
|
||||||
{
|
|
||||||
protected $connection = 'default';
|
|
||||||
protected $table = 'ticket';
|
|
||||||
|
|
||||||
public function datetime()
|
|
||||||
{
|
|
||||||
return date('Y-m-d H:i:s', $this->attributes['datetime']);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function User()
|
|
||||||
{
|
|
||||||
$user = User::where('id', $this->attributes['userid'])->first();
|
|
||||||
if ($user == null) {
|
|
||||||
self::where('id', '=', $this->attributes['id'])->delete();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $user;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,9 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
class Token extends Model
|
|
||||||
{
|
|
||||||
protected $connection = 'default';
|
|
||||||
protected $table = 'user_token';
|
|
||||||
}
|
|
||||||
@ -1,49 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
use App\Utils\Tools;
|
|
||||||
|
|
||||||
class TrafficLog extends Model
|
|
||||||
{
|
|
||||||
protected $connection = 'default';
|
|
||||||
protected $table = 'user_traffic_log';
|
|
||||||
|
|
||||||
public function node()
|
|
||||||
{
|
|
||||||
$node = Node::where('id', $this->attributes['node_id'])->first();
|
|
||||||
if ($node == null) {
|
|
||||||
self::where('id', '=', $this->attributes['id'])->delete();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $node;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function user()
|
|
||||||
{
|
|
||||||
$user = User::where('id', $this->attributes['user_id'])->first();
|
|
||||||
if ($user == null) {
|
|
||||||
self::where('id', '=', $this->attributes['id'])->delete();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $user;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function totalUsed()
|
|
||||||
{
|
|
||||||
return Tools::flowAutoShow($this->attributes['u'] + $this->attributes['d']);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function totalUsedRaw()
|
|
||||||
{
|
|
||||||
return number_format(($this->attributes['u'] + $this->attributes['d']) / 1024, 2, '.', '');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function logTime()
|
|
||||||
{
|
|
||||||
return Tools::toDateTime($this->attributes['log_time']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,26 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
class UnblockIp extends Model
|
|
||||||
{
|
|
||||||
protected $connection = 'default';
|
|
||||||
protected $table = 'unblockip';
|
|
||||||
|
|
||||||
public function user()
|
|
||||||
{
|
|
||||||
$user = User::where('id', $this->attributes['userid'])->first();
|
|
||||||
if ($user == null) {
|
|
||||||
self::where('id', '=', $this->attributes['id'])->delete();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $user;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function time()
|
|
||||||
{
|
|
||||||
return date('Y-m-d H:i:s', $this->attributes['datetime']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,456 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* User Model
|
|
||||||
*/
|
|
||||||
|
|
||||||
use App\Utils\Tools;
|
|
||||||
use App\Utils\Hash;
|
|
||||||
use App\Services\Config;
|
|
||||||
use App\Utils\GA;
|
|
||||||
use App\Utils\QQWry;
|
|
||||||
use App\Utils\Radius;
|
|
||||||
use Ramsey\Uuid\Uuid;
|
|
||||||
use App\Models\DetectLog;
|
|
||||||
use App\Models\DetectBanLog;
|
|
||||||
|
|
||||||
class User extends Model
|
|
||||||
{
|
|
||||||
protected $connection = 'default';
|
|
||||||
protected $table = 'user';
|
|
||||||
|
|
||||||
public $isLogin;
|
|
||||||
|
|
||||||
public $isAdmin;
|
|
||||||
|
|
||||||
protected $casts = [
|
|
||||||
't' => 'float',
|
|
||||||
'u' => 'float',
|
|
||||||
'd' => 'float',
|
|
||||||
'port' => 'int',
|
|
||||||
'transfer_enable' => 'float',
|
|
||||||
'enable' => 'int',
|
|
||||||
'is_admin' => 'boolean',
|
|
||||||
'is_multi_user' => 'int',
|
|
||||||
'node_speedlimit' => 'float',
|
|
||||||
];
|
|
||||||
|
|
||||||
public function getGravatarAttribute()
|
|
||||||
{
|
|
||||||
$hash = md5(strtolower(trim($this->attributes['email'])));
|
|
||||||
return 'https://gravatar.loli.net/avatar/' . $hash;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function isAdmin()
|
|
||||||
{
|
|
||||||
return $this->attributes['is_admin'];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function lastSsTime()
|
|
||||||
{
|
|
||||||
if ($this->attributes['t'] == 0) {
|
|
||||||
return '从未使用喵';
|
|
||||||
}
|
|
||||||
return Tools::toDateTime($this->attributes['t']);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getMuMd5()
|
|
||||||
{
|
|
||||||
$str = str_replace(
|
|
||||||
array('%id', '%suffix'),
|
|
||||||
array($this->attributes['id'], Config::get('mu_suffix')),
|
|
||||||
Config::get('mu_regex')
|
|
||||||
);
|
|
||||||
preg_match_all("|%-?[1-9]\d*m|U", $str, $matches, PREG_PATTERN_ORDER);
|
|
||||||
foreach ($matches[0] as $key) {
|
|
||||||
$key_match = str_replace(array('%', 'm'), '', $key);
|
|
||||||
$md5 = substr(
|
|
||||||
MD5($this->attributes['id'] . $this->attributes['passwd'] . $this->attributes['method'] . $this->attributes['obfs'] . $this->attributes['protocol']),
|
|
||||||
($key_match < 0 ? $key_match : 0),
|
|
||||||
abs($key_match)
|
|
||||||
);
|
|
||||||
$str = str_replace($key, $md5, $str);
|
|
||||||
}
|
|
||||||
return $str;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function lastCheckInTime()
|
|
||||||
{
|
|
||||||
if ($this->attributes['last_check_in_time'] == 0) {
|
|
||||||
return '从未签到';
|
|
||||||
}
|
|
||||||
return Tools::toDateTime($this->attributes['last_check_in_time']);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function regDate()
|
|
||||||
{
|
|
||||||
return $this->attributes['reg_date'];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function updatePassword($pwd)
|
|
||||||
{
|
|
||||||
$this->pass = Hash::passwordHash($pwd);
|
|
||||||
$this->save();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function get_forbidden_ip()
|
|
||||||
{
|
|
||||||
return str_replace(',', PHP_EOL, $this->attributes['forbidden_ip']);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function get_forbidden_port()
|
|
||||||
{
|
|
||||||
return str_replace(',', PHP_EOL, $this->attributes['forbidden_port']);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function updateSsPwd($pwd)
|
|
||||||
{
|
|
||||||
$this->passwd = $pwd;
|
|
||||||
$this->save();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function updateMethod($method)
|
|
||||||
{
|
|
||||||
$this->method = $method;
|
|
||||||
$this->save();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function addInviteCode()
|
|
||||||
{
|
|
||||||
$uid = $this->attributes['id'];
|
|
||||||
$code = new InviteCode();
|
|
||||||
while (true) {
|
|
||||||
$temp_code = Tools::genRandomChar(4);
|
|
||||||
if (InviteCode::where('user_id', $uid)->count() == 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$code->code = $temp_code;
|
|
||||||
$code->user_id = $uid;
|
|
||||||
$code->save();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getUuid()
|
|
||||||
{
|
|
||||||
return Uuid::uuid3(
|
|
||||||
Uuid::NAMESPACE_DNS,
|
|
||||||
$this->attributes['id'] . '|' . $this->attributes['passwd']
|
|
||||||
)->toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function trafficUsagePercent()
|
|
||||||
{
|
|
||||||
$total = $this->attributes['u'] + $this->attributes['d'];
|
|
||||||
$transferEnable = $this->attributes['transfer_enable'];
|
|
||||||
if ($transferEnable == 0) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
$percent = $total / $transferEnable;
|
|
||||||
$percent = round($percent, 2);
|
|
||||||
$percent *= 100;
|
|
||||||
return $percent;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function enableTraffic()
|
|
||||||
{
|
|
||||||
$transfer_enable = $this->attributes['transfer_enable'];
|
|
||||||
return Tools::flowAutoShow($transfer_enable);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function enableTrafficInGB()
|
|
||||||
{
|
|
||||||
$transfer_enable = $this->attributes['transfer_enable'];
|
|
||||||
return Tools::flowToGB($transfer_enable);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function usedTraffic()
|
|
||||||
{
|
|
||||||
$total = $this->attributes['u'] + $this->attributes['d'];
|
|
||||||
return Tools::flowAutoShow($total);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function unusedTraffic()
|
|
||||||
{
|
|
||||||
$total = $this->attributes['u'] + $this->attributes['d'];
|
|
||||||
$transfer_enable = $this->attributes['transfer_enable'];
|
|
||||||
return Tools::flowAutoShow($transfer_enable - $total);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function TodayusedTraffic()
|
|
||||||
{
|
|
||||||
$total = $this->attributes['u'] + $this->attributes['d'] - $this->attributes['last_day_t'];
|
|
||||||
return Tools::flowAutoShow($total);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function LastusedTraffic()
|
|
||||||
{
|
|
||||||
$total = $this->attributes['last_day_t'];
|
|
||||||
return Tools::flowAutoShow($total);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function isAbleToCheckin()
|
|
||||||
{
|
|
||||||
$last = $this->attributes['last_check_in_time'];
|
|
||||||
|
|
||||||
$now = time();
|
|
||||||
return date('Ymd', $now) != date('Ymd', $last);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* @param traffic 单位 MB
|
|
||||||
*/
|
|
||||||
public function addTraffic($traffic)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getGAurl()
|
|
||||||
{
|
|
||||||
$ga = new GA();
|
|
||||||
$url = $ga->getUrl(
|
|
||||||
urlencode(Config::get('appName') . '-' . $this->attributes['user_name'] . '-两步验证码'),
|
|
||||||
$this->attributes['ga_token']
|
|
||||||
);
|
|
||||||
return $url;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function inviteCodes()
|
|
||||||
{
|
|
||||||
$uid = $this->attributes['id'];
|
|
||||||
return InviteCode::where('user_id', $uid)->get();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function ref_by_user()
|
|
||||||
{
|
|
||||||
$uid = $this->attributes['ref_by'];
|
|
||||||
return self::where('id', $uid)->first();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function clean_link()
|
|
||||||
{
|
|
||||||
$uid = $this->attributes['id'];
|
|
||||||
Link::where('userid', $uid)->delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function clear_inviteCodes()
|
|
||||||
{
|
|
||||||
$uid = $this->attributes['id'];
|
|
||||||
InviteCode::where('user_id', $uid)->delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function online_ip_count()
|
|
||||||
{
|
|
||||||
$uid = $this->attributes['id'];
|
|
||||||
$total = Ip::where('datetime', '>=', time() - 90)->where('userid', $uid)->orderBy('userid', 'desc')->get();
|
|
||||||
$unique_ip_list = array();
|
|
||||||
foreach ($total as $single_record) {
|
|
||||||
$single_record->ip = Tools::getRealIp($single_record->ip);
|
|
||||||
$is_node = Node::where('node_ip', $single_record->ip)->first();
|
|
||||||
if ($is_node) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!in_array($single_record->ip, $unique_ip_list)) {
|
|
||||||
$unique_ip_list[] = $single_record->ip;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return count($unique_ip_list);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function kill_user()
|
|
||||||
{
|
|
||||||
$uid = $this->attributes['id'];
|
|
||||||
$email = $this->attributes['email'];
|
|
||||||
|
|
||||||
Radius::Delete($email);
|
|
||||||
|
|
||||||
RadiusBan::where('userid', '=', $uid)->delete();
|
|
||||||
Disconnect::where('userid', '=', $uid)->delete();
|
|
||||||
Bought::where('userid', '=', $uid)->delete();
|
|
||||||
Bought::where('userid', '=', $uid)->delete();
|
|
||||||
Ip::where('userid', '=', $uid)->delete();
|
|
||||||
Code::where('userid', '=', $uid)->delete();
|
|
||||||
DetectLog::where('user_id', '=', $uid)->delete();
|
|
||||||
Link::where('userid', '=', $uid)->delete();
|
|
||||||
LoginIp::where('userid', '=', $uid)->delete();
|
|
||||||
InviteCode::where('user_id', '=', $uid)->delete();
|
|
||||||
TelegramSession::where('user_id', '=', $uid)->delete();
|
|
||||||
UnblockIp::where('userid', '=', $uid)->delete();
|
|
||||||
TrafficLog::where('user_id', '=', $uid)->delete();
|
|
||||||
Token::where('user_id', '=', $uid)->delete();
|
|
||||||
PasswordReset::where('email', '=', $email)->delete();
|
|
||||||
|
|
||||||
$this->delete();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function get_table_json_array()
|
|
||||||
{
|
|
||||||
$id = $this->attributes['id'];
|
|
||||||
$today_traffic = Tools::flowToMB($this->attributes['u'] + $this->attributes['d'] - $this->attributes['last_day_t']);
|
|
||||||
$is_enable = $this->attributes['enable'] == 1 ? '可用' : '禁用';
|
|
||||||
$reg_location = $this->attributes['reg_ip'];
|
|
||||||
$account_expire_in = $this->attributes['expire_in'];
|
|
||||||
$class_expire_in = $this->attributes['class_expire'];
|
|
||||||
$used_traffic = Tools::flowToGB($this->attributes['u'] + $this->attributes['d']);
|
|
||||||
$enable_traffic = Tools::flowToGB($this->attributes['transfer_enable']);
|
|
||||||
|
|
||||||
$im_type = '';
|
|
||||||
$im_value = $this->attributes['im_value'];
|
|
||||||
switch ($this->attributes['im_type']) {
|
|
||||||
case 1:
|
|
||||||
$im_type = '微信';
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
$im_type = 'QQ';
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
$im_type = 'Google+';
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
$im_type = 'Telegram';
|
|
||||||
$im_value = '<a href="https://telegram.me/' . $im_value . '">' . $im_value . '</a>';
|
|
||||||
}
|
|
||||||
|
|
||||||
$ref_user = self::find($this->attributes['ref_by']);
|
|
||||||
|
|
||||||
if ($this->attributes['ref_by'] == 0) {
|
|
||||||
$ref_user_id = 0;
|
|
||||||
$ref_user_name = '系统邀请';
|
|
||||||
} elseif ($ref_user == null) {
|
|
||||||
$ref_user_id = $this->attributes['ref_by'];
|
|
||||||
$ref_user_name = '邀请人已经被删除';
|
|
||||||
} else {
|
|
||||||
$ref_user_id = $this->attributes['ref_by'];
|
|
||||||
$ref_user_name = $ref_user->user_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
$iplocation = new QQWry();
|
|
||||||
$location = $iplocation->getlocation($reg_location);
|
|
||||||
$reg_location .= "\n" . iconv('gbk', 'utf-8//IGNORE', $location['country'] . $location['area']);
|
|
||||||
|
|
||||||
$return_array = array(
|
|
||||||
'DT_RowId' => 'row_1_' . $id,
|
|
||||||
$id,
|
|
||||||
$id,
|
|
||||||
$this->attributes['user_name'],
|
|
||||||
$this->attributes['remark'],
|
|
||||||
$this->attributes['email'],
|
|
||||||
$this->attributes['money'],
|
|
||||||
$im_type,
|
|
||||||
$im_value,
|
|
||||||
$this->attributes['node_group'],
|
|
||||||
$account_expire_in,
|
|
||||||
$this->attributes['class'],
|
|
||||||
$class_expire_in,
|
|
||||||
$this->attributes['passwd'],
|
|
||||||
$this->attributes['port'],
|
|
||||||
$this->attributes['method'],
|
|
||||||
$this->attributes['protocol'],
|
|
||||||
$this->attributes['obfs'],
|
|
||||||
$this->online_ip_count(),
|
|
||||||
$this->lastSsTime(),
|
|
||||||
$used_traffic,
|
|
||||||
$enable_traffic,
|
|
||||||
$this->lastCheckInTime(),
|
|
||||||
$today_traffic,
|
|
||||||
$is_enable,
|
|
||||||
$this->attributes['reg_date'],
|
|
||||||
$reg_location,
|
|
||||||
$this->attributes['auto_reset_day'],
|
|
||||||
$this->attributes['auto_reset_bandwidth'],
|
|
||||||
$ref_user_id,
|
|
||||||
$ref_user_name
|
|
||||||
);
|
|
||||||
return $return_array;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function get_user_attributes($key)
|
|
||||||
{
|
|
||||||
return $this->attributes[$key];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function get_top_up()
|
|
||||||
{
|
|
||||||
$codes = Code::where('userid', $this->attributes['id'])->get();
|
|
||||||
$top_up = 0;
|
|
||||||
foreach ($codes as $code) {
|
|
||||||
$top_up += $code->number;
|
|
||||||
}
|
|
||||||
return round($top_up, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 最后一次被封禁的时间
|
|
||||||
public function last_detect_ban_time()
|
|
||||||
{
|
|
||||||
return ($this->attributes['last_detect_ban_time'] == '1989-06-04 00:05:00'
|
|
||||||
? '未被封禁过'
|
|
||||||
: $this->attributes['last_detect_ban_time']
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 当前解封时间
|
|
||||||
public function relieve_time()
|
|
||||||
{
|
|
||||||
if ($this->attributes['detect_ban'] == 1) {
|
|
||||||
$logs = DetectBanLog::where('user_id', $this->attributes['id'])->orderBy("id", "desc")->first();
|
|
||||||
$time = ($logs->end_time + $logs->ban_time * 60);
|
|
||||||
return date('Y-m-d H:i:s', $time);
|
|
||||||
} else {
|
|
||||||
return '当前未被封禁';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 累计被封禁的次数
|
|
||||||
public function detect_ban_number()
|
|
||||||
{
|
|
||||||
$logs = DetectBanLog::where('user_id', $this->attributes['id'])->get();
|
|
||||||
return count($logs);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 最后一次封禁的违规次数
|
|
||||||
public function user_detect_ban_number()
|
|
||||||
{
|
|
||||||
$logs = DetectBanLog::where('user_id', $this->attributes['id'])->orderBy("id", "desc")->first();
|
|
||||||
return $logs->detect_number;
|
|
||||||
}
|
|
||||||
public function yesterdayIncome()
|
|
||||||
{
|
|
||||||
return Code::where('usedatetime', 'like', date('Y-m-d%', strtotime('-1 days')))->sum(number);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function todayIncome()
|
|
||||||
{
|
|
||||||
return Code::where('usedatetime', 'like', date('Y-m-d%'))->sum(number);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function thisMonthIncome()
|
|
||||||
{
|
|
||||||
return Code::where('usedatetime', 'like', date('Y-m%'))->sum(number);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function lastMonthIncome()
|
|
||||||
{
|
|
||||||
return Code::where('usedatetime', 'like', date('Y-m%', strtotime('-1 months')))->sum(number);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function totalIncome()
|
|
||||||
{
|
|
||||||
return Code::where('usedatetime', 'like', date('%'))->sum(number);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function paidUserCount()
|
|
||||||
{
|
|
||||||
return self::where('class', '!=', '0')->count();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function disableReason()
|
|
||||||
{
|
|
||||||
$reason_id = DetectLog::where('user_id', '=', $this->attributes['id'])->orderBy('id', 'DESC')->first();
|
|
||||||
$reason = DetectRule::where('id', '=', $reason_id->list_id)->get();
|
|
||||||
return $reason[0]->text;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,9 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
class UserSubscribeLog extends Model
|
|
||||||
{
|
|
||||||
protected $connection = 'default';
|
|
||||||
protected $table = 'user_subscribe_log';
|
|
||||||
}
|
|
||||||
@ -1,31 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Services;
|
|
||||||
|
|
||||||
use App\Models\User;
|
|
||||||
use App\Utils\Tools;
|
|
||||||
|
|
||||||
class Analytic
|
|
||||||
{
|
|
||||||
public function userCount()
|
|
||||||
{
|
|
||||||
return User::all()->count();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function checkinUserCount()
|
|
||||||
{
|
|
||||||
return User::where('last_checkin_time', '>', 1)->count();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function activedUserCount()
|
|
||||||
{
|
|
||||||
return User::where('t', '>', 1)->count();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function totalTraffic()
|
|
||||||
{
|
|
||||||
$u = User::all()->sum('u');
|
|
||||||
$d = User::all()->sum('d');
|
|
||||||
return Tools::flowAutoShow($u + $d);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,120 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Services;
|
|
||||||
|
|
||||||
use App\Models\User;
|
|
||||||
use App\Models\Node;
|
|
||||||
use App\Utils\Tools;
|
|
||||||
|
|
||||||
class Analytics
|
|
||||||
{
|
|
||||||
public function getTotalUser()
|
|
||||||
{
|
|
||||||
return User::count();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getCheckinUser()
|
|
||||||
{
|
|
||||||
return User::where('last_check_in_time', '>', 0)->count();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getTodayCheckinUser()
|
|
||||||
{
|
|
||||||
return User::where('last_check_in_time', '>', strtotime('today'))->count();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getTrafficUsage()
|
|
||||||
{
|
|
||||||
$total = User::sum('u') + User::sum('d');
|
|
||||||
return Tools::flowAutoShow($total);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getTodayTrafficUsage()
|
|
||||||
{
|
|
||||||
$total = User::sum('u') + User::sum('d') - User::sum('last_day_t');
|
|
||||||
return Tools::flowAutoShow($total);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function getRawTodayTrafficUsage()
|
|
||||||
{
|
|
||||||
return User::sum('u') + User::sum('d') - User::sum('last_day_t');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getLastTrafficUsage()
|
|
||||||
{
|
|
||||||
$total = User::sum('last_day_t');
|
|
||||||
return Tools::flowAutoShow($total);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function getRawLastTrafficUsage()
|
|
||||||
{
|
|
||||||
return User::sum('last_day_t');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getUnusedTrafficUsage()
|
|
||||||
{
|
|
||||||
$total = User::sum('transfer_enable') - User::sum('u') - User::sum('d');
|
|
||||||
return Tools::flowAutoShow($total);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getRawUnusedTrafficUsage()
|
|
||||||
{
|
|
||||||
return User::sum('transfer_enable') - User::sum('u') - User::sum('d');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function getTotalTraffic()
|
|
||||||
{
|
|
||||||
$total = User::sum('transfer_enable');
|
|
||||||
return Tools::flowAutoShow($total);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getRawTotalTraffic()
|
|
||||||
{
|
|
||||||
return User::sum('transfer_enable');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getOnlineUser($time)
|
|
||||||
{
|
|
||||||
$time = time() - $time;
|
|
||||||
return User::where('t', '>', $time)->count();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getUnusedUser()
|
|
||||||
{
|
|
||||||
return User::where('t', '=', 0)->count();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getTotalNode()
|
|
||||||
{
|
|
||||||
return Node::count();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getTotalNodes()
|
|
||||||
{
|
|
||||||
return Node::where('node_heartbeat', '>', 0)->where(
|
|
||||||
static function ($query) {
|
|
||||||
$query->Where('sort', '=', 0)
|
|
||||||
->orWhere('sort', '=', 10)
|
|
||||||
->orWhere('sort', '=', 11)
|
|
||||||
->orWhere('sort', '=', 12)
|
|
||||||
->orWhere('sort', '=', 13);
|
|
||||||
}
|
|
||||||
)->count();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getAliveNodes()
|
|
||||||
{
|
|
||||||
return Node::where(
|
|
||||||
static function ($query) {
|
|
||||||
$query->Where('sort', '=', 0)
|
|
||||||
->orWhere('sort', '=', 10)
|
|
||||||
->orWhere('sort', '=', 11)
|
|
||||||
->orWhere('sort', '=', 12)
|
|
||||||
->orWhere('sort', '=', 13);
|
|
||||||
}
|
|
||||||
)->where('node_heartbeat', '>', time() - 90)->count();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,554 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Services;
|
|
||||||
|
|
||||||
class AppsProfiles
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Surge 策略组配置
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public static function Surge()
|
|
||||||
{
|
|
||||||
$Apps_Profiles = [
|
|
||||||
'lhie1' => [
|
|
||||||
'Checks' => ['🇭🇰 香港', '🇯🇵 日本', '🇸🇬 坡坡', '🇨🇳 台湾', '🇺🇸 美国', '🇰🇷 韩国', '🇨🇳 中继'],
|
|
||||||
'ProxyGroup' => [
|
|
||||||
[
|
|
||||||
'name' => '🍃 Proxy',
|
|
||||||
'type' => 'select',
|
|
||||||
'content' => [
|
|
||||||
'left-proxies' => ['🇭🇰 香港', '🇯🇵 日本', '🇸🇬 坡坡', '🇨🇳 台湾', '🇺🇸 美国', '🇰🇷 韩国', '🇨🇳 中继', '🚀 Direct']
|
|
||||||
]
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => '🍂 Domestic',
|
|
||||||
'type' => 'select',
|
|
||||||
'content' => [
|
|
||||||
'left-proxies' => ['🚀 Direct', '🍃 Proxy', '🇨🇳 中继']
|
|
||||||
]
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => '🍎 Only',
|
|
||||||
'type' => 'select',
|
|
||||||
'content' => [
|
|
||||||
'left-proxies' => ['🚀 Direct', '🇭🇰 香港', '🇯🇵 日本', '🇸🇬 坡坡', '🇨🇳 台湾', '🇺🇸 美国', '🇰🇷 韩国', '🇨🇳 中继']
|
|
||||||
]
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => '☁️ Others',
|
|
||||||
'type' => 'select',
|
|
||||||
'content' => [
|
|
||||||
'left-proxies' => ['🍃 Proxy', '🍂 Domestic']
|
|
||||||
]
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => '🇭🇰 香港',
|
|
||||||
'type' => 'select',
|
|
||||||
'content' => [
|
|
||||||
'regex' => '(香港|HK)'
|
|
||||||
],
|
|
||||||
'url' => 'http://www.qualcomm.cn/generate_204',
|
|
||||||
'interval' => 3600
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => '🇯🇵 日本',
|
|
||||||
'type' => 'select',
|
|
||||||
'content' => [
|
|
||||||
'regex' => '(日本|JP)'
|
|
||||||
],
|
|
||||||
'url' => 'http://www.qualcomm.cn/generate_204',
|
|
||||||
'interval' => 3600
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => '🇸🇬 坡坡',
|
|
||||||
'type' => 'select',
|
|
||||||
'content' => [
|
|
||||||
'regex' => '(新加坡|SG)'
|
|
||||||
],
|
|
||||||
'url' => 'http://www.qualcomm.cn/generate_204',
|
|
||||||
'interval' => 3600
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => '🇨🇳 台湾',
|
|
||||||
'type' => 'select',
|
|
||||||
'content' => [
|
|
||||||
'regex' => '(台湾|TW)'
|
|
||||||
],
|
|
||||||
'url' => 'http://www.qualcomm.cn/generate_204',
|
|
||||||
'interval' => 3600
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => '🇺🇸 美国',
|
|
||||||
'type' => 'select',
|
|
||||||
'content' => [
|
|
||||||
'regex' => '(美国|US)'
|
|
||||||
],
|
|
||||||
'url' => 'http://www.qualcomm.cn/generate_204',
|
|
||||||
'interval' => 3600
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => '🇰🇷 韩国',
|
|
||||||
'type' => 'select',
|
|
||||||
'content' => [
|
|
||||||
'regex' => '(韩国|KR)'
|
|
||||||
],
|
|
||||||
'url' => 'http://www.qualcomm.cn/generate_204',
|
|
||||||
'interval' => 3600
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => '🇨🇳 中继',
|
|
||||||
'type' => 'select',
|
|
||||||
'content' => [
|
|
||||||
'regex' => '(中继|中转|中国|回国|China)'
|
|
||||||
],
|
|
||||||
'url' => 'http://www.qualcomm.cn/generate_204',
|
|
||||||
'interval' => 3600
|
|
||||||
]
|
|
||||||
]
|
|
||||||
],
|
|
||||||
'123456' => [
|
|
||||||
'Checks' => [],
|
|
||||||
'ProxyGroup' => [
|
|
||||||
[
|
|
||||||
'name' => '🍃 Proxy',
|
|
||||||
'type' => 'select',
|
|
||||||
'content' => [
|
|
||||||
'regex' => '(.*)'
|
|
||||||
]
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => '🍂 Domestic',
|
|
||||||
'type' => 'select',
|
|
||||||
'content' => [
|
|
||||||
'left-proxies' => ['🚀 Direct', '🍃 Proxy']
|
|
||||||
]
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => '🍎 Only',
|
|
||||||
'type' => 'select',
|
|
||||||
'content' => [
|
|
||||||
'left-proxies' => ['🚀 Direct', '🍃 Proxy']
|
|
||||||
]
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => '☁️ Others',
|
|
||||||
'type' => 'select',
|
|
||||||
'content' => [
|
|
||||||
'left-proxies' => ['🍃 Proxy', '🍂 Domestic']
|
|
||||||
]
|
|
||||||
]
|
|
||||||
]
|
|
||||||
]
|
|
||||||
];
|
|
||||||
|
|
||||||
return $Apps_Profiles;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Surfboard 策略组配置
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public static function Surfboard()
|
|
||||||
{
|
|
||||||
$Apps_Profiles = [
|
|
||||||
'lhie1' => [
|
|
||||||
'Checks' => ['🇭🇰 香港', '🇯🇵 日本', '🇸🇬 坡坡', '🇨🇳 台湾', '🇺🇸 美国', '🇰🇷 韩国', '🇨🇳 中继'],
|
|
||||||
'ProxyGroup' => [
|
|
||||||
[
|
|
||||||
'name' => '🍃 Proxy',
|
|
||||||
'type' => 'select',
|
|
||||||
'content' => [
|
|
||||||
'left-proxies' => ['🇭🇰 香港', '🇯🇵 日本', '🇸🇬 坡坡', '🇨🇳 台湾', '🇺🇸 美国', '🇰🇷 韩国', '🇨🇳 中继', '🚀 Direct']
|
|
||||||
]
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => '🍂 Domestic',
|
|
||||||
'type' => 'select',
|
|
||||||
'content' => [
|
|
||||||
'left-proxies' => ['🚀 Direct', '🍃 Proxy', '🇨🇳 中继']
|
|
||||||
]
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => '☁️ Others',
|
|
||||||
'type' => 'select',
|
|
||||||
'content' => [
|
|
||||||
'left-proxies' => ['🍃 Proxy', '🍂 Domestic']
|
|
||||||
]
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => '🇭🇰 香港',
|
|
||||||
'type' => 'select',
|
|
||||||
'content' => [
|
|
||||||
'regex' => '(香港|HK)'
|
|
||||||
],
|
|
||||||
'url' => 'http://www.qualcomm.cn/generate_204',
|
|
||||||
'interval' => 3600
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => '🇯🇵 日本',
|
|
||||||
'type' => 'select',
|
|
||||||
'content' => [
|
|
||||||
'regex' => '(日本|JP)'
|
|
||||||
],
|
|
||||||
'url' => 'http://www.qualcomm.cn/generate_204',
|
|
||||||
'interval' => 3600
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => '🇸🇬 坡坡',
|
|
||||||
'type' => 'select',
|
|
||||||
'content' => [
|
|
||||||
'regex' => '(新加坡|SG)'
|
|
||||||
],
|
|
||||||
'url' => 'http://www.qualcomm.cn/generate_204',
|
|
||||||
'interval' => 3600
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => '🇨🇳 台湾',
|
|
||||||
'type' => 'select',
|
|
||||||
'content' => [
|
|
||||||
'regex' => '(台湾|TW)'
|
|
||||||
],
|
|
||||||
'url' => 'http://www.qualcomm.cn/generate_204',
|
|
||||||
'interval' => 3600
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => '🇺🇸 美国',
|
|
||||||
'type' => 'select',
|
|
||||||
'content' => [
|
|
||||||
'regex' => '(美国|US)'
|
|
||||||
],
|
|
||||||
'url' => 'http://www.qualcomm.cn/generate_204',
|
|
||||||
'interval' => 3600
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => '🇰🇷 韩国',
|
|
||||||
'type' => 'select',
|
|
||||||
'content' => [
|
|
||||||
'regex' => '(韩国|KR)'
|
|
||||||
],
|
|
||||||
'url' => 'http://www.qualcomm.cn/generate_204',
|
|
||||||
'interval' => 3600
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => '🇨🇳 中继',
|
|
||||||
'type' => 'select',
|
|
||||||
'content' => [
|
|
||||||
'regex' => '(中继|中转|中国|回国|China)'
|
|
||||||
],
|
|
||||||
'url' => 'http://www.qualcomm.cn/generate_204',
|
|
||||||
'interval' => 3600
|
|
||||||
]
|
|
||||||
]
|
|
||||||
],
|
|
||||||
'123456' => [
|
|
||||||
'Checks' => [],
|
|
||||||
'ProxyGroup' => [
|
|
||||||
[
|
|
||||||
'name' => '🍃 Proxy',
|
|
||||||
'type' => 'select',
|
|
||||||
'content' => [
|
|
||||||
'regex' => '(.*)'
|
|
||||||
]
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => '🍂 Domestic',
|
|
||||||
'type' => 'select',
|
|
||||||
'content' => [
|
|
||||||
'left-proxies' => ['🚀 Direct', '🍃 Proxy']
|
|
||||||
]
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => '☁️ Others',
|
|
||||||
'type' => 'select',
|
|
||||||
'content' => [
|
|
||||||
'left-proxies' => ['🍃 Proxy', '🍂 Domestic']
|
|
||||||
]
|
|
||||||
]
|
|
||||||
]
|
|
||||||
]
|
|
||||||
];
|
|
||||||
|
|
||||||
return $Apps_Profiles;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Clash 策略组配置
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public static function Clash()
|
|
||||||
{
|
|
||||||
$Apps_Profiles = [
|
|
||||||
'lhie1' => [
|
|
||||||
'Checks' => ['香港', '日本', '坡坡', '台湾', '美国', '韩国', '中继'],
|
|
||||||
'ProxyGroup' => [
|
|
||||||
[
|
|
||||||
'name' => '香港',
|
|
||||||
'type' => 'url-test',
|
|
||||||
'content' => [
|
|
||||||
'regex' => '(香港|HK)'
|
|
||||||
],
|
|
||||||
'url' => 'http://www.qualcomm.cn/generate_204',
|
|
||||||
'interval' => 3600
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => '日本',
|
|
||||||
'type' => 'url-test',
|
|
||||||
'content' => [
|
|
||||||
'regex' => '(日本|JP)'
|
|
||||||
],
|
|
||||||
'url' => 'http://www.qualcomm.cn/generate_204',
|
|
||||||
'interval' => 3600
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => '坡坡',
|
|
||||||
'type' => 'url-test',
|
|
||||||
'content' => [
|
|
||||||
'regex' => '(新加坡|SG)'
|
|
||||||
],
|
|
||||||
'url' => 'http://www.qualcomm.cn/generate_204',
|
|
||||||
'interval' => 3600
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => '美国',
|
|
||||||
'type' => 'url-test',
|
|
||||||
'content' => [
|
|
||||||
'regex' => '(美国|US)'
|
|
||||||
],
|
|
||||||
'url' => 'http://www.qualcomm.cn/generate_204',
|
|
||||||
'interval' => 3600
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => '台湾',
|
|
||||||
'type' => 'url-test',
|
|
||||||
'content' => [
|
|
||||||
'regex' => '(台湾|TW)'
|
|
||||||
],
|
|
||||||
'url' => 'http://www.qualcomm.cn/generate_204',
|
|
||||||
'interval' => 3600
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => '韩国',
|
|
||||||
'type' => 'url-test',
|
|
||||||
'content' => [
|
|
||||||
'regex' => '(韩国|KR)'
|
|
||||||
],
|
|
||||||
'url' => 'http://www.qualcomm.cn/generate_204',
|
|
||||||
'interval' => 3600
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => '中继',
|
|
||||||
'type' => 'url-test',
|
|
||||||
'content' => [
|
|
||||||
'regex' => '(中继|中转|中国|回国|China)'
|
|
||||||
],
|
|
||||||
'url' => 'http://www.qualcomm.cn/generate_204',
|
|
||||||
'interval' => 3600
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'Proxy',
|
|
||||||
'type' => 'select',
|
|
||||||
'content' => [
|
|
||||||
'left-proxies' => ['香港', '日本', '坡坡', '台湾', '美国', '韩国', '中继']
|
|
||||||
]
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'Domestic',
|
|
||||||
'type' => 'select',
|
|
||||||
'content' => [
|
|
||||||
'left-proxies' => ['DIRECT', 'Proxy', '中继']
|
|
||||||
]
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'AsianTV',
|
|
||||||
'type' => 'select',
|
|
||||||
'content' => [
|
|
||||||
'left-proxies' => ['Domestic', 'Proxy', '中继']
|
|
||||||
]
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'GlobalTV',
|
|
||||||
'type' => 'select',
|
|
||||||
'content' => [
|
|
||||||
'left-proxies' => ['Proxy', '香港', '日本', '坡坡', '台湾', '美国', '韩国', '中继']
|
|
||||||
]
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'Others',
|
|
||||||
'type' => 'select',
|
|
||||||
'content' => [
|
|
||||||
'left-proxies' => ['Proxy', 'Domestic']
|
|
||||||
]
|
|
||||||
]
|
|
||||||
]
|
|
||||||
],
|
|
||||||
'ConnersHua_Pro' => [
|
|
||||||
'Checks' => ['香港', '日本', '坡坡', '台湾', '美国', '韩国', '中继'],
|
|
||||||
'ProxyGroup' => [
|
|
||||||
[
|
|
||||||
'name' => '香港',
|
|
||||||
'type' => 'url-test',
|
|
||||||
'content' => [
|
|
||||||
'regex' => '(香港|HK)'
|
|
||||||
],
|
|
||||||
'url' => 'http://www.qualcomm.cn/generate_204',
|
|
||||||
'interval' => 3600
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => '日本',
|
|
||||||
'type' => 'url-test',
|
|
||||||
'content' => [
|
|
||||||
'regex' => '(日本|JP)'
|
|
||||||
],
|
|
||||||
'url' => 'http://www.qualcomm.cn/generate_204',
|
|
||||||
'interval' => 3600
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => '坡坡',
|
|
||||||
'type' => 'url-test',
|
|
||||||
'content' => [
|
|
||||||
'regex' => '(新加坡|SG)'
|
|
||||||
],
|
|
||||||
'url' => 'http://www.qualcomm.cn/generate_204',
|
|
||||||
'interval' => 3600
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => '美国',
|
|
||||||
'type' => 'url-test',
|
|
||||||
'content' => [
|
|
||||||
'regex' => '(美国|US)'
|
|
||||||
],
|
|
||||||
'url' => 'http://www.qualcomm.cn/generate_204',
|
|
||||||
'interval' => 3600
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => '台湾',
|
|
||||||
'type' => 'url-test',
|
|
||||||
'content' => [
|
|
||||||
'regex' => '(台湾|TW)'
|
|
||||||
],
|
|
||||||
'url' => 'http://www.qualcomm.cn/generate_204',
|
|
||||||
'interval' => 3600
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => '韩国',
|
|
||||||
'type' => 'url-test',
|
|
||||||
'content' => [
|
|
||||||
'regex' => '(韩国|KR)'
|
|
||||||
],
|
|
||||||
'url' => 'http://www.qualcomm.cn/generate_204',
|
|
||||||
'interval' => 3600
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => '中继',
|
|
||||||
'type' => 'url-test',
|
|
||||||
'content' => [
|
|
||||||
'regex' => '(中继|中转|中国|回国|China|CN)'
|
|
||||||
],
|
|
||||||
'url' => 'http://www.qualcomm.cn/generate_204',
|
|
||||||
'interval' => 3600
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'PROXY',
|
|
||||||
'type' => 'select',
|
|
||||||
'content' => [
|
|
||||||
'left-proxies' => ['香港', '日本', '坡坡', '台湾', '美国', '韩国', '中继']
|
|
||||||
]
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'Final',
|
|
||||||
'type' => 'select',
|
|
||||||
'content' => [
|
|
||||||
'left-proxies' => ['PROXY', 'DIRECT']
|
|
||||||
]
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'ForeignMedia',
|
|
||||||
'type' => 'select',
|
|
||||||
'content' => [
|
|
||||||
'left-proxies' => ['PROXY', '香港', '日本', '坡坡', '台湾', '美国', '韩国', '中继']
|
|
||||||
]
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'DomesticMedia',
|
|
||||||
'type' => 'select',
|
|
||||||
'content' => [
|
|
||||||
'left-proxies' => ['DIRECT', 'PROXY', '中继']
|
|
||||||
]
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'Apple',
|
|
||||||
'type' => 'select',
|
|
||||||
'content' => [
|
|
||||||
'left-proxies' => ['DIRECT', 'PROXY']
|
|
||||||
]
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'Hijacking',
|
|
||||||
'type' => 'select',
|
|
||||||
'content' => [
|
|
||||||
'left-proxies' => ['DIRECT', 'REJECT']
|
|
||||||
]
|
|
||||||
]
|
|
||||||
]
|
|
||||||
],
|
|
||||||
'ConnersHua_BacktoCN' => [
|
|
||||||
'Checks' => [],
|
|
||||||
'ProxyGroup' => [
|
|
||||||
[
|
|
||||||
'name' => 'PROXY',
|
|
||||||
'type' => 'select',
|
|
||||||
'content' => [
|
|
||||||
'regex' => '(中继|中转|中国|回国|China)'
|
|
||||||
]
|
|
||||||
]
|
|
||||||
]
|
|
||||||
],
|
|
||||||
'123456' => [
|
|
||||||
'Checks' => [],
|
|
||||||
'ProxyGroup' => [
|
|
||||||
[
|
|
||||||
'name' => 'Proxy',
|
|
||||||
'type' => 'select',
|
|
||||||
'content' => [
|
|
||||||
'regex' => '(.*)'
|
|
||||||
]
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'Domestic',
|
|
||||||
'type' => 'select',
|
|
||||||
'content' => [
|
|
||||||
'left-proxies' => ['DIRECT', 'Proxy']
|
|
||||||
]
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'AsianTV',
|
|
||||||
'type' => 'select',
|
|
||||||
'content' => [
|
|
||||||
'left-proxies' => ['Domestic', 'Proxy']
|
|
||||||
]
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'GlobalTV',
|
|
||||||
'type' => 'select',
|
|
||||||
'content' => [
|
|
||||||
'left-proxies' => ['Proxy']
|
|
||||||
]
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'Others',
|
|
||||||
'type' => 'select',
|
|
||||||
'content' => [
|
|
||||||
'left-proxies' => ['Proxy', 'Domestic']
|
|
||||||
]
|
|
||||||
]
|
|
||||||
]
|
|
||||||
]
|
|
||||||
];
|
|
||||||
|
|
||||||
return $Apps_Profiles;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue