Skip to content

Commit

Permalink
Merge pull request #766 from hplato/ia7
Browse files Browse the repository at this point in the history
v2.0.750 - color slider control
  • Loading branch information
hplato authored Aug 27, 2018
2 parents b3693b0 + 4357413 commit 7b8e5f2
Show file tree
Hide file tree
Showing 8 changed files with 166 additions and 48 deletions.
9 changes: 7 additions & 2 deletions lib/http_server.pl
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,11 @@ sub http_process_request {

# print "Error, no SET argument: $header\n" unless $get_arg;

#allow setby to be passed in URL. Objects can then take a setby argument if there is an alternative action.
#used for RGB. Downside is that the true setby (web) would be lost.
my $get_arg_setby = "";
($get_arg_setby) = $get_arg =~ /select_setby=(\S+)/;
$get_arg =~ s/select_setby=(\S+)// if ($get_arg_setby);
# Change select_item=$item&select_state=abc to $item=abc
$get_arg =~ s/select_item=(\S+)\&&select_state=/$1=/;

Expand Down Expand Up @@ -765,10 +770,10 @@ sub http_process_request {

# Can be a scalar or a object
$state =~ tr/\"/\'/; # So we can use "" to quote it

$get_arg_setby = "web [$client_ip_address]" unless $get_arg_setby;
# my $eval_cmd = qq[($item and ref($item) and UNIVERSAL::isa($item, 'Generic_Item')) ?
my $eval_cmd = qq[($item and ref($item) ne '' and ref($item) ne 'SCALAR' and $item->can('set')) ?
($item->set("$state", "web [$client_ip_address]")) : ($item = "$state")];
($item->set("$state", "$get_arg_setby")) : ($item = "$state")];
print "SET eval: $eval_cmd\n" if $main::Debug{http};
eval $eval_cmd;
print "SET eval error. cmd=$eval_cmd error=$@\n" if $@;
Expand Down
48 changes: 37 additions & 11 deletions lib/json_server.pl
Original file line number Diff line number Diff line change
Expand Up @@ -883,34 +883,52 @@ sub json_get {
}

if ( $path[0] eq 'security' ) {
#check if $Authorized
if (defined $path[1] and $path[1] eq 'authorize') {
print "IN AUTHORIZE\n";
# Passwords are stored as MD5 hashes in the user data file
# Take that MD5, then take the current date (in YYYYDDMM format) and then calculate
# an authorization MD5 value. Adding in the current date means that the lifespan of a compromised
# password token is at most 1 day.
my $status = "";
if ($args{user} && $args{user}[0] eq "") {
$status = "Empty Username";
$status = "fail";
&main::print_log("json_server.pl: ERROR, authorize attempt with no username");
} elsif ($args{password} && $args{password}[0] eq "") {
$status = "Empty Password";
$status = "fail";
&main::print_log("json_server.pl: ERROR, authorize attempt with no password");

} else {
my $password = &Groups('getpw','',$args{user}[0]);
my $time_seed = &main::time_date_stamp('18',$Time);
my $time_seedY = &main::time_date_stamp('18',$Time - 86400);
my $time_seedT = &main::time_date_stamp('18',$Time + 86400);

#to account for clock drift, check today and tomorrow values around midnight
#if time is between 11:55 and midnight then also check tomorrow
#if time is between midnight and 00:05 then also check yesterday
print "PW=$password, time_seed=$time_seed, $time_seedY, $time_seedT\n";
if (time_greater_than("11:55 PM")) {
my $time_seedT = &main::time_date_stamp('18',$Time + 86400);
my $pwdcheck1 = md5_hex($password . $time_seedT);
$status = "success" if (lc $args{password}[0] eq lc $pwdcheck1);
}
if (time_less_than("00:05 AM")) {
my $time_seedY = &main::time_date_stamp('18',$Time - 86400);
my $pwdcheck2 = md5_hex($password . $time_seedY);
$status = "success" if (lc $args{password}[0] eq lc $pwdcheck2);
}
#print "PW=$password, time_seed=$time_seed";
my $pwdcheck = md5_hex($password . $time_seed);
print "PWC=$pwdcheck\n";
#print "PWC=$pwdcheck\n";

if (lc $args{password}[0] eq lc $pwdcheck) {
if ($status eq "" and (lc $args{password}[0] eq lc $pwdcheck)) {
$status = "success";
&main::print_log("json_server.pl: INFO, user $args{user}[0] successfully authenticated");

} else {
$status = "fail";
&main::print_log("json_server.pl: WARNING, user $args{user}[0] authentication attempt failed");

}
}
$json_data{security}->{authorize} = $status;
} else {
#check if $Authorized
my $ref;
my $users;
my $found = 0;
Expand Down Expand Up @@ -1508,7 +1526,7 @@ sub json_object_detail {
my %json_complete_object;
my @f = qw( category filename measurement rf_id set_by members
state states state_log type label sort_order groups hidden parents schedule logger_status
idle_time text html seconds_remaining fp_location fp_icons fp_icon_set img link level);
idle_time text html seconds_remaining fp_location fp_icons fp_icon_set img link level rgb);

# Build list of fields based on those requested.
foreach my $f ( sort @f ) {
Expand Down Expand Up @@ -1551,6 +1569,14 @@ sub json_object_detail {
$value = $a if ( defined $a and $a ne "" ); #don't return a null value
}

elsif ( $f eq 'rgb' ) {
my ($a,$b,$c) = $object->$method;

$value = "$a,$b,$c" if (( defined $a and $a ne "" ) #don't return a null value
and ( defined $b and $b ne "" )
and ( defined $c and $c ne "" ));
}

#if ( $f eq 'hidden' ) {
# my $a = $object->$method;
# if ($a == 1 or $a eq "1") {
Expand Down
8 changes: 4 additions & 4 deletions web/ia7/house/modes.shtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@

<div class="col-sm-4">
<div style="vertical-align:middle">
<button entity='mode_mh' class='btn btn-default btn-lg btn-list btn-popover btn-block btn-state-cmd navbutton-padding'>Mr.House Modes<span class='pull-right'>loading...</span>
<button entity='mode_mh' class='btn btn-default btn-lg btn-list btn-popover btn-block btn-state-cmd navbutton-padding'>Mr.House Modes<span class='pull-right object-state'>loading...</span>
</button>
</div>
</div>


<div class="col-sm-4">
<div style="vertical-align:middle">
<button entity='mode_security' class='btn btn-default btn-lg btn-list btn-popover btn-block btn-state-cmd navbutton-padding'>Security Mode<span class='pull-right'>loading...</span>
<button entity='mode_security' class='btn btn-default btn-lg btn-list btn-popover btn-block btn-state-cmd navbutton-padding'>Security Mode<span class='pull-right object-state'>loading...</span>
</button>
</div>
</div>

<div class="col-sm-4">
<div style="vertical-align:middle">
<button entity='mode_occupied' class='btn btn-default btn-lg btn-list btn-popover btn-block btn-state-cmd navbutton-padding'>Occupied Mode<span class='pull-right'>loading...</span>
<button entity='mode_occupied' class='btn btn-default btn-lg btn-list btn-popover btn-block btn-state-cmd navbutton-padding'>Occupied Mode<span class='pull-right object-state'>loading...</span>
</button>
</div>
</div>
Expand All @@ -29,7 +29,7 @@
<div id='row1' 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-4">
<div style="vertical-align:middle">
<button entity='mode_sleeping' class='btn btn-default btn-lg btn-list btn-popover btn-block btn-state-cmd navbutton-padding'>Sleeping Mode<span class='pull-right'>loading...</span>
<button entity='mode_sleeping' class='btn btn-default btn-lg btn-list btn-popover btn-block btn-state-cmd navbutton-padding'>Sleeping Mode<span class='pull-right object-state'>loading...</span>
</button>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions web/ia7/house/sample.shtml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@

<div class="col-sm-4">
<div style="vertical-align:middle">
<button entity='gen_door' class='btn btn-default btn-lg btn-list btn-popover btn-block btn-state-cmd navbutton-padding'>Garage Door<span class='pull-right'>loading...</span>
<button entity='gen_door' class='btn btn-default btn-lg btn-list btn-popover btn-block btn-state-cmd navbutton-padding'>Garage Door<span class='pull-right object-state'>loading...</span>
</button>
</div>
</div>


<div class="col-sm-4">
<div style="vertical-align:middle">
<button entity='test_light' class='btn btn-default btn-lg btn-list btn-popover btn-block btn-state-cmd navbutton-padding'>Garage Light<span class='pull-right'>loading...</span>
<button entity='test_light' class='btn btn-default btn-lg btn-list btn-popover btn-block btn-state-cmd navbutton-padding'>Garage Light<span class='pull-right object-state'>loading...</span>
</button>
</div>
</div>
Expand Down
Loading

0 comments on commit 7b8e5f2

Please sign in to comment.