Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- ini_set('display_errors',1);
- require('connect.php');
- if(isset($_POST['username']) && strlen($_POST['username']) <= 100)
- {$username = strip_tags(trim($_POST['username']));}
- if(isset($_POST['password']) && strlen($_POST['password']) <= 100)
- {$password = strip_tags(trim($_POST['password']));}
- if(isset($_POST['domain']) && strlen($_POST['domain']) <= 100)
- {$domain = strip_tags(trim($_POST['domain']));}
- if(isset($_POST['address']) && strlen($_POST['address']) <= 100)
- {$address = strip_tags(trim($_POST['address']));}
- if(isset($_POST['phone']) && strlen($_POST['phone']) <= 100)
- {$phone = strip_tags(trim($_POST['phone']));}
- $required = array($username,$password,$domain,$address,$phone);
- $error = false;
- foreach($required as $field) {
- if(empty($_POST[$field])) {
- $error = true;
- }
- }
- if($error) {
- echo "All fields are required.";
- } else {
- //Create AD user
- $cmd = 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -Noninteractive -command ". C:\adduser.ps1 \'' . $username . '\' \'' . $password . '\' \'' . $address . '\' \'' . $phone . '\';"';
- if ( $a=exec($cmd) ) {
- echo "ok";
- }
- //Create DNS record
- $cmd = 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -Noninteractive -command ". C:\setdns.ps1 \'' . $username . '\';"';
- if ( $a=exec($cmd) ) {
- echo "ok";
- }
- //Create MySQL user
- $conn = mysql_connect(192.168.0.10, root, J_bernard);
- mysql_query("CREATE USER '$username'@'localhost' IDENTIFIED BY '$password';");
- mysql_close($conn);
- //Create MySQL database
- $conn = mysql_connect(192.168.0.10, $username, $password);
- if(! $conn){
- die("Connection to database failed: " . mysql_error());
- } else {
- echo "Connected successfully";
- }
- $db = $username;
- $sql = "CREATE DATABASE $db";
- $retval = mysql_query($sql, $conn);
- if(! $retval){
- die("Could not create database: " . mysql_error());
- } else {
- echo "Database $db created successfully\n";
- }
- //Grant user privileges
- mysql_query("GRANT ALL ON $db.* TO '$username'@'localhost' IDENTIFIED BY '$password';");
- mysql_close($conn);
- }
- ?>
Add Comment
Please, Sign In to add comment