Table of Contents
The Network Security Toolkit system provides such a set of powerful tools, it often becomes difficult to keep track of all of them. It was decided that a Web User Interface (WUI) could provide the following:
A simple interface for common tasks.
A way for the developers to write common scripts and comments describing what they wanted to accomplish (its very easy to add features to the Network Security Toolkit today and forget about them and/or how to use them in six months).
The general steps for adding a WUI front end page include:
Pick a directory (or create a new one) under
wui/cgi-bin
to create your
CGI script under. For example, the front
end to the top command is found at
wui/cgi-bin/system/top.cgi
.
Copy an existing CGI script to use as
a starting point to your new interface. The
wui/cgi-bin/system/top.cgi
works well as
a template for simple interfaces.
Update the top level wui/index.html
file and add a link to your newly created script.
Here are a few tips to keep in mind when creating your own CGI scripts:
Use the Environment
link in the
System
section of the
WUI to get an idea of what environment
variables your CGI script will have at its
disposal.
Make sure that the first line of your script starts with
the @bashCgiBegin()
macro and that the
last line of your script (or prior to any exit point) contains
the @bashCgiEnd()
macro.
Make sure that you pair each invocation of the
@bashCgiOutBegin()
macro with a
corresponding @bashCgiOutEnd()
invocation
(alternatively, you can use /bin/cat
<<EOF
and EOF
lines to mark
sections of text to put out).
Be careful about indentation. Unfortunately, the
/bin/cat <<EOF
requires the matching
EOF
to be at the start of the line (which
means that the @bashCgiOutEnd()
macro
must also be at the start of a line).
The simplest type of WUI interface you can create is one that runs a standard command line program and captures the output. We provide several macros to help facilitate the process.
The following shows the entire script which makes up the front end to the top interface:
#! /bin/bash # # top.cgi @bashCgiBegin("$Id: top.cgi,v 1.46 2008/04/04 12:41:48 rwhalb Exp $","2003-09-26","Information On Running Processes",," @htmlEntity("script",,"@htmlAttr("src","@topDir()/javascript/pstop.js")@htmlAttr("type","text/javascript")") ") # # local defines... @define("exitAnchor","System") # # parse any arguments... set_query_options; # # exit text... qrft="${QUERY_return_from:-"NST WUI Index"}"; qrlt="${QUERY_return_label:-"Exit"}" exit_hover_text="@jsn("${qrlt}") to page: @jsqh("${qrft}")..."; exit_hover_text_len="$(((${#qrft} * @dtm()) + 130))"; # # quick and dirty way to get the current process count... PROCESS_CNT="$(/usr/bin/sudo /bin/ls -1d /proc/[0-9]* | /usr/bin/wc -l)"; # remove the cmd and pipe used to get the process count... ((PROCESS_CNT = PROCESS_CNT - 2)); @bashCgiOutBegin() @javascriptBegin() setNavLinkHome("../../index.cgi","","System"); addSectionHeader("Information On Running Processes \x3cspan style='font-size: 70%;'\x3e(Process Count: \x3cspan onmouseover=\"domTT_activate(this, event, 'content', dispProcCntTT(${PROCESS_CNT}), 'width', 350, 'id', 'topHeader');\"\x3e"\x3cspan style='color: green;'\x3e${PROCESS_CNT}\x3c/span\x3e"\x3c/span\x3e)\x3c/span\x3e", "proccnt", "h2", "/nstwui/images/", null); @javascriptEnd() @p("This page displays <i>multiple</i> views of current <u>active</u> processes running on this @bold("@nst()") probe using different <u>sort</u> criteria:") @verticalGapSmall() <center> <table@htmlAttr("border","0")> <tr> <td> @javascriptButton("collapsePsSections();","Collapse All","@toolTipAttr("@jsn("Collapse") <u>All</u> @jsqh("Process") output sections below...","310")") </td> <td> @javascriptButton("expandPsSections();","Expand All","@toolTipAttr("@jsn("Expand") <u>All</u> @jsqh("Process") output sections below...","300")") </td> <td> @wuiExitButton("${qrlt}",,"@toolTipAttr("${exit_hover_text}","${exit_hover_text_len}")") </td> </tr> </table> </center> <div@htmlAttr("class","line1px") @htmlAttr("style","margin: 0.2em; border-color: blue;")> </div> @javascriptBegin() setNavLinkHome("@topDir()/index.cgi","","System"); addCollapsiblePSHeader("Current Processes: "top -b -n 1"", "pstop", ps_section_state['pstop'], "h2", "/nstwui/images/", null); @javascriptEnd() @comment("Start section appearance as: 'closed'...") <div@htmlAttr("id","pstop-area") @htmlAttr("style","display: none;")> @p("The following output displays the <u>current</u> <u>process</u> <u>list</u> running on this @bold("@nst()") system produced by the \"@manPageLink("top")\" command.") @runCommand("TERM=ansi /usr/bin/sudo -H /usr/bin/top -b -n 1") @verticalGapSmall() @noteMessage(" The number of processes reported by the \"@bold("top")\" command above and the \"@bold("ps")\" command below will be <u>slightly</u> <u>higher</u> due to the @bold("Apache Web Server") spawning off <u>multiple</u> tasks (i.e. "@bold("top.cgi")" processes) to render this @nst() @bold("WUI") web page. ","Note:") <center> @wuiExitButton("${qrlt}",,"@toolTipAttr("${exit_hover_text}","${exit_hover_text_len}")") </center> </div> @javascriptBegin() // // Now appropriately show section in the desired state... setOpenClose('pstop-icon', 'pstop-area', ps_section_state['pstop']); @javascriptEnd() @comment("###Sorted By: Process ID###") @verticalGap() @javascriptBegin() setNavLinkHome("@topDir()/index.cgi","","System"); addCollapsiblePSHeader("Current Processes (Sorted By: Process ID)", "pspid", ps_section_state['pspid'], "h2", "/nstwui/images/", null); @javascriptEnd() <div@htmlAttr("id","pspid-area") @htmlAttr("style","display: none;")> @p("The following output is a custom <u>process</u> <u>listing</u> in \"@bold("wide")\" output format for <u>all</u> processes that are running on this @nst() system. The output is sorted by \"@bold("Process ID (@acroPID())")\" and produced by issuing the following \"@manPageLink("ps")\" command.") @runCommand("/usr/bin/sudo /bin/ps -eww -o user,pid,ppid,pgid,sid,egid,pcpu,pmem,tty,start,etime,time,args --sort pid") @verticalGapSmall() @noteMessage(" Use the @manPageLink("setsid") utility program for <u>setting</u> a new \"@bold("Session ID")\" (@bold("SID")) and also sets the \"@bold("Process Group ID")\" (@bold("PGID")). ","Note: How To Run A Program In A New Session") <center> @wuiExitButton("${qrlt}",,"@toolTipAttr("${exit_hover_text}","${exit_hover_text_len}")") </center> </div> @javascriptBegin() setOpenClose('pspid-icon', 'pspid-area', ps_section_state['pspid']); @javascriptEnd() @comment("###Sorted By: User ID###") @verticalGap() @javascriptBegin() setNavLinkHome("@topDir()/index.cgi","","System"); addCollapsiblePSHeader("Current Processes (Sorted By: User ID)", "psuser", ps_section_state['psuser'], "h2", "/nstwui/images/", null); @javascriptEnd() <div@htmlAttr("id","psuser-area") @htmlAttr("style","display: none;")> @p("The following output displays the <u>current</u> <u>process</u> <u>list</u> in \"@bold("wide")\" output format for <u>all</u> processes that are running on this @nst() system. The output is sorted by \"@bold("User ID")\" and produced by issuing the following \"@manPageLink("ps")\" command.") @runCommand("/usr/bin/sudo /bin/ps -eww -o user,pid,ppid,pgid,sid,egid,pcpu,pmem,tty,start,etime,time,args --sort user") @verticalGapSmall() <center> @wuiExitButton("${qrlt}",,"@toolTipAttr("${exit_hover_text}","${exit_hover_text_len}")") </center> </div> @javascriptBegin() setOpenClose('psuser-icon', 'psuser-area', ps_section_state['psuser']); @javascriptEnd() @comment("###Sorted By: Process Name###") @verticalGap() @javascriptBegin() setNavLinkHome("@topDir()/index.cgi","","System"); addCollapsiblePSHeader("Current Processes (Sorted By: Process Name)", "psargs", ps_section_state['psargs'], "h2", "/nstwui/images/", null); @javascriptEnd() <div@htmlAttr("id","psargs-area") @htmlAttr("style","display: none;")> @p("The following output displays the <u>current</u> <u>process</u> <u>list</u> in \"@bold("wide")\" output format for <u>all</u> processes that are running on this @nst() system. The output is sorted by \"@bold("Process Name")\" and produced by issuing the following \"@manPageLink("ps")\" command.") @runCommand("/usr/bin/sudo /bin/ps -eww -o user,pid,ppid,pgid,sid,egid,pcpu,pmem,tty,start,etime,time,args --sort args") @verticalGapSmall() <center> @wuiExitButton("${qrlt}",,"@toolTipAttr("${exit_hover_text}","${exit_hover_text_len}")") </center> </div> @javascriptBegin() setOpenClose('psargs-icon', 'psargs-area', ps_section_state['psargs']); @javascriptEnd() @comment("###Sorted By: Elapse Time###") @verticalGap() @javascriptBegin() setNavLinkHome("@topDir()/index.cgi","","System"); addCollapsiblePSHeader("Current Processes (Sorted By: Elapse Time)", "psetime", ps_section_state['psetime'], "h2", "/nstwui/images/", null); @javascriptEnd() <div@htmlAttr("id","psetime-area") @htmlAttr("style","display: none;")> @p("The following output displays the <u>current</u> <u>process</u> <u>list</u> in \"@bold("wide")\" output format for <u>all</u> processes that are running on this @nst() system. The output is sorted by \"@bold("Process Elapse Time")\" and produced by issuing the following \"@manPageLink("ps")\" command.") @runCommand("/usr/bin/sudo /bin/ps -eww -o user,pid,ppid,pgid,sid,egid,pcpu,pmem,tty,start,etime,time,args --sort etime") @verticalGapSmall() <center> @wuiExitButton("${qrlt}",,"@toolTipAttr("${exit_hover_text}","${exit_hover_text_len}")") </center> </div> @javascriptBegin() setOpenClose('psetime-icon', 'psetime-area', ps_section_state['psetime']); @javascriptEnd() @comment("###Sorted By: CPU Time###") @verticalGap() @javascriptBegin() setNavLinkHome("@topDir()/index.cgi","","System"); addCollapsiblePSHeader("Current Processes (Sorted By: CPU Time)", "pscputime", ps_section_state['pscputime'], "h2", "/nstwui/images/", null); @javascriptEnd() <div@htmlAttr("id","pscputime-area") @htmlAttr("style","display: none;")> @p("The following output displays the <u>current</u> <u>process</u> <u>list</u> in \"@bold("wide")\" output format for <u>all</u> processes that are running on this @nst() system. The output is sorted by \"@bold("Accumlated CPU Time")\" and produced by issuing the following \"@manPageLink("ps")\", \"@manPageLink("sort")\" and \"@manPageLink("cut")\" commands.") @comment(" @runCommand("/usr/bin/sudo /bin/ps -eww -o time,user,pid,ppid,pgid,sid,egid,pcpu,pmem,tty,start,etime,time,args | /bin/sort -r | /bin/cut -d' ' -f2-") ") @runCommand("(echo "USER PID PPID PGID SID EGID %CPU %MEM TT STARTED ELAPSED TIME COMMAND"; /usr/bin/sudo /bin/ps -eww -o time,user,pid,ppid,pgid,sid,egid,pcpu,pmem,tty,start,etime,time,args | /bin/sort -r | /bin/cut -d' ' -f2-)") @verticalGapSmall() <center> @wuiExitButton("${qrlt}",,"@toolTipAttr("${exit_hover_text}","${exit_hover_text_len}")") </center> </div> @javascriptBegin() setOpenClose('pscputime-icon', 'pscputime-area', ps_section_state['pscputime']); @javascriptEnd() @comment("###Sorted By: CPU Utilization###") @verticalGap() @javascriptBegin() setNavLinkHome("@topDir()/index.cgi","","System"); addCollapsiblePSHeader("Current Processes (Sorted By: CPU Utilization)", "pscpu", ps_section_state['pscpu'], "h2", "/nstwui/images/", null); @javascriptEnd() <div@htmlAttr("id","pscpu-area") @htmlAttr("style","display: none;")> @p("The following output displays the <u>current</u> <u>process</u> <u>list</u> in \"@bold("wide")\" output format for <u>all</u> processes that are running on this @nst() system. The output is sorted by \"@bold("CPU Utilization")\" and produced by issuing the following \"@manPageLink("ps")\" command.") @runCommand("/usr/bin/sudo /bin/ps u -eww O -C") @verticalGapSmall() <center> @wuiExitButton("${qrlt}",,"@toolTipAttr("${exit_hover_text}","${exit_hover_text_len}")") </center> </div> @javascriptBegin() setOpenClose('pscpu-icon', 'pscpu-area', ps_section_state['pscpu']); @javascriptEnd() @comment("###Sorted By: Memory Usage###") @verticalGap() @javascriptBegin() setNavLinkHome("@topDir()/index.cgi","","System"); addCollapsiblePSHeader("Current Processes (Sorted By: Memory Usage)", "psmem", ps_section_state['psmem'], "h2", "/nstwui/images/", null); @javascriptEnd() <div@htmlAttr("id","psmem-area") @htmlAttr("style","display: none;")> @p("The following output displays the <u>current</u> <u>process</u> <u>list</u> in \"@bold("wide")\" output format for <u>all</u> processes that are running on this @nst() system. The output is sorted by \"@bold("Memory Utilization")\" and produced by issuing the following \"@manPageLink("ps")\" command.") @runCommand("/usr/bin/sudo /bin/ps u -eww O -v") @verticalGapSmall() <center> @wuiExitButton("${qrlt}",,"@toolTipAttr("${exit_hover_text}","${exit_hover_text_len}")") </center> </div> @javascriptBegin() setOpenClose('psmem-icon', 'psmem-area', ps_section_state['psmem']); @javascriptEnd() @comment("###Current Processes With Threads###") @verticalGap() @javascriptBegin() setNavLinkHome("@topDir()/index.cgi","","System"); addCollapsiblePSHeader("Display Current Processes With Threads", "psthread", ps_section_state['psthread'], "h2", "/nstwui/images/", null); @javascriptEnd() <div@htmlAttr("id","psthread-area") @htmlAttr("style","display: none;")> @p("The following output displays the <u>current</u> <u>process</u> <u>list</u> along with <u>threads</u> (@bold("-L")) and <u>process</u> <u>group</u> <u>IDs</u> (@bold("-j")) for <u>all</u> processes that are running on this @nst() system. The output was produced by the \"@manPageLink("ps")\" command.") @runCommand("/usr/bin/sudo /bin/ps v -ewwLj") </div> @javascriptBegin() setOpenClose('psthread-icon', 'psthread-area', ps_section_state['psthread']); @javascriptEnd() @bashCgiOutEnd() # # set exit label/return... QUERY_return_from="@jsqh("${qrft}")"; QUERY_return_label="${qrlt}"; @bashCgiEnd("${exit_hover_text_len}")