diff --git a/api_speedtest.php b/api_speedtest.php index 80fcca65a..2d29ba090 100644 --- a/api_speedtest.php +++ b/api_speedtest.php @@ -358,7 +358,7 @@ function whichSpeedtest() return 'sivel\'s'; } - return 'LibreSpeed'; + return 'librespeed'; } return 'no'; diff --git a/img/st-chart.png b/img/st-chart.png index c038da224..94ad851c3 100644 Binary files a/img/st-chart.png and b/img/st-chart.png differ diff --git a/img/st-pref.png b/img/st-pref.png index e09fa940e..98d3c7e48 100644 Binary files a/img/st-pref.png and b/img/st-pref.png differ diff --git a/scripts/pi-hole/js/settings.js b/scripts/pi-hole/js/settings.js index 586fb2265..18d74dbc2 100644 --- a/scripts/pi-hole/js/settings.js +++ b/scripts/pi-hole/js/settings.js @@ -486,7 +486,6 @@ $(function () { const speedtestChartPreview = $("#speedtestchartpreview"); const speedtestChartPreviewBtn = $("#speedtestchartpreviewBtn"); - const speedtestUpdate = $("#speedtestupdate"); const speedtestUninstall = $("#speedtestuninstall"); const speedtestDelete = $("#speedtestdelete"); const speedtestDeleteLabel = speedtestDelete.parent().children("label"); @@ -494,6 +493,10 @@ $(function () { const speedtestLog = $("#latestLog"); const speedtestLogBtn = $("#latestLogBtn"); + const speedtestCLIOfficial = $("#speedtestcliOfficial"); + const speedtestCLISivel = $("#speedtestcliSivel"); + const speedtestCLILibre = $("#speedtestcliLibre"); + const speedtestSubmit = $("#st-submit"); const defaultClass = "btn-primary"; const colorClasses = ["btn-success", "btn-warning", "btn-danger"]; @@ -502,6 +505,8 @@ $(function () { speedtestChartType.prop("checked", type === "bar"); localStorage.setItem("speedtest_chart_type", type); + var speedtestCLISelected = false; + const preCode = content => { const pre = document.createElement("pre"); const code = document.createElement("code"); @@ -557,7 +562,7 @@ $(function () { const serviceStatus = () => { whichSpeedtest(); const speedtestVersion = localStorage.getItem("speedtest") || "unknown"; - let cliText = "Will use official CLI"; + let cliText = "Will install CLI before next run"; if (speedtestVersion !== "no") { cliText = `Using ${speedtestVersion} CLI`; } @@ -855,7 +860,6 @@ $(function () { document.addEventListener("DOMContentLoaded", function () { speedtestDays.attr("value", speedtestDays.val()); speedtestChartTypeSave.attr("value", null); - speedtestUpdate.attr("value", null); speedtestUninstall.attr("value", null); speedtestDelete.attr("value", null); speedtestTest.attr("value", null); @@ -888,10 +892,6 @@ $(function () { previewChart(speedtestChartPreview.find("div").length === 0); }); - speedtestUpdate.on("click", function () { - speedtestUpdate.attr("value", speedtestUpdate.attr("value") ? null : "up"); - }); - speedtestTest.on("click", function () { speedtestTest.attr("value", speedtestTest.attr("value") ? null : "yes"); const status = speedtestStatus.find("pre"); @@ -948,6 +948,18 @@ $(function () { canRestore(); }); + speedtestCLIOfficial.on("click", function () { + speedtestCLISelected = true; + }); + + speedtestCLISivel.on("click", function () { + speedtestCLISelected = true; + }); + + speedtestCLILibre.on("click", function () { + speedtestCLISelected = true; + }); + setInterval(() => { if (speedtestStatus.find("pre").length > 0) { serviceStatus(); @@ -972,6 +984,22 @@ $(function () { closestServers(); } + if (!speedtestCLISelected) { + whichSpeedtest(); + const currentCLI = localStorage.getItem("speedtest"); + if (currentCLI === "official") { + speedtestCLIOfficial.prop("checked", true); + } + + if (currentCLI === "sivel's") { + speedtestCLISivel.prop("checked", true); + } + + if (currentCLI === "librespeed") { + speedtestCLILibre.prop("checked", true); + } + } + canRestore(); }, 1000); }); diff --git a/scripts/pi-hole/php/header_authenticated.php b/scripts/pi-hole/php/header_authenticated.php index 1a66cbbdd..f80750867 100644 --- a/scripts/pi-hole/php/header_authenticated.php +++ b/scripts/pi-hole/php/header_authenticated.php @@ -197,6 +197,41 @@ function getNumberOfDaysInDB($dbSpeedtest) $speedtestcharttype = $setupVars['SPEEDTEST_CHART_TYPE']; } +function speedtestExecute($command) +{ + $output = array(); + $return_status = -1; + exec('/bin/bash -c \''.$command.'\'', $output, $return_status); + + if ($return_status !== 0) { + trigger_error("Executing {$command} failed.", E_USER_WARNING); + } + + return array('data' => implode("\n", $output)); +} + +function whichSpeedtest() +{ + if (file_exists('/usr/bin/speedtest')) { + $officialInstalled = speedtestExecute('. /opt/pihole/speedtestmod/lib.sh ; notInstalled speedtest && echo "false" || echo "true"')['data']; + + if ($officialInstalled === 'true') { + return 'official'; + } + + $version = speedtestExecute('/usr/bin/speedtest -h')['data']; + + if (strpos($version, 'sivel') !== false) { + return 'sivel\'s'; + } + + return 'librespeed'; + } + + return 'no'; +} + +$speedtestcli = whichSpeedtest(); $piholeFTLConf = piholeFTLConfig(); require 'header.php'; diff --git a/scripts/pi-hole/php/savesettings.php b/scripts/pi-hole/php/savesettings.php index 6cd8fe0ba..06b75bcb7 100644 --- a/scripts/pi-hole/php/savesettings.php +++ b/scripts/pi-hole/php/savesettings.php @@ -618,43 +618,73 @@ function addStaticDHCPLease($mac, $ip, $hostname) } pihole_execute('-a -st '.trim($charttype)); - $success .= 'The Speedtest settings have been updated'; + $success .= 'Speedtest Settings have been updated'; if (isset($_POST['speedtesttest'])) { $success .= ' and a speedtest has been started'; pihole_execute('-a -sn', !isset($_POST['speedtestuninstall'])); } + $run_mod_script = false; + $opt_mod_script = ''; + + if (isset($_POST['speedtestbackup'])) { + $run_mod_script = true; + $opt_mod_script .= ' -b'; + } + + if (isset($_POST['speedtestupgrade'])) { + $run_mod_script = true; + $opt_mod_script .= ' -u'; + } + if (isset($_POST['speedtestupdate'])) { - $success .= ' and Pi-hole will be updated'; - if (isset($_POST['speedtestuninstall'])) { - $success .= ', but the Mod will be uninstalled'; - if (isset($_POST['speedtestdelete'])) { - $success .= ' and its history will be deleted'; - pihole_execute('-a -up un db', true); - } else { - pihole_execute('-a -up un', true); - } - } else { - if (isset($_POST['speedtestdelete'])) { - $success .= ' and its history will be modified'; - pihole_execute('-a -up db', true); - } else { - pihole_execute('-a -up', true); - } - } - } elseif (isset($_POST['speedtestuninstall'])) { - $success .= ' and the Mod will be uninstalled'; - if (isset($_POST['speedtestdelete'])) { - $success .= ' and its history will be deleted'; - pihole_execute('-a -un db', true); - } else { - pihole_execute('-a -un', true); + $run_mod_script = true; + } + + if (isset($_POST['speedtestonline'])) { + $run_mod_script = true; + $opt_mod_script .= ' -o'; + } + + if (isset($_POST['speedtestreinstall'])) { + $run_mod_script = true; + $opt_mod_script .= ' -r'; + } + + if (isset($_POST['speedtestuninstall'])) { + $run_mod_script = true; + $opt_mod_script .= ' -n'; + } + + if (isset($_POST['speedtestdelete'])) { + $run_mod_script = true; + $opt_mod_script .= ' -d'; + } + + if (isset($_POST['speedtestverbose'])) { + $run_mod_script = true; + $opt_mod_script .= ' -x'; + } + + if (isset($_POST['speedtestcli']) && whichSpeedtest() != $_POST['speedtestcli']) { + $run_mod_script = true; + $chosen_cli = ''; + + if ($_POST['speedtestcli'] == 'sivel\'s') { + $chosen_cli = 'sivel'; + } elseif ($_POST['speedtestcli'] == 'librespeed') { + $chosen_cli = 'libre'; } - } elseif (isset($_POST['speedtestdelete'])) { - $success .= ' and its history will be modified'; - pihole_execute('-a -db', true); + + $opt_mod_script .= ' -s'.$chosen_cli; } + + if ($run_mod_script) { + $success .= ' and the Mod Script has been executed'; + pihole_execute('-a -sm'.$opt_mod_script, true); + } + break; default: // Option not found diff --git a/scripts/pi-hole/php/update_checker.php b/scripts/pi-hole/php/update_checker.php index e2be46944..9725802ba 100644 --- a/scripts/pi-hole/php/update_checker.php +++ b/scripts/pi-hole/php/update_checker.php @@ -35,9 +35,10 @@ function checkUpdate($currentVersion, $latestVersion) $versions = parse_ini_file($versionsfile); // Get Pi-hole core branch / version / commit - // Check if on a dev branch + // Check if on a dev branch or untagged commit $core_branch = $versions['CORE_BRANCH']; - if ($core_branch !== 'master') { + $core_version = $versions['CORE_VERSION']; + if ($core_branch !== 'master' || !strpos($core_version, '.')) { $core_current = 'vDev'; $core_commit = $versions['CORE_VERSION']; } else { @@ -46,7 +47,8 @@ function checkUpdate($currentVersion, $latestVersion) // Get Pi-hole web branch / version / commit $web_branch = $versions['WEB_BRANCH']; - if ($web_branch !== 'master') { + $web_version = $versions['WEB_VERSION']; + if ($web_branch !== 'master' || !strpos($web_version, '.')) { $web_current = 'vDev'; $web_commit = $versions['WEB_VERSION']; } else { @@ -55,7 +57,8 @@ function checkUpdate($currentVersion, $latestVersion) // Get Speedtest Mod branch / version / commit $speedtest_branch = $versions['SPEEDTEST_BRANCH']; - if ($speedtest_branch !== 'master') { + $speedtest_version = $versions['SPEEDTEST_VERSION']; + if ($speedtest_branch !== 'master' || !strpos($speedtest_version, '.')) { $speedtest_current = 'vDev'; $speedtest_commit = $versions['SPEEDTEST_VERSION']; } else { diff --git a/settings.php b/settings.php index 26698dda1..6fb2e5979 100644 --- a/settings.php +++ b/settings.php @@ -1615,29 +1615,71 @@ class="form-control"
- -
- Mod the Mod -

With the Script

+
+ Restoration options +

For when something's the matter

- - + + +
+
+ + +
+
+ +
+
+ +
+ Speedtest CLI +

To be tried first

+
+ checked> + +
+
+ checked> + +
+
+ checked> + +
+

If you just confirmed a new CLI, please wait a moment for the selection to update.

+
+ +
+ Main options +

For when nothing's (hopefully) the matter

+
+ + +
+
+ + +
+
+ + +

- +

To be tried first

id