akoimeexx

Simple web-based Shell class

Jul 22nd, 2011
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.03 KB | None | 0 0
  1. <?php
  2.     class Shell {
  3.         /* Define constants */
  4.         // This can be set to null for unrestricted buffer space
  5.         const MAX_OUTPUT_BUFFER = 256;
  6.        
  7.         /* Define static properties */
  8.         private static $output_buffer = array();
  9.        
  10.         /**
  11.          * Execute a command, add the output to the buffer stack
  12.          * @return Int Command return status
  13.          * @param $command String
  14.          */
  15.         static function exec($command) {
  16.             @exec($command, $tmp_ob, $status);
  17.             Shell::$output_buffer = array_merge((array) Shell::$output_buffer, (array) $tmp_ob);
  18.             while(count(Shell::$output_buffer) > Shell::MAX_OUTPUT_BUFFER && Shell::MAX_OUTPUT_BUFFER != null) {
  19.                 array_shift(Shell::$output_buffer);
  20.             }
  21.             return (int) $status;
  22.         }
  23.        
  24.         /**
  25.          * Flush the buffer stack
  26.          * @return null
  27.          */
  28.         static function flush() {
  29.             Shell::$output_buffer = array();
  30.         }
  31.        
  32.         /**
  33.          * Print the buffer stack
  34.          * @return null
  35.          */
  36.         static function output() {
  37.             foreach(Shell::$output_buffer as $output_line) {
  38.                 printf("%s\n", $output_line);
  39.             }
  40.         }
  41.     }
  42. ?>
Advertisement
Add Comment
Please, Sign In to add comment