mirror of
				https://github.com/v2board/v2board.git
				synced 2025-10-30 08:52:05 +08:00 
			
		
		
		
	update server stat and app default config
This commit is contained in:
		| @@ -2,13 +2,12 @@ | ||||
|  | ||||
| namespace App\Console\Commands; | ||||
|  | ||||
| use App\Utils\CacheKey; | ||||
| use Illuminate\Console\Command; | ||||
| use App\Models\User; | ||||
| use App\Models\Order; | ||||
| use App\Models\Server; | ||||
| use App\Models\ServerLog; | ||||
| use App\Utils\Helper; | ||||
| use App\Models\ServerStat; | ||||
| use Illuminate\Support\Facades\Cache; | ||||
| use Illuminate\Support\Facades\DB; | ||||
|  | ||||
| class V2boardCache extends Command | ||||
| { | ||||
| @@ -43,5 +42,29 @@ class V2boardCache extends Command | ||||
|      */ | ||||
|     public function handle() | ||||
|     { | ||||
|         $this->serverStat(); | ||||
|     } | ||||
|  | ||||
|     private function serverStat() | ||||
|     { | ||||
|         $serverLogs = ServerLog::select( | ||||
|             'server_id', | ||||
|             DB::raw("sum(u) as u"), | ||||
|             DB::raw("sum(d) as d"), | ||||
|             DB::raw("count(*) as online") | ||||
|         ) | ||||
|             ->where('updated_at', '>=', time() - 3600) | ||||
|             ->groupBy('server_id') | ||||
|             ->get(); | ||||
|         foreach ($serverLogs as $serverLog) { | ||||
|             $data = [ | ||||
|                 'server_id' => $serverLog->server_id, | ||||
|                 'u' => $serverLog->u, | ||||
|                 'd' => $serverLog->d, | ||||
|                 'online' => $serverLog->online | ||||
|             ]; | ||||
|             Cache::put(CacheKey::get('SERVER_STAT', $serverLog->server_id), json_encode($data), 3600); | ||||
|             ServerStat::create($data); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -6,6 +6,7 @@ use App\Http\Requests\Admin\ServerSave; | ||||
| use App\Http\Requests\Admin\ServerSort; | ||||
| use App\Http\Requests\Admin\ServerUpdate; | ||||
| use App\Services\ServerService; | ||||
| use App\Utils\CacheKey; | ||||
| use Illuminate\Http\Request; | ||||
| use App\Http\Controllers\Controller; | ||||
| use App\Models\ServerGroup; | ||||
| @@ -25,6 +26,14 @@ class ServerController extends Controller | ||||
|                 $server[$i]['tags'] = json_decode($server[$i]['tags']); | ||||
|             } | ||||
|             $server[$i]['group_id'] = json_decode($server[$i]['group_id']); | ||||
|             $serverStat = Cache::get(CacheKey::get('SERVER_STAT', $server[$i]['id'])); | ||||
|             dd($serverStat); | ||||
|             if ($serverStat) { | ||||
|                 $serverStat = json_decode($serverStat, true); | ||||
|                 $server[$i]['u'] = $serverStat['u']; | ||||
|                 $server[$i]['d'] = $serverStat['d']; | ||||
|                 $server[$i]['online'] = $serverStat['online']; | ||||
|             } | ||||
|             if ($server[$i]['parent_id']) { | ||||
|                 $server[$i]['last_check_at'] = Cache::get('server_last_check_at_' . $server[$i]['parent_id']); | ||||
|             } else { | ||||
|   | ||||
| @@ -12,7 +12,7 @@ use App\Utils\Helper; | ||||
|  | ||||
| class AppController extends Controller | ||||
| { | ||||
|     CONST CLIENT_CONFIG = '{"policy":{"levels":{"0":{"uplinkOnly":0}}},"dns":{"servers":["114.114.114.114","8.8.8.8"]},"outboundDetour":[{"protocol":"freedom","tag":"direct","settings":{}}],"inbound":{"listen":"0.0.0.0","port":31211,"protocol":"socks","settings":{"auth":"noauth","udp":true,"ip":"127.0.0.1"}},"inboundDetour":[{"listen":"0.0.0.0","allocate":{"strategy":"always","refresh":5,"concurrency":3},"port":31210,"protocol":"http","tag":"httpDetour","domainOverride":["http","tls"],"streamSettings":{},"settings":{"timeout":0}}],"routing":{"strategy":"rules","settings":{"domainStrategy":"IPIfNonMatch","rules":[{"type":"field","ip":["geoip:cn"],"outboundTag":"direct"},{"type":"field","ip":["0.0.0.0/8","10.0.0.0/8","100.64.0.0/10","127.0.0.0/8","169.254.0.0/16","172.16.0.0/12","192.0.0.0/24","192.0.2.0/24","192.168.0.0/16","198.18.0.0/15","198.51.100.0/24","203.0.113.0/24","::1/128","fc00::/7","fe80::/10"],"outboundTag":"direct"}]}},"outbound":{"tag":"proxy","sendThrough":"0.0.0.0","mux":{"enabled":false,"concurrency":8},"protocol":"vmess","settings":{"vnext":[{"address":"server","port":443,"users":[{"id":"uuid","alterId":2,"security":"auto","level":0}],"remark":"remark"}]},"streamSettings":{"network":"tcp","tcpSettings":{"header":{"type":"none"}},"security":"none","tlsSettings":{"allowInsecure":true,"allowInsecureCiphers":true},"kcpSettings":{"header":{"type":"none"},"mtu":1350,"congestion":false,"tti":20,"uplinkCapacity":5,"writeBufferSize":1,"readBufferSize":1,"downlinkCapacity":20},"wsSettings":{"path":"","headers":{"Host":"server.cc"}}}}}'; | ||||
|     CONST CLIENT_CONFIG = '{"policy":{"levels":{"0":{"uplinkOnly":0}}},"dns":{"servers":["8.8.8.8","localhost"]},"outboundDetour":[{"protocol":"freedom","tag":"direct","settings":{}}],"inbound":{"listen":"0.0.0.0","port":31211,"protocol":"socks","settings":{"auth":"noauth","udp":true,"ip":"127.0.0.1"}},"inboundDetour":[{"listen":"0.0.0.0","allocate":{"strategy":"always","refresh":5,"concurrency":3},"port":31210,"protocol":"http","tag":"httpDetour","domainOverride":["http","tls"],"streamSettings":{},"settings":{"timeout":0}}],"routing":{"strategy":"rules","settings":{"domainStrategy":"IPIfNonMatch","rules":[{"type":"field","ip":["geoip:cn"],"outboundTag":"direct"},{"type":"field","ip":["0.0.0.0/8","10.0.0.0/8","100.64.0.0/10","127.0.0.0/8","169.254.0.0/16","172.16.0.0/12","192.0.0.0/24","192.0.2.0/24","192.168.0.0/16","198.18.0.0/15","198.51.100.0/24","203.0.113.0/24","::1/128","fc00::/7","fe80::/10"],"outboundTag":"direct"}]}},"outbound":{"tag":"proxy","sendThrough":"0.0.0.0","mux":{"enabled":false,"concurrency":8},"protocol":"vmess","settings":{"vnext":[{"address":"server","port":443,"users":[{"id":"uuid","alterId":2,"security":"auto","level":0}],"remark":"remark"}]},"streamSettings":{"network":"tcp","tcpSettings":{"header":{"type":"none"}},"security":"none","tlsSettings":{"allowInsecure":true,"allowInsecureCiphers":true},"kcpSettings":{"header":{"type":"none"},"mtu":1350,"congestion":false,"tti":20,"uplinkCapacity":5,"writeBufferSize":1,"readBufferSize":1,"downlinkCapacity":20},"wsSettings":{"path":"","headers":{"Host":"server.cc"}}}}}'; | ||||
|     CONST SOCKS_PORT = 10010; | ||||
|     CONST HTTP_PORT = 10011; | ||||
|  | ||||
|   | ||||
| @@ -11,7 +11,8 @@ class CommController extends Controller | ||||
|     { | ||||
|         return response([ | ||||
|             'data' => [ | ||||
|                 'isTelegram' => (int)config('v2board.telegram_bot_enable', 0) | ||||
|                 'isTelegram' => (int)config('v2board.telegram_bot_enable', 0), | ||||
|                 'stripePk' => config('v2board.stripe_pk_live') | ||||
|             ] | ||||
|         ]); | ||||
|     } | ||||
|   | ||||
| @@ -9,6 +9,4 @@ class ServerLog extends Model | ||||
| { | ||||
|     protected $table = 'v2_server_log'; | ||||
|     protected $dateFormat = 'U'; | ||||
|     protected $dispatchesEvents = [ | ||||
|     ]; | ||||
| } | ||||
|   | ||||
							
								
								
									
										12
									
								
								app/Models/ServerStat.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								app/Models/ServerStat.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,12 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Models; | ||||
|  | ||||
| use Illuminate\Database\Eloquent\Model; | ||||
|  | ||||
| class ServerStat extends Model | ||||
| { | ||||
|     protected $table = 'v2_server_stat'; | ||||
|     protected $dateFormat = 'U'; | ||||
|     protected $guarded = ['id']; | ||||
| } | ||||
| @@ -6,7 +6,8 @@ class CacheKey | ||||
| { | ||||
|     CONST KEYS = [ | ||||
|         'EMAIL_VERIFY_CODE' => '邮箱验证吗', | ||||
|         'LAST_SEND_EMAIL_VERIFY_TIMESTAMP' => '最后一次发送邮箱验证码时间' | ||||
|         'LAST_SEND_EMAIL_VERIFY_TIMESTAMP' => '最后一次发送邮箱验证码时间', | ||||
|         'SERVER_STAT' => '节点统计信息' | ||||
|     ]; | ||||
|  | ||||
|     public static function get(string $key, $uniqueValue) | ||||
|   | ||||
| @@ -178,10 +178,12 @@ CREATE TABLE `v2_server_stat` ( | ||||
|   `id` int(11) NOT NULL AUTO_INCREMENT, | ||||
|   `server_id` int(11) NOT NULL, | ||||
|   `u` varchar(255) NOT NULL, | ||||
|   `d` varchar(25) NOT NULL, | ||||
|   `d` varchar(255) NOT NULL, | ||||
|   `online` int(11) NOT NULL, | ||||
|   `created_at` int(11) NOT NULL, | ||||
|   `updated_at` int(11) NOT NULL, | ||||
|   PRIMARY KEY (`id`) | ||||
|   PRIMARY KEY (`id`), | ||||
|   KEY `created_at` (`created_at`) | ||||
| ) ENGINE=InnoDB DEFAULT CHARSET=latin1; | ||||
|  | ||||
|  | ||||
| @@ -261,4 +263,4 @@ CREATE TABLE `v2_user` ( | ||||
| ) ENGINE=InnoDB DEFAULT CHARSET=utf8; | ||||
|  | ||||
|  | ||||
| -- 2020-05-12 12:31:04 | ||||
| -- 2020-06-04 15:23:25 | ||||
|   | ||||
| @@ -256,3 +256,9 @@ ADD INDEX log_at (`log_at`); | ||||
|  | ||||
| ALTER TABLE `v2_user` | ||||
| ADD `telegram_id` bigint NULL AFTER `invite_user_id`; | ||||
|  | ||||
| ALTER TABLE `v2_server_stat` | ||||
| ADD `online` int(11) NOT NULL AFTER `d`; | ||||
|  | ||||
| ALTER TABLE `v2_server_stat` | ||||
| ADD INDEX `created_at` (`created_at`); | ||||
|   | ||||
| @@ -1,63 +0,0 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Library; | ||||
|  | ||||
| class TomatoPay | ||||
| { | ||||
|     private $mchid; | ||||
|     private $account; | ||||
|     private $key; | ||||
|  | ||||
|     public function __construct($mchid, $account, $key) | ||||
|     { | ||||
|         $this->mchid = $mchid; | ||||
|         $this->account = $account; | ||||
|         $this->key = $key; | ||||
|     } | ||||
|  | ||||
|     public function alipay($cny, $trade) | ||||
|     { | ||||
|         $params = [ | ||||
|             'mchid' => $this->mchid, | ||||
|             'account' => $this->account, | ||||
|             'cny' => $cny, | ||||
|             'type' => '1', | ||||
|             'trade' => $trade | ||||
|         ]; | ||||
|         $params['signs'] = $this->sign($params); | ||||
|         return $this->buildHtml('https://b.fanqieui.com/gateways/alipay.php', $params); | ||||
|     } | ||||
|  | ||||
|     public function wxpay($cny, $trade) | ||||
|     { | ||||
|         $params = [ | ||||
|             'mchid' => $this->mchid, | ||||
|             'account' => $this->account, | ||||
|             'cny' => $cny, | ||||
|             'type' => '1', | ||||
|             'trade' => $trade | ||||
|         ]; | ||||
|         $params['signs'] = $this->sign($params); | ||||
|         return $this->buildHtml('https://b.fanqieui.com/gateways/wxpay.php', $params); | ||||
|     } | ||||
|  | ||||
|     public function sign($params) | ||||
|     { | ||||
|         $o = ''; | ||||
|         foreach ($params as $k => $v) { | ||||
|             $o .= "$k=" . ($v) . "&"; | ||||
|         } | ||||
|         return md5(substr($o, 0, -1) . $this->key); | ||||
|     } | ||||
|  | ||||
|     public function buildHtml($url, $params, $method = 'post', $target = '_self') | ||||
|     { | ||||
|         // return var_dump($params); | ||||
|         $html = "<form id='submit' name='submit' action='" . $url . "' method='$method' target='$target'>"; | ||||
|         foreach ($params as $key => $value) { | ||||
|             $html .= "<input type='hidden' name='$key' value='$value'/>"; | ||||
|         } | ||||
|         $html .= "</form><script>document.forms['submit'].submit();</script>"; | ||||
|         return $html; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										14
									
								
								library/V2ray.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								library/V2ray.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,14 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Library; | ||||
|  | ||||
|  | ||||
| class V2ray | ||||
| { | ||||
|     protected $config; | ||||
|  | ||||
|     public function __construct() | ||||
|     { | ||||
|         $this->config = new \StdClass(); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										2
									
								
								public/assets/user/umi.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								public/assets/user/umi.js
									
									
									
									
										vendored
									
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
		Reference in New Issue
	
	Block a user