Skip to content

Instantly share code, notes, and snippets.

@runvnc
Created March 8, 2014 01:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save runvnc/9423819 to your computer and use it in GitHub Desktop.
Save runvnc/9423819 to your computer and use it in GitHub Desktop.
Not catching sigsegv
import msgqredis, marshal, cgi, auth, strutils, osproc, streams
var request: TQueuedRequest
var requestStr: string
var c: int = 1
when isMainModule:
echo("------------- NEW NEW procreq starting up. -------------")
while true:
echo("top of while loop " & $c)
c = c+1
try:
requestStr = startProcessing("http")
except:
echo("Problem with startProcessing")
if requestStr != nil:
request = to[TQueuedRequest](requestStr)
var query: tuple[apikey, user, args: string]
for k, v in decodeData(request.query):
query = ( apikey: "", user: "", args: "" )
case k
of "apikey":
query.apikey = v
of "user":
query.user = v
of "args":
query.args=v
#look up api key and check if it matches username
var user = auth(query.apikey, query.user)
#if not send bad auth messsage
if user == nil:
request.respond("Not authorized", "text/plain")
else:
#spawn a child running oicctl process with args from command
var args = query.args.split(' ')
args.insert(user, 0)
var conv = startProcess("./oicctl", "", args)
proc readStreamToOutput(input) =
var line: TaintedString = ""
while input.readLine(line):
#as child spits out output push it into response queue
request.respond(line, "text/plain")
#when child is done push done message to response queue
request.respond("{{END}}", "text/plain")
#remove from processing
discard doneProcessing(requestStr)
readStreamToOutput(conv.outputStream)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment