| Raw bytes | ");
}
}
diff --git a/app/Utils/Radius.php b/app/Utils/Radius.php
index 3c9d9cb5..677d0bcd 100644
--- a/app/Utils/Radius.php
+++ b/app/Utils/Radius.php
@@ -17,33 +17,33 @@ class Radius
*/
public static function Add($user, $pwd)
{
- if (Config::get('enable_radius')=='true') {
- $email=$user->email;
- $email=str_replace("@", "", $email);
- $email=str_replace(".", "", $email);
+ if (Config::get('enable_radius') == 'true') {
+ $email = $user->email;
+ $email = str_replace("@", "", $email);
+ $email = str_replace(".", "", $email);
- $exists=RadiusRadCheck::where("username", $email)->first();
+ $exists = RadiusRadCheck::where("username", $email)->first();
- if ($exists==null) {
+ if ($exists == null) {
$rb = RadiusBan::where('userid', $user->id)->first();
if ($rb != null) {
return;
}
- $newRad=new RadiusRadCheck();
- $newRad->username=$email;
- $newRad->attribute="Cleartext-Password";
- $newRad->op=":=";
- $newRad->value=$pwd;
+ $newRad = new RadiusRadCheck();
+ $newRad->username = $email;
+ $newRad->attribute = "Cleartext-Password";
+ $newRad->op = ":=";
+ $newRad->value = $pwd;
$newRad->save();
- $newRad=new RadiusRadUserGroup();
- $newRad->username=$email;
- $newRad->groupname="user";
- $newRad->priority="0";
+ $newRad = new RadiusRadUserGroup();
+ $newRad->username = $email;
+ $newRad->groupname = "user";
+ $newRad->priority = "0";
$newRad->save();
} else {
- $exists->value=$pwd;
+ $exists->value = $pwd;
$exists->save();
}
}
@@ -52,14 +52,14 @@ class Radius
public static function Delete($email)
{
- if (Config::get('enable_radius')=='true') {
- $email=str_replace("@", "", $email);
- $email=str_replace(".", "", $email);
+ if (Config::get('enable_radius') == 'true') {
+ $email = str_replace("@", "", $email);
+ $email = str_replace(".", "", $email);
- $exists=RadiusRadCheck::where("username", $email)->first();
+ $exists = RadiusRadCheck::where("username", $email)->first();
- if ($exists!=null) {
+ if ($exists != null) {
RadiusRadCheck::where("username", $email)->delete();
RadiusRadUserGroup::where("username", $email)->delete();
}
@@ -68,21 +68,21 @@ class Radius
public static function ChangeUserName($origin_email, $new_email, $passwd)
{
- if (Config::get('enable_radius')=='true') {
- $email1=str_replace("@", "", $origin_email);
- $email1=str_replace(".", "", $email1);
- $email2=str_replace("@", "", $new_email);
- $email2=str_replace(".", "", $email2);
+ if (Config::get('enable_radius') == 'true') {
+ $email1 = str_replace("@", "", $origin_email);
+ $email1 = str_replace(".", "", $email1);
+ $email2 = str_replace("@", "", $new_email);
+ $email2 = str_replace(".", "", $email2);
- $exists=RadiusRadCheck::where("username", $email1)->first();
+ $exists = RadiusRadCheck::where("username", $email1)->first();
- if ($exists!=null) {
- $exists->username=$email2;
- $exists->value=$passwd;
+ if ($exists != null) {
+ $exists->username = $email2;
+ $exists->value = $passwd;
$exists->save();
- $exists=RadiusRadUserGroup::where("username", $email1)->first();
- $exists->username=$email2;
+ $exists = RadiusRadUserGroup::where("username", $email1)->first();
+ $exists->username = $email2;
$exists->save();
} else {
$user = User::where('email', '=', $origin_email)->first();
@@ -91,17 +91,17 @@ class Radius
return;
}
- $newRad=new RadiusRadCheck();
- $newRad->username=$email2;
- $newRad->attribute="Cleartext-Password";
- $newRad->op=":=";
- $newRad->value=$passwd;
+ $newRad = new RadiusRadCheck();
+ $newRad->username = $email2;
+ $newRad->attribute = "Cleartext-Password";
+ $newRad->op = ":=";
+ $newRad->value = $passwd;
$newRad->save();
- $newRad=new RadiusRadUserGroup();
- $newRad->username=$email2;
- $newRad->groupname="user";
- $newRad->priority="0";
+ $newRad = new RadiusRadUserGroup();
+ $newRad->username = $email2;
+ $newRad->groupname = "user";
+ $newRad->priority = "0";
$newRad->save();
}
}
@@ -109,15 +109,15 @@ class Radius
public static function AddNas($ip, $name)
{
- if (Config::get('enable_radius')=='true') {
- $exists=RadiusNas::where("shortname", $ip)->first();
- if ($exists==null) {
- $exists=new RadiusNas();
- $exists->nasname=$ip;
- $exists->shortname=$ip;
- $exists->type="other";
- $exists->secret=Config::get('radius_secret');
- $exists->description=$ip;
+ if (Config::get('enable_radius') == 'true') {
+ $exists = RadiusNas::where("shortname", $ip)->first();
+ if ($exists == null) {
+ $exists = new RadiusNas();
+ $exists->nasname = $ip;
+ $exists->shortname = $ip;
+ $exists->type = "other";
+ $exists->secret = Config::get('radius_secret');
+ $exists->description = $ip;
$exists->save();
}
}
@@ -125,15 +125,15 @@ class Radius
public static function DelNas($ip)
{
- if (Config::get('enable_radius')=='true') {
+ if (Config::get('enable_radius') == 'true') {
RadiusNas::where("shortname", $ip)->delete();
}
}
public static function GetUserName($email)
{
- $emailt=str_replace("@", "", $email);
- $emailt=str_replace(".", "", $emailt);
+ $emailt = str_replace("@", "", $email);
+ $emailt = str_replace(".", "", $emailt);
return $emailt;
}
}
diff --git a/app/Utils/Telegram.php b/app/Utils/Telegram.php
index be62c64c..2bf83315 100644
--- a/app/Utils/Telegram.php
+++ b/app/Utils/Telegram.php
@@ -8,28 +8,28 @@ class Telegram
{
/**
- * ·¢ËÍÏûϢ
+ * ������Ϣ
*/
public static function Send($messageText)
{
if (Config::get('enable_telegram') == 'true') {
$bot = new \TelegramBot\Api\BotApi(Config::get('telegram_token'));
- try{
- $bot->sendMessage(Config::get('telegram_chatid'), $messageText);
- } catch (\Exception $e) {
+ try {
+ $bot->sendMessage(Config::get('telegram_chatid'), $messageText);
+ } catch (\Exception $e) {
echo $e->getMessage();
}
}
}
-
-
+
+
public static function SendMarkdown($messageText)
{
if (Config::get('enable_telegram') == 'true') {
$bot = new \TelegramBot\Api\BotApi(Config::get('telegram_token'));
- try{
- $bot->sendMessage(Config::get('telegram_chatid'), $messageText, "Markdown");
- } catch (\Exception $e) {
+ try {
+ $bot->sendMessage(Config::get('telegram_chatid'), $messageText, "Markdown");
+ } catch (\Exception $e) {
echo $e->getMessage();
}
}
diff --git a/app/Utils/TelegramProcess.php b/app/Utils/TelegramProcess.php
index 402c6a61..5f771535 100644
--- a/app/Utils/TelegramProcess.php
+++ b/app/Utils/TelegramProcess.php
@@ -9,103 +9,104 @@ use App\Controllers\LinkController;
class TelegramProcess
{
private static $all_rss = [
- "clean_link"=>"重置订阅",
- "?mu=0" => "SSR普通订阅" ,
+ "clean_link" => "重置订阅",
+ "?mu=0" => "SSR普通订阅",
"?mu=1" => "SSR单端口订阅",
- "?mu=3"=> "SS/SSD订阅",
+ "?mu=3" => "SS/SSD订阅",
"?mu=2" => "V2ray订阅",
- "?mu=4"=> "Clash订阅"];
+ "?mu=4" => "Clash订阅"];
- private static function callback_bind_method($bot,$message,$command)
- {
+ private static function callback_bind_method($bot, $message, $command)
+ {
$reply_to = $message->getMessageId();
$user = User::where('telegram_id', $message->getFrom()->getId())->first();
- $reply_message="???";
+ $reply_message = "???";
if ($user != null) {
- switch (true){
- case (strpos($command,"mu")):
+ switch (true) {
+ case (strpos($command, "mu")):
$ssr_sub_token = LinkController::GenerateSSRSubCode($user->id, 0);
$subUrl = Config::get('subUrl');
- $reply_message = self::$all_rss[$command].": ".$subUrl.$ssr_sub_token.$command.PHP_EOL;
+ $reply_message = self::$all_rss[$command] . ": " . $subUrl . $ssr_sub_token . $command . PHP_EOL;
break;
- case ($command=="clean_link"):
+ case ($command == "clean_link"):
$user->clean_link();
- $reply_message="链接重置成功";
+ $reply_message = "链接重置成功";
break;
}
$bot->sendMessage($message->getChat()->getId(), $reply_message, $parseMode = null, $disablePreview = false, $replyToMessageId = $reply_to);
}
-}
- private static function needbind_method($bot, $message, $command, $user, $reply_to=null)
+ }
+
+ private static function needbind_method($bot, $message, $command, $user, $reply_to = null)
{
- $reply = [
- "message" => "???",
- "markup" => null,
- ];
+ $reply = [
+ "message" => "???",
+ "markup" => null,
+ ];
if ($user != null) {
switch ($command) {
case 'traffic':
- $reply['message']="您当前的流量状况:
+ $reply['message'] = "您当前的流量状况:
今日已使用 " . $user->TodayusedTraffic() . " " . number_format(($user->u + $user->d - $user->last_day_t) / $user->transfer_enable * 100, 2) . "%
今日之前已使用 " . $user->LastusedTraffic() . " " . number_format($user->last_day_t / $user->transfer_enable * 100, 2) . "%
未使用 " . $user->unusedTraffic() . " " . number_format(($user->transfer_enable - ($user->u + $user->d)) / $user->transfer_enable * 100, 2) . "%";
break;
case 'checkin':
if (!$user->isAbleToCheckin()) {
- $reply['message']= "您今天已经签过到了!";
+ $reply['message'] = "您今天已经签过到了!";
break;
}
$traffic = rand(Config::get('checkinMin'), Config::get('checkinMax'));
$user->transfer_enable = $user->transfer_enable + Tools::toMB($traffic);
$user->last_check_in_time = time();
$user->save();
- $reply['message']= "签到成功!获得了 " . $traffic . " MB 流量!";
+ $reply['message'] = "签到成功!获得了 " . $traffic . " MB 流量!";
break;
case 'prpr':
$prpr = array('⁄(⁄ ⁄•⁄ω⁄•⁄ ⁄)⁄', '(≧ ﹏ ≦)', '(*/ω\*)', 'ヽ(*。>Д<)o゜', '(つ ﹏ ⊂)', '( > < )');
- $reply['message']= $prpr[mt_rand(0, 5)];
+ $reply['message'] = $prpr[mt_rand(0, 5)];
break;
case "rss":
$reply['message'] = "点击以下按钮获取对应订阅: ";
$keys = [];
- foreach (self::$all_rss as $key => $value){
+ foreach (self::$all_rss as $key => $value) {
$keys[] = [["text" => $value, "callback_data" => $key]];
}
- $reply['mark'] = new \TelegramBot\Api\Types\Inline\InlineKeyboardMarkup(
+ $reply['mark'] = new \TelegramBot\Api\Types\Inline\InlineKeyboardMarkup(
$keys
);
break;
}
} else {
- $reply['message'] = "您未绑定本站账号,您可以进入网站的“资料编辑”,在右下方绑定您的账号";
+ $reply['message'] = "您未绑定本站账号,您可以进入网站的“资料编辑”,在右下方绑定您的账号";
}
- return $reply;
+ return $reply;
}
public static function telegram_process($bot, $message, $command)
{
$user = User::where('telegram_id', $message->getFrom()->getId())->first();
- $reply_to = $message->getMessageId();
- $reply = [
- "message" => "???",
- "markup" => null,
- ];
+ $reply_to = $message->getMessageId();
+ $reply = [
+ "message" => "???",
+ "markup" => null,
+ ];
if ($message->getChat()->getId() > 0) {
//个人
$bot->sendChatAction($message->getChat()->getId(), 'typing');
switch ($command) {
case 'ping':
- $reply['message']= 'Pong!您的 ID 是 ' . $message->getChat()->getId() . '!';
+ $reply['message'] = 'Pong!您的 ID 是 ' . $message->getChat()->getId() . '!';
break;
case 'traffic':
case 'checkin':
case 'prpr':
case "rss":
- $reply=TelegramProcess::needbind_method($bot, $message, $command, $user, $reply_to);
+ $reply = TelegramProcess::needbind_method($bot, $message, $command, $user, $reply_to);
break;
case 'help':
$reply['message'] = "命令列表:
@@ -114,50 +115,50 @@ class TelegramProcess
/checkin 签到
/help 获取帮助信息
/rss 获取节点订阅";
- if($user==null){
- $help_list.=PHP_EOL."您未绑定本站账号,您可以进入网站的“资料编辑”,在右下方绑定您的账号";
- }
+ if ($user == null) {
+ $help_list .= PHP_EOL . "您未绑定本站账号,您可以进入网站的“资料编辑”,在右下方绑定您的账号";
+ }
break;
default:
- if ($message->getPhoto()==null){
- if (is_numeric($message->getText()) || strlen($message->getText()) != 6) {
- $reply['message']= Tuling::chat($message->getFrom()->getId(), $message->getText());
+ if ($message->getPhoto() == null) {
+ if (is_numeric($message->getText()) || strlen($message->getText()) != 6) {
+ $reply['message'] = Tuling::chat($message->getFrom()->getId(), $message->getText());
+ break;
+ }
+
+ if ($user == null) {
+ $reply['message'] = "登录验证失败,您未绑定本站账号";
break;
}
-
- if($user==null){
- $reply['message']= "登录验证失败,您未绑定本站账号";
- break;
- }
$uid = TelegramSessionManager::verify_login_number($message->getText(), $user->id);
if ($uid != 0) {
- $reply['message']= "登录验证成功,邮箱:" . $user->email;
+ $reply['message'] = "登录验证成功,邮箱:" . $user->email;
} else {
- $reply['message']= "登录验证失败,数字无效";
+ $reply['message'] = "登录验证失败,数字无效";
}
- break;
- }
+ break;
+ }
$bot->sendMessage($message->getChat()->getId(), "正在解码,请稍候。。。");
- $bot->sendChatAction($message->getChat()->getId(), 'typing');
+ $bot->sendChatAction($message->getChat()->getId(), 'typing');
$photos = $message->getPhoto();
$photo_size_array = array();
$photo_id_array = array();
$photo_id_list_array = array();
-
+
foreach ($photos as $photo) {
$file = $bot->getFile($photo->getFileId());
$real_id = substr($file->getFileId(), 0, 36);
if (!isset($photo_size_array[$real_id])) {
$photo_size_array[$real_id] = 0;
}
-
+
if ($photo_size_array[$real_id] >= $file->getFileSize()) {
- continue;
+ continue;
}
-
+
$photo_size_array[$real_id] = $file->getFileSize();
$photo_id_array[$real_id] = $file->getFileId();
if (!isset($photo_id_list_array[$real_id])) {
@@ -184,31 +185,31 @@ class TelegramProcess
if (substr($qrcode_text, 0, 11) == 'mod://bind/' && strlen($qrcode_text) == 27) {
$uid = TelegramSessionManager::verify_bind_session(substr($qrcode_text, 11));
if ($uid == 0) {
- $reply['message']= "绑定失败,二维码无效:" . substr($qrcode_text, 11)."二维码的有效期为10分钟,请尝试刷新网站的“资料编辑”页面以更新二维码";
- continue;
- }
+ $reply['message'] = "绑定失败,二维码无效:" . substr($qrcode_text, 11) . "二维码的有效期为10分钟,请尝试刷新网站的“资料编辑”页面以更新二维码";
+ continue;
+ }
$user = User::where('id', $uid)->first();
$user->telegram_id = $message->getFrom()->getId();
$user->im_type = 4;
$user->im_value = $message->getFrom()->getUsername();
$user->save();
- $reply['message']= "绑定成功,邮箱:" . $user->email;
- break;
+ $reply['message'] = "绑定成功,邮箱:" . $user->email;
+ break;
}
if (substr($qrcode_text, 0, 12) == 'mod://login/' && strlen($qrcode_text) == 28) {
if ($user == null) {
- $reply['message']= "登录验证失败,您未绑定本站账号" . substr($qrcode_text, 12);
- break;
+ $reply['message'] = "登录验证失败,您未绑定本站账号" . substr($qrcode_text, 12);
+ break;
}
-
+
$uid = TelegramSessionManager::verify_login_session(substr($qrcode_text, 12), $user->id);
if ($uid != 0) {
- $reply['message']= "登录验证成功,邮箱:" . $user->email;
+ $reply['message'] = "登录验证成功,邮箱:" . $user->email;
} else {
- $reply['message']= "登录验证失败,二维码无效" . substr($qrcode_text, 12);
+ $reply['message'] = "登录验证失败,二维码无效" . substr($qrcode_text, 12);
}
- break;
+ break;
}
break;
@@ -223,12 +224,12 @@ class TelegramProcess
switch ($command) {
case 'ping':
- $reply['message']= 'Pong!这个群组的 ID 是 ' . $message->getChat()->getId() . '!';
+ $reply['message'] = 'Pong!这个群组的 ID 是 ' . $message->getChat()->getId() . '!';
break;
case 'traffic':
case 'checkin':
case 'prpr':
- $reply=TelegramProcess::needbind_method($bot, $message, $command, $user, $reply_to);
+ $reply = TelegramProcess::needbind_method($bot, $message, $command, $user, $reply_to);
break;
case 'help':
$reply['message'] = "命令列表:
@@ -237,28 +238,27 @@ class TelegramProcess
/checkin 签到
/help 获取帮助信息
/rss 获取节点订阅 ";
- if($user==null){
- $reply['message'].=PHP_EOL."您未绑定本站账号,您可以进入网站的“资料编辑”,在右下方绑定您的账号";
- }
+ if ($user == null) {
+ $reply['message'] .= PHP_EOL . "您未绑定本站账号,您可以进入网站的“资料编辑”,在右下方绑定您的账号";
+ }
break;
default:
if ($message->getText() != null) {
if ($message->getChat()->getId() == Config::get('telegram_chatid')) {
- $reply['message']= Tuling::chat($message->getFrom()->getId(), $message->getText());
+ $reply['message'] = Tuling::chat($message->getFrom()->getId(), $message->getText());
} else {
- $reply['message']='不约,叔叔我们不约';
+ $reply['message'] = '不约,叔叔我们不约';
}
}
if ($message->getNewChatMember() != null && Config::get('enable_welcome_message') == 'true') {
- $reply['message']="欢迎 " . $message->getNewChatMember()->getFirstName() . " " . $message->getNewChatMember()->getLastName();
+ $reply['message'] = "欢迎 " . $message->getNewChatMember()->getFirstName() . " " . $message->getNewChatMember()->getLastName();
+ } else {
+ $reply['message'] = null;
}
- else{
- $reply['message']=null;
- }
}
}
- $bot->sendMessage($message->getChat()->getId(), $reply['message'] , $parseMode = null, $disablePreview = false, $replyToMessageId = $reply_to, $replyMarkup=$reply['mark']);
+ $bot->sendMessage($message->getChat()->getId(), $reply['message'], $parseMode = null, $disablePreview = false, $replyToMessageId = $reply_to, $replyMarkup = $reply['mark']);
$bot->sendChatAction($message->getChat()->getId(), '');
}
@@ -281,15 +281,17 @@ class TelegramProcess
}), function () {
return true;
});
- $bot->on(function($update) use ($bot){
+ $bot->on(function ($update) use ($bot) {
$callback = $update->getCallbackQuery();
//Answer to Telegram, you make answer in the end, or in the beginning.
- $message = $callback->getMessage();
+ $message = $callback->getMessage();
$message->setFrom($callback->getFrom());
- TelegramProcess::callback_bind_method($bot,$message,$callback->getData());
- }, function($update){
+ TelegramProcess::callback_bind_method($bot, $message, $callback->getData());
+ }, function ($update) {
$callback = $update->getCallbackQuery();
- if (is_null($callback) || !strlen($callback->getData())){return false; }
+ if (is_null($callback) || !strlen($callback->getData())) {
+ return false;
+ }
return true;
});
diff --git a/app/Utils/TelegramSessionManager.php b/app/Utils/TelegramSessionManager.php
index 391626a1..48714362 100644
--- a/app/Utils/TelegramSessionManager.php
+++ b/app/Utils/TelegramSessionManager.php
@@ -10,7 +10,7 @@ class TelegramSessionManager
{
public static function GenerateRandomLink()
{
- $i =0;
+ $i = 0;
for ($i = 0; $i < 10; $i++) {
$token = Tools::genRandomChar(16);
$Elink = TelegramSession::where("session_content", "=", $token)->first();
@@ -18,25 +18,25 @@ class TelegramSessionManager
return $token;
}
}
-
+
return "couldn't alloc token";
}
-
+
public static function GenerateLoginRandomLink()
{
- $i =0;
+ $i = 0;
for ($i = 0; $i < 10; $i++) {
$token = Tools::genRandomChar(16);
$number = rand(100000, 999999);
- $Elink = TelegramSession::where("session_content", "LIKE", $token."|%")->orWhere("session_content", "LIKE", "%|".$number)->first();
+ $Elink = TelegramSession::where("session_content", "LIKE", $token . "|%")->orWhere("session_content", "LIKE", "%|" . $number)->first();
if ($Elink == null) {
- return $token."|".$number;
+ return $token . "|" . $number;
}
}
-
+
return "couldn't alloc token";
}
-
+
public static function add_bind_session($user)
{
$Elink = TelegramSession::where("type", "=", 0)->where("user_id", "=", $user->id)->first();
@@ -46,17 +46,17 @@ class TelegramSessionManager
$Elink->save();
return $Elink->session_content;
}
-
+
$NLink = new TelegramSession();
$NLink->type = 0;
$NLink->user_id = $user->id;
$NLink->datetime = time();
$NLink->session_content = TelegramSessionManager::GenerateRandomLink();
$NLink->save();
-
+
return $NLink->session_content;
}
-
+
public static function verify_bind_session($token)
{
$Elink = TelegramSession::where("type", "=", 0)->where('session_content', $token)->where('datetime', '>', time() - 600)->orderBy('datetime', 'desc')->first();
@@ -67,7 +67,7 @@ class TelegramSessionManager
}
return 0;
}
-
+
public static function add_login_session()
{
$NLink = new TelegramSession();
@@ -76,13 +76,13 @@ class TelegramSessionManager
$NLink->datetime = time();
$NLink->session_content = TelegramSessionManager::GenerateLoginRandomLink();
$NLink->save();
-
+
return $NLink->session_content;
}
-
+
public static function verify_login_session($token, $uid)
{
- $Elink = TelegramSession::where("type", "=", 1)->where('user_id', 0)->where('session_content', "LIKE", $token."|%")->where('datetime', '>', time() - 90)->orderBy('datetime', 'desc')->first();
+ $Elink = TelegramSession::where("type", "=", 1)->where('user_id', 0)->where('session_content', "LIKE", $token . "|%")->where('datetime', '>', time() - 90)->orderBy('datetime', 'desc')->first();
if ($Elink != null) {
$Elink->user_id = $uid;
$Elink->save();
@@ -90,10 +90,10 @@ class TelegramSessionManager
}
return 0;
}
-
+
public static function verify_login_number($token, $uid)
{
- $Elink = TelegramSession::where("type", "=", 1)->where('user_id', 0)->where('session_content', "LIKE", "%|".$token)->where('datetime', '>', time() - 90)->orderBy('datetime', 'desc')->first();
+ $Elink = TelegramSession::where("type", "=", 1)->where('user_id', 0)->where('session_content', "LIKE", "%|" . $token)->where('datetime', '>', time() - 90)->orderBy('datetime', 'desc')->first();
if ($Elink != null) {
$Elink->user_id = $uid;
$Elink->save();
@@ -101,10 +101,10 @@ class TelegramSessionManager
}
return 0;
}
-
+
public static function step2_verify_login_session($token, $number)
{
- $Elink = TelegramSession::where("type", "=", 1)->where('session_content', $token."|".$number)->where('datetime', '>', time() - 90)->orderBy('datetime', 'desc')->first();
+ $Elink = TelegramSession::where("type", "=", 1)->where('session_content', $token . "|" . $number)->where('datetime', '>', time() - 90)->orderBy('datetime', 'desc')->first();
if ($Elink != null) {
$uid = $Elink->user_id;
$Elink->delete();
@@ -112,10 +112,10 @@ class TelegramSessionManager
}
return 0;
}
-
+
public static function check_login_session($token, $number)
{
- $Elink = TelegramSession::where("type", "=", 1)->where('session_content', $token."|".$number)->orderBy('datetime', 'desc')->first();
+ $Elink = TelegramSession::where("type", "=", 1)->where('session_content', $token . "|" . $number)->orderBy('datetime', 'desc')->first();
if ($Elink != null) {
if ($Elink->datetime < time() - 90) {
return -1;
diff --git a/app/Utils/Tools.php b/app/Utils/Tools.php
index a28af155..a14c9d41 100644
--- a/app/Utils/Tools.php
+++ b/app/Utils/Tools.php
@@ -32,18 +32,18 @@ class Tools
} elseif (abs($value) > $kb) {
return round($value / $kb, 2) . "KB";
} else {
- return round($value, 2)."B";
+ return round($value, 2) . "B";
}
}
- //虽然名字是toMB,但是实际上功能是from MB to B
+ //虽然名字是toMB,但是实际上功能是from MB to B
public static function toMB($traffic)
{
$mb = 1048576;
return $traffic * $mb;
}
- //虽然名字是toGB,但是实际上功能是from GB to B
+ //虽然名字是toGB,但是实际上功能是from GB to B
public static function toGB($traffic)
{
$gb = 1048576 * 1024;
@@ -72,18 +72,18 @@ class Tools
}
//获取随机字符串
-
- public static function genRandomNum($length = 8)
- {
- // 来自Miku的 6位随机数 注册验证码 生成方案
- $chars = '0123456789';
- $char = '';
- for ($i = 0; $i < $length; $i++) {
- $char .= $chars[mt_rand(0, strlen($chars) - 1)];
- }
- return $char;
- }
-
+
+ public static function genRandomNum($length = 8)
+ {
+ // 来自Miku的 6位随机数 注册验证码 生成方案
+ $chars = '0123456789';
+ $char = '';
+ for ($i = 0; $i < $length; $i++) {
+ $char .= $chars[mt_rand(0, strlen($chars) - 1)];
+ }
+ return $char;
+ }
+
public static function genRandomChar($length = 8)
{
// 密码字符集,可任意添加你需要的字符
@@ -128,7 +128,7 @@ class Tools
public static function genUUID()
{
// @TODO
- return self::genSID();
+ return self::genSID();
}
public static function getLastPort()
@@ -161,12 +161,12 @@ class Tools
public static function getDir($dir)
{
- $dirArray[]=null;
+ $dirArray[] = null;
if (false != ($handle = opendir($dir))) {
- $i=0;
+ $i = 0;
while (false !== ($file = readdir($handle))) {
- if ($file != "." && $file != ".."&&!strpos($file, ".")) {
- $dirArray[$i]=$file;
+ if ($file != "." && $file != ".." && !strpos($file, ".")) {
+ $dirArray[$i] = $file;
$i++;
}
}
@@ -293,8 +293,8 @@ class Tools
return $rule->id;
}
- //递归处理这个节点
- $maybe_rule_id = Tools::has_conflict_rule($rule, $ruleset, $edit_rule_id, $origin_node_id, $rule->user_id);
+ //递归处理这个节点
+ $maybe_rule_id = Tools::has_conflict_rule($rule, $ruleset, $edit_rule_id, $origin_node_id, $rule->user_id);
if ($maybe_rule_id != 0) {
return $maybe_rule_id;
}
@@ -303,7 +303,7 @@ class Tools
if (($input_rule->id == $edit_rule_id || $edit_rule_id == 0) && $input_rule->dist_node_id != -1) {
$dist_node = Node::find($input_rule->dist_node_id);
- if ($input_rule->source_node_id == 0 && ($dist_node->sort == 10 ||$dist_node->sort == 12)) {
+ if ($input_rule->source_node_id == 0 && ($dist_node->sort == 10 || $dist_node->sort == 12)) {
return -1;
}
@@ -333,10 +333,10 @@ class Tools
if ($single_rule->dist_node_id == $path->begin_node->id) {
$path->begin_node = $single_rule->Source_Node();
if ($path->begin_node->isNodeAccessable() == false) {
- $path->path = ''.$single_rule->Source_Node()->name.''." → ".$path->path;
+ $path->path = '' . $single_rule->Source_Node()->name . '' . " → " . $path->path;
$path->status = "阻断";
} else {
- $path->path = $single_rule->Source_Node()->name." → ".$path->path;
+ $path->path = $single_rule->Source_Node()->name . " → " . $path->path;
$path->status = "通畅";
}
return $pathset;
@@ -345,10 +345,10 @@ class Tools
if ($path->end_node->id == $single_rule->source_node_id) {
$path->end_node = $single_rule->Dist_Node();
if ($path->end_node->isNodeAccessable() == false) {
- $path->path = $path->path." → ".''.$single_rule->Dist_Node()->name.'';
+ $path->path = $path->path . " → " . '' . $single_rule->Dist_Node()->name . '';
$path->status = "阻断";
} else {
- $path->path = $path->path." → ".$single_rule->Dist_Node()->name;
+ $path->path = $path->path . " → " . $single_rule->Dist_Node()->name;
}
return $pathset;
}
@@ -358,7 +358,7 @@ class Tools
$new_path = new \stdClass();
$new_path->begin_node = $single_rule->Source_Node();
if ($new_path->begin_node->isNodeAccessable() == false) {
- $new_path->path = ''.$single_rule->Source_Node()->name.'';
+ $new_path->path = '' . $single_rule->Source_Node()->name . '';
$new_path->status = "阻断";
} else {
$new_path->path = $single_rule->Source_Node()->name;
@@ -367,10 +367,10 @@ class Tools
$new_path->end_node = $single_rule->Dist_Node();
if ($new_path->end_node->isNodeAccessable() == false) {
- $new_path->path .= " -> ".''.$single_rule->Dist_Node()->name.'';
+ $new_path->path .= " -> " . '' . $single_rule->Dist_Node()->name . '';
$new_path->status = "阻断";
} else {
- $new_path->path .= " -> ".$single_rule->Dist_Node()->name;
+ $new_path->path .= " -> " . $single_rule->Dist_Node()->name;
}
$new_path->port = $port;
@@ -425,9 +425,8 @@ class Tools
public static function checkNoneProtocol($user)
{
- if($user->method == 'none' && !in_array($user->protocol, Config::getSupportParam('allow_none_protocol')))
- {
- return false;
+ if ($user->method == 'none' && !in_array($user->protocol, Config::getSupportParam('allow_none_protocol'))) {
+ return false;
}
return true;
@@ -438,22 +437,22 @@ class Tools
return str_replace("::ffff:", "", $rawIp);
}
- public static function isInt($str)
- {
- if($str[0]=='-'){
- $str=substr($str,1);
- }
+ public static function isInt($str)
+ {
+ if ($str[0] == '-') {
+ $str = substr($str, 1);
+ }
- return ctype_digit($str);
+ return ctype_digit($str);
}
-
+
public static function v2Array($node)
{
$server = explode(';', $node);
$item = [
- 'host'=>'',
- 'path'=>'',
- 'tls'=>''
+ 'host' => '',
+ 'path' => '',
+ 'tls' => ''
];
$item['add'] = $server[0];
if ($server[1] == "0" or $server[1] == "") {
@@ -507,10 +506,10 @@ class Tools
{
$server = explode(';', $node);
$item = [
- 'host'=>'',
- 'path'=>'',
- 'net'=>'ws',
- 'tls'=>''
+ 'host' => '',
+ 'path' => '',
+ 'net' => 'ws',
+ 'tls' => ''
];
$item['add'] = $server[0];
if ($server[1] == "0" or $server[1] == "") {
@@ -528,7 +527,7 @@ class Tools
}
if (count($server) >= 5 && $server[4] == 'ws') {
$item['net'] = 'ws';
- }elseif (count($server) >= 5 && $server[4] == 'tls'){
+ } elseif (count($server) >= 5 && $server[4] == 'tls') {
$item['tls'] = 'tls';
}
if (count($server) >= 6) {
diff --git a/app/Utils/Tuling.php b/app/Utils/Tuling.php
index b61db44c..322d450d 100644
--- a/app/Utils/Tuling.php
+++ b/app/Utils/Tuling.php
@@ -14,16 +14,16 @@ class Tuling
$data['key'] = Config::get('tuling_apikey');
$data['userid'] = $user;
$data['info'] = $text;
-
+
$param = json_encode($data);
-
-
+
+
$sock = new HTTPSocket;
$sock->connect("www.tuling123.com", 80);
$sock->set_method('POST');
$sock->add_header('Content-Type', 'application/json');
$sock->query('/openapi/api', $param);
-
+
$result = $sock->fetch_body();
$result_array = json_decode($result, true);
return $result_array['text'];
diff --git a/app/Utils/URL.php b/app/Utils/URL.php
index d2df2e88..86f26d4e 100644
--- a/app/Utils/URL.php
+++ b/app/Utils/URL.php
@@ -1,5 +1,7 @@
xxx, xxx => xxx)
$args_explode = explode('|', $origin);
@@ -79,43 +87,46 @@ class URL
return $return_array;
}
- public static function SSCanConnect($user, $mu_port = 0) {
- if($mu_port != 0) {
+ public static function SSCanConnect($user, $mu_port = 0)
+ {
+ if ($mu_port != 0) {
$mu_user = User::where('port', '=', $mu_port)->where("is_multi_user", "<>", 0)->first();
if ($mu_user == null) {
return;
}
return URL::SSCanConnect($mu_user);
}
- if(URL::CanMethodConnect($user->method) >= 2 && URL::CanProtocolConnect($user->protocol) >= 2 && URL::CanObfsConnect($user->obfs) >= 2) {
+ if (URL::CanMethodConnect($user->method) >= 2 && URL::CanProtocolConnect($user->protocol) >= 2 && URL::CanObfsConnect($user->obfs) >= 2) {
return true;
- }else{
+ } else {
return false;
}
}
- public static function SSRCanConnect($user, $mu_port = 0) {
- if($mu_port != 0) {
+ public static function SSRCanConnect($user, $mu_port = 0)
+ {
+ if ($mu_port != 0) {
$mu_user = User::where('port', '=', $mu_port)->where("is_multi_user", "<>", 0)->first();
if ($mu_user == null) {
return;
}
return URL::SSRCanConnect($mu_user);
}
- if(URL::CanMethodConnect($user->method) != 2 && URL::CanProtocolConnect($user->protocol) != 2 && URL::CanObfsConnect($user->obfs) != 2) {
+ if (URL::CanMethodConnect($user->method) != 2 && URL::CanProtocolConnect($user->protocol) != 2 && URL::CanObfsConnect($user->obfs) != 2) {
return true;
- }else{
+ } else {
return false;
}
}
- public static function getSSConnectInfo($user) {
+ public static function getSSConnectInfo($user)
+ {
$new_user = clone $user;
- if(URL::CanObfsConnect($new_user->obfs) == 5) {
+ if (URL::CanObfsConnect($new_user->obfs) == 5) {
$new_user->obfs = 'plain';
$new_user->obfs_param = '';
}
- if(URL::CanProtocolConnect($new_user->protocol) == 3) {
+ if (URL::CanProtocolConnect($new_user->protocol) == 3) {
$new_user->protocol = 'origin';
$new_user->protocol_param = '';
}
@@ -124,9 +135,10 @@ class URL
return $new_user;
}
- public static function getSSRConnectInfo($user) {
+ public static function getSSRConnectInfo($user)
+ {
$new_user = clone $user;
- if(URL::CanObfsConnect($new_user->obfs) == 4) {
+ if (URL::CanObfsConnect($new_user->obfs) == 4) {
$new_user->obfs = 'plain';
$new_user->obfs_param = '';
}
@@ -135,10 +147,11 @@ class URL
return $new_user;
}
- public static function getAllItems($user, $is_mu = 0, $is_ss = 0) {
+ public static function getAllItems($user, $is_mu = 0, $is_ss = 0)
+ {
$return_array = array();
if ($user->is_admin) {
- $nodes=Node::where(
+ $nodes = Node::where(
function ($query) {
$query->where('sort', 0)
->orwhere('sort', 10)
@@ -146,35 +159,35 @@ class URL
}
)->where("type", "1")->orderBy("name")->get();
} else {
- $nodes=Node::where(
+ $nodes = Node::where(
function ($query) {
$query->where('sort', 0)
->orwhere('sort', 10)
->orwhere('sort', 13);
}
)->where(
- function ($query) use ($user){
+ function ($query) use ($user) {
$query->where("node_group", "=", $user->node_group)
->orWhere("node_group", "=", 0);
}
)->where("type", "1")->where("node_class", "<=", $user->class)->orderBy("name")->get();
}
- if($is_mu) {
+ if ($is_mu) {
if ($user->is_admin) {
- if ($is_mu!=1){
- $mu_nodes = Node::where('sort', 9)->where('server', '=', $is_mu)->where("type", "1")->get();
- }else{
- $mu_nodes = Node::where('sort', 9)->where("type", "1")->get();
- }
+ if ($is_mu != 1) {
+ $mu_nodes = Node::where('sort', 9)->where('server', '=', $is_mu)->where("type", "1")->get();
+ } else {
+ $mu_nodes = Node::where('sort', 9)->where("type", "1")->get();
+ }
} else {
- if ($is_mu!=1){
+ if ($is_mu != 1) {
$mu_nodes = Node::where('sort', 9)->where('server', '=', $is_mu)->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();
- }else{
+ } else {
$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)
@@ -199,12 +212,12 @@ class URL
}
}
$item = URL::getItem($user, $node, 0, $relay_rule_id, $is_ss);
- if($item != null) {
+ if ($item != null) {
array_push($return_array, $item);
}
- }else{
+ } else {
$item = URL::getItem($user, $node, 0, 0, $is_ss);
- if($item != null) {
+ if ($item != null) {
array_push($return_array, $item);
}
}
@@ -220,12 +233,12 @@ class URL
}
}
$item = URL::getItem($user, $node, $mu_node->server, $relay_rule_id, $is_ss);
- if($item != null) {
+ if ($item != null) {
array_push($return_array, $item);
}
- }else{
+ } else {
$item = URL::getItem($user, $node, $mu_node->server, 0, $is_ss);
- if($item != null) {
+ if ($item != null) {
array_push($return_array, $item);
}
}
@@ -234,82 +247,88 @@ class URL
}
return $return_array;
}
- public static function getAllUrl($user, $is_mu, $is_ss = 0) {
+
+ public static function getAllUrl($user, $is_mu, $is_ss = 0)
+ {
$return_url = '';
- if(!$is_ss){
- $return_url .= URL::getUserTraffic($user, $is_mu).PHP_EOL;
- $return_url .= URL::getUserClassExpiration($user, $is_mu).PHP_EOL;
- }
- if(strtotime($user->expire_in) |