Advertisement
terorama

PHP / Console_new

Mar 21st, 2013
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.64 KB | None | 0 0
  1. <?php
  2. ob_start();
  3.  
  4. $logform =<<<INF
  5.    <form action="{$_SERVER["PHP_SELF"]}" method="post" name="logform"
  6.             enctype="application/www-form-urlencoded">
  7.    <fieldset>
  8.    <legend>input auth code</legend>
  9.    <label for="password">input password</label>
  10.        <input type="text" name="password" />
  11.        <input type="submit" name="submit" value="submit" />
  12.    </fieldset>
  13.    </form>
  14.  
  15. INF;
  16.  
  17.  
  18.  
  19.  
  20. function php_inform() {
  21.  
  22.  
  23. ob_start();
  24.   ?>
  25.  
  26. <script type="text/javascript" src="jquery.min.js"></script>
  27.    <script type="text/javascript">
  28.  
  29.      
  30.       function checkpos(el) {
  31.  
  32.          var zdiv = document.getElementById("posdiv");
  33.       }
  34.  
  35.       function onSuccess(inf) {
  36.          if (inf['reztype']=='load') {
  37.             document.forms.phpform.phptext.value = inf['rez'];
  38.    
  39.             $('#sourcediv').html('<pre>'+inf['source']+'</pre>');
  40.  
  41.             if (window.infblock)
  42.                infblock.html('document loaded');
  43.  
  44.          }
  45.          else {
  46.             if (!window.infblock) {
  47.                $('form[name=phpform] textarea').before($('<div/>',{id:'infblock'}).html('status'));
  48.                infblock = $('#infblock').css('color','green');
  49.             }
  50.            
  51.             infblock.html(inf.rez);
  52.          }
  53.          
  54.       }
  55.      
  56.       function ajax_go(action, fname, content) {
  57.  
  58.          if (!content)
  59.             content = '';
  60.  
  61.          if (window.infblock)
  62.             infblock.html('Waiting...');
  63.  
  64.          $.ajax ( {
  65.             type: 'POST',
  66.             url: '<?=$_SERVER["PHP_SELF"]?>',
  67.             data: {
  68.                ajax:'',action:action, fname:fname, content: content
  69.             },
  70.             dataType: 'json',
  71.             success: onSuccess
  72.          }
  73.          )
  74.       }
  75.  
  76.  
  77.       function load_file(el) {
  78.          
  79.          var fname = el.form.fname.value;
  80.          ajax_go('load', fname);  
  81.       }
  82.  
  83.       function save_file(el) {
  84.          
  85.          var fname = el.form.fname.value;
  86.          var content = el.form.phptext.value;
  87.  
  88.          ajax_go('save', fname, content);
  89.       }
  90.  
  91.       function launch_file(el) {
  92.          var fname = el.form.fname.value;
  93.          window.open(fname);
  94.       }
  95.    </script>
  96.  
  97. <?php
  98.  
  99.    $php_header = ob_get_clean();
  100.  
  101. $php_inpform = <<<INF
  102.  
  103.    
  104.    <form  name="phpform"
  105.              enctype="application/www-form-urlencoded" >
  106.    <fieldset>
  107.    <legend>PHP Exec Form</legend>
  108.    <label for="fname">Input file name</label>
  109.    <input type="text" name="fname" value="" />
  110.    <input type="button" onclick="load_file(this)" value="load" />
  111.    <input type="button" onclick="save_file(this)" value="save" />
  112.    <input type="button" onclick="launch_file(this)" value="launch" />  
  113.    <p>Input PHP text</p>
  114.    
  115.    <textarea name="phptext" rows="40" cols="100"></textarea>
  116.    <br />
  117.  
  118.    
  119.    <div id="posdiv"></div>
  120.    </fieldset>
  121.    </form>
  122.  
  123. INF;
  124.  
  125.    return $php_header."\r\n".$php_inpform;
  126. }
  127.  
  128.  
  129.    session_start();
  130.  
  131.    if (isset($_GET["reset"])) {
  132.  
  133.       session_destroy();
  134.       ob_clean();
  135.       header('Location: '.$_SERVER["PHP_SELF"]);
  136.    }
  137.  
  138.    if (!isset($_SESSION["logged"]))
  139.       logon();
  140.    else
  141.       php_execform();
  142.  
  143.    //---------------------------------------
  144.    function logon() {
  145.  
  146.       global $logform;
  147.  
  148.       if (isset($_POST["submit"])) {
  149.  
  150.          if (@$_POST["createpass"]==true) {
  151.  
  152.             $fh = fopen(dirname(__FILE__).DIRECTORY_SEPARATOR.'hash8.txt', 'w');
  153.             fwrite($fh,md5($_POST["password"]));
  154.             fclose($fh);
  155.             echo "password created";
  156.             exit();
  157.          }
  158.  
  159.          $pass=md5($_POST["password"]);
  160.  
  161.          $fh = fopen(dirname(__FILE__).DIRECTORY_SEPARATOR.'hash.txt','r');
  162.  
  163.          $s=fread($fh, 1024);
  164.  
  165.          fclose($fh);
  166.  
  167.          if ($pass!=$s) {
  168.             echo "invalid password<br/>";
  169.             echo "<a href=\"{$_SERVER["REQUEST_URI"]}\" />back</a>";
  170.            
  171.             }
  172.          else
  173.             {
  174.                $_SESSION["logged"]=true;
  175.                ob_clean();
  176.                header('Location:'.$_SERVER["PHP_SELF"]);
  177.             }
  178.       }
  179.       else {
  180.          echo $logform;
  181.       }
  182.    }
  183.  
  184.    //---------------------------------------
  185.    function php_execform() {
  186.  
  187.  
  188.       if (isset($_POST["ajax"])) {
  189.  
  190.          $source = '';
  191.          
  192.          if ($_POST["action"]=='load') {
  193.             $reztype = 'load';
  194.             $rez =file_get_contents(dirname(__FILE__).'/'.$_POST['fname']);
  195.            
  196.             $fn=dirname(__FILE__).'/'.(isset($_POST["fname"])?$_POST["fname"]:'test.php');
  197.             $fh = fopen ($fn, 'r');
  198.             $i=1;
  199.             $strz='';
  200.             while ($row= fgets($fh)) {
  201.                $row=htmlentities($row);
  202.                $strz.= $i.' '.$row;
  203.                $i++;
  204.             }
  205.            
  206.             $source = $strz;
  207.          } else {
  208.             $reztype = 'save';
  209.  
  210.             file_put_contents(dirname(__FILE__).'/'.$_POST['fname'], $_POST['content']);
  211.             $rez = "document ".$_POST["fname"].' saved';
  212.          }
  213.  
  214.          echo json_encode(Array('reztype'=>$reztype, 'rez'=>$rez, 'source'=>$source));
  215.          return;
  216.  
  217.       }
  218.  //-------------------------------------------
  219.         echo '<div style="float:left;width:900px;">';
  220.         echo php_inform();
  221.         echo '</div>';
  222.  
  223.       echo '<div id= "sourcediv" style="margin-top=10px;background-color:#ffe;margin-left:900px;">';
  224.       echo '<pre></pre></div><div style="margin-top=10px;margin-left:900px;">';
  225.      
  226.       $d= opendir('.');
  227.       while ($f=readdir($d)) {
  228.          if (is_file($f)) {
  229.             echo $f.' '.date('d.m.Y H:i:s',filemtime($f)).' '.filesize($f).'<br />';
  230.          }
  231.       }
  232.      
  233.       echo '</div>';
  234.    }
  235.  
  236.  
  237. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement