Skip to content

Commit 15b8d0e

Browse files
Baxxy13jens-maus
andauthored
add new option to run programs with condition check (#60)
allow to run programs with condition check Co-authored-by: Jens Maus <[email protected]>
1 parent 3ba2736 commit 15b8d0e

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

xmlapi/index.cgi

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ if {[info exists sid] && [check_session $sid]} {
8484
<tr><td><a href=./runprogram.cgi?sid=$sid>runprogram.cgi</a></td><td><b>Starts a program with the specified id.</b><br/>
8585
<i>sid=string</i> - security access token id<br/>
8686
<i>program_id=int</i> - id of program to modify (e.g. "1234")<br/>
87+
<i>cond_check=0/1</i> - execute program with normal condition checks or not (only first "then" is executed) (default=0)
8788
</td></tr>
8889
<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/>
8990
<i>sid=string</i> - security access token id<br/>

xmlapi/runprogram.cgi

+11-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ puts -nonewline "<?xml version='1.0' encoding='ISO-8859-1' ?><result>"
88
if {[info exists sid] && [check_session $sid]} {
99

1010
set program_id "-1"
11+
set cond_check 0
1112
catch {
1213
set input $env(QUERY_STRING)
1314
set pairs [split $input &]
@@ -16,10 +17,19 @@ if {[info exists sid] && [check_session $sid]} {
1617
set program_id $val
1718
continue
1819
}
20+
if {0 != [regexp "^cond_check=(.*)$" $pair dummy val]} {
21+
set cond_check $val
22+
continue
23+
}
1924
}
2025
}
2126

22-
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); }}"]
27+
# execut with condition check or without
28+
if { $cond_check == 1 } {
29+
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); }}"]
30+
} else {
31+
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); }}"]
32+
}
2333

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

0 commit comments

Comments
 (0)