Advertisement
Guest User

Untitled

a guest
May 20th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 8.20 KB | None | 0 0
  1. <?php
  2.  
  3. $command = $_POST['command'];
  4. $location = $_POST['location'];
  5.  
  6. $response = [
  7.     'command'       => $command,
  8.     'location'      => $location,
  9.     'msg'           => $message,
  10. ];
  11.  
  12. $resume = [
  13.     'root' =>[
  14.         'information'   =>  [
  15.             'name.info'      =>  'Nicolas Toporcov',
  16.             'email.info'     =>  'ntoporcov@me.com',
  17.             'telephone.info' =>  '(904) 704 3653'
  18.         ],
  19.  
  20.         'education'     =>  [
  21.             'university.info'    =>  'University of North Florida',
  22.             'degree.info'        =>  'Bachelor in Communication',
  23.             'year.info'          =>  '2015'
  24.         ],
  25.  
  26.         'skills'    =>  [
  27.             'basic.list' =>  ['Adwords','Google Analytics','Deployment','Server Config','Object Oriented Programming'],
  28.             'intermediate.list'  =>  ['PHP','Git','XMLHR','API Interaction','UX Design','Prototyping'],
  29.             'advanced.list'  =>  ['HTML','CSS','JQuery','Javascript','Photoshop','Illustrator','InDesign','WordPress','Print Design','UI Design'],
  30.             'miscellaneous.list' =>  ['Photography','Videography','Video Editing','Animation']
  31.         ],
  32.  
  33.         'experience'    =>  [
  34.  
  35.             'gleanview' =>  [
  36.                 'company.info'  => 'GleanView, a Sales and Marketing Solution',
  37.                 'period.info'   => 'July 2017 - Now',
  38.                 'position.info' => 'Marketing Front-End Developer and Product Designer',
  39.                 'description.info'  => 'GleanView is where I started learning about web development and product
  40. design from scratch. I’ve been responsible for the entire website and landing
  41. pages design and development, all google display ads design, company blog
  42. design and setup in wordpress and more recently product design for the
  43. software itself.'
  44.             ],
  45.  
  46.             'lunic' => [
  47.                 'company.info'  => 'Lunic Visuals, Photography and Videography Company',
  48.                 'period.info'   => 'January 2017 - Now',
  49.                 'position.info' => 'Co-Owner',
  50.                 'description.info'  => 'Lunic is a company I started with my wife to offer Photography and
  51. Videography. We’ve been doing mostly engagement photoshoots and
  52. wedding photography and videography. I also designed and developed our
  53. website in wordpress.'
  54.             ],
  55.  
  56.             'JBJ' => [
  57.                 'company.info'  => 'Jacksonville Business Journal, a local newspaper about businesses',
  58.                 'period.info'   => 'February 2016 - June 2017',
  59.                 'position.info' => 'Graphic Designer',
  60.                 'description.info'  => 'The Jacksonville Business Journal was my first full-time employment where
  61. I was responsible for design. I was responsible for designing, placing and
  62. managing ads being sold for the weekly newspaper as well as the annual
  63. Book of Lists. While working at the JBJ I learned a lot about Design in itself,
  64. specially how to deal with deadlines and handling super short notices.',
  65.             ],
  66.         ]
  67.     ]
  68.  
  69. ];
  70.  
  71.  
  72. switch (count($location)){
  73.     case 1:
  74.         $currentLocation = $resume[$location[0]];
  75.         break;
  76.     case 2:
  77.         $currentLocation = $resume[$location[0]] [$location[1]];
  78.         break;
  79.     case 3:
  80.         $currentLocation = $resume[$location[0]] [$location[1]] [$location[2]];
  81.         break;
  82.     case 4:
  83.         $currentLocation = $resume[$location[0]] [$location[1]] [$location[2]] [$location[3]];
  84.         break;
  85.     case 5:
  86.         $currentLocation = $resume[$location[0]] [$location[1]] [$location[2]] [$location[3]] [$location[4]];
  87.         break;
  88.     case 6:
  89.         $currentLocation = $resume[$location[0]] [$location[1]] [$location[2]] [$location[3]] [$location[4]] [$location[5]];
  90.         break;
  91. }
  92.  
  93. switch ($command[0]){
  94.  
  95.  
  96.     // show all folders and files in the current directory
  97.     case 'ls':
  98.         $response['msg'] = implode('&nbsp;&nbsp;&nbsp;',array_keys($currentLocation));
  99.         break;
  100.  
  101.  
  102.     // move to directory
  103.     case 'cd':
  104.         if(array_key_exists($command[1],$currentLocation)){
  105.  
  106.             //checks if argument is file
  107.             if (substr_count($command[1],'.info') > 0){
  108.                 $response['msg'] = '-bash: cd: Invalid Command. Command cd can only be used to choose directory to move to.
  109.                Use rd to read .info files';
  110.                 break;
  111.             } elseif (substr_count($command[1],'.list') > 0){
  112.                 $response['msg'] = '-bash: cd: Invalid Command. Command cd can only be used to choose directory to move to.
  113.                Use rd to read .list files';
  114.                 break;
  115.             }else{
  116.                 array_push($location,$command[1]);
  117.                 $response['location'] = $location;
  118.                 break;
  119.             }
  120.         } elseif($command[1] === '../'){
  121.             if(count($location) > 1){
  122.                 $removedElement = array_pop($location);
  123.                 $response['location'] = $location;
  124.             }else{
  125.                 $response['msg'] = '-bash: Currently in root directory.';
  126.             }
  127.         }
  128.         else{
  129.             $response['msg'] = '-bash: Directory '.$command[1].' not found. Run ls to list files in current directory';
  130.         }
  131.         break;
  132.  
  133.     // show current directory
  134.     case 'pwd':
  135.  
  136.         $response['msg'] = implode('/',$location);
  137.         break;
  138.  
  139.  
  140.     // read file
  141.     case 'cat':
  142.  
  143.         //checks if command is about a file, not a directory
  144.         if(substr_count($command[1],'.')){
  145.  
  146.             //checks if file exists
  147.              if(array_key_exists($command[1],$currentLocation)){
  148.                  $value = $currentLocation[$command[1]];
  149.  
  150.                  if (gettype($value) === 'string'){
  151.                      $response['msg'] =  $command[1].' => '.$value;
  152.                  }elseif(gettype($value) === 'array'){
  153.                      $value = implode('&nbsp;&nbsp;&nbsp;', $value);
  154.                      $response['msg'] =  $command[1].' => '.$value;
  155.                  }
  156.              }else{
  157.                  $response['msg'] = '-bash: File '.$command[1].' not found.';
  158.              }
  159.  
  160.  
  161.             //checks if they used -a modifier to read all files in directory
  162.         }else if($command[1]==='-a') {
  163.  
  164.                 $messageLines = [];
  165.                 foreach($currentLocation as $key => $value){
  166.  
  167.                     if(gettype($value)==='string'){
  168.                         array_push( $messageLines,$key.' => '.$value.'<br>');
  169.  
  170.                     }elseif(gettype($value)==='array'){
  171.  
  172.                         if(substr_count($key,'.') > 0){
  173.                             $value = implode('&nbsp;&nbsp;&nbsp;',$value);
  174.                             array_push( $messageLines,$key.' => '.$value.'<br>');
  175.                         }
  176.                     }
  177.                 }
  178.  
  179.                 if(count($messageLines) > 0){
  180.                     $response['msg'] = implode($messageLines);
  181.                 }else{
  182.                     $response['msg'] = '-bash: No readable files found in current directory: '.implode('/',$location);
  183.                 }
  184.  
  185.  
  186.             // if argument is a directory
  187.         }else{
  188.                 $response['msg'] = '-bash: File '.$command[1].' is a directory. It can not be read. Run cd to change directories, or rd -a to read all files in a directory';
  189.         }
  190.         break;
  191.  
  192.     case 'color':
  193.         $response['msg'] = $command[1];
  194.         break;
  195.  
  196.     case '-help':
  197.         $response['msg'] =
  198.             '<br><strong>COMMANDS AVAILABLE</strong><br><br>
  199.             ls => Lists all files and directories in current location<br>
  200.             pwd => Shows path of current directory<br>
  201.             cd [dir] => Changes directory to [dir]<br>
  202.             cd ../ => Goes back to the previous directory<br>
  203.             cat [file.ext] => Reads content of file. Explicit file extension is required.<br>
  204.             cat -a => Reads all contents of all readable files in current directory<br>
  205.             color [css] =>  Changes color of text in terminal. Accepts CSS colors and hex colors.<br>
  206.             -help => shows help dialogue<br><br>';
  207.         break;
  208.  
  209.     default:
  210.         $response['msg'] = '-bash: '.$command[0].': Command not found. Run -help to see a list of commands';
  211. };
  212.  
  213.  
  214. echo json_encode($response);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement