Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- This is in my main.php controller
- ---------------------------------
- function create_server() {
- $data['success'] = FALSE;
- $data['server_hosts'] = $this->queries->get_host_list();
- if (isset($_POST) && (!empty($_POST))) {
- //$this->form_validation->set_rules('number_of_servers', 'number_of_servers', 'required|is_natural_no_zero');
- $this->form_validation->set_rules('host_id', 'host_id', 'required|is_natural_no_zero');
- if ($this->form_validation->run() != FALSE) {
- $host_id = $_POST['host_id'];
- $number_of_servers = 1;
- $server_location = $_POST['server_location'];
- $host_details = $this->queries->get_host_details(1);
- $this->admin->create_server_atlantic($host_details, $server_location, $number_of_servers);
- $data['success'] = TRUE;
- }
- }
- $this->load->view("create_server", $data);
- }
- This is in my models
- --------------------
- <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
- class Queries extends CI_Model {
- function is_duplicate_ip($ip_address) {
- $result = $this->db->get_where("old_ips", array("ip_address" => $ip_address));
- if ($result->num_rows()) {
- return TRUE;
- } else {
- return FALSE;
- }
- }
- function get_host_details($host_id) {
- $result = $this->db->get_where("server_hosts", "host_id = $host_id", 1);
- if ($result->num_rows()) {
- return $result->row_array();
- } else {
- return FALSE;
- }
- }
- function get_host_list() {
- $result = $this->db->get("server_hosts");
- if ($result->num_rows()) {
- foreach ($result->result_array() as $row) {
- $return_data[] = $row;
- }
- return $return_data;
- } else {
- return FALSE;
- }
- }
- function insert_server($server_ip,$username,$password,$server_name,$server_location,$instance_id,$user_id = "1") {
- $this->db->insert("servers", array("server_ip" => $server_ip, "server_location" => $server_location, "server_name" => $server_name, "username" => $username, "status" => "1", "instance_id" => $instance_id, "created_timestamp" => time(), "user_id" => $user_id));
- $this->db->insert("old_ips", array("ip_address" => $server_ip));
- return mysql_insert_id();
- }
- function get_next_ai_value($table = 'servers') {
- $result = $this->db->query("SHOW TABLE STATUS LIKE '".$table."'");
- $row = $result->row_array();
- return $row['Auto_increment'];
- }
- function get_random_name() {
- $return_data = array();
- $firstname = '';
- $lastname = '';
- $result = $this->db->query("SELECT firstname,gender FROM firstnames ORDER BY rand() LIMIT 1,50");
- $row = $result->row_array();
- $firstname = $row['firstname'];
- $gender = $row['gender'];
- $result = $this->db->query("SELECT lastname FROM lastnames ORDER BY rand() LIMIT 1,500");
- $row = $result->row_array();
- $lastname = $row['lastname'];
- $return_data['name'] = $firstname." ".$lastname;
- $return_data['gender'] = $gender;
- return $return_data;
- }
- function check_login($username,$password) {
- $sql = "SELECT * FROM users WHERE username = ".$this->db->escape($username)." and password = ".$this->db->escape($password)." and active = 1 LIMIT 1";
- $result = $this->db->query($sql);
- if ($result->num_rows()) {
- $row = $result->row_array();
- return $row;
- } else {
- return FALSE;
- }
- }
- function insert_into_rdm($servername,$ip_address,$username,$password) {
- $uuid = generate_uuid();
- $xml = '<?xml version="1.0"?>
- <Connection>
- <UserName>'.$username.'</UserName>
- <ConnectionType>RDPConfigured</ConnectionType>
- <ClearTextPassword>'.$password.'</ClearTextPassword>
- <CreatedBy>BILLY-DESKTOP\Billy</CreatedBy>
- <CreationDateTime>2015-01-16T09:34:05.5657021-05:00</CreationDateTime>
- <Events />
- <Group>Builders\New</Group>
- <ID>'.$uuid.'</ID>
- <MetaInformation>
- <PasswordHistory>
- <PasswordHistory>
- <ModifiedBy>BILLY-DESKTOP\Billy</ModifiedBy>
- <ModifiedDateTime>2015-01-16T09:34:05.5657021-05:00</ModifiedDateTime>
- <SafePassword>TDHFoKmF7Q7JDvqwCVk6yg==</SafePassword>
- </PasswordHistory>
- </PasswordHistory>
- </MetaInformation>
- <Name>'.$servername.'</Name>
- <OpenEmbedded>true</OpenEmbedded>
- <PinEmbeddedMode>False</PinEmbeddedMode>
- <RDP>
- <NetworkLevelAuthentication>true</NetworkLevelAuthentication>
- <RedirectDirectX>false</RedirectDirectX>
- <SafePassword>DAKOq9XZNJHOfQzbdCSc/g==</SafePassword>
- <SmartSizingStreched>false</SmartSizingStreched>
- <UserName>'.$username.'</UserName>
- <VideoPlaybackMode>Disabled</VideoPlaybackMode>
- </RDP>
- <Stamp>2e7c4ec0-fdc2-425b-97b2-99bb22a5eb4b</Stamp>
- <Url>'.$ip_address.'</Url>
- <UsesSerialPorts>false</UsesSerialPorts>
- </Connection>';
- /*
- $xml = '<?xml version="1.0"?>
- <Connection>
- <UserName>'.$username.'</UserName>
- <ConnectionType>RDPConfigured</ConnectionType>
- <ClearTextPassword>'.$password.'</ClearTextPassword>
- <CreatedBy>BILLY-DESKTOP\Billy</CreatedBy>
- <CreationDateTime>2015-01-01T14:57:18.2277815-05:00</CreationDateTime>
- <Events />
- <ID>'.$uuid.'</ID>
- <MetaInformation>
- <PasswordHistory>
- <PasswordHistory>
- <ModifiedBy>BILLY-DESKTOP\Billy</ModifiedBy>
- <ModifiedDateTime>2015-01-01T14:57:18.2287557-05:00</ModifiedDateTime>
- </PasswordHistory>
- </PasswordHistory>
- </MetaInformation>
- <Name>'.$servername.'</Name>
- <OpenEmbedded>true</OpenEmbedded>
- <PinEmbeddedMode>False</PinEmbeddedMode>
- <PlayList />
- <RDP>
- <LoadAddOns>false</LoadAddOns>
- <NetworkLevelAuthentication>true</NetworkLevelAuthentication>
- <RedirectDirectX>false</RedirectDirectX>
- <SmartSizingStreched>false</SmartSizingStreched>
- <UserName>'.$username.'</UserName>
- <VideoPlaybackMode>Disabled</VideoPlaybackMode>
- </RDP>
- <ScreenSize>R1280x800</ScreenSize>
- <Stamp>4eb2b4b6-9fe6-48b5-bf65-c486e8e342d5</Stamp>
- <Tools>
- <CredentialSource>CurrentSession</CredentialSource>
- </Tools>
- <Url>'.$ip_address.'</Url>
- <UsesHardDrives>false</UsesHardDrives>
- <UsesSerialPorts>false</UsesSerialPorts>
- </Connection>';
- */
- $sql = "INSERT INTO `Connections` (`ID`, `Data`, `SecurityGroup`, `ConnectionType`, `ConnectionSubType`, `GroupName`, `Name`, `UnsafePassword`, `DataSourceID`, `MetaData`, `CreationDate`, `Description`, `CustomerID`, `ModifiedUsername`, `ModifiedLoggedUserName`, `ModifiedDate`, `Version`, `AttachmentCount`, `AttachmentPrivateCount`)
- VALUES ('".$uuid."', '".mysql_real_escape_string($xml)."', '43b6a724-0aaf-4cdd-813d-b2edb9e57053', '1', NULL, 'Builders\New', '".$servername."', NULL, '00000000-0000-0000-0000-000000000000', '<?xml version=\"1.0\"?><RDMOConnectionMetaData><ConnectionType >RDPConfigured</ConnectionType><Group >Builders\New</Group><Name >".$servername."</Name> <SecurityGroupInherited >true</SecurityGroupInherited></RDMOConnectionMetaData>', '2015-01-01 20:07:20', NULL, NULL, 'BILLY-DESKTOP\\Billy', 'billy', '2015-01-01 20:50:22', '10', '0', '0')";
- $this->db->query($sql);
- }
- }
- This is in my functions file
- -----------------------------
- function generate_guid(){return sprintf('%04X%04X%04X%04X%04X%04X%04X%04X%04X',mt_rand(0, 65535), mt_rand(16384, 20479), mt_rand(0, 65535), mt_rand(16384, 20479), mt_rand(32768, 49151), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(32768, 49151)); }
- function generate_uuid() {
- return sprintf( '%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
- mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ),
- mt_rand( 0, 0xffff ),
- mt_rand( 0, 0x0fff ) | 0x4000,
- mt_rand( 0, 0x3fff ) | 0x8000,
- mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff )
- );
- }
- function rand_string( $length ) {
- $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
- return substr(str_shuffle($chars),0,$length);
- }
- function get_random_birthdate() {
- $int= mt_rand(157766400,504748800);
- $string = date("M-d-Y",$int);
- return $string;
- }
- function generate_rdm_xml($servername,$ip_address,$username,$password) {
- $id = generate_uuid();
- $xml = '<?xml version="1.0"?>
- <Connection>
- <UserName>administrator</UserName>
- <ConnectionType>RDPConfigured</ConnectionType>
- <ClearTextPassword>'.$password.'</ClearTextPassword>
- <CreatedBy>BILLY-DESKTOP\Billy</CreatedBy>
- <CreationDateTime>2015-01-01T14:57:18.2277815-05:00</CreationDateTime>
- <Events />
- <ID>'.$id.'</ID>
- <MetaInformation>
- <PasswordHistory>
- <PasswordHistory>
- <ModifiedBy>BILLY-DESKTOP\Billy</ModifiedBy>
- <ModifiedDateTime>2015-01-01T14:57:18.2287557-05:00</ModifiedDateTime>
- </PasswordHistory>
- </PasswordHistory>
- </MetaInformation>
- <Name>'.$ip_address.'</Name>
- <OpenEmbedded>true</OpenEmbedded>
- <PinEmbeddedMode>False</PinEmbeddedMode>
- <PlayList />
- <RDP>
- <LoadAddOns>false</LoadAddOns>
- <NetworkLevelAuthentication>true</NetworkLevelAuthentication>
- <RedirectDirectX>false</RedirectDirectX>
- <SmartSizingStreched>false</SmartSizingStreched>
- <UserName>administrator</UserName>
- <VideoPlaybackMode>Disabled</VideoPlaybackMode>
- </RDP>
- <Stamp>4eb2b4b6-9fe6-48b5-bf65-c486e8e342d5</Stamp>
- <Tools>
- <CredentialSource>CurrentSession</CredentialSource>
- </Tools>
- <Url>'.$ip_address.'</Url>
- <UsesHardDrives>false</UsesHardDrives>
- <UsesSerialPorts>false</UsesSerialPorts>
- </Connection>';
- }
- Main admin creation function
- ----------------------------
- function create_server_atlantic($host_details, $server_location, $number_of_servers) {
- $ci =& get_instance();
- $winver = 12;
- if ($winver == 8) {
- $cloneimage = "31928-76646"; // win2k08
- $password = "ABC123";
- } else {
- $cloneimage = "31928-76647"; // win2k12
- $password = 'ABC123';
- }
- $is_new_ip = FALSE;
- while ($is_new_ip == FALSE) {
- // Generate all the variables necessary for atlantic.net API
- $timestamp = time();
- $guid = generate_guid();
- $str_to_sign = $timestamp.$guid;
- $signature = hash_hmac('sha256', $str_to_sign, $host_details['api_private_key'], true);
- $encodedsignature = base64_encode($signature);
- $next_ai_value = $ci->queries->get_next_ai_value();
- $atlantic_server_name = substr($_SESSION['user']['firstname'],0,1).substr($_SESSION['user']['lastname'],0,1).$next_ai_value;
- /*
- *
- * This is the original post code
- $post_values = array(
- "Version" => "2010-12-30",
- "ACSAccessKeyId" => $host_details['api_key'],
- "Format" => "json",
- "Timestamp" => $timestamp,
- "Rndguid" => $guid,
- "Signature" => $encodedsignature,
- //"Action" => "describe-image",
- "Action" => "run-instance",
- "servername" => $atlantic_server_name,
- "planname" => "S",
- //"cloneimage" => $cloneimage,
- "imageid" => "",
- "vm_location" => $server_location,
- //"imageid" => "Master-Image-31928-76647",
- //"imageid" => "Master-Image-31928-76646",
- //"imageid" => "Windows-2008-R2-SP1-Datacenter_64bit",
- "imageid" => "Windows-2012-R2-Datacenter_64bit",
- "server_qty" => $number_of_servers
- );
- */
- $post_values = array(
- "Version" => "2010-12-30",
- "ACSAccessKeyId" => $host_details['api_key'],
- "Format" => "json",
- "Timestamp" => $timestamp,
- "Rndguid" => $guid,
- "Signature" => $encodedsignature,
- //"Action" => "describe-image",
- "Action" => "run-instance",
- "servername" => $atlantic_server_name,
- "planname" => "S",
- "cloneimage" => $cloneimage,
- //"imageid" => "",
- "vm_location" => $server_location,
- //"imageid" => "Master-Image-31928-76647",
- //"imageid" => "Master-Image-31928-76646",
- //"imageid" => "Windows-2008-R2-SP1-Datacenter_64bit",
- //"imageid" => "Windows-2012-R2-Datacenter_64bit",
- "server_qty" => $number_of_servers
- );
- $url = $host_details['api_host_url'].http_build_query($post_values);
- $response = curl_get($url);
- if ($response['success']) {
- $json = json_decode($response['response'], TRUE);
- $item = $json['run-instanceresponse']['instancesSet']['item'];
- if ($ci->queries->is_duplicate_ip($item['ip_address'])) {
- sleep(15);
- $timestamp = time();
- $guid = generate_guid();
- $str_to_sign = $timestamp.$guid;
- $signature = hash_hmac('sha256', $str_to_sign, $host_details['api_private_key'], true);
- $encodedsignature = base64_encode($signature);
- $post_values = array(
- "Version" => "2010-12-30",
- "ACSAccessKeyId" => $host_details['api_key'],
- "Format" => "json",
- "Timestamp" => $timestamp,
- "Rndguid" => $guid,
- "Signature" => $encodedsignature,
- "Action" => "terminate-instance",
- "instanceid" => $item['instanceid']
- );
- $url = $host_details['api_host_url'].http_build_query($post_values);
- $response = curl_get($url);
- } else {
- // Email & FB Password
- $login_pass = rand_string(8);
- // Username and password for the box
- $item['username'] = "administrator";
- // only use this for the preconfigured boxes
- $item['password'] = $password;
- // Generate a name for the user
- $name = $ci->queries->get_random_name();
- // Generate a birth date between 1/1/75 and 1/1/85
- $birthdate = get_random_birthdate();
- // Insert the server information into the database
- $server_id = $ci->queries->insert_server($item['ip_address'],$item['username'], $item['password'], $atlantic_server_name, $server_location, $item['instanceid']);
- // Generate a server description
- $description = "Name: ".$name['name']."\rD.O.B: ".$birthdate."\r\rInstance ID: ".$item['instanceid']."\rServer Location: ".$server_location."\rEmail/FB Password: ".$login_pass;
- // Insert into the account preparation card
- $ci->trello->create_card($name['name']." - ".$atlantic_server_name." - ".date("M-d-y", time()), $description);
- // Insert into remote desktop manager
- $ci->queries->insert_into_rdm($atlantic_server_name, $item['ip_address'], $item['username'], $item['password']);
- $is_new_ip = TRUE;
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment