<?php
  require 'include/head.inc';
  require 'include/common.inc';

  if(isset($_POST['submit']) && $_POST['password']!="") {

    $fh_pass = fopen(".htpasswd", 'w');
    fwrite($fh_pass, "admin:" . crypt($_POST['password'], base64_encode($_POST['password'])) . "\n");
    fclose($fh_pass);

    $fh_access = fopen(".htaccess", 'w');
    fwrite($fh_access, "AuthUserFile " . getcwd() . "/.htpasswd\n");
    fwrite($fh_access, "AuthGroupFile /dev/null\n");
    fwrite($fh_access, "AuthName \"Banana Admin\"\n");
    fwrite($fh_access, "AuthType Basic\n");
    fwrite($fh_access, "require user admin\n");
    fclose($fh_access);

    block("lightgreen", "admin password set");
    exit;
  }
?>

<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
  <table bgcolor="black">
    <tr><th><b><font color="white">set admin password</font></b></th><tr>
  </table>

  <table>
    <tr>  
      <th align="left">Password:</th> <th><input type="text" name="password"></th>
    </tr>
  
    <tr>
      <th></th><th align="right" columnspan=2><input type="submit" name="submit" value="Set"></th>
    </tr>
  </table>
</form>