diff --git a/lib/ia7_utilities.pl b/lib/ia7_utilities.pl index c880ceab9..4cf4a415a 100644 --- a/lib/ia7_utilities.pl +++ b/lib/ia7_utilities.pl @@ -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", @@ -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 @@ -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; @@ -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"; diff --git a/lib/json_server.pl b/lib/json_server.pl index cafd771df..df679bd72 100755 --- a/lib/json_server.pl +++ b/lib/json_server.pl @@ -58,6 +58,7 @@ sub json { $request_type = $HTTP_REQ_TYPE; } my %arg_hash = %HTTP_ARGV; + if ( $arguments ne '' ) { %arg_hash = (); @@ -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 ); + } } } @@ -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"; @@ -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 @@ -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' ) { diff --git a/web/ia7/house/main.shtml b/web/ia7/house/main.shtml index 1bc9ae478..bdeed6330 100644 --- a/web/ia7/house/main.shtml +++ b/web/ia7/house/main.shtml @@ -82,7 +82,7 @@

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

+ designed the IA7 web prototype, updates by H.Plato. IA7 v1.4.400 Font Awesome by Dave Gandy - http://fontawesome.io

diff --git a/web/ia7/include/javascript.js b/web/ia7/include/javascript.js index f9da397c9..9a70fccf3 100644 --- a/web/ia7/include/javascript.js +++ b/web/ia7/include/javascript.js @@ -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){ @@ -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 = ""; - list_output += (list_html); + + if (table) { + list_output = ""; + list_output += ""; + list_output += ""; + + for (var i = 0; i < keys.length; i++){ + var value = json.data[keys[i]]; + var name = keys[i]; + var list_html + list_output += ""; + } + list_output += "
VariableValue
"+name+""+value+"
"; + } 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 += ""; + } } + //list_output += (list_html); //Print list output if exists; if (list_output !== ""){