summaryrefslogtreecommitdiff
path: root/interactor/interactor.js
diff options
context:
space:
mode:
Diffstat (limited to 'interactor/interactor.js')
-rwxr-xr-xinteractor/interactor.js25
1 files changed, 23 insertions, 2 deletions
diff --git a/interactor/interactor.js b/interactor/interactor.js
index 64684ae..ae38b29 100755
--- a/interactor/interactor.js
+++ b/interactor/interactor.js
@@ -69,7 +69,26 @@ function stopproc(proc){
mkdirp("logs");
+function validparameterchar(c){
+ return 48<=c.charCodeAt(0)&&c.charCodeAt(0)<58;
+}
+
io.on("connection",function(conn){
+ // TODO: make nicer
+ var unsafe_parameter=conn.request._query.parameter;
+ var aicmd_here=aicmd;
+ if(unsafe_parameter!=null){
+ var parameter="";
+ for(var i=0;i<unsafe_parameter.length;i++){
+ if(validparameterchar(unsafe_parameter[i])){
+ parameter+=unsafe_parameter[i];
+ }
+ }
+ if(parameter!=""){
+ aicmd_here+=" "+parameter;
+ }
+ }
+
var id=uniqid();
console.log("New IO connection id "+id);
var pingtimeout=null;
@@ -91,6 +110,8 @@ io.on("connection",function(conn){
fs.writeSync(logfile,s+"\n");
};
+ conn.emit("ainame",aicmd_here);
+
conn.on("disconnect",function(){
console.log("Disconnect id "+id);
log("Ending log on disconnect (id "+id+")");
@@ -133,11 +154,11 @@ io.on("connection",function(conn){
});
- var proc=spawn("sh",["-c",aicmd],{
+ var proc=spawn("sh",["-c",aicmd_here],{
stdio:["pipe","pipe",process.stderr]
});
childpids.push(proc.pid);
- log("Process '"+aicmd+"' started with pid "+proc.pid+", initiated by ip "+conn.request.connection.remoteAddress);
+ log("Process '"+aicmd_here+"' started with pid "+proc.pid+", initiated by ip "+conn.request.connection.remoteAddress);
var buffer="";
proc.stdout.on("data",function(data){
var idx,line,mv,win;