改进
This commit is contained in:
parent
fe04c15a07
commit
daac560c0e
@ -1,35 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Jobs;
|
|
||||||
|
|
||||||
use Illuminate\Bus\Queueable;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldBeUnique;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
|
||||||
use Illuminate\Queue\SerializesModels;
|
|
||||||
|
|
||||||
class CheckServer implements ShouldQueue
|
|
||||||
{
|
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
}
|
|
||||||
}
|
|
@ -3,6 +3,7 @@
|
|||||||
namespace App\Jobs;
|
namespace App\Jobs;
|
||||||
|
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
|
use App\Models\Tunnel;
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
@ -22,10 +23,13 @@ class Cost implements ShouldQueue
|
|||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
Server::with('tunnels')->where('status', 'up')->chunk(100, function ($servers) {
|
Server::where('status', 'up')->with('tunnels')->chunk(100, function ($servers) {
|
||||||
foreach ($servers as $server) {
|
foreach ($servers as $server) {
|
||||||
|
|
||||||
foreach ($server->tunnels as $host) {
|
$tunnels = $server->toArray()['tunnels'];
|
||||||
|
|
||||||
|
foreach ($tunnels as $host) {
|
||||||
|
$host = Tunnel::with(['user', 'server'])->find($host['id']);
|
||||||
$host->load('user');
|
$host->load('user');
|
||||||
|
|
||||||
Log::debug('------------');
|
Log::debug('------------');
|
||||||
@ -36,6 +40,7 @@ public function handle()
|
|||||||
$tunnel_data = Cache::get($cache_key, null);
|
$tunnel_data = Cache::get($cache_key, null);
|
||||||
|
|
||||||
if (!is_null($tunnel_data)) {
|
if (!is_null($tunnel_data)) {
|
||||||
|
Log::debug('frpTunnel_data_ 不为空。');
|
||||||
$traffic = ($tunnel_data['today_traffic_in'] ?? 0) + ($tunnel_data['today_traffic_out'] ?? 0);
|
$traffic = ($tunnel_data['today_traffic_in'] ?? 0) + ($tunnel_data['today_traffic_out'] ?? 0);
|
||||||
|
|
||||||
Log::debug('本次使用的流量: ' . round($traffic / 1024 / 1024 / 1024, 2) ?? 0);
|
Log::debug('本次使用的流量: ' . round($traffic / 1024 / 1024 / 1024, 2) ?? 0);
|
||||||
@ -78,7 +83,16 @@ public function handle()
|
|||||||
Log::debug('此时 traffic: ' . $traffic);
|
Log::debug('此时 traffic: ' . $traffic);
|
||||||
|
|
||||||
// lock for update
|
// lock for update
|
||||||
$host->user->balance -= $traffic * $host->user->cost;
|
|
||||||
|
Log::debug('此时 user->traffic: ' . $host->user->traffic);
|
||||||
|
Log::debug('扣除后的流量: ' . $host->user->traffic - $gb);
|
||||||
|
|
||||||
|
Cache::lock('user_traffic_' . $host->user->id)->get(function () use ($host, $gb) {
|
||||||
|
$host->user->update([
|
||||||
|
'traffic' => $host->user->traffic - $gb
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,40 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Jobs;
|
|
||||||
|
|
||||||
use Illuminate\Bus\Queueable;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
|
||||||
use Illuminate\Queue\SerializesModels;
|
|
||||||
use Illuminate\Support\Facades\Http;
|
|
||||||
|
|
||||||
class StatusJob implements ShouldQueue
|
|
||||||
{
|
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
||||||
|
|
||||||
public int $host_id;
|
|
||||||
|
|
||||||
public array $requests;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct($host_id, $requests)
|
|
||||||
{
|
|
||||||
$this->host_id = $host_id;
|
|
||||||
$this->requests = $requests;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
Http::remote()->asForm()->patch('hosts/'.$this->host_id, $this->requests);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,46 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Jobs;
|
|
||||||
|
|
||||||
use App\Models\Host;
|
|
||||||
use App\Models\Tunnel;
|
|
||||||
use Illuminate\Bus\Queueable;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
|
||||||
use Illuminate\Queue\SerializesModels;
|
|
||||||
|
|
||||||
class StopAllHostJob implements ShouldQueue
|
|
||||||
{
|
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
||||||
|
|
||||||
public int $user_id;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct(int $user_id)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
$this->user_id = $user_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
$hosts = Tunnel::where('user_id', $this->user_id);
|
|
||||||
|
|
||||||
$hosts->chunk(100, function () use ($hosts) {
|
|
||||||
foreach ($hosts as $host) {
|
|
||||||
$host->status = 'stopped';
|
|
||||||
$host->save();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
@ -25,14 +25,16 @@ const items = ref([
|
|||||||
name: "隧道",
|
name: "隧道",
|
||||||
route: "tunnels",
|
route: "tunnels",
|
||||||
},
|
},
|
||||||
// {
|
|
||||||
// name: "服务器列表",
|
|
||||||
// route: "servers",
|
|
||||||
// },
|
|
||||||
{
|
{
|
||||||
name: "创建隧道",
|
name: "创建隧道",
|
||||||
route: "tunnels.create",
|
route: "tunnels.create",
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
name: "客户端下载",
|
||||||
|
route: "downloads",
|
||||||
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// 如果是管理员
|
// 如果是管理员
|
||||||
|
@ -32,8 +32,8 @@
|
|||||||
<a
|
<a
|
||||||
class="nav-link text-auto"
|
class="nav-link text-auto"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
href="https://forum.laecloud.com"
|
href="https://wiki.laecloud.com/PortIO"
|
||||||
>社区</a
|
>文档</a
|
||||||
>
|
>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
@ -35,33 +35,16 @@ const routes = [
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: "/servers",
|
path: "/downloads",
|
||||||
name: "servers",
|
name: "downloads",
|
||||||
component: () => import("../views/Servers/Index.vue"),
|
component: () => import("../views/Downloads.vue"),
|
||||||
meta: {
|
meta: {
|
||||||
title: "服务器列表",
|
title: "客户端下载",
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: "/servers/create",
|
|
||||||
name: "servers.create",
|
|
||||||
component: () => import("../views/Servers/Create.vue"),
|
|
||||||
meta: {
|
|
||||||
admin: true,
|
|
||||||
title: "创建服务器",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: "/servers/:id/edit",
|
|
||||||
name: "servers.edit",
|
|
||||||
component: () => import("../views/Servers/Edit.vue"),
|
|
||||||
meta: {
|
|
||||||
admin: true,
|
|
||||||
title: "创建服务器",
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
|
67
resources/js/views/Downloads.vue
Normal file
67
resources/js/views/Downloads.vue
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
<template>
|
||||||
|
<h1>客户端下载</h1>
|
||||||
|
|
||||||
|
<table class="table table-bordered">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>名称</th>
|
||||||
|
<th>架构</th>
|
||||||
|
<th>下载</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
|
||||||
|
<tbody>
|
||||||
|
<tr v-for="i in items">
|
||||||
|
<td>{{ i.name }}</td>
|
||||||
|
<td>{{ i.arch }}</td>
|
||||||
|
<td>
|
||||||
|
<a :href="i.url">下载</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { ref } from "vue";
|
||||||
|
|
||||||
|
const version = [
|
||||||
|
{
|
||||||
|
name: "Windows Frpc amd64",
|
||||||
|
arch: "amd64",
|
||||||
|
url: "https://r2.laecloud.com/MEFrpRelease/MirrorEdgeFrp_0.46.1_beta_windows_amd64.zip",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Windows Frpc i386",
|
||||||
|
arch: "i386",
|
||||||
|
url: "https://r2.laecloud.com/MEFrpRelease/MirrorEdgeFrp_0.46.1_beta_windows_386.zip",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Windows Python 图形化启动器",
|
||||||
|
arch: "amd64",
|
||||||
|
url: "https://r2.laecloud.com/MEFrpRelease/Mirror_Edge_Frp_Python_Win.zip",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Linux Frpc amd64",
|
||||||
|
arch: "amd64",
|
||||||
|
url: "https://r2.laecloud.com/MEFrpRelease/frp_MirrorEdgeFrp_0.46.1_beta_linux_amd64.tar.gz",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Linux Frpc arm64",
|
||||||
|
arch: "arm64",
|
||||||
|
url: "https://r2.laecloud.com/MEFrpRelease/frp_MirrorEdgeFrp_0.46.1_beta_linux_arm64.tar.gz",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Darwin Frpc amd64",
|
||||||
|
arch: "amd64",
|
||||||
|
url: "https://r2.laecloud.com/MEFrpRelease/frp_MirrorEdgeFrp_0.46.1_beta_darwin_amd64.tar.gz",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Darwin Frpc arm64",
|
||||||
|
arch: "arm64",
|
||||||
|
url: "https://r2.laecloud.com/MEFrpRelease/frp_MirrorEdgeFrp_0.46.1_beta_darwin_arm64.tar.gz",
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const items = ref(version);
|
||||||
|
</script>
|
@ -18,7 +18,7 @@
|
|||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr v-for="tunnel in tunnels">
|
<tr v-for="tunnel in tunnels">
|
||||||
<th>1</th>
|
<th>{{ tunnel.id }}</th>
|
||||||
<td>
|
<td>
|
||||||
<router-link
|
<router-link
|
||||||
:to="{
|
:to="{
|
||||||
|
Loading…
Reference in New Issue
Block a user