Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add new option to run programs with condition check (runprogram-cc.cgi) #60

Merged
merged 4 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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