New File
parent
f98f872088
commit
df2f920703
@ -0,0 +1,2 @@
|
||||
.git
|
||||
uim-index-dev/
|
||||
@ -0,0 +1,19 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an new idea for this project
|
||||
title: "[Feature Request]"
|
||||
labels: enhancement
|
||||
|
||||
---
|
||||
|
||||
- [ ] I acknowledge if I don't follow the format below or I don't check these box, my issue could be closed without any notice.
|
||||
- [ ] I certify that I have read project Wiki and other issue may related to this one.
|
||||
|
||||
**Feature**
|
||||
The feature you want.
|
||||
|
||||
**Solution**
|
||||
If you have some solution about this issue, type it here.
|
||||
|
||||
**Addition**
|
||||
Additional context here.
|
||||
@ -0,0 +1,46 @@
|
||||
.idea
|
||||
.vs/
|
||||
.htaccess
|
||||
*/.DS_Store
|
||||
.DS_Store
|
||||
composer.lock
|
||||
.php_cs.cache
|
||||
.env
|
||||
.editorconfig
|
||||
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
|
||||
|
||||
.vscode
|
||||
config/.malio_config.php
|
||||
malio-noobfs.js
|
||||
malio-dev.js
|
||||
malio-release.js
|
||||
malio.js
|
||||
resources/email/template
|
||||
.i18n.php
|
||||
@ -0,0 +1,98 @@
|
||||
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
|
||||
@ -0,0 +1,4 @@
|
||||
# How to Contribute / 如何贡献代码
|
||||
|
||||
[English](#English)
|
||||
[简体中文](#简体中文)
|
||||
@ -0,0 +1,26 @@
|
||||
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
|
||||
@ -0,0 +1,3 @@
|
||||
# 欢迎使用 SSPanel V3 魔改再次修改版
|
||||
|
||||
**ss-panel-v3-mod**是一款专为 Shadowsocks/ShadowsocksR 设计的管理面板,再次感谢 ss-panel-v3-mod 的制作者,修改后的功能简介:
|
||||
@ -0,0 +1,81 @@
|
||||
<?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::getdb('Telegram.enable.Diary') !== '0') {
|
||||
Telegram::Send(
|
||||
str_replace(
|
||||
array(
|
||||
'%getTodayCheckinUser%',
|
||||
'%lastday_total%'
|
||||
),
|
||||
array(
|
||||
$sts->getTodayCheckinUser(),
|
||||
Tools::flowAutoShow($lastday_total)
|
||||
),
|
||||
Config::getdb('Telegram.msg.Diary')
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static function reall()
|
||||
{
|
||||
$users = User::all();
|
||||
foreach ($users as $user) {
|
||||
$user->last_day_t = ($user->u + $user->d);
|
||||
$user->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,76 @@
|
||||
<?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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function customEmail()
|
||||
{
|
||||
echo '发送自定义邮件 (邮件内容请编辑)';
|
||||
// ask for input
|
||||
fwrite(STDOUT, '请输入邮件标题: ');
|
||||
// get input
|
||||
$emailTitle = trim(fgets(STDIN));
|
||||
echo "邮件标题: $emailTitle";
|
||||
fwrite(STDOUT, "按下[Y]确认来发送邮件..... \n");
|
||||
$y = trim(fgets(STDIN));
|
||||
|
||||
if (strtolower($y) == 'y') {
|
||||
$users = User::all();
|
||||
foreach ($users as $user) {
|
||||
echo 'Send daily mail to user: ' . $user->id . ' ('.$user->email.')';
|
||||
try {
|
||||
Mail::send($user->email, $emailTitle, 'customEmail.tpl', ['user' => $user], []);
|
||||
} catch (Exception $e) {
|
||||
echo $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,210 @@
|
||||
<?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
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Services\Config;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
|
||||
class Malio
|
||||
{
|
||||
public static function GenerateUUIDforAllUsers()
|
||||
{
|
||||
$users = User::all();
|
||||
foreach ($users as $user) {
|
||||
if ($user->uuid == null) {
|
||||
$user->uuid = Uuid::uuid3(Uuid::NAMESPACE_DNS, ($user->passwd) . Config::get('key') . $user->id)->toString();
|
||||
if ($user->save()) {
|
||||
echo ($user->id . " 生成UUID成功 " . $user->uuid . PHP_EOL);
|
||||
} else {
|
||||
echo ($user->id . " 失败 " . $user->uuid . PHP_EOL);
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,224 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,406 @@
|
||||
<?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\Services\Config;
|
||||
use App\Services\DefaultConfig;
|
||||
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 ('detectConfigs'):
|
||||
return $this->detectConfigs();
|
||||
case ('portAutoChange'):
|
||||
return PortAutoChange::index();
|
||||
case ('alipay'):
|
||||
return (new ChenPay())->AliPayListen();
|
||||
case ('wxpay'):
|
||||
return (new ChenPay())->WxPayListen();
|
||||
case ('createAdmin'):
|
||||
return $this->createAdmin();
|
||||
case ('resetTraffic'):
|
||||
return $this->resetTraffic();
|
||||
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();
|
||||
case ('GenerateUUIDforAllUsers'):
|
||||
return Malio::GenerateUUIDforAllUsers();
|
||||
case ('delSubCache'):
|
||||
return $this->delSubCache();
|
||||
case ('sendCustomEmail'):
|
||||
return ExtMail::customEmail();
|
||||
default:
|
||||
return $this->defaultAction();
|
||||
}
|
||||
}
|
||||
|
||||
public function defaultAction()
|
||||
{
|
||||
echo (PHP_EOL . '用法: php xcat [选项]' . PHP_EOL);
|
||||
echo ('常用选项:' . PHP_EOL);
|
||||
echo (' createAdmin - 创建管理员帐号' . 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()
|
||||
{
|
||||
if (Config::get('use_new_telegram_bot') === true) {
|
||||
$WebhookUrl = (Config::get('baseUrl') . '/TelegramCallback?token=' . Config::get('telegram_request_token'));
|
||||
$telegram = new \Telegram\Bot\Api(Config::get('telegram_token'));
|
||||
$telegram->removeWebhook();
|
||||
if ($telegram->setWebhook(['url' => $WebhookUrl])) {
|
||||
echo('New Bot @' . $telegram->getMe()->getUsername() . ' 设置成功!');
|
||||
}
|
||||
} else {
|
||||
$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 ('Old Bot 设置成功!' . 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;
|
||||
}
|
||||
}
|
||||
|
||||
public function detectConfigs()
|
||||
{
|
||||
echo DefaultConfig::detectConfigs();
|
||||
}
|
||||
|
||||
public function delSubCache()
|
||||
{
|
||||
if (Config::get('enable_sub_cache') === true) {
|
||||
if (Tools::delSubCache() === true) {
|
||||
echo (PHP_EOL . '订阅缓存清理成功.' . PHP_EOL);
|
||||
} else {
|
||||
echo (PHP_EOL . '订阅缓存清理失败.' . PHP_EOL);
|
||||
}
|
||||
} else {
|
||||
echo (PHP_EOL . '订阅缓存未开启.' . PHP_EOL);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,76 @@
|
||||
<?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());
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,146 @@
|
||||
<?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());
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,43 @@
|
||||
<?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());
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,148 @@
|
||||
<?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());
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Admin;
|
||||
|
||||
use App\Controllers\AdminController;
|
||||
use App\Services\Auth;
|
||||
use App\Models\GConfig;
|
||||
|
||||
class GConfigController extends AdminController
|
||||
{
|
||||
public function update($request, $response, $args)
|
||||
{
|
||||
$key = trim($args['key']);
|
||||
$user = Auth::getUser();
|
||||
|
||||
$config = GConfig::find($key);
|
||||
$config->oldvalue = $config->value;
|
||||
$config->value = $request->getParam('value');
|
||||
$config->operator_id = $user->id;
|
||||
$config->operator_name = $user->user_name;
|
||||
$config->operator_email = $user->email;
|
||||
$config->last_update = time();
|
||||
if (!$config->save()) {
|
||||
$rs['ret'] = 0;
|
||||
$rs['msg'] = '修改失败';
|
||||
return $response->write(json_encode($rs));
|
||||
}
|
||||
$rs['ret'] = 1;
|
||||
$rs['msg'] = '修改成功';
|
||||
return $response->write(json_encode($rs));
|
||||
}
|
||||
|
||||
public function telegram($request, $response, $args)
|
||||
{
|
||||
$table_config['total_column'] = array(
|
||||
'op' => '操作',
|
||||
'name' => '配置名称',
|
||||
'key' => '配置名',
|
||||
'value' => '配置值',
|
||||
'operator_id' => '操作员 ID',
|
||||
'operator_name' => '操作员名称',
|
||||
'operator_email' => '操作员邮箱',
|
||||
'last_update' => '修改时间'
|
||||
);
|
||||
$table_config['default_show_column'] = array();
|
||||
foreach ($table_config['total_column'] as $column => $value) {
|
||||
$table_config['default_show_column'][] = $column;
|
||||
}
|
||||
$table_config['ajax_url'] = 'telegram/ajax';
|
||||
return $this->view()->assign('table_config', $table_config)->fetch('admin/config/telegram/index.tpl');
|
||||
}
|
||||
|
||||
public function telegram_edit($request, $response, $args)
|
||||
{
|
||||
$key = trim($args['key']);
|
||||
$config = GConfig::find($key);
|
||||
return $this->view()->assign('edit_config', $config)->fetch('admin/config/telegram/edit.tpl');
|
||||
}
|
||||
|
||||
public function telegram_update($request, $response, $args)
|
||||
{
|
||||
return self::update($request, $response, $args);
|
||||
}
|
||||
|
||||
public function telegram_ajax($request, $response, $args)
|
||||
{
|
||||
$start = $request->getParam("start");
|
||||
$limit_length = $request->getParam('length');
|
||||
$configs = GConfig::skip($start)->where('key', 'LIKE', "%Telegram%")->limit($limit_length)->get();
|
||||
$total_conut = GConfig::where('key', 'LIKE', "%Telegram%")->count();
|
||||
$data = [];
|
||||
foreach ($configs as $config) {
|
||||
$tempdata = [];
|
||||
$tempdata['op'] = '<a class="btn btn-brand" href="/admin/config/telegram/' . $config->key . '/edit">编辑</a>';
|
||||
$tempdata['name'] = $config->name;
|
||||
$tempdata['key'] = $config->key;
|
||||
$tempdata['value'] = $config->value;
|
||||
$tempdata['operator_id'] = $config->operator_id;
|
||||
$tempdata['operator_name'] = $config->operator_name;
|
||||
$tempdata['operator_email'] = $config->operator_email;
|
||||
$tempdata['last_update'] = date('Y-m-d H:i:s', $config->last_update);
|
||||
if (strpos($config->key, '.enable.')) {
|
||||
switch ((int) $config->value) {
|
||||
case 0:
|
||||
$tempdata['value'] = '关闭';
|
||||
break;
|
||||
case 1:
|
||||
$tempdata['value'] = '开启';
|
||||
break;
|
||||
default:
|
||||
$tempdata['value'] = '未知';
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
$tempdata['value'] = '(请在编辑页面查看)';
|
||||
}
|
||||
$data[] = $tempdata;
|
||||
}
|
||||
$info = [
|
||||
'draw' => $request->getParam('draw'),
|
||||
'recordsTotal' => $total_conut,
|
||||
'recordsFiltered' => $total_conut,
|
||||
'data' => $data
|
||||
];
|
||||
|
||||
return json_encode($info, true);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,190 @@
|
||||
<?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());
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,311 @@
|
||||
<?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());
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,41 @@
|
||||
<?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());
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Services\View;
|
||||
use App\Services\Auth;
|
||||
use Slim\Http\Response;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Smarty;
|
||||
use App\Services\Internationalization;
|
||||
|
||||
/**
|
||||
* 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();
|
||||
$this->i18n = new Internationalization();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get smarty
|
||||
*
|
||||
* @return Smarty
|
||||
*/
|
||||
public function view()
|
||||
{
|
||||
return $this->view;
|
||||
}
|
||||
|
||||
// TODO: remove
|
||||
/**
|
||||
* Output JSON
|
||||
*
|
||||
* @param Response $response
|
||||
* @param array|object $resource
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function echoJson(Response $response, $resource)
|
||||
{
|
||||
return $response->withJson($resource);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,591 @@
|
||||
<?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 (in_array($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 (!in_array($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)
|
||||
{
|
||||
$confStr = [
|
||||
'Proxy' => 'proxies',
|
||||
'ProxyGroup' => 'proxy-groups',
|
||||
];
|
||||
if (isset($_GET['newconf']) && (int) $_GET['newconf'] == 0) {
|
||||
$confStr = [
|
||||
'Proxy' => 'Proxy',
|
||||
'ProxyGroup' => 'Proxy Group',
|
||||
];
|
||||
}
|
||||
|
||||
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[$confStr['Proxy']] = $Proxys;
|
||||
if (isset($Configs['ProxyGroup'])) {
|
||||
$tmp[$confStr['ProxyGroup']] = self::getClashConfProxyGroup(
|
||||
$AllProxys,
|
||||
$Configs['ProxyGroup']
|
||||
);
|
||||
} else {
|
||||
$tmp[$confStr['ProxyGroup']] = 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)
|
||||
{
|
||||
$confStr = 'rules';
|
||||
if (isset($_GET['newconf']) && (int) $_GET['newconf'] == 0) {
|
||||
$confStr = 'Rule';
|
||||
}
|
||||
$return = ($confStr . ':' . PHP_EOL);
|
||||
|
||||
// 加载本地规则文件
|
||||
if ($local) {
|
||||
$render = ConfRender::getTemplateRender();
|
||||
return $return . $render->fetch(trim($Rules['source']));
|
||||
}
|
||||
|
||||
// 加载远程规则文件
|
||||
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[$confStr])) {
|
||||
$return .= $sourceContent;
|
||||
} else {
|
||||
$return .= Yaml::dump($sourceRule[$confStr], 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...
|
||||
}
|
||||
@ -0,0 +1,363 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Models\InviteCode;
|
||||
use App\Services\Auth;
|
||||
use App\Services\Config;
|
||||
use App\Services\MalioConfig;
|
||||
use App\Utils\AliPay;
|
||||
use App\Utils\TelegramSessionManager;
|
||||
use App\Utils\TelegramProcess;
|
||||
use App\Utils\Geetest;
|
||||
use App\Utils\Tools;
|
||||
use App\Services\Internationalization;
|
||||
use App\Utils\Telegram\Process;
|
||||
use Slim\Http\{Request, Response};
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
/**
|
||||
* HomeController
|
||||
*/
|
||||
class HomeController extends BaseController
|
||||
{
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param Response $response
|
||||
* @param array $args
|
||||
*/
|
||||
public function index($request, $response, $args): ResponseInterface
|
||||
{
|
||||
$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') === false && Config::get('theme') == 'material') {
|
||||
return $response->write($this->view()->fetch('indexold.tpl'));
|
||||
} else {
|
||||
if (!Auth::getUser()->isLogin) {
|
||||
$i18n = new Internationalization();
|
||||
if (MalioConfig::get('only_one_lang') != 'none') {
|
||||
$i18n->lang = MalioConfig::get('only_one_lang');
|
||||
} else {
|
||||
$i18n->detectLang($request, $response, $args);
|
||||
}
|
||||
return $response->write($this->view()
|
||||
->assign('i18n', $i18n)
|
||||
->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'));
|
||||
} else {
|
||||
return $response->write($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')
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param Response $response
|
||||
* @param array $args
|
||||
*/
|
||||
public function indexold($request, $response, $args): ResponseInterface
|
||||
{
|
||||
return $response->write($this->view()->fetch('indexold.tpl'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param Response $response
|
||||
* @param array $args
|
||||
*/
|
||||
public function code($request, $response, $args): ResponseInterface
|
||||
{
|
||||
$codes = InviteCode::where('user_id', '=', '0')->take(10)->get();
|
||||
return $response->write($this->view()->assign('codes', $codes)->fetch('code.tpl'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param Response $response
|
||||
* @param array $args
|
||||
*/
|
||||
public function tos($request, $response, $args): ResponseInterface
|
||||
{
|
||||
return $response->write($this->view()->fetch('tos.tpl'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param Response $response
|
||||
* @param array $args
|
||||
*/
|
||||
public function staff($request, $response, $args): ResponseInterface
|
||||
{
|
||||
return $response->write($this->view()->fetch('staff.tpl'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param Response $response
|
||||
* @param array $args
|
||||
*/
|
||||
public function telegram($request, $response, $args): ResponseInterface
|
||||
{
|
||||
$token = $request->getQueryParam('token');
|
||||
if ($token == Config::get('telegram_request_token')) {
|
||||
TelegramProcess::process();
|
||||
$result = '1';
|
||||
} else {
|
||||
$result = '0';
|
||||
}
|
||||
return $response->write($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param Response $response
|
||||
* @param array $args
|
||||
*/
|
||||
public function NewTelegram($request, $response, $args): ResponseInterface
|
||||
{
|
||||
$token = $request->getQueryParam('token');
|
||||
if ($token == Config::get('telegram_request_token')) {
|
||||
Process::index();
|
||||
$result = '1';
|
||||
} else {
|
||||
$result = '0';
|
||||
}
|
||||
return $response->write($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param Response $response
|
||||
* @param array $args
|
||||
*/
|
||||
public function page404($request, $response, $args): ResponseInterface
|
||||
{
|
||||
return $response->write($this->view()->fetch('404.tpl'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param Response $response
|
||||
* @param array $args
|
||||
*/
|
||||
public function page405($request, $response, $args): ResponseInterface
|
||||
{
|
||||
return $response->write($this->view()->fetch('405.tpl'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param Response $response
|
||||
* @param array $args
|
||||
*/
|
||||
public function page500($request, $response, $args): ResponseInterface
|
||||
{
|
||||
return $response->write($this->view()->fetch('500.tpl'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param Response $response
|
||||
* @param array $args
|
||||
*/
|
||||
public function getOrderList($request, $response, $args): ResponseInterface
|
||||
{
|
||||
$key = $request->getParam('key');
|
||||
if (!$key || $key != Config::get('key')) {
|
||||
$res['ret'] = 0;
|
||||
$res['msg'] = '错误';
|
||||
return $response->write(json_encode($res));
|
||||
}
|
||||
return $response->write(json_encode(['data' => AliPay::getList()]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param Response $response
|
||||
* @param array $args
|
||||
*/
|
||||
public function setOrder($request, $response, $args): ResponseInterface
|
||||
{
|
||||
$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->write(json_encode($res));
|
||||
}
|
||||
return $response->write(json_encode(['res' => AliPay::setOrder($sn, $url)]));
|
||||
}
|
||||
|
||||
public function getDocCenter($request, $response, $args)
|
||||
{
|
||||
$user = Auth::getUser();
|
||||
if (!$user->isLogin && Config::get('enable_documents') === false) {
|
||||
$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)
|
||||
->fetch('doc/index.tpl');
|
||||
}
|
||||
|
||||
public function getSubLink($request, $response, $args)
|
||||
{
|
||||
$type = trim($request->getParam('type'));
|
||||
$user = Auth::getUser();
|
||||
if (!$user->isLogin) {
|
||||
return $msg = '!> ₍₍ ◝(・ω・)◟ ⁾⁾ 您没有登录噢,[点击此处登录](/auth/login \':ignore target=_blank\') 之后再刷新就阔以了啦';
|
||||
} else {
|
||||
$subInfo = LinkController::getSubinfo($user, 0);
|
||||
switch ($type) {
|
||||
case 'ssr':
|
||||
$msg = [
|
||||
'**订阅链接:**',
|
||||
'```',
|
||||
$subInfo['ssr'],
|
||||
'```'
|
||||
];
|
||||
break;
|
||||
case 'v2ray':
|
||||
$msg = [
|
||||
'**订阅链接:**',
|
||||
'```',
|
||||
$subInfo['v2ray'],
|
||||
'```'
|
||||
];
|
||||
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'],
|
||||
'```'
|
||||
];
|
||||
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:
|
||||
if (in_array($type, $subInfo)) {
|
||||
$msg = [
|
||||
'```',
|
||||
$subInfo[$type],
|
||||
'```'
|
||||
];
|
||||
} else {
|
||||
$msg = [
|
||||
'获取失败了呢...,请联系管理员。'
|
||||
];
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return implode(PHP_EOL, $msg);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,274 @@
|
||||
<?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;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,137 @@
|
||||
<?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;
|
||||
}
|
||||
|
||||
// 0: new node; -1: offline; 1: online
|
||||
$node_heartbeat = $node->node_heartbeat + 300;
|
||||
$node_online = -1;
|
||||
if ($node_heartbeat == 300) {
|
||||
$node_online = 0;
|
||||
} elseif ($node_heartbeat > time()) {
|
||||
$node_online = 1;
|
||||
}
|
||||
|
||||
$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',
|
||||
'online' => $node_online
|
||||
],
|
||||
];
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,316 @@
|
||||
<?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;
|
||||
use App\Services\MalioConfig;
|
||||
|
||||
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('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('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', 'node_connector',
|
||||
'sort', 'uuid', 'sha224uuid');
|
||||
|
||||
$users = array();
|
||||
|
||||
foreach ($users_raw as $user_raw) {
|
||||
if ($node->sort == 14) {
|
||||
$user_raw->sha224uuid = hash('sha224', $user_raw->uuid);
|
||||
}
|
||||
if ($user_raw->transfer_enable > $user_raw->u + $user_raw->d) {
|
||||
$user_raw = Tools::keyFilter($user_raw, $key_list);
|
||||
$users[] = $user_raw;
|
||||
} else if (Config::get('keep_connect') === true) {
|
||||
$user_raw = Tools::keyFilter($user_raw, $key_list);
|
||||
// 流量耗尽用户限速至 1Mbps
|
||||
$user_raw->node_speedlimit = 1;
|
||||
$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 (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);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Models\PasswordReset;
|
||||
use App\Services\Password;
|
||||
use App\Utils\Hash;
|
||||
use App\Services\Internationalization;
|
||||
use App\Services\MalioConfig;
|
||||
|
||||
/***
|
||||
* Class Password
|
||||
* @package App\Controllers
|
||||
* 密码重置
|
||||
*/
|
||||
class PasswordController extends BaseController
|
||||
{
|
||||
public function reset($request, $response, $args)
|
||||
{
|
||||
$i18n = new Internationalization();
|
||||
if (MalioConfig::get('only_one_lang') != 'none') {
|
||||
$i18n->lang = MalioConfig::get('only_one_lang');
|
||||
} else {
|
||||
$i18n->detectLang($request, $response, $args);
|
||||
}
|
||||
|
||||
return $this->view()->assign('i18n', $i18n)->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'];
|
||||
|
||||
$i18n = new Internationalization();
|
||||
if (MalioConfig::get('only_one_lang') != 'none') {
|
||||
$i18n->lang = MalioConfig::get('only_one_lang');
|
||||
} else {
|
||||
$i18n->detectLang($request, $response, $args);
|
||||
}
|
||||
|
||||
return $this->view()->assign('i18n', $i18n)->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));
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,467 @@
|
||||
<?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 = '' . $single_path->begin_node->name . '' . ' <i class="fas fa-long-arrow-alt-right"></i> ' . $path->path;
|
||||
$path->status = '阻断';
|
||||
} else {
|
||||
$path->path = $single_path->begin_node->name . ' <i class="fas fa-long-arrow-alt-right"></i> ' . $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 . ' <i class="fas fa-long-arrow-alt-right"></i> ' . '' . $single_path->end_node->name . '';
|
||||
$path->status = '阻断';
|
||||
} else {
|
||||
$path->path = $path->path . ' <i class="fas fa-long-arrow-alt-right"></i> ' . $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);
|
||||
}
|
||||
)->where('node_class', '<=', $user->class)->orderBy('name')->get();
|
||||
|
||||
$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);
|
||||
}
|
||||
)->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;
|
||||
}
|
||||
}
|
||||
|
||||
$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);
|
||||
}
|
||||
)->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);
|
||||
}
|
||||
)->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();
|
||||
if (($port_raw == null && $port != $user->port)) {
|
||||
$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));
|
||||
}
|
||||
|
||||
Tools::delSubCache();
|
||||
|
||||
$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);
|
||||
}
|
||||
)->where('node_class', '<=', $user->class)->orderBy('name')->get();
|
||||
|
||||
$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);
|
||||
}
|
||||
)->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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$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);
|
||||
}
|
||||
)->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);
|
||||
}
|
||||
)->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();
|
||||
if (($port_raw == null && $port != $user->port)) {
|
||||
$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));
|
||||
}
|
||||
|
||||
Tools::delSubCache();
|
||||
|
||||
$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));
|
||||
}
|
||||
|
||||
Tools::delSubCache();
|
||||
|
||||
$rs['ret'] = 1;
|
||||
$rs['msg'] = '删除成功';
|
||||
return $response->getBody()->write(json_encode($rs));
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,20 @@
|
||||
<?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
@ -0,0 +1,563 @@
|
||||
<?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\Tools;
|
||||
use App\Utils\TelegramSessionManager;
|
||||
use App\Utils\Geetest;
|
||||
|
||||
use App\Utils\URL;
|
||||
use App\Models\Node;
|
||||
use App\Models\Relay;
|
||||
use Slim\Http\{Request, Response};
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
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'),
|
||||
'enable_flag' => Config::get('enable_flag'),
|
||||
'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));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $requesr
|
||||
* @param Response $response
|
||||
* @param array $args
|
||||
*/
|
||||
public function getNodeInfo($request, $response, $args): ResponseInterface
|
||||
{
|
||||
$user = $this->user;
|
||||
$id = $args['id'];
|
||||
$mu = $request->getQueryParam('ismu');
|
||||
$relay_rule_id = $request->getQueryParam('relay_rule');
|
||||
$node = Node::find($id);
|
||||
|
||||
if ($node == null) {
|
||||
return $response->withJson([null]);
|
||||
}
|
||||
|
||||
switch ($node->sort) {
|
||||
case 0:
|
||||
if ((($user->class >= $node->node_class
|
||||
&& ($user->node_group == $node->node_group || $node->node_group == 0)) || $user->is_admin)
|
||||
&& ($node->node_bandwidth_limit == 0 || $node->node_bandwidth < $node->node_bandwidth_limit)
|
||||
) {
|
||||
return $response->withJson([
|
||||
'ret' => 1,
|
||||
'nodeInfo' => [
|
||||
'node' => $node,
|
||||
'user' => $user,
|
||||
'mu' => $mu,
|
||||
'relay_rule_id' => $relay_rule_id,
|
||||
'URL' => URL::class,
|
||||
],
|
||||
]);
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if ($user->class >= $node->node_class
|
||||
&& ($user->node_group == $node->node_group || $node->node_group == 0)
|
||||
) {
|
||||
$email = $user->email;
|
||||
$email = Radius::GetUserName($email);
|
||||
$json_show = 'VPN 信息<br>地址:' . $node->server
|
||||
. '<br>用户名:' . $email . '<br>密码:' . $this->user->passwd
|
||||
. '<br>支持方式:' . $node->method . '<br>备注:' . $node->info;
|
||||
|
||||
return $response->write(
|
||||
$this->view()->assign('json_show', $json_show)->fetch('user/nodeinfovpn.tpl')
|
||||
);
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if ($user->class >= $node->node_class
|
||||
&& ($user->node_group == $node->node_group || $node->node_group == 0)) {
|
||||
$email = $user->email;
|
||||
$email = Radius::GetUserName($email);
|
||||
$json_show = 'SSH 信息<br>地址:' . $node->server
|
||||
. '<br>用户名:' . $email . '<br>密码:' . $this->user->passwd
|
||||
. '<br>支持方式:' . $node->method . '<br>备注:' . $node->info;
|
||||
|
||||
return $response->write(
|
||||
$this->view()->assign('json_show', $json_show)->fetch('user/nodeinfossh.tpl')
|
||||
);
|
||||
}
|
||||
break;
|
||||
case 5:
|
||||
if ($user->class >= $node->node_class
|
||||
&& ($user->node_group == $node->node_group || $node->node_group == 0)) {
|
||||
$email = $user->email;
|
||||
$email = Radius::GetUserName($email);
|
||||
|
||||
$json_show = 'Anyconnect 信息<br>地址:' . $node->server
|
||||
. '<br>用户名:' . $email . '<br>密码:' . $this->user->passwd
|
||||
. '<br>支持方式:' . $node->method . '<br>备注:' . $node->info;
|
||||
|
||||
return $response->write(
|
||||
$this->view()->assign('json_show', $json_show)->fetch('user/nodeinfoanyconnect.tpl')
|
||||
);
|
||||
}
|
||||
break;
|
||||
case 10:
|
||||
if ((($user->class >= $node->node_class
|
||||
&& ($user->node_group == $node->node_group || $node->node_group == 0)) || $user->is_admin)
|
||||
&& ($node->node_bandwidth_limit == 0 || $node->node_bandwidth < $node->node_bandwidth_limit)) {
|
||||
return $response->withJson([
|
||||
'ret' => 1,
|
||||
'nodeInfo' => [
|
||||
'node' => $node,
|
||||
'user' => $user,
|
||||
'mu' => $mu,
|
||||
'relay_rule_id' => $relay_rule_id,
|
||||
'URL' => URL::class,
|
||||
],
|
||||
]);
|
||||
}
|
||||
break;
|
||||
case 13:
|
||||
if ((($user->class >= $node->node_class
|
||||
&& ($user->node_group == $node->node_group || $node->node_group == 0)) || $user->is_admin)
|
||||
&& ($node->node_bandwidth_limit == 0 || $node->node_bandwidth < $node->node_bandwidth_limit)) {
|
||||
return $response->withJson([
|
||||
'ret' => 1,
|
||||
'nodeInfo' => [
|
||||
'node' => $node,
|
||||
'user' => $user,
|
||||
'mu' => $mu,
|
||||
'relay_rule_id' => $relay_rule_id,
|
||||
'URL' => URL::class,
|
||||
],
|
||||
]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Default and judgement fail return
|
||||
return $response->withJson([
|
||||
'ret' => 0,
|
||||
'nodeInfo' => [
|
||||
'message' => ':)',
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Middleware;
|
||||
|
||||
use App\Services\Auth as AuthService;
|
||||
|
||||
class Admin
|
||||
{
|
||||
/**
|
||||
* @param \Slim\Http\Request $request
|
||||
* @param \Slim\Http\Response $response
|
||||
* @param callable $next
|
||||
*
|
||||
* @return \Slim\Http\Response
|
||||
*/
|
||||
public function __invoke($request, $response, $next)
|
||||
{
|
||||
$user = AuthService::getUser();
|
||||
if (!$user->isLogin) {
|
||||
return $response->withStatus(302)->withHeader('Location', '/auth/login');
|
||||
}
|
||||
if (!$user->isAdmin()) {
|
||||
return $response->withStatus(302)->withHeader('Location', '/user');
|
||||
}
|
||||
return $next($request, $response);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Middleware;
|
||||
|
||||
use App\Services\Auth as AuthService;
|
||||
|
||||
class Auth
|
||||
{
|
||||
/**
|
||||
* @param \Slim\Http\Request $request
|
||||
* @param \Slim\Http\Response $response
|
||||
* @param callable $next
|
||||
*
|
||||
* @return \Slim\Http\Response
|
||||
*/
|
||||
public function __invoke($request, $response, $next)
|
||||
{
|
||||
$user = AuthService::getUser();
|
||||
if (!$user->isLogin) {
|
||||
return $response->withStatus(302)->withHeader('Location', '/auth/login');
|
||||
}
|
||||
$enablePages = array('/user/disable', '/user/backtoadmin', '/user/logout');
|
||||
if ($user->enable == 0 && !in_array($_SERVER['REQUEST_URI'], $enablePages)) {
|
||||
return $response->withStatus(302)->withHeader('Location', '/user/disable');
|
||||
}
|
||||
return $next($request, $response);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Middleware;
|
||||
|
||||
use App\Services\Auth as AuthService;
|
||||
|
||||
class Guest
|
||||
{
|
||||
/**
|
||||
* @param \Slim\Http\Request $request
|
||||
* @param \Slim\Http\Response $response
|
||||
* @param callable $next
|
||||
*
|
||||
* @return \Slim\Http\Response
|
||||
*/
|
||||
public function __invoke($request, $response, $next)
|
||||
{
|
||||
$user = AuthService::getUser();
|
||||
if ($user->isLogin) {
|
||||
return $response->withStatus(302)->withHeader('Location', '/user');
|
||||
}
|
||||
return $next($request, $response);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Middleware;
|
||||
|
||||
use App\Services\Config;
|
||||
use App\Models\Node;
|
||||
use App\Services\MalioConfig;
|
||||
|
||||
class Mod_Mu
|
||||
{
|
||||
/**
|
||||
* @param \Slim\Http\Request $request
|
||||
* @param \Slim\Http\Response $response
|
||||
* @param callable $next
|
||||
*
|
||||
* @return \Slim\Http\Response
|
||||
*/
|
||||
public function __invoke($request, $response, $next)
|
||||
{
|
||||
$key = $request->getQueryParam('key');
|
||||
if ($key === null) {
|
||||
return $response->withjson([
|
||||
'ret' => 0,
|
||||
'data' => 'Your key is null.'
|
||||
]);
|
||||
}
|
||||
|
||||
$keys = Config::getMuKey();
|
||||
$auth = in_array($key, $keys);
|
||||
|
||||
if ($auth == false) {
|
||||
$res['ret'] = 0;
|
||||
$res['data'] = 'token is invalid';
|
||||
$response->getBody()->write(json_encode($res));
|
||||
return $response;
|
||||
}
|
||||
|
||||
if (Config::get('checkNodeIp') === true){
|
||||
$node = Node::where('node_ip', 'LIKE', $_SERVER['REMOTE_ADDR'] . '%')->first();
|
||||
if ($auth === false || ($node === null && $_SERVER['REMOTE_ADDR'] != '127.0.0.1')) {
|
||||
return $response->withJson([
|
||||
'ret' => 0,
|
||||
'data' => 'Token or IP is invalid. Now, your IP address is ' . $_SERVER['REMOTE_ADDR']
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
return $next($request, $response);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
/**
|
||||
* Ann Model
|
||||
*/
|
||||
class Ann extends Model
|
||||
{
|
||||
protected $connection = 'default';
|
||||
protected $table = 'announcement';
|
||||
}
|
||||
@ -0,0 +1,20 @@
|
||||
<?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']);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,21 @@
|
||||
<?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']);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,96 @@
|
||||
<?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();
|
||||
}
|
||||
|
||||
/*
|
||||
* 套餐已使用的天数
|
||||
*
|
||||
*/
|
||||
public function used_days()
|
||||
{
|
||||
return (int) ((strtotime(date('Y-m-d')) - $this->datetime) / 86400);
|
||||
}
|
||||
|
||||
/*
|
||||
* 是否有效期内
|
||||
*
|
||||
*/
|
||||
public function valid()
|
||||
{
|
||||
$shop = $this->shop();
|
||||
if ($this->use_loop()) {
|
||||
return (time() - $shop->reset_exp() * 86400 < $this->datetime);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* 是否周期性商品
|
||||
*
|
||||
*/
|
||||
public function use_loop()
|
||||
{
|
||||
$shop = $this->shop();
|
||||
return ($shop->reset() != 0 && $shop->reset_value() != 0 && $shop->reset_exp() != 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* 下一次流量重置时间
|
||||
*
|
||||
*/
|
||||
public function reset_time($unix = false)
|
||||
{
|
||||
$shop = $this->shop();
|
||||
if ($this->use_loop()) {
|
||||
$day = $shop->reset() - ($this->used_days() % $shop->reset());
|
||||
$time = time() + ($day * 86400);
|
||||
return ($unix == false ? date('Y-m-d', $time) : $time);
|
||||
}
|
||||
return ($unix == false ? '-' : 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* 过期时间
|
||||
*
|
||||
*/
|
||||
public function exp_time($unix = false)
|
||||
{
|
||||
$shop = $this->shop();
|
||||
if ($this->use_loop()) {
|
||||
$time = $this->datetime + ($shop->reset_exp() * 86400);
|
||||
return ($unix == false ? date('Y-m-d H:i:s', $time) : $time);
|
||||
}
|
||||
return ($unix == false ? '-' : 0);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class CheckInLog
|
||||
{
|
||||
protected $connection = 'default';
|
||||
protected $table = 'ss_checkin_log';
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
<?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();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class Config extends Model
|
||||
{
|
||||
protected $connection = 'default';
|
||||
protected $table = 'config';
|
||||
}
|
||||
@ -0,0 +1,31 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class DetectBanLog extends Model
|
||||
{
|
||||
protected $connection = "default";
|
||||
protected $table = "detect_ban_log";
|
||||
}
|
||||
@ -0,0 +1,42 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
/**
|
||||
* DetectLog Model
|
||||
*/
|
||||
class DetectRule extends Model
|
||||
{
|
||||
protected $connection = 'default';
|
||||
protected $table = 'detect_list';
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
/**
|
||||
* Disconnect Model
|
||||
*/
|
||||
class Disconnect extends Model
|
||||
{
|
||||
protected $connection = 'default';
|
||||
protected $table = 'disconnect_ip';
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
/**
|
||||
* EmailVerify Model
|
||||
*/
|
||||
class EmailVerify extends Model
|
||||
{
|
||||
protected $connection = 'default';
|
||||
protected $table = 'email_verify';
|
||||
}
|
||||
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Services\DefaultConfig;
|
||||
|
||||
class GConfig extends Model
|
||||
{
|
||||
|
||||
/**
|
||||
* The connection name for the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $connection = 'default';
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'gconfig';
|
||||
|
||||
/**
|
||||
* The primary key associated with the table.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $primaryKey = 'key';
|
||||
|
||||
/**
|
||||
* Indicates if the IDs are auto-incrementing.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $incrementing = false;
|
||||
|
||||
/**
|
||||
* The "type" of the auto-incrementing ID.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $keyType = 'string';
|
||||
|
||||
public static function recover($user)
|
||||
{
|
||||
$this->oldvalue = $this->value;
|
||||
$this->value = DefaultConfig::default_value($this->key)['value'];
|
||||
$this->operator_id = $user->id;
|
||||
$this->operator_name = ('[恢复默认] - ' . $user->user_name);
|
||||
$this->operator_email = $user->email;
|
||||
$this->last_update = time();
|
||||
$this->save();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
/**
|
||||
* InviteCode Model
|
||||
*/
|
||||
class InviteCode extends Model
|
||||
{
|
||||
protected $connection = 'default';
|
||||
protected $table = 'ss_invite_code';
|
||||
}
|
||||
@ -0,0 +1,40 @@
|
||||
<?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']);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class Link extends Model
|
||||
{
|
||||
protected $connection = 'default';
|
||||
protected $table = 'link';
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
<?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']);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model as EloquentMedel;
|
||||
|
||||
/**
|
||||
* Base Model
|
||||
*/
|
||||
class Model extends EloquentMedel
|
||||
{
|
||||
public $timestamps = false;
|
||||
}
|
||||
@ -0,0 +1,193 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
/**
|
||||
* Node Model
|
||||
*/
|
||||
|
||||
use App\Utils\{Tools, URL};
|
||||
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];
|
||||
}
|
||||
|
||||
public function getServer()
|
||||
{
|
||||
$out = '';
|
||||
$explode = explode(';', $this->attributes['server']);
|
||||
if (in_array($this->attributes['sort'], [0, 10])) {
|
||||
if (isset($explode[1]) && stripos($explode[1], 'server=') !== false) {
|
||||
$out = URL::parse_args($explode[1])['server'];
|
||||
}
|
||||
}
|
||||
return ($out != '' ? $out : $explode[0]);
|
||||
}
|
||||
|
||||
public function getOffsetPort($port)
|
||||
{
|
||||
return Tools::OutPort($this->attributes['server'], $this->attributes['name'], $port)['port'];
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,22 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class NodeOnlineLog extends Model
|
||||
{
|
||||
protected $connection = 'default';
|
||||
protected $table = 'ss_node_online_log';
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class PasswordReset extends Model
|
||||
{
|
||||
protected $connection = 'default';
|
||||
protected $table = 'ss_password_reset';
|
||||
}
|
||||
@ -0,0 +1,20 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class Paylist extends Model
|
||||
{
|
||||
protected $connection = 'default';
|
||||
protected $table = 'paylist';
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class RadiusBan extends Model
|
||||
{
|
||||
protected $connection = 'default';
|
||||
protected $table = 'radius_ban';
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class RadiusNas extends Model
|
||||
{
|
||||
protected $connection = 'radius';
|
||||
protected $table = 'nas';
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class RadiusRadAcct extends Model
|
||||
{
|
||||
protected $connection = 'radius';
|
||||
protected $table = 'radacct';
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class RadiusRadCheck extends Model
|
||||
{
|
||||
protected $connection = 'radius';
|
||||
protected $table = 'radcheck';
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class RadiusRadPostauth extends Model
|
||||
{
|
||||
protected $connection = 'radius';
|
||||
protected $table = 'radpostauth';
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class RadiusRadUserGroup extends Model
|
||||
{
|
||||
protected $connection = 'radius';
|
||||
protected $table = 'radusergroup';
|
||||
}
|
||||
@ -0,0 +1,49 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
/**
|
||||
* Node Model
|
||||
*/
|
||||
class Role extends Model
|
||||
{
|
||||
protected $connection = 'default';
|
||||
protected $table = 'user_role';
|
||||
}
|
||||
@ -0,0 +1,193 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Services\Config;
|
||||
use App\Services\MalioConfig;
|
||||
|
||||
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;
|
||||
} elseif (MalioConfig::get('reset_bandwidth_and_expire_date_when_change_class') == true && $user->class != $content['class']) {
|
||||
$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();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
/**
|
||||
* SmsVerify Model
|
||||
*/
|
||||
class SmsVerify extends Model
|
||||
{
|
||||
protected $connection = 'default';
|
||||
protected $table = 'sms_verify';
|
||||
}
|
||||
@ -0,0 +1,79 @@
|
||||
<?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];
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class Token extends Model
|
||||
{
|
||||
protected $connection = 'default';
|
||||
protected $table = 'user_token';
|
||||
}
|
||||
@ -0,0 +1,49 @@
|
||||
<?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']);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
<?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']);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,831 @@
|
||||
<?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 App\Utils\URL;
|
||||
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()
|
||||
{
|
||||
$email_su=substr($this->attributes['email'],-6);
|
||||
$email_pre=substr($this->attributes['email'],0,-7);
|
||||
if($email_su=="qq.com" and is_numeric($email_pre)) {
|
||||
return "https://q4.qlogo.cn/g?b=qq&nk=".$this->attributes['email']."&s=3";
|
||||
}
|
||||
$hash = md5(strtolower(trim($this->attributes['email'])));
|
||||
return "https://secure.gravatar.com/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();
|
||||
return $this->attributes['uuid'];
|
||||
}
|
||||
|
||||
/*
|
||||
* 总流量
|
||||
*/
|
||||
public function enableTraffic()
|
||||
{
|
||||
$transfer_enable = $this->attributes['transfer_enable'];
|
||||
return Tools::flowAutoShow($transfer_enable);
|
||||
}
|
||||
|
||||
/*
|
||||
* 总流量[GB]
|
||||
*/
|
||||
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 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 unusedTraffic()
|
||||
{
|
||||
$total = $this->attributes['u'] + $this->attributes['d'];
|
||||
$transfer_enable = $this->attributes['transfer_enable'];
|
||||
return Tools::flowAutoShow($transfer_enable - $total);
|
||||
}
|
||||
|
||||
/*
|
||||
* 剩余流量占总流量的百分比
|
||||
*/
|
||||
public function unusedTrafficPercent()
|
||||
{
|
||||
$transferEnable = $this->attributes['transfer_enable'];
|
||||
if ($transferEnable == 0) {
|
||||
return 0;
|
||||
}
|
||||
$unusedTraffic = $transferEnable - ($this->attributes['u'] + $this->attributes['d']);
|
||||
$percent = $unusedTraffic / $transferEnable;
|
||||
$percent = round($percent, 2);
|
||||
$percent *= 100;
|
||||
return $percent;
|
||||
}
|
||||
|
||||
/*
|
||||
* 今天使用的流量
|
||||
*/
|
||||
public function TodayusedTraffic()
|
||||
{
|
||||
$total = $this->attributes['u'] + $this->attributes['d'] - $this->attributes['last_day_t'];
|
||||
return Tools::flowAutoShow($total);
|
||||
}
|
||||
|
||||
/*
|
||||
* 今天使用的流量占总流量的百分比
|
||||
*/
|
||||
public function TodayusedTrafficPercent()
|
||||
{
|
||||
$transferEnable = $this->attributes['transfer_enable'];
|
||||
if ($transferEnable == 0) {
|
||||
return 0;
|
||||
}
|
||||
$TodayusedTraffic = $this->attributes['u'] + $this->attributes['d'] - $this->attributes['last_day_t'];
|
||||
$percent = $TodayusedTraffic / $transferEnable;
|
||||
$percent = round($percent, 2);
|
||||
$percent *= 100;
|
||||
return $percent;
|
||||
}
|
||||
|
||||
/*
|
||||
* 今天之前已使用的流量
|
||||
*/
|
||||
public function LastusedTraffic()
|
||||
{
|
||||
$total = $this->attributes['last_day_t'];
|
||||
return Tools::flowAutoShow($total);
|
||||
}
|
||||
|
||||
/*
|
||||
* 今天之前已使用的流量占总流量的百分比
|
||||
*/
|
||||
public function LastusedTrafficPercent()
|
||||
{
|
||||
$transferEnable = $this->attributes['transfer_enable'];
|
||||
if ($transferEnable == 0) {
|
||||
return 0;
|
||||
}
|
||||
$LastusedTraffic = $this->attributes['last_day_t'];
|
||||
$percent = $LastusedTraffic / $transferEnable;
|
||||
$percent = round($percent, 2);
|
||||
$percent *= 100;
|
||||
return $percent;
|
||||
}
|
||||
|
||||
/*
|
||||
* 是否可以签到
|
||||
*/
|
||||
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->attributes['obfs_param'],
|
||||
$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()
|
||||
{
|
||||
$logs = DetectBanLog::where('user_id', $this->attributes['id'])->orderBy('id', 'desc')->first();
|
||||
if ($this->attributes['enable'] == 0 && $logs != null) {
|
||||
$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 calIncome($req)
|
||||
{
|
||||
switch($req)
|
||||
{
|
||||
case "yesterday":
|
||||
$number = Code::whereDate('usedatetime', '=', date('Y-m-d',strtotime('-1 days')))->sum('number');
|
||||
break;
|
||||
case "today":
|
||||
$number = Code::whereDate('usedatetime', '=', date('Y-m-d'))->sum('number');
|
||||
break;
|
||||
case "this month":
|
||||
$number = Code::whereMonth('usedatetime', '=', date('m'))->sum('number');
|
||||
break;
|
||||
case "last month":
|
||||
$number = Code::whereMonth('usedatetime', '=', date('m',strtotime('last month')))->sum('number');
|
||||
break;
|
||||
default:
|
||||
$number = Code::sum('number');
|
||||
break;
|
||||
}
|
||||
return is_null($number)?0:$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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理订阅缓存
|
||||
*/
|
||||
public function cleanSubCache()
|
||||
{
|
||||
$id = $this->attributes['id'];
|
||||
$user_path = (BASE_PATH . '/storage/SubscribeCache/' . $id . '/');
|
||||
if (is_dir($user_path)) {
|
||||
Tools::delDirAndFile($user_path);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 签到
|
||||
*/
|
||||
public function checkin()
|
||||
{
|
||||
$return = [
|
||||
'ok' => true,
|
||||
'msg' => ''
|
||||
];
|
||||
if (!$this->isAbleToCheckin()) {
|
||||
$return['ok'] = false;
|
||||
$return['msg'] = '您似乎已经签到过了...';
|
||||
} else {
|
||||
$traffic = random_int((int) Config::get('checkinMin'), (int) Config::get('checkinMax'));
|
||||
$this->transfer_enable += Tools::toMB($traffic);
|
||||
$this->last_check_in_time = time();
|
||||
$this->save();
|
||||
$return['msg'] = '获得了 ' . $traffic . 'MB 流量.';
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新加密方式
|
||||
*/
|
||||
public function setMethod($method)
|
||||
{
|
||||
$return = [
|
||||
'ok' => true,
|
||||
'msg' => '设置成功,您可自由选用两种客户端来进行连接。'
|
||||
];
|
||||
if ($method == '') {
|
||||
$return['ok'] = false;
|
||||
$return['msg'] = '非法输入';
|
||||
return $return;
|
||||
}
|
||||
if (!Tools::is_param_validate('method', $method)) {
|
||||
$return['ok'] = false;
|
||||
$return['msg'] = '加密无效';
|
||||
return $return;
|
||||
}
|
||||
$this->method = $method;
|
||||
if (!Tools::checkNoneProtocol($this)) {
|
||||
$return['ok'] = false;
|
||||
$return['msg'] = '系统检测到您将要设置的加密方式为 none ,但您的协议并不在以下协议【' . implode(',', Config::getSupportParam('allow_none_protocol')) . '】之内,请您先修改您的协议,再来修改此处设置。';
|
||||
return $return;
|
||||
}
|
||||
if (!URL::SSCanConnect($this) && !URL::SSRCanConnect($this)) {
|
||||
$return['ok'] = false;
|
||||
$return['msg'] = '您这样设置之后,就没有客户端能连接上了,所以系统拒绝了您的设置,请您检查您的设置之后再进行操作。';
|
||||
return $return;
|
||||
}
|
||||
$this->updateMethod($method);
|
||||
if (!URL::SSCanConnect($this)) {
|
||||
$return['ok'] = true;
|
||||
$return['msg'] = '设置成功,但您目前的协议,混淆,加密方式设置会导致 Shadowsocks 原版客户端无法连接,请您自行更换到 ShadowsocksR 客户端。';
|
||||
}
|
||||
if (!URL::SSRCanConnect($this)) {
|
||||
$return['ok'] = true;
|
||||
$return['msg'] = '设置成功,但您目前的协议,混淆,加密方式设置会导致 ShadowsocksR 客户端无法连接,请您自行更换到 Shadowsocks 客户端。';
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新协议
|
||||
*/
|
||||
public function setProtocol($Protocol)
|
||||
{
|
||||
$return = [
|
||||
'ok' => true,
|
||||
'msg' => '设置成功,您可自由选用客户端来连接。'
|
||||
];
|
||||
if ($Protocol == '') {
|
||||
$return['ok'] = false;
|
||||
$return['msg'] = '非法输入';
|
||||
return $return;
|
||||
}
|
||||
if (!Tools::is_param_validate('protocol', $Protocol)) {
|
||||
$return['ok'] = false;
|
||||
$return['msg'] = '协议无效';
|
||||
return $return;
|
||||
}
|
||||
$this->protocol = $Protocol;
|
||||
if (!Tools::checkNoneProtocol($this)) {
|
||||
$return['ok'] = false;
|
||||
$return['msg'] = '系统检测到您目前的加密方式为 none ,但您将要设置为的协议并不在以下协议【' . implode(',', Config::getSupportParam('allow_none_protocol')) . '】之内,请您先修改您的加密方式,再来修改此处设置。';
|
||||
return $return;
|
||||
}
|
||||
if (!URL::SSCanConnect($this) && !URL::SSRCanConnect($this)) {
|
||||
$return['ok'] = false;
|
||||
$return['msg'] = '您这样设置之后,就没有客户端能连接上了,所以系统拒绝了您的设置,请您检查您的设置之后再进行操作。';
|
||||
return $return;
|
||||
}
|
||||
$this->save();
|
||||
$this->cleanSubCache();
|
||||
if (!URL::SSCanConnect($this)) {
|
||||
$return['ok'] = true;
|
||||
$return['msg'] = '设置成功,但您目前的协议,混淆,加密方式设置会导致 Shadowsocks 原版客户端无法连接,请您自行更换到 ShadowsocksR 客户端。';
|
||||
}
|
||||
if (!URL::SSRCanConnect($this)) {
|
||||
$return['ok'] = true;
|
||||
$return['msg'] = '设置成功,但您目前的协议,混淆,加密方式设置会导致 ShadowsocksR 客户端无法连接,请您自行更换到 Shadowsocks 客户端。';
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新混淆
|
||||
*/
|
||||
public function setObfs($Obfs)
|
||||
{
|
||||
$return = [
|
||||
'ok' => true,
|
||||
'msg' => '设置成功,您可自由选用客户端来连接。'
|
||||
];
|
||||
if ($Obfs == '') {
|
||||
$return['ok'] = false;
|
||||
$return['msg'] = '非法输入';
|
||||
return $return;
|
||||
}
|
||||
if (!Tools::is_param_validate('obfs', $Obfs)) {
|
||||
$return['ok'] = false;
|
||||
$return['msg'] = '混淆无效';
|
||||
return $return;
|
||||
}
|
||||
$this->obfs = $Obfs;
|
||||
if (!URL::SSCanConnect($this) && !URL::SSRCanConnect($this)) {
|
||||
$return['ok'] = false;
|
||||
$return['msg'] = '您这样设置之后,就没有客户端能连接上了,所以系统拒绝了您的设置,请您检查您的设置之后再进行操作。';
|
||||
return $return;
|
||||
}
|
||||
$this->save();
|
||||
$this->cleanSubCache();
|
||||
if (!URL::SSCanConnect($this)) {
|
||||
$return['ok'] = true;
|
||||
$return['msg'] = '设置成功,但您目前的协议,混淆,加密方式设置会导致 Shadowsocks 原版客户端无法连接,请您自行更换到 ShadowsocksR 客户端。';
|
||||
}
|
||||
if (!URL::SSRCanConnect($this)) {
|
||||
$return['ok'] = true;
|
||||
$return['msg'] = '设置成功,但您目前的协议,混淆,加密方式设置会导致 ShadowsocksR 客户端无法连接,请您自行更换到 Shadowsocks 客户端。';
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解绑 Telegram
|
||||
*/
|
||||
public function TelegramReset()
|
||||
{
|
||||
$return = [
|
||||
'ok' => true,
|
||||
'msg' => '解绑成功.'
|
||||
];
|
||||
$telegram_id = $this->telegram_id;
|
||||
$this->telegram_id = 0;
|
||||
if ($this->save()) {
|
||||
if (
|
||||
Config::get('enable_telegram') === true
|
||||
&&
|
||||
Config::get('group_bound_user') === true
|
||||
&&
|
||||
Config::get('unbind_kick_member') === true
|
||||
) {
|
||||
\App\Utils\Telegram\TelegramTools::SendPost(
|
||||
'kickChatMember',
|
||||
[
|
||||
'chat_id' => Config::get('telegram_chatid'),
|
||||
'user_id' => $telegram_id,
|
||||
]
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$return = [
|
||||
'ok' => false,
|
||||
'msg' => '解绑失败.'
|
||||
];
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新端口
|
||||
*/
|
||||
public function setPort($Port)
|
||||
{
|
||||
$PortOccupied = User::pluck('port')->toArray();
|
||||
if (in_array($Port, $PortOccupied) == true) {
|
||||
return [
|
||||
'ok' => false,
|
||||
'msg' => '端口已被占用'
|
||||
];
|
||||
}
|
||||
$origin_port = $this->port;
|
||||
$this->port = $Port;
|
||||
$relay_rules = Relay::where('user_id', $this->id)->where('port', $origin_port)->get();
|
||||
foreach ($relay_rules as $rule) {
|
||||
$rule->port = $this->port;
|
||||
$rule->save();
|
||||
}
|
||||
$this->save();
|
||||
$this->cleanSubCache();
|
||||
return [
|
||||
'ok' => true,
|
||||
'msg' => $this->port
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置端口
|
||||
*/
|
||||
public function ResetPort()
|
||||
{
|
||||
$price = Config::get('port_price');
|
||||
if ($this->money < $price) {
|
||||
return [
|
||||
'ok' => false,
|
||||
'msg' => '余额不足'
|
||||
];
|
||||
}
|
||||
$this->money -= $price;
|
||||
$Port = Tools::getAvPort();
|
||||
$this->setPort($Port);
|
||||
$this->save();
|
||||
return [
|
||||
'ok' => true,
|
||||
'msg' => $this->port
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定端口
|
||||
*/
|
||||
public function SpecifyPort($Port)
|
||||
{
|
||||
$price = Config::get('port_price_specify');
|
||||
if ($this->money < $price) {
|
||||
return [
|
||||
'ok' => false,
|
||||
'msg' => '余额不足'
|
||||
];
|
||||
}
|
||||
if ($Port < Config::get('min_port') || $Port > Config::get('max_port') || Tools::isInt($Port) == false) {
|
||||
return [
|
||||
'ok' => false,
|
||||
'msg' => '端口不在要求范围内'
|
||||
];
|
||||
}
|
||||
$PortOccupied = User::pluck('port')->toArray();
|
||||
if (in_array($Port, $PortOccupied) == true) {
|
||||
return [
|
||||
'ok' => false,
|
||||
'msg' => '端口已被占用'
|
||||
];
|
||||
}
|
||||
$this->money -= $price;
|
||||
$this->setPort($Port);
|
||||
$this->save();
|
||||
return [
|
||||
'ok' => true,
|
||||
'msg' => '钦定成功'
|
||||
];
|
||||
}
|
||||
|
||||
public function valid_use_loop()
|
||||
{
|
||||
$boughts = Bought::where('userid', $this->id)->orderBy('id', 'desc')->get();
|
||||
$data = [];
|
||||
foreach ($boughts as $bought) {
|
||||
$shop = $bought->shop();
|
||||
if ($shop != null && $bought->valid()) {
|
||||
$data[] = $bought->reset_time();
|
||||
}
|
||||
}
|
||||
if (count($data) == 0) {
|
||||
return '未购买套餐.';
|
||||
}
|
||||
if (count($data) == 1) {
|
||||
return $data[0];
|
||||
}
|
||||
return '多个有效套餐无法显示.';
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class UserSubscribeLog extends Model
|
||||
{
|
||||
protected $connection = 'default';
|
||||
protected $table = 'user_subscribe_log';
|
||||
}
|
||||
@ -0,0 +1,31 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,143 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Models\Node;
|
||||
use App\Utils\Tools;
|
||||
use App\Models\Code;
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
public function getIncome($start, $end)
|
||||
{
|
||||
$sum = Code::where('usedatetime', '>=', date("Y-m-d H:i:s", $start))
|
||||
->where('usedatetime', '<', date("Y-m-d H:i:s", $end))
|
||||
->sum('number');
|
||||
if ($sum == null) {
|
||||
$sum = 0;
|
||||
}
|
||||
return $sum;
|
||||
}
|
||||
|
||||
public function getNewUsers($start, $end)
|
||||
{
|
||||
$users = User::where('reg_date', '>=', date("Y-m-d H:i:s", $start))
|
||||
->where('reg_date', '<', date("Y-m-d H:i:s", $end))
|
||||
->count();
|
||||
if ($users == null) {
|
||||
$users = 0;
|
||||
}
|
||||
return $users;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,554 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
class Auth
|
||||
{
|
||||
|
||||
protected $user;
|
||||
|
||||
private static function getDriver()
|
||||
{
|
||||
return Factory::createAuth();
|
||||
}
|
||||
|
||||
public static function login($uid, $time)
|
||||
{
|
||||
self::getDriver()->login($uid, $time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current user(cached)
|
||||
*
|
||||
* @return \App\Models\User
|
||||
*/
|
||||
public static function getUser()
|
||||
{
|
||||
global $user;
|
||||
if ($user === null) {
|
||||
$user = self::getDriver()->getUser();
|
||||
}
|
||||
return $user;
|
||||
}
|
||||
|
||||
public static function logout()
|
||||
{
|
||||
self::getDriver()->logout();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Auth;
|
||||
|
||||
abstract class Base
|
||||
{
|
||||
abstract public function login($uid, $time);
|
||||
|
||||
abstract public function logout();
|
||||
|
||||
abstract public function getUser();
|
||||
}
|
||||
@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Auth;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Models\Node;
|
||||
use App\Utils;
|
||||
use App\Utils\Hash;
|
||||
use App\Services\Config;
|
||||
|
||||
class Cookie extends Base
|
||||
{
|
||||
public function login($uid, $time)
|
||||
{
|
||||
$user = User::find($uid);
|
||||
$expire_in = $time + time();
|
||||
$key = Hash::cookieHash($user->pass, $expire_in);
|
||||
Utils\Cookie::set([
|
||||
'uid' => $uid,
|
||||
'email' => $user->email,
|
||||
'key' => $key,
|
||||
'ip' => md5($_SERVER['REMOTE_ADDR'] . Config::get('key') . $uid . $expire_in),
|
||||
'expire_in' => $expire_in
|
||||
], $expire_in);
|
||||
}
|
||||
|
||||
public function getUser()
|
||||
{
|
||||
$uid = Utils\Cookie::get('uid');
|
||||
$email = Utils\Cookie::get('email');
|
||||
$key = Utils\Cookie::get('key');
|
||||
$ipHash = Utils\Cookie::get('ip');
|
||||
$expire_in = Utils\Cookie::get('expire_in');
|
||||
|
||||
$user = new User();
|
||||
$user->isLogin = false;
|
||||
|
||||
if ($uid == null) {
|
||||
return $user;
|
||||
}
|
||||
|
||||
if ($expire_in < time()) {
|
||||
return $user;
|
||||
}
|
||||
|
||||
if (Config::get('enable_login_bind_ip') == true) {
|
||||
$nodes = Node::where('node_ip', '=', $_SERVER['REMOTE_ADDR'])->first();
|
||||
if (($nodes == null) && $ipHash != md5($_SERVER['REMOTE_ADDR'] . Config::get('key') . $uid . $expire_in)) {
|
||||
return $user;
|
||||
}
|
||||
}
|
||||
|
||||
$user = User::find($uid);
|
||||
if ($user == null) {
|
||||
$user = new User();
|
||||
$user->isLogin = false;
|
||||
return $user;
|
||||
}
|
||||
|
||||
if ($user->email != $email) {
|
||||
$user = new User();
|
||||
$user->isLogin = false;
|
||||
}
|
||||
|
||||
|
||||
if (Hash::cookieHash($user->pass, $expire_in) != $key) {
|
||||
$user = new User();
|
||||
$user->isLogin = false;
|
||||
return $user;
|
||||
}
|
||||
|
||||
|
||||
$user->isLogin = true;
|
||||
return $user;
|
||||
}
|
||||
|
||||
public function logout()
|
||||
{
|
||||
$time = time() - 1000;
|
||||
Utils\Cookie::set([
|
||||
'uid' => null,
|
||||
'email' => null,
|
||||
'key' => null
|
||||
], $time);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Auth;
|
||||
|
||||
use App\Utils;
|
||||
use App\Services\Jwt;
|
||||
|
||||
class JwtToken extends Base
|
||||
{
|
||||
public function login($uid, $time)
|
||||
{
|
||||
$expireTime = time() + $time;
|
||||
$ary = [
|
||||
'uid' => $uid,
|
||||
'expire_time' => $expireTime
|
||||
];
|
||||
$decode = Jwt::encode($ary);
|
||||
Utils\Cookie::set([
|
||||
//"uid" => $uid,
|
||||
'token' => $decode
|
||||
], $expireTime);
|
||||
}
|
||||
|
||||
public function logout()
|
||||
{
|
||||
Utils\Cookie::set([
|
||||
//"uid" => $uid,
|
||||
'token' => ''
|
||||
], time() - 3600);
|
||||
}
|
||||
|
||||
public function getUser()
|
||||
{
|
||||
$token = Utils\Cookie::get('token');
|
||||
$tokenInfo = Jwt::decodeArray($token);
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue