Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Options: All, Emoncms, EmonHub, Firmware, Database #1230

Merged
merged 4 commits into from Apr 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 11 additions & 8 deletions Modules/admin/admin_controller.php
Expand Up @@ -14,7 +14,7 @@

function admin_controller()
{
global $mysqli,$session,$route,$updatelogin,$allow_emonpi_admin, $log_filename, $log_enabled, $redis, $homedir;
global $mysqli,$session,$route,$updatelogin,$allow_emonpi_admin, $admin_show_update, $log_filename, $log_enabled, $redis, $homedir;
$result = "<br><div class='alert-error' style='top:0px; left:0px; width:100%; height:100%; text-align:center; padding-top:100px; padding-bottom:100px; border-radius:4px;'><h4>"._('Admin re-authentication required')."</h4></div>";

// Allow for special admin session if updatelogin property is set to true in settings.php
Expand Down Expand Up @@ -125,7 +125,7 @@ function read_file($file, $lines) {
}
}

else if ($allow_emonpi_admin && $route->action == 'emonpi') {
else if (($admin_show_update || $allow_emonpi_admin) && $route->action == 'emonpi') {
//put $update_logfile here so it can be referenced in other if statements
//before it was only accesable in the update subaction
//placed some other variables here as well so they are grouped
Expand All @@ -141,13 +141,16 @@ function read_file($file, $lines) {
if ($route->subaction == 'update' && $session['write'] && $session['admin']) {
$route->format = "text";
// Get update argument e.g. 'emonpi' or 'rfm69pi'
$argument="";
if (isset($_POST['argument'])) {
$argument = $_POST['argument'];
}
$firmware="";
if (isset($_POST['firmware'])) $firmware = $_POST['firmware'];
if (!in_array($firmware,array("emonpi","rfm69pi","rfm12pi","custom"))) return "Invalid firmware type";
// Type: all, emoncms, firmware
$type="";
if (isset($_POST['type'])) $type = $_POST['type'];
if (!in_array($type,array("all","emoncms","firmware","emonhub"))) return "Invalid update type";

$redis->rpush("service-runner","$update_script $argument>$update_logfile");
$result = "service-runner trigger sent";
$redis->rpush("service-runner","$update_script $type $firmware>$update_logfile");
return "service-runner trigger sent";
}

if ($route->subaction == 'getupdatelog' && $session['admin']) {
Expand Down
102 changes: 62 additions & 40 deletions Modules/admin/admin_main_view.php
@@ -1,4 +1,4 @@
<?php global $path, $emoncms_version, $allow_emonpi_admin, $log_enabled, $log_filename, $mysqli, $redis_enabled, $redis, $mqtt_enabled, $feed_settings, $shutdownPi;
<?php global $path, $emoncms_version, $allow_emonpi_admin, $log_enabled, $log_filename, $mysqli, $redis_enabled, $redis, $mqtt_enabled, $feed_settings, $shutdownPi, $admin_show_update;

// Retrieve server information
$system = system_information();
Expand Down Expand Up @@ -211,18 +211,66 @@ function disk_list()
<a href="<?php echo $path; ?>admin/users" class="btn btn-info"><?php echo _('Users'); ?></a>
</td>
</tr>

<?php if ($admin_show_update || $allow_emonpi_admin) { ?>
<tr>
<td>
<h3><?php echo _('Update database'); ?></h3>
<p><?php echo _('Run this after updating emoncms, after installing a new module or to check emoncms database status.'); ?></p>
<h3><?php echo _('Update All'); ?></h3>
<p><?php echo _('OS, Packages, EmonHub, Emoncms & Firmware (If new version)'); ?></p>
</td>
<td class="buttons"><br>
<a href="<?php echo $path; ?>admin/db" class="btn btn-info"><?php echo _('Update & check'); ?></a>
<a class="update btn btn-info" type="all"><?php echo _('Update All'); ?></a>
</td>
</tr>
<?php
if ($log_enabled) {
?>

<tr>
<td>
<h4><?php echo _('Emoncms Only'); ?></h4>
<p><?php echo _('Emoncms, Emoncms Modules and Services'); ?></p>
<p><b>Release info:</b> <a href="https://github.com/emoncms/emoncms/releases"> Emoncms</a></p>
</td>
<td class="buttons"><br>
<a class="update btn btn-info" type="emoncms"><?php echo _('Update Emoncms'); ?></a>
</td>
</tr>

<tr>
<td>
<h4><?php echo _('EmonHub Only'); ?></h4>
<p><b>Release info:</b> <a href="https://github.com/openenergymonitor/emonhub/releases"> EmonHub</a></p>
</td>
<td class="buttons"><br>
<a class="update btn btn-info" type="emonhub"><?php echo _('Update EmonHub'); ?></a>
</td>
</tr>

<tr>
<td>
<h4><?php echo _('Update Firmware Only'); ?></h4>
<p><?php echo _('Select your hardware type and firmware version'); ?></p>
<p><b>Release info:</b> <a href="https://github.com/openenergymonitor/emonpi/releases">emonPi</a> | <a href="https://github.com/openenergymonitor/RFM2Pi/releases">RFM69Pi</a></p>
</td>
<td class="buttons"><br>
<div class="input-append"><select id="selected_firmware"><option value="emonpi">EmonPi</option><option value="rfm69pi">RFM69Pi</option><option value="rfm12pi">RFM12Pi</option><option value="custom">Custom</option></select>
<button class="update btn btn-info" type="firmware">Update Firmware</button></div>
</td>
</tr>

<tr>
<td>
<h4><?php echo _('MySQL Database Only'); ?></h4>
<p><?php echo _('Run this after a manual emoncms update, after installing a new module or to check emoncms database status.'); ?></p>
</td>
<td class="buttons"><br>
<a href="<?php echo $path; ?>admin/db" class="btn btn-info"><?php echo _('Update Database'); ?></a>
</td>
</tr>
<tr>
<td colspan="2" style="border-top: 0px"><pre id="update-log-bound" style="display: none;"><div id="update-log"></div></pre></td>
</tr>
<?php } ?>

<?php if ($log_enabled) { ?>
<tr colspan="2" >
<td colspan="2" >
<table class="table table-condensed" style="background-color: transparent">
Expand Down Expand Up @@ -255,37 +303,7 @@ function disk_list()
</table>
</td>
</tr>
<?php
}

if ($allow_emonpi_admin) {
?>
<tr>
<td colspan="2" style="margin:0px; padding:0px;">
<table class="table table-condensed" style="background-color: transparent">
<tr>
<td style="border-top: 0px">
<h3><?php echo _('Update'); ?></h3>
<p><b>emonPi Update:</b> updates emonPi firmware &amp; Emoncms</p>
<p><b>emonBase Update:</b> updates emonBase (RFM69Pi firmware) &amp; Emoncms</p>
<p><b>Change Logs:</b> <a href="https://github.com/emoncms/emoncms/releases"> Emoncms</a> | <a href="https://github.com/openenergymonitor/emonpi/releases">emonPi</a> | <a href="https://github.com/openenergymonitor/RFM2Pi/releases">RFM69Pi</a></p>
<p><i>Caution: ensure RFM69Pi is populated with RFM69CW module not RFM12B before running RFM69Pi update: <a href="https://learn.openenergymonitor.org/electricity-monitoring/networking/which-radio-module">Identifying different RF Modules</a>.</i></p>
</td>
<td class="buttons" style="border-top: 0px"><br>
<button id="emonpiupdate" class="btn btn-warning"><?php echo _('emonPi Update'); ?></button>
<button id="rfm69piupdate" class="btn btn-danger"><?php echo _('emonBase Update'); ?></button><br></br>
<a href="<?php echo $path; ?>admin/emonpi/downloadupdatelog" class="btn btn-info"><?php echo _('Download Log'); ?></a><br><br>
</td>
</tr>
<tr>
<td colspan="2" style="border-top: 0px"><pre id="update-log-bound" style="display: none;"><div id="update-log"></div></pre></td>
</tr>
</table>
</td>
</tr>
<?php
}
?>
<?php } ?>

<tr colspan=2>
<td colspan=2>
Expand Down Expand Up @@ -592,8 +610,12 @@ function getLog() {

var refresher_update;

$("#emonpiupdate").click(function() {
$.ajax({ type: "POST", url: path+"admin/emonpi/update", data: "argument=emonpi", async: true, success: function(result)
$(".update").click(function() {

var type = $(this).attr("type");
var firmware = $("#selected_firmware").val();

$.ajax({ type: "POST", url: path+"admin/emonpi/update", data: "type="+type+"&firmware="+firmware, async: true, success: function(result)
{
$("#update-log").html(result);
$("#update-log-bound").scrollTop = $("#update-log-bound").scrollHeight;
Expand Down