Guest User

Untitled

a guest
Nov 3rd, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.19 KB | None | 0 0
  1. <?php
  2.     ini_set('display_errors',1);
  3.     require('connect.php');
  4.    
  5.     if(isset($_POST['username']) && strlen($_POST['username']) <= 100)
  6.     {$username = strip_tags(trim($_POST['username']));}
  7.  
  8.     if(isset($_POST['password']) && strlen($_POST['password']) <= 100)
  9.     {$password = strip_tags(trim($_POST['password']));}
  10.  
  11.     if(isset($_POST['domain']) && strlen($_POST['domain']) <= 100)
  12.     {$domain = strip_tags(trim($_POST['domain']));}
  13.    
  14.     if(isset($_POST['address']) && strlen($_POST['address']) <= 100)
  15.     {$address = strip_tags(trim($_POST['address']));}
  16.    
  17.     if(isset($_POST['phone']) && strlen($_POST['phone']) <= 100)
  18.     {$phone = strip_tags(trim($_POST['phone']));}
  19.    
  20.     $required = array($username,$password,$domain,$address,$phone);
  21.     $error = false;
  22.     foreach($required as $field) {
  23.         if(empty($_POST[$field])) {
  24.             $error = true;
  25.         }
  26.     }
  27.     if($error) {
  28.         echo "All fields are required.";
  29.     } else {
  30.             //Create AD user
  31.             $cmd = 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -Noninteractive -command ". C:\adduser.ps1 \'' . $username . '\' \'' . $password . '\' \'' . $address . '\' \'' . $phone . '\';"';
  32.             if ( $a=exec($cmd) ) {
  33.                 echo "ok";
  34.             }
  35.  
  36.             //Create DNS record
  37.             $cmd = 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -Noninteractive -command ". C:\setdns.ps1 \'' . $username . '\';"';
  38.             if ( $a=exec($cmd) ) {
  39.                 echo "ok";
  40.             }
  41.            
  42.             //Create MySQL user
  43.             $conn  = mysql_connect(192.168.0.10, root, J_bernard);
  44.             mysql_query("CREATE USER '$username'@'localhost' IDENTIFIED BY '$password';");
  45.             mysql_close($conn);
  46.            
  47.             //Create MySQL database
  48.             $conn  = mysql_connect(192.168.0.10, $username, $password);
  49.             if(! $conn){
  50.                 die("Connection to database failed: " . mysql_error());
  51.             } else {
  52.                 echo "Connected successfully";
  53.             }
  54.  
  55.             $db = $username;
  56.             $sql =  "CREATE DATABASE $db";
  57.             $retval = mysql_query($sql, $conn);
  58.             if(! $retval){
  59.                 die("Could not create database: " . mysql_error());
  60.             } else {
  61.                 echo "Database $db created successfully\n";
  62.             }
  63.            
  64.             //Grant user privileges
  65.             mysql_query("GRANT ALL ON $db.* TO '$username'@'localhost' IDENTIFIED BY '$password';");
  66.             mysql_close($conn);
  67.     }
  68. ?>
Add Comment
Please, Sign In to add comment