Skip to content

Commit

Permalink
add new option to run programs with condition check (#60)
Browse files Browse the repository at this point in the history
allow to run programs with condition check

Co-authored-by: Jens Maus <mail@jens-maus.de>
  • Loading branch information
Baxxy13 and jens-maus authored Sep 22, 2023
1 parent 3ba2736 commit 15b8d0e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions xmlapi/index.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ if {[info exists sid] && [check_session $sid]} {
<tr><td><a href=./runprogram.cgi?sid=$sid>runprogram.cgi</a></td><td><b>Starts a program with the specified id.</b><br/>
<i>sid=string</i> - security access token id<br/>
<i>program_id=int</i> - id of program to modify (e.g. "1234")<br/>
<i>cond_check=0/1</i> - execute program with normal condition checks or not (only first "then" is executed) (default=0)
</td></tr>
<tr><td><a href=./scripterrors.cgi?sid=$sid>scripterrors.cgi</a></td><td><b>Searches for the last 10 lines in /var/log/messages containing script runtime errors and outputs them.</b><br/>
<i>sid=string</i> - security access token id<br/>
Expand Down
12 changes: 11 additions & 1 deletion xmlapi/runprogram.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ puts -nonewline "<?xml version='1.0' encoding='ISO-8859-1' ?><result>"
if {[info exists sid] && [check_session $sid]} {

set program_id "-1"
set cond_check 0
catch {
set input $env(QUERY_STRING)
set pairs [split $input &]
Expand All @@ -16,10 +17,19 @@ if {[info exists sid] && [check_session $sid]} {
set program_id $val
continue
}
if {0 != [regexp "^cond_check=(.*)$" $pair dummy val]} {
set cond_check $val
continue
}
}
}

array set res [rega_script "if ($program_id > 0) { object obj = dom.GetObject($program_id); if (obj && obj.IsTypeOf(OT_PROGRAM)) { obj.ProgramExecute(); Write(obj); }}"]
# execut with condition check or without
if { $cond_check == 1 } {
array set res [rega_script "if ($program_id > 0) { object obj = dom.GetObject($program_id); if (obj && obj.IsTypeOf(OT_PROGRAM)) { obj.State(1); Write(obj); }}"]
} else {
array set res [rega_script "if ($program_id > 0) { object obj = dom.GetObject($program_id); if (obj && obj.IsTypeOf(OT_PROGRAM)) { obj.ProgramExecute(); Write(obj); }}"]
}

if { $res(STDOUT) != "" } {
puts -nonewline "<started program_id=\"$program_id\"/>"
Expand Down

0 comments on commit 15b8d0e

Please sign in to comment.