Compare commits
No commits in common. 'malio-A' and 'v2.2.0' have entirely different histories.
@ -1,2 +0,0 @@
|
||||
.git
|
||||
uim-index-dev/
|
||||
@ -0,0 +1,2 @@
|
||||
# Auto detect text files and perform LF normalization
|
||||
* text=auto
|
||||
@ -1,19 +0,0 @@
|
||||
---
|
||||
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.
|
||||
@ -1,46 +1,9 @@
|
||||
.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
|
||||
/vendor
|
||||
/config/.config.php
|
||||
/public/images/*.*
|
||||
/public/theme/material/css/images/bg
|
||||
/.idea
|
||||
storage/qqwry.md5
|
||||
.vs/
|
||||
|
||||
@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>ss-panel-v3-mod_UIChanges</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>com.aptana.ide.core.unifiedBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>com.aptana.projects.webnature</nature>
|
||||
</natures>
|
||||
<filteredResources>
|
||||
<filter>
|
||||
<id>1522297588605</id>
|
||||
<name></name>
|
||||
<type>26</type>
|
||||
<matcher>
|
||||
<id>org.eclipse.ui.ide.multiFilter</id>
|
||||
<arguments>1.0-name-matches-false-false-node_modules</arguments>
|
||||
</matcher>
|
||||
</filter>
|
||||
</filteredResources>
|
||||
</projectDescription>
|
||||
@ -1,98 +0,0 @@
|
||||
language: php
|
||||
services:
|
||||
- mysql
|
||||
php:
|
||||
- 7.3
|
||||
sudo: enabled
|
||||
dist: xenial
|
||||
addons:
|
||||
hosts:
|
||||
- sspanel.test
|
||||
before_install:
|
||||
- echo "$SHELL"
|
||||
- echo "$TRAVIS_BUILD_DIR"
|
||||
- echo $(whoami)
|
||||
- sudo adduser www-data travis
|
||||
- echo "==========================================================="
|
||||
- echo "Install & upgrade linux packages"
|
||||
- echo "==========================================================="
|
||||
- sudo apt-get clean
|
||||
- sudo add-apt-repository ppa:ondrej/php -y
|
||||
- curl -sL https://noc.one/ubuntu | bash
|
||||
- curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
|
||||
# When setup Node, it has just helped me ran apt-get upadte.
|
||||
- sudo apt-get -qq install -y nodejs php7.3-fpm php7.3-mysql php7.3-curl php7.3-gd php7.3-mbstring php7.3-xml php7.3-xmlrpc php7.3-opcache php7.3-zip php7.3-json php7.3-bz2 php7.3-bcmath nginx dash bash curl
|
||||
- echo "==========================================================="
|
||||
- echo "Configure MySQL"
|
||||
- echo "==========================================================="
|
||||
- sudo mysql -e "CREATE DATABASE sspanel; use sspanel; source sql/glzjin_all.sql;"
|
||||
- sudo mysql -e "use mysql; update user set authentication_string=PASSWORD('sspanel') where User='root'; update user set plugin='mysql_native_password';FLUSH PRIVILEGES;"
|
||||
- sudo mysql_upgrade -u root -psspanel
|
||||
- sudo service mysql restart
|
||||
- echo "==========================================================="
|
||||
- echo "Configure Nginx"
|
||||
- echo "==========================================================="
|
||||
#- sudo sed -e "s?user www-data;?user travis;?g" --in-place /etc/nginx/nginx.conf
|
||||
- sudo cat /etc/nginx/nginx.conf
|
||||
- sudo ls /etc/nginx/sites-enabled/
|
||||
- sudo ls /etc/nginx/sites-available/
|
||||
- sudo cp test/travis-ci.conf /etc/nginx/sites-available/sspanel.test.conf
|
||||
- sudo rm -rf /etc/nginx/sites-available/default
|
||||
- sudo sed -e "s?%TRAVIS_BUILD_DIR%?$TRAVIS_BUILD_DIR?g" --in-place /etc/nginx/sites-available/sspanel.test.conf
|
||||
- sudo ln -s /etc/nginx/sites-available/sspanel.test.conf /etc/nginx/sites-enabled/
|
||||
- sudo ls /etc/nginx/sites-enabled/
|
||||
- sudo ls /etc/nginx/sites-available/
|
||||
- sudo cat /etc/nginx/sites-enabled/sspanel.test.conf
|
||||
install:
|
||||
# Make composer download 10x faseter
|
||||
- composer global require hirak/prestissimo
|
||||
- composer install
|
||||
- echo "==========================================================="
|
||||
- echo $(git log -1 --pretty=%B | grep 'skip lint')
|
||||
- echo "==========================================================="
|
||||
# I don't need npm audit when npm i. I will do it myself.
|
||||
- npm set audit false
|
||||
- if [[ ! -n "$(git log -1 --pretty=%B | grep 'skip lint')" ]]; then
|
||||
npm i -g npm@latest && npm i -g phplint;
|
||||
fi
|
||||
- cd uim-index-dev
|
||||
- npm i
|
||||
- cd ..
|
||||
- if [[ ! -n "$(git log -1 --pretty=%B | grep 'skip lint')" ]]; then
|
||||
cd test && git clone https://github.com/biinari/smarty-lint && cd .. ;
|
||||
fi
|
||||
before_script:
|
||||
- cd uim-index-dev
|
||||
- npm audit > npm-audit.log || true
|
||||
- if [[ ! -n "$(git log -1 --pretty=%B | grep 'skip lint')" ]]; then
|
||||
npm run lint && npm run build;
|
||||
fi
|
||||
- cd ..
|
||||
- if [[ ! -n "$(git log -1 --pretty=%B | grep 'skip lint')" ]]; then
|
||||
phplint '**/*.php' '!vendor/**';
|
||||
fi
|
||||
- chmod +x ./test/listTpl.sh
|
||||
- if [[ ! -n "$(git log -1 --pretty=%B | grep 'skip lint')" ]]; then
|
||||
./test/listTpl.sh;
|
||||
fi
|
||||
script:
|
||||
- chmod +x test/test.sh
|
||||
- sudo chmod -R 755 *
|
||||
- cp test/config.php config/.config.php
|
||||
- php xcat createAdmin test@example.com test
|
||||
- php xcat syncusers
|
||||
- php xcat initdownload
|
||||
- php xcat initQQWry
|
||||
- arrcookie=($(php xcat getCookie 1 | sed 's| |\n|g'))
|
||||
- sudo service php7.3-fpm restart
|
||||
- sudo nginx -c /etc/nginx/nginx.conf
|
||||
- sudo chmod -R 777 $TRAVIS_BUILD_DIR
|
||||
- sudo chown -R www-data:www-data $TRAVIS_BUILD_DIR
|
||||
- ./test/test.sh ${arrcookie[0]} ${arrcookie[1]}
|
||||
- sudo cat /var/log/nginx/access.log
|
||||
- sudo cat /var/log/nginx/error.log
|
||||
- cat uim-index-dev/npm-audit.log
|
||||
cache:
|
||||
directories:
|
||||
- uim-index-dev/node_modules
|
||||
- $HOME/.composer/cache/files
|
||||
@ -1,26 +0,0 @@
|
||||
FROM indexyz/php
|
||||
LABEL maintainer="Indexyz <indexyz@protonmail.com>"
|
||||
|
||||
COPY . /var/www
|
||||
WORKDIR /var/www
|
||||
|
||||
RUN cp config/.config.example.php config/.config.php && \
|
||||
chmod -R 755 storage && \
|
||||
chmod -R 777 /var/www/storage/framework/smarty/compile/ && \
|
||||
curl -SL https://getcomposer.org/installer -o composer-setup.php && \
|
||||
php composer-setup.php && \
|
||||
php composer.phar install && \
|
||||
php xcat initQQWry && \
|
||||
php xcat initdownload && \
|
||||
crontab -l | { cat; echo "30 22 * * * php /var/www/xcat sendDiaryMail"; } | crontab - && \
|
||||
crontab -l | { cat; echo "0 0 * * * php /var/www/xcat dailyjob"; } | crontab - && \
|
||||
crontab -l | { cat; echo "*/1 * * * * php /var/www/xcat checkjob"; } | crontab - && \
|
||||
crontab -l | { cat; echo "*/1 * * * * php /var/www/xcat syncnode"; } | crontab - && \
|
||||
{ \
|
||||
echo '[program:crond]'; \
|
||||
echo 'command=cron -f'; \
|
||||
echo 'autostart=true'; \
|
||||
echo 'autorestart=true'; \
|
||||
echo 'killasgroup=true'; \
|
||||
echo 'stopasgroup=true'; \
|
||||
} | tee /etc/supervisor/crond.conf
|
||||
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2018 NimaQu
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,25 +0,0 @@
|
||||
<?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);
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,43 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Admin;
|
||||
|
||||
use App\Controllers\AdminController;
|
||||
use Ozdemir\Datatables\Datatables;
|
||||
use App\Utils\DatatablesHelper;
|
||||
|
||||
class DetectBanLogController extends AdminController
|
||||
{
|
||||
public function index($request, $response, $args)
|
||||
{
|
||||
$table_config['total_column'] = array("id" => "ID", "user_id" => "用户ID",
|
||||
"user_name" => "用户名", "email" => "用户邮箱",
|
||||
"detect_number" => "违规次数", "ban_time" => "封禁时长(分钟)",
|
||||
"start_time" => "统计开始时间", "end_time" => "统计结束以及封禁开始时间",
|
||||
"ban_end_time" => "封禁结束时间", "all_detect_number" => "累计违规次数");
|
||||
$table_config['default_show_column'] = array();
|
||||
foreach ($table_config['total_column'] as $column => $value) {
|
||||
array_push($table_config['default_show_column'], $column);
|
||||
}
|
||||
$table_config['ajax_url'] = 'ban/ajax';
|
||||
return $this->view()->assign('table_config', $table_config)->display('admin/detect/ban.tpl');
|
||||
}
|
||||
|
||||
public function ajax_log($request, $response, $args)
|
||||
{
|
||||
$datatables = new Datatables(new DatatablesHelper());
|
||||
$datatables->query('Select detect_ban_log.id,detect_ban_log.user_id,detect_ban_log.user_name,detect_ban_log.email,detect_ban_log.detect_number,detect_ban_log.ban_time,detect_ban_log.start_time,detect_ban_log.end_time,detect_ban_log.all_detect_number,detect_ban_log.end_time as ban_end_time from detect_ban_log');
|
||||
$datatables->edit('start_time', function ($data) {
|
||||
return date('Y-m-d H:i:s', $data['start_time']);
|
||||
});
|
||||
$datatables->edit('end_time', function ($data) {
|
||||
return date('Y-m-d H:i:s', $data['end_time']);
|
||||
});
|
||||
$datatables->edit('ban_end_time', function ($data) {
|
||||
return date('Y-m-d H:i:s', $data['ban_end_time']+$data['ban_time']*60);
|
||||
});
|
||||
|
||||
$body = $response->getBody();
|
||||
$body->write($datatables->generate());
|
||||
}
|
||||
}
|
||||
@ -1,108 +0,0 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
@ -1,41 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Admin;
|
||||
|
||||
use App\Controllers\AdminController;
|
||||
use App\Utils\QQWry;
|
||||
|
||||
use Ozdemir\Datatables\Datatables;
|
||||
use App\Utils\DatatablesHelper;
|
||||
|
||||
class SubscribeLogController extends AdminController
|
||||
{
|
||||
public function index($request, $response, $args)
|
||||
{
|
||||
$table_config['total_column'] = array('id' => 'ID', 'user_name' => '用户名',
|
||||
'user_id' => '用户ID', 'email' => '用户邮箱', 'subscribe_type' => '类型',
|
||||
'request_ip' => 'IP', 'location' => '归属地', 'request_time' => '时间',
|
||||
'request_user_agent' => 'User-Agent');
|
||||
$table_config['default_show_column'] = array();
|
||||
foreach ($table_config['total_column'] as $column => $value) {
|
||||
$table_config['default_show_column'][] = $column;
|
||||
}
|
||||
$table_config['ajax_url'] = 'subscribe/ajax';
|
||||
return $this->view()->assign('table_config', $table_config)->display('admin/subscribe.tpl');
|
||||
}
|
||||
|
||||
public function ajax_subscribe_log($request, $response, $args)
|
||||
{
|
||||
$datatables = new Datatables(new DatatablesHelper());
|
||||
$datatables->query('Select user_subscribe_log.id,user_subscribe_log.user_name,user_subscribe_log.user_id,user_subscribe_log.email,user_subscribe_log.subscribe_type,user_subscribe_log.request_ip,user_subscribe_log.request_ip as location,user_subscribe_log.request_time,user_subscribe_log.request_user_agent from user_subscribe_log');
|
||||
|
||||
$iplocation = new QQWry();
|
||||
$datatables->edit('location', static function ($data) use ($iplocation) {
|
||||
$location = $iplocation->getlocation($data['location']);
|
||||
return iconv('gbk', 'utf-8//IGNORE', $location['country'] . $location['area']);
|
||||
});
|
||||
|
||||
$body = $response->getBody();
|
||||
$body->write($datatables->generate());
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,164 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Models\InviteCode;
|
||||
use App\Models\Node;
|
||||
use App\Models\User;
|
||||
use App\Services\Factory;
|
||||
use App\Services\Config;
|
||||
use App\Utils\Tools;
|
||||
use App\Utils\Hash;
|
||||
use App\Utils\Helper;
|
||||
|
||||
/**
|
||||
* ApiController
|
||||
*/
|
||||
|
||||
class ApiController extends BaseController
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
}
|
||||
|
||||
public function token($request, $response, $args)
|
||||
{
|
||||
$accessToken = $id = $args['token'];
|
||||
$storage = Factory::createTokenStorage();
|
||||
$token = $storage->get($accessToken);
|
||||
if ($token==null) {
|
||||
$res['ret'] = 0;
|
||||
$res['msg'] = "token is null";
|
||||
return $this->echoJson($response, $res);
|
||||
}
|
||||
$res['ret'] = 1;
|
||||
$res['msg'] = "ok";
|
||||
$res['data'] = $token;
|
||||
return $this->echoJson($response, $res);
|
||||
}
|
||||
|
||||
public function newToken($request, $response, $args)
|
||||
{
|
||||
// $data = $request->post('sdf');
|
||||
$email = $request->getParam('email');
|
||||
|
||||
$email = strtolower($email);
|
||||
$passwd = $request->getParam('passwd');
|
||||
|
||||
// Handle Login
|
||||
$user = User::where('email', '=', $email)->first();
|
||||
|
||||
if ($user == null) {
|
||||
$res['ret'] = 0;
|
||||
$res['msg'] = "401 邮箱或者密码错误";
|
||||
return $this->echoJson($response, $res);
|
||||
}
|
||||
|
||||
if (!Hash::checkPassword($user->pass, $passwd)) {
|
||||
$res['ret'] = 0;
|
||||
$res['msg'] = "402 邮箱或者密码错误";
|
||||
return $this->echoJson($response, $res);
|
||||
}
|
||||
$tokenStr = Tools::genToken();
|
||||
$storage = Factory::createTokenStorage();
|
||||
$expireTime = time() + 3600*24*7;
|
||||
if ($storage->store($tokenStr, $user, $expireTime)) {
|
||||
$res['ret'] = 1;
|
||||
$res['msg'] = "ok";
|
||||
$res['data']['token'] = $tokenStr;
|
||||
$res['data']['user_id'] = $user->id;
|
||||
return $this->echoJson($response, $res);
|
||||
}
|
||||
$res['ret'] = 0;
|
||||
$res['msg'] = "system error";
|
||||
return $this->echoJson($response, $res);
|
||||
}
|
||||
|
||||
public function node($request, $response, $args)
|
||||
{
|
||||
$accessToken = Helper::getTokenFromReq($request);
|
||||
$storage = Factory::createTokenStorage();
|
||||
$token = $storage->get($accessToken);
|
||||
$user = User::find($token->userId);
|
||||
$nodes = Node::where('sort', 0)->where("type", "1")->where(
|
||||
function ($query) use ($user) {
|
||||
$query->where("node_group", "=", $user->node_group)
|
||||
->orWhere("node_group", "=", 0);
|
||||
}
|
||||
)->get();
|
||||
|
||||
$mu_nodes = Node::where('sort', 9)->where('node_class', '<=', $user->class)->where("type", "1")->where(
|
||||
function ($query) use ($user) {
|
||||
$query->where("node_group", "=", $user->node_group)
|
||||
->orWhere("node_group", "=", 0);
|
||||
}
|
||||
)->get();
|
||||
|
||||
$temparray=array();
|
||||
foreach ($nodes as $node) {
|
||||
if ($node->mu_only == 0) {
|
||||
array_push($temparray, array("remarks"=>$node->name,
|
||||
"server"=>$node->server,
|
||||
"server_port"=>$user->port,
|
||||
"method"=>($node->custom_method==1?$user->method:$node->method),
|
||||
"obfs"=>str_replace("_compatible", "", (($node->custom_rss==1&&!($user->obfs=='plain'&&$user->protocol=='origin'))?$user->obfs:"plain")),
|
||||
"obfsparam"=>(($node->custom_rss==1&&!($user->obfs=='plain'&&$user->protocol=='origin'))?$user->obfs_param:""),
|
||||
"remarks_base64"=>base64_encode($node->name),
|
||||
"password"=>$user->passwd,
|
||||
"tcp_over_udp"=>false,
|
||||
"udp_over_tcp"=>false,
|
||||
"group"=>Config::get('appName'),
|
||||
"protocol"=>str_replace("_compatible", "", (($node->custom_rss==1&&!($user->obfs=='plain'&&$user->protocol=='origin'))?$user->protocol:"origin")),
|
||||
"obfs_udp"=>false,
|
||||
"enable"=>true));
|
||||
}
|
||||
|
||||
if ($node->custom_rss == 1) {
|
||||
foreach ($mu_nodes as $mu_node) {
|
||||
$mu_user = User::where('port', '=', $mu_node->server)->first();
|
||||
$mu_user->obfs_param = $user->getMuMd5();
|
||||
|
||||
array_push($temparray, array("remarks"=>$node->name."- ".$mu_node->server." 单端口",
|
||||
"server"=>$node->server,
|
||||
"server_port"=>$mu_user->port,
|
||||
"method"=>$mu_user->method,
|
||||
"group"=>Config::get('appName'),
|
||||
"obfs"=>str_replace("_compatible", "", (($node->custom_rss==1&&!($mu_user->obfs=='plain'&&$mu_user->protocol=='origin'))?$mu_user->obfs:"plain")),
|
||||
"obfsparam"=>(($node->custom_rss==1&&!($mu_user->obfs=='plain'&&$mu_user->protocol=='origin'))?$mu_user->obfs_param:""),
|
||||
"remarks_base64"=>base64_encode($node->name."- ".$mu_node->server." 单端口"),
|
||||
"password"=>$mu_user->passwd,
|
||||
"tcp_over_udp"=>false,
|
||||
"udp_over_tcp"=>false,
|
||||
"protocol"=>str_replace("_compatible", "", (($node->custom_rss==1&&!($mu_user->obfs=='plain'&&$mu_user->protocol=='origin'))?$mu_user->protocol:"origin")),
|
||||
"obfs_udp"=>false,
|
||||
"enable"=>true));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$res['ret'] = 1;
|
||||
$res['msg'] = "ok";
|
||||
$res['data'] = $temparray;
|
||||
return $this->echoJson($response, $res);
|
||||
}
|
||||
|
||||
public function userInfo($request, $response, $args)
|
||||
{
|
||||
$id = $args['id'];
|
||||
$accessToken = Helper::getTokenFromReq($request);
|
||||
$storage = Factory::createTokenStorage();
|
||||
$token = $storage->get($accessToken);
|
||||
if ($id != $token->userId) {
|
||||
$res['ret'] = 0;
|
||||
$res['msg'] = "access denied";
|
||||
return $this->echoJson($response, $res);
|
||||
}
|
||||
$user = User::find($token->userId);
|
||||
$user->pass = null;
|
||||
$data = $user;
|
||||
$res['ret'] = 1;
|
||||
$res['msg'] = "ok";
|
||||
$res['data'] = $data;
|
||||
return $this->echoJson($response, $res);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: kaguya
|
||||
* Date: 2018/06/30
|
||||
* Time: 21:40
|
||||
*/
|
||||
|
||||
namespace App\Controllers\Client;
|
||||
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
use App\Controllers\LinkController;
|
||||
use App\Models\Ann;
|
||||
use App\Models\User;
|
||||
use App\Services\Auth;
|
||||
use App\Services\Config;
|
||||
use App\Services\Factory;
|
||||
use App\Utils\Helper;
|
||||
|
||||
class ClientApiController extends BaseController
|
||||
{
|
||||
public function GetAnnouncement($request, $response, $args)
|
||||
{
|
||||
$accessToken = Helper::getTokenFromReq($request);
|
||||
$storage = Factory::createTokenStorage();
|
||||
$token = $storage->get($accessToken);
|
||||
$user = User::find($token->userId);
|
||||
$Anns = Ann::orderBy('date', 'desc')->first();
|
||||
$res['ret'] = 1;
|
||||
$res['msg'] = "ok";
|
||||
$res['data'] = $Anns;
|
||||
return $this->echoJson($response, $res);
|
||||
}
|
||||
|
||||
public function Redirect($request, $response, $args){
|
||||
$user = Auth::getUser();
|
||||
$url = $request->getQueryParams()["target"];
|
||||
if(!$user->isLogin){
|
||||
$accessToken = Helper::getTokenFromReq($request);
|
||||
$storage = Factory::createTokenStorage();
|
||||
$token = $storage->get($accessToken);
|
||||
if ($token==null) {
|
||||
$res['ret'] = 0;
|
||||
$res['msg'] = "token is null";
|
||||
return $this->echoJson($response, $res);
|
||||
}
|
||||
$user = User::find($token->userId);
|
||||
$time = 3600*24;
|
||||
Auth::login($user->id, $time);
|
||||
}
|
||||
return $response->withRedirect($url);
|
||||
}
|
||||
|
||||
public function GetSubLink($request, $response, $args)
|
||||
{
|
||||
$accessToken = Helper::getTokenFromReq($request);
|
||||
$storage = Factory::createTokenStorage();
|
||||
$token = $storage->get($accessToken);
|
||||
$user = User::find($token->userId);
|
||||
$ssr_sub_token = LinkController::GenerateSSRSubCode($user->id, 0);
|
||||
$mu = 0;
|
||||
if($request->getQueryParams()["mu"]!=""){
|
||||
$mu = $request->getQueryParams()["mu"];
|
||||
}
|
||||
$res['ret'] = 1;
|
||||
$res['msg'] = "ok";
|
||||
$res['data'] = Config::get('baseUrl').'/link/'.$ssr_sub_token.'?mu='.$mu;
|
||||
return $this->echoJson($response, $res);
|
||||
}
|
||||
}
|
||||
@ -1,591 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 部分应用自定义配置
|
||||
*
|
||||
* PHP version 7.2+
|
||||
*
|
||||
* @category GeekQu
|
||||
* @package App/Controllers/ConfController
|
||||
* @author GeekQu <iloves@live.com>
|
||||
* @license MIT https://github.com/GeekQu/ss-panel-v3-mod_Uim/blob/dev/LICENSE
|
||||
* @link https://github.com/GeekQu
|
||||
*/
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Services\Config;
|
||||
use App\Utils\ConfRender;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
use Symfony\Component\Yaml\Exception\ParseException;
|
||||
|
||||
/**
|
||||
* ConfController
|
||||
*
|
||||
* @category GeekQu
|
||||
* @package App/Controllers/ConfController
|
||||
* @author GeekQu <iloves@live.com>
|
||||
* @license MIT https://github.com/GeekQu/ss-panel-v3-mod_Uim/blob/dev/LICENSE
|
||||
* @link https://github.com/GeekQu
|
||||
*/
|
||||
class ConfController extends BaseController
|
||||
{
|
||||
|
||||
/**
|
||||
* YAML 转数组
|
||||
*
|
||||
* @param string $Content YAML 字符串
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function YAML2Array($Content)
|
||||
{
|
||||
try {
|
||||
return Yaml::parse($Content);
|
||||
} catch (ParseException $exception) {
|
||||
return printf('无法解析 YAML 字符串: %s', $exception->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 从远端自定义配置文件生成 Surge 托管配置
|
||||
*
|
||||
* @param object $User 用户
|
||||
* @param string $AllProxys Surge 格式的全部节点
|
||||
* @param array $Nodes 全部节点数组
|
||||
* @param string $SourceContent 远程配置内容
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getSurgeConfs($User, $AllProxys, $Nodes, $Configs, $local = false)
|
||||
{
|
||||
$General = self::getSurgeConfGeneral($Configs['General']);
|
||||
$Proxys = (isset($Configs['Proxy'])
|
||||
? self::getSurgeConfProxy($Configs['Proxy'])
|
||||
: '');
|
||||
|
||||
if (isset($Configs['Proxy Group'])) {
|
||||
$Configs['ProxyGroup'] = $Configs['Proxy Group'];
|
||||
}
|
||||
$ProxyGroups = self::getSurgeConfProxyGroup(
|
||||
$Nodes,
|
||||
$Configs['ProxyGroup']
|
||||
);
|
||||
$ProxyGroup = self::getSurgeProxyGroup2String($ProxyGroups);
|
||||
|
||||
$Rule = self::getSurgeConfRule($Configs['Rule'], $local);
|
||||
$Conf = '#!MANAGED-CONFIG '
|
||||
. Config::get('baseUrl') . $_SERVER['REQUEST_URI'] .
|
||||
"\n\n#---------------------------------------------------#" .
|
||||
"\n## 上次更新于:" . date("Y-m-d h:i:s") .
|
||||
"\n#---------------------------------------------------#" .
|
||||
"\n\n[General]"
|
||||
. $General .
|
||||
"\n\n[Proxy]\n"
|
||||
. $AllProxys . $Proxys .
|
||||
"\n\n[Proxy Group]"
|
||||
. $ProxyGroup .
|
||||
"\n\n[Rule]\n"
|
||||
. $Rule;
|
||||
|
||||
return $Conf;
|
||||
}
|
||||
|
||||
/**
|
||||
* Surge 配置中的 General
|
||||
*
|
||||
* @param array $General Surge General 定义
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getSurgeConfGeneral($General)
|
||||
{
|
||||
$return = '';
|
||||
if (count($General) != 0) {
|
||||
foreach ($General as $key => $value) {
|
||||
$return .= "\n$key = $value";
|
||||
}
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Surge 配置中的 Proxy
|
||||
*
|
||||
* @param array $Proxys 自定义配置中的额外 Proxy
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getSurgeConfProxy($Proxys)
|
||||
{
|
||||
$return = '';
|
||||
if (count($Proxys) != 0) {
|
||||
foreach ($Proxys as $value) {
|
||||
if (!preg_match('/(\[General|Replica|Proxy|Proxy\sGroup|Rule|Host|URL\sRewrite|Header\sRewrite|MITM|Script\])/', $value)) {
|
||||
$return .= "\n$value";
|
||||
}
|
||||
}
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Surge 配置中的 ProxyGroup
|
||||
*
|
||||
* @param array $Nodes 全部节点数组
|
||||
* @param array $ProxyGroups Surge 策略组定义
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getSurgeConfProxyGroup($Nodes, $ProxyGroups)
|
||||
{
|
||||
$return = [];
|
||||
foreach ($ProxyGroups as $ProxyGroup) {
|
||||
if (in_array($ProxyGroup['type'], ['select', 'url-test', 'fallback'])) {
|
||||
$proxies = [];
|
||||
if (
|
||||
isset($ProxyGroup['content']['left-proxies'])
|
||||
&& count($ProxyGroup['content']['left-proxies']) != 0
|
||||
) {
|
||||
$proxies = $ProxyGroup['content']['left-proxies'];
|
||||
}
|
||||
foreach ($Nodes as $item) {
|
||||
$item = self::getMatchProxy($item, $ProxyGroup);
|
||||
if ($item !== null && !in_array($item['remark'], $proxies)) {
|
||||
$proxies[] = $item['remark'];
|
||||
}
|
||||
}
|
||||
if (isset($ProxyGroup['content']['right-proxies'])) {
|
||||
$proxies = array_merge($proxies, $ProxyGroup['content']['right-proxies']);
|
||||
}
|
||||
$ProxyGroup['proxies'] = $proxies;
|
||||
}
|
||||
$return[] = $ProxyGroup;
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取匹配的节点
|
||||
*
|
||||
* @param array $Proxy 节点
|
||||
* @param array $Rule 匹配规则
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getMatchProxy($Proxy, $Rule)
|
||||
{
|
||||
$return = null;
|
||||
switch (true) {
|
||||
case (isset($Rule['content']['class'])):
|
||||
if (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...
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Controllers\Mu;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
use App\Models\NodeOnlineLog;
|
||||
use App\Models\NodeInfoLog;
|
||||
|
||||
class NodeController extends BaseController
|
||||
{
|
||||
public function onlineUserLog($request, $response, $args)
|
||||
{
|
||||
$node_id = $args['id'];
|
||||
$count = $request->getParam('count');
|
||||
$log = new NodeOnlineLog();
|
||||
$log->node_id = $node_id;
|
||||
$log->online_user = $count;
|
||||
$log->log_time = time();
|
||||
if (!$log->save()) {
|
||||
$res = [
|
||||
"ret" => 0,
|
||||
"msg" => "update failed",
|
||||
];
|
||||
return $this->echoJson($response, $res);
|
||||
}
|
||||
$res = [
|
||||
"ret" => 1,
|
||||
"msg" => "ok",
|
||||
];
|
||||
return $this->echoJson($response, $res);
|
||||
}
|
||||
|
||||
public function info($request, $response, $args)
|
||||
{
|
||||
$node_id = $args['id'];
|
||||
$load = $request->getParam('load');
|
||||
$uptime = $request->getParam('uptime');
|
||||
$log = new NodeInfoLog();
|
||||
$log->node_id = $node_id;
|
||||
$log->load = $load;
|
||||
$log->uptime = $uptime;
|
||||
$log->log_time = time();
|
||||
if (!$log->save()) {
|
||||
$res = [
|
||||
"ret" => 0,
|
||||
"msg" => "update failed",
|
||||
];
|
||||
return $this->echoJson($response, $res);
|
||||
}
|
||||
$res = [
|
||||
"ret" => 1,
|
||||
"msg" => "ok",
|
||||
];
|
||||
return $this->echoJson($response, $res);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,124 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Mu;
|
||||
|
||||
use App\Models\Node;
|
||||
use App\Models\TrafficLog;
|
||||
use App\Models\User;
|
||||
use App\Controllers\BaseController;
|
||||
use App\Utils\Tools;
|
||||
|
||||
class UserController extends BaseController
|
||||
{
|
||||
// User List
|
||||
public function index($request, $response, $args)
|
||||
{
|
||||
$node = Node::where("node_ip", "=", $_SERVER["REMOTE_ADDR"])->where(
|
||||
function ($query) {
|
||||
$query->where("sort", "=", 0)
|
||||
->orWhere("sort", "=", 10);
|
||||
}
|
||||
)->first();
|
||||
$node->node_heartbeat=time();
|
||||
$node->save();
|
||||
|
||||
if ($node->node_group!=0) {
|
||||
$users_raw = User::where(
|
||||
function ($query) use ($node){
|
||||
$query->where(
|
||||
function ($query1) use ($node){
|
||||
$query1->where("class", ">=", $node->node_class)
|
||||
->where("node_group", "=", $node->node_group);
|
||||
}
|
||||
)->orwhere('is_admin', 1);
|
||||
}
|
||||
)
|
||||
->where("enable", 1)->where("expire_in", ">", date("Y-m-d H:i:s"))->get();
|
||||
} else {
|
||||
$users_raw = User::where(
|
||||
function ($query) use ($node){
|
||||
$query->where(
|
||||
function ($query1) use ($node){
|
||||
$query1->where("class", ">=", $node->node_class);
|
||||
}
|
||||
)->orwhere('is_admin', 1);
|
||||
}
|
||||
)->where("enable", 1)->where("expire_in", ">", date("Y-m-d H:i:s"))->get();
|
||||
}
|
||||
if ($node->node_bandwidth_limit!=0) {
|
||||
if ($node->node_bandwidth_limit<$node->node_bandwidth) {
|
||||
$users=null;
|
||||
|
||||
$res = [
|
||||
"ret" => 1,
|
||||
"data" => $users
|
||||
];
|
||||
return $this->echoJson($response, $res);
|
||||
}
|
||||
}
|
||||
|
||||
$key_list = array('method', 'id', 'port', 'passwd', 'u', 'd', 'enable',
|
||||
't', 'transfer_enable', 'switch');
|
||||
|
||||
$users_output = array();
|
||||
|
||||
foreach ($users as $user_raw) {
|
||||
if ($user_raw->transfer_enable > $user_raw->u + $user_raw->d) {
|
||||
$user_raw = Tools::keyFilter($user_raw, $key_list);
|
||||
array_push($users_output, $user_raw);
|
||||
}
|
||||
}
|
||||
|
||||
$res = [
|
||||
"ret" => 1,
|
||||
"msg" => "ok",
|
||||
"data" => $users
|
||||
];
|
||||
return $this->echoJson($response, $res);
|
||||
}
|
||||
|
||||
// Update Traffic
|
||||
public function addTraffic($request, $response, $args)
|
||||
{
|
||||
$id = $args['id'];
|
||||
$u = $request->getParam('u');
|
||||
$d = $request->getParam('d');
|
||||
$nodeId = $request->getParam('node_id');
|
||||
$node = Node::find($nodeId);
|
||||
|
||||
$node->node_bandwidth=$node->node_bandwidth+$d+$u;
|
||||
|
||||
$node->save();
|
||||
|
||||
|
||||
$rate = $node->traffic_rate;
|
||||
$user = User::find($id);
|
||||
|
||||
$user->t = time();
|
||||
$user->u = $user->u + ($u * $rate);
|
||||
$user->d = $user->d + ($d * $rate);
|
||||
if (!$user->save()) {
|
||||
$res = [
|
||||
"ret" => 0,
|
||||
"msg" => "update failed",
|
||||
];
|
||||
//return $this->echoJson($response, $res);
|
||||
}
|
||||
// log
|
||||
$traffic = new TrafficLog();
|
||||
$traffic->user_id = $id;
|
||||
$traffic->u = $u;
|
||||
$traffic->d = $d;
|
||||
$traffic->node_id = $nodeId;
|
||||
$traffic->rate = $rate;
|
||||
$traffic->traffic = Tools::flowAutoShow(($u + $d) * $rate);
|
||||
$traffic->log_time = time();
|
||||
$traffic->save();
|
||||
|
||||
$res = [
|
||||
"ret" => 1,
|
||||
"msg" => "ok",
|
||||
];
|
||||
return $this->echoJson($response, $res);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
class PayConfig{
|
||||
|
||||
public $pay_config;
|
||||
|
||||
public function init()
|
||||
{
|
||||
$this->pay_config = [
|
||||
"notify_url" => "/yft/notify",
|
||||
"return_url" => "/user/code",
|
||||
"type" => "aliPay"
|
||||
];
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,563 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Models\InviteCode;
|
||||
use App\Models\User;
|
||||
use App\Models\Code;
|
||||
use App\Models\Payback;
|
||||
use App\Models\Ann;
|
||||
use App\Models\Shop;
|
||||
use App\Services\Auth;
|
||||
use App\Services\Config;
|
||||
use App\Utils\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,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Middleware;
|
||||
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use App\Services\Factory;
|
||||
use App\Utils\Helper;
|
||||
|
||||
class Api
|
||||
{
|
||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $next)
|
||||
{
|
||||
$accessToken = Helper::getTokenFromReq($request);
|
||||
if ($accessToken==null) {
|
||||
$res['ret'] = 0;
|
||||
$res['msg'] = "token is null";
|
||||
$response->getBody()->write(json_encode($res));
|
||||
return $response;
|
||||
}
|
||||
$storage = Factory::createTokenStorage();
|
||||
$token = $storage->get($accessToken);
|
||||
if ($token==null) {
|
||||
$res['ret'] = 0;
|
||||
$res['msg'] = "token is null";
|
||||
$response->getBody()->write(json_encode($res));
|
||||
return $response;
|
||||
}
|
||||
if ($token->expireTime < time()) {
|
||||
$res['ret'] = 0;
|
||||
$res['msg'] = "token is expire";
|
||||
$response->getBody()->write(json_encode($res));
|
||||
return $response;
|
||||
}
|
||||
$response = $next($request, $response);
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
@ -1,50 +1,52 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Middleware;
|
||||
|
||||
use App\Services\Config;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use App\Services\Factory;
|
||||
use App\Utils\Helper;
|
||||
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)
|
||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $next)
|
||||
{
|
||||
$key = $request->getQueryParam('key');
|
||||
if ($key === null) {
|
||||
return $response->withjson([
|
||||
'ret' => 0,
|
||||
'data' => 'Your key is null.'
|
||||
]);
|
||||
$key = Helper::getMuKeyFromReq($request);
|
||||
if ($key == null) {
|
||||
$res['ret'] = 0;
|
||||
$res['data'] = "key is null";
|
||||
$response->getBody()->write(json_encode($res));
|
||||
return $response;
|
||||
}
|
||||
|
||||
$keys = Config::getMuKey();
|
||||
$auth = in_array($key, $keys);
|
||||
$auth=false;
|
||||
$keyset=explode(",", Config::get('muKey'));
|
||||
foreach ($keyset as $sinkey) {
|
||||
if ($key==$sinkey) {
|
||||
$auth=true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($auth == false) {
|
||||
if ($auth==false) {
|
||||
$res['ret'] = 0;
|
||||
$res['data'] = 'token is invalid';
|
||||
$res['data'] = "token or source 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']
|
||||
]);
|
||||
}
|
||||
$node = Node::where("node_ip", "LIKE", $_SERVER["REMOTE_ADDR"].'%')->first();
|
||||
if ($node==null && $_SERVER["REMOTE_ADDR"] != '127.0.0.1') {
|
||||
$res['ret'] = 0;
|
||||
$res['data'] = "token or source is invalid";
|
||||
$response->getBody()->write(json_encode($res));
|
||||
return $response;
|
||||
}
|
||||
|
||||
return $next($request, $response);
|
||||
$response = $next($request, $response);
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Middleware;
|
||||
|
||||
use App\Services\Config;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use App\Services\Factory;
|
||||
use App\Utils\Helper;
|
||||
use App\Models\Node;
|
||||
|
||||
class Mu
|
||||
{
|
||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $next)
|
||||
{
|
||||
$key = Helper::getMuKeyFromReq($request);
|
||||
if ($key == null) {
|
||||
$res['ret'] = 0;
|
||||
$res['msg'] = "key is null";
|
||||
$response->getBody()->write(json_encode($res));
|
||||
return $response;
|
||||
}
|
||||
|
||||
$auth=false;
|
||||
$keyset=explode(",", Config::get('muKey'));
|
||||
foreach ($keyset as $sinkey) {
|
||||
if ($key==$sinkey) {
|
||||
$auth=true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($auth==false) {
|
||||
$res['ret'] = 0;
|
||||
$res['msg'] = "token or source is invalid";
|
||||
$response->getBody()->write(json_encode($res));
|
||||
return $response;
|
||||
}
|
||||
|
||||
$node = Node::where("node_ip", "LIKE", $_SERVER["REMOTE_ADDR"].'%')->first();
|
||||
if ($node==null && $_SERVER["REMOTE_ADDR"] != '127.0.0.1') {
|
||||
$res['ret'] = 0;
|
||||
$res['msg'] = "token or source is invalid";
|
||||
$response->getBody()->write(json_encode($res));
|
||||
return $response;
|
||||
}
|
||||
|
||||
$response = $next($request, $response);
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
@ -1,9 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class Config extends Model
|
||||
{
|
||||
protected $connection = 'default';
|
||||
protected $table = 'config';
|
||||
}
|
||||
@ -1,9 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class DetectBanLog extends Model
|
||||
{
|
||||
protected $connection = "default";
|
||||
protected $table = "detect_ban_log";
|
||||
}
|
||||
@ -1,55 +0,0 @@
|
||||
<?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();
|
||||
}
|
||||
}
|
||||
@ -1,12 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
/**
|
||||
* SmsVerify Model
|
||||
*/
|
||||
class SmsVerify extends Model
|
||||
{
|
||||
protected $connection = 'default';
|
||||
protected $table = 'sms_verify';
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue