Skip to content

Commit

Permalink
v1.4.400 - improved global vars, filtered bad JSON URLS
Browse files Browse the repository at this point in the history
  • Loading branch information
hplato committed May 29, 2017
1 parent 9a4f1d5 commit 9206af6
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 17 deletions.
26 changes: 22 additions & 4 deletions lib/ia7_utilities.pl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ sub main::ia7_update_schedule {

sub ia7_update_collection {
&main::print_log("[IA7_Collection_Updater] : Starting");
my $ia7_coll_current_ver = 1.2;
my $ia7_coll_current_ver = 1.3;

my @collection_files = (
"$main::Pgm_Root/data/web/collections.json",
Expand All @@ -36,6 +36,7 @@ sub ia7_update_collection {
&main::print_log("[IA7_Collection_Updater] : Reviewing $file to current version $ia7_coll_current_ver");
my $json_data;
my $file_data;
my $updated;
eval {
$file_data = &main::file_read($file);
$json_data = decode_json($file_data); #HP, wrap this in eval to prevent MH crashes
Expand All @@ -45,11 +46,11 @@ sub ia7_update_collection {
&main::print_log("[IA7_Collection_Updater] : WARNING: decode_json failed for $file. Please check this file!");
}
else {
my $updated = 0;
$updated = 0;

if ( ( !defined $json_data->{meta}->{version} )
or ( $json_data->{meta}->{version} < 1.2 ) )
{ #IA7 v1.2 required change
{ #IA7 v1.2 required change
$json_data->{700}->{user} = '$Authorized'
unless ( defined $json_data->{700}->{user} );
my $found = 0;
Expand All @@ -59,9 +60,26 @@ sub ia7_update_collection {
push( @{ $json_data->{500}->{children} }, 700 )
unless ($found);
$json_data->{meta}->{version} = "1.2";
&main::print_log("[IA7_Collection_Updater] : Updating $file to version 1.2");
&main::print_log("[IA7_Collection_Updater] : Updating $file to version 1.2 (MH 4.2 IA7 v1.2.100 support)");
$updated = 1;
}
if ( $json_data->{meta}->{version} < 1.3 ) {
#IA7 v1.4 required change
#convert back to a file so we can globally change links
my $file_data2 = to_json( $json_data, { utf8 => 1, pretty => 1 } );
$file_data2 =~ s/\"link\"[\s+]:[\s+]\"\/ia7\/\#path=\/vars\"/\"link\" : \"\/ia7\/\#path\=\/vars_global\"/g;
$file_data2 =~ s/\"link\"[\s+]:[\s+]\"\/ia7\/\#path=\/vars\/Save\"/\"link\" : \"\/ia7\/\#path\=\/vars_save\"/g;
eval {
$json_data = decode_json($file_data2); #HP, wrap this in eval to prevent MH crashes
};
if ($@) {
&main::print_log("[IA7_Collection_Updater] : WARNING: decode_json failed for v1.3 update.");
} else {
$json_data->{meta}->{version} = "1.3";
&main::print_log("[IA7_Collection_Updater] : Updating $file to version 1.3 (MH 4.3 IA7 v1.4.400 support)");
$updated = 1;
}
}
if ($updated) {
my $json_newdata = to_json( $json_data, { utf8 => 1, pretty => 1 } );
my $backup_file = $file . ".t" . int( ::get_tickcount() / 1000 ) . ".backup";
Expand Down
66 changes: 60 additions & 6 deletions lib/json_server.pl
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ sub json {
$request_type = $HTTP_REQ_TYPE;
}
my %arg_hash = %HTTP_ARGV;

if ( $arguments ne '' ) {
%arg_hash = ();

Expand Down Expand Up @@ -93,13 +94,19 @@ sub json {
# Split Path into Array
$path_str =~ s/^\/json//i; # Remove leading 'json' path
$path_str =~ s/^\/|\/$//g; # Remove leadin trailing slash.

my @path = split( '/', $path_str );

if ( lc($request_type) eq "get" ) {
return json_get( $request_type, \@path, \%args, $body );
}
elsif ( lc($request_type) eq "put" ) {
json_put( $request_type, \@path, \%args, $body );
if ($path_str eq '') {
print_log "Json_Server.pl: WARNING: null json request received. Ignoring...";
} else {

if ( lc($request_type) eq "get" ) {
return json_get( $request_type, \@path, \%args, $body );
}
elsif ( lc($request_type) eq "put" ) {
json_put( $request_type, \@path, \%args, $body );
}
}
}

Expand Down Expand Up @@ -162,7 +169,7 @@ sub json_get {
}
}
$fields{all} = 1 unless %fields;

# List defined collections
if ( $path[0] eq 'collections' || $path[0] eq '' ) {
my $collection_file = "$Pgm_Root/data/web/collections.json";
Expand Down Expand Up @@ -600,6 +607,7 @@ sub json_get {
next if $key eq 'INC';
next if $key eq 'ISA';
next if $key eq 'SIG';
next if $key eq 'User_Code';
my $iref = ${$ref}{$key};

# this is for constants
Expand All @@ -608,6 +616,52 @@ sub json_get {
}
$json_data{vars} = \%json_vars;
}

if ( $path[0] eq 'vars_global' || $path[0] eq '' ) {
my %json_vars_global;
for my $key ( sort keys %main:: ) {

# Assume all the global vars we care about are $Ab...
next if $key !~ /^[A-Z][a-z]/ or $key =~ /\:/;
next if $key eq 'Save' or $key eq 'Tk_objects'; # Covered elsewhere
next if $key eq 'Socket_Ports';
next if $key eq 'User_Code';

my $glob = $main::{$key};
if ( ${$glob} ) {
my $value = ${$glob};
next if $value =~ /HASH/; # Skip object pointers
next if $key eq 'Password';
$value =~ s/[\r\n]+$//;
#print "db: [$key -> $value]\n";
$json_vars_global{$key} = $value;
}
elsif ( %{$glob} ) {
for my $key2 ( sort keys %{$glob} ) {
my $value = ${$glob}{$key2};# . "\n";
$value = '' unless $value; # Avoid -w uninitialized value msg
$value =~ s/[\r\n]+$//;
next if $value =~ /HASH\(/; # Skip object pointers
next if $value =~ /ARRAY\(/;
#print "db: [$key\{$key2\} -> $value]\n";
$json_vars_global{"$key\{$key2\}"} = $value;
}
}
}
$json_data{vars_global} = \%json_vars_global;
}

if ( $path[0] eq 'vars_save' || $path[0] eq '' ) {
my %json_vars_save;

for my $key ( sort keys %Save ) {
my $value = ( $Save{$key} ) ? $Save{$key} : '';
$value =~ s/[\r\n]+$//;
$json_vars_save{$key} = $value;
}

$json_data{vars_save} = \%json_vars_save;
}

if ( $path[0] eq 'notifications' ) {

Expand Down
2 changes: 1 addition & 1 deletion web/ia7/house/main.shtml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
<div class='col-sm-12 col-sm-offset-0 col-md-10 col-md-offset-1 col-lg-8 col-lg-offset-2'>
<div class='col-sm-12'>
<p class="text-muted"><small> MisterHouse was created by Bruce Winter. Ron Klinkien developed the v2.3 web interface. Kevin Robert Keegan
designed the v4 web prototype, updates by H.Plato. IA7 v1.4.350 Font Awesome by Dave Gandy - http://fontawesome.io</small></p>
designed the IA7 web prototype, updates by H.Plato. IA7 v1.4.400 Font Awesome by Dave Gandy - http://fontawesome.io</small></p>
</div>
</div>
</div>
Expand Down
30 changes: 24 additions & 6 deletions web/ia7/include/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ function changePage (){
if (path.indexOf('objects') === 0){
loadList();
}
else if (path.indexOf('vars') === 0){
else if ((path.indexOf('vars') === 0) || (path.indexOf('vars_global') === 0) || (path.indexOf('vars_save') === 0)){
loadVars();
}
else if (path.indexOf('prefs') === 0){
Expand Down Expand Up @@ -465,18 +465,36 @@ function loadVars (){ //variables list
dataType: "json",
success: function( json ) {
JSONStore(json);
var table = false;
if (json.meta.path[0] != 'vars') table = true;
var list_output = "";
var keys = [];
for (var key in json.data) {
keys.push(key);
}
keys.sort ();
for (var i = 0; i < keys.length; i++){
var value = variableList(json.data[keys[i]]);
var name = keys[i];
var list_html = "<ul><li><b>" + name + ":</b>" + value+"</li></ul>";
list_output += (list_html);

if (table) {
list_output = "<table class='table table-curved'><thead><tr>";
list_output += "<th>Variable</th><th>Value</th>";
list_output += "</tr></thead><tbody>";

for (var i = 0; i < keys.length; i++){
var value = json.data[keys[i]];
var name = keys[i];
var list_html
list_output += "<tr><td>"+name+"</td><td>"+value+"</td></tr>";
}
list_output += "</tbody></table>";
} else {
for (var i = 0; i < keys.length; i++){
var value = variableList(json.data[keys[i]]);
var name = keys[i];
var list_html
list_output += "<ul><li><b>" + name + ":</b>" + value+"</li></ul>";
}
}
//list_output += (list_html);

//Print list output if exists;
if (list_output !== ""){
Expand Down

0 comments on commit 9206af6

Please sign in to comment.