forked from dmacias72/unRAID_6.0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shellinabox_64.plg
477 lines (404 loc) · 12.7 KB
/
shellinabox_64.plg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
<?xml version='1.0' standalone='yes'?>
<PLUGIN>
<!--
2012-11-30 - v0.1 - Initial Build
2013-07-24 - v0.2 - Initial public release. Using the patched version of shellinabox by overbryn to correct the Firefox issues.
2014-02-08 - v0.3 - Add ability to spicfy user css files
The plugin implements a web server that can export arbitrary command line tools to a web based terminal emulator. This emulator is accessible to any JavaScript and CSS enabled web browser and does not require any additional browser plugins.
-->
<FILE Name="/boot/packages/shellinabox-2.14-x86_64-1alien.tgz" Run="upgradepkg --install-new">
<URL>http://www.slackware.com/~alien/sbrepos/14.1/x86_64/shellinabox/shellinabox-2.14-x86_64-1alien.tgz</URL>
<MD5>69b422000827ab1ad7b155b203bcf75d</MD5>
</FILE>
<FILE Name="/boot/config/plugins/shellinaboxd/shellinabox.png">
<URL>http://unraid-greenleaf-repository.googlecode.com/files/shellinabox.png</URL>
</FILE>
<!-- clean up previous install -->
<FILE Name="/tmp/shellinaboxd-cleanup" Run="/bin/bash">
<INLINE>
<![CDATA[
[ -d /usr/local/emhttp/plugins/shellinaboxd ] && rm -f -R /usr/local/emhttp/plugins/shellinaboxd
[ -f /etc/rc.d/rc.shellinaboxd ] && rm -f /etc/rc.d/rc.shellinabox
[ -f /var/run/shellinaboxd/shellinaboxd.pid ] && rm -f /var/run/shellinaboxd/shellinaboxd.pid
rm /tmp/shellinaboxd-cleanup
]]>
</INLINE>
</FILE>
<FILE Name="/boot/config/plugins/shellinaboxd/shellinaboxd.cfg">
<INLINE>
<![CDATA[
#shellinaboxd configuration
SERVICE="disable"
PORT="4500"
CSS="Normal:+/usr/doc/shellinabox-2.14/black-on-white.css,White:-/usr/doc/shellinabox-2.14/white-on-black.css"
]]>
</INLINE>
</FILE>
<FILE Name="/etc/rc.d/rc.shellinaboxd" Mode="0770">
<INLINE>
<![CDATA[
#!/bin/sh
# Start/stop/restart the shellinaboxd:
shellinaboxd_start() {
# no-op if not enabled
if [ $SERVICE != "enable" ]; then
return
fi
# no-op if already running
if [ -r /var/run/shellinaboxd/shellinaboxd.pid ]; then
return
fi
CMDLINE="cd /tmp && /usr/sbin/shellinaboxd --background=/var/run/shellinaboxd/shellinaboxd.pid -s /:LOGIN --port=$PORT"
echo "Starting Shellinaboxd: $CMDLINE"
sleep 1
nohup $CMDLINE --user-css=$CSS > /dev/null 2>&1 &
TIMER=0
while [ ! -e /var/run/httpd.pid ]; do
sleep 1
let TIMER=$TIMER+1
echo -n $TIMER
if [ $TIMER -gt 10 ]; then
echo -n "shellinaboxd.pid not created for some reason"
break
fi
done
echo "... OK"
}
shellinaboxd_stop() {
echo "Stopping shellinaboxd..."
kill $(cat /var/run/shellinaboxd/shellinaboxd.pid)
sleep 3
if [ -e /var/run/shellinaboxd/shellinaboxd.pid ]; then
kill -9 $(cat /var/run/shellinaboxd/shellinaboxd.pid)
rm -f /var/run/shellinaboxd/shellinaboxd.pid
fi
echo "shellinaboxd Stopped"
}
shellinaboxd_restart() {
shellinaboxd_stop
sleep 3
shellinaboxd_start
}
shellinaboxd_buttonstart()
{
echo "Enabling Shellinabox"
CONFIG="/boot/config/plugins/shellinaboxd/shellinaboxd.cfg"
if [ -f $CONFIG ]; then
sed -i "s/"disable"/"enable/"" $CONFIG
sleep 3
echo "Starting Shellinabox"
shellinaboxd_start
fi
}
shellinaboxd_update()
{
shellinaboxd_stop
sleep 1
shellinaboxd_install
sleep 1
shellinaboxd_start
}
# read our configuration
source /boot/config/plugins/shellinaboxd/shellinaboxd.cfg
case "$1" in
'start')
shellinaboxd_start
;;
'stop')
shellinaboxd_stop
;;
'restart')
shellinaboxd_restart
;;
'update')
shellinaboxd_update
;;
'buttonstart')
shellinaboxd_buttonstart
;;
*)
echo "usage $0 start|stop|restart|update"
esac
]]>
</INLINE>
</FILE>
<FILE Name="/usr/local/emhttp/plugins/shellinaboxd/shellinaboxd.page">
<INLINE>
<![CDATA[
Menu="NetworkServices"
Icon="shellinabox.png"
Version="shellinabox-2.14-i486-2rj"
Author="prostuff1"
Type="php"
Title="shellinaboxd"
]]>
</INLINE>
</FILE>
<FILE Name="/usr/local/emhttp/plugins/shellinaboxd/shellinabox.png">
<LOCAL>/boot/config/plugins/shellinaboxd/shellinabox.png</LOCAL>
</FILE>
<FILE Name="/usr/local/emhttp/plugins/shellinaboxd/shellinaboxd.php">
<INLINE>
<![CDATA[
<?PHP
$shellinaboxd_cfg = parse_ini_file( "/boot/config/plugins/shellinaboxd/shellinaboxd.cfg");
$shellinaboxd_running = file_exists( "/var/run/shellinaboxd/shellinaboxd.pid") ? "yes" : "no";
?>
<style>
.notes {
font-size:85%;
color:#666;
}
.status_head {
font-size: 14px;
font-weight: bold;
}
</style>
<div style="width: 49%; float:left">
<div id="title">
<span class="left">Status: <img src='/plugins/shellinaboxd/device_status.png'>
<?if ($shellinaboxd_running=="yes"):?>
<a href="http://<?=$var['NAME'];?>:<?=$shellinaboxd_cfg["PORT"];?>" target="_blank"><span class="green"><b>RUNNING</b></span></a><span style="font-size:12px;"><b><?=$shellinaboxd_curversion?></b></span>
<?else:?>
<span class="red"><b>STOPPED</b></span>
<?endif;?>
</span>
</div>
<?if ($shellinaboxd_running=="yes"):?>
<div style="position:relative;float:left;width:50%;text-align:right; margin-bottom:24px">
<form name="shellinaboxd_stop" method="POST" action="/update.htm" target="progressFrame">
<input type="hidden" name="cmd" value="/etc/rc.d/rc.shellinaboxd stop">
<input type="submit" name="runCmd" value="Stop">
</form>
</div>
<div style="position:relative;float:left;width:50%;text-align:left;margin-bottom:24px">
<form name="shellinaboxd_restart" method="POST" action="/update.htm" target="progressFrame">
<input type="hidden" name="cmd" value="/etc/rc.d/rc.shellinaboxd restart">
<input type="submit" name="runCmd" value="Restart">
</form>
</div>
<?else:?>
<div style="position:relative;float:left;width:100%;text-align:center;margin-bottom:24px">
<form name="shellinaboxd_start" method="POST" action="/update.htm" target="progressFrame">
<input type="hidden" name="cmd" value="/etc/rc.d/rc.shellinaboxd buttonstart">
<input type="submit" name="runCmd" value="Start">
</form>
</div>
<?endif;?>
<? if ($shellinaboxd_rollback=="yes"): ?>
<div style="position:relative;float:left;width:50%;text-align:right;margin-bottom:24px">
<form name="shellinaboxd_update1" method="POST" action="/update.htm" target="progressFrame">
<input type="hidden" name="cmd" value="/etc/rc.d/rc.shellinaboxd updateplg">
<input type="submit" name="runCmd" value="Update PLG">
</form>
</div>
<div style="position:relative;float:left;width:50%;text-align:left;margin-bottom:24px">
<form name="shellinaboxd_downgrade" method="POST" action="/update.htm" target="progressFrame">
<input type="hidden" name="cmd" value="/etc/rc.d/rc.shellinaboxd downgradeplg">
<input type="submit" name="runCmd" value="Downgrade PLG">
</form>
</div>
<?else:?>
<div style="position:relative;float:left;width:100%;text-align:center;margin-bottom:24px">
<form name="shellinaboxd_update" method="POST" action="/update.htm" target="progressFrame">
<input type="hidden" name="cmd" value="/etc/rc.d/rc.shellinaboxd updateplg">
<input type="submit" name="runCmd" value="Update PLG">
</form>
</div>
<?endif;?><br/>
<p style="margin-left:10px;"><b>Plug-in Version: <?=$shellinaboxd_plgver;?></b></p>
</div>
<div style="width: 49%; float:right">
<div id="title">
<span class="left">Configuration: <img src='/plugins/deluge/new_config.png'></span>
</div>
<form name="shellinaboxd_settings" method="POST" action="/plugins/shellinaboxd/shellinaboxdctl.php" target="progressFrame" onsubmit="return validateForm()">
<input type="hidden" name="cmd" value="apply">
<table class="settings">
<tr>
<td>Enable shellinaboxd:</td>
<td><select name="SERVICE" size="1" onChange="checkRUNNING(this.form);">
<?=mk_option($shellinaboxd_cfg['SERVICE'], "disable", "No");?>
<?=mk_option($shellinaboxd_cfg['SERVICE'], "enable", "Yes");?>
</select></td>
</tr>
<tr>
<td>shellinaboxd Port:</td>
<td><input type="text" name="PORT" value="<?=$shellinaboxd_cfg['PORT'];?>"></td>
</tr>
<tr>
<td>shellinaboxd CSS:</td>
<td><input type="text" name="CSS" value="<?=$shellinaboxd_cfg['CSS'];?>"></td>
</tr>
<td></td>
<td><input type="submit" name="runCmd" value="Apply"><button type="button" onClick="done();">Done</button></td>
</tr>
</table>
</form>
</div>
<div id="title"><span class="left">Console:
<?if ($shellinaboxd_running=="yes"):?>
<?$HOST = shell_exec( "ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1'" ); ?>
<br/>
<a target="_blank" href="http://<? echo $HOST;?>:<?=$shellinaboxd_cfg['PORT'];?>">Open in new tab</a>
<br/>
<br/>
<span style="width:95%;">
<iframe src="http://<? echo $HOST;?>:<?=$shellinaboxd_cfg['PORT'];?>" style="width:95%;height:400px"></iframe>
</span>
<?endif;?>
</span></div>
<script type="text/javascript">
function checkRUNNING(form)
{
if ("<?=$shellinaboxd_running;?>" == "yes") {
form.PORT.disabled = true;
form.CSS.disabled = true;
}
}
function validateForm()
{
document.forms["shellinaboxd_settings"]["PORT"].disabled = false;
document.forms["shellinaboxd_settings"]["CSS"].disabled = false;
}
checkRUNNING(document.shellinaboxd_settings);
</script>
]]>
</INLINE>
</FILE>
<FILE Name="/usr/local/emhttp/plugins/shellinaboxd/shellinaboxdctl.php">
<INLINE>
<![CDATA[
<?PHP
$logfile = "/var/log/plugins/shellinaboxd";
$configfile = "/boot/config/plugins/shellinaboxd/shellinaboxd.cfg";
date_default_timezone_set(substr(readlink("/etc/localtime-copied-from"), 20));
if (empty($_SERVER['SHELL']))
$newline = "<br>";
else
$newline = "\n";
$cur_dt = date("F j\, Y h:i:s A");
write_log("\nStart: $cur_dt");
$settings = array(
"SERVICE",
"PORT",
"CSS",
);
parse_str($argv[1],$_POST);
$SERVICE=$_POST['SERVICE'];
$PORT=$_POST['PORT'];
$CSS=$_POST['CSS'];
write_log("SERVICE: $SERVICE\nPORT: $PORT\nCSS: $CSS");
switch ($_POST['cmd']) {
case 'apply':
saveconfig();
if ($SERVICE == "enable") {
applyconfig();
startshellinaboxd();
}
else
stopshellinaboxd();
break;
case 'start':
break;
case 'stop':
break;
case 'enable':
break;
case 'disable':
break;
default:
break;
}
if (empty($_SERVER['SHELL'])) {
echo("<html>");
echo("<head><script>var goback=parent.location;</script></head>");
echo("<body onLoad=\"parent.location=goback;\"></body>");
echo("</html>");
}
$cur_dt = date("F j\, Y h:i:s A");
write_log("\nEnd: $cur_dt");
function startshellinaboxd() {
global $newline, $log;
echo("Starting shellinaboxd...");
exec_log("/etc/rc.d/rc.shellinaboxd start");
echo("Completed$newline");
}
function stopshellinaboxd() {
global $newline, $log;
echo("Stopping shellinaboxd...");
exec_log("/etc/rc.d/rc.shellinaboxd stop");
echo("Completed$newline");
}
function applyconfig() {
echo("Applying Settings...");
global $newline, $log, $SERVICE, $PORT, $CSS;
}
function saveconfig () {
echo("Saving Settings...");
global $_POST, $configfile, $settings, $newline;
$string .= "#shellinaboxd configuration\n";
foreach ($_POST as $key=>$value) {
if (in_array($key, $settings)) {
$string .= "$key=\"$value\"\n";
}
}
write_string($configfile, $string, TRUE);
echo("Completed$newline ");
}
function exec_log($cmd) {
$results = exec($cmd);
$results = "\nCMD: $cmd \nResults: $results";
write_log($results);
}
function write_log($contents) {
global $logfile;
write_string($logfile, "$contents\n", FALSE);
}
function write_string ($file, $contents, $overwrite) {
if (file_exists($file)) {
if ($overwrite)
unlink($file);
touch($file);
}
else {
touch($file);
}
$fp = @fopen($file, 'a');
@flock($fp, LOCK_EX);
@fwrite($fp, $contents);
@flock($fp, LOCK_UN);
@fclose($fp);
}
?>
]]>
</INLINE>
</FILE>
<FILE Name="/tmp/shellinaboxd-install" Run="/bin/bash">
<INLINE>
<![CDATA[
# include our config vars
source /boot/config/plugins/shellinaboxd/shellinaboxd.cfg
# create shellinaboxd-writable directory for pid file
if [ ! -e /var/run/shellinaboxd ]; then
mkdir /var/run/shellinaboxd
chmod 0777 /var/run/shellinaboxd
fi
# create shellinaboxd plugin dir if required
if [ ! -d /boot/config/plugins/shellinaboxd ]; then
mkdir -p /boot/config/plugins/shellinaboxd
fi
#Start shellinaboxd if enabled
#[ $SERVICE = "enable" ] && php /usr/local/emhttp/plugins/shellinaboxd/shellinaboxdctl.php "cmd=apply&SERVICE=$SERVICE&PORT=$PORT&CSS=$CSS"
rm /tmp/shellinaboxd-install
]]>
</INLINE>
</FILE>
<!-- create log file -->
<FILE Name="/var/log/plugins/shellinaboxd">
<INLINE>
<![CDATA[
]]>
</INLINE>
</FILE>
</PLUGIN>