SHARE
TWEET

Untitled

a guest Aug 12th, 2016 36 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. This is in my main.php controller
  2. ---------------------------------
  3.  
  4.  
  5.     function create_server() {
  6.  
  7.         $data['success'] = FALSE;
  8.         $data['server_hosts'] = $this->queries->get_host_list();
  9.  
  10.         if (isset($_POST) && (!empty($_POST))) {
  11.            
  12.             //$this->form_validation->set_rules('number_of_servers', 'number_of_servers', 'required|is_natural_no_zero');
  13.             $this->form_validation->set_rules('host_id', 'host_id', 'required|is_natural_no_zero');
  14.  
  15.             if ($this->form_validation->run() != FALSE) {
  16.        
  17.                 $host_id = $_POST['host_id'];
  18.                 $number_of_servers = 1;
  19.                 $server_location = $_POST['server_location'];
  20.                 $host_details = $this->queries->get_host_details(1);
  21.                 $this->admin->create_server_atlantic($host_details, $server_location, $number_of_servers);
  22.                
  23.                 $data['success'] = TRUE;   
  24.             }
  25.            
  26.         }
  27.        
  28.         $this->load->view("create_server", $data);
  29.        
  30.     }
  31.  
  32.  
  33.  
  34.  
  35.  
  36. This is in my models
  37. --------------------
  38.  
  39. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  40.  
  41. class Queries extends CI_Model {
  42.    
  43.     function is_duplicate_ip($ip_address) {
  44.        
  45.         $result = $this->db->get_where("old_ips", array("ip_address" => $ip_address));
  46.         if ($result->num_rows()) {
  47.             return TRUE;
  48.         } else {
  49.             return FALSE;
  50.         }
  51.        
  52.     }
  53.    
  54.     function get_host_details($host_id) {
  55.        
  56.         $result = $this->db->get_where("server_hosts", "host_id = $host_id", 1);
  57.         if ($result->num_rows()) {
  58.             return $result->row_array();
  59.         } else {
  60.             return FALSE;
  61.         }
  62.        
  63.     }
  64.  
  65.     function get_host_list() {
  66.    
  67.         $result = $this->db->get("server_hosts");
  68.         if ($result->num_rows()) {
  69.             foreach ($result->result_array() as $row) {
  70.                 $return_data[] = $row;
  71.             }
  72.             return $return_data;
  73.         } else {
  74.             return FALSE;
  75.         }
  76.    
  77.     }
  78.    
  79.     function insert_server($server_ip,$username,$password,$server_name,$server_location,$instance_id,$user_id = "1") {
  80.         $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));
  81.         $this->db->insert("old_ips", array("ip_address" => $server_ip));
  82.         return mysql_insert_id();
  83.     }
  84.    
  85.     function get_next_ai_value($table = 'servers') {
  86.        
  87.         $result = $this->db->query("SHOW TABLE STATUS LIKE '".$table."'");
  88.         $row = $result->row_array();
  89.         return $row['Auto_increment'];
  90.        
  91.     }
  92.    
  93.     function get_random_name() {
  94.        
  95.         $return_data = array();
  96.        
  97.         $firstname = '';
  98.         $lastname = '';
  99.        
  100.         $result = $this->db->query("SELECT firstname,gender FROM firstnames ORDER BY rand() LIMIT 1,50");
  101.         $row = $result->row_array();
  102.        
  103.         $firstname = $row['firstname'];
  104.         $gender = $row['gender'];
  105.        
  106.         $result = $this->db->query("SELECT lastname FROM lastnames ORDER BY rand() LIMIT 1,500");
  107.         $row = $result->row_array();
  108.        
  109.         $lastname = $row['lastname'];
  110.        
  111.         $return_data['name'] = $firstname." ".$lastname;
  112.         $return_data['gender'] = $gender;
  113.        
  114.         return $return_data;
  115.        
  116.     }
  117.    
  118.     function check_login($username,$password) {
  119.    
  120.         $sql = "SELECT * FROM users WHERE username = ".$this->db->escape($username)." and password = ".$this->db->escape($password)." and active = 1 LIMIT 1";
  121.         $result = $this->db->query($sql);
  122.         if ($result->num_rows()) {
  123.    
  124.             $row = $result->row_array();
  125.             return $row;
  126.    
  127.         } else {
  128.    
  129.             return FALSE;
  130.    
  131.         }
  132.    
  133.     }
  134.    
  135.     function insert_into_rdm($servername,$ip_address,$username,$password) {
  136.        
  137.         $uuid = generate_uuid();
  138.        
  139.         $xml = '<?xml version="1.0"?>
  140. <Connection>
  141.  <UserName>'.$username.'</UserName>
  142.  <ConnectionType>RDPConfigured</ConnectionType>
  143.  <ClearTextPassword>'.$password.'</ClearTextPassword>
  144.  <CreatedBy>BILLY-DESKTOP\Billy</CreatedBy>
  145.  <CreationDateTime>2015-01-16T09:34:05.5657021-05:00</CreationDateTime>
  146.  <Events />
  147.  <Group>Builders\New</Group>
  148.  <ID>'.$uuid.'</ID>
  149.  <MetaInformation>
  150.    <PasswordHistory>
  151.      <PasswordHistory>
  152.        <ModifiedBy>BILLY-DESKTOP\Billy</ModifiedBy>
  153.        <ModifiedDateTime>2015-01-16T09:34:05.5657021-05:00</ModifiedDateTime>
  154.        <SafePassword>TDHFoKmF7Q7JDvqwCVk6yg==</SafePassword>
  155.      </PasswordHistory>
  156.    </PasswordHistory>
  157.  </MetaInformation>
  158.  <Name>'.$servername.'</Name>
  159.  <OpenEmbedded>true</OpenEmbedded>
  160.  <PinEmbeddedMode>False</PinEmbeddedMode>
  161.  <RDP>
  162.    <NetworkLevelAuthentication>true</NetworkLevelAuthentication>
  163.    <RedirectDirectX>false</RedirectDirectX>
  164.    <SafePassword>DAKOq9XZNJHOfQzbdCSc/g==</SafePassword>
  165.    <SmartSizingStreched>false</SmartSizingStreched>
  166.    <UserName>'.$username.'</UserName>
  167.    <VideoPlaybackMode>Disabled</VideoPlaybackMode>
  168.  </RDP>
  169.  <Stamp>2e7c4ec0-fdc2-425b-97b2-99bb22a5eb4b</Stamp>
  170.  <Url>'.$ip_address.'</Url>
  171.  <UsesSerialPorts>false</UsesSerialPorts>
  172. </Connection>';
  173.         /*
  174.         $xml = '<?xml version="1.0"?>
  175. <Connection>
  176.   <UserName>'.$username.'</UserName>
  177.   <ConnectionType>RDPConfigured</ConnectionType>
  178.   <ClearTextPassword>'.$password.'</ClearTextPassword>
  179.   <CreatedBy>BILLY-DESKTOP\Billy</CreatedBy>
  180.   <CreationDateTime>2015-01-01T14:57:18.2277815-05:00</CreationDateTime>
  181.   <Events />
  182.   <ID>'.$uuid.'</ID>
  183.   <MetaInformation>
  184.     <PasswordHistory>
  185.       <PasswordHistory>
  186.         <ModifiedBy>BILLY-DESKTOP\Billy</ModifiedBy>
  187.         <ModifiedDateTime>2015-01-01T14:57:18.2287557-05:00</ModifiedDateTime>
  188.       </PasswordHistory>
  189.     </PasswordHistory>
  190.   </MetaInformation>
  191.   <Name>'.$servername.'</Name>
  192.   <OpenEmbedded>true</OpenEmbedded>
  193.   <PinEmbeddedMode>False</PinEmbeddedMode>
  194.   <PlayList />
  195.   <RDP>
  196.     <LoadAddOns>false</LoadAddOns>
  197.     <NetworkLevelAuthentication>true</NetworkLevelAuthentication>
  198.     <RedirectDirectX>false</RedirectDirectX>
  199.     <SmartSizingStreched>false</SmartSizingStreched>
  200.     <UserName>'.$username.'</UserName>
  201.     <VideoPlaybackMode>Disabled</VideoPlaybackMode>
  202.   </RDP>
  203.   <ScreenSize>R1280x800</ScreenSize>
  204.   <Stamp>4eb2b4b6-9fe6-48b5-bf65-c486e8e342d5</Stamp>
  205.   <Tools>
  206.     <CredentialSource>CurrentSession</CredentialSource>
  207.   </Tools>
  208.   <Url>'.$ip_address.'</Url>
  209.   <UsesHardDrives>false</UsesHardDrives>
  210.   <UsesSerialPorts>false</UsesSerialPorts>
  211. </Connection>';
  212.         */
  213.    
  214. $sql = "INSERT INTO `Connections` (`ID`, `Data`, `SecurityGroup`, `ConnectionType`, `ConnectionSubType`, `GroupName`, `Name`, `UnsafePassword`, `DataSourceID`, `MetaData`, `CreationDate`, `Description`, `CustomerID`, `ModifiedUsername`, `ModifiedLoggedUserName`, `ModifiedDate`, `Version`, `AttachmentCount`, `AttachmentPrivateCount`)
  215.         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')";
  216.     $this->db->query($sql);
  217.        
  218.     }
  219.    
  220. }
  221.  
  222.  
  223.  
  224.  
  225. This is in my functions file
  226. -----------------------------
  227.  
  228. 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)); }
  229.  
  230. function generate_uuid() {
  231.     return sprintf( '%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
  232.             mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ),
  233.             mt_rand( 0, 0xffff ),
  234.             mt_rand( 0, 0x0fff ) | 0x4000,
  235.             mt_rand( 0, 0x3fff ) | 0x8000,
  236.             mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff )
  237.     );
  238. }
  239.  
  240. function rand_string( $length ) {
  241.     $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  242.     return substr(str_shuffle($chars),0,$length);
  243. }
  244.  
  245.  
  246. function get_random_birthdate() {
  247.     $int= mt_rand(157766400,504748800);
  248.     $string = date("M-d-Y",$int);
  249.     return $string;
  250. }
  251.  
  252. function generate_rdm_xml($servername,$ip_address,$username,$password) {
  253.    
  254.     $id = generate_uuid();
  255.  
  256.     $xml = '<?xml version="1.0"?>
  257. <Connection>
  258.  <UserName>administrator</UserName>
  259.  <ConnectionType>RDPConfigured</ConnectionType>
  260.  <ClearTextPassword>'.$password.'</ClearTextPassword>
  261.  <CreatedBy>BILLY-DESKTOP\Billy</CreatedBy>
  262.  <CreationDateTime>2015-01-01T14:57:18.2277815-05:00</CreationDateTime>
  263.  <Events />
  264.  <ID>'.$id.'</ID>
  265.  <MetaInformation>
  266.    <PasswordHistory>
  267.      <PasswordHistory>
  268.        <ModifiedBy>BILLY-DESKTOP\Billy</ModifiedBy>
  269.        <ModifiedDateTime>2015-01-01T14:57:18.2287557-05:00</ModifiedDateTime>
  270.      </PasswordHistory>
  271.    </PasswordHistory>
  272.  </MetaInformation>
  273.  <Name>'.$ip_address.'</Name>
  274.  <OpenEmbedded>true</OpenEmbedded>
  275.  <PinEmbeddedMode>False</PinEmbeddedMode>
  276.  <PlayList />
  277.  <RDP>
  278.    <LoadAddOns>false</LoadAddOns>
  279.    <NetworkLevelAuthentication>true</NetworkLevelAuthentication>
  280.    <RedirectDirectX>false</RedirectDirectX>
  281.    <SmartSizingStreched>false</SmartSizingStreched>
  282.    <UserName>administrator</UserName>
  283.    <VideoPlaybackMode>Disabled</VideoPlaybackMode>
  284.  </RDP>
  285.  <Stamp>4eb2b4b6-9fe6-48b5-bf65-c486e8e342d5</Stamp>
  286.  <Tools>
  287.    <CredentialSource>CurrentSession</CredentialSource>
  288.  </Tools>
  289.  <Url>'.$ip_address.'</Url>
  290.  <UsesHardDrives>false</UsesHardDrives>
  291.  <UsesSerialPorts>false</UsesSerialPorts>
  292. </Connection>';
  293.  
  294. }
  295.  
  296.  
  297.  
  298.  
  299.  
  300. Main admin creation function
  301. ----------------------------
  302.  
  303.     function create_server_atlantic($host_details, $server_location, $number_of_servers) {
  304.        
  305.         $ci =& get_instance();
  306.  
  307.         $winver = 12;
  308.        
  309.         if ($winver == 8) {
  310.             $cloneimage = "31928-76646"; // win2k08
  311.             $password = "ABC123";
  312.         } else {
  313.             $cloneimage = "31928-76647"; // win2k12
  314.             $password = 'ABC123';
  315.            
  316.         }
  317.        
  318.         $is_new_ip = FALSE;
  319.         while ($is_new_ip == FALSE) {
  320.        
  321.             // Generate all the variables necessary for atlantic.net API
  322.             $timestamp = time();
  323.             $guid = generate_guid();
  324.             $str_to_sign = $timestamp.$guid;
  325.             $signature = hash_hmac('sha256', $str_to_sign, $host_details['api_private_key'], true);
  326.             $encodedsignature = base64_encode($signature);
  327.             $next_ai_value = $ci->queries->get_next_ai_value();
  328.             $atlantic_server_name = substr($_SESSION['user']['firstname'],0,1).substr($_SESSION['user']['lastname'],0,1).$next_ai_value;
  329.    
  330.             /*
  331.              *
  332.              * This is the original post code
  333.             $post_values = array(
  334.                     "Version" => "2010-12-30",
  335.                     "ACSAccessKeyId" => $host_details['api_key'],
  336.                     "Format" => "json",
  337.                     "Timestamp" => $timestamp,
  338.                     "Rndguid" => $guid,
  339.                     "Signature" => $encodedsignature,
  340.                     //"Action" => "describe-image",
  341.                     "Action" => "run-instance",
  342.                     "servername" => $atlantic_server_name,
  343.                     "planname" => "S",
  344.                     //"cloneimage" => $cloneimage,
  345.                     "imageid" => "",
  346.                     "vm_location" => $server_location,
  347.                     //"imageid" => "Master-Image-31928-76647",
  348.                     //"imageid" => "Master-Image-31928-76646",
  349.                     //"imageid" => "Windows-2008-R2-SP1-Datacenter_64bit",
  350.                     "imageid" => "Windows-2012-R2-Datacenter_64bit",
  351.                     "server_qty" => $number_of_servers
  352.             );
  353.            */
  354.  
  355.             $post_values = array(
  356.                 "Version" => "2010-12-30",
  357.                 "ACSAccessKeyId" => $host_details['api_key'],
  358.                 "Format" => "json",
  359.                 "Timestamp" => $timestamp,
  360.                 "Rndguid" => $guid,
  361.                 "Signature" => $encodedsignature,
  362.                 //"Action" => "describe-image",
  363.                 "Action" => "run-instance",
  364.                 "servername" => $atlantic_server_name,
  365.                 "planname" => "S",
  366.                 "cloneimage" => $cloneimage,
  367.                 //"imageid" => "",
  368.                 "vm_location" => $server_location,
  369.                 //"imageid" => "Master-Image-31928-76647",
  370.                 //"imageid" => "Master-Image-31928-76646",
  371.                 //"imageid" => "Windows-2008-R2-SP1-Datacenter_64bit",
  372.                 //"imageid" => "Windows-2012-R2-Datacenter_64bit",
  373.                 "server_qty" => $number_of_servers
  374.             );
  375.            
  376.             $url = $host_details['api_host_url'].http_build_query($post_values);
  377.             $response = curl_get($url);
  378.    
  379.             if ($response['success']) {
  380.                
  381.                 $json = json_decode($response['response'], TRUE);
  382.                 $item = $json['run-instanceresponse']['instancesSet']['item'];
  383.                
  384.                 if ($ci->queries->is_duplicate_ip($item['ip_address'])) {
  385.                     sleep(15);
  386.                    
  387.                     $timestamp = time();
  388.                     $guid = generate_guid();
  389.                     $str_to_sign = $timestamp.$guid;
  390.                     $signature = hash_hmac('sha256', $str_to_sign, $host_details['api_private_key'], true);
  391.                     $encodedsignature = base64_encode($signature);
  392.                    
  393.                     $post_values = array(
  394.                         "Version" => "2010-12-30",
  395.                         "ACSAccessKeyId" => $host_details['api_key'],
  396.                         "Format" => "json",
  397.                         "Timestamp" => $timestamp,
  398.                         "Rndguid" => $guid,
  399.                         "Signature" => $encodedsignature,
  400.                         "Action" => "terminate-instance",
  401.                         "instanceid" => $item['instanceid']
  402.                     );
  403.                    
  404.                     $url = $host_details['api_host_url'].http_build_query($post_values);
  405.                     $response = curl_get($url);
  406.                    
  407.                 } else {
  408.                
  409.                     // Email & FB Password
  410.                     $login_pass = rand_string(8);
  411.                    
  412.                     // Username and password for the box
  413.                     $item['username'] = "administrator";
  414.                    
  415.                     // only use this for the preconfigured boxes
  416.                     $item['password'] = $password;
  417.                    
  418.                     // Generate a name for the user
  419.                     $name = $ci->queries->get_random_name();
  420.                    
  421.                     // Generate a birth date between 1/1/75 and 1/1/85
  422.                     $birthdate = get_random_birthdate();
  423.                    
  424.                     // Insert the server information into the database
  425.                     $server_id = $ci->queries->insert_server($item['ip_address'],$item['username'], $item['password'], $atlantic_server_name, $server_location, $item['instanceid']);
  426.    
  427.                     // Generate a server description
  428.                     $description = "Name: ".$name['name']."\rD.O.B: ".$birthdate."\r\rInstance ID: ".$item['instanceid']."\rServer Location: ".$server_location."\rEmail/FB Password: ".$login_pass;
  429.                    
  430.                     // Insert into the account preparation card            
  431.                     $ci->trello->create_card($name['name']." - ".$atlantic_server_name." - ".date("M-d-y", time()), $description);
  432.                    
  433.                     // Insert into remote desktop manager
  434.                     $ci->queries->insert_into_rdm($atlantic_server_name, $item['ip_address'], $item['username'], $item['password']);
  435.                    
  436.                     $is_new_ip = TRUE;
  437.                    
  438.                 }
  439.                
  440.             }
  441.        
  442.         }
  443.  
  444.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top