Location: PHPKode > scripts > cPanel Account Creator > cpanel-account-creattor/useradmin.php
<?php 
/*---------------------------------------------------+
| cpanel creator
+----------------------------------------------------+
| Copyright 2009 - Neil Taylor
| http://studyhost.co.uk
+----------------------------------------------------+
| This program is free software: you can redistribute it and/or modify
| it under the terms of the GNU General Public License as published by
| the Free Software Foundation, either version 3 of the License, or
| (at your option) any later version.
|
| This program is distributed in the hope that it will be useful,
| but WITHOUT ANY WARRANTY; without even the implied warranty of
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
| GNU General Public License for more details.
|
| You should have received a copy of the GNU General Public License
| along with this program.  If not, see <http://www.gnu.org/licenses/>
+----------------------------------------------------*/ 
session_start();
$admin = $_SESSION["myaccess"];
if (!$_SESSION["myusername"] or $admin != "admin")  {
header("Location:index.php");
}

else {


$message = "<p>Welcome to the user edit</p>";
 function deleteuser($usertobedeleted) {           
      $open_users_file = "users.ini";
      $full_list = (parse_ini_file("$open_users_file",true));    
        unset($full_list[$usertobedeleted]);
        
      foreach ($full_list as $key  => $value) 
        {
          $newarray .= "[".$key."]\n";
            foreach ($value as $test => $answer) 
              {
                $newarray .= $test." = ".$full_list[$key][$test]."\n";
              }$newarray .= "\n";
        }
        file_put_contents($open_users_file,$newarray);    
      //header("Location:index.php");
        }
     
function userlist() {
  echo ("<table border=\"0\" cellpadding=\"0\" cellspacing=\"1\">");
  $passwords_array = (parse_ini_file("users.ini",true));   
  $i = 1;
    foreach ($passwords_array as $key  => $value) {
    echo ("<tr ");
    
    echo ($i % 2) ? "class=\"grey\"" : "class=\"white\"";
    
    echo (">\n");
      echo("<td style=\"padding:5px;\">".$key."</td>\n");
      foreach ($value as $test => $answer) {
	  
      if ($test == "password") {continue;} 
	   if ($test == "email") {
      echo("<td style=\"padding:5px;\"><a href=\"".$passwords_array[$key][$test]."\">".$passwords_array[$key][$test]."</a></td>\n");
	  }
	  else {
	  echo("<td style=\"padding:5px;\">".$passwords_array[$key][$test]."</td>\n");
	  }
      }
      if ($passwords_array[$key][accesslevel] == 'user') 
      {
      
	  echo("<td style=\"width:20px;padding:5px;\"><img src=\"images/Icon_edit.gif\" alt=\"Edit\" title=\"Edit\"  style=\"cursor: pointer;\" onClick=\"toggleTable('".$key."');\" /></td>");
	  
      echo("<td style=\"width:20px;padding:5px;\"><input type=\"image\" name=\"delete\" style=\"width:17px; height:16px;\" src=\"images/Icon_delete.gif\" title=\"Delete\" alt=\"Delete\" value=\"".$key."\" onclick=\"return(confirm('do you really want to delete?'));\" /></td>\n");
      }
      else {
      echo("<td style=\"width:20px;\">&nbsp;</td>\n");
      echo("<td style=\"width:20px;\">&nbsp;</td>\n");
      }
      echo ("</tr>");
	  echo ("<tr><td colspan=\"5\" ");
	  echo ($i % 2) ? "class=\"grey\"" : "class=\"white\"";
	  echo (">");
	  echo ("<span id=\"".$key."\" class=\"edituser\"><div class=\"new\">");
	  echo ("<p>Please use the form below to edit the user <b>".$key."</b> details</p>");
	  echo ("<label>New Username:<span>Please enter a username</span></label><input type=\"text\" name=\"".$key."_new_user\">");
	  echo ("<label>New Email:<span>Please enter a email address</span></label><input type=\"text\" name=\"".$key."_new_email\">");
	  echo ("<label>New Password:<span>Please enter a password</span></label><input type=\"text\" name=\"".$key."_new_password\"><br style=\"clear:both;\"></div>");
	  echo ("<input name=\"".$key."_change\" type=\"submit\" value=\"Change\" style=\"margin-left :165px; margin-bottom:0px;\">");
	  echo ("</span></td></tr>");
     $i = $i+1; 
  }
   echo ("</table>");
}   
  
require('_adminbar.php');
  
   if (array_key_exists('submitcheck', $_POST)) {
     // if($_POST["submitcheck"]=="1") {
        $addusername=$_POST['addusername']; 
        $addpassword=$_POST['addpassword'];
        $addemail=$_POST['addemail'];
        
        if (isset($_POST['addaccess'])) {
        $addaccess = "admin";
        }
        else {
        $addaccess = "user";
        }
        
        if (($addusername) && ($addpassword) && ($addemail)) {
        $message = "<p>".$addaccess." &ldquo;<b>". $addusername ."</b>&rdquo; has being added</p>";
        
          #$open_users_file = fopen('users2.ini', 'w');
        $newuser = "\n[".$addusername."]\n";
        $newuser .= "password = ".$addpassword."\n";
        $newuser .= "email = ".$addemail."\n";
        $newuser .= "accesslevel = ".$addaccess."\n";
        
        
        $open_users_file = "users.ini";
        file_put_contents($open_users_file, $newuser,FILE_APPEND);
        
        
        }
        else {$message = "<p class=\"error\">PLEASE FILL IN ALL FIELDS</p>";}
        #form test ends 
      }
  
  
if(isset($_POST['delete'])) {
$deletevalue = $_POST['delete'];
deleteuser($deletevalue);
}
  
  
  
if($_GET['logout'] == "yes") {
session_destroy();
}  
  
// ----------------------------------------------------------------------
//   Function    : edituser()
//   Description : Edits the users details
// ----------------------------------------------------------------------
function edituser($user_edit, $new_user, $new_password, $new_email) {
$open_users_file = "users.ini";
$newuser_array =(parse_ini_file("$open_users_file",true));   
foreach($newuser_array as $key => $value)
{
		
	if ($key == $user_edit)
	{
if ($new_password) {$newuser_array[$key][password] = $new_password;}
		if ($new_email) {$newuser_array[$key][email] = $new_email;}
	}
}
if ($new_user) {
$newuser_array[$new_user] = $newuser_array[$key];
unset($newuser_array[$key]);
}
  foreach ($newuser_array as $key  => $value) 
        {
          $newarray .= "[".$key."]\n";
            foreach ($value as $test => $answer) 
              {
                $newarray .= $test." = ".$newuser_array[$key][$test]."\n";
              }$newarray .= "\n";
        }
        file_put_contents($open_users_file,$newarray);   
        $message = "<p>User ".$key." Altered";
}
//   calling    : edituser() function
   
	if ('Change')
	{
	$open_users_file = "users.ini";
  $newuser_array =(parse_ini_file("$open_users_file",true));
foreach($newuser_array as $key => $value)
{
	$user_edit = $key;
	$new_user = $_POST[$key."_new_user"];
	$new_password = $_POST[$key."_new_password"];
	$new_email = $_POST[$key."_new_email"];
  edituser($user_edit, $new_user, $new_password, $new_email );
  $message = "<p>User ".$key." Altered";
  }
}
}
 ?>
<html>  
  <head>    
    <title>User admin      
    </title>    
    <link rel="stylesheet" href="formstyle.css" type="text/css" media="screen" />
<script type="text/javascript" language="javascript" src="dropdown.js"></script>
<script language="JavaScript" type="text/javascript">
      function toggleadduser(adduserform) {
            if ('none' == document.getElementById(adduserform).style.display) {
                  document.getElementById(adduserform).style.display = 'block';
				  document.getElementById("adduser").className = "greybox";
            }
            else {
                  document.getElementById(adduserform).style.display = 'none';
				  document.getElementById("adduser").className = "bluebox";
            }
      }
</script>  
  </head>  
  <body>    
    <div id="controlbar">         
      <?php adminbar(); ?>     
    </div>    
    <fieldset>        
      <legend>Add User Account       
      </legend>        
      <?php echo($message); ?>       
      <form name="form2" method="post" action="<?php echo $PHP_SELF;?>" autocomplete="off">           
        <input type="hidden" name="submitcheck" value="1">           
        <?php userlist(); ?>           
        <br/>           
        <br/>           
        <a href="javascript:toggleadduser('adduserform')" id="adduser" class="bluebox" title="Login">+    Add User</a>          
        <span id="adduserform" style="display: none;">               
          <div>            
            <label>Username:               
              <span>Please enter a username               
              </span>            
            </label>                 
            <input type="text" name="addusername" />                 
            <label>Password:               
              <span>Please enter a password               
              </span>            
            </label>                 
            <input type="password" name="addpassword">                 
            <label>Email:               
              <span>Please enter a email address               
              </span>            
            </label>                 
            <input type="text" name="addemail">                 
            <label>Access Level:               
              <span>Is the user a Admin?               
              </span>            
            </label>                   
            <input type="checkbox" style="width:16px;margin:9px 95px 0px 15px;" name="addaccess" value="Admin">    <br style="clear:both;">             
          </div>             
          <input name="submit" type="submit" value="Add User" style="margin-left :165px; margin-bottom:0px;">           
        </span>        
      </form>      
      </fieldset>        
      <div class="company">        
        <a href="#">&copy company</a>      
      </div>  
  </body>
</html>
Return current item: cPanel Account Creator