Skip to content

Commit

Permalink
Invoming Overview: Clear broker database button
Browse files Browse the repository at this point in the history
Closes #19
  • Loading branch information
christianTF committed Jan 7, 2020
1 parent dfcfae8 commit 4963347
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 70 deletions.
3 changes: 2 additions & 1 deletion bin/mqttgateway.pl
Original file line number Diff line number Diff line change
Expand Up @@ -830,4 +830,5 @@ END
if($log) {
LOGEND "MQTT Gateway exited";
}
}
}

4 changes: 4 additions & 0 deletions bin/sudo/mosq_purgedb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
systemctl stop mosquitto
rm /var/lib/mosquitto/mosquitto.db
systemctl start mosquitto
1 change: 1 addition & 0 deletions sudoers/sudoers
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ loxberry ALL = NOPASSWD: REPLACELBPBINDIR/sudo/mosq_restart.sh
loxberry ALL = NOPASSWD: REPLACELBPBINDIR/sudo/mosq_stop.sh
loxberry ALL = NOPASSWD: REPLACELBPBINDIR/sudo/mosq_readconfig.sh
loxberry ALL = NOPASSWD: REPLACELBPBINDIR/sudo/mosq_symlink.sh
loxberry ALL = NOPASSWD: REPLACELBPBINDIR/sudo/mosq_purgedb.sh
loxberry ALL = NOPASSWD: REPLACELBPBINDIR/updateconfig.pl
28 changes: 26 additions & 2 deletions templates/mqtt.html
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ <h2 class='ui-bar ui-bar-a ui-corner-all'>Conversions defined by other plugins</


<TMPL_IF FORM_TOPICS>
<!-- Form TOPICS -->
<!-- Form TOPICS (Incoming Overview) -->
<style>
.topics_table {
/* font-family: "Trebuchet MS", Arial, Helvetica, sans-serif; */
Expand Down Expand Up @@ -253,8 +253,10 @@ <h2 class='ui-bar ui-bar-a ui-corner-all' id='head_donate'>Donate for test equip
</div>
<!-- <button id="Main.remove_donate" data-mini="true"><TMPL_VAR donate_done_remove></button> -->
</div>
<br>


<!-- Clear broker database -->
<button class="ui-btn ui-btn-icon-right" id="purgemosquittodb" data-inline="true" style="display:none">Clear broker database</button>

<script>

Expand Down Expand Up @@ -688,6 +690,9 @@ <h2 class='ui-bar ui-bar-a ui-corner-all' id='package_mqttgateway_mosquitto'>Mos
if( cfg.Main.donation_remove === true )
$("#coll_donate").hide();

// View PurgeDB button if Mosquitto is managed by plugin
if( cfg.Main.enable_mosquitto === true )
$("#purgemosquittodb").show();

// Elements in subscriptions
if( cfg.subscriptions ) {
Expand Down Expand Up @@ -879,6 +884,25 @@ <h2 class='ui-bar ui-bar-a ui-corner-all' id='package_mqttgateway_mosquitto'>Mos

});
});

$("#purgemosquittodb").click(function(){
console.log("Restart Mosquitto database");
$("#purgemosquittodb").attr("disabled", true);
$.post( 'index.cgi', {
ajax: 'mosquitto_purgedb' })
.done(function(resp) {
// console.log( "ajax_post", "success", resp );
})
.fail(function(resp) {
console.log( "ajax_post", "failed", resp );
})
.always(function(resp) {
// console.log( "ajax_post", "finished", resp );
$("#purgemosquittodb").attr("disabled", false);
update_pids();

});
});

$("#check_securepin").click(function(){

Expand Down
91 changes: 24 additions & 67 deletions webfrontend/htmlauth/index.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,29 @@ if( $q->{ajax} ) {
require Time::HiRes;
my %response;
ajax_header();

# GetPids
if( $q->{ajax} eq "getpids" ) {
pids();
$response{pids} = \%pids;
print JSON::encode_json(\%response);
}

# Purge Mosquitto DB
if( $q->{ajax} eq "mosquitto_purgedb" ) {
qx( sudo $lbpbindir/sudo/mosq_purgedb.sh );
# Now restart the Gateway
$q->{ajax} = "restartgateway";
}

# Restart Mosquitto DB
if( $q->{ajax} eq "mosquitto_restart" ) {
qx( sudo $lbpbindir/sudo/mosq_restart.sh );
pids();
$response{pids} = \%pids;
print JSON::encode_json(\%response);
}

# Restart Gateway
if( $q->{ajax} eq "restartgateway" ) {
pkill('mqttgateway.pl');
Expand All @@ -36,7 +53,9 @@ if( $q->{ajax} ) {
$response{pids} = \%pids;
print JSON::encode_json(\%response);
}
# Relayed topics


# Relayed topics for Incoming Overview
if( $q->{ajax} eq "relayed_topics" ) {

if (defined $q->{udpinport} and $q->{udpinport} ne "0") {
Expand All @@ -55,6 +74,7 @@ if( $q->{ajax} ) {
my $datafile = "/dev/shm/mqttgateway_topics.json";
print LoxBerry::System::read_file($datafile);
}

# Delete topic
if( $q->{ajax} eq "retain" ) {

Expand All @@ -75,6 +95,7 @@ if( $q->{ajax} ) {
print LoxBerry::System::read_file($datafile);
}

# Disable cache of topic
if( $q->{ajax} eq "disablecache" ) {
require LoxBerry::JSON;
my $json = LoxBerry::JSON->new();
Expand All @@ -92,7 +113,8 @@ if( $q->{ajax} ) {
$json->write();

}


# Set resetAfterSend for a topic
if( $q->{ajax} eq "resetAfterSend" ) {
require LoxBerry::JSON;
my $json = LoxBerry::JSON->new();
Expand Down Expand Up @@ -250,77 +272,12 @@ sub conversions_form
########################################################################
sub topics_form
{


# require "$lbpbindir/libs/LoxBerry/JSON/JSONIO.pm";
# require POSIX;

# my $datafile = "/dev/shm/mqttgateway_topics.json";
# my $relayjsonobj = LoxBerry::JSON::JSONIO->new();
# my $relayjson = $relayjsonobj->open(filename => $datafile);


# # HTTP
# my $http_table, $http_count = 0;
# $http_table .= qq { <table class="topics_table" id="http_table" data-filter="true"> };
# $http_table .= qq { <thead> };
# $http_table .= qq { <tr> };
# $http_table .= qq { <th>Miniserver Virtual Input</th> };
# $http_table .= qq { <th>Last value</th> };
# $http_table .= qq { <th>Last submission</th> };
# $http_table .= qq { </tr> };
# $http_table .= qq { </thead> };
# $http_table .= qq { <tbody> };

# foreach my $topic (sort keys %{$relayjson->{http}}) {
# $http_count++;
# $http_table .= qq { <tr> };
# $http_table .= qq { <td>$topic</td> };
# $http_table .= qq { <td>$relayjson->{http}{$topic}{message}</td> };
# $http_table .= qq { <td> } . POSIX::strftime('%d.%m.%Y %H:%M:%S', localtime($relayjson->{http}{$topic}{timestamp})) . qq { </td> };
# $http_table .= qq { </tr> };
# }
# $http_table .= qq { </tbody> };
# $http_table .= qq { </table> };

# $template->param("http_table", $http_table);
# $template->param("http_count", $http_count);


# # UDP
# my $udp_table, $udp_count = 0;
# $udp_table .= qq { <table class="topics_table" id="udp_table" data-filter="true"> };
# $udp_table .= qq { <thead> };
# $udp_table .= qq { <tr> };
# $udp_table .= qq { <th>Miniserver UDP</th> };
# #$udp_table .= qq { <th>Last value</th> };
# $udp_table .= qq { <th>Last submission</th> };
# $udp_table .= qq { </tr> };
# $udp_table .= qq { </thead> };
# $udp_table .= qq { <tbody> };

# foreach my $topic (sort keys %{$relayjson->{udp}}) {
# $udp_count++;
# $udp_table .= qq { <tr> };
# $udp_table .= qq { <td>MQTT: $topic=$relayjson->{udp}{$topic}{message}</td> };
# # $udp_table .= qq { <td>$relayjson->{udp}{$topic}{message}</td> };
# $udp_table .= qq { <td> } . POSIX::strftime('%d.%m.%Y %H:%M:%S', localtime($relayjson->{udp}{$topic}{timestamp})) . qq { </td> };
# $udp_table .= qq { </tr> };
# }
# $udp_table .= qq { </tbody> };
# $udp_table .= qq { </table> };

# $template->param("udp_table", $udp_table);
# $template->param("udp_count", $udp_count);

# Donate
my $donate = "Thanks to all that have already donated for my special Test-Miniserver, making things much more easier than testing on the \"production\" house! Also, I'm buying (not <i>really</i> needed) hardware devices (e.g. Shelly's and other equipment) to test it with LoxBerry and plugins. As I'm spending my time, hopefully you support my expenses for my test environment. About a donation of about 5 or 10 Euros, or whatever amount it is worth for you, I will be very happy!";
my $donate_done_remove = "Done! Remove this!";
$template->param("donate", $donate);
$template->param("donate_done_remove", $donate_done_remove);




}

Expand Down

0 comments on commit 4963347

Please sign in to comment.