This commit is contained in:
iVampireSP.com 2023-05-14 17:36:47 +08:00
parent fe04c15a07
commit daac560c0e
No known key found for this signature in database
GPG Key ID: 2F7B001CA27A8132
10 changed files with 98 additions and 153 deletions

View File

@ -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()
{
//
}
}

View File

@ -3,6 +3,7 @@
namespace App\Jobs;
use App\Models\Server;
use App\Models\Tunnel;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
@ -22,10 +23,13 @@ class Cost implements ShouldQueue
*/
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 ($server->tunnels as $host) {
$tunnels = $server->toArray()['tunnels'];
foreach ($tunnels as $host) {
$host = Tunnel::with(['user', 'server'])->find($host['id']);
$host->load('user');
Log::debug('------------');
@ -36,6 +40,7 @@ public function handle()
$tunnel_data = Cache::get($cache_key, null);
if (!is_null($tunnel_data)) {
Log::debug('frpTunnel_data_ 不为空。');
$traffic = ($tunnel_data['today_traffic_in'] ?? 0) + ($tunnel_data['today_traffic_out'] ?? 0);
Log::debug('本次使用的流量: ' . round($traffic / 1024 / 1024 / 1024, 2) ?? 0);
@ -78,7 +83,16 @@ public function handle()
Log::debug('此时 traffic: ' . $traffic);
// 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
]);
});
}
}
}

View File

@ -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);
}
}

View File

@ -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();
}
});
}
}

View File

@ -25,14 +25,16 @@ const items = ref([
name: "隧道",
route: "tunnels",
},
// {
// name: "",
// route: "servers",
// },
{
name: "创建隧道",
route: "tunnels.create",
},
{
name: "客户端下载",
route: "downloads",
},
]);
//

View File

@ -32,8 +32,8 @@
<a
class="nav-link text-auto"
target="_blank"
href="https://forum.laecloud.com"
>社区</a
href="https://wiki.laecloud.com/PortIO"
>文档</a
>
</li>
</ul>

View File

@ -35,33 +35,16 @@ const routes = [
},
},
{
path: "/servers",
name: "servers",
component: () => import("../views/Servers/Index.vue"),
path: "/downloads",
name: "downloads",
component: () => import("../views/Downloads.vue"),
meta: {
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: "创建服务器",
title: "客户端下载",
},
},
];

View 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>

View File

@ -18,7 +18,7 @@
</thead>
<tbody>
<tr v-for="tunnel in tunnels">
<th>1</th>
<th>{{ tunnel.id }}</th>
<td>
<router-link
:to="{