8
8
* License: GNU/GPLv2
9
9
* @see LICENSE.txt
10
10
*
11
- * This file: CLI handler (last modified: 2023.12.01 ).
11
+ * This file: CLI handler (last modified: 2024.09.02 ).
12
12
*/
13
13
14
14
namespace phpMussel \CLI ;
@@ -119,31 +119,35 @@ public function __construct(\phpMussel\Core\Loader &$Loader, \phpMussel\Core\Sca
119
119
if (substr ($ Command , 0 , 10 ) === 'hash_file: ' ) {
120
120
$ this ->LastAlgo = substr ($ Command , 10 );
121
121
echo "\n" . $ this ->hashFile ($ Clean );
122
+ continue ;
122
123
}
123
124
124
125
/** Generate a CoEx signature using a file. */
125
- elseif ($ Command === 'coex_file ' ) {
126
+ if ($ Command === 'coex_file ' ) {
126
127
echo "\n" . $ this ->coexFile ($ Clean );
128
+ continue ;
127
129
}
128
130
129
131
/** Fetch PE metadata. */
130
- elseif ($ Command === 'pe_meta ' ) {
132
+ if ($ Command === 'pe_meta ' ) {
131
133
echo "\n" . $ this ->peMeta ($ Clean );
134
+ continue ;
132
135
}
133
136
134
137
/** Generate a hash signature using a string. */
135
- elseif (substr ($ Command , 0 , 5 ) === 'hash: ' ) {
138
+ if (substr ($ Command , 0 , 5 ) === 'hash: ' ) {
136
139
$ this ->LastAlgo = substr ($ Command , 5 );
137
140
if (in_array ($ this ->LastAlgo , hash_algos ())) {
138
141
$ TargetData = substr ($ Clean , strlen ($ Command ) + 1 );
139
142
echo "\n" . hash ($ this ->LastAlgo , $ TargetData ) . ': ' . strlen ($ TargetData ) . ': ' . $ this ->Loader ->L10N ->getString ('cli_signature_placeholder ' ) . "\n" ;
140
143
} else {
141
144
echo "\n" . $ this ->Loader ->L10N ->getString ('cli_algo_not_supported ' ) . "\n" ;
142
145
}
146
+ continue ;
143
147
}
144
148
145
149
/** Generate a URL scanner signature from a URL. */
146
- elseif ($ Command === 'url_sig ' ) {
150
+ if ($ Command === 'url_sig ' ) {
147
151
echo "\n" ;
148
152
$ Clean = $ this ->Scanner ->normalise (substr ($ Clean , strlen ($ Command ) + 1 ));
149
153
$ URL = ['AvoidMe ' => '' , 'ForThis ' => '' ];
@@ -184,57 +188,64 @@ public function __construct(\phpMussel\Core\Loader &$Loader, \phpMussel\Core\Sca
184
188
}
185
189
}
186
190
unset($ URL );
191
+ continue ;
187
192
}
188
193
189
194
/** Generate a CoEx signature using a string. */
190
- elseif (preg_match ('~^(?:(?:[Cc]|ϲ|с)(?:[Oo]|ο|о)(?:[Ee]|е)(?:[Xx]|х))$~ ' , $ CommandNatural )) {
195
+ if (preg_match ('~^(?:(?:[Cc]|ϲ|с)(?:[Oo]|ο|о)(?:[Ee]|е)(?:[Xx]|х))$~ ' , $ CommandNatural )) {
191
196
$ TargetData = substr ($ Clean , strlen ($ Command ) + 1 );
192
197
echo sprintf (
193
198
"\n\$sha256:%s; \$StringLength:%d;%s \n" ,
194
199
hash ('sha256 ' , $ TargetData ),
195
200
strlen ($ TargetData ),
196
201
$ this ->Loader ->L10N ->getString ('cli_signature_placeholder ' )
197
202
);
203
+ continue ;
198
204
}
199
205
200
206
/** Convert a binary string to a hexadecimal. */
201
- elseif (preg_match ('~^(?:[Hh][Ee][Xx]_[Ee][Nn][Cc][Oo][Dd][Ee]|[Xx]|х)$~ ' , $ CommandNatural )) {
207
+ if (preg_match ('~^(?:[Hh][Ee][Xx]_[Ee][Nn][Cc][Oo][Dd][Ee]|[Xx]|х)$~ ' , $ CommandNatural )) {
202
208
$ TargetData = substr ($ Clean , strlen ($ Command ) + 1 );
203
209
echo "\n" . bin2hex ($ TargetData ) . "\n" ;
210
+ continue ;
204
211
}
205
212
206
213
/** Convert a hexadecimal to a binary string. */
207
- elseif ($ Command === 'hex_decode ' ) {
214
+ if ($ Command === 'hex_decode ' ) {
208
215
$ TargetData = substr ($ Clean , strlen ($ Command ) + 1 );
209
216
echo "\n" . ($ this ->Loader ->hexSafe ($ TargetData ) ?: $ this ->Loader ->L10N ->getString ('response.Invalid data ' )) . "\n" ;
217
+ continue ;
210
218
}
211
219
212
220
/** Convert a binary string to a base64 string. */
213
- elseif ($ Command === 'base64_encode ' || $ Command === 'b ' ) {
221
+ if ($ Command === 'base64_encode ' || $ Command === 'b ' ) {
214
222
$ TargetData = substr ($ Clean , strlen ($ Command ) + 1 );
215
223
echo "\n" . base64_encode ($ TargetData ) . "\n" ;
224
+ continue ;
216
225
}
217
226
218
227
/** Convert a base64 string to a binary string. */
219
- elseif ($ Command === 'base64_decode ' ) {
228
+ if ($ Command === 'base64_decode ' ) {
220
229
$ TargetData = substr ($ Clean , strlen ($ Command ) + 1 );
221
230
echo "\n" . (base64_decode ($ TargetData ) ?: $ this ->Loader ->L10N ->getString ('response.Invalid data ' )) . "\n" ;
231
+ continue ;
222
232
}
223
233
224
234
/** Scan a file or directory. */
225
- elseif (preg_match ('~^(?:[Ss][Cc][Aa][Nn]|[Ss]|ѕ)$~ ' , $ CommandNatural )) {
235
+ if (preg_match ('~^(?:[Ss][Cc][Aa][Nn]|[Ss]|ѕ)$~ ' , $ CommandNatural )) {
226
236
$ TargetData = substr ($ Clean , strlen ($ Command ) + 1 );
227
- echo "\n" ;
228
- echo $ this -> Scanner -> scan ( $ TargetData ) . "\n" ;
237
+ echo "\n" . $ this -> Scanner -> scan ( $ TargetData ) . "\n" ;
238
+ continue ;
229
239
}
230
240
231
241
/** Print the command list. */
232
- elseif (preg_match ('~^(?:[Cc]|ϲ|с)$~ ' , $ CommandNatural )) {
242
+ if (preg_match ('~^(?:[Cc]|ϲ|с)$~ ' , $ CommandNatural )) {
233
243
echo "\n" . $ this ->Loader ->L10N ->getString ('cli_commands ' );
244
+ continue ;
234
245
}
235
246
236
247
/** Print a list of supported algorithms. */
237
- elseif ($ Command === 'algo ' ) {
248
+ if ($ Command === 'algo ' ) {
238
249
echo "\n" ;
239
250
$ Algos = hash_algos ();
240
251
$ Pos = 1 ;
@@ -252,12 +263,11 @@ public function __construct(\phpMussel\Core\Loader &$Loader, \phpMussel\Core\Sca
252
263
}
253
264
}
254
265
echo "\n" ;
266
+ continue ;
255
267
}
256
268
257
269
/** Bad command notice. */
258
- else {
259
- echo "\n" . $ this ->Loader ->L10N ->getString ('bad_command ' ) . "\n" ;
260
- }
270
+ echo "\n" . $ this ->Loader ->L10N ->getString ('bad_command ' ) . "\n" ;
261
271
}
262
272
}
263
273
0 commit comments