mirror of
https://github.com/henrywhitaker3/Speedtest-Tracker.git
synced 2025-12-21 21:33:08 +01:00
Compare commits
190 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2ed811e949 | ||
|
|
99d80ed235 | ||
|
|
9541117125 | ||
|
|
db7e307b20 | ||
|
|
e90619b536 | ||
|
|
fa58ab0168 | ||
|
|
c98ddc74c1 | ||
|
|
2d6e00f51b | ||
|
|
744f045ccf | ||
|
|
56e3b15e75 | ||
|
|
8468ffc022 | ||
|
|
7fece6fd89 | ||
|
|
c5c3a54809 | ||
|
|
2837f9f031 | ||
|
|
d1efe9a166 | ||
|
|
be2c70605e | ||
|
|
e21ce23bbe | ||
|
|
6b7bbf089f | ||
|
|
cee8a887ef | ||
|
|
dcd3381259 | ||
|
|
dab973dbf8 | ||
|
|
0c23b16164 | ||
|
|
02f76ca617 | ||
|
|
11fb44b789 | ||
|
|
715dac7828 | ||
|
|
9b4a0afda0 | ||
|
|
da8e7f409c | ||
|
|
676df45ae9 | ||
|
|
2f8d12dba1 | ||
|
|
4929d0efac | ||
|
|
bee655dd8f | ||
|
|
32bcde92bb | ||
|
|
f412dc70e6 | ||
|
|
681fc8fbed | ||
|
|
a81adebe62 | ||
|
|
1ae66474f3 | ||
|
|
dd158c7c83 | ||
|
|
fd70dc6cb8 | ||
|
|
77576f6537 | ||
|
|
f41039ce78 | ||
|
|
2ada8a22a9 | ||
|
|
52a91af086 | ||
|
|
af66d17ba4 | ||
|
|
dd27802e0f | ||
|
|
3444b8be18 | ||
|
|
043fd42b9a | ||
|
|
eeec6ae26c | ||
|
|
05d276fca0 | ||
|
|
f5f378e8c3 | ||
|
|
2f8137db0e | ||
|
|
95dbbc96b6 | ||
|
|
3d44da1f87 | ||
|
|
4e8b46f786 | ||
|
|
f110704a7a | ||
|
|
73517f92f7 | ||
|
|
ea9e5c1a52 | ||
|
|
ad36edc749 | ||
|
|
1467bee847 | ||
|
|
67eec58d74 | ||
|
|
752ef06626 | ||
|
|
feffc0023f | ||
|
|
f918288728 | ||
|
|
b74e69314a | ||
|
|
44c6c256c0 | ||
|
|
fde30602b0 | ||
|
|
a7652af2ba | ||
|
|
95325db128 | ||
|
|
46d13fd08a | ||
|
|
1637e66bef | ||
|
|
71e132e513 | ||
|
|
21ed016d25 | ||
|
|
8bc6975b69 | ||
|
|
5a0f5a2b3c | ||
|
|
17b72b91d0 | ||
|
|
0910bbb757 | ||
|
|
e9de226c7a | ||
|
|
10137a602a | ||
|
|
342e87b08d | ||
|
|
100cc1d768 | ||
|
|
2d1af61fb1 | ||
|
|
41a3bb3b5b | ||
|
|
365acda11c | ||
|
|
2df827b722 | ||
|
|
48839a0aa3 | ||
|
|
05e856799a | ||
|
|
2a243d251c | ||
|
|
73999eba53 | ||
|
|
24a2c0e7df | ||
|
|
c18b334128 | ||
|
|
e479e828bb | ||
|
|
f9b6f99a05 | ||
|
|
d577954660 | ||
|
|
cf5bafe586 | ||
|
|
7eb668a892 | ||
|
|
bc28094e67 | ||
|
|
326b0edbac | ||
|
|
eb1ec516b9 | ||
|
|
33c61071d4 | ||
|
|
6306824351 | ||
|
|
47cbce56a9 | ||
|
|
f8387e4f4b | ||
|
|
353b381f25 | ||
|
|
065bc45d11 | ||
|
|
4d78eff393 | ||
|
|
14ba9e092f | ||
|
|
628b0fdbea | ||
|
|
2cb31d52a7 | ||
|
|
8b8c3ae801 | ||
|
|
846942929e | ||
|
|
8e151c9ce5 | ||
|
|
a568d83dbc | ||
|
|
dcf94b6a4b | ||
|
|
47ecb7d58c | ||
|
|
4e61e0fccb | ||
|
|
59a4a25bed | ||
|
|
0e60bf195f | ||
|
|
2b57d6c244 | ||
|
|
8f846bd4fe | ||
|
|
081eac4f1e | ||
|
|
7071d0ac4c | ||
|
|
87aba591c0 | ||
|
|
5e5e9d8992 | ||
|
|
d16889f406 | ||
|
|
5d0020a707 | ||
|
|
e9d8f4754b | ||
|
|
18439da15a | ||
|
|
2919c9fb9b | ||
|
|
3097c244de | ||
|
|
6c64613628 | ||
|
|
2e39a238e7 | ||
|
|
8e003017bd | ||
|
|
9190385f93 | ||
|
|
226e2c42a7 | ||
|
|
c55baae478 | ||
|
|
7654da9559 | ||
|
|
7922955217 | ||
|
|
c90b40a96f | ||
|
|
72ff3317fa | ||
|
|
b00db26910 | ||
|
|
b31252a7b3 | ||
|
|
a836967445 | ||
|
|
ced5a2e7a4 | ||
|
|
270abea478 | ||
|
|
efc9b29360 | ||
|
|
b9d289c9d2 | ||
|
|
1562e13e19 | ||
|
|
0b00ba2304 | ||
|
|
5f5b731fbe | ||
|
|
dd7df0df81 | ||
|
|
0e454f8143 | ||
|
|
f61be56f2e | ||
|
|
f33af5fc41 | ||
|
|
861d354d15 | ||
|
|
07b419801c | ||
|
|
be2be4583c | ||
|
|
b05168ac6f | ||
|
|
c70e7a26c4 | ||
|
|
daf9975853 | ||
|
|
7a03c64ceb | ||
|
|
29a0b3d0a1 | ||
|
|
1c09d39b1e | ||
|
|
439c6322f2 | ||
|
|
d093a89829 | ||
|
|
6ffd59485a | ||
|
|
7dd7cdda8c | ||
|
|
15e4537ea6 | ||
|
|
4403cf161c | ||
|
|
7a950b838a | ||
|
|
21d3aea934 | ||
|
|
342d3fabf4 | ||
|
|
4b95cb12ef | ||
|
|
8ff87c2e7a | ||
|
|
149c69ce64 | ||
|
|
933291c5fc | ||
|
|
29c36d88e2 | ||
|
|
4b167af50e | ||
|
|
7d0ea79798 | ||
|
|
375eab288d | ||
|
|
8e2ddd974a | ||
|
|
d78c3e2669 | ||
|
|
a83d4e363b | ||
|
|
334623454d | ||
|
|
a7aa3e7885 | ||
|
|
2e1022c116 | ||
|
|
355d38acb7 | ||
|
|
1e9887ac46 | ||
|
|
8538dd231f | ||
|
|
5793140e89 | ||
|
|
56ecff1a09 | ||
|
|
eff8f92016 |
3
.github/workflows/laravel-dev.yml
vendored
3
.github/workflows/laravel-dev.yml
vendored
@@ -10,6 +10,9 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: shivammathur/setup-php@b7d1d9c9a92d8d8463ce36d7f60da34d461724f8
|
||||
with:
|
||||
php-version: '7.4'
|
||||
- uses: actions/checkout@v2
|
||||
- name: Copy .env
|
||||
run: php -r "file_exists('.env') || copy('.env.example', '.env');"
|
||||
|
||||
3
.github/workflows/laravel-pr.yml
vendored
3
.github/workflows/laravel-pr.yml
vendored
@@ -10,6 +10,9 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: shivammathur/setup-php@b7d1d9c9a92d8d8463ce36d7f60da34d461724f8
|
||||
with:
|
||||
php-version: '7.4'
|
||||
- uses: actions/checkout@v2
|
||||
- name: Copy .env
|
||||
run: php -r "file_exists('.env') || copy('.env.example', '.env');"
|
||||
|
||||
3
.github/workflows/laravel-stable.yml
vendored
3
.github/workflows/laravel-stable.yml
vendored
@@ -10,6 +10,9 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: shivammathur/setup-php@b7d1d9c9a92d8d8463ce36d7f60da34d461724f8
|
||||
with:
|
||||
php-version: '7.4'
|
||||
- uses: actions/checkout@v2
|
||||
- name: Copy .env
|
||||
run: php -r "file_exists('.env') || copy('.env.example', '.env');"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Speedtest Tracker
|
||||
|
||||
[](https://hub.docker.com/r/henrywhitaker3/speedtest-tracker) [](https://github.com/henrywhitaker3/Speedtest-Tracker/actions) [](https://github.com/henrywhitaker3/Speedtest-Tracker/actions) [](https://github.com/henrywhitaker3/Speedtest-Tracker/commits) [](https://github.com/henrywhitaker3/Speedtest-Tracker/issues) [](https://github.com/henrywhitaker3/Speedtest-Tracker/commits)  [](https://github.com/henrywhitaker3/Speedtest-Tracker/blob/master/LICENSE)
|
||||
[](https://hub.docker.com/r/henrywhitaker3/speedtest-tracker) [](https://github.com/henrywhitaker3/Speedtest-Tracker/actions) [](https://github.com/henrywhitaker3/Speedtest-Tracker/actions) [](https://github.com/henrywhitaker3/Speedtest-Tracker/commits) [](https://github.com/henrywhitaker3/Speedtest-Tracker/issues) [](https://github.com/henrywhitaker3/Speedtest-Tracker/commits)  [](https://github.com/henrywhitaker3/Speedtest-Tracker/blob/master/LICENSE)
|
||||
|
||||
This program runs a speedtest check every hour and graphs the results. The back-end is written in [Laravel](https://laravel.com/) and the front-end uses [React](https://reactjs.org/). It uses the [Ookla's speedtest cli](https://www.speedtest.net/apps/cli) package to get the data and uses [Chart.js](https://www.chartjs.org/) to plot the results.
|
||||
|
||||
@@ -100,4 +100,4 @@ After enabling, you should change the password through the web UI.
|
||||
|
||||
### Manual Install
|
||||
|
||||
For manual installtions, please follow the instrucitons [here](https://github.com/henrywhitaker3/Speedtest-Tracker/wiki/Manual-Installation).
|
||||
For manual installations, please follow the instructions [here](https://github.com/henrywhitaker3/Speedtest-Tracker/wiki/Manual-Installation).
|
||||
|
||||
@@ -28,7 +28,9 @@ class Kernel extends ConsoleKernel
|
||||
*/
|
||||
protected function schedule(Schedule $schedule)
|
||||
{
|
||||
$schedule->job(new SpeedtestJob(true, config('integrations')))->cron(SettingsHelper::get('schedule')['value']);
|
||||
if ((bool)SettingsHelper::get('schedule_enabled')->value) {
|
||||
$schedule->job(new SpeedtestJob(true, config('integrations')))->cron(SettingsHelper::get('schedule')['value']);
|
||||
}
|
||||
$schedule->command('speedtest:overview')->cron('0 ' . SettingsHelper::get('speedtest_overview_time')->value . ' * * *');
|
||||
$schedule->command('speedtest:clear-sessions')->everyMinute();
|
||||
}
|
||||
@@ -40,7 +42,7 @@ class Kernel extends ConsoleKernel
|
||||
*/
|
||||
protected function commands()
|
||||
{
|
||||
$this->load(__DIR__.'/Commands');
|
||||
$this->load(__DIR__ . '/Commands');
|
||||
|
||||
require base_path('routes/console.php');
|
||||
}
|
||||
|
||||
@@ -7,7 +7,8 @@ use App\Setting;
|
||||
use Cache;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class SettingsHelper {
|
||||
class SettingsHelper
|
||||
{
|
||||
|
||||
/**
|
||||
* Get a Setting object by name
|
||||
@@ -19,9 +20,9 @@ class SettingsHelper {
|
||||
{
|
||||
$name = Setting::where('name', $name)->get();
|
||||
|
||||
if(sizeof($name) == 0) {
|
||||
if (sizeof($name) == 0) {
|
||||
return false;
|
||||
} else if(sizeof($name) == 1) {
|
||||
} else if (sizeof($name) == 1) {
|
||||
return $name[0];
|
||||
} else {
|
||||
$name = $name->keyBy('name');
|
||||
@@ -40,11 +41,11 @@ class SettingsHelper {
|
||||
{
|
||||
$setting = SettingsHelper::get($name);
|
||||
|
||||
if($value === false) {
|
||||
if ($value === false) {
|
||||
$value = "0";
|
||||
}
|
||||
|
||||
if($setting !== false) {
|
||||
if ($setting !== false) {
|
||||
$setting->value = $value;
|
||||
$setting->save();
|
||||
} else {
|
||||
@@ -54,7 +55,7 @@ class SettingsHelper {
|
||||
]);
|
||||
}
|
||||
|
||||
if($name == 'show_failed_tests_on_graph') {
|
||||
if ($name == 'show_failed_tests_on_graph') {
|
||||
Cache::flush();
|
||||
}
|
||||
|
||||
@@ -69,13 +70,13 @@ class SettingsHelper {
|
||||
public static function getBase()
|
||||
{
|
||||
$base = env('BASE_PATH', '/');
|
||||
if($base == '') {
|
||||
if ($base == '') {
|
||||
$base = '/';
|
||||
} else {
|
||||
if($base[0] != '/') {
|
||||
if ($base[0] != '/') {
|
||||
$base = '/' . $base;
|
||||
}
|
||||
if($base[-1] != '/') {
|
||||
if ($base[-1] != '/') {
|
||||
$base = $base . '/';
|
||||
}
|
||||
}
|
||||
@@ -90,12 +91,17 @@ class SettingsHelper {
|
||||
*/
|
||||
public static function settingIsEditable(string $key)
|
||||
{
|
||||
// Manual override for app_name
|
||||
if ($key === 'app_name') {
|
||||
return true;
|
||||
}
|
||||
|
||||
$results = [];
|
||||
|
||||
// Try exact key
|
||||
$val = exec('echo $' . $key);
|
||||
|
||||
if($val == "") {
|
||||
if ($val == "") {
|
||||
array_push($results, true);
|
||||
} else {
|
||||
array_push($results, false);
|
||||
@@ -104,25 +110,25 @@ class SettingsHelper {
|
||||
// Try key all caps
|
||||
$val = exec('echo $' . strtoupper($key));
|
||||
|
||||
if($val == "") {
|
||||
if ($val == "") {
|
||||
array_push($results, true);
|
||||
} else {
|
||||
array_push($results, false);
|
||||
}
|
||||
|
||||
if(env($key, false) == false) {
|
||||
if (env($key, false) == false) {
|
||||
array_push($results, true);
|
||||
} else {
|
||||
array_push($results, false);
|
||||
}
|
||||
|
||||
if(env(strtoupper($key), false) == false) {
|
||||
if (env(strtoupper($key), false) == false) {
|
||||
array_push($results, true);
|
||||
} else {
|
||||
array_push($results, false);
|
||||
}
|
||||
|
||||
if(in_array(false, $results)) {
|
||||
if (in_array(false, $results)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -138,6 +144,12 @@ class SettingsHelper {
|
||||
{
|
||||
return [
|
||||
'base' => SettingsHelper::getBase(),
|
||||
'name' => SettingsHelper::get('app_name')->value,
|
||||
'widgets' => [
|
||||
'show_average' => (bool)SettingsHelper::get('show_average')->value,
|
||||
'show_max' => (bool)SettingsHelper::get('show_max')->value,
|
||||
'show_min' => (bool)SettingsHelper::get('show_min')->value,
|
||||
],
|
||||
'graphs' => [
|
||||
'download_upload_graph_enabled' => SettingsHelper::get('download_upload_graph_enabled'),
|
||||
'download_upload_graph_width' => SettingsHelper::get('download_upload_graph_width'),
|
||||
@@ -163,15 +175,15 @@ class SettingsHelper {
|
||||
*/
|
||||
public static function testNotification($agent = true)
|
||||
{
|
||||
$agents = [ 'slack', 'telegram' ];
|
||||
$agents = ['slack', 'telegram'];
|
||||
|
||||
if($agent === true) {
|
||||
if ($agent === true) {
|
||||
event(new TestNotificationEvent($agents));
|
||||
return true;
|
||||
}
|
||||
|
||||
if(in_array($agent, $agents)) {
|
||||
event(new TestNotificationEvent([ $agent ]));
|
||||
if (in_array($agent, $agents)) {
|
||||
event(new TestNotificationEvent([$agent]));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -188,14 +200,14 @@ class SettingsHelper {
|
||||
'telegram_chat_id' => SettingsHelper::get('telegram_chat_id')->value,
|
||||
];
|
||||
|
||||
foreach($settings as $key => $value) {
|
||||
foreach ($settings as $key => $value) {
|
||||
$key = 'integrations.' . $key;
|
||||
|
||||
if($value === "") {
|
||||
if ($value === "") {
|
||||
$value = null;
|
||||
}
|
||||
|
||||
config()->set([ $key => $value ]);
|
||||
config()->set([$key => $value]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,9 +15,9 @@ class SettingsController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
if((bool)SettingsHelper::get('auth')->value === true) {
|
||||
if ((bool)SettingsHelper::get('auth')->value === true) {
|
||||
$this->middleware('auth:api')
|
||||
->except([ 'config' ]);
|
||||
->except(['config']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,21 +51,21 @@ class SettingsController extends Controller
|
||||
public function store(Request $request)
|
||||
{
|
||||
$rule = [
|
||||
'name' => [ 'required', 'string', 'min:1' ],
|
||||
'name' => ['required', 'string', 'min:1'],
|
||||
];
|
||||
if($request->name == 'schedule') {
|
||||
$rule['value'] = [ 'required', new Cron ];
|
||||
if ($request->name == 'schedule') {
|
||||
$rule['value'] = ['required', new Cron];
|
||||
}
|
||||
|
||||
$validator = Validator::make($request->all(), $rule);
|
||||
if($validator->fails()) {
|
||||
if ($validator->fails()) {
|
||||
return response()->json([
|
||||
'method' => 'Store a setting',
|
||||
'error' => $validator->errors()
|
||||
], 422);
|
||||
}
|
||||
|
||||
if(!isset($request->value)) {
|
||||
if (!isset($request->value)) {
|
||||
$request->value = '';
|
||||
}
|
||||
|
||||
@@ -86,12 +86,12 @@ class SettingsController extends Controller
|
||||
public function bulkStore(Request $request)
|
||||
{
|
||||
$rule = [
|
||||
'data' => [ 'array', 'required' ],
|
||||
'data.*.name' => [ 'string', 'required' ],
|
||||
'data' => ['array', 'required'],
|
||||
'data.*.name' => ['string', 'required'],
|
||||
];
|
||||
|
||||
$validator = Validator::make($request->all(), $rule);
|
||||
if($validator->fails()) {
|
||||
if ($validator->fails()) {
|
||||
return response()->json([
|
||||
'method' => 'Bulk store a setting',
|
||||
'error' => $validator->errors()
|
||||
@@ -99,14 +99,14 @@ class SettingsController extends Controller
|
||||
}
|
||||
|
||||
$settings = [];
|
||||
foreach($request->data as $d) {
|
||||
if(!isset($d['value']) || $d['value'] == null) {
|
||||
$d['value'] = '';
|
||||
foreach ($request->data as $d) {
|
||||
if (!isset($d['value']) || $d['value'] == null) {
|
||||
$d['value'] = '';
|
||||
}
|
||||
|
||||
if($d['name'] == 'speedtest_overview_time') {
|
||||
$ok = [ '00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23' ];
|
||||
if(!in_array($d['value'], $ok)) {
|
||||
if ($d['name'] == 'speedtest_overview_time') {
|
||||
$ok = ['00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23'];
|
||||
if (!in_array($d['value'], $ok)) {
|
||||
return response()->json([
|
||||
'method' => 'Bulk store a setting',
|
||||
'error' => 'Invalid speedtest_overview_time value'
|
||||
@@ -116,9 +116,9 @@ class SettingsController extends Controller
|
||||
|
||||
$setting = SettingsHelper::get($d['name']);
|
||||
|
||||
if($setting == false) {
|
||||
if ($setting == false) {
|
||||
$setting = SettingsHelper::set($d['name'], $d['value']);
|
||||
} else if(SettingsHelper::settingIsEditable($setting->name)) {
|
||||
} else if (SettingsHelper::settingIsEditable($setting->name)) {
|
||||
$setting = SettingsHelper::set($d['name'], $d['value']);
|
||||
} else {
|
||||
continue;
|
||||
|
||||
@@ -18,9 +18,9 @@ class SpeedtestController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
if((bool)SettingsHelper::get('auth')->value === true) {
|
||||
if ((bool)SettingsHelper::get('auth')->value === true) {
|
||||
$this->middleware('auth:api')
|
||||
->only([ 'run', 'delete', 'deleteAll' ]);
|
||||
->only(['run', 'delete', 'deleteAll']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ class SpeedtestController extends Controller
|
||||
public function index()
|
||||
{
|
||||
$data = Speedtest::orderBy('created_at', 'desc')
|
||||
->paginate();
|
||||
->paginate();
|
||||
|
||||
return response()->json([
|
||||
'method' => 'index of speedtests',
|
||||
@@ -49,12 +49,12 @@ class SpeedtestController extends Controller
|
||||
public function time($days)
|
||||
{
|
||||
$rule = [
|
||||
'days' => [ 'required', 'integer' ],
|
||||
'days' => ['required', 'integer'],
|
||||
];
|
||||
|
||||
$validator = Validator::make([ 'days' => $days ], $rule);
|
||||
$validator = Validator::make(['days' => $days], $rule);
|
||||
|
||||
if($validator->fails()) {
|
||||
if ($validator->fails()) {
|
||||
return response()->json([
|
||||
'method' => 'get speedtests in last x days',
|
||||
'error' => $validator->errors(),
|
||||
@@ -65,16 +65,16 @@ class SpeedtestController extends Controller
|
||||
$data = Cache::remember('speedtest-days-' . $days, $ttl, function () use ($days) {
|
||||
$showFailed = (bool)SettingsHelper::get('show_failed_tests_on_graph')->value;
|
||||
|
||||
if($showFailed === true) {
|
||||
if ($showFailed === true) {
|
||||
return Speedtest::where('created_at', '>=', Carbon::now()->subDays($days))
|
||||
->orderBy('created_at', 'asc')
|
||||
->get();
|
||||
->orderBy('created_at', 'asc')
|
||||
->get();
|
||||
}
|
||||
|
||||
return Speedtest::where('created_at', '>=', Carbon::now()->subDays($days))
|
||||
->where('failed', false)
|
||||
->orderBy('created_at', 'asc')
|
||||
->get();
|
||||
->where('failed', false)
|
||||
->orderBy('created_at', 'asc')
|
||||
->get();
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
@@ -93,12 +93,12 @@ class SpeedtestController extends Controller
|
||||
public function fail($days)
|
||||
{
|
||||
$rule = [
|
||||
'days' => [ 'required', 'integer' ],
|
||||
'days' => ['required', 'integer'],
|
||||
];
|
||||
|
||||
$validator = Validator::make([ 'days' => $days ], $rule);
|
||||
$validator = Validator::make(['days' => $days], $rule);
|
||||
|
||||
if($validator->fails()) {
|
||||
if ($validator->fails()) {
|
||||
return response()->json([
|
||||
'method' => 'get speedtests in last x days',
|
||||
'error' => $validator->errors(),
|
||||
@@ -122,20 +122,38 @@ class SpeedtestController extends Controller
|
||||
public function latest()
|
||||
{
|
||||
$data = SpeedtestHelper::latest();
|
||||
$avg = Speedtest::select(DB::raw('AVG(ping) as ping, AVG(download) as download, AVG(upload) as upload'))
|
||||
->where('failed', false)
|
||||
->get();
|
||||
$max = Speedtest::select(DB::raw('MAX(ping) as ping, MAX(download) as download, MAX(upload) as upload'))
|
||||
->where('failed', false)
|
||||
->get();
|
||||
|
||||
if($data) {
|
||||
return response()->json([
|
||||
'method' => 'get latest speedtest',
|
||||
'data' => $data,
|
||||
'average' => $avg[0],
|
||||
'max' => $max[0],
|
||||
], 200);
|
||||
$response = [
|
||||
'method' => 'get latest speedtest',
|
||||
'data' => $data,
|
||||
];
|
||||
|
||||
if (SettingsHelper::get('show_average')) {
|
||||
$avg = Speedtest::select(DB::raw('AVG(ping) as ping, AVG(download) as download, AVG(upload) as upload'))
|
||||
->where('failed', false)
|
||||
->first()
|
||||
->toArray();
|
||||
$response['average'] = $avg;
|
||||
}
|
||||
|
||||
if (SettingsHelper::get('show_max')) {
|
||||
$max = Speedtest::select(DB::raw('MAX(ping) as ping, MAX(download) as download, MAX(upload) as upload'))
|
||||
->where('failed', false)
|
||||
->first()
|
||||
->toArray();
|
||||
$response['maximum'] = $max;
|
||||
}
|
||||
|
||||
if (SettingsHelper::get('show_min')) {
|
||||
$min = Speedtest::select(DB::raw('MIN(ping) as ping, MIN(download) as download, MIN(upload) as upload'))
|
||||
->where('failed', false)
|
||||
->first()
|
||||
->toArray();
|
||||
$response['minimum'] = $min;
|
||||
}
|
||||
|
||||
if ($data) {
|
||||
return response()->json($response, 200);
|
||||
} else {
|
||||
return response()->json([
|
||||
'method' => 'get latest speedtest',
|
||||
@@ -158,7 +176,7 @@ class SpeedtestController extends Controller
|
||||
'method' => 'run speedtest',
|
||||
'data' => 'a new speedtest has been added to the queue'
|
||||
], 200);
|
||||
} catch(Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
return response()->json([
|
||||
'method' => 'run speedtest',
|
||||
'error' => $e
|
||||
@@ -175,7 +193,7 @@ class SpeedtestController extends Controller
|
||||
{
|
||||
$ret = SpeedtestHelper::deleteAll();
|
||||
|
||||
if($ret['success']) {
|
||||
if ($ret['success']) {
|
||||
return response()->json([
|
||||
'method' => 'delete all speedtests from the database',
|
||||
'success' => true
|
||||
|
||||
@@ -52,19 +52,19 @@ class SpeedtestJob implements ShouldQueue
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
if($this->config['healthchecks_enabled'] === true) {
|
||||
if ($this->config['healthchecks_enabled'] === true) {
|
||||
$this->healthcheck('start');
|
||||
}
|
||||
$output = SpeedtestHelper::output();
|
||||
$speedtest = SpeedtestHelper::runSpeedtest($output, $this->scheduled);
|
||||
if($speedtest == false) {
|
||||
if($this->config['healthchecks_enabled'] === true) {
|
||||
if ($speedtest == false) {
|
||||
if ($this->config['healthchecks_enabled'] === true) {
|
||||
$this->healthcheck('fail');
|
||||
}
|
||||
|
||||
event(new SpeedtestFailedEvent());
|
||||
} else {
|
||||
if($this->config['healthchecks_enabled'] === true) {
|
||||
if ($this->config['healthchecks_enabled'] === true) {
|
||||
$this->healthcheck('success');
|
||||
}
|
||||
|
||||
@@ -82,19 +82,19 @@ class SpeedtestJob implements ShouldQueue
|
||||
private function healthcheck(String $method)
|
||||
{
|
||||
try {
|
||||
$hc = new Healthchecks(SettingsHelper::get('healthchecks_uuid')->value);
|
||||
if($method === 'start') {
|
||||
$hc = new Healthchecks(SettingsHelper::get('healthchecks_uuid')->value, SettingsHelper::get('healthchecks_server_url')->value);
|
||||
if ($method === 'start') {
|
||||
$hc->start();
|
||||
}
|
||||
|
||||
if($method === 'success') {
|
||||
if ($method === 'success') {
|
||||
$hc->success();
|
||||
}
|
||||
|
||||
if($method === 'fail') {
|
||||
if ($method === 'fail') {
|
||||
$hc->fail();
|
||||
}
|
||||
} catch(Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
Log::error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,18 +35,20 @@ class IntegrationsServiceProvider extends ServiceProvider
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
if(File::exists(env('DB_DATABASE'))) {
|
||||
if(Schema::hasTable('settings')) {
|
||||
if (File::exists(env('DB_DATABASE'))) {
|
||||
if (Schema::hasTable('settings')) {
|
||||
$setting = SettingsHelper::get('healthchecks_uuid');
|
||||
|
||||
if($setting !== false) {
|
||||
if ($setting !== false) {
|
||||
try {
|
||||
App::bind('healthcheck', function() use ($setting) {
|
||||
return new Healthchecks($setting->value);
|
||||
SettingsHelper::loadIntegrationConfig();
|
||||
|
||||
App::bind('healthcheck', function () use ($setting) {
|
||||
return new Healthchecks($setting->value, SettingsHelper::get('healthchecks_server_url')->value);
|
||||
});
|
||||
} catch(InvalidUuidStringException $e) {
|
||||
} catch (InvalidUuidStringException $e) {
|
||||
Log::error('Invalid healthchecks UUID');
|
||||
} catch(Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
Log::error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,70 @@
|
||||
{
|
||||
"1.10.4": [
|
||||
{
|
||||
"description": "Updated dependencies.",
|
||||
"link": ""
|
||||
}
|
||||
],
|
||||
"1.10.3": [
|
||||
{
|
||||
"description": "Moved stuff into pages.",
|
||||
"link": ""
|
||||
}
|
||||
],
|
||||
"1.10.2": [
|
||||
{
|
||||
"description": "Added option to disable scheduled tests.",
|
||||
"link": ""
|
||||
}
|
||||
],
|
||||
"1.10.1": [
|
||||
{
|
||||
"description": "Fixed integrations config being empty causing healthchecks to not run on scheduled tests.",
|
||||
"link": ""
|
||||
}
|
||||
],
|
||||
"1.10.0": [
|
||||
{
|
||||
"description": "Added automated build for ARM.",
|
||||
"link": ""
|
||||
},
|
||||
{
|
||||
"description": "Updated dependencies.",
|
||||
"link": ""
|
||||
}
|
||||
],
|
||||
"1.9.10": [
|
||||
{
|
||||
"description": "Laravel will now log into daily files and logs will only be kept for 7 days.",
|
||||
"link": ""
|
||||
}
|
||||
],
|
||||
"1.9.9": [
|
||||
{
|
||||
"description": "Updated dependencies.",
|
||||
"link": ""
|
||||
}
|
||||
],
|
||||
"1.9.8": [
|
||||
{
|
||||
"description": "Fixed bug with minimum display setting.",
|
||||
"link": ""
|
||||
}
|
||||
],
|
||||
"1.9.7": [
|
||||
{
|
||||
"description": "Added option to display minimum values on the top widgets.",
|
||||
"link": ""
|
||||
},
|
||||
{
|
||||
"description": "New general settings section.",
|
||||
"link": ""
|
||||
},
|
||||
{
|
||||
"description": "Updated dependencies.",
|
||||
"link": ""
|
||||
}
|
||||
],
|
||||
"1.9.6": [
|
||||
{
|
||||
"description": "Clear the cache on restore.",
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
"fruitcake/laravel-cors": "^2.0",
|
||||
"guzzlehttp/guzzle": "^7.0",
|
||||
"henrywhitaker3/healthchecks-io": "^1.0",
|
||||
"laravel-notification-channels/telegram": "^0.4.0",
|
||||
"laravel-notification-channels/telegram": "^0.5.0",
|
||||
"laravel/framework": "^7.0",
|
||||
"laravel/slack-notification-channel": "^2.0",
|
||||
"laravel/tinker": "^2.0",
|
||||
@@ -27,9 +27,9 @@
|
||||
"facade/ignition": "^2.0",
|
||||
"fzaninotto/faker": "^1.9.1",
|
||||
"mockery/mockery": "^1.3.1",
|
||||
"nunomaduro/collision": "^4.1",
|
||||
"nunomaduro/larastan": "^0.6.2",
|
||||
"phpunit/phpunit": "^8.5"
|
||||
"phpunit/phpunit": "^9.5",
|
||||
"nunomaduro/larastan": "^0.7.0",
|
||||
"nunomaduro/collision": "^5.3"
|
||||
},
|
||||
"config": {
|
||||
"optimize-autoloader": true,
|
||||
|
||||
3341
composer.lock
generated
3341
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -37,7 +37,7 @@ return [
|
||||
'channels' => [
|
||||
'stack' => [
|
||||
'driver' => 'stack',
|
||||
'channels' => ['single'],
|
||||
'channels' => ['daily'],
|
||||
'ignore_exceptions' => false,
|
||||
],
|
||||
|
||||
@@ -51,7 +51,7 @@ return [
|
||||
'driver' => 'daily',
|
||||
'path' => storage_path('logs/laravel.log'),
|
||||
'level' => 'debug',
|
||||
'days' => 14,
|
||||
'days' => 7,
|
||||
],
|
||||
|
||||
'slack' => [
|
||||
|
||||
@@ -7,7 +7,7 @@ return [
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
'version' => '1.9.6',
|
||||
'version' => '1.10.4',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
use App\Helpers\SettingsHelper;
|
||||
use App\Setting;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddWidgetCardSettings extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
if (!SettingsHelper::get('show_average')) {
|
||||
Setting::create([
|
||||
'name' => 'show_average',
|
||||
'value' => true,
|
||||
'description' => 'If enabled, the average value for speedtests will be shown in the widgets.'
|
||||
]);
|
||||
}
|
||||
|
||||
if (!SettingsHelper::get('show_max')) {
|
||||
Setting::create([
|
||||
'name' => 'show_max',
|
||||
'value' => true,
|
||||
'description' => 'If enabled, the maximum value for speedtests will be shown in the widgets.'
|
||||
]);
|
||||
}
|
||||
|
||||
if (!SettingsHelper::get('show_min')) {
|
||||
Setting::create([
|
||||
'name' => 'show_min',
|
||||
'value' => true,
|
||||
'description' => 'If enabled, the minimum value for speedtests will be shown in the widgets.'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Setting::whereIn('name', [
|
||||
'show_average',
|
||||
'show_max',
|
||||
'show_min',
|
||||
])->delete();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
use App\Helpers\SettingsHelper;
|
||||
use App\Setting;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddScheduleEnabledSetting extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
if (!SettingsHelper::get('schedule_enabled')) {
|
||||
Setting::create([
|
||||
'name' => 'schedule_enabled',
|
||||
'value' => true,
|
||||
'description' => 'Enable/disable the schedule worker'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Setting::whereIn('name', [
|
||||
'schedule_enabled',
|
||||
])->delete();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
use App\Helpers\SettingsHelper;
|
||||
use App\Setting;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddAppNameSetting extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
if (!SettingsHelper::get('app_name')) {
|
||||
Setting::create([
|
||||
'name' => 'app_name',
|
||||
'value' => 'Speedtest Tracker',
|
||||
'description' => 'Set a custom app name'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Setting::whereIn('name', [
|
||||
'app_name',
|
||||
])->delete();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
use App\Helpers\SettingsHelper;
|
||||
use App\Setting;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddCustomHealthchecksSetting extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
if (!SettingsHelper::get('healthchecks_server_url')) {
|
||||
Setting::create([
|
||||
'name' => 'healthchecks_server_url',
|
||||
'value' => 'https://hc-ping.com/',
|
||||
'description' => 'The URL of the healthchecks.io server. Change this to use a self-hosted server.'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Setting::whereIn('name', [
|
||||
'healthchecks_server_url',
|
||||
])->delete();
|
||||
}
|
||||
}
|
||||
2170
package-lock.json
generated
2170
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
32
package.json
32
package.json
@@ -10,29 +10,29 @@
|
||||
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/preset-react": "^7.10.4",
|
||||
"axios": "^0.20",
|
||||
"bootstrap": "^4.5.2",
|
||||
"axios": "^0.21",
|
||||
"@babel/preset-react": "^7.12.13",
|
||||
"bootstrap": "^4.6.0",
|
||||
"cross-env": "^7.0",
|
||||
"jquery": "^3.5",
|
||||
"laravel-mix": "^5.0.5",
|
||||
"lodash": "^4.17.20",
|
||||
"laravel-mix": "^5.0.9",
|
||||
"lodash": "^4.17.21",
|
||||
"popper.js": "^1.12",
|
||||
"react": "^16.2.0",
|
||||
"react-dom": "^16.2.0",
|
||||
"resolve-url-loader": "^3.1.0",
|
||||
"sass": "^1.26.10",
|
||||
"sass-loader": "^10.0.1"
|
||||
"react": "^17.0.1",
|
||||
"react-dom": "^17.0.1",
|
||||
"resolve-url-loader": "^3.1.2",
|
||||
"sass": "^1.32.8",
|
||||
"sass-loader": "^10.1.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/plugin-proposal-class-properties": "^7.10.4",
|
||||
"chart.js": "^2.9.3",
|
||||
"csv-file-validator": "^1.8.0",
|
||||
"@babel/plugin-proposal-class-properties": "^7.13.0",
|
||||
"chart.js": "^2.9.4",
|
||||
"csv-file-validator": "^1.10.1",
|
||||
"js-cookie": "^2.2.1",
|
||||
"react-bootstrap": "^1.3.0",
|
||||
"react-chartjs-2": "^2.10.0",
|
||||
"react-bootstrap": "^1.5.1",
|
||||
"react-chartjs-2": "^2.11.1",
|
||||
"react-router": "^5.2.0",
|
||||
"react-router-dom": "^5.2.0",
|
||||
"react-toastify": "^6.0.8"
|
||||
"react-toastify": "^7.0.3"
|
||||
}
|
||||
}
|
||||
|
||||
51
phpunit.xml
51
phpunit.xml
@@ -1,29 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
|
||||
bootstrap="vendor/autoload.php"
|
||||
colors="true">
|
||||
<testsuites>
|
||||
<testsuite name="Unit">
|
||||
<directory suffix="Test.php">./tests/Unit</directory>
|
||||
</testsuite>
|
||||
<testsuite name="Feature">
|
||||
<directory suffix="Test.php">./tests/Feature</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<filter>
|
||||
<whitelist processUncoveredFilesFromWhitelist="true">
|
||||
<directory suffix=".php">./app</directory>
|
||||
</whitelist>
|
||||
</filter>
|
||||
<php>
|
||||
<server name="APP_ENV" value="testing"/>
|
||||
<server name="BCRYPT_ROUNDS" value="4"/>
|
||||
<server name="CACHE_DRIVER" value="array"/>
|
||||
<server name="DB_CONNECTION" value="sqlite"/>
|
||||
<server name="DB_DATABASE" value=":memory:"/>
|
||||
<server name="MAIL_MAILER" value="array"/>
|
||||
<server name="QUEUE_CONNECTION" value="sync"/>
|
||||
<server name="SESSION_DRIVER" value="array"/>
|
||||
</php>
|
||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" bootstrap="vendor/autoload.php" colors="true">
|
||||
<coverage processUncoveredFiles="true">
|
||||
<include>
|
||||
<directory suffix=".php">./app</directory>
|
||||
</include>
|
||||
</coverage>
|
||||
<testsuites>
|
||||
<testsuite name="Unit">
|
||||
<directory suffix="Test.php">./tests/Unit</directory>
|
||||
</testsuite>
|
||||
<testsuite name="Feature">
|
||||
<directory suffix="Test.php">./tests/Feature</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<php>
|
||||
<server name="APP_ENV" value="testing"/>
|
||||
<server name="BCRYPT_ROUNDS" value="4"/>
|
||||
<server name="CACHE_DRIVER" value="array"/>
|
||||
<server name="DB_CONNECTION" value="sqlite"/>
|
||||
<server name="DB_DATABASE" value=":memory:"/>
|
||||
<server name="MAIL_MAILER" value="array"/>
|
||||
<server name="QUEUE_CONNECTION" value="sync"/>
|
||||
<server name="SESSION_DRIVER" value="array"/>
|
||||
</php>
|
||||
</phpunit>
|
||||
|
||||
10946
public/css/app.css
vendored
10946
public/css/app.css
vendored
File diff suppressed because one or more lines are too long
138415
public/js/app.js
vendored
138415
public/js/app.js
vendored
File diff suppressed because one or more lines are too long
@@ -12,7 +12,7 @@ License: MIT
|
||||
*/
|
||||
|
||||
/*!
|
||||
* Bootstrap v4.5.2 (https://getbootstrap.com/)
|
||||
* Bootstrap v4.5.3 (https://getbootstrap.com/)
|
||||
* Copyright 2011-2020 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
|
||||
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
||||
*/
|
||||
@@ -24,9 +24,9 @@ License: MIT
|
||||
*/
|
||||
|
||||
/*!
|
||||
* Chart.js v2.9.3
|
||||
* Chart.js v2.9.4
|
||||
* https://www.chartjs.org
|
||||
* (c) 2019 Chart.js Contributors
|
||||
* (c) 2020 Chart.js Contributors
|
||||
* Released under the MIT License
|
||||
*/
|
||||
|
||||
@@ -81,15 +81,6 @@ License: MIT
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
/** @license React v16.13.1
|
||||
* react-dom.production.min.js
|
||||
*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
/** @license React v16.13.1
|
||||
* react-is.production.min.js
|
||||
*
|
||||
@@ -99,7 +90,16 @@ License: MIT
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
/** @license React v16.13.1
|
||||
/** @license React v16.14.0
|
||||
* react-dom.production.min.js
|
||||
*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
/** @license React v16.14.0
|
||||
* react.production.min.js
|
||||
*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
@@ -132,3 +132,7 @@ License: MIT
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
//! moment.js
|
||||
|
||||
//! moment.js locale configuration
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import React, { Component } from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import { Container, Row, Col, Collapse, Button, Modal } from 'react-bootstrap';
|
||||
import { Row, Col} from 'react-bootstrap';
|
||||
import SessionsTable from './SessionsTable';
|
||||
import ResetPassword from './ResetPassword';
|
||||
|
||||
@@ -44,34 +44,18 @@ export default class Authentication extends Component {
|
||||
|
||||
if( (window.config.auth == true && window.authenticated == true)) {
|
||||
return (
|
||||
<Container className="mb-4">
|
||||
<div>
|
||||
<Row>
|
||||
<Col sm={{ span: 12 }} className="mb-3 text-center">
|
||||
<div className="mouse" aria-controls="testsTable" onClick={this.toggleCollapse} aria-expanded={showCollapse}>
|
||||
<h4 className="d-inline mr-2">Authentication</h4>
|
||||
{(showCollapse) ?
|
||||
<span className="ti-angle-up"></span>
|
||||
:
|
||||
<span className="ti-angle-down"></span>
|
||||
}
|
||||
</div>
|
||||
<Col sm={{ span: 12 }} className="text-center">
|
||||
<ResetPassword />
|
||||
</Col>
|
||||
</Row>
|
||||
<Collapse in={showCollapse}>
|
||||
<div>
|
||||
<Row>
|
||||
<Col sm={{ span: 12 }} className="text-center">
|
||||
<ResetPassword />
|
||||
</Col>
|
||||
</Row>
|
||||
<Row>
|
||||
<Col sm={{ span: 12 }} className="text-center">
|
||||
<SessionsTable />
|
||||
</Col>
|
||||
</Row>
|
||||
</div>
|
||||
</Collapse>
|
||||
</Container>
|
||||
<Row>
|
||||
<Col sm={{ span: 12 }} className="text-center">
|
||||
<SessionsTable />
|
||||
</Col>
|
||||
</Row>
|
||||
</div>
|
||||
);
|
||||
} else {
|
||||
return (
|
||||
|
||||
@@ -37,6 +37,10 @@ export default class HistoryGraph extends Component {
|
||||
});
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
clearInterval(this.state.interval);
|
||||
}
|
||||
|
||||
getDLULPing = (days) => {
|
||||
var url = 'api/speedtest/time/' + days;
|
||||
|
||||
|
||||
@@ -26,6 +26,10 @@ export default class LatestResults extends Component {
|
||||
});
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
clearInterval(this.state.interval);
|
||||
}
|
||||
|
||||
getData = () => {
|
||||
var url = 'api/speedtest/latest';
|
||||
|
||||
@@ -131,9 +135,7 @@ export default class LatestResults extends Component {
|
||||
>
|
||||
<Widget
|
||||
title="Ping"
|
||||
value={parseFloat(data.data.ping).toFixed(1)}
|
||||
avg={parseFloat(data.average.ping).toFixed(1)}
|
||||
max={parseFloat(data.max.ping).toFixed(1)}
|
||||
data={data}
|
||||
failed={data.data.failed}
|
||||
unit="ms"
|
||||
icon="ping"
|
||||
@@ -147,9 +149,7 @@ export default class LatestResults extends Component {
|
||||
>
|
||||
<Widget
|
||||
title="Download"
|
||||
value={parseFloat(data.data.download).toFixed(1)}
|
||||
avg={parseFloat(data.average.download).toFixed(1)}
|
||||
max={parseFloat(data.max.download).toFixed(1)}
|
||||
data={data}
|
||||
failed={data.data.failed}
|
||||
unit="Mbit/s"
|
||||
icon="dl"
|
||||
@@ -163,9 +163,7 @@ export default class LatestResults extends Component {
|
||||
>
|
||||
<Widget
|
||||
title="Upload"
|
||||
value={parseFloat(data.data.upload).toFixed(1)}
|
||||
avg={parseFloat(data.average.upload).toFixed(1)}
|
||||
max={parseFloat(data.max.upload).toFixed(1)}
|
||||
data={data}
|
||||
failed={data.data.failed}
|
||||
unit="Mbit/s"
|
||||
icon="ul"
|
||||
|
||||
89
resources/js/components/Graphics/TestsTable.js
vendored
89
resources/js/components/Graphics/TestsTable.js
vendored
@@ -26,6 +26,10 @@ export default class TestsTable extends Component {
|
||||
});
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
clearInterval(this.state.interval);
|
||||
}
|
||||
|
||||
getData = (page = this.state.page, refresh = true) => {
|
||||
var url = 'api/speedtest/?page=' + page;
|
||||
|
||||
@@ -83,59 +87,48 @@ export default class TestsTable extends Component {
|
||||
|
||||
if(data.length > 0) {
|
||||
return (
|
||||
<Container className="mb-4 mt-4" fluid>
|
||||
<Row>
|
||||
<Col sm={{ span: 12 }} className="mb-3 text-center">
|
||||
<div className="mouse" aria-controls="testsTable" onClick={this.toggleCollapse} aria-expanded={show}>
|
||||
<h4 className="d-inline mr-2">All tests</h4>
|
||||
{(show) ?
|
||||
<span className="ti-angle-up"></span>
|
||||
:
|
||||
<span className="ti-angle-down"></span>
|
||||
}
|
||||
</div>
|
||||
{(show) &&
|
||||
<div className="my-1">
|
||||
<div>
|
||||
<Container className="mb-4 mt-4 px-5">
|
||||
<Row>
|
||||
<Col sm={{ span: 12 }} className="mb-3 text-center">
|
||||
<div>
|
||||
<h4 className="d-inline mr-2">All tests</h4>
|
||||
<span className="text-muted">Auto refresh: {(refresh) ? 'On' : 'Off'}</span>
|
||||
</div>
|
||||
}
|
||||
</Col>
|
||||
</Row>
|
||||
<Collapse in={show}>
|
||||
<div>
|
||||
</Col>
|
||||
</Row>
|
||||
<Row>
|
||||
<Col sm={{ span: 12 }} id="testsTable">
|
||||
<Table responsive>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Time</th>
|
||||
<th>Download (Mbit/s)</th>
|
||||
<th>Upload (Mbit/s)</th>
|
||||
<th>Ping (ms)</th>
|
||||
<th>More</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{data.map((e,i) => {
|
||||
return (
|
||||
<TableRow key={e.id} data={e} />
|
||||
);
|
||||
})}
|
||||
</tbody>
|
||||
</Table>
|
||||
</Col>
|
||||
</Row>
|
||||
{page < lastPage &&
|
||||
<Row>
|
||||
<Col sm={{ span: 12 }} id="testsTable">
|
||||
<Table responsive>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Time</th>
|
||||
<th>Download (Mbit/s)</th>
|
||||
<th>Upload (Mbit/s)</th>
|
||||
<th>Ping (ms)</th>
|
||||
<th>More</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{data.map((e,i) => {
|
||||
return (
|
||||
<TableRow key={e.id} data={e} />
|
||||
);
|
||||
})}
|
||||
</tbody>
|
||||
</Table>
|
||||
<Col sm={{ span: 12 }} className="text-center">
|
||||
<Button variant="primary" onClick={this.getMoreData}>Show more</Button>
|
||||
</Col>
|
||||
</Row>
|
||||
{page < lastPage &&
|
||||
<Row>
|
||||
<Col sm={{ span: 12 }} className="text-center">
|
||||
<Button variant="primary" onClick={this.getMoreData}>Show more</Button>
|
||||
</Col>
|
||||
</Row>
|
||||
}
|
||||
</div>
|
||||
</Collapse>
|
||||
</Container>
|
||||
}
|
||||
</Container>
|
||||
</div>
|
||||
);
|
||||
} else {
|
||||
return (
|
||||
|
||||
101
resources/js/components/Graphics/Widget.js
vendored
101
resources/js/components/Graphics/Widget.js
vendored
@@ -8,38 +8,88 @@ export default class Widget extends Component {
|
||||
|
||||
this.state = {
|
||||
title: this.props.title,
|
||||
value: this.props.value,
|
||||
unit: this.props.unit,
|
||||
icon: this.props.icon,
|
||||
avg: this.props.avg,
|
||||
max: this.props.max,
|
||||
failed: this.props.failed,
|
||||
data: this.props.data
|
||||
}
|
||||
}
|
||||
|
||||
parseData(title, data) {
|
||||
var returnData = {};
|
||||
|
||||
|
||||
if(title == 'Ping') {
|
||||
returnData.value = parseFloat(data.data.ping).toFixed(1);
|
||||
|
||||
if(window.config.widgets.show_average) {
|
||||
returnData.avg = parseFloat(data.average.ping).toFixed(1);
|
||||
}
|
||||
|
||||
if(window.config.widgets.show_max) {
|
||||
returnData.max = parseFloat(data.maximum.ping).toFixed(1);
|
||||
}
|
||||
|
||||
if(window.config.widgets.show_min) {
|
||||
returnData.min = parseFloat(data.minimum.ping).toFixed(1);
|
||||
}
|
||||
}
|
||||
|
||||
if(title == 'Upload') {
|
||||
returnData.value = parseFloat(data.data.upload).toFixed(1);
|
||||
|
||||
if(window.config.widgets.show_average) {
|
||||
returnData.avg = parseFloat(data.average.upload).toFixed(1);
|
||||
}
|
||||
|
||||
if(window.config.widgets.show_max) {
|
||||
returnData.max = parseFloat(data.maximum.upload).toFixed(1);
|
||||
}
|
||||
|
||||
if(window.config.widgets.show_min) {
|
||||
returnData.min = parseFloat(data.minimum.upload).toFixed(1);
|
||||
}
|
||||
}
|
||||
|
||||
if(title == 'Download') {
|
||||
returnData.value = parseFloat(data.data.download).toFixed(1);
|
||||
|
||||
if(window.config.widgets.show_average) {
|
||||
returnData.avg = parseFloat(data.average.download).toFixed(1);
|
||||
}
|
||||
|
||||
if(window.config.widgets.show_max) {
|
||||
returnData.max = parseFloat(data.maximum.download).toFixed(1);
|
||||
}
|
||||
|
||||
if(window.config.widgets.show_min) {
|
||||
returnData.min = parseFloat(data.minimum.download).toFixed(1);
|
||||
}
|
||||
}
|
||||
|
||||
return returnData;
|
||||
}
|
||||
|
||||
componentDidUpdate = () => {
|
||||
if(this.props.title != this.state.title || this.props.value != this.state.value || this.props.unit != this.state.unit || this.props.icon != this.state.icon || this.props.avg != this.state.avg || this.props.max != this.state.max || this.props.failed != this.state.failed) {
|
||||
if(this.props.title != this.state.title || this.props.data != this.state.data || this.props.unit != this.state.unit || this.props.icon != this.state.icon || this.props.failed != this.state.failed) {
|
||||
this.setState({
|
||||
title: this.props.title,
|
||||
value: this.props.value,
|
||||
unit: this.props.unit,
|
||||
icon: this.props.icon,
|
||||
avg: this.props.avg,
|
||||
max: this.props.max,
|
||||
failed: this.props.failed,
|
||||
data: this.props.data
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
var title = this.state.title;
|
||||
var value = this.state.value;
|
||||
var unit = this.state.unit;
|
||||
var icon = this.state.icon;
|
||||
var max = this.state.max;
|
||||
var avg = this.state.avg;
|
||||
var failed = Boolean(Number(this.state.failed));
|
||||
|
||||
var data = this.parseData(title, this.state.data);
|
||||
|
||||
switch(icon) {
|
||||
case 'ping':
|
||||
icon = <span className="ti-pulse icon text-success"></span>;
|
||||
@@ -63,17 +113,30 @@ export default class Widget extends Component {
|
||||
</div>
|
||||
|
||||
<div className="text-truncate">
|
||||
<h3 className="d-inline">{(!failed) ? value : <span className="ti-close text-danger"></span> }</h3>
|
||||
<h3 className="d-inline">{(!failed) ? data.value : <span className="ti-close text-danger"></span> }</h3>
|
||||
<p className="d-inline ml-2">{unit} (current)</p>
|
||||
</div>
|
||||
<div className="text-muted text-truncate">
|
||||
<h5 className="d-inline">{avg}</h5>
|
||||
<p className="d-inline ml-2">{unit} (average)</p>
|
||||
</div>
|
||||
<div className="text-muted text-truncate">
|
||||
<h5 className="d-inline">{max}</h5>
|
||||
<p className="d-inline ml-2">{unit} (maximum)</p>
|
||||
</div>
|
||||
|
||||
{window.config.widgets.show_average &&
|
||||
<div className="text-muted text-truncate">
|
||||
<h5 className="d-inline">{data.avg}</h5>
|
||||
<p className="d-inline ml-2">{unit} (average)</p>
|
||||
</div>
|
||||
}
|
||||
|
||||
{window.config.widgets.show_max &&
|
||||
<div className="text-muted text-truncate">
|
||||
<h5 className="d-inline">{data.max}</h5>
|
||||
<p className="d-inline ml-2">{unit} (maximum)</p>
|
||||
</div>
|
||||
}
|
||||
|
||||
{window.config.widgets.show_min &&
|
||||
<div className="text-muted text-truncate">
|
||||
<h5 className="d-inline">{data.min}</h5>
|
||||
<p className="d-inline ml-2">{unit} (minimum)</p>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</Card.Body>
|
||||
|
||||
7
resources/js/components/Home/HomePage.js
vendored
7
resources/js/components/Home/HomePage.js
vendored
@@ -5,25 +5,22 @@ import LatestResults from '../Graphics/LatestResults';
|
||||
import Footer from './Footer';
|
||||
import DataRow from '../Data/DataRow';
|
||||
import TestsTable from '../Graphics/TestsTable';
|
||||
import Settings from '../Settings/Settings';
|
||||
import Login from '../Login';
|
||||
import Authentication from '../Authentication/Authentication';
|
||||
import Navbar from '../Navbar';
|
||||
|
||||
export default class HomePage extends Component {
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div>
|
||||
<Navbar />
|
||||
<div className="my-4">
|
||||
{(window.config.auth == true && window.authenticated == false) &&
|
||||
<Login />
|
||||
}
|
||||
<LatestResults />
|
||||
<HistoryGraph />
|
||||
<TestsTable />
|
||||
<Settings />
|
||||
<Authentication />
|
||||
<DataRow />
|
||||
</div>
|
||||
<Footer />
|
||||
</div>
|
||||
|
||||
3
resources/js/components/Login.js
vendored
3
resources/js/components/Login.js
vendored
@@ -39,6 +39,9 @@ export default class Login extends Component {
|
||||
Cookies.set('auth', token, { expires: expires })
|
||||
window.location.reload(true);
|
||||
})
|
||||
.catch((err) => {
|
||||
toast.error('Something went wrong logging in.');
|
||||
})
|
||||
}
|
||||
|
||||
toggleShow = () => {
|
||||
|
||||
64
resources/js/components/Navbar.js
vendored
64
resources/js/components/Navbar.js
vendored
@@ -1,19 +1,77 @@
|
||||
import React, { Component } from 'react';
|
||||
import {Nav, Navbar as BootstrapNavbar, NavLink as BootstrapNavLink} from 'react-bootstrap';
|
||||
import ReactDOM from 'react-dom';
|
||||
import { Link, NavLink } from 'react-router-dom';
|
||||
|
||||
export default class Navbar extends Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
|
||||
this.state = {
|
||||
|
||||
brand: {
|
||||
name: window.config.name,
|
||||
url: window.config.base
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
generatePagesArray() {
|
||||
var pages = [
|
||||
{
|
||||
name: 'Home',
|
||||
url: window.config.base,
|
||||
authRequired: false
|
||||
},
|
||||
{
|
||||
name: 'All Tests',
|
||||
url: window.config.base + 'speedtests',
|
||||
authRequired: false
|
||||
},
|
||||
{
|
||||
name: 'Settings',
|
||||
url: window.config.base + 'settings',
|
||||
authRequired: true
|
||||
},
|
||||
]
|
||||
|
||||
return pages;
|
||||
}
|
||||
|
||||
generateLinks = () => {
|
||||
var pages = this.generatePagesArray();
|
||||
|
||||
return pages.map(page => {
|
||||
if(
|
||||
page.authRequired === false ||
|
||||
(
|
||||
page.authRequired === true &&
|
||||
window.config.auth &&
|
||||
window.authenticated
|
||||
) ||
|
||||
(
|
||||
page.authRequired === true &&
|
||||
window.config.auth === false
|
||||
)
|
||||
) {
|
||||
return <BootstrapNavLink key={page.url} as={NavLink} to={page.url}>{page.name}</BootstrapNavLink>;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
var brand = this.state.brand;
|
||||
var pages = this.generateLinks();
|
||||
|
||||
return (
|
||||
<div>
|
||||
</div>
|
||||
<BootstrapNavbar variant="dark" bg="dark" expand="sm">
|
||||
<BootstrapNavbar.Brand as={Link} to={brand.url}><img style={{width: '15%'}} src={window.config.base + 'files/icons/fav/android-icon-192x192.png'} /> {brand.name}</BootstrapNavbar.Brand>
|
||||
<BootstrapNavbar.Toggle aria-controls="basic-navbar-nav" />
|
||||
<BootstrapNavbar.Collapse id="basic-navbar-nav">
|
||||
<Nav className="ml-auto">
|
||||
{pages}
|
||||
</Nav>
|
||||
</BootstrapNavbar.Collapse>
|
||||
</BootstrapNavbar>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
77
resources/js/components/Settings/Setting.js
vendored
77
resources/js/components/Settings/Setting.js
vendored
@@ -1,77 +0,0 @@
|
||||
import React, { Component } from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import { Card, Form, Button } from 'react-bootstrap';
|
||||
import Axios from 'axios';
|
||||
import { toast } from 'react-toastify';
|
||||
|
||||
export default class Setting extends Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
|
||||
this.state = {
|
||||
name: this.props.name,
|
||||
value: this.props.value,
|
||||
description: this.props.description,
|
||||
}
|
||||
}
|
||||
|
||||
ucfirst(string) {
|
||||
return string.charAt(0).toUpperCase() + string.slice(1);
|
||||
}
|
||||
|
||||
update = () => {
|
||||
var url = 'api/settings?token=' + window.token;
|
||||
var data = {
|
||||
name: this.state.name,
|
||||
value: this.state.value
|
||||
};
|
||||
|
||||
Axios.post(url, data)
|
||||
.then((resp) => {
|
||||
toast.success(this.ucfirst(this.state.name) + ' updated');
|
||||
})
|
||||
.catch((err) => {
|
||||
if(err.response.status == 422) {
|
||||
var errors = err.response.data.error;
|
||||
for(var key in errors) {
|
||||
var error = errors[key];
|
||||
toast.error(error[0])
|
||||
}
|
||||
} else {
|
||||
toast.error('Something went wrong')
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
updateValue = (e) => {
|
||||
this.setState({
|
||||
value: e.target.value
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
var name = this.state.name;
|
||||
var value = this.state.value;
|
||||
var description = this.state.description;
|
||||
|
||||
return (
|
||||
<Card className="m-2 setting-card">
|
||||
<Card.Body className="d-flex align-items-center">
|
||||
<div>
|
||||
<h4>{this.ucfirst(name)}</h4>
|
||||
<div dangerouslySetInnerHTML={{ __html: description}} />
|
||||
<Form.Group controlId={name}>
|
||||
<Form.Label>{this.ucfirst(name)}</Form.Label>
|
||||
<Form.Control type="text" label={name} defaultValue={value} onInput={this.updateValue} />
|
||||
</Form.Group>
|
||||
<Button variant="primary" onClick={this.update}>Save</Button>
|
||||
</div>
|
||||
</Card.Body>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (document.getElementById('Setting')) {
|
||||
ReactDOM.render(<Setting />, document.getElementById('Setting'));
|
||||
}
|
||||
292
resources/js/components/Settings/SettingWithModal.js
vendored
292
resources/js/components/Settings/SettingWithModal.js
vendored
@@ -1,292 +0,0 @@
|
||||
import React, { Component } from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import { Card, Form, Button, Modal, Row, Col } from 'react-bootstrap';
|
||||
import Axios from 'axios';
|
||||
import { toast } from 'react-toastify';
|
||||
import SettingsModalCard from '../Settings/SettingsModalCard';
|
||||
|
||||
export default class SettingWithModal extends Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
|
||||
this.state = {
|
||||
title: this.props.title,
|
||||
description: this.props.description,
|
||||
settings: this.props.settings,
|
||||
show: false,
|
||||
autoClose: this.props.autoClose
|
||||
}
|
||||
}
|
||||
|
||||
ucfirst(string) {
|
||||
return string.charAt(0).toUpperCase() + string.slice(1);
|
||||
}
|
||||
|
||||
update = () => {
|
||||
var url = 'api/settings/bulk?token=' + window.token;
|
||||
var data = [];
|
||||
var settings = this.state.settings;
|
||||
|
||||
settings.forEach(e => {
|
||||
if(e.type !== 'button-get') {
|
||||
var res = {
|
||||
name: e.obj.name,
|
||||
value: e.obj.value
|
||||
};
|
||||
data.push(res);
|
||||
}
|
||||
});
|
||||
|
||||
data = {
|
||||
data: data
|
||||
};
|
||||
|
||||
Axios.post(url, data)
|
||||
.then((resp) => {
|
||||
toast.success(this.state.title + ' updated');
|
||||
if(this.state.autoClose) {
|
||||
this.toggleShow();
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
if(err.response.status == 422) {
|
||||
toast.error('Your input was invalid');
|
||||
} else {
|
||||
toast.error('Something went wrong')
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
updateValue = (e) => {
|
||||
var name = e.target.id;
|
||||
if(e.target.type == 'checkbox') {
|
||||
var val = e.target.checked;
|
||||
} else {
|
||||
var val = e.target.value;
|
||||
}
|
||||
var settings = this.state.settings;
|
||||
var i = 0;
|
||||
settings.forEach(ele => {
|
||||
if(ele.obj.name == name) {
|
||||
ele.obj.value = val;
|
||||
}
|
||||
settings[i] = ele;
|
||||
i++;
|
||||
});
|
||||
this.setState({
|
||||
settings: settings
|
||||
});
|
||||
}
|
||||
|
||||
toggleShow = () => {
|
||||
var show = this.state.show;
|
||||
if(show) {
|
||||
this.setState({
|
||||
show: false
|
||||
});
|
||||
} else {
|
||||
this.setState({
|
||||
show: true
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
var title = this.state.title;
|
||||
var description = this.state.description;
|
||||
var show = this.state.show;
|
||||
var settings = this.state.settings;
|
||||
|
||||
return (
|
||||
<>
|
||||
<SettingsModalCard title={title} description={description} toggleShow={this.toggleShow} />
|
||||
<Modal show={show} onHide={this.toggleShow}>
|
||||
<Modal.Header closeButton>
|
||||
<Modal.Title>{title}</Modal.Title>
|
||||
</Modal.Header>
|
||||
<Modal.Body>
|
||||
{settings.map((e,i) => {
|
||||
var name = e.obj.name.split('_');
|
||||
name[0] = this.ucfirst(name[0]);
|
||||
name = name.join(' ');
|
||||
|
||||
if(e.obj.description == null || e.obj.description == '') {
|
||||
var sm = { span: 12 };
|
||||
var md = { span: 12 };
|
||||
} else {
|
||||
var sm = { span: 12 };
|
||||
var md = { span: 6 };
|
||||
}
|
||||
|
||||
var readonly = false;
|
||||
if(window.config.editable[e.obj.name] == false) {
|
||||
readonly = true;
|
||||
}
|
||||
|
||||
if(e.type == 'info') {
|
||||
return (
|
||||
<Row key={e.obj.id} className="d-flex align-items-center">
|
||||
<Col md={md} sm={sm}>
|
||||
<p>{e.obj.content}</p>
|
||||
</Col>
|
||||
</Row>
|
||||
)
|
||||
} else if(e.type == 'checkbox') {
|
||||
return (
|
||||
<Row key={e.obj.id} className="d-flex align-items-center">
|
||||
<Col md={md} sm={sm}>
|
||||
<Form.Group controlId={e.obj.name}>
|
||||
{readonly ?
|
||||
<>
|
||||
<Form.Check type="checkbox" disabled label={name} defaultChecked={Boolean(Number(e.obj.value))} onInput={this.updateValue} />
|
||||
<Form.Text className="text-muted">This setting is defined as an env variable and is not editable.</Form.Text>
|
||||
</>
|
||||
:
|
||||
<Form.Check type="checkbox" label={name} defaultChecked={Boolean(Number(e.obj.value))} onInput={this.updateValue} />
|
||||
}
|
||||
</Form.Group>
|
||||
</Col>
|
||||
{e.description == null &&
|
||||
<Col md={md} sm={sm}>
|
||||
<p>{e.obj.description}</p>
|
||||
</Col>
|
||||
}
|
||||
</Row>
|
||||
);
|
||||
} else if(e.type == 'number') {
|
||||
return (
|
||||
<Row key={e.obj.id}>
|
||||
<Col md={md} sm={sm}>
|
||||
<Form.Group controlId={e.obj.name}>
|
||||
<Form.Label>{name}</Form.Label>
|
||||
{readonly ?
|
||||
<>
|
||||
<Form.Control type="number" disabled min={e.min} max={e.max} defaultValue={e.obj.value} onInput={this.updateValue} />
|
||||
<Form.Text className="text-muted">This setting is defined as an env variable and is not editable.</Form.Text>
|
||||
</>
|
||||
:
|
||||
<Form.Control type="number" min={e.min} max={e.max} defaultValue={e.obj.value} onInput={this.updateValue} />
|
||||
}
|
||||
</Form.Group>
|
||||
</Col>
|
||||
{e.description == null &&
|
||||
<Col md={md} sm={sm}>
|
||||
<p>{e.obj.description}</p>
|
||||
</Col>
|
||||
}
|
||||
</Row>
|
||||
);
|
||||
} else if(e.type == 'text') {
|
||||
return (
|
||||
<Row key={e.obj.id}>
|
||||
<Col md={md} sm={sm}>
|
||||
<Form.Group controlId={e.obj.name}>
|
||||
<Form.Label>{name}</Form.Label>
|
||||
{readonly ?
|
||||
<>
|
||||
<Form.Control type="text" disabled defaultValue={e.obj.value} onInput={this.updateValue} />
|
||||
<Form.Text className="text-muted">This setting is defined as an env variable and is not editable.</Form.Text>
|
||||
</>
|
||||
:
|
||||
<Form.Control type="text" defaultValue={e.obj.value} onInput={this.updateValue} />
|
||||
}
|
||||
</Form.Group>
|
||||
</Col>
|
||||
{e.description == null &&
|
||||
<Col md={md} sm={sm}>
|
||||
<p>{e.obj.description}</p>
|
||||
</Col>
|
||||
}
|
||||
</Row>
|
||||
);
|
||||
} else if(e.type == 'select') {
|
||||
return (
|
||||
<Row key={e.obj.id}>
|
||||
<Col md={md} sm={sm}>
|
||||
<Form.Group controlId={e.obj.name}>
|
||||
<Form.Label>{name}</Form.Label>
|
||||
{readonly ?
|
||||
<>
|
||||
<Form.Control as="select" disabled defaultValue={e.obj.value} onInput={this.updateValue}>
|
||||
{e.options.map((e,i) => {
|
||||
return (
|
||||
<option key={i} value={e.value}>{e.name}</option>
|
||||
)
|
||||
})}
|
||||
</Form.Control>
|
||||
<Form.Text className="text-muted">This setting is defined as an env variable and is not editable.</Form.Text>
|
||||
</>
|
||||
:
|
||||
<Form.Control as="select" defaultValue={e.obj.value} onInput={this.updateValue}>
|
||||
{e.options.map((e,i) => {
|
||||
return (
|
||||
<option key={i} value={e.value}>{e.name}</option>
|
||||
)
|
||||
})}
|
||||
</Form.Control>
|
||||
}
|
||||
</Form.Group>
|
||||
</Col>
|
||||
{e.description == null &&
|
||||
<Col md={md} sm={sm}>
|
||||
<p>{e.obj.description}</p>
|
||||
</Col>
|
||||
}
|
||||
</Row>
|
||||
)
|
||||
} else if(e.type == 'button-get') {
|
||||
return (
|
||||
<Row key={e.obj.id}>
|
||||
<Col md={md} sm={sm}>
|
||||
<p>{name}</p>
|
||||
<Button onClick={() => { Axios.get(e.url) }} >{name}</Button>
|
||||
</Col>
|
||||
{e.description == null &&
|
||||
<Col md={md} sm={sm}>
|
||||
<p>{e.obj.description}</p>
|
||||
</Col>
|
||||
}
|
||||
</Row>
|
||||
)
|
||||
} else if(e.type == 'group') {
|
||||
return (
|
||||
<div key={e.obj.id}>
|
||||
<Row>
|
||||
<Col md={md} sm={sm}>
|
||||
<p className="mb-0">{name}</p>
|
||||
</Col>
|
||||
{e.description == null &&
|
||||
<Col md={md} sm={sm}>
|
||||
<p>{e.obj.description}</p>
|
||||
</Col>
|
||||
}
|
||||
</Row>
|
||||
<Row>
|
||||
<Col sm={{ span: 12 }}>
|
||||
{e.children.map((ee,ii) => {
|
||||
if(ee.type == 'button-get') {
|
||||
return (
|
||||
<Button key={ii} variant={ee.btnType} className={'mr-2 mb-3'} onClick={() => { Axios.get(ee.url)
|
||||
.then((resp) => { toast.success('Healthcheck sent') })
|
||||
.catch((resp) => { resp = resp.response; toast.error(resp.data.error) })
|
||||
}} >{ee.text}</Button>
|
||||
)
|
||||
}
|
||||
})}
|
||||
</Col>
|
||||
</Row>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
})}
|
||||
<Button variant="primary" type="submit" onClick={this.update} >Save</Button>
|
||||
</Modal.Body>
|
||||
</Modal>
|
||||
</>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (document.getElementById('Setting')) {
|
||||
ReactDOM.render(<Setting />, document.getElementById('Setting'));
|
||||
}
|
||||
305
resources/js/components/Settings/Settings.js
vendored
305
resources/js/components/Settings/Settings.js
vendored
@@ -1,305 +0,0 @@
|
||||
import React, { Component } from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import { Modal, Container, Row, Col, Collapse } from 'react-bootstrap';
|
||||
import Loader from '../Loader';
|
||||
import Axios from 'axios';
|
||||
import Setting from './Setting';
|
||||
import SettingWithModal from './SettingWithModal';
|
||||
import ResetSettings from './ResetSettings';
|
||||
|
||||
export default class Settings extends Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
|
||||
this.state = {
|
||||
show: false,
|
||||
loading: true,
|
||||
data: [],
|
||||
}
|
||||
}
|
||||
|
||||
componentDidMount = () => {
|
||||
if( (window.config.auth == true && window.authenticated == true) || window.config.auth == false) {
|
||||
this.getData();
|
||||
}
|
||||
}
|
||||
|
||||
toggleShow = () => {
|
||||
if(this.state.show) {
|
||||
var show = false;
|
||||
} else {
|
||||
var show = true;
|
||||
}
|
||||
|
||||
this.setState({
|
||||
show: show
|
||||
});
|
||||
}
|
||||
|
||||
getData = () => {
|
||||
var url = 'api/settings/?token=' + window.token;
|
||||
|
||||
Axios.get(url)
|
||||
.then((resp) => {
|
||||
this.setState({
|
||||
loading: false,
|
||||
data: resp.data
|
||||
});
|
||||
})
|
||||
.catch((err) => {
|
||||
if(err.response) {
|
||||
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
buildSettingsCards = () => {
|
||||
var e = this.state.data;
|
||||
|
||||
return (
|
||||
<Row>
|
||||
<Col lg={{ span: 4 }} md={{ span: 6 }} sm={{ span: 12 }}>
|
||||
<Setting name={e.schedule.name} value={e.schedule.value} description={e.schedule.description} />
|
||||
</Col>
|
||||
<Col lg={{ span: 4 }} md={{ span: 6 }} sm={{ span: 12 }}>
|
||||
<Setting name={e.server.name} value={e.server.value} description={e.server.description} />
|
||||
</Col>
|
||||
<Col lg={{ span: 4 }} md={{ span: 6 }} sm={{ span: 12 }}>
|
||||
<SettingWithModal title="Graph settings" description="Control settings for the graphs." autoClose={true} settings={[
|
||||
{
|
||||
obj: e.download_upload_graph_enabled,
|
||||
type: 'checkbox'
|
||||
},
|
||||
{
|
||||
obj: e.download_upload_graph_width,
|
||||
type: 'select',
|
||||
options: [
|
||||
{
|
||||
name: 'Full-width',
|
||||
'value': 12
|
||||
},
|
||||
{
|
||||
name: 'Half-width',
|
||||
'value': 6
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
obj: e.ping_graph_enabled,
|
||||
type: 'checkbox'
|
||||
},
|
||||
{
|
||||
obj: e.ping_graph_width,
|
||||
type: 'select',
|
||||
options: [
|
||||
{
|
||||
name: 'Full-width',
|
||||
'value': 12
|
||||
},
|
||||
{
|
||||
name: 'Half-width',
|
||||
'value': 6
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
obj: e.failure_graph_enabled,
|
||||
type: 'checkbox'
|
||||
},
|
||||
{
|
||||
obj: e.failure_graph_width,
|
||||
type: 'select',
|
||||
options: [
|
||||
{
|
||||
name: 'Full-width',
|
||||
'value': 12
|
||||
},
|
||||
{
|
||||
name: 'Half-width',
|
||||
'value': 6
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
obj: e.show_failed_tests_on_graph,
|
||||
type: 'checkbox'
|
||||
}
|
||||
]} />
|
||||
</Col>
|
||||
<Col lg={{ span: 4 }} md={{ span: 6 }} sm={{ span: 12 }}>
|
||||
<SettingWithModal title="Notification settings" description="Control which types of notifications the server sends." autoClose={false} settings={[
|
||||
{
|
||||
obj: e.slack_webhook,
|
||||
type: 'text'
|
||||
},
|
||||
{
|
||||
obj: e.telegram_bot_token,
|
||||
type: 'text'
|
||||
},
|
||||
{
|
||||
obj: e.telegram_chat_id,
|
||||
type: 'text'
|
||||
},
|
||||
{
|
||||
obj: {
|
||||
id: (Math.floor(Math.random() * 10000) + 1),
|
||||
name: "Test notifications",
|
||||
description: "After saving your updated notification settings, use this to check your settings are correct."
|
||||
},
|
||||
type: 'button-get',
|
||||
url: 'api/settings/test-notification?token=' + window.token
|
||||
},
|
||||
{
|
||||
obj: e.speedtest_notifications,
|
||||
type: 'checkbox'
|
||||
},
|
||||
{
|
||||
obj: e.speedtest_overview_notification,
|
||||
type: 'checkbox'
|
||||
},
|
||||
{
|
||||
obj: e.speedtest_overview_time,
|
||||
type: 'number',
|
||||
min: 0,
|
||||
max: 23
|
||||
},
|
||||
{
|
||||
obj: {
|
||||
id: (Math.floor(Math.random() * 10000) + 1),
|
||||
name: "Conditional Notifications",
|
||||
description: ""
|
||||
},
|
||||
type: 'group',
|
||||
children: [
|
||||
|
||||
]
|
||||
},
|
||||
{
|
||||
obj: e.threshold_alert_percentage_notifications,
|
||||
type: 'checkbox',
|
||||
},
|
||||
{
|
||||
obj: e.threshold_alert_percentage,
|
||||
type: 'number',
|
||||
min: 0,
|
||||
max: 100
|
||||
},
|
||||
{
|
||||
obj: e.threshold_alert_absolute_notifications,
|
||||
type: 'checkbox',
|
||||
},
|
||||
{
|
||||
obj: e.threshold_alert_absolute_download,
|
||||
type: 'number',
|
||||
},
|
||||
{
|
||||
obj: e.threshold_alert_absolute_upload,
|
||||
type: 'number',
|
||||
},
|
||||
{
|
||||
obj: e.threshold_alert_absolute_ping,
|
||||
type: 'number',
|
||||
}
|
||||
]} />
|
||||
</Col>
|
||||
<Col lg={{ span: 4 }} md={{ span: 6 }} sm={{ span: 12 }}>
|
||||
<SettingWithModal title="healthchecks.io settings" description="Control settings for healthchecks.io" autoClose={false} settings={[
|
||||
{
|
||||
obj: e.healthchecks_uuid,
|
||||
type: 'text'
|
||||
},
|
||||
{
|
||||
obj: e.healthchecks_enabled,
|
||||
type: 'checkbox'
|
||||
},
|
||||
{
|
||||
obj: {
|
||||
id: (Math.floor(Math.random() * 10000) + 1),
|
||||
name: "Test healthchecks (after saving)",
|
||||
description: ""
|
||||
},
|
||||
type: 'group',
|
||||
children: [
|
||||
{
|
||||
type: 'button-get',
|
||||
url: 'api/settings/test-healthchecks/start?token=' + window.token,
|
||||
btnType: 'outline-success',
|
||||
text: 'Start',
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
type: 'button-get',
|
||||
url: 'api/settings/test-healthchecks/success?token=' + window.token,
|
||||
btnType: 'success',
|
||||
text: 'Success',
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
type: 'button-get',
|
||||
url: 'api/settings/test-healthchecks/fail?token=' + window.token,
|
||||
btnType: 'danger',
|
||||
text: 'Fail',
|
||||
inline: true,
|
||||
},
|
||||
]
|
||||
},
|
||||
]} />
|
||||
</Col>
|
||||
<Col lg={{ span: 4 }} md={{ span: 6 }} sm={{ span: 12 }}>
|
||||
<ResetSettings />
|
||||
</Col>
|
||||
</Row>
|
||||
)
|
||||
}
|
||||
|
||||
render() {
|
||||
var show = this.state.show;
|
||||
var loading = this.state.loading;
|
||||
var data = this.state.data;
|
||||
if(!loading) {
|
||||
var cards = this.buildSettingsCards();
|
||||
}
|
||||
if( (window.config.auth == true && window.authenticated == true) || window.config.auth == false) {
|
||||
return (
|
||||
<div>
|
||||
<Container className="my-4">
|
||||
<Row>
|
||||
<Col sm={{ span: 12 }} className="mb-3 text-center">
|
||||
<div className="mouse" onClick={this.toggleShow}>
|
||||
<h4 className="mb-0 mr-2 d-inline">Settings</h4>
|
||||
{(show) ?
|
||||
<span className="ti-angle-up"></span>
|
||||
:
|
||||
<span className="ti-angle-down"></span>
|
||||
}
|
||||
</div>
|
||||
</Col>
|
||||
</Row>
|
||||
<Collapse in={show}>
|
||||
<div>
|
||||
<Row>
|
||||
<Col sm={{ span: 12 }}>
|
||||
{loading ?
|
||||
<Loader small />
|
||||
:
|
||||
cards
|
||||
}
|
||||
</Col>
|
||||
</Row>
|
||||
</div>
|
||||
</Collapse>
|
||||
</Container>
|
||||
|
||||
</div>
|
||||
);
|
||||
} else {
|
||||
return(
|
||||
<></>
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (document.getElementById('Settings')) {
|
||||
ReactDOM.render(<Settings />, document.getElementById('Settings'));
|
||||
}
|
||||
282
resources/js/components/Settings/SettingsIndex.js
vendored
Normal file
282
resources/js/components/Settings/SettingsIndex.js
vendored
Normal file
@@ -0,0 +1,282 @@
|
||||
import Axios from 'axios';
|
||||
import React, { Component } from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import Footer from '../Home/Footer';
|
||||
import Loader from '../Loader';
|
||||
import Navbar from '../Navbar';
|
||||
import SettingsTabs from './SettingsTabs';
|
||||
|
||||
export default class SettingsIndex extends Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
|
||||
this.state = {
|
||||
data: null,
|
||||
loading: true,
|
||||
}
|
||||
}
|
||||
|
||||
getData = () => {
|
||||
var url = 'api/settings/?token=' + window.token;
|
||||
|
||||
Axios.get(url)
|
||||
.then((resp) => {
|
||||
this.setState({
|
||||
data: this.sortSettings(resp.data),
|
||||
loading: false,
|
||||
});
|
||||
})
|
||||
.catch((err) => {
|
||||
//
|
||||
})
|
||||
}
|
||||
|
||||
sortSettings = (data) => {
|
||||
return {
|
||||
General: [
|
||||
{
|
||||
obj: data.app_name,
|
||||
type: 'text',
|
||||
},
|
||||
{
|
||||
obj: data.schedule_enabled,
|
||||
type: 'checkbox',
|
||||
},
|
||||
{
|
||||
obj: data.schedule,
|
||||
type: 'text',
|
||||
},
|
||||
{
|
||||
obj: data.server,
|
||||
type: 'text',
|
||||
},
|
||||
{
|
||||
obj: data.show_average,
|
||||
type: 'checkbox',
|
||||
},
|
||||
{
|
||||
obj: data.show_max,
|
||||
type: 'checkbox',
|
||||
},
|
||||
{
|
||||
obj: data.show_min,
|
||||
type: 'checkbox',
|
||||
}
|
||||
],
|
||||
Graphs: [
|
||||
{
|
||||
obj: data.download_upload_graph_enabled,
|
||||
type: 'checkbox',
|
||||
hideDescription: true
|
||||
},
|
||||
{
|
||||
obj: data.download_upload_graph_width,
|
||||
type: 'select',
|
||||
options: [
|
||||
{
|
||||
name: 'Full-width',
|
||||
'value': 12
|
||||
},
|
||||
{
|
||||
name: 'Half-width',
|
||||
'value': 6
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
obj: data.ping_graph_enabled,
|
||||
type: 'checkbox',
|
||||
hideDescription: true
|
||||
},
|
||||
{
|
||||
obj: data.ping_graph_width,
|
||||
type: 'select',
|
||||
options: [
|
||||
{
|
||||
name: 'Full-width',
|
||||
'value': 12
|
||||
},
|
||||
{
|
||||
name: 'Half-width',
|
||||
'value': 6
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
obj: data.failure_graph_enabled,
|
||||
type: 'checkbox',
|
||||
hideDescription: true
|
||||
},
|
||||
{
|
||||
obj: data.failure_graph_width,
|
||||
type: 'select',
|
||||
options: [
|
||||
{
|
||||
name: 'Full-width',
|
||||
'value': 12
|
||||
},
|
||||
{
|
||||
name: 'Half-width',
|
||||
'value': 6
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
obj: data.show_failed_tests_on_graph,
|
||||
type: 'checkbox',
|
||||
},
|
||||
],
|
||||
Notifications: [
|
||||
{
|
||||
obj: data.slack_webhook,
|
||||
type: 'text'
|
||||
},
|
||||
{
|
||||
obj: data.telegram_bot_token,
|
||||
type: 'text'
|
||||
},
|
||||
{
|
||||
obj: data.telegram_chat_id,
|
||||
type: 'text'
|
||||
},
|
||||
{
|
||||
type: 'btn-get',
|
||||
url: 'api/settings/test-notification?token=' + window.token,
|
||||
btnType: 'primary',
|
||||
obj: {
|
||||
id: (Math.floor(Math.random() * 10000) + 1),
|
||||
name: 'Test notifications',
|
||||
description: 'After saving your updated notification settings, use this to check your settings are correct.'
|
||||
}
|
||||
},
|
||||
{
|
||||
obj: data.speedtest_notifications,
|
||||
type: 'checkbox'
|
||||
},
|
||||
{
|
||||
obj: data.speedtest_overview_notification,
|
||||
type: 'checkbox'
|
||||
},
|
||||
{
|
||||
obj: data.speedtest_overview_time,
|
||||
type: 'number',
|
||||
min: 0,
|
||||
max: 23,
|
||||
},
|
||||
// Add handling for title stuff
|
||||
{
|
||||
obj: data.threshold_alert_percentage,
|
||||
type: 'number',
|
||||
min: 0,
|
||||
max: 100
|
||||
},
|
||||
{
|
||||
obj: data.threshold_alert_absolute_notifications,
|
||||
type: 'checkbox'
|
||||
},
|
||||
{
|
||||
obj: data.threshold_alert_absolute_download,
|
||||
type: 'number'
|
||||
},
|
||||
{
|
||||
obj: data.threshold_alert_absolute_upload,
|
||||
type: 'number'
|
||||
},
|
||||
{
|
||||
obj: data.threshold_alert_absolute_ping,
|
||||
type: 'number'
|
||||
},
|
||||
],
|
||||
healthchecks: [
|
||||
{
|
||||
obj: data.healthchecks_enabled,
|
||||
type: 'checkbox'
|
||||
},
|
||||
{
|
||||
obj: data.healthchecks_server_url,
|
||||
type: 'text'
|
||||
},
|
||||
{
|
||||
obj: data.healthchecks_uuid,
|
||||
type: 'text'
|
||||
},
|
||||
{
|
||||
obj: {
|
||||
id: (Math.floor(Math.random() * 10000) + 1),
|
||||
name: "Test healthchecks.io integration",
|
||||
description: ""
|
||||
},
|
||||
},
|
||||
{
|
||||
obj: {
|
||||
id: (Math.floor(Math.random() * 10000) + 1),
|
||||
name: "Start",
|
||||
description: ""
|
||||
},
|
||||
type: 'btn-get',
|
||||
url: 'api/settings/test-healthchecks/start?token=' + window.token,
|
||||
btnType: 'outline-success',
|
||||
inline: true,
|
||||
earlyReturn: true,
|
||||
classes: 'mr-2'
|
||||
},
|
||||
{
|
||||
obj: {
|
||||
id: (Math.floor(Math.random() * 10000) + 1),
|
||||
name: "Success",
|
||||
description: ""
|
||||
},
|
||||
type: 'btn-get',
|
||||
url: 'api/settings/test-healthchecks/success?token=' + window.token,
|
||||
btnType: 'success',
|
||||
text: 'Success',
|
||||
inline: true,
|
||||
earlyReturn: true,
|
||||
classes: 'mr-2'
|
||||
},
|
||||
{
|
||||
obj: {
|
||||
id: (Math.floor(Math.random() * 10000) + 1),
|
||||
name: "Fail",
|
||||
description: ""
|
||||
},
|
||||
type: 'btn-get',
|
||||
url: 'api/settings/test-healthchecks/fail?token=' + window.token,
|
||||
btnType: 'danger',
|
||||
text: 'Fail',
|
||||
inline: true,
|
||||
earlyReturn: true,
|
||||
classes: 'mr-2'
|
||||
},
|
||||
|
||||
]
|
||||
};
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this.getData();
|
||||
}
|
||||
|
||||
render() {
|
||||
var data = this.state.data;
|
||||
var loading = this.state.loading;
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Navbar />
|
||||
<div className="container my-5">
|
||||
{loading ?
|
||||
<Loader />
|
||||
:
|
||||
<SettingsTabs data={data} />
|
||||
}
|
||||
</div>
|
||||
<Footer />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (document.getElementById('settingsIndex')) {
|
||||
ReactDOM.render(<SettingsIndex />, document.getElementById('settingsIndex'));
|
||||
}
|
||||
185
resources/js/components/Settings/SettingsInput.js
vendored
Normal file
185
resources/js/components/Settings/SettingsInput.js
vendored
Normal file
@@ -0,0 +1,185 @@
|
||||
import React, { Component } from 'react';
|
||||
import { Form } from 'react-bootstrap';
|
||||
import ReactDOM from 'react-dom';
|
||||
|
||||
export default class SettingsInput extends Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
|
||||
this.state = {
|
||||
type: this.props.type,
|
||||
name: this.props.name,
|
||||
displayName: (this.props.name) ? this.formatName(this.props.name) : '',
|
||||
value: (this.props.value) ? this.props.value : '',
|
||||
classes: this.props.classes,
|
||||
id: this.props.id,
|
||||
label: (this.props.label) ? this.props.label : false,
|
||||
readonly: true,
|
||||
description: (this.props.description) ? this.props.description : false,
|
||||
options: this.props.options ? this.props.options : [],
|
||||
hideDescription: this.props.hideDescription ? true : false,
|
||||
min: this.props.min ? this.props.min : null,
|
||||
max: this.props.max ? this.props.max : null,
|
||||
url: this.props.url,
|
||||
inline: this.props.inline ? 'd-inline-block' : 'd-block',
|
||||
btnType: this.props.btnType,
|
||||
earlyReturn: this.props.earlyReturn ? true : false,
|
||||
}
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this.setState({
|
||||
readonly: this.isReadOnly()
|
||||
});
|
||||
}
|
||||
|
||||
formatName(name) {
|
||||
name = name.split('_').join(' ');
|
||||
|
||||
return name.charAt(0).toUpperCase() + name.slice(1);
|
||||
}
|
||||
|
||||
handleInput = (evt) => {
|
||||
var val = evt.target.value;
|
||||
|
||||
if(this.state.type === 'checkbox') {
|
||||
val = evt.target.checked;
|
||||
}
|
||||
|
||||
this.props.handler(
|
||||
this.state.name,
|
||||
val
|
||||
);
|
||||
|
||||
this.setState({
|
||||
value: val
|
||||
});
|
||||
}
|
||||
|
||||
isReadOnly = () => {
|
||||
if(window.config.editable[this.state.name] == false) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
generateNumberInput(disabled) {
|
||||
return <Form.Control
|
||||
name={this.state.name}
|
||||
type={this.state.type}
|
||||
defaultValue={this.state.value}
|
||||
disabled={disabled}
|
||||
min={this.state.min}
|
||||
max={this.state.max}
|
||||
onInput={this.handleInput} />
|
||||
}
|
||||
|
||||
generateSelectInput(disabled) {
|
||||
return (
|
||||
<Form.Control
|
||||
as="select"
|
||||
name={this.state.name}
|
||||
type={this.state.type}
|
||||
defaultValue={this.state.value}
|
||||
disabled={disabled}
|
||||
onInput={this.handleInput}
|
||||
>
|
||||
{this.state.options.map((option,i) => {
|
||||
return <option key={i} value={option.value}>{option.name}</option>
|
||||
})}
|
||||
</Form.Control>
|
||||
);
|
||||
}
|
||||
|
||||
generateCheckboxInput(disabled) {
|
||||
return <Form.Control
|
||||
custom
|
||||
className="ml-2"
|
||||
name={this.state.name}
|
||||
type={this.state.type}
|
||||
defaultChecked={this.state.value}
|
||||
disabled={disabled}
|
||||
onInput={this.handleInput} />
|
||||
}
|
||||
|
||||
generateTextInput(disabled) {
|
||||
return <Form.Control
|
||||
name={this.state.name}
|
||||
type={this.state.type}
|
||||
defaultValue={this.state.value}
|
||||
disabled={disabled}
|
||||
onInput={this.handleInput} />
|
||||
}
|
||||
|
||||
generateButtonGetInput() {
|
||||
var url = this.state.url;
|
||||
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
className={"btn btn-" + this.state.btnType + ' ' + this.state.inline + ' ' + this.state.classes}
|
||||
onClick={() => {
|
||||
window.axios.get(url)
|
||||
}}
|
||||
>{this.state.displayName}</button>
|
||||
);
|
||||
}
|
||||
|
||||
generateInput = () => {
|
||||
var disabled = (this.state.readonly) ? true : false;
|
||||
var input = null;
|
||||
|
||||
if(this.state.type === 'number') {
|
||||
input = this.generateNumberInput(disabled);
|
||||
}
|
||||
|
||||
if(this.state.type === 'select') {
|
||||
input = this.generateSelectInput(disabled);
|
||||
}
|
||||
|
||||
if(this.state.type === 'checkbox') {
|
||||
input = this.generateCheckboxInput(disabled);
|
||||
}
|
||||
|
||||
if(this.state.type === 'text') {
|
||||
input = this.generateTextInput(disabled);
|
||||
}
|
||||
|
||||
if(this.state.type === 'btn-get') {
|
||||
input = this.generateButtonGetInput();
|
||||
}
|
||||
|
||||
if(this.state.earlyReturn) {
|
||||
return input;
|
||||
}
|
||||
|
||||
return (
|
||||
<Form.Group controlId={this.state.id}>
|
||||
{this.state.label &&
|
||||
<Form.Label style={{fontSize: '1.25rem'}}>{this.formatName(this.state.name)}</Form.Label>
|
||||
}
|
||||
|
||||
{input}
|
||||
|
||||
{this.state.description && !this.state.hideDescription &&
|
||||
<p className="mt-1 text-muted" dangerouslySetInnerHTML={{ __html: this.state.description }}></p>
|
||||
}
|
||||
|
||||
{this.state.readonly &&
|
||||
<Form.Text className="text-muted">This setting is defined as an env variable and is not editable.</Form.Text>
|
||||
}
|
||||
</Form.Group>
|
||||
);
|
||||
}
|
||||
|
||||
render() {
|
||||
var input = this.generateInput();
|
||||
|
||||
return input;
|
||||
}
|
||||
}
|
||||
|
||||
if (document.getElementById('SettingsInput')) {
|
||||
ReactDOM.render(<SettingsInput />, document.getElementById('SettingsInput'));
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
import React, { Component } from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import { Card, Button } from 'react-bootstrap';
|
||||
|
||||
export default class SettingsModalCard extends Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
|
||||
this.state = {
|
||||
title: this.props.title,
|
||||
description: this.props.description,
|
||||
toggleShow: this.props.toggleShow,
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
var title = this.state.title;
|
||||
var description = this.state.description;
|
||||
var toggleShow = this.state.toggleShow;
|
||||
|
||||
return (
|
||||
<Card className="m-2 setting-card">
|
||||
<Card.Body className="d-flex align-items-center">
|
||||
<div>
|
||||
<h4>{title}</h4>
|
||||
<p>{description}</p>
|
||||
<Button variant="primary" onClick={toggleShow}>Edit</Button>
|
||||
</div>
|
||||
</Card.Body>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (document.getElementById('SettingModalCard')) {
|
||||
ReactDOM.render(<SettingsModalCard />, document.getElementById('SettingModalCard'));
|
||||
}
|
||||
177
resources/js/components/Settings/SettingsTabs.js
vendored
Normal file
177
resources/js/components/Settings/SettingsTabs.js
vendored
Normal file
@@ -0,0 +1,177 @@
|
||||
import Axios from 'axios';
|
||||
import React, { Component } from 'react';
|
||||
import { Nav, Tab, Tabs } from 'react-bootstrap';
|
||||
import ReactDOM from 'react-dom';
|
||||
import { toast } from 'react-toastify';
|
||||
import SettingsInput from './SettingsInput';
|
||||
import ResetSettings from './tabs/ResetSettings';
|
||||
import BackupSettings from './tabs/BackupSettings';
|
||||
import GeneralSettings from './tabs/GeneralSettings';
|
||||
import GraphsSettings from './tabs/GraphsSettings';
|
||||
import HealthchecksSettings from './tabs/HealthchecksSettings';
|
||||
import NotificationsSettings from './tabs/NotificationsSettings';
|
||||
import Authentication from '../Authentication/Authentication';
|
||||
|
||||
export default class SettingsTabs extends Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
|
||||
this.state = {
|
||||
tab: "General",
|
||||
data: this.props.data
|
||||
}
|
||||
}
|
||||
|
||||
generateTabs = () => {
|
||||
var tabs = [
|
||||
'General',
|
||||
'Graphs',
|
||||
'Notifications',
|
||||
'healthchecks.io',
|
||||
'Reset',
|
||||
'Backup/Restore',
|
||||
];
|
||||
|
||||
if(window.config.auth) {
|
||||
tabs.push('Authentication');
|
||||
}
|
||||
|
||||
return tabs.map((tab) => {
|
||||
return <Tab key={tab} eventKey={tab} title={tab} />
|
||||
});
|
||||
}
|
||||
|
||||
switchTab = (tab) => {
|
||||
this.setState({
|
||||
tab: tab
|
||||
});
|
||||
}
|
||||
|
||||
save = (settings, name) => {
|
||||
var url = 'api/settings/bulk?token=' + window.token;
|
||||
var data = [];
|
||||
|
||||
settings.forEach(e => {
|
||||
if(e.type !== 'btn-get') {
|
||||
var res = {
|
||||
name: e.obj.name,
|
||||
value: e.obj.value
|
||||
};
|
||||
data.push(res);
|
||||
}
|
||||
});
|
||||
|
||||
data = {
|
||||
data: data
|
||||
};
|
||||
|
||||
Axios.post(url, data)
|
||||
.then((resp) => {
|
||||
toast.success(name + ' settings updated');
|
||||
Axios.get('api/settings/config')
|
||||
.then((resp) => {
|
||||
window.config = resp.data;
|
||||
})
|
||||
})
|
||||
.catch((err) => {
|
||||
if(err.response.status == 422) {
|
||||
toast.error('Your input was invalid');
|
||||
} else {
|
||||
toast.error('Something went wrong')
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
generateInputs = (settings, handler) => {
|
||||
return settings.map((setting) => {
|
||||
return <SettingsInput
|
||||
key={setting.obj.id}
|
||||
name={setting.obj.name}
|
||||
id={setting.obj.id}
|
||||
type={setting.type}
|
||||
value={setting.obj.value}
|
||||
description={setting.obj.description}
|
||||
handler={handler}
|
||||
label={setting.obj.name}
|
||||
description={setting.obj.description}
|
||||
options={setting.type == 'select' ? setting.options : []}
|
||||
hideDescription={setting.hideDescription ? setting.hideDescription : false}
|
||||
min={setting.min ? setting.min : false}
|
||||
max={setting.max ? setting.max : false}
|
||||
btnType={setting.btnType}
|
||||
inline={setting.inline}
|
||||
url={setting.url}
|
||||
earlyReturn={setting.earlyReturn ? true : false}
|
||||
classes={setting.classes ? setting.classes : ''}
|
||||
/>
|
||||
})
|
||||
}
|
||||
|
||||
getTabContent = () => {
|
||||
var data = this.state.data;
|
||||
|
||||
switch(this.state.tab) {
|
||||
case 'General':
|
||||
return <GeneralSettings
|
||||
data={data.General}
|
||||
generateInputs={this.generateInputs}
|
||||
save={this.save} />
|
||||
case 'Graphs':
|
||||
return <GraphsSettings
|
||||
data={data.Graphs}
|
||||
generateInputs={this.generateInputs}
|
||||
save={this.save} />
|
||||
case 'Notifications':
|
||||
return <NotificationsSettings
|
||||
data={data.Notifications}
|
||||
generateInputs={this.generateInputs}
|
||||
save={this.save} />
|
||||
case 'healthchecks.io':
|
||||
return <HealthchecksSettings
|
||||
data={data.healthchecks}
|
||||
generateInputs={this.generateInputs}
|
||||
save={this.save} />
|
||||
case 'Reset':
|
||||
return <ResetSettings
|
||||
data={data.healthchecks}
|
||||
generateInputs={this.generateInputs}
|
||||
save={this.save} />
|
||||
case 'Backup/Restore':
|
||||
return <BackupSettings
|
||||
data={data.healthchecks}
|
||||
generateInputs={this.generateInputs}
|
||||
save={this.save} />
|
||||
case 'Authentication':
|
||||
return <Authentication
|
||||
data={data.healthchecks}
|
||||
generateInputs={this.generateInputs}
|
||||
save={this.save} />
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
var tabs = this.generateTabs();
|
||||
var activeTab = this.state.tab;
|
||||
var tabContent = this.getTabContent();
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Tabs
|
||||
variant="tabs"
|
||||
onSelect={(tab) => { this.switchTab(tab) }}
|
||||
activeKey={activeTab}
|
||||
>
|
||||
{tabs}
|
||||
</Tabs>
|
||||
|
||||
<div className="mt-3">
|
||||
{tabContent}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (document.getElementById('settingsTabs')) {
|
||||
ReactDOM.render(<SettingsTabs />, document.getElementById('settingsTabs'));
|
||||
}
|
||||
26
resources/js/components/Settings/tabs/BackupSettings.js
vendored
Normal file
26
resources/js/components/Settings/tabs/BackupSettings.js
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
import React, { Component } from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import { Modal, Button, Tab } from 'react-bootstrap';
|
||||
import Axios from 'axios';
|
||||
import DataRow from '../../Data/DataRow';
|
||||
|
||||
export default class BackupSettings extends Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
|
||||
this.state = {
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Tab.Content>
|
||||
<DataRow />
|
||||
</Tab.Content>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (document.getElementById('BackupSettings')) {
|
||||
ReactDOM.render(<BackupSettings />, document.getElementById('BackupSettings'));
|
||||
}
|
||||
46
resources/js/components/Settings/tabs/GeneralSettings.js
vendored
Normal file
46
resources/js/components/Settings/tabs/GeneralSettings.js
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
import React, { Component } from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import { Modal, Button, Tab } from 'react-bootstrap';
|
||||
import Axios from 'axios';
|
||||
|
||||
export default class GeneralSettings extends Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
|
||||
this.state = {
|
||||
data: this.props.data
|
||||
}
|
||||
}
|
||||
|
||||
inputHandler = (name, val) => {
|
||||
var settings = this.state.data;
|
||||
var i = 0;
|
||||
settings.forEach(ele => {
|
||||
if(ele.obj.name == name) {
|
||||
ele.obj.value = val;
|
||||
}
|
||||
settings[i] = ele;
|
||||
i++;
|
||||
});
|
||||
this.setState({
|
||||
data: settings
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
var settings = this.props.generateInputs(this.state.data, this.inputHandler);
|
||||
|
||||
return (
|
||||
<Tab.Content>
|
||||
{settings}
|
||||
<div className="mt-3">
|
||||
<button className="btn btn-primary" onClick={() => { this.props.save(this.state.data, 'General') }}>Save</button>
|
||||
</div>
|
||||
</Tab.Content>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (document.getElementById('GeneralSettings')) {
|
||||
ReactDOM.render(<GeneralSettings />, document.getElementById('GeneralSettings'));
|
||||
}
|
||||
48
resources/js/components/Settings/tabs/GraphsSettings.js
vendored
Normal file
48
resources/js/components/Settings/tabs/GraphsSettings.js
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
import React, { Component } from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import { Modal, Button, Tab } from 'react-bootstrap';
|
||||
import Axios from 'axios';
|
||||
import { toast } from 'react-toastify';
|
||||
import SettingsInput from '../SettingsInput';
|
||||
|
||||
export default class GraphsSettings extends Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
|
||||
this.state = {
|
||||
data: this.props.data
|
||||
}
|
||||
}
|
||||
|
||||
inputHandler = (name, val) => {
|
||||
var settings = this.state.data;
|
||||
var i = 0;
|
||||
settings.forEach(ele => {
|
||||
if(ele.obj.name == name) {
|
||||
ele.obj.value = val;
|
||||
}
|
||||
settings[i] = ele;
|
||||
i++;
|
||||
});
|
||||
this.setState({
|
||||
data: settings
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
var settings = this.props.generateInputs(this.state.data, this.inputHandler);
|
||||
|
||||
return (
|
||||
<Tab.Content>
|
||||
{settings}
|
||||
<div className="mt-3">
|
||||
<button className="btn btn-primary" onClick={() => { this.props.save(this.state.data, 'General') }}>Save</button>
|
||||
</div>
|
||||
</Tab.Content>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (document.getElementById('GraphsSettings')) {
|
||||
ReactDOM.render(<GraphsSettings />, document.getElementById('GraphsSettings'));
|
||||
}
|
||||
48
resources/js/components/Settings/tabs/HealthchecksSettings.js
vendored
Normal file
48
resources/js/components/Settings/tabs/HealthchecksSettings.js
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
import React, { Component } from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import { Modal, Button, Tab } from 'react-bootstrap';
|
||||
import Axios from 'axios';
|
||||
import { toast } from 'react-toastify';
|
||||
import SettingsInput from '../SettingsInput';
|
||||
|
||||
export default class HealthchecksSettings extends Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
|
||||
this.state = {
|
||||
data: this.props.data
|
||||
}
|
||||
}
|
||||
|
||||
inputHandler = (name, val) => {
|
||||
var settings = this.state.data;
|
||||
var i = 0;
|
||||
settings.forEach(ele => {
|
||||
if(ele.obj.name == name) {
|
||||
ele.obj.value = val;
|
||||
}
|
||||
settings[i] = ele;
|
||||
i++;
|
||||
});
|
||||
this.setState({
|
||||
data: settings
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
var settings = this.props.generateInputs(this.state.data, this.inputHandler);
|
||||
|
||||
return (
|
||||
<Tab.Content>
|
||||
{settings}
|
||||
<div className="mt-3">
|
||||
<button className="btn btn-primary" onClick={() => { this.props.save(this.state.data, 'healthchecks.io') }}>Save</button>
|
||||
</div>
|
||||
</Tab.Content>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (document.getElementById('HealthchecksSettings')) {
|
||||
ReactDOM.render(<HealthchecksSettings />, document.getElementById('HealthchecksSettings'));
|
||||
}
|
||||
46
resources/js/components/Settings/tabs/NotificationsSettings.js
vendored
Normal file
46
resources/js/components/Settings/tabs/NotificationsSettings.js
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
import React, { Component } from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import { Modal, Button, Tab } from 'react-bootstrap';
|
||||
import Axios from 'axios';
|
||||
|
||||
export default class NotificationsSettings extends Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
|
||||
this.state = {
|
||||
data: this.props.data
|
||||
}
|
||||
}
|
||||
|
||||
inputHandler = (name, val) => {
|
||||
var settings = this.state.data;
|
||||
var i = 0;
|
||||
settings.forEach(ele => {
|
||||
if(ele.obj.name == name) {
|
||||
ele.obj.value = val;
|
||||
}
|
||||
settings[i] = ele;
|
||||
i++;
|
||||
});
|
||||
this.setState({
|
||||
data: settings
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
var settings = this.props.generateInputs(this.state.data, this.inputHandler);
|
||||
|
||||
return (
|
||||
<Tab.Content>
|
||||
{settings}
|
||||
<div className="mt-3">
|
||||
<button className="btn btn-primary" onClick={() => { this.props.save(this.state.data, 'Notifications') }}>Save</button>
|
||||
</div>
|
||||
</Tab.Content>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (document.getElementById('NotificationsSettings')) {
|
||||
ReactDOM.render(<NotificationsSettings />, document.getElementById('NotificationsSettings'));
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
import React, { Component } from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import { Modal, Button } from 'react-bootstrap';
|
||||
import SettingsModalCard from './SettingsModalCard';
|
||||
import { Button } from 'react-bootstrap';
|
||||
import Axios from 'axios';
|
||||
import { toast } from 'react-toastify';
|
||||
|
||||
@@ -10,15 +9,6 @@ export default class ResetSettings extends Component {
|
||||
super(props)
|
||||
|
||||
this.state = {
|
||||
show: false,
|
||||
}
|
||||
}
|
||||
|
||||
toggleShow = () => {
|
||||
if(this.state.show) {
|
||||
this.setState({ show: false });
|
||||
} else {
|
||||
this.setState({ show:true });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,17 +35,9 @@ export default class ResetSettings extends Component {
|
||||
|
||||
return (
|
||||
<>
|
||||
<SettingsModalCard title={title} description="Bulk delete speedtests from the database." toggleShow={this.toggleShow} />
|
||||
<Modal show={show} onHide={this.toggleShow}>
|
||||
<Modal.Header>
|
||||
<Modal.Title>{title}</Modal.Title>
|
||||
</Modal.Header>
|
||||
<Modal.Body>
|
||||
<h4>Clear all speedtests</h4>
|
||||
<p className="text-muted">If using SQLite, a backup of the database will be stored in the location of the current database.</p>
|
||||
<Button onClick={this.deleteAll} variant="danger">Delete all</Button>
|
||||
</Modal.Body>
|
||||
</Modal>
|
||||
<h4>Clear all speedtests</h4>
|
||||
<p className="text-muted">If using SQLite, a backup of the database will be stored in the location of the current database.</p>
|
||||
<Button onClick={this.deleteAll} variant="danger">Delete all</Button>
|
||||
</>
|
||||
);
|
||||
}
|
||||
29
resources/js/components/SpeedtestsPage.js
vendored
Normal file
29
resources/js/components/SpeedtestsPage.js
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
import React, { Component } from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import TestsTable from './Graphics/TestsTable';
|
||||
import Footer from './Home/Footer';
|
||||
import Navbar from './Navbar';
|
||||
|
||||
export default class SpeedtestsPage extends Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
|
||||
this.state = {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div>
|
||||
<Navbar />
|
||||
<TestsTable />
|
||||
<Footer />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (document.getElementById('SpeedtestsPage')) {
|
||||
ReactDOM.render(<SpeedtestsPage />, document.getElementById('SpeedtestsPage'));
|
||||
}
|
||||
14
resources/js/index.js
vendored
14
resources/js/index.js
vendored
@@ -8,6 +8,8 @@ import { ToastContainer } from 'react-toastify';
|
||||
import 'react-toastify/dist/ReactToastify.css';
|
||||
import HomePage from './components/Home/HomePage';
|
||||
import Cookies from 'js-cookie';
|
||||
import SettingsIndex from './components/Settings/SettingsIndex';
|
||||
import SpeedtestsPage from './components/SpeedtestsPage';
|
||||
|
||||
export default class Index extends Component {
|
||||
constructor(props) {
|
||||
@@ -84,6 +86,18 @@ export default class Index extends Component {
|
||||
<HomePage />
|
||||
</div>
|
||||
)} />
|
||||
<Route exact path={window.config.base + 'speedtests'} render={(props) => (
|
||||
<div>
|
||||
<SpeedtestsPage />
|
||||
|
||||
</div>
|
||||
)} />
|
||||
<Route exact path={window.config.base + 'settings'} render={(props) => (
|
||||
<div>
|
||||
<SettingsIndex />
|
||||
|
||||
</div>
|
||||
)} />
|
||||
<Route exact path={window.config.base + "error/:code"} render={(props) => ( <ErrorPage code={props.match.params.code} /> )} />
|
||||
<Route render={(props) => (<ErrorPage code="404" />)} />
|
||||
</Switch>
|
||||
|
||||
@@ -16,20 +16,20 @@ use Illuminate\Support\Facades\Route;
|
||||
|
|
||||
*/
|
||||
|
||||
Route::get(SettingsHelper::getBase() . 'files/{path?}', function($file) {
|
||||
Route::get(SettingsHelper::getBase() . 'files/{path?}', function ($file) {
|
||||
$fileP = explode('?', $file)[0];
|
||||
$fileP = public_path() . '/' . $fileP;
|
||||
if(file_exists($fileP)) {
|
||||
if (file_exists($fileP)) {
|
||||
$contents = File::get($fileP);
|
||||
$mime = \GuzzleHttp\Psr7\mimetype_from_filename($fileP);
|
||||
return Response::make(File::get($fileP), 200, [ 'Content-type' => $mime ]);
|
||||
return Response::make(File::get($fileP), 200, ['Content-type' => $mime]);
|
||||
} else {
|
||||
abort(404);
|
||||
}
|
||||
})->where('path', '.*')
|
||||
->name('files');
|
||||
->name('files');
|
||||
|
||||
Route::get('/{path?}', function() {
|
||||
return view('app', [ 'title' => 'Speedtest Tracker' ]);
|
||||
Route::get('/{path?}', function () {
|
||||
return view('app', ['title' => SettingsHelper::get('app_name')->value]);
|
||||
})->where('path', '^((?!\/api\/).)*$')
|
||||
->name('react');
|
||||
->name('react');
|
||||
|
||||
@@ -27,13 +27,13 @@ class APISpeedtestTest extends TestCase
|
||||
$dl = [];
|
||||
$ul = [];
|
||||
|
||||
for($i = 0; $i < 3; $i++) {
|
||||
for ($i = 0; $i < 3; $i++) {
|
||||
$pingVal = $faker->randomFloat();
|
||||
array_push($ping,$pingVal);
|
||||
array_push($ping, $pingVal);
|
||||
$dlVal = $faker->randomFloat();
|
||||
array_push($dl,$dlVal);
|
||||
array_push($dl, $dlVal);
|
||||
$ulVal = $faker->randomFloat();
|
||||
array_push($ul,$ulVal);
|
||||
array_push($ul, $ulVal);
|
||||
|
||||
Speedtest::create([
|
||||
'ping' => $pingVal,
|
||||
@@ -70,7 +70,12 @@ class APISpeedtestTest extends TestCase
|
||||
'download',
|
||||
'upload',
|
||||
],
|
||||
'max' => [
|
||||
'maximum' => [
|
||||
'ping',
|
||||
'download',
|
||||
'upload',
|
||||
],
|
||||
'minimum' => [
|
||||
'ping',
|
||||
'download',
|
||||
'upload',
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Tests\TestCase;
|
||||
|
||||
class BackupTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* A basic feature test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExample()
|
||||
{
|
||||
$response = $this->get('/');
|
||||
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SettingsTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* A basic feature test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExample()
|
||||
{
|
||||
$response = $this->get('/');
|
||||
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@ class LatestTest extends TestCase
|
||||
*/
|
||||
private $controller;
|
||||
|
||||
public function setUp() : void
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
@@ -53,6 +53,7 @@ class LatestTest extends TestCase
|
||||
|
||||
$this->assertArrayHasKey('data', $resp);
|
||||
$this->assertArrayHasKey('average', $resp);
|
||||
$this->assertArrayHasKey('max', $resp);
|
||||
$this->assertArrayHasKey('maximum', $resp);
|
||||
$this->assertArrayHasKey('minimum', $resp);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user