mirror of
https://github.com/wikihost-opensource/als.git
synced 2025-12-24 12:57:59 +08:00
Fix feature toggles
This commit is contained in:
@@ -84,6 +84,7 @@ class Websocket
|
||||
|
||||
private function doPing($ticket, $domain)
|
||||
{
|
||||
if (!env('UTILITIES_PING', true)) { return; }
|
||||
$host = gethostbyname($domain);
|
||||
if ($host === false || ($host == $domain && !ip2long($domain))) {
|
||||
$this->send("1|{$ticket}|0");
|
||||
@@ -118,6 +119,7 @@ class Websocket
|
||||
|
||||
public function doTraceroute($ticket, $domain)
|
||||
{
|
||||
if (!env('UTILITIES_TRACEROUTE', true)) { return; }
|
||||
/** @var MaxMind\Db\Reader $reader */
|
||||
global $reader;
|
||||
|
||||
@@ -238,6 +240,7 @@ class Websocket
|
||||
|
||||
public function startIperf3($ticket)
|
||||
{
|
||||
if (!env('UTILITIES_IPERF3', true)) { return; }
|
||||
$timeout = 60;
|
||||
$port = rand(env('UTILITIES_IPERF3_PORT_MIN', '30000'), env('UTILITIES_IPERF3_PORT_MAX', '31000'));
|
||||
while (in_array($port, self::$ports)) {
|
||||
|
||||
@@ -1,33 +1,35 @@
|
||||
<?php
|
||||
applog('Working with speedtest static file(s)...');
|
||||
if (env('ENABLE_SPEEDTEST', true)) {
|
||||
applog('Working with speedtest static file(s)...');
|
||||
|
||||
$speedtestFiles = [];
|
||||
$multiplier = env('IEC_FORMAT', 'true') ? 1024 : 1000;
|
||||
$sizeMap = ['KB', 'MB', 'GB', 'TB'];
|
||||
$baseBufferSize = pow($multiplier, 2);
|
||||
foreach (explode(" ", env('SPEEDTEST_FILE_LIST', '1MB 10MB 100MB 1GB')) as $speedtestSize) {
|
||||
if (empty($speedtestSize)) continue;
|
||||
$speedtestFiles = [];
|
||||
$multiplier = env('IEC_FORMAT', 'true') ? 1024 : 1000;
|
||||
$sizeMap = ['KB', 'MB', 'GB', 'TB'];
|
||||
$baseBufferSize = pow($multiplier, 2);
|
||||
foreach (explode(" ", env('SPEEDTEST_FILE_LIST', '1MB 10MB 100MB 1GB')) as $speedtestSize) {
|
||||
if (empty($speedtestSize)) continue;
|
||||
|
||||
preg_match('/(\d+)(KB|MB|GB|TB)/m', $speedtestSize, $matches, PREG_OFFSET_CAPTURE, 0);
|
||||
if (empty($matches)) continue;
|
||||
$targetSize = $matches[1][0] * pow($multiplier, array_search($matches[2][0], $sizeMap) + 1);
|
||||
$path = '/app/webspaces/speedtest-static/' . $speedtestSize . '.test';
|
||||
if (file_exists($path) && filesize($path) == $targetSize) {
|
||||
applog('Skip create speedtest file with size: ' . $speedtestSize . ', File exists and size match');
|
||||
continue;
|
||||
}
|
||||
applog('Creating speedtest file with size: ' . $speedtestSize . ' ...');
|
||||
$random = fopen('/dev/urandom', 'r');
|
||||
$speedtestFd = fopen($path, 'w+');
|
||||
while ($targetSize != 0) {
|
||||
if ($targetSize >= $baseBufferSize) {
|
||||
$readSize = $baseBufferSize;
|
||||
} else {
|
||||
$readSize = $targetSize;
|
||||
preg_match('/(\d+)(KB|MB|GB|TB)/m', $speedtestSize, $matches, PREG_OFFSET_CAPTURE, 0);
|
||||
if (empty($matches)) continue;
|
||||
$targetSize = $matches[1][0] * pow($multiplier, array_search($matches[2][0], $sizeMap) + 1);
|
||||
$path = '/app/webspaces/speedtest-static/' . $speedtestSize . '.test';
|
||||
if (file_exists($path) && filesize($path) == $targetSize) {
|
||||
applog('Skip create speedtest file with size: ' . $speedtestSize . ', File exists and size match');
|
||||
continue;
|
||||
}
|
||||
$targetSize -= $readSize;
|
||||
fwrite($speedtestFd, fread($random, $readSize));
|
||||
applog('Creating speedtest file with size: ' . $speedtestSize . ' ...');
|
||||
$random = fopen('/dev/urandom', 'r');
|
||||
$speedtestFd = fopen($path, 'w+');
|
||||
while ($targetSize != 0) {
|
||||
if ($targetSize >= $baseBufferSize) {
|
||||
$readSize = $baseBufferSize;
|
||||
} else {
|
||||
$readSize = $targetSize;
|
||||
}
|
||||
$targetSize -= $readSize;
|
||||
fwrite($speedtestFd, fread($random, $readSize));
|
||||
}
|
||||
fclose($speedtestFd);
|
||||
fclose($random);
|
||||
}
|
||||
fclose($speedtestFd);
|
||||
fclose($random);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
go(function () {
|
||||
if (!env('ENABLE_SPEEDTEST', true)) { return; }
|
||||
$server = new Swoole\Coroutine\Http\Server('unix:///tmp/speedtest.sock');
|
||||
$server->handle('/upload', function ($request, $response) {
|
||||
$response->header('server', 'webserver/1.0');
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
go(function () {
|
||||
do {
|
||||
foreach (['/tmp/speedtest.sock', '/tmp/speedtest-api.sock'] as $file) {
|
||||
if (!file_exists($file)) break;
|
||||
if (!file_exists($file)) continue;
|
||||
chmod($file, 0777);
|
||||
}
|
||||
} while (false);
|
||||
|
||||
@@ -74,6 +74,9 @@ export default defineComponent({
|
||||
this.componentConfig.testFiles = data.testfiles
|
||||
this.componentConfig.display_traffic = data.display_traffic
|
||||
this.componentConfig.display_speedtest = data.display_speedtest
|
||||
this.componentConfig.utilities_ping = data.utilities_ping
|
||||
this.componentConfig.utilities_traceroute = data.utilities_traceroute
|
||||
this.componentConfig.utilities_iperf3 = data.utilities_iperf3
|
||||
|
||||
this.tableData = []
|
||||
this.tableData.push({
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
<template>
|
||||
<div>
|
||||
<n-card>
|
||||
<template #header>
|
||||
网络工具
|
||||
</template>
|
||||
<n-space>
|
||||
<n-button @click="activate('ping')">Ping</n-button>
|
||||
<n-button @click="activate('traceroute')">Traceroute</n-button>
|
||||
<n-button @click="activate('iperf3')">iPerf3</n-button>
|
||||
<n-button v-show="componentConfig.utilities_ping" @click="activate('ping')">Ping</n-button>
|
||||
<n-button v-show="componentConfig.utilities_traceroute" @click="activate('traceroute')">Traceroute</n-button>
|
||||
<n-button v-show="componentConfig.utilities_iperf3" @click="activate('iperf3')">iPerf3</n-button>
|
||||
</n-space>
|
||||
</n-card>
|
||||
<n-drawer v-model:show="componentSwitch.ping" :native-scrollbar="true" :width="drawWidth" placement="right">
|
||||
@@ -24,6 +25,7 @@
|
||||
<iperf3 v-model:ws="ws" v-model:wsMessage="wsMessage" v-model:componentConfig="componentConfig" />
|
||||
</n-drawer-content>
|
||||
</n-drawer>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
|
||||
Reference in New Issue
Block a user