Advertisement
ShadyPL

PHP interaction with Linux (interakcja PHP z Linux)

Feb 4th, 2013
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.39 KB | None | 0 0
  1. <?php
  2. ////////////////////////////////////////////////////////////
  3. //////// script created by Shady on GNU/GPL license ////////
  4. ////////  gg 15530223 | mail izzypjchamp@gmail.com  ////////
  5. ////////////////////////////////////////////////////////////
  6.  
  7. define("PATH", "/home/user_name/script_directory/");
  8.  
  9. function read_input() {
  10.     $stream = fopen("/dev/stdin", "r");
  11.     $input = trim(fgets($stream, 255));
  12.     $input = explode(' ', $input);
  13.     fclose($stream);
  14.     return $input;
  15. }
  16.  
  17. echo "Hello I am a helper Shady, how can I help you? ";
  18. $src = read_input();
  19.  
  20. switch($src[0]) {
  21.     default:
  22.         echo "I'm sorry, I do not know what you mean.\n(Type 'help' to get a list of functions)\n";
  23.     break;
  24.    
  25.     case 'help':
  26.         echo "List of functions: \ndelete_file [file] - removes the file from your PATH,\nrand [from] [to] [number] - draws a number from the interval\nabout - about me,\nauthor - my creator,\nexit - closes the script.\n";
  27.     break;
  28.  
  29.     case 'delete_file':
  30.         if(empty($src[1])) echo "Please enter the file name..\n";
  31.         elseif(!file_exists(PATH.$src[1])) echo $src[1]." does not exist..\n";
  32.         else {
  33.             unlink(PATH.$src[1]);
  34.             echo $src[1]." was removed!\n";
  35.         }
  36.     break;
  37.  
  38.     case 'rand':
  39.         if(empty($src[1]) || empty($src[2])) echo "Enter the range of numbers.\n";
  40.         elseif(empty($src[3])) echo "Enter the number of results.\n";
  41.         elseif($src[1] >= $src[2]) echo "The first number must be less than the second.\n";
  42.         else {
  43.             echo "The drawn numbers it:\n";
  44.             $i = 0;
  45.             while ($i < $src[3]) {
  46.                 echo mt_rand($src[1], $src[2])." ";
  47.                 $i++;
  48.             }
  49.             echo "\n";
  50.     }
  51.     break;
  52.  
  53.     case 'today':
  54.     echo "Today we ".date('l jS F Y, h:i A').".\n";
  55.     break;
  56.  
  57.     case 'about':
  58.         echo "I am a bot written in PHP, used to demonstrate PHP interaction with the Linux operating systems.\n";
  59.     break;
  60.  
  61.     case 'author':
  62.         echo "I was created by my Lord Shady, who did not put in me a lot of the source code, which explains why I'm so stupid. You can contact him by e-mail (izzypjchamp@gmail.com)\n";
  63.     break;
  64.  
  65.     case 'exit':
  66.         $farewell = array('Bye bye :)', 'See you!', 'Goodbye', 'It was nice to');
  67.         shuffle($farewell);
  68.  
  69.         echo $farewell[0]."\n";
  70.     break;
  71. }
  72. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement