Source

phpshell / phpshell.php

The default branch has multiple heads

Full commit
  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
<?php // -*- coding: utf-8 -*-

/*

  **************************************************************
  *                     PHP Shell @VERSION@                    *
  **************************************************************

  $Rev$ $Date$

  PHP Shell is an interactive PHP script that will execute any command
  entered.  See the files README, INSTALL, and SECURITY or
  http://phpshell.sf.net/ for further information.

  Copyright (C) 2000-2006, 2008 Martin Geisler <mgeisler@mgeisler.net>

  This program is free software; you can redistribute it and/or
  modify it under the terms of the GNU General Public License
  as published by the Free Software Foundation; either version 2
  of the License, or (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  02110-1301 USA.
  
*/

/* There are no user-configurable settings in this file, please see
 * config.php instead. */


/* This error handler will turn all notices, warnings, and errors into fatal
 * errors, unless they have been suppressed with the @-operator. */
function error_handler($errno, $errstr, $errfile, $errline, $errcontext) {
    /* The @-opertor (used with chdir() below) temporarely makes
     * error_reporting() return zero, and we don't want to die in that case.
     * We do note the error in the output, though. */
    if (error_reporting() == 0) {
        $_SESSION['output'] .= $errstr . "\n";
    } else {
        die('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
  <title>PHP Shell @VERSION@</title>
  <link rel="stylesheet" href="style.css" type="text/css">
</head>
<body>
  <h1>Fatal Error!</h1>
  <p><b>' . $errstr . '</b></p>
  <p>in <b>' . $errfile . '</b>, line <b>' . $errline . '</b>.</p>

  <hr>

  <p>Please consult the <a href="README">README</a>, <a
  href="INSTALL">INSTALL</a>, and <a href="SECURITY">SECURITY</a> files for
  instruction on how to use PHP Shell.</p>

  <hr>

  <address>
  Copyright &copy; 2000&ndash;2005, <a href="mailto:mgeisler@mgeisler.net">
  Martin Geisler</a> and others, please see <a href="AUTHORS">AUTHORS</a>. 
  This is PHP Shell @VERSION@, get the latest version at <a
  href="http://phpshell.sourceforge.net/">phpshell.sf.net</a>.
  </address>

</body>
</html>');
    }
}

/* Installing our error handler makes PHP die on even the slightest problem.
 * This is what we want in a security critical application like this. */
set_error_handler('error_handler');


/* Clear history */
function clear() {
  $_SESSION['output'] = '';
}

function stripslashes_deep($value) {
    if (is_array($value))
        return array_map('stripslashes_deep', $value);
    else
        return stripslashes($value);
}

function htmlescape($value) {
    return str_replace("\0", "&#000;", 
        htmlspecialchars($value, ENT_COMPAT));
}

/* even though proc_open has a $cwd argument, we don't use it because php 4 
 * doesn't support it. */
function add_dir($cmd, $dir){
    return "cd ".escapeshellarg($dir)."\n".$cmd;
}

/* executes a command in the given working directory and returns output */
function exec_cwd($cmd, $directory) {   
    list($status, $stdout, $stderr) = exec_command($cmd, $directory);
    return $stdout;
}

/* return exit code of command */
function exec_test_cwd($cmd, $directory) {
    list($status, $stderr, $stderr) = exec_command($cmd, $directory);
    return $status;
}

/* 
 * Where the real magic happens
 *
 * $mergeoutputs says if the command's stdout and stderr should be separated 
 * or merged into a single string.
 * $fd9 adds an extra pipe on file descriptor 9 to the process, used for out 
 * of band communication.
 */
function exec_command($cmd, $dir, $mergeoutput=False, $fd9=False) {

    $io = array();
    $pipes = array(1 => array('pipe', 'w'), 2 => array('pipe', 'w'));
    if($fd9) $pipes[9] = array('pipe', 'w');
    $p = proc_open(add_dir($command, $_SESSION['cwd']), $pipes, $io);

    /* 
     * Read output using stream_select. Reading the pipes sequentially could
     * potentially cause a deadlock if the subshell would write a large 
     * ammount of data to pipe 2 (stderr), while we are reading pipe 1. The
     * subshell would then block waiting for us to read pipe 2, and we would
     * block waiting for the subshell to write to pipe 1, resulting in a 
     * deadlock.
     */

    // set all streams to nonblocking mode, so we can read them all at once 
    // below
    foreach($io as $pipe) {
        stream_set_blocking($pipe, 0);
    }

    $out = $err = $out9 = '';

    while (True) {
        // we need to recreate $read each time, because it gets modified in
        // stream_select. Also, we just want to select on those pipes that are
        // not closed yet. 
        $read = array();
        foreach($io as $pipe){
            if(!feof($pipe))
                $read[] = $pipe;
        }

        // break out if nothing more to read
        if(count($read) == 0) 
            break;

        // define these because we must pass something by reference
        $write = null;
        $except = null;

        // wait for the subshell to write to any of the pipes
        stream_select($read, $write, $except, 10000);

        // and read them. We don't bother to see which one is ready, we just 
        // try them all. That's why we put them in nonblocking mode. 
        $out .= fgets($io[1]);
        if ($mergeoutput) {
            $out .= fgets($io[2]);
        } else {
            $err .= fgets($io[2]);
        }
        if ($fd9) {
            $out9 .= fgets($io[9]);
        }
    }

    fclose($io[1]);
    fclose($io[2]);
    fclose($io[9]);
    $status = proc_close($p);
    $ret = array($status, $out);
    if (!$mergeoutputs) $ret[] = $err;
    if ($fd9) $ret[] = $out9;    
    return $ret;
}



/* initialize everything */

if (get_magic_quotes_gpc())
    $_POST = stripslashes_deep($_POST);

/* Initialize some variables we need again and again. */
$username = isset($_POST['username']) ? $_POST['username'] : '';
$password = isset($_POST['password']) ? $_POST['password'] : '';
$nounce   = isset($_POST['nounce'])   ? $_POST['nounce']   : '';

$command  = isset($_POST['command'])  ? $_POST['command']  : '';
$rows     = isset($_POST['rows'])     ? $_POST['rows']     : 24;
$columns  = isset($_POST['columns'])  ? $_POST['columns']  : 80;

/* Load the configuration. */
$ini = parse_ini_file('config.php', true);

if (empty($ini['settings']))
    $ini['settings'] = array();

/* Default settings --- these settings should always be set to something. */
$default_settings = array(
    'home-directory'        => '.',
    'safe-mode-warning'     => True);
$showeditor = false;
$writeaccesswarning = false;

/* Merge settings. */
$ini['settings'] = array_merge($default_settings, $ini['settings']);

session_start();


function runcommand($cmd) {
    global $rows, $columns, $ini;

    $extra_env = 
        "export ROWS=$rows\n".
        "export COLUMNS=$columns\n";

    $aliases = '';
    foreach($ini['aliases'] as $al => $expansion){
        $aliases .= "alias $al=".escapeshellarg($expansion)."\n";
    }

    $command = 
        $extra_env.
        $aliases.
        $cmd."\n".
        "pwd >&9\n";

    list($status, $out, $newcwd) = exec_command($command, $_SESSION['cwd'], True, True);

    // trim because 'pwd' adds a newline
    if(strlen($newcwd) > 0 && $newcwd{0} == '/')
        $_SESSION['cwd'] = trim($newcwd);

    return htmlescape($out);
}    


function builtin_download($arg) {
    /* download specified file */

    if ($arg == '') {
        $_SESSION['output'] .= "Syntax: download filename\n(you forgot filename)\n";
        return;
    }

    /* test if file exists */
    if(exec_test_cwd("test -e ".escapeshellarg($arg), $_SESSION['cwd']) != 0) {
        $_SESSION['output'] .= "download: file not found: '$arg'\n";
        return;
    }

    if(exec_test_cwd("test -r ".escapeshellarg($arg), $_SESSION['cwd']) != 0) {
        $_SESSION['output'] .= "download: Permission denied for file '$arg'\n";
        return;
    }

    $filesize = trim(exec_cwd("stat -c%s ".escapeshellarg($arg), $_SESSION['cwd']));

    // We can't use exec_command because we need access to the pipe
    $io = array();
    $p = proc_open(add_dir('cat '.escapeshellarg($arg), $_SESSION['cwd']), 
                   array(1 => array('pipe', 'w')), $io);

    /* Passing a filename correctly in a content disposition header is nigh 
     * impossible. If the filename is unsafe, we just pass nothing and let the
     * user choose himself. 
     * The 'rules' are at http://tools.ietf.org/html/rfc6266#appendix-D
     * If problematic characters are encountered we use the filename*= form, 
     * user agents that don't support that don't get a filename hint. 
     */
    $basename = basename($arg);
    // match non-ascii, non printable, and '%', '\', '"'. 
    if (preg_match('/[\x00-\x1F\x80-\xFF\x7F%\\\\"]/', $basename)) {
        // Assume UTF-8 on the file system, since there's no way to check
        $filename_hdr = "filename*=UTF-8''".rawurlencode($basename).';';
    } else {
        $filename_hdr = 'filename="'.$basename.'";';
    }

    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; '.$filename_hdr);
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: private, must-revalidate, post-check=0, pre-check=0');
    if($filesize) header('Content-Length: '.$filesize);

    /* Read output from cat. */
    fpassthru($io[1]);
    
    fclose($io[1]);
    proc_close($p);

    die();
    return;
}

/* This is a tiny editor which you can start calling 'editor file'*/
function builtin_editor($arg) {
    global $editorcontent, $filetoedit, $showeditor, $writeaccesswarning;

    if($arg == '') {
        $_SESSION['output'] .= " Syntax: editor filename\n (you forgot the filename)\n";
        return;
    }

    $escarg = escapeshellarg($arg);
    $filetoedit = $arg;

    if(exec_test_cwd("test -e $escarg", $_SESSION['cwd']) != 0) {
        // file does not exist
        $editorcontent = '';
        $showeditor = true;

        // test current directory for write access
        if(exec_test_cwd("test -w .", $_SESSION['cwd']) != 0) {
            $writeaccesswarning = true;
        }

    } else {

        if(exec_test_cwd("test -f $escarg", $_SESSION['cwd']) != 0) {
            $_SESSION['output'] .= "editor: file '$arg' not found or not a regular file\n";
            return;
        }

        if(exec_test_cwd("test -r $escarg", $_SESSION['cwd']) != 0) {
            $_SESSION['output'] .= "editor: Permission denied for file '$arg'\n";
            return;
        }

        // test write access
        if(exec_test_cwd("test -w $escarg", $_SESSION['cwd']) != 0) {
            $writeaccesswarning = true;
        }

        list($status, $output, $error) = exec_command("cat $escarg", $_SESSION['cwd']);
        if($status != 0) {
            $_SESSION['output'] .= "editor: error: ".htmlescape($error)."\n";
        } else {
            $editorcontent = htmlspecialchars($output);
            $showeditor = true;
        }
    }

    return;
}

function builtin_logout($cmd = null, $arg = null) {
    /* Empty the session data, except for the 'authenticated' entry which the
     * rest of the code needs to be able to check. */
    $_SESSION = array('authenticated' => false);

    /* Unset the client's cookie, if it has one. */
//    if (isset($_COOKIE[session_name()]))
//        setcookie(session_name(), '', time()-42000, '/');

    /* Destroy the session data on the server.  This prevents the simple
     * replay attach where one uses the back button to re-authenticate using
     * the old POST data since the server wont know the session then.*/
//    session_destroy();
}


/* the builtins this shell recognizes */
$builtins = array(
    'download' => 'builtin_download',
    'editor' => 'builtin_editor',
    'exit' => 'builtin_logout',
    'logout' => 'builtin_logout');


/* Delete the session data if the user requested a logout.  This leaves the
 * session cookie at the user, but this is not important since we
 * authenticates on $_SESSION['authenticated']. */
if (isset($_POST['logout']))
    logout();
    
/* Delete history if submitted */
if (isset($_POST['clear']))
    clear();

/* Attempt authentication. */
if (isset($_SESSION['nounce']) && $nounce == $_SESSION['nounce'] && 
    isset($ini['users'][$username])) {
    if (strchr($ini['users'][$username], ':') === false) {
        // No seperator found, assume this is a password in clear text.
        $_SESSION['authenticated'] = ($ini['users'][$username] == $password);
    } else {
        list($fkt, $salt, $hash) = explode(':', $ini['users'][$username]);
        $_SESSION['authenticated'] = ($fkt($salt . $password) == $hash);
    }
}


/* Enforce default non-authenticated state if the above code didn't set it
 * already. */
if (!isset($_SESSION['authenticated']))
    $_SESSION['authenticated'] = false;


if ($_SESSION['authenticated']) {  
    /* Initialize the session variables. */
    if (empty($_SESSION['cwd'])) {
        $_SESSION['cwd'] = realpath($ini['settings']['home-directory']);
        $_SESSION['history'] = array();
        $_SESSION['output'] = '';
    }

    /* Save content from 'editor' */
    if (isset($_POST["filetoedit"]) && ($_POST["filetoedit"] != "")) {        
        $io = array();
        $p = proc_open(add_dir('cat >'.escapeshellarg($_POST['filetoedit']), $_SESSION['cwd']), 
                       array(0 => array('pipe', 'r'), 2 => array('pipe', 'w')), $io);

        /*
         * I'm not entirely sure this approach will not deadlock, but I think 
         * it is ok. If the subshell fails it will exits and our write 
         * fails. There is one assumption though: the subshell will not block
         * on writing to it's stderr while we are not reading it. As long as 
         * the error message is small enough to fit in the kernel buffer, as 
         * is expected with sh/cat redirect errors, this is no problem, but if
         * that assumption does not hold we will have to do some uglier tricks
         * using stream_select and friends. 
         * 
         * IMPORTANT ASSUMPTION: THE ERROR MESSAGE IS SMALL ENOUGH TO FIT IN 
         * THE KERNELS BUFFER OF THE SUBSHELLS STDOUT.
         */

        /* The docs are not entirely clear whether fwrite can write only part
         * of the string to a pipe, but testing shows that php internally 
         * splits up large writes into smaller ones, so everything gets 
         * written.
         */
        if(fwrite($io[0], $content) === FALSE) {
            $_SESSION['output'] .= "editor: Error saving editor content to ".htmlescape($_POST['filetoedit'])."\n";
        }
        // close immediately to let the shell know we are done. 
        fclose($io[0]);
        // also read any error messages
        while (!feof($io[2])) {
            $errmsg .= fread($io[2], 8192);
        }
        if(trim($errmsg) != '') {
            $_SESSION['output'] .= htmlescape('editor: '.$errmsg);
        }
        fclose($io[2]);
        proc_close($p);
    }

    /* execute the command */
    if (trim($command) != '') {
        /* Save the command for later use in the JavaScript.  If the command is
         * already in the history, then the old entry is removed before the
         * new entry is put into the list at the front. */
        if (($i = array_search($command, $_SESSION['history'])) !== false)
            unset($_SESSION['history'][$i]);
        
        array_unshift($_SESSION['history'], $command);
  
        /* Now append the commmand to the output. */
        $_SESSION['output'] .= '$ ' . $command . "\n";

        // append a space to $command to guarantee the last capture group 
        // matches. It's removed afterward. 
        preg_match('/^[[:space:]]*([^[:space:]]+)([[:space:]].*)$/', $command.' ', $regs);
        $cmd_name = $regs[1];
        $arg = trim($regs[2]);

        if(array_key_exists($cmd_name, $builtins)) {
            $builtins[$cmd_name]($arg);
        } else {
            /* The command is not an internal command, so we execute it and 
             * save the output. We use the full input, not the one parsed with
             * the regex above, and let the shell parse it. */
            runcommand($command);
        }
    }

    /* Build the command history for use in the JavaScript */
    if (empty($_SESSION['history'])) {
        $js_command_hist = '""';
    } else {
        $escaped = array_map('addslashes', $_SESSION['history']);
        $js_command_hist = '"", "' . implode('", "', $escaped) . '"';
    }
}

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
  <title>PHP Shell @VERSION@</title>
  <link rel="stylesheet" href="style.css" type="text/css">

  <script type="text/javascript">
  <?php if ($_SESSION['authenticated'] && ! $showeditor) { ?>

  var current_line = 0;
  var command_hist = new Array(<?php echo $js_command_hist ?>);
  var last = 0;

  function key(e) {
    if (!e) var e = window.event;

    if (e.keyCode == 38 && current_line < command_hist.length-1) {
      command_hist[current_line] = document.shell.command.value;
      current_line++;
      document.shell.command.value = command_hist[current_line];
    }

    if (e.keyCode == 40 && current_line > 0) {
      command_hist[current_line] = document.shell.command.value;
      current_line--;
      document.shell.command.value = command_hist[current_line];
    }

  }

  function init() {
    document.shell.setAttribute("autocomplete", "off");
    document.shell.output.scrollTop = document.shell.output.scrollHeight;
    document.shell.command.focus()
  }

  <?php } elseif($_SESSION['authenticated'] && $showeditor) { ?>

  function init() {
    document.shell.filecontent.focus();
  }

  <?php } else { /* if not authenticated */ ?>

  function init() {
    document.shell.username.focus();
  }

  <?php } ?>
  </script>
</head>

<body onload="init()">

<h1>PHP Shell @VERSION@</h1>

<form name="shell" action="<?php print($_SERVER['PHP_SELF']) ?>" method="post">

<?php
if (!$_SESSION['authenticated']) {
    /* Genereate a new nounce every time we preent the login page.  This binds
     * each login to a unique hit on the server and prevents the simple replay
     * attack where one uses the back button in the browser to replay the POST
     * data from a login. */
    $_SESSION['nounce'] = mt_rand();

?>

<fieldset>
  <legend>Authentication</legend>

  <?php
  if (!empty($username))
      echo '  <p class="error">Login failed, please try again:</p>' . "\n";
  else
      echo "  <p>Please login:</p>\n";
  ?>

  <p>Username: <input name="username" type="text" value="<?php echo $username
  ?>"></p>

  <p>Password: <input name="password" type="password"></p>

  <p><input type="submit" value="Login"></p>

  <input name="nounce" type="hidden" value="<?php echo $_SESSION['nounce']; ?>">

</fieldset>

<?php } else { /* Authenticated. */ ?>

<?php if ($ini['settings']['safe-mode-warning'] && ini_get('safe_mode')) { ?>

<div class="warning">
  <p><b>Warning:</b> PHP is running in <a
  href="http://php.net/features.safe-mode">Safe Mode</a>.  This means
  that PHP Shell is likely to <b>fail</b> in strange ways.  See the <a
  href="SECURITY">SECURITY</a> file for some background information
  about Safe Mode and its effects on PHP Shell.</p>
  
  <p>Please note that there is nothing that PHP Shell can do to
  deactivate Safe Mode.  You will have to talk to your system
  administrator about it.</p>

  <p>PHP Shell will try its best to carry on despite Safe Mode.  You
  can disable this warning by setting <code>safe-mode-warning</code>
  to <code>false</code> in the configuration file.</p>
</div>

<?php } /* Safe mode. */ ?>

<fieldset>
  <legend style="background-color: transparent">Script Directory: <code><?php
     echo htmlescape(dirname(__FILE__));
    ?></code> &#9899; Current Directory: <code><?php
     echo htmlescape($_SESSION['cwd']);
    ?></code></legend>

    <?php if(! $showeditor) { /* Outputs the 'terminal' without the editor */ ?>

<div id="terminal">
<textarea name="output" readonly="readonly" cols="<?php echo $columns ?>" rows="<?php echo $rows ?>">
<?php
$lines = substr_count($_SESSION['output'], "\n");
$padding = str_repeat("\n", max(0, $rows+1 - $lines));
echo rtrim($padding . $_SESSION['output']);
?>
</textarea>
<p id="prompt">
  $&nbsp;<input name="command" type="text"
                onkeyup="key(event)" size="<?php echo $columns-2 ?>" tabindex="1">
</p>
</div>

<?php } else { /* Output the 'editor' */ 
print("You are editing this file: ".$filetoedit); 
if($writeaccesswarning) { ?>

<div class="warning">
  <p><b>Warning:</b> You may not have write access to <code><?php echo $filetoedit; ?></code></p>
</div>

<?php } /*write access warning*/ ?>

<div id="terminal">
<textarea name="filecontent" cols="<?php echo $columns ?>" rows="<?php echo $rows ?>">
<?php
    print($editorcontent);
?>
</textarea>
</div>

<?php } /* End of terminal */ ?>

<p>
<?php if(! $showeditor) { /* You can not resize the textarea while
                           * the editor is 'running', because if you would
                           * do so you would lose the changes you have
                           * already made in the textarea since last saving */
?>
  <span style="float: right">Size: <input type="text" name="rows" size="2"
  maxlength="3" value="<?php echo $rows ?>"> &times; <input type="text"
  name="columns" size="2" maxlength="3" value="<?php echo $columns
  ?>"></span>
<?php } ?>


<?php if(! $showeditor) { /* for normal 'non-editor-mode' */ ?>
<input type="submit" value="Execute Command">
<input type="submit" name="clear" value="Clear">
<?php } else { /* for 'editor-mode' */ ?>
<input type="hidden" name="filetoedit" id="filetoedit" value="<?php print($filetoedit) ?>">
<input type="submit" value="Save and Exit">
<input type="reset" value="Undo all Changes">
<input type="submit" value="Exit without saving" onclick="javascript:document.getElementById('filetoedit').value='';return true;">
<?php } ?>

  <input type="submit" name="logout" value="Logout">
</p>

</fieldset>

<?php } ?>

</form>


<hr>

<p>Please consult the <a href="README">README</a>, <a
href="INSTALL">INSTALL</a>, and <a href="SECURITY">SECURITY</a> files for
instruction on how to use PHP Shell.</p>

<hr>

<address>
Copyright &copy; <a href="mailto:mgeisler@mgeisler.net">Martin Geisler</a> and
others, please see <a href="AUTHORS">AUTHORS</a>. This is PHP Shell @VERSION@, 
get the latest version at <a href="http://phpshell.sourceforge.net/">
phpshell.sourceforge.net</a>.
</address>

</body>
</html>