1
- {
2
- module : "Shell" ,
3
-
4
- BASH : "bash" ,
5
- SH : "sh" ,
6
- COMMAND_EXIT : "exit" ,
7
- COMMAND_LINE_RND : "\n" ,
8
-
9
- gThreadGroup : new java . lang . ThreadGroup ( "ShellGroups" ) ,
10
-
11
- Executor : ( function ( ) {
12
- var r = function ( shell ) {
13
- this . shell = shell ;
14
- this . thread = null ;
15
- this . timeout_limit = 300000 ;
16
- } ;
17
- r . prototype = {
18
- setLoginShell : function ( s ) {
19
- if ( s ) this . shell = s ;
20
- } ,
21
- getLoginShell : function ( ) {
22
- return this . shell ;
23
- } ,
24
- setTimeoutLimit : function ( time ) {
25
- if ( time ) this . timeout_limit = time ;
26
- } ,
27
- getTimeoutLimit : function ( time ) {
28
- return this . timeout_limit ;
29
- } ,
30
- execute : function ( command ) {
31
- var process , processBuilder , os ;
32
- var successResult = null ,
33
- errorResult = null ;
34
- var shell = this . shell ;
35
- var rResult = null ;
36
- var timeout_limit = this . timeout_limit ;
37
- try {
38
- processBuilder = new java . lang . ProcessBuilder ( shell , "-c" , command ) ;
39
- processBuilder . directory ( new java . io . File ( java . lang . System . getProperty ( "user.home" ) ) ) ;
40
- process = processBuilder . start ( ) ; ( new java . lang . Thread ( new java . lang . Runnable ( {
41
- run : function ( ) {
42
- java . lang . Thread . sleep ( timeout_limit ) ;
43
- if ( process != null ) process . destroy ( ) ;
44
- }
45
- } ) ) ) . start ( ) ;
46
- rResult = process . waitFor ( ) ;
47
- successMsg = new java . lang . StringBuilder ( ) ;
48
- errorMsg = new java . lang . StringBuilder ( ) ;
49
- successResult = new java . io . BufferedReader ( new java . io . InputStreamReader ( process . getInputStream ( ) ) ) ;
50
- errorResult = new java . io . BufferedReader ( new java . io . InputStreamReader ( process . getErrorStream ( ) ) ) ;
51
- var s ;
52
- while ( ( s = successResult . readLine ( ) ) != null ) {
53
- successMsg . append ( s ) ;
54
- successMsg . append ( Shell . COMMAND_LINE_RND ) ;
55
- }
56
- while ( ( s = errorResult . readLine ( ) ) != null ) {
57
- errorMsg . append ( s ) ; ;
58
- errorMsg . append ( Shell . COMMAND_LINE_RND ) ;
59
- }
60
- if ( successResult != null ) successResult . close ( ) ;
61
- if ( errorResult != null ) errorResult . close ( ) ;
62
- if ( process != null ) process . destroy ( ) ;
63
- process = null ;
64
- return {
65
- code : rResult ,
66
- success : successMsg . toString ( ) ,
67
- error : errorMsg . toString ( )
68
- } ;
69
- } catch ( error ) {
70
- Log . i ( "Timeout: " + command ) ;
71
- if ( successResult != null ) successResult . close ( ) ;
72
- if ( errorResult != null ) errorResult . close ( ) ;
73
- if ( process != null ) process . destroy ( ) ;
74
- process = null ;
75
- return {
76
- code : 1 ,
77
- success : "" ,
78
- error : "Timeout after " + ( timeout_limit / 1000 ) + " seconds."
79
- } ;
80
- }
81
-
82
- } ,
83
- terminate : function ( ) { } ,
84
- } ;
85
- return r ;
86
- } ( ) ) ,
87
-
1
+ /*
2
+ mirai-rhinojs-sdk
3
+ Copyright (C) 2020 StageGuard
4
+
5
+ This program is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU Affero General Public License as published
7
+ by the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU Affero General Public License for more details.
14
+
15
+ You should have received a copy of the GNU Affero General Public License
16
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
17
+ */
18
+
19
+ {
20
+ module : "Shell" ,
21
+
22
+ BASH : "bash" ,
23
+ SH : "sh" ,
24
+ COMMAND_EXIT : "exit" ,
25
+ COMMAND_LINE_RND : "\n" ,
26
+
27
+ gThreadGroup : new java . lang . ThreadGroup ( "ShellGroups" ) ,
28
+
29
+ Executor : ( function ( ) {
30
+ var r = function ( shell ) {
31
+ this . shell = shell ;
32
+ this . thread = null ;
33
+ this . timeout_limit = 300000 ;
34
+ } ;
35
+ r . prototype = {
36
+ setLoginShell : function ( s ) {
37
+ if ( s ) this . shell = s ;
38
+ } ,
39
+ getLoginShell : function ( ) {
40
+ return this . shell ;
41
+ } ,
42
+ setTimeoutLimit : function ( time ) {
43
+ if ( time ) this . timeout_limit = time ;
44
+ } ,
45
+ getTimeoutLimit : function ( time ) {
46
+ return this . timeout_limit ;
47
+ } ,
48
+ execute : function ( command ) {
49
+ var process , processBuilder , os ;
50
+ var successResult = null ,
51
+ errorResult = null ;
52
+ var shell = this . shell ;
53
+ var rResult = null ;
54
+ var timeout_limit = this . timeout_limit ;
55
+ try {
56
+ processBuilder = new java . lang . ProcessBuilder ( shell , "-c" , command ) ;
57
+ processBuilder . directory ( new java . io . File ( java . lang . System . getProperty ( "user.home" ) ) ) ;
58
+ process = processBuilder . start ( ) ; ( new java . lang . Thread ( new java . lang . Runnable ( {
59
+ run : function ( ) {
60
+ java . lang . Thread . sleep ( timeout_limit ) ;
61
+ if ( process != null ) process . destroy ( ) ;
62
+ }
63
+ } ) ) ) . start ( ) ;
64
+ rResult = process . waitFor ( ) ;
65
+ successMsg = new java . lang . StringBuilder ( ) ;
66
+ errorMsg = new java . lang . StringBuilder ( ) ;
67
+ successResult = new java . io . BufferedReader ( new java . io . InputStreamReader ( process . getInputStream ( ) ) ) ;
68
+ errorResult = new java . io . BufferedReader ( new java . io . InputStreamReader ( process . getErrorStream ( ) ) ) ;
69
+ var s ;
70
+ while ( ( s = successResult . readLine ( ) ) != null ) {
71
+ successMsg . append ( s ) ;
72
+ successMsg . append ( Shell . COMMAND_LINE_RND ) ;
73
+ }
74
+ while ( ( s = errorResult . readLine ( ) ) != null ) {
75
+ errorMsg . append ( s ) ; ;
76
+ errorMsg . append ( Shell . COMMAND_LINE_RND ) ;
77
+ }
78
+ if ( successResult != null ) successResult . close ( ) ;
79
+ if ( errorResult != null ) errorResult . close ( ) ;
80
+ if ( process != null ) process . destroy ( ) ;
81
+ process = null ;
82
+ return {
83
+ code : rResult ,
84
+ success : successMsg . toString ( ) ,
85
+ error : errorMsg . toString ( )
86
+ } ;
87
+ } catch ( error ) {
88
+ Log . i ( "Timeout: " + command ) ;
89
+ if ( successResult != null ) successResult . close ( ) ;
90
+ if ( errorResult != null ) errorResult . close ( ) ;
91
+ if ( process != null ) process . destroy ( ) ;
92
+ process = null ;
93
+ return {
94
+ code : 1 ,
95
+ success : "" ,
96
+ error : "Timeout after " + ( timeout_limit / 1000 ) + " seconds."
97
+ } ;
98
+ }
99
+
100
+ } ,
101
+ terminate : function ( ) { } ,
102
+ } ;
103
+ return r ;
104
+ } ( ) ) ,
105
+
88
106
}
0 commit comments