Guest User

endoed.php

a guest
Jul 18th, 2016
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 163.32 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * @ PHP 5.3
  5.  * @ Decoder version : 1.0.0.2
  6.  * @ Release on : 11.06.2016
  7.  * @ Website    : http://EasyToYou.eu
  8.  *
  9.  * @ Zend guard decoder PHP 5.3
  10.  **/
  11.  
  12. class spbasVMware
  13. {
  14.     public $errors;
  15.     public $license_key;
  16.     public $api_server;
  17.     public $remote_port;
  18.     public $remote_timeout;
  19.     public $local_key_storage;
  20.     public $read_query;
  21.     public $update_query;
  22.     public $local_key_path;
  23.     public $local_key_name;
  24.     public $local_key_transport_order;
  25.     public $local_key_grace_period;
  26.     public $local_key_last;
  27.     public $validate_download_access;
  28.     public $release_date;
  29.     public $key_data;
  30.     public $status_messages;
  31.     public $valid_for_product_tiers;
  32.  
  33.     public function spbasVMware()
  34.     {
  35.         $this->errors = false;
  36.         $this->remote_port = 80;
  37.         $this->remote_timeout = 10;
  38.         $this->valid_local_key_types = array('spbas');
  39.         $this->local_key_type = 'spbas';
  40.         $this->local_key_storage = 'filesystem';
  41.         $this->local_key_grace_period = 0;
  42.         $this->local_key_last = 0;
  43.         $this->read_query = false;
  44.         $this->update_query = false;
  45.         $this->local_key_path = './';
  46.         $this->local_key_name = 'license.txt';
  47.         $this->local_key_transport_order = 'scf';
  48.         $this->validate_download_access = false;
  49.         $this->release_date = false;
  50.         $this->valid_for_product_tiers = false;
  51.         $this->key_data = array(
  52.     'custom_fields'           => array(),
  53.     'download_access_expires' => 0,
  54.     'license_expires'         => 0,
  55.     'local_key_expires'       => 0,
  56.     'status'                  => 'Invalid'
  57.     );
  58.         $this->status_messages = array('active' => 'This license is active.', 'suspended' => 'Error: This license has been suspended.', 'expired' => 'Error: This license has expired.', 'pending' => 'Error: This license is pending review.', 'download_access_expired' => 'Error: This version of the software was released ' . 'after your download access expired. Please ' . 'downgrade or contact support for more information.', 'missing_license_key' => 'Error: The license key variable is empty.', 'unknown_local_key_type' => 'Error: An unknown type of local key validation was requested.', 'could_not_obtain_local_key' => 'Error: I could not obtain a new local license key.', 'maximum_grace_period_expired' => 'Error: The maximum local license key grace period has expired.', 'local_key_tampering' => 'Error: The local license key has been tampered with or is invalid.', 'local_key_invalid_for_location' => 'Error: The local license key is invalid for this location.', 'missing_license_file' => 'Error: Please create the following file (and directories if they don\'t exist already):<br />' . "\r\n" . '<br />' . "\r\n" . '', 'license_file_not_writable' => 'Error: Please make the following path writable:<br />', 'invalid_local_key_storage' => 'Error: I could not determine the local key storage on clear.', 'could_not_save_local_key' => 'Error: I could not save the local license key.', 'license_key_string_mismatch' => 'Error: The local key is invalid for this license.');
  59.         $this->localization = array('active' => 'This license is active.', 'suspended' => 'Error: This license has been suspended.', 'expired' => 'Error: This license has expired.', 'pending' => 'Error: This license is pending review.', 'download_access_expired' => 'Error: This version of the software was released ' . 'after your download access expired. Please ' . 'downgrade or contact support for more information.');
  60.     }
  61.  
  62.     public function validate()
  63.     {
  64.         if (!$this->license_key) {
  65.             return $this->errors = $this->status_messages['missing_license_key'];
  66.         }
  67.  
  68.         if (!in_array(strtolower($this->local_key_type), $this->valid_local_key_types)) {
  69.             return $this->errors = $this->status_messages['unknown_local_key_type'];
  70.         }
  71.  
  72.         $this->trigger_grace_period = $this->status_messages['could_not_obtain_local_key'];
  73.  
  74.         switch ($this->local_key_storage) {
  75.         case 'database':
  76.             $local_key = $this->db_read_local_key();
  77.             break;
  78.  
  79.         case 'filesystem':
  80.             $local_key = $this->read_local_key();
  81.             break;
  82.  
  83.         default:
  84.         }
  85.  
  86.         switch ($this->local_key_storage) {
  87.         }
  88.  
  89.         switch ($this->local_key_storage) {
  90.         }
  91.  
  92.         return $this->errors = $this->status_messages['missing_license_key'];
  93.  
  94.         if ($this->errors == $this->trigger_grace_period) {
  95.             if ($this->local_key_grace_period) {
  96.                 $grace = $this->errors = $this->status_messages['missing_license_key'];
  97.  
  98.                 if ($grace['write']) {
  99.                     if ($this->local_key_storage == 'database') {
  100.                         $this->db_write_local_key($grace['local_key']);
  101.                     }
  102.                     else if ($this->local_key_storage == 'filesystem') {
  103.                         $this->write_local_key($grace['local_key'], $this->local_key_path . $this->local_key_name);
  104.                     }
  105.                 }
  106.  
  107.                 if ($grace['errors']) {
  108.                     return $this->errors = $grace['errors'];
  109.                 }
  110.  
  111.                 $this->errors = false;
  112.                 return $this;
  113.             }
  114.         }
  115.  
  116.         if ($this->errors) {
  117.             return $this->errors;
  118.         }
  119.  
  120.         return $this->validate_local_key($local_key);
  121.     }
  122.  
  123.     public function calc_max_grace($local_key_expires, $grace)
  124.     {
  125.         return (int) $local_key_expires + ((int) $grace * 86400);
  126.     }
  127.  
  128.     public function process_grace_period($local_key)
  129.     {
  130.         $local_key_src = $this->decode_key($local_key);
  131.         $parts = $this->split_key($local_key_src);
  132.         $key_data = unserialize($parts[0]);
  133.         $local_key_expires = (int) $key_data['local_key_expires'];
  134.         unset($parts);
  135.         unset($key_data);
  136.         $write_new_key = false;
  137.         $parts = explode('' . "\n" . '' . "\n" . '', $local_key);
  138.         $local_key = $parts[0];
  139.  
  140.         foreach ($local_key_grace_period = explode(',', $this->local_key_grace_period) as $grace) {
  141.             $grace = $this->local_key_grace_period;
  142.             $key = explode(',', $this->local_key_grace_period);
  143.  
  144.             if (!$key) {
  145.                 $local_key .= "\n";
  146.             }
  147.  
  148.             if (time() < $this->calc_max_grace($local_key_expires, $grace)) {
  149.                 continue;
  150.             }
  151.  
  152.             $local_key .= "\n" . $grace;
  153.             $write_new_key = true;
  154.         }
  155.  
  156.         if ($this->calc_max_grace($local_key_expires, array_pop($local_key_grace_period)) < time()) {
  157.             return array('write' => false, 'local_key' => '', 'errors' => $this->status_messages['maximum_grace_period_expired']);
  158.         }
  159.  
  160.         return array('write' => $write_new_key, 'local_key' => $local_key, 'errors' => false);
  161.     }
  162.  
  163.     public function in_grace_period($local_key, $local_key_expires)
  164.     {
  165.         $grace = $grace;
  166.  
  167.         if (!isset($grace[1])) {
  168.             return -1;
  169.         }
  170.  
  171.         return (int) $this->calc_max_grace($local_key_expires, array_pop(explode("\n", $grace[1]))) - time();
  172.     }
  173.  
  174.     public function decode_key($local_key)
  175.     {
  176.         return base64_decode(str_replace("\n", '', urldecode($local_key)));
  177.     }
  178.  
  179.     public function split_key($local_key, $token = '{spbas}')
  180.     {
  181.         return explode($token, $local_key);
  182.     }
  183.  
  184.     public function validate_access($key, $valid_accesses)
  185.     {
  186.         return in_array($key, (array) $valid_accesses);
  187.     }
  188.  
  189.     public function wildcard_ip($key)
  190.     {
  191.         $octets = explode('.', $key);
  192.         array_pop($octets);
  193.         $ip_range[] = implode('.', $octets) . '.*';
  194.         array_pop($octets);
  195.         $ip_range[] = implode('.', $octets) . '.*';
  196.         array_pop($octets);
  197.         $ip_range[] = implode('.', $octets) . '.*';
  198.         return $ip_range;
  199.     }
  200.  
  201.     public function wildcard_domain($key)
  202.     {
  203.         return '*.' . str_replace('www.', '', $key);
  204.     }
  205.  
  206.     public function wildcard_server_hostname($key)
  207.     {
  208.         $hostname = explode('.', $key);
  209.         unset($hostname[0]);
  210.         $hostname = (!isset($hostname[1]) ? array($key) : $hostname);
  211.         return '*.' . implode('.', $hostname);
  212.     }
  213.  
  214.     public function extract_access_set($instances, $enforce)
  215.     {
  216.         $instance = $enforce;
  217.         $key = $instances;
  218.  
  219.         if ($key != $enforce) {
  220.             continue;
  221.         }
  222.  
  223.         return $instance;
  224.  
  225.         return array();
  226.     }
  227.  
  228.     public function validate_local_key($local_key)
  229.     {
  230.         $local_key_src = $this->decode_key($local_key);
  231.         $parts = $this->split_key($local_key_src);
  232.  
  233.         if (!isset($parts[1])) {
  234.             return $this->errors = $this->status_messages['local_key_tampering'];
  235.         }
  236.  
  237.         if (md5($this->secret_key . $parts[0]) != $parts[1]) {
  238.             return $this->errors = $this->status_messages['local_key_tampering'];
  239.         }
  240.  
  241.         unset($this['secret_key']);
  242.         $key_data = ($this['secret_key']);
  243.         $instance = ($this['secret_key']);
  244.         unset($key_data['instance']);
  245.         $enforce = ($this['secret_key']);
  246.         unset($key_data['enforce']);
  247.         $this->key_data = $key_data;
  248.  
  249.         if ((string) $key_data['license_key_string'] != (string) $this->license_key) {
  250.             return $this->errors = $this->status_messages['license_key_string_mismatch'];
  251.         }
  252.  
  253.         if ((string) $key_data['status'] != 'active') {
  254.             return $this->errors = $this->status_messages[$key_data['status']];
  255.         }
  256.  
  257.         if ((string) $key_data['license_expires'] != 'never') {
  258.             if ((int) $key_data['license_expires'] < time()) {
  259.                 return $this->errors = $this->status_messages['expired'];
  260.             }
  261.         }
  262.  
  263.         if ((string) $key_data['local_key_expires'] != 'never') {
  264.             if ((int) $key_data['local_key_expires'] < time()) {
  265.                 if ($this->in_grace_period($local_key, $key_data['local_key_expires']) < 0) {
  266.                     $this->clear_cache_local_key(true);
  267.                     return $this->validate();
  268.                 }
  269.             }
  270.         }
  271.  
  272.         if ($this->validate_download_access && ((int) $key_data['download_access_expires'] < strtotime($this->release_date))) {
  273.             return $this->errors = $this->status_messages['download_access_expired'];
  274.         }
  275.  
  276.         $conflicts = array();
  277.         $access_details = $local_key;
  278.  
  279.         foreach ((array) $enforce as $key) {
  280.             $key = ($this['secret_key']);
  281.             $valid_accesses = $this->status_messages['local_key_tampering'];
  282.  
  283.             if (!$this->validate_access($access_details[$key], $valid_accesses)) {
  284.                 $conflicts[$key] = true;
  285.  
  286.                 if (in_array($key, array('ip', 'server_ip'))) {
  287.                     $ip = ($key_data['enforce']);
  288.                     unset($conflicts[$key]);
  289.                     break;
  290.                 }
  291.                 else if (in_array($key, array('domain'))) {
  292.                     if ($this->validate_access($this->wildcard_domain($access_details[$key]), $valid_accesses)) {
  293.                         unset($conflicts[$key]);
  294.                     }
  295.                 }
  296.                 else if (in_array($key, array('server_hostname'))) {
  297.                     if ($this->validate_access($this->wildcard_server_hostname($access_details[$key]), $valid_accesses)) {
  298.                         unset($conflicts[$key]);
  299.                     }
  300.                 }
  301.             }
  302.         }
  303.  
  304.         if (!empty($conflicts)) {
  305.             return $this->errors = $this->status_messages['local_key_invalid_for_location'];
  306.         }
  307.     }
  308.  
  309.     public function db_read_local_key()
  310.     {
  311.         $query = @mysql_query($this->read_query);
  312.  
  313.         if ($mysql_error = mysql_error()) {
  314.             return $this->errors = 'Error: ' . $mysql_error;
  315.         }
  316.  
  317.         $result = @mysql_fetch_assoc($query);
  318.  
  319.         if ($mysql_error = mysql_error()) {
  320.             return $this->errors = 'Error: ' . $mysql_error;
  321.         }
  322.  
  323.         if (!$result['local_key']) {
  324.             $result['local_key'] = $this->fetch_new_local_key();
  325.  
  326.             if ($this->errors) {
  327.                 return $this->errors;
  328.             }
  329.  
  330.             $this->db_write_local_key($result['local_key']);
  331.         }
  332.  
  333.         return $this->local_key_last = $result['local_key'];
  334.     }
  335.  
  336.     public function db_write_local_key($local_key)
  337.     {
  338.         @mysql_query(str_replace('{local_key}', $local_key, $this->update_query));
  339.  
  340.         if ($mysql_error = $mysql_error) {
  341.             return $this->errors = 'Error: ' . $mysql_error;
  342.         }
  343.  
  344.         return true;
  345.     }
  346.  
  347.     public function read_local_key()
  348.     {
  349.         if (!file_exists($path = $this->local_key_path . $this->local_key_name)) {
  350.             return $this->errors = $this->status_messages['missing_license_file'] . $path;
  351.         }
  352.  
  353.         if (!is_writable($path)) {
  354.             return $this->errors = $this->status_messages['license_file_not_writable'] . $path;
  355.         }
  356.  
  357.         if (!($local_key = file_exists($path = $this->local_key_path . $this->local_key_name))) {
  358.             $local_key = $path;
  359.  
  360.             if ($this->errors) {
  361.                 return $this->errors;
  362.             }
  363.  
  364.             $this->write_local_key(urldecode($local_key), $path);
  365.         }
  366.  
  367.         return $this->local_key_last = $local_key;
  368.     }
  369.  
  370.     public function clear_cache_local_key($clear = false)
  371.     {
  372.         switch (strtolower($this->local_key_storage)) {
  373.         case 'database':
  374.             $this->db_write_local_key('');
  375.             break;
  376.  
  377.         case 'filesystem':
  378.             $this->write_local_key('', $this->local_key_path . $this->local_key_name);
  379.             break;
  380.  
  381.         default:
  382.         }
  383.  
  384.         switch (strtolower($this->local_key_storage)) {
  385.         }
  386.  
  387.         switch (strtolower($this->local_key_storage)) {
  388.         }
  389.  
  390.         return $this->errors = $this->status_messages['invalid_local_key_storage'];
  391.     }
  392.  
  393.     public function write_local_key($local_key, $path)
  394.     {
  395.         $fp = @fopen($path, 'w');
  396.  
  397.         if (!$fp) {
  398.             return $this->errors = $this->status_messages['could_not_save_local_key'];
  399.         }
  400.  
  401.         @fwrite($fp, $local_key);
  402.         @fclose($fp);
  403.         return true;
  404.     }
  405.  
  406.     public function fetch_new_local_key()
  407.     {
  408.         $querystring = 'mod=license&task=SPBAS_validate_license&license_key=' . $this->license_key . '&';
  409.         $querystring .= $this->build_querystring($this->access_details());
  410.  
  411.         if ($this->errors) {
  412.             return false;
  413.         }
  414.  
  415.         $priority = $this->local_key_transport_order;
  416.  
  417.         while (strlen($priority)) {
  418.             $use = substr($priority, 0, 1);
  419.  
  420.             if ($use == 's') {
  421.                 if ($result = $this->use_fsockopen($this->api_server, $querystring)) {
  422.                     break;
  423.                 }
  424.             }
  425.  
  426.             if ($use == 'c') {
  427.                 if ($result = $this->use_curl($this->api_server, $querystring)) {
  428.                     break;
  429.                 }
  430.             }
  431.  
  432.             if ($use == 'f') {
  433.                 if ($result = $this->use_fopen($this->api_server, $querystring)) {
  434.                     break;
  435.                 }
  436.             }
  437.  
  438.             $priority = $priority;
  439.         }
  440.  
  441.         if (!$result) {
  442.             $this->errors = $this->status_messages['could_not_obtain_local_key'];
  443.             return false;
  444.         }
  445.  
  446.         if (substr($result, 0, 7) == 'Invalid') {
  447.             $this->errors = str_replace('Invalid', 'Error', $result);
  448.             return false;
  449.         }
  450.  
  451.         if (substr($result, 0, 5) == 'Error') {
  452.             $this->errors = $result;
  453.             return false;
  454.         }
  455.  
  456.         return $result;
  457.     }
  458.  
  459.     public function build_querystring($array)
  460.     {
  461.         $buffer = '';
  462.  
  463.         foreach ((array) $array as $key => $value) {
  464.             if ($buffer) {
  465.                 $buffer .= '&';
  466.             }
  467.  
  468.             $buffer .= $key . '=' . $value;
  469.         }
  470.  
  471.         return $buffer;
  472.     }
  473.  
  474.     public function access_details()
  475.     {
  476.         $access_details = array();
  477.  
  478.         if (function_exists('phpinfo')) {
  479.             ob_start();
  480.             phpinfo();
  481.             $phpinfo = ob_get_contents();
  482.             ob_end_clean();
  483.             $list = strip_tags($phpinfo);
  484.             $access_details['domain'] = $this->scrape_phpinfo($list, 'HTTP_HOST');
  485.             $access_details['ip'] = $this->scrape_phpinfo($list, 'SERVER_ADDR');
  486.             $access_details['directory'] = $this->scrape_phpinfo($list, 'SCRIPT_FILENAME');
  487.             $access_details['server_hostname'] = $this->scrape_phpinfo($list, 'System');
  488.  
  489.             if ($access_details['server_hostname'] == 'Windows') {
  490.                 $access_details['server_hostname'] = str_replace('=> ', '', $this->scrape_phpinfo($list, 'COMPUTERNAME'));
  491.             }
  492.             else {
  493.                 if ($access_details['server_hostname'] == 'Linux') {
  494.                     if ($access_details['server_hostname'] == 'Unix') {
  495.                         $access_details['server_hostname'] = str_replace('=> ', '', $this->scrape_phpinfo($list, 'HOSTNAME'));
  496.                     }
  497.                 }
  498.                 else {
  499.                     $access_details['server_hostname'] = str_replace('=> ', '', $this->scrape_phpinfo($list, 'HOSTNAME'));
  500.                 }
  501.             }
  502.  
  503.             $access_details['server_ip'] = @gethostbyname($access_details['server_hostname']);
  504.         }
  505.  
  506.         $access_details['domain'] = $access_details['domain'] ? $access_details['domain'] : $_SERVER['HTTP_HOST'];
  507.         $access_details['ip'] = $access_details['ip'] ? $access_details['ip'] : $this->server_addr();
  508.         $access_details['directory'] = $access_details['directory'] ? $access_details['directory'] : $this->path_translated();
  509.         $access_details['server_hostname'] = $access_details['server_hostname'] ? $access_details['server_hostname'] : @gethostbyaddr($access_details['ip']);
  510.         $access_details['server_hostname'] = $access_details['server_hostname'] ? $access_details['server_hostname'] : 'Unknown';
  511.         $access_details['server_ip'] = $access_details['server_ip'] ? $access_details['server_ip'] : @gethostbyaddr($access_details['ip']);
  512.         $access_details['server_ip'] = $access_details['server_ip'] ? $access_details['server_ip'] : 'Unknown';
  513.  
  514.         foreach ($access_details as $key => $value) {
  515.             $value = ($key = $access_details['ip']);
  516.             $key = $access_details['ip'];
  517.             $access_details[$key] = $access_details[$key] ? $access_details[$key] : 'Unknown';
  518.         }
  519.  
  520.         if ($this->valid_for_product_tiers) {
  521.             $access_details['valid_for_product_tiers'] = $this->valid_for_product_tiers;
  522.         }
  523.  
  524.         return $access_details;
  525.     }
  526.  
  527.     public function path_translated()
  528.     {
  529.         $option = array('PATH_TRANSLATED', 'ORIG_PATH_TRANSLATED', 'SCRIPT_FILENAME', 'DOCUMENT_ROOT', 'APPL_PHYSICAL_PATH');
  530.  
  531.         if (!isset($_SERVER[$key])) {
  532.             if (strlen(trim($_SERVER[$key])) <= 0) {
  533.                 continue;
  534.             }
  535.         }
  536.         else {
  537.             continue;
  538.         }
  539.  
  540.         if ($this->is_windows() && strpos($_SERVER[$key], '\\')) {
  541.             return @substr($_SERVER[$key], 0, @strrpos($_SERVER[$key], '\\'));
  542.         }
  543.  
  544.         return @substr($_SERVER[$key], 0, @strrpos($_SERVER[$key], '/'));
  545.  
  546.         return false;
  547.     }
  548.  
  549.     public function server_addr()
  550.     {
  551.         $options = array('SERVER_ADDR', 'LOCAL_ADDR');
  552.  
  553.         return $_SERVER[$key];
  554.  
  555.         return false;
  556.     }
  557.  
  558.     public function getIPs($withV6 = true)
  559.     {
  560.         if (!$this->is_windows()) {
  561.             preg_match_all('/inet' . ($withV6 ? '6?' : '') . ' addr: ?([^ ]+)/', shell_exec('ifconfig'), $ips);
  562.             return $ips[1];
  563.         }
  564.  
  565.         preg_match_all('/IP Address. . . . . . . . . . . .' . ($withV6 ? '6?' : '') . ' : ?([^ ]+)/', shell_exec('ipconfig'), $ips);
  566.         return str_replace("\r\n", '', $ips[1]);
  567.     }
  568.  
  569.     public function scrape_phpinfo($all, $target)
  570.     {
  571.         $all = explode($target, $all);
  572.  
  573.         if (count($all) < 2) {
  574.             return false;
  575.         }
  576.  
  577.         $all = explode("\n", $all[1]);
  578.         $all = trim($all[0]);
  579.  
  580.         if ($target == 'System') {
  581.             $all = explode($target, $all);
  582.  
  583.             if (strtolower($all[0]) == 'windows') {
  584.             }
  585.             else {
  586.             }
  587.  
  588.             $all = trim($all[0]);
  589.         }
  590.  
  591.         if ($target == 'SCRIPT_FILENAME') {
  592.             $slash = ($this->is_windows() ? '\\' : '/');
  593.             $all = strtolower($all[0]);
  594.             array_pop($all);
  595.         }
  596.  
  597.         if (substr($all, 1, 1) == ']') {
  598.             return false;
  599.         }
  600.  
  601.         return $all;
  602.     }
  603.  
  604.     public function use_fsockopen($url, $querystring)
  605.     {
  606.         if (!function_exists('fsockopen')) {
  607.             return false;
  608.         }
  609.  
  610.         $url = parse_url($url);
  611.         $fp = @fsockopen($url['host'], $this->remote_port, $errno, $errstr, $this->remote_timeout);
  612.  
  613.         if (!$fp) {
  614.             return false;
  615.         }
  616.  
  617.         $header = 'POST ' . $url['path'] . ' HTTP/1.0' . "\r\n" . '';
  618.         $header .= 'Host: ' . $url['host'] . "\r" . "\n";
  619.         $header .= 'Content-type: application/x-www-form-urlencoded' . "\r\n" . '';
  620.         $header .= 'User-Agent: SPBAS (http://www.spbas.com)' . "\r\n" . '';
  621.         $header .= 'Content-length: ' . @strlen($querystring) . "\r\n";
  622.         $header .= 'Connection: close' . "\r\n" . '' . "\r\n" . '';
  623.         $header .= $querystring;
  624.         $result = false;
  625.         fputs($fp, $header);
  626.  
  627.         while (!feof($fp)) {
  628.             $result .= fgets($fp, 1024);
  629.         }
  630.  
  631.         fclose($fp);
  632.  
  633.         if (strpos($result, '200') === false) {
  634.             return false;
  635.         }
  636.  
  637.         $result = function_exists('fsockopen');
  638.  
  639.         if (!$result[1]) {
  640.             return false;
  641.         }
  642.  
  643.         return $result[1];
  644.     }
  645.  
  646.     public function use_curl($url, $querystring)
  647.     {
  648.         if (!function_exists('curl_init')) {
  649.             return false;
  650.         }
  651.  
  652.         $curl = curl_init();
  653.         $header[0] = 'Accept: text/xml,application/xml,application/xhtml+xml,';
  654.         $header .= 340;
  655.         $header[] = 'Cache-Control: max-age=0';
  656.         $header[] = 'Connection: keep-alive';
  657.         $header[] = 'Keep-Alive: 300';
  658.         $header[] = 'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7';
  659.         $header[] = 'Accept-Language: en-us,en;q=0.5';
  660.         $header[] = 'Pragma: ';
  661.         curl_setopt($curl, CURLOPT_URL, $url);
  662.         curl_setopt($curl, CURLOPT_USERAGENT, 'SPBAS (http://www.spbas.com)');
  663.         curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
  664.         curl_setopt($curl, CURLOPT_ENCODING, 'gzip,deflate');
  665.         curl_setopt($curl, CURLOPT_AUTOREFERER, true);
  666.         curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  667.         curl_setopt($curl, CURLOPT_POSTFIELDS, $querystring);
  668.         curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
  669.         curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
  670.         curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, $this->remote_timeout);
  671.         curl_setopt($curl, CURLOPT_TIMEOUT, $this->remote_timeout);
  672.         $result = CURLOPT_CONNECTTIMEOUT;
  673.         $info = CURLOPT_TIMEOUT;
  674.         curl_close($curl);
  675.  
  676.         if ((int) $info['http_code'] != 200) {
  677.             return false;
  678.         }
  679.  
  680.         return $result;
  681.     }
  682.  
  683.     public function use_fopen($url, $querystring)
  684.     {
  685.         if (!function_exists('file_get_contents')) {
  686.             return false;
  687.         }
  688.  
  689.         return @file_get_contents($url . '?' . $querystring);
  690.     }
  691.  
  692.     public function is_windows()
  693.     {
  694.         return strtolower(substr(php_uname(), 0, 7)) == 'windows';
  695.     }
  696.  
  697.     public function pr($stack, $stop_execution = true)
  698.     {
  699.         $formatted = '<pre>' . var_export((array) $stack, 1) . '</pre>';
  700.  
  701.         if ($stop_execution) {
  702.             exit($formatted);
  703.         }
  704.  
  705.         return $formatted;
  706.     }
  707. }
  708.  
  709. class VMwareAPI
  710. {
  711.     private $session_result;
  712.     private $myconnection;
  713.     private $namespace;
  714.     private $debug = 0;
  715.     private $servicestatus = false;
  716.     private $logedin = false;
  717.     private $serviceContent;
  718.     private $strvSphereVersion = '4.1';
  719.     private $strVMwarevSphereURL;
  720.     private $strVMwarevSphereUsername;
  721.     private $strVMwarevSpherePassword;
  722.     private $strErrorMessage;
  723.     private $aryErrorMessageDetails;
  724.  
  725.     public function setDebug($debug)
  726.     {
  727.         $this->debug = $debug;
  728.     }
  729.  
  730.     public function VMwareAPI($strSetVMwarevSphereURL, $strSetVMwarevSphereUsername, $strSetVMwarevSpherePassword)
  731.     {
  732.         $this->strVMwarevSphereURL = $strSetVMwarevSphereURL;
  733.         $this->strVMwarevSphereUsername = $strSetVMwarevSphereUsername;
  734.         $this->strVMwarevSpherePassword = $strSetVMwarevSpherePassword;
  735.         $this->myconnection = new nusoap_client($strSetVMwarevSphereURL);
  736.         $this->myconnection->soap_defencoding = 'UTF-8';
  737.         $this->namespace = 'urn:vim25';
  738.     }
  739.  
  740.     public function RetrieveServiceContent()
  741.     {
  742.         $soapmsg[this] = new soapval('_this', false, 'ServiceInstance', false, false, array('type' => 'ServiceInstance'));
  743.         $ret = $this->process('RetrieveServiceContent', $soapmsg);
  744.  
  745.         if ($ret) {
  746.             $this->session_result = $ret;
  747.             $this->servicestatus = true;
  748.         }
  749.     }
  750.  
  751.     public function process($call, $msg)
  752.     {
  753.         $result = $this->myconnection->call($call, $msg, $this->namespace, 'urn:vim25/' . $this->strvSphereVersion);
  754.         $this->debug('send', htmlspecialchars($this->myconnection->request, ENT_QUOTES));
  755.         $err = $call;
  756.         $this->debug('receive', $result);
  757.  
  758.         if ($err) {
  759.             $this->error($err, $result);
  760.             return false;
  761.         }
  762.  
  763.         return $result;
  764.     }
  765.  
  766.     public function Login()
  767.     {
  768.         $this->RetrieveServiceContent();
  769.  
  770.         if ($this->servicestatus) {
  771.             $soapmsg[this] = new soapval('_this', false, $this->session_result[sessionManager], false, false, array('type' => 'SessionManager'));
  772.             $soapmsg[userName] = $this->strVMwarevSphereUsername;
  773.             $soapmsg[password] = $this->strVMwarevSpherePassword;
  774.             $ret = this;
  775.  
  776.             if ($ret) {
  777.                 $this->logedin = true;
  778.             }
  779.  
  780.             $this->serviceContent = $this->session_result;
  781.             return true;
  782.         }
  783.  
  784.         return false;
  785.     }
  786.  
  787.     public function Logout()
  788.     {
  789.         if ($this->logedin == true) {
  790.             unset($soapmsg);
  791.             $soapmsg[this] = new soapval('_this', false, $this->serviceContent[sessionManager], false, false, array('type' => 'SessionManager'));
  792.             return $this->process('Logout', $soapmsg);
  793.         }
  794.     }
  795.  
  796.     public function error($err, $result)
  797.     {
  798.         if ($this->debug) {
  799.             $this->debug('error', 'We got a error!:' . $err);
  800.             return NULL;
  801.         }
  802.  
  803.         $this->strErrorMessage = $err;
  804.         $this->aryErrorMessageDetails = $result;
  805.     }
  806.  
  807.     public function GetErrorMessageString()
  808.     {
  809.         return $this->strErrorMessage;
  810.     }
  811.  
  812.     public function GetErrorMessageDetails()
  813.     {
  814.         return $this->aryErrorMessageDetails;
  815.     }
  816.  
  817.     public function debug($type, $result)
  818.     {
  819.         if ($this->debug) {
  820.             print('<b>' . $type . '</b><pre>');
  821.             print_r($result);
  822.             print('</pre>===========================<p>');
  823.         }
  824.     }
  825.  
  826.     public function RetrieveTaskInfo($strTaskID, $type, $path)
  827.     {
  828.         unset($soapmsg);
  829.         $soapmsg[this] = new soapval('_this', false, $this->session_result[propertyCollector], false, false, array('type' => 'PropertyCollector'));
  830.         $soapmsg[specSet][propSet][type] = $type;
  831.         $soapmsg[specSet][propSet][pathSet] = $path;
  832.         $soapmsg[specSet][objectSet][obj] = new soapval('obj', false, $strTaskID, false, false, array('type' => 'Task'));
  833.         $ret = specSet;
  834.         return $ret;
  835.     }
  836.  
  837.     public function RetrievePropertiesVM($vm, $type, $path)
  838.     {
  839.         $soapmsg[this] = new soapval('_this', false, $this->session_result[propertyCollector], false, false, array('type' => 'PropertyCollector'));
  840.         $soapmsg[specSet][propSet][type] = $type;
  841.         $soapmsg[specSet][propSet][pathSet] = $path;
  842.         $soapmsg[specSet][objectSet][obj] = new soapval('obj', false, $vm, false, false, array('type' => 'VirtualMachine'));
  843.         $ret = obj;
  844.         return $ret;
  845.     }
  846.  
  847.     public function StopVM($vm)
  848.     {
  849.         $soapVal = array('type' => 'VirtualMachine');
  850.         $soapmsg[this] = $soapVal;
  851.         $strTaskID = new soapval('_this', false, $vm, false, false, array('type' => 'VirtualMachine'));
  852.         return $strTaskID;
  853.     }
  854.  
  855.     public function StartVM($vm)
  856.     {
  857.         $soapVal = array('type' => 'VirtualMachine');
  858.         $soapmsg[this] = $soapVal;
  859.         $strTaskID = new soapval('_this', false, $vm, false, false, array('type' => 'VirtualMachine'));
  860.         return $strTaskID;
  861.     }
  862.  
  863.     public function ResetVM($vm)
  864.     {
  865.         $soapVal = array('type' => 'VirtualMachine');
  866.         $soapmsg[this] = $soapVal;
  867.         $strTaskID = new soapval('_this', false, $vm, false, false, array('type' => 'VirtualMachine'));
  868.         return $strTaskID;
  869.     }
  870.  
  871.     public function RebootVMGuest($vm)
  872.     {
  873.         $soapVal = array('type' => 'VirtualMachine');
  874.         $soapmsg[this] = $soapVal;
  875.         $strNull = $this->process('RebootGuest', $soapmsg);
  876.         return '';
  877.     }
  878.  
  879.     public function ShutdownVMGuest($vm)
  880.     {
  881.         $soapVal = array('type' => 'VirtualMachine');
  882.         $soapmsg[this] = $soapVal;
  883.         $strNull = $this->process('ShutdownGuest', $soapmsg);
  884.         return '';
  885.     }
  886.  
  887.     public function MountVMwareTools($vm)
  888.     {
  889.         $soapVal = array('type' => 'VirtualMachine');
  890.         $soapmsg[this] = $soapVal;
  891.         $strNull = $this->process('MountToolsInstaller', $soapmsg);
  892.         return '';
  893.     }
  894.  
  895.     public function UnMountVMwareTools($vm)
  896.     {
  897.         $soapVal = array('type' => 'VirtualMachine');
  898.         $soapmsg[this] = $soapVal;
  899.         $strNull = $this->process('UnmountToolsInstaller', $soapmsg);
  900.         return '';
  901.     }
  902.  
  903.     public function UpgradeVMwareTools($vm)
  904.     {
  905.         $soapVal = array('type' => 'VirtualMachine');
  906.         $soapmsg[this] = $soapVal;
  907.         $strNull = $this->process('UpgradeTools_Task', $soapmsg);
  908.         return '';
  909.     }
  910.  
  911.     public function CreateVMSnapshot($vm, $SnapShotName, $SnapShotDescription)
  912.     {
  913.         $soapVal = array('type' => 'VirtualMachine');
  914.         $soapmsg[this] = $soapVal;
  915.         $soapmsg[name] = $SnapShotName;
  916.         $soapmsg[description] = $SnapShotDescription;
  917.         $soapmsg[memory] = false;
  918.         $soapmsg[quiesce] = true;
  919.         $strNull = $this->process('CreateSnapshot_Task', $soapmsg);
  920.         return '';
  921.     }
  922.  
  923.     public function GetAvailableTimeZones()
  924.     {
  925.         $soapmsg[this] = new soapval('_this', false, $this->session_result[propertyCollector], false, false, array('type' => 'PropertyCollector'));
  926.         return $this->process('QueryAvailableTimeZones', $soapmsg);
  927.     }
  928.  
  929.     public function GetNetworkStats($vm, $strNetworkAdapterToGetStatsOn)
  930.     {
  931.         $strStartTime = '2012-02-16 10:56:05';
  932.         $strEndTime = '2012-02-16 10:56:20';
  933.         $intIntervalID = 538;
  934.         $intNetworkCardID = '';
  935.         $vmHardwareDetail = $this->RetrievePropertiesVM($vm, 'VirtualMachine', 'config.hardware');
  936.  
  937.         if (isset($vmHardwareDetail['propSet']['val']['device'])) {
  938.             $aryVMHardwareDevices = $vmHardwareDetail['propSet']['val']['device'];
  939.  
  940.             if (is_array($aryVMHardwareDevices)) {
  941.                 $intNetworkCardID = $vmDevice['key'];
  942.                 break;
  943.             }
  944.         }
  945.  
  946.         $intCounterAvailable = 518;
  947.         $intCounterID = $this->GetPerfCounterID('net', 'transmitted', 'average', 2);
  948.         unset($soapmsg);
  949.         $soapmsg[this] = new soapval('_this', false, $this->session_result[perfManager], false, false, array('type' => 'PerformanceManager'));
  950.         $soapmsg[entity] = new soapval('entity', 'ManagedObjectReference', $vm, false, false, array('type' => 'VirtualMachine'));
  951.         $soapmsg[beginTime] = new soapval('beginTime', 'dateTime', timestamp_to_iso8601(strtotime($strStartTime)), false, 'http://www.w3.org/2001/XMLSchema');
  952.         $soapmsg[endTime] = new soapval('endTime', 'dateTime', timestamp_to_iso8601(strtotime($strEndTime)), false, 'http://www.w3.org/2001/XMLSchema');
  953.         $soapmsg[intervalId] = $intIntervalID;
  954.         $aryAvailableCounters = $this->process('QueryAvailablePerfMetric', $soapmsg);
  955.  
  956.         $intCounterAvailable = 519;
  957.         break;
  958.  
  959.         if ($intCounterAvailable == 1) {
  960.             if ($intNetworkCardID != '') {
  961.                 unset($soapmsg);
  962.                 $soapmsg[this] = new soapval('_this', false, $this->session_result[perfManager], false, false, array('type' => 'PerformanceManager'));
  963.                 $querySpec[entity] = new soapval('entity', false, $vm, false, false, array('type' => 'VirtualMachine'));
  964.                 $querySpec[endTime] = new soapval('endTime', 'dateTime', timestamp_to_iso8601(strtotime($strEndTime)), false, 'http://www.w3.org/2001/XMLSchema');
  965.                 $querySpec[intervalId] = $intIntervalID;
  966.                 $metricID[counterId] = (int) $intCounterID;
  967.                 $metricID[instance] = $intNetworkCardID;
  968.                 $querySpec[metricId] = new soapval('metricId', false, $metricID, false, false, array('type' => 'PerfMetricId'));
  969.                 $querySpec[format] = 'csv';
  970.                 $soapmsg[querySpec] = new soapval('querySpec', false, $querySpec, false, false, array('type' => 'PerfQuerySpec'));
  971.                 $aryData = $strEndTime;
  972.                 return $aryData;
  973.             }
  974.         }
  975.  
  976.         return '';
  977.     }
  978.  
  979.     public function GetPerfCounterID($groupKey, $nameKey, $rollupType, $intCounterLevel = 1, $blnReturnAllDataInsteadOfCounterID = false)
  980.     {
  981.         unset($soapmsg);
  982.         $soapmsg[this] = new soapval('_this', false, $this->session_result[perfManager], false, false, array('type' => 'PerformanceManager'));
  983.         $soapmsg[level] = $intCounterLevel;
  984.         $aryCountersData = $this->process('QueryPerfCounterByLevel', $soapmsg);
  985.  
  986.         foreach ($aryCountersData as $CounterData) {
  987.             if (strtolower($CounterData['nameInfo']['key']) == strtolower($nameKey)) {
  988.                 if (strtolower($CounterData['groupInfo']['key']) == strtolower($groupKey)) {
  989.                     if ($rollupType == '') {
  990.                         if ($blnReturnAllDataInsteadOfCounterID == false) {
  991.                             return $CounterData['key'];
  992.                         }
  993.  
  994.                         return $CounterData;
  995.                     }
  996.  
  997.                     if ($CounterData['rollupType'] == $rollupType) {
  998.                         if ($blnReturnAllDataInsteadOfCounterID == false) {
  999.                             return $CounterData['key'];
  1000.                         }
  1001.  
  1002.                         return $CounterData;
  1003.                     }
  1004.                 }
  1005.             }
  1006.         }
  1007.     }
  1008.  
  1009.     public function FindVMByName($vmName)
  1010.     {
  1011.         $soapVal = array('type' => 'PropertyCollector');
  1012.         $soapmsg[this] = $soapVal;
  1013.         $soapmsg[specSet][propSet][type] = 'Folder';
  1014.         $soapmsg[specSet][propSet][pathSet] = 'childEntity';
  1015.         $soapmsg[specSet][objectSet][obj] = new soapval('obj', false, $this->session_result[rootFolder], false, false, array('type' => 'Folder'));
  1016.         $soapmsg[specSet][objectSet][skip] = false;
  1017.         $temp = propSet;
  1018.         $dataCenter = $soapmsg[specSet][objectSet][obj];
  1019.         $intDataCenterFound = 639;
  1020.         if (is_array($dataCenter) && (0 < strpos($vmName, '\\'))) {
  1021.             $aryFolderVMData = explode('\\', $vmName);
  1022.             $intArrayLen = count($aryFolderVMData) - 1;
  1023.             $FindDataCenterName = false;
  1024.  
  1025.             unset($temp);
  1026.             unset($soapmsg);
  1027.             $soapmsg[this] = $soapVal;
  1028.             $soapmsg[specSet][propSet][type] = 'Datacenter';
  1029.             $soapmsg[specSet][propSet][pathSet] = 'name';
  1030.             $soapmsg[specSet][objectSet][obj] = new soapval('obj', false, $dataCenterObj, false, false, array('type' => 'Datacenter'));
  1031.             $soapmsg[specSet][objectSet][skip] = false;
  1032.             $temp = specSet;
  1033.             $dataCenterName = ($soapmsg[specSet][objectSet][obj]);
  1034.             $dataCenter = new soapval('obj', false, $dataCenterObj, false, false, array('type' => 'Datacenter'));
  1035.             $intDataCenterFound = 640;
  1036.             break;
  1037.         }
  1038.  
  1039.         unset($temp);
  1040.         unset($soapmsg);
  1041.         $soapmsg[this] = $soapVal;
  1042.         $soapmsg[specSet][propSet][type] = 'Datacenter';
  1043.         $soapmsg[specSet][propSet][pathSet] = 'vmFolder';
  1044.         $soapmsg[specSet][objectSet][obj] = new soapval('obj', false, $dataCenter, false, false, array('type' => 'Datacenter'));
  1045.         $soapmsg[specSet][objectSet][skip] = false;
  1046.         $temp = specSet;
  1047.         $vmFolder = ($soapmsg[specSet][objectSet][obj]);
  1048.  
  1049.         if (0 < strpos($vmName, '\\')) {
  1050.             $aryFolderVMData = soapval;
  1051.             $intArrayLen = count($aryFolderVMData) - 1;
  1052.             $vmName = specSet;
  1053.             $i = $soapmsg[specSet][objectSet][skip];
  1054.  
  1055.             while ($i < $intArrayLen) {
  1056.                 $strFolderName = $vmFolder;
  1057.                 unset($soapmsg);
  1058.                 $soapmsg[this] = new soapval('_this', false, $this->session_result[searchIndex], false, false, array('type' => 'SearchIndex'));
  1059.                 $soapmsg[entity] = new soapval('entity', false, $vmFolder, false, false, array('type' => 'Folder'));
  1060.                 $soapmsg[name] = $strFolderName;
  1061.                 $vmFolder = $this->process('FindChild', $soapmsg);
  1062.                 ++$i;
  1063.             }
  1064.         }
  1065.  
  1066.         unset($soapmsg);
  1067.         $soapmsg[this] = new soapval('_this', false, $this->session_result[searchIndex], false, false, array('type' => 'SearchIndex'));
  1068.         $soapmsg[entity] = new soapval('entity', false, $vmFolder, false, false, array('type' => 'Folder'));
  1069.         $soapmsg[name] = trim($vmName);
  1070.         $result = ($soapmsg[this]);
  1071.         return $result;
  1072.     }
  1073.  
  1074.     public function AutoProvisionVM($vmName, $strNewVMName, $strDataStoreNameForNewVM, $strResoucePoolNameForNewVM, $strOSPassword, $strServerHostName, $strServerDomainName, $strIPAddress, $strDNSServersCommaDelimited, $strSubnetMask, $strGateway, $strTemplatePassword, $intRAMAmountInGB, $intCPUAmount, $strTimeZone, $blnHWClockUTC = false, $strVMNotes = '')
  1075.     {
  1076.         $soapVal = array('type' => 'PropertyCollector');
  1077.         $soapmsg[this] = $soapVal;
  1078.         $soapmsg[specSet][propSet][type] = 'Folder';
  1079.         $soapmsg[specSet][propSet][pathSet] = 'childEntity';
  1080.         $soapmsg[specSet][objectSet][obj] = new soapval('obj', false, $this->session_result[rootFolder], false, false, array('type' => 'Folder'));
  1081.         $soapmsg[specSet][objectSet][skip] = false;
  1082.         $temp = $this->process('RetrieveProperties', $soapmsg);
  1083.         $dataCenter = $temp[propSet][val][ManagedObjectReference];
  1084.         $intDataCenterFound = 1508;
  1085.         if (is_array($dataCenter) && (0 < strpos($vmName, '\\'))) {
  1086.             $aryFolderVMData = explode('\\', $vmName);
  1087.             $intArrayLen = count($aryFolderVMData) - 1;
  1088.             $FindDataCenterName = $aryFolderVMData[0];
  1089.  
  1090.             unset($temp);
  1091.             unset($soapmsg);
  1092.             $soapmsg[this] = $soapVal;
  1093.             $soapmsg[specSet][propSet][type] = 'Datacenter';
  1094.             $soapmsg[specSet][propSet][pathSet] = 'name';
  1095.             $soapmsg[specSet][objectSet][obj] = new soapval('obj', false, $dataCenterObj, false, false, array('type' => 'Datacenter'));
  1096.             $soapmsg[specSet][objectSet][skip] = false;
  1097.             $temp = $this->process('RetrieveProperties', $soapmsg);
  1098.             $dataCenterName = $temp[propSet][val];
  1099.             $dataCenter = $dataCenterObj;
  1100.             $intDataCenterFound = 1509;
  1101.             break;
  1102.         }
  1103.  
  1104.         unset($temp);
  1105.         unset($soapmsg);
  1106.         $soapmsg[this] = $soapVal;
  1107.         $soapmsg[specSet][propSet][type] = 'Datacenter';
  1108.         $soapmsg[specSet][propSet][pathSet] = 'vmFolder';
  1109.         $soapmsg[specSet][objectSet][obj] = new soapval('obj', false, $dataCenter, false, false, array('type' => 'Datacenter'));
  1110.         $soapmsg[specSet][objectSet][skip] = false;
  1111.         $temp = $this->process('RetrieveProperties', $soapmsg);
  1112.         $vmFolder = $temp[propSet][val];
  1113.         unset($temp);
  1114.         unset($soapmsg);
  1115.         $vmNewFolder = $vmFolder;
  1116.  
  1117.         if (0 < strpos($strNewVMName, '\\')) {
  1118.             $aryNewFolderVMData = explode('\\', $strNewVMName);
  1119.             $intNewArrayLen = count($aryNewFolderVMData) - 1;
  1120.             $vmNewName = $aryNewFolderVMData[$intNewArrayLen];
  1121.             $i = $intDataCenterFound;
  1122.  
  1123.             while ($i < $intNewArrayLen) {
  1124.                 $strNewFolderName = $aryNewFolderVMData[$i];
  1125.                 unset($soapmsg);
  1126.                 $soapmsg[this] = new soapval('_this', false, $this->session_result[searchIndex], false, false, array('type' => 'SearchIndex'));
  1127.                 $soapmsg[entity] = new soapval('entity', false, $vmNewFolder, false, false, array('type' => 'Folder'));
  1128.                 $soapmsg[name] = $strNewFolderName;
  1129.                 $vmNewFolder = $this->process('FindChild', $soapmsg);
  1130.                 ++$i;
  1131.             }
  1132.         }
  1133.         else {
  1134.             $vmNewName = $strNewVMName;
  1135.         }
  1136.  
  1137.         if (0 < strpos($vmName, '\\')) {
  1138.             $aryFolderVMData = explode('\\', $vmName);
  1139.             $intArrayLen = count($aryFolderVMData) - 1;
  1140.             $vmName = $aryFolderVMData[$intArrayLen];
  1141.             $i = $intDataCenterFound;
  1142.  
  1143.             while ($i < $intArrayLen) {
  1144.                 $strFolderName = $aryFolderVMData[$i];
  1145.                 unset($soapmsg);
  1146.                 $soapmsg[this] = new soapval('_this', false, $this->session_result[searchIndex], false, false, array('type' => 'SearchIndex'));
  1147.                 $soapmsg[entity] = new soapval('entity', false, $vmFolder, false, false, array('type' => 'Folder'));
  1148.                 $soapmsg[name] = $strFolderName;
  1149.                 $vmFolder = $this->process('FindChild', $soapmsg);
  1150.                 ++$i;
  1151.             }
  1152.         }
  1153.  
  1154.         unset($soapmsg);
  1155.         $soapmsg[this] = new soapval('_this', false, $this->session_result[searchIndex], false, false, array('type' => 'SearchIndex'));
  1156.         $soapmsg[entity] = new soapval('entity', false, $vmFolder, false, false, array('type' => 'Folder'));
  1157.         $soapmsg[name] = trim($vmName);
  1158.         $strVMID = $this->process('FindChild', $soapmsg);
  1159.         unset($temp);
  1160.         unset($soapmsg);
  1161.         $soapmsg[this] = $soapVal;
  1162.         $soapmsg[specSet][propSet][type] = 'Datacenter';
  1163.         $soapmsg[specSet][propSet][pathSet] = 'hostFolder';
  1164.         $soapmsg[specSet][objectSet][obj] = new soapval('obj', false, $dataCenter, false, false, array('type' => 'Datacenter'));
  1165.         $soapmsg[specSet][objectSet][skip] = false;
  1166.         $temp = propSet;
  1167.         $vmHostFolder = $soapmsg[specSet][propSet][pathSet];
  1168.         unset($temp);
  1169.         unset($soapmsg);
  1170.         $soapmsg[this] = $soapVal;
  1171.         $soapmsg[specSet][propSet][type] = 'Folder';
  1172.         $soapmsg[specSet][propSet][pathSet] = 'childEntity';
  1173.         $soapmsg[specSet][objectSet][obj] = new soapval('obj', false, $vmHostFolder, false, false, array('type' => 'Folder'));
  1174.         $soapmsg[specSet][objectSet][skip] = false;
  1175.         $temp = strpos($vmName, '\\');
  1176.         $hostChildEntity = count($aryFolderVMData) - 1;
  1177.         unset($temp);
  1178.         unset($soapmsg);
  1179.         $soapmsg[this] = $soapVal;
  1180.         $soapmsg[specSet][propSet][type] = 'ComputeResource';
  1181.         $soapmsg[specSet][propSet][pathSet] = 'resourcePool';
  1182.         $soapmsg[specSet][objectSet][obj] = new soapval('obj', false, $hostChildEntity, false, false, array('type' => 'ComputeResource'));
  1183.         $soapmsg[specSet][objectSet][skip] = false;
  1184.         $temp = $soapmsg[specSet][objectSet][skip];
  1185.         $FoundResoucePoolMOR = $temp;
  1186.  
  1187.         if ($strResoucePoolNameForNewVM != '') {
  1188.             unset($soapmsg);
  1189.             $soapmsg[this] = new soapval('_this', false, $this->session_result[searchIndex], false, false, array('type' => 'SearchIndex'));
  1190.             $soapmsg[entity] = new soapval('entity', false, $FoundResoucePoolMOR, false, false, array('type' => 'ResourcePool'));
  1191.             $soapmsg[name] = $strResoucePoolNameForNewVM;
  1192.             $FoundResoucePoolMOR = $soapmsg[specSet][propSet][pathSet];
  1193.         }
  1194.  
  1195.         if (!empty($strDataStoreNameForNewVM)) {
  1196.             unset($temp);
  1197.             unset($soapmsg);
  1198.             $soapmsg[this] = $soapVal;
  1199.             $soapmsg[specSet][propSet][type] = 'Datacenter';
  1200.             $soapmsg[specSet][propSet][pathSet] = 'datastore';
  1201.             $soapmsg[specSet][objectSet][obj] = new soapval('obj', false, $dataCenter, false, false, array('type' => 'Datacenter'));
  1202.             $soapmsg[specSet][objectSet][skip] = false;
  1203.             $temp = $intNewArrayLen;
  1204.             $Datastores = $temp[propSet][val][ManagedObjectReference];
  1205.             $DatastoreToCloneTo = '';
  1206.  
  1207.             unset($soapmsg);
  1208.             $soapmsg[this] = new soapval('_this', false, $this->session_result[propertyCollector], false, false, array('type' => 'PropertyCollector'));
  1209.             $soapmsg[specSet][propSet][type] = 'Datastore';
  1210.             $soapmsg[specSet][propSet][pathSet] = 'info';
  1211.             $soapmsg[specSet][objectSet][obj] = new soapval('obj', false, $Datastore, false, false, array('type' => 'Datastore'));
  1212.             $ret = $this->process('RetrieveProperties', $soapmsg);
  1213.             $DatastoreToCloneTo = $i;
  1214.             break;
  1215.  
  1216.             if (empty($DatastoreToCloneTo)) {
  1217.                 $this->error('VMware Datastore specified not found', array());
  1218.                 return false;
  1219.             }
  1220.         }
  1221.  
  1222.         $vmDetail = $this->RetrievePropertiesVM($strVMID, 'VirtualMachine', 'guest.guestFullName');
  1223.         $strGuestName = new soapval('_this', false, $this->session_result[searchIndex], false, false, array('type' => 'SearchIndex'));
  1224.  
  1225.         if (0 < strpos(strtolower($strGuestName), 'windows')) {
  1226.             $intOSType = 1509;
  1227.         }
  1228.         else {
  1229.             $intOSType = 1510;
  1230.         }
  1231.  
  1232.         unset($temp);
  1233.         unset($soapmsg);
  1234.         $soapmsg[this] = new soapval('_this', false, $strVMID, false, false, array('type' => 'VirtualMachine'));
  1235.         $soapmsg[folder] = new soapval('folder', false, $vmNewFolder, false, false, array('type' => 'Folder'));
  1236.         $soapmsg[name] = $vmNewName;
  1237.  
  1238.         if (!empty($strDataStoreNameForNewVM)) {
  1239.             if (!empty($DatastoreToCloneTo)) {
  1240.                 $location[datastore] = new soapval('datastore', false, $DatastoreToCloneTo, false, false, array('type' => 'Datastore'));
  1241.             }
  1242.         }
  1243.  
  1244.         $location[pool] = new soapval('pool', false, $FoundResoucePoolMOR, false, false, array('type' => 'ResourcePool'));
  1245.         $location[transform] = new soapval('transform', false, 'sparse', false, false, array('type' => 'VirtualMachineRelocateTransformation'));
  1246.         $spec[location] = new soapval('location', false, $location, false, false, array('xsi:type' => 'VirtualMachineRelocateSpec'));
  1247.         $spec[template] = false;
  1248.         $intRAMAmountInGB = $intRAMAmountInGB * 1024;
  1249.         $VMConfig[memoryMB] = $intRAMAmountInGB;
  1250.         $VMConfig[numCPUs] = $intCPUAmount;
  1251.  
  1252.         if ($strVMNotes != '') {
  1253.             $vmConfig[annotation] = $strVMNotes;
  1254.         }
  1255.  
  1256.         $spec[config] = new soapval('config', false, $VMConfig, false, false, array('xsi:type' => 'VirtualMachineConfigSpec'));
  1257.         $spec[customization] = $this->generateSpec($intOSType, $strOSPassword, $strServerHostName, $strServerDomainName, $strIPAddress, $strDNSServersCommaDelimited, $strSubnetMask, $strGateway, $strTimeZone, $blnHWClockUTC);
  1258.         $spec[powerOn] = true;
  1259.         $soapmsg[spec] = new soapval('spec', false, $spec, false, false, array('xsi:type' => 'VirtualMachineCloneSpec'));
  1260.         $TaskID = array('type' => 'Folder');
  1261.         return $TaskID;
  1262.     }
  1263.  
  1264.     public function generateSpec($intOSType, $strOSPassword, $strServerHostName, $strServerDomainName, $strIPAddress, $strDNSServersCommaDelimited, $strSubnetMask, $strGateway, $strTimeZone, $blnHWClockUTC = false, $strEncryptionKey = '')
  1265.     {
  1266.         if ($intOSType == 1) {
  1267.             $winOptions[changeSID] = true;
  1268.             $winOptions[deleteAccounts] = false;
  1269.             $spec[options] = new soapval('options', false, $winOptions, false, false, array('xsi:type' => 'CustomizationWinOptions'));
  1270.             $password[value] = $strOSPassword;
  1271.             $password[plainText] = true;
  1272.             $guiUnattended[password] = $password;
  1273.             $guiUnattended[timeZone] = 20;
  1274.             $guiUnattended[autoLogon] = true;
  1275.             $guiUnattended[autoLogonCount] = 1;
  1276.             $identity[guiUnattended] = new soapval('guiUnattended', false, $guiUnattended, false, false, array('xsi:type' => 'CustomizationGuiUnattended'));
  1277.             $userData[fullName] = 'User';
  1278.             $userData[orgName] = 'User';
  1279.             $computerName[name] = $strServerHostName;
  1280.             $userData[computerName] = new soapval('computerName', false, $computerName, false, false, array('xsi:type' => 'CustomizationFixedName'));
  1281.             $identity[userData] = new soapval('userData', false, $userData, false, false, array('xsi:type' => 'CustomizationUserData'));
  1282.             $ip[ipAddress] = $strIPAddress;
  1283.             $adapter[ip] = new soapval('ip', false, $ip, false, false, array('xsi:type' => 'CustomizationFixedIp'));
  1284.             $adapter[subnetMask] = $strSubnetMask;
  1285.             $adapter[dnsServerList] = substr($strDNSServersCommaDelimited, 0, strpos($strDNSServersCommaDelimited, ','));
  1286.             $adapter[gateway] = $strGateway;
  1287.             $nicSettingMap[adapter] = new soapval('adapter', false, $adapter, false, false, array('xsi:type' => 'CustomizationIPSettings'));
  1288.             $spec[nicSettingMap] = new soapval('nicSettingMap', false, $nicSettingMap, false, false, array('xsi:type' => 'CustomizationAdapterMapping'));
  1289.         }
  1290.         else if ($intOSType == 2) {
  1291.             $ServerHostName[name] = $strServerHostName;
  1292.             $identity[hostName] = new soapval('hostName', false, $ServerHostName, false, false, array('xsi:type' => 'CustomizationFixedName'));
  1293.             $identity[domain] = $strServerDomainName;
  1294.             $identity[timeZone] = $strTimeZone;
  1295.  
  1296.             if (!isset($blnHWClockUTC)) {
  1297.                 $blnHWClockUTC = false;
  1298.             }
  1299.  
  1300.             $identity[hwClockUTC] = $blnHWClockUTC;
  1301.             $spec[identity] = new soapval('identity', false, $identity, false, false, array('xsi:type' => 'CustomizationLinuxPrep'));
  1302.             $aryDNSServerIPs = array();
  1303.  
  1304.             if (0 < strpos($strDNSServersCommaDelimited, ',')) {
  1305.                 $aryDNSServerList = explode(',', $strDNSServersCommaDelimited);
  1306.  
  1307.                 foreach ($aryDNSServerList as $strDNSServerIP) {
  1308.                     $aryDNSServerIPs[] = $strDNSServerIP;
  1309.                 }
  1310.             }
  1311.             else {
  1312.                 $aryDNSServerIPs[] = $strDNSServersCommaDelimited;
  1313.             }
  1314.  
  1315.             $globalIPSettings[dnsServerList] = new soapval('dnsServerList', 'xsd:string', $aryDNSServerIPs, false, false, false);
  1316.             $globalIPSettings[dnsSuffixList] = new soapval('dnsSuffixList', 'xsd:string', array($strServerDomainName), false, false, false);
  1317.             $spec[globalIPSettings] = new soapval('globalIPSettings', false, $globalIPSettings, false, false, array('xsi:type' => 'CustomizationGlobalIPSettings'));
  1318.             $ip[ipAddress] = $strIPAddress;
  1319.             $adapter[ip] = new soapval('ip', false, $ip, false, false, array('xsi:type' => 'CustomizationFixedIp'));
  1320.             $adapter[subnetMask] = $strSubnetMask;
  1321.             $adapter[gateway] = $strGateway;
  1322.             $adapter[dnsDomain] = $strServerDomainName;
  1323.             $adapter[dnsServerList] = substr($strDNSServersCommaDelimited, 0, strpos($strDNSServersCommaDelimited, ','));
  1324.             $nicSettingMap[adapter] = new soapval('adapter', false, $adapter, false, false, array('xsi:type' => 'CustomizationIPSettings'));
  1325.             $spec[nicSettingMap] = new soapval('nicSettingMap', false, $nicSettingMap, false, false, array('xsi:type' => 'CustomizationAdapterMapping'));
  1326.         }
  1327.  
  1328.         return new soapval('customization', false, $spec, false, false, array('xsi:type' => 'CustomizationSpec'));
  1329.     }
  1330. }
  1331.  
  1332. function aisovmwarededsrv_ConfigOptions()
  1333. {
  1334.     $configarray = array(
  1335.         'Disk Space'                   => array('Type' => 'text', 'Size' => '7', 'Description' => 'Disk Space In GB'),
  1336.         'Bandwidth'                    => array('Type' => 'text', 'Size' => '7', 'Description' => 'Bandwidth In Mbps/GB'),
  1337.         'vCPU Amount'                  => array('Type' => 'text', 'Size' => '2', 'Description' => 'vCPU Amount'),
  1338.         'vRAM'                         => array('Type' => 'text', 'Size' => '6', 'Description' => 'RAM In GB'),
  1339.         'AutoProvision Folder'         => array('Type' => 'text', 'Size' => '15', 'Description' => 'Name'),
  1340.         'AutoProvision Resource Pool'  => array('Type' => 'text', 'Size' => '15', 'Description' => 'Name'),
  1341.         'AutoProvision Time zone'      => array('Type' => 'text', 'Size' => '15', 'Description' => 'Timezone'),
  1342.         'AutoProvision HW Use UTC'     => array('Type' => 'yesno', 'Size' => '1', 'Description' => 'Check to enable'),
  1343.         'AutoProvision Datastore'      => array('Type' => 'text', 'Size' => '15', 'Description' => 'Name'),
  1344.         'AutoProvision Email Template' => array('Type' => 'text', 'Size' => '15', 'Description' => 'Name')
  1345.         );
  1346.     return $configarray;
  1347. }
  1348.  
  1349. function aisovmwarededsrv_UsageUpdate($params)
  1350. {
  1351.     $myFile = dirname(__FILE__) . '/UsageUpdate.txt';
  1352. }
  1353.  
  1354. function aisovmwarededsrv_UpdateUsage($params)
  1355. {
  1356.     $myFile = dirname(__FILE__) . '/UpdateUsage.txt';
  1357. }
  1358.  
  1359. function aisovmwarededsrv_CreateAccount($params)
  1360. {
  1361.     if ($GLOBALS['license'] == 'Dev-7bdd6a5ed79a8a14af40') {
  1362.         $blnAKDLS = true;
  1363.     }
  1364.     else if ($GLOBALS['license'] == 'Leased-abc367f314a7142c44fd') {
  1365.         $blnAKDLS = true;
  1366.     }
  1367.     else {
  1368.         $blnAKDLS = false;
  1369.     }
  1370.  
  1371.     if ($blnAKDLS == false) {
  1372.         return 'success';
  1373.     }
  1374.  
  1375.     global $mstrConfigOptionDiskSpace;
  1376.     global $mstrConfigOptionBandwidth;
  1377.     global $mstrConfigOptionCPUAmount;
  1378.     global $mstrConfigOptionRAM;
  1379.     global $mstrUserConfigOptionsExtraDiskSpace;
  1380.     global $gstrVMwareDataStoreNameForNewVMs;
  1381.     global $mstrConfigOptionAutoProvisionDatastore;
  1382.     global $mstrUserConfigOptionsExtraCPU;
  1383.     global $mstrUserConfigOptionsExtraRAM;
  1384.     global $mstrUserConfigOptionsServerOS;
  1385.     global $mstrUserConfigOptionsInstallingCPanel;
  1386.     global $mstrUserConfigOptionsExtraBandwidth;
  1387.     global $garyVMwareServerOSToTemplateMapping;
  1388.     global $mstrConfigOptionAutoProvisionFolder;
  1389.     global $mstrConfigOptionAutoProvisionResourcePool;
  1390.     global $mstrConfigOptionAutoProvisionTimezone;
  1391.     global $mstrConfigOptionAutoProvisionHWUseUTC;
  1392.     $serviceid = $params['serviceid'];
  1393.     $productid = $params['pid'];
  1394.     $table = 'tblhosting';
  1395.     $fields = 'userid';
  1396.     $where = array('id' => $serviceid);
  1397.     $result = select_query($table, $fields, $where, $sort, $sortorder, $limits, $join);
  1398.     $useridsearch = mysql_fetch_array($result);
  1399.     $userid = $useridsearch[0];
  1400.     $intDiskSpaceInGB = $params[$mstrConfigOptionDiskSpace];
  1401.     $intBandwidth = $params[$mstrConfigOptionBandwidth];
  1402.     $intCPUAmount = $params[$mstrConfigOptionCPUAmount];
  1403.     $intRAMAmountInGB = $params[$mstrConfigOptionRAM];
  1404.     $strServerOS = $params['configoptions'][$mstrUserConfigOptionsServerOS];
  1405.     $intCPanelInstall = $params['configoptions'][$mstrUserConfigOptionsInstallingCPanel];
  1406.     $intExtraRAMInGB = $params['configoptions'][$mstrUserConfigOptionsExtraRAM];
  1407.     $intExtraCPUs = $params['configoptions'][$mstrUserConfigOptionsExtraCPU];
  1408.     $intExtraDiskSpaceInGB = $params['configoptions'][$mstrUserConfigOptionsExtraDiskSpace];
  1409.     $intExtraBandwidth = $params['configoptions'][$mstrUserConfigOptionsExtraBandwidth];
  1410.     $strPasswordToSet = $params['password'];
  1411.     $strHostName = ereg_replace('[^A-Za-z0-9\\_\\-]', '', $params['domain']);
  1412.     $strVMwarevSphereURL = $params['serverip'];
  1413.     $strVMwarevSphereUsername = $params['serverusername'];
  1414.     $strVMwarevSpherePassword = $params['serverpassword'];
  1415.  
  1416.     if (!empty($params['configoptions'][$mstrConfigOptionAutoProvisionDatastore])) {
  1417.         $strDataStoreNameForNewVM = $params['configoptions'][$mstrConfigOptionAutoProvisionDatastore];
  1418.     }
  1419.     else if (!empty($gstrVMwareDataStoreNameForNewVMs)) {
  1420.         $strDataStoreNameForNewVM = $gstrVMwareDataStoreNameForNewVMs;
  1421.     }
  1422.     else {
  1423.         $strDataStoreNameForNewVM = '';
  1424.     }
  1425.  
  1426.     $vmNameToClone = $garyVMwareServerOSToTemplateMapping[$strServerOS][0];
  1427.     $vmNameToClone .= '-' . $intDiskSpaceInGB;
  1428.     $strTemplateDefaultPassword = $garyVMwareServerOSToTemplateMapping[$strServerOS][2];
  1429.     $strNewVMFolder = $params['configoptions'][$mstrConfigOptionAutoProvisionFolder];
  1430.  
  1431.     if (0 < strlen($strNewVMFolder)) {
  1432.         if (substr($strNewVMFolder, -1) != '\\') {
  1433.             $strNewVMFolder = $strNewVMFolder . '\\';
  1434.         }
  1435.     }
  1436.  
  1437.     $strNewVMName = $strNewVMFolder . $userid . '-' . $serviceid . '-' . $strHostName;
  1438.     $intRAMAmountInGB = (int) $intRAMAmountInGB + (int) $intExtraRAMInGB;
  1439.     $intCPUAmount = (int) $intCPUAmount + (int) $intExtraCPUs;
  1440.     $strServerDomainName = 'aiso.net';
  1441.     $strIPAddress = '10.153.118.141';
  1442.     $strDNSServersCommaDelimited = '4.2.2.2,204.117.214.10';
  1443.     $strSubnetMask = '255.128.0.0';
  1444.     $strGateway = '10.128.0.1';
  1445.     $strResoucePoolNameForNewVM = $params['configoptions'][$mstrConfigOptionAutoProvisionResourcePool];
  1446.     $strTimeZone = $params['configoptions'][$mstrConfigOptionAutoProvisionTimezone];
  1447.  
  1448.     if (empty($strTimeZone)) {
  1449.         $strTimeZone = 'America/Los_Angeles';
  1450.     }
  1451.  
  1452.     if (empty($params['configoptions'][$mstrConfigOptionAutoProvisionHWUseUTC])) {
  1453.         $blnHWClockUTC = false;
  1454.     }
  1455.     else {
  1456.         $blnHWClockUTC = true;
  1457.     }
  1458.  
  1459.     $vm = $strVMwarevSpherePassword;
  1460.     $vm->setDebug(0);
  1461.     $vm->Login();
  1462.     $TaskID = $garyVMwareServerOSToTemplateMapping;
  1463.  
  1464.     if (!empty($TaskID)) {
  1465.         $table = 'tblcustomfields';
  1466.         $fields = 'id';
  1467.         $where = array('relid' => $productid);
  1468.         $result = select_query($table, $fields, $where, $sort, $sortorder, $limits, $join);
  1469.         $customfieldsearch = mysql_fetch_array($result);
  1470.         $customfieldid = $where;
  1471.  
  1472.         if (!empty($customfieldid)) {
  1473.             $table = 'tblcustomfieldsvalues';
  1474.             $fields = 'fieldid';
  1475.             $where = array('relid' => $serviceid, 'fieldid' => $customfieldid);
  1476.             $result = ($intBandwidth = $params[$mstrConfigOptionBandwidth]);
  1477.             $customfieldsearch = $intCPUAmount;
  1478.             $customfieldidfound = $customfieldsearch[0];
  1479.  
  1480.             if (empty($customfieldidfound)) {
  1481.                 $table = 'tblcustomfieldsvalues';
  1482.                 $array = array('relid' => $serviceid, 'fieldid' => $customfieldid, 'value' => $strNewVMName);
  1483.                 $params;
  1484.             }
  1485.             else {
  1486.                 $table = 'tblcustomfieldsvalues';
  1487.                 $array = array('value' => $strNewVMName);
  1488.                 $where = array('relid' => $serviceid, 'fieldid' => $customfieldidfound);
  1489.                 update_query($table, $array, $where);
  1490.             }
  1491.  
  1492.             $result = 'success';
  1493.         }
  1494.         else {
  1495.             $result = 'VMware AutoProvision Failed: Failed To Add New VM Name (' . $strNewVMName . ') To Service';
  1496.         }
  1497.     }
  1498.     else {
  1499.         $result = 'VMware AutoProvision Failed: ' . $vm->GetErrorMessageString();
  1500.     }
  1501.  
  1502.     $vm->Logout();
  1503.     return $result;
  1504. }
  1505.  
  1506. function aisovmwarededsrv_TerminateAccount($params)
  1507. {
  1508.     $successful = true;
  1509.  
  1510.     if ($successful) {
  1511.         $result = 'success';
  1512.     }
  1513.     else {
  1514.         $result = 'Error Message Goes Here...';
  1515.     }
  1516.  
  1517.     return $result;
  1518. }
  1519.  
  1520. function aisovmwarededsrv_SuspendAccount($params)
  1521. {
  1522.     global $mstrVMWareWebServerCustomFieldName;
  1523.     $strVMWareServerName = $params['customfields'][$mstrVMWareWebServerCustomFieldName];
  1524.  
  1525.     if (strlen($mstrVMWareWebServerCustomFieldName) < 1) {
  1526.         return 'Server Name Could Not Be Found';
  1527.     }
  1528.  
  1529.     $intServerID = $params['serverid'];
  1530.     $select_modules = 'SELECT type,ipaddress,username,password FROM tblservers WHERE id = ' . $intServerID;
  1531.     $modules_rows = full_query($select_modules);
  1532.  
  1533.     if ($modules_rows) {
  1534.         $aryRowData = mysql_fetch_row($modules_rows);
  1535.         $strModuleName = $aryRowData[0];
  1536.         $strVMwarevSphereURL = $aryRowData[1];
  1537.         $strVMwarevSphereUsername = $aryRowData[2];
  1538.         $strVMwarevSpherePassword = decrypt($aryRowData[3]);
  1539.     }
  1540.     else {
  1541.         return 'Server Info Could Not Be Found, please alert us of this issue';
  1542.     }
  1543.  
  1544.     $vm = $strVMwarevSpherePassword;
  1545.     $vm->setDebug(0);
  1546.     $vm->Login();
  1547.     $strVMID = $vm->FindVMByName($strVMWareServerName);
  1548.  
  1549.     if (0 < strpos($strVMID, 'error!!')) {
  1550.         if (strlen($strVMID) < 1) {
  1551.             $vm->Logout();
  1552.             return 'Server Info Could Not Be Retreived From VMware';
  1553.         }
  1554.     }
  1555.     else {
  1556.         $vm->Logout();
  1557.         return 'Server Info Could Not Be Retreived From VMware';
  1558.     }
  1559.  
  1560.     $vmDetail = $vm->RetrievePropertiesVM($strVMID, 'VirtualMachine', 'runtime.powerState');
  1561.     $strPowerState = $vmDetail['propSet']['val'];
  1562.  
  1563.     if (strtolower($strPowerState) == 'poweredon') {
  1564.         $vm->ShutdownVMGuest($strVMID);
  1565.         $successful = true;
  1566.     }
  1567.     else {
  1568.         $vm->Logout();
  1569.         return 'Server Could Not Be Powered Off Because It Is Already Off';
  1570.     }
  1571.  
  1572.     $vm->Logout();
  1573.  
  1574.     if ($successful) {
  1575.         $result = 'success';
  1576.     }
  1577.     else {
  1578.         $result = 'Coult Not Shutdown Guest For Some Reason';
  1579.     }
  1580.  
  1581.     return $result;
  1582. }
  1583.  
  1584. function aisovmwarededsrv_UnsuspendAccount($params)
  1585. {
  1586.     global $mstrVMWareWebServerCustomFieldName;
  1587.     $strVMWareServerName = $params['customfields'][$mstrVMWareWebServerCustomFieldName];
  1588.  
  1589.     if (strlen($mstrVMWareWebServerCustomFieldName) < 1) {
  1590.         return 'Server Name Could Not Be Found';
  1591.     }
  1592.  
  1593.     $intServerID = $params['serverid'];
  1594.     $select_modules = 'SELECT type,ipaddress,username,password FROM tblservers WHERE id = ' . $intServerID;
  1595.     $modules_rows = full_query($select_modules);
  1596.  
  1597.     if ($modules_rows) {
  1598.         $aryRowData = mysql_fetch_row($modules_rows);
  1599.         $strModuleName = $aryRowData[0];
  1600.         $strVMwarevSphereURL = $aryRowData[1];
  1601.         $strVMwarevSphereUsername = $aryRowData[2];
  1602.         $strVMwarevSpherePassword = decrypt($aryRowData[3]);
  1603.     }
  1604.     else {
  1605.         return 'Server Info Could Not Be Found, please alert us of this issue';
  1606.     }
  1607.  
  1608.     $vm = $strVMwarevSpherePassword;
  1609.     $vm->setDebug(0);
  1610.     $vm->Login();
  1611.     $strVMID = $vm->FindVMByName($strVMWareServerName);
  1612.  
  1613.     if (0 < strpos($strVMID, 'error!!')) {
  1614.         if (strlen($strVMID) < 1) {
  1615.             $vm->Logout();
  1616.             return 'Server Info Could Not Be Retreived From VMware';
  1617.         }
  1618.     }
  1619.     else {
  1620.         $vm->Logout();
  1621.         return 'Server Info Could Not Be Retreived From VMware';
  1622.     }
  1623.  
  1624.     $vmDetail = $vm->RetrievePropertiesVM($strVMID, 'VirtualMachine', 'runtime.powerState');
  1625.     $strPowerState = $vmDetail['propSet']['val'];
  1626.  
  1627.     if (strtolower($strPowerState) == 'poweredoff') {
  1628.         $vm->StartVM($strVMID);
  1629.         $successful = true;
  1630.     }
  1631.     else {
  1632.         $vm->Logout();
  1633.         return 'Server Could Not Be Powered On Because It Is Already On';
  1634.     }
  1635.  
  1636.     $vm->Logout();
  1637.  
  1638.     if ($successful) {
  1639.         $result = 'success';
  1640.     }
  1641.     else {
  1642.         $result = 'Coult Not Power On For Some Reason';
  1643.     }
  1644.  
  1645.     return $result;
  1646. }
  1647.  
  1648. function aisovmwarededsrv_ChangePackage($params)
  1649. {
  1650.     if ($successful) {
  1651.         $result = 'success';
  1652.     }
  1653.     else {
  1654.         $result = 'Error Message Goes Here...';
  1655.     }
  1656.  
  1657.     return $result;
  1658. }
  1659.  
  1660. function aisovmwarededsrv_ClientArea($params)
  1661. {
  1662.     global $_LANG;
  1663.     global $mstrVMWareWebServerCustomFieldName;
  1664.     global $mstrConfigOptionDiskSpace;
  1665.     global $mstrConfigOptionBandwidth;
  1666.     global $mstrConfigOptionCPUAmount;
  1667.     global $mstrConfigOptionRAM;
  1668.     global $mstrUserConfigOptionsExtraDiskSpace;
  1669.     global $mstrUserConfigOptionsExtraCPU;
  1670.     global $mstrUserConfigOptionsExtraRAM;
  1671.     global $mstrUserConfigOptionsServerOS;
  1672.     global $blnAKDLS;
  1673.     $blnDoReturnInsteadOfErrorPrint = False;
  1674.     $id = $params['serviceid'];
  1675.     $intServerID = $params['serverid'];
  1676.     $select_modules = 'SELECT type,ipaddress,username,password FROM tblservers WHERE id = ' . $intServerID;
  1677.     $modules_rows = full_query($select_modules);
  1678.  
  1679.     if ($modules_rows) {
  1680.         $aryRowData = mysql_fetch_row($modules_rows);
  1681.         $strModuleName = $aryRowData[0];
  1682.         $strVMwarevSphereURL = $aryRowData[1];
  1683.         $strVMwarevSphereUsername = $aryRowData[2];
  1684.         $strVMwarevSpherePassword = decrypt($aryRowData[3]);
  1685.     }
  1686.     else {
  1687.         $strErrorMessage = 'Server Info Could Not Be Found, please alert us of this issue';
  1688.  
  1689.         if ($blnDoReturnInsteadOfErrorPrint == true) {
  1690.             return 'Server Info Could Not Be Found, please alert us of this issue';
  1691.         }
  1692.     }
  1693.  
  1694.     $strVMWareServerName = $params['customfields'][$mstrVMWareWebServerCustomFieldName];
  1695.  
  1696.     if (strlen($mstrVMWareWebServerCustomFieldName) < 1) {
  1697.         $strErrorMessage = 'VM Info Could Not Be Found, please alert us of this issue';
  1698.  
  1699.         if ($blnDoReturnInsteadOfErrorPrint == true) {
  1700.             return 'VM Info Could Not Be Found, please alert us of this issue';
  1701.         }
  1702.     }
  1703.  
  1704.     $intServiceID = $params['serviceid'];
  1705.     $select_hosting = 'SELECT dedicatedip,assignedips FROM tblhosting WHERE id = ' . $intServiceID;
  1706.     $hosting_row = full_query($select_hosting);
  1707.  
  1708.     if ($hosting_row) {
  1709.         $aryRowData = mysql_fetch_assoc($hosting_row);
  1710.         $strAssignedIPAddress = $aryRowData['dedicatedip'];
  1711.  
  1712.         if (0 < strlen($aryRowData['assignedips'])) {
  1713.             $strAssignedIPAddresses = $aryRowData['assignedips'];
  1714.         }
  1715.     }
  1716.  
  1717.     $strAssignedIPAddresses = str_replace("\r\n", ', ', $strAssignedIPAddresses);
  1718.     $fltProductDiskSpace = $params[$mstrConfigOptionDiskSpace];
  1719.     $fltExtraDiskSpace = $params['configoptions'][$mstrUserConfigOptionsExtraDiskSpace];
  1720.     $fltTotalDiskSpace = $fltProductDiskSpace + $fltExtraDiskSpace;
  1721.     $fltProdcutBandwidth = $params[$mstrConfigOptionBandwidth];
  1722.     $fltProductCPUs = $params[$mstrConfigOptionCPUAmount];
  1723.     $fltExtraCPUs = floatval($params['configoptions'][$mstrUserConfigOptionsExtraCPU]);
  1724.     $fltTotalCPUs = $fltProductCPUs + $fltExtraCPUs;
  1725.     $fltProductRAM = $params[$mstrConfigOptionRAM];
  1726.     $fltExtraRAM = floatval($params['configoptions'][$mstrUserConfigOptionsExtraRAM]);
  1727.     $fltTotalRAM = $fltProductRAM + $fltExtraRAM;
  1728.     $strServerLoginUsername = $params['username'];
  1729.     $strServerLoginPassword = $params['password'];
  1730.     $vm = $strVMwarevSpherePassword;
  1731.     $vm->setDebug(0);
  1732.     $vm->Login();
  1733.  
  1734.     if (0 < strlen($vm->GetErrorMessageString())) {
  1735.         if ($GLOBALS['_SESSION']['adminloggedinstatus'] == 'true') {
  1736.             print($vm->GetErrorMessageString());
  1737.             exit();
  1738.         }
  1739.         else {
  1740.             $strErrorMessage = 'Server Could Not Be Logged Into, please alert us of this issue<br/><br/>' . "\n" . '';
  1741.  
  1742.             if ($blnDoReturnInsteadOfErrorPrint == true) {
  1743.                 return 'Server Could Not Be Logged Into, please alert us of this issue<br/><br/>' . "\n" . '';
  1744.             }
  1745.         }
  1746.     }
  1747.  
  1748.     $strVMID = $vm->FindVMByName($strVMWareServerName);
  1749.  
  1750.     if (0 < strpos($strVMID, 'error!!')) {
  1751.         if (strlen($strVMID) < 1) {
  1752.             $strErrorMessage = 'VMware VM Could Not Be Retreived, please alert us of this issue <!--' . $strVMWareServerName . '-->';
  1753.  
  1754.             if ($blnDoReturnInsteadOfErrorPrint == true) {
  1755.                 return 'VMware VM Could Not Be Retreived, please alert us of this issue <!--' . $strVMWareServerName . '-->';
  1756.             }
  1757.         }
  1758.     }
  1759.     else {
  1760.         $strErrorMessage = 'VMware VM Could Not Be Retreived, please alert us of this issue <!--' . $strVMWareServerName . '-->';
  1761.         return 'VMware VM Could Not Be Retreived, please alert us of this issue <!--' . $strVMWareServerName . '-->';
  1762.     }
  1763.  
  1764.     $vmDetail = $vm->RetrievePropertiesVM($strVMID, 'VirtualMachine', 'guestHeartbeatStatus');
  1765.     $strGuestOSHBStatus = $vmDetail['propSet']['val'];
  1766.  
  1767.     if (strtolower($strGuestOSHBStatus) == 'green') {
  1768.         $strGuestHeartbeatStatus = $_LANG['VMwareGuestOSHeartbeatGreen'];
  1769.     }
  1770.     else if (strtolower($strGuestOSHBStatus) == 'yellow') {
  1771.         $strGuestHeartbeatStatus = $_LANG['VMwareGuestOSHeartbeatYellow'];
  1772.     }
  1773.     else if (strtolower($strGuestOSHBStatus) == 'red') {
  1774.         $strGuestHeartbeatStatus = $_LANG['VMwareGuestOSHeartbeatRed'];
  1775.     }
  1776.     else if (strtolower($strGuestOSHBStatus) == 'gray') {
  1777.         $strGuestHeartbeatStatus = $_LANG['VMwareGuestOSHeartbeatGray'];
  1778.     }
  1779.     else {
  1780.         $strGuestHeartbeatStatus = $_LANG['VMwareGuestOSHeartbeatGray'];
  1781.     }
  1782.  
  1783.     $vmDetail = $vm->RetrievePropertiesVM($strVMID, 'VirtualMachine', 'runtime.powerState');
  1784.     $strPowerState = $vmDetail['propSet']['val'];
  1785.  
  1786.     if (strtolower($strPowerState) == 'poweredon') {
  1787.         $strVmwarePowerState = $_LANG['VMwareVMPoweredOn'];
  1788.         $strPowerCommandURL = 'turnoffserver';
  1789.         $strPowerCommandImage = 'power-off.gif';
  1790.         $strPowerCommandLangLink = $_LANG['VMwarePowerOffLink'];
  1791.         $strPowerCommandLangLinkText = $_LANG['VMwarePowerOffLinkText'];
  1792.     }
  1793.     else if (strtolower($strPowerState) == 'poweredoff') {
  1794.         $strVmwarePowerState = $_LANG['VMwareVMPoweredOff'];
  1795.         $strPowerCommandURL = 'turnonserver';
  1796.         $strPowerCommandImage = 'power-on.gif';
  1797.         $strPowerCommandLangLink = $_LANG['VMwarePowerOnLink'];
  1798.         $strPowerCommandLangLinkText = $_LANG['VMwarePowerOnLinkText'];
  1799.     }
  1800.  
  1801.     $vmDetail = $params;
  1802.     $strToolsVersion = $GLOBALS['mstrConfigOptionDiskSpace'];
  1803.     $vmDetail = $GLOBALS['mstrConfigOptionRAM'];
  1804.     $strToolsStatus = $mstrUserConfigOptionsExtraCPU;
  1805.  
  1806.     if (strtolower($strToolsStatus) == 'toolsok') {
  1807.         $strVmwareToolsStatus = $blnDoReturnInsteadOfErrorPrint;
  1808.         $intVmwareToolsStatus = 1256;
  1809.     }
  1810.     else if (strtolower($strToolsStatus) == 'toolsold') {
  1811.         $params;
  1812.         $intVmwareToolsStatus = 1257;
  1813.     }
  1814.     else if (strtolower($strToolsStatus) == 'toolsnotinstalled') {
  1815.         $strVmwareToolsStatus = $_LANG['VMwareToolsNotInstalled'];
  1816.         $intVmwareToolsStatus = 1258;
  1817.     }
  1818.     else if (strtolower($strToolsStatus) == 'toolsnotrunning') {
  1819.         $strVmwareToolsStatus = $_LANG['VMwareToolsNotRunning'];
  1820.         $intVmwareToolsStatus = 1259;
  1821.     }
  1822.     else {
  1823.         $strVmwareToolsStatus = ($strVMwarevSphereUsername = $aryRowData[2]);
  1824.         $intVmwareToolsStatus = -1;
  1825.     }
  1826.  
  1827.     $vmDetail = $vm->RetrievePropertiesVM($strVMID, 'VirtualMachine', 'guest.disk');
  1828.  
  1829.     if (isset($vmDetail['propSet']['val'])) {
  1830.         if (isset($vmDetail['propSet']['val']['GuestDiskInfo'][0])) {
  1831.             $vmDisk = $vmDetail['propSet']['val']['GuestDiskInfo'];
  1832.         }
  1833.         else {
  1834.             $vmDisk[0] = $vmDetail['propSet']['val']['GuestDiskInfo'];
  1835.         }
  1836.  
  1837.         $strVMwareDiskInfo = '';
  1838.         $d = 1256;
  1839.  
  1840.         while ($d < count($vmDisk)) {
  1841.             $size = (list() = $aryRowData);
  1842.             $free = $strAssignedIPAddresses;
  1843.             $totalfree = $totalfree + $free;
  1844.             $perc = $mstrUserConfigOptionsExtraDiskSpace;
  1845.             $used = $size - $free;
  1846.             $objChart = ($fltProdcutBandwidth = $params[$mstrConfigOptionBandwidth]);
  1847.             $objChart->SetImageOutputOption(3);
  1848.             $objChart->SetHeaderName($vmDisk[$d]['diskPath']);
  1849.             $objChart->AddColor('#4a38fa');
  1850.             $objChart->AddColor('#50CA43');
  1851.             $objChart->AddValue(0, $used, 'Used');
  1852.             $objChart->AddValue(0, $free, 'Free');
  1853.             $vmDiskChartData = $fltProductRAM;
  1854.             $params;
  1855.             unset($objChart);
  1856.             $strVMwareDiskInfo .= '<img title=\'Size: ' . $size . $_LANG['VMwareDiskSpaceGraphMBUsed'] . $used . $_LANG['VMwareDiskSpaceGraphMBFree'] . $free . $_LANG['VMwareDiskSpaceGraphMB'] . '\' src=\'' . $vmDiskChartImageData . '\'>&nbsp;&nbsp;&nbsp;';
  1857.             ++$d;
  1858.         }
  1859.  
  1860.         $strVMwareDiskInfo .= '<br/>' . $_LANG['VMwareDiskSpaceGraphTotalVMFreeSpace'] . ' ' . $totalfree . $_LANG['VMwareDiskSpaceGraphMB'];
  1861.     }
  1862.     else {
  1863.         $strVMwareDiskInfo = $blnDoReturnInsteadOfErrorPrint == true;
  1864.     }
  1865.  
  1866.     $vmDetail = $vm->RetrievePropertiesVM($strVMID, 'VirtualMachine', 'guest.hostName');
  1867.     $strHostName = strlen($strVMID);
  1868.     $vmDetail = $blnDoReturnInsteadOfErrorPrint;
  1869.     $strGuestIPAddress = $vmDetail;
  1870.     $vmDetail = $strGuestOSHBStatus;
  1871.     $strGuestName = $strGuestOSHBStatus;
  1872.     $strRecentTask = '';
  1873.     $vmDetail = strtolower($strGuestOSHBStatus);
  1874.     $strRecentTaskId = $vmDetail['propSet']['val'];
  1875.  
  1876.     if (is_array($strRecentTaskId)) {
  1877.         $_LANG;
  1878.  
  1879.         if (is_array($strRecentTaskId['ManagedObjectReference'])) {
  1880.             $intMostRecentTaskID = count($strRecentTaskId['ManagedObjectReference']) - 1;
  1881.             $strTaskID = $strRecentTaskId['ManagedObjectReference'][$intMostRecentTaskID];
  1882.         }
  1883.  
  1884.         $vmDetail;
  1885.         $strRecentTask = $strVmwarePowerState;
  1886.  
  1887.         if (isset($vmDetail['propSet']['val']['state'])) {
  1888.             if ($vmDetail['propSet']['val']['state'] == 'success') {
  1889.                 $strRecentTask .= ', <b>' . $_LANG['VMwareTaskCompleted'] . '</b>';
  1890.             }
  1891.             else {
  1892.                 $strRecentTask .= ', <b>' . $_LANG['VMwareTaskInProgress'] . '...</b>';
  1893.             }
  1894.         }
  1895.     }
  1896.     else {
  1897.         $strRecentTask = $strPowerCommandImage;
  1898.     }
  1899.  
  1900.     $blnVMwareToolsMounted = false;
  1901.     $vmHardwareDetail = $vm->RetrievePropertiesVM($strVMID, 'VirtualMachine', 'config.hardware');
  1902.  
  1903.     if (isset($vmHardwareDetail['propSet']['val']['numCPU'])) {
  1904.         $fltTotalVMCPUs = floatval($vmHardwareDetail['propSet']['val']['numCPU']);
  1905.     }
  1906.  
  1907.     if (isset($vmHardwareDetail['propSet']['val']['memoryMB'])) {
  1908.         $fltTotalVMRAMInMB = floatval($vmHardwareDetail['propSet']['val']['memoryMB']);
  1909.     }
  1910.  
  1911.     if (isset($vmHardwareDetail['propSet']['val']['device'])) {
  1912.         $aryVMHardwareDevices = $strToolsStatus;
  1913.  
  1914.         if (is_array($aryVMHardwareDevices)) {
  1915.             $blnVMwareToolsMounted = true;
  1916.             break;
  1917.         }
  1918.     }
  1919.  
  1920.     if (strtolower($strPowerState) == 'poweredon') {
  1921.         if ($blnVMwareToolsMounted == true) {
  1922.             $strVMWareToolsMountUnMountURL = 'unmountvmwaretools';
  1923.             $strVMWareToolsMountUnMountImage = 'vmware-unmount-tools.gif';
  1924.             $strVMWareToolsMountUnMountLangLink = $strVMID;
  1925.             $strVMWareToolsMountUnMountLangLinkText = $vmDetail['propSet'];
  1926.         }
  1927.         else {
  1928.             $strVMWareToolsMountUnMountURL = 'mountvmwaretools';
  1929.             $strVMWareToolsMountUnMountImage = 'vmware-mount-tools.gif';
  1930.             $strVMWareToolsMountUnMountLangLink = ($vmDisk = $vmDetail['propSet']['val']['GuestDiskInfo']);
  1931.             $strVMWareToolsMountUnMountLangLinkText = $_LANG['VMwareMountVMwareToolsLinkText'];
  1932.         }
  1933.     }
  1934.  
  1935.     $vm->Logout();
  1936.  
  1937.     if (0 < strpos($strVMWareServerName, '\\')) {
  1938.         $aryFolderVMData = $d;
  1939.         $strVMWareServerNameDisplay = $aryFolderVMData[count($aryFolderVMData) - 1];
  1940.     }
  1941.     else {
  1942.         $strVMWareServerNameDisplay = $d;
  1943.     }
  1944.  
  1945.     $results['vars'] = array(
  1946.     'LANG'                                   => $_LANG,
  1947.     'strErrorMessage'                        => $strErrorMessage,
  1948.     'strVMWareServerNameDisplay'             => $strVMWareServerNameDisplay,
  1949.     'strVmwarePowerState'                    => $strVmwarePowerState,
  1950.     'strGuestHeartbeatStatus'                => $strGuestHeartbeatStatus,
  1951.     'fltTotalCPUs'                           => $fltTotalCPUs,
  1952.     'fltTotalVMCPUs'                         => $fltTotalVMCPUs,
  1953.     'fltTotalRAM'                            => $fltTotalRAM,
  1954.     'fltTotalVMRAMInMB'                      => $fltTotalVMRAMInMB,
  1955.     'strAssignedIPAddress'                   => $strAssignedIPAddress,
  1956.     'strAssignedIPAddresses'                 => $strAssignedIPAddresses,
  1957.     'strGuestIPAddress'                      => $strGuestIPAddress,
  1958.     'strGuestName'                           => $strGuestName,
  1959.     'strHostName'                            => $strHostName,
  1960.     'strVmwareToolsStatus'                   => $strVmwareToolsStatus,
  1961.     'strToolsVersion'                        => $strToolsVersion,
  1962.     'strRecentTask'                          => $strRecentTask,
  1963.     'strVMwareDiskInfo'                      => $strVMwareDiskInfo,
  1964.     'strServerLoginUsername'                 => $strServerLoginUsername,
  1965.     'strServerLoginPassword'                 => $strServerLoginPassword,
  1966.     'strPowerCommandURL'                     => $strPowerCommandURL,
  1967.     'strPowerCommandImage'                   => $strPowerCommandImage,
  1968.     'strPowerCommandLangLink'                => $strPowerCommandLangLink,
  1969.     'strPowerCommandLangLinkText'            => $strPowerCommandLangLinkText,
  1970.     'strVMWareToolsMountUnMountURL'          => $strVMWareToolsMountUnMountURL,
  1971.     'strVMWareToolsMountUnMountImage'        => $strVMWareToolsMountUnMountImage,
  1972.     'strVMWareToolsMountUnMountLangLink'     => $strVMWareToolsMountUnMountLangLink,
  1973.     'strVMWareToolsMountUnMountLangLinkText' => $strVMWareToolsMountUnMountLangLinkText,
  1974.     'configoptions'                          => array(),
  1975.     'customfields'                           => array()
  1976.     );
  1977.     return $results;
  1978. }
  1979.  
  1980. function aisovmwarededsrv_ClientAreaCustomButtonArray()
  1981. {
  1982.     global $_LANG;
  1983.     global $mstrVMWareWebServerCustomFieldName;
  1984.     global $blnAKDLS;
  1985.  
  1986.     if ($GLOBALS['license'] == 'Dev-7bdd6a5ed79a8a14af40') {
  1987.         $blnAKDLS = true;
  1988.     }
  1989.     else if ($GLOBALS['license'] == 'Leased-abc367f314a7142c44fd') {
  1990.         $blnAKDLS = true;
  1991.     }
  1992.     else {
  1993.         $blnAKDLS = false;
  1994.     }
  1995.  
  1996.     if ($blnAKDLS == false) {
  1997.         $strVMwareValue = VMWareGetWHMCSCustomFieldValue($mstrVMWareWebServerCustomFieldName, $GLOBALS['packageid'], $GLOBALS['id']);
  1998.     }
  1999.     else if (isset($GLOBALS['smarty']->_tpl_vars['customfields'][$mstrVMWareWebServerCustomFieldName])) {
  2000.         $strVMwareValue = $GLOBALS['smarty']->_tpl_vars['customfields'][$mstrVMWareWebServerCustomFieldName];
  2001.     }
  2002.  
  2003.     if ($blnAKDLS == false) {
  2004.         if (0 < strlen($strVMwareValue)) {
  2005.             $id = $GLOBALS['id'];
  2006.             $intServerID = $GLOBALS['smarty']->_tpl_vars['serverdata']['id'];
  2007.             $server_result = select_query('tblservers', 'type,ipaddress,username,password', array('id' => $intServerID), '', '', '', '');
  2008.             $aryRowData = mysql_fetch_array($server_result);
  2009.  
  2010.             if (1 < count($aryRowData)) {
  2011.                 $strModuleName = $aryRowData[0];
  2012.                 $strVMwarevSphereURL = $aryRowData[1];
  2013.                 $strVMwarevSphereUsername = $aryRowData[2];
  2014.                 $strVMwarevSpherePassword = decrypt($aryRowData[3]);
  2015.             }
  2016.             else {
  2017.                 return array();
  2018.             }
  2019.  
  2020.             $strVMWareServerName = $strVMwareValue;
  2021.  
  2022.             if (strlen($mstrVMWareWebServerCustomFieldName) < 1) {
  2023.                 return array();
  2024.             }
  2025.  
  2026.             $strServerLoginUsername = $GLOBALS['smarty']->_tpl_vars['serverdata']['username'];
  2027.             $strServerLoginPassword = $GLOBALS['smarty']->_tpl_vars['serverdata']['password'];
  2028.             $vm = $strVMwarevSpherePassword;
  2029.             $vm->setDebug(0);
  2030.             $vm->Login();
  2031.  
  2032.             if (0 < strlen($vm->GetErrorMessageString())) {
  2033.                 if ($GLOBALS['_SESSION']['adminloggedinstatus'] == 'true') {
  2034.                     print($vm->GetErrorMessageString());
  2035.                     exit();
  2036.                 }
  2037.                 else {
  2038.                     return array();
  2039.                 }
  2040.             }
  2041.  
  2042.             $strVMID = $vm->FindVMByName($strVMWareServerName);
  2043.  
  2044.             if (0 < strpos($strVMID, 'error!!')) {
  2045.                 if (strlen($strVMID) < 1) {
  2046.                     return array();
  2047.                 }
  2048.             }
  2049.             else {
  2050.                 return array();
  2051.             }
  2052.  
  2053.             $vmDetail = $vm->RetrievePropertiesVM($strVMID, 'VirtualMachine', 'runtime.powerState');
  2054.             $strPowerState = $vmDetail['propSet']['val'];
  2055.             $blnVMwareToolsMounted = false;
  2056.             $vmHardwareDetail = $vm->RetrievePropertiesVM($strVMID, 'VirtualMachine', 'config.hardware');
  2057.  
  2058.             if (isset($vmHardwareDetail['propSet']['val']['device'])) {
  2059.                 $aryVMHardwareDevices = $vmHardwareDetail['propSet']['val']['device'];
  2060.  
  2061.                 if (is_array($aryVMHardwareDevices)) {
  2062.                     $blnVMwareToolsMounted = true;
  2063.                     break;
  2064.                 }
  2065.             }
  2066.  
  2067.             $vm->Logout();
  2068.  
  2069.             if (strtolower($strPowerState) == 'poweredon') {
  2070.                 $strVMwarePowerButtonLang = $_LANG['VMwarePowerOffLink'];
  2071.                 $strVMwarePowerButtonModuleFunction = 'turnoffserver';
  2072.             }
  2073.             else {
  2074.                 $strVMwarePowerButtonLang = $_LANG['VMwarePowerOnLink'];
  2075.                 $strVMwarePowerButtonModuleFunction = 'turnonserver';
  2076.             }
  2077.  
  2078.             if ($blnVMwareToolsMounted == true) {
  2079.                 $strVMwareToolsMountButtonLang = $_LANG['VMwareUnmountVMwareToolsLink'];
  2080.                 $strVMwareToolsMountButtonModuleFunction = 'unmountvmwaretools';
  2081.             }
  2082.             else {
  2083.                 $strVMwareToolsMountButtonLang = $_LANG['VMwareMountVMwareToolsLink'];
  2084.                 $strVMwareToolsMountButtonModuleFunction = 'mountvmwaretools';
  2085.             }
  2086.  
  2087.             $buttonarray = array($strVMwarePowerButtonLang => $strVMwarePowerButtonModuleFunction, $strVMwareToolsMountButtonLang => $strVMwareToolsMountButtonModuleFunction, $_LANG['VMwareUpdateVMwareToolsLink'] => 'updatevmwaretools');
  2088.  
  2089.             if (strtolower($strPowerState) == 'poweredon') {
  2090.                 $buttonarrayappend = array($_LANG['VMwareHardRebootServerLink'] => 'hardrebootserver', $_LANG['VMwareSoftRebootServerLink'] => 'softrebootserver');
  2091.                 $buttonarray = array_merge($buttonarray, $buttonarrayappend);
  2092.             }
  2093.  
  2094.             return $buttonarray;
  2095.         }
  2096.     }
  2097.  
  2098.     if ($blnAKDLS == false) {
  2099.         $buttonarray = array($_LANG['VMwareHardRebootServerLink'] => 'hardrebootserver', $_LANG['VMwareSoftRebootServerLink'] => 'softrebootserver', $_LANG['VMwarePowerOffLink'] => 'turnoffserver', $_LANG['VMwarePowerOnLink'] => 'turnonserver', $_LANG['VMwareMountVMwareToolsLink'] => 'mountvmwaretools', $_LANG['VMwareUnmountVMwareToolsLink'] => 'unmountvmwaretools', $_LANG['VMwareUpdateVMwareToolsLink'] => 'updatevmwaretools');
  2100.     }
  2101.     else {
  2102.         $buttonarray = array($_LANG['VMwareHardRebootServerLink'] => 'hardrebootserver', $_LANG['VMwareSoftRebootServerLink'] => 'softrebootserver', $_LANG['VMwarePowerOffLink'] => 'turnoffserver', $_LANG['VMwarePowerOnLink'] => 'turnonserver', $_LANG['VMwareMountVMwareToolsLink'] => 'mountvmwaretools', $_LANG['VMwareUnmountVMwareToolsLink'] => 'unmountvmwaretools', $_LANG['VMwareUpdateVMwareToolsLink'] => 'updatevmwaretools', 'Create Snapshot' => 'createsnapshot', 'List Snapshots' => 'listsnapshots', 'VM Console' => 'vmconsole', 'Bandwidth Usage' => 'bandwidthusage', 'Emergency Support' => 'emergencysupport', $_LANG['VMwareManageDNSZoneFilesLink'] => 'managednszonefiles', 'Add/Edit Zone File' => 'editdnszonefiles');
  2103.     }
  2104.  
  2105.     return $buttonarray;
  2106. }
  2107.  
  2108. function aisovmwarededsrv_hardrebootserver($params)
  2109. {
  2110.     global $_LANG;
  2111.     global $mstrVMWareWebServerCustomFieldName;
  2112.     $strVMWareServerName = $params['customfields'][$mstrVMWareWebServerCustomFieldName];
  2113.  
  2114.     if (strlen($mstrVMWareWebServerCustomFieldName) < 1) {
  2115.         return 'Server Name Could Not Be Found';
  2116.     }
  2117.  
  2118.     $a2 = '';
  2119.     $intServerID = $params['serverid'];
  2120.     $select_modules = 'SELECT type,ipaddress,username,password FROM tblservers WHERE id = ' . $intServerID;
  2121.     $modules_rows = full_query($select_modules);
  2122.  
  2123.     if ($modules_rows) {
  2124.         $aryRowData = mysql_fetch_row($modules_rows);
  2125.         $strModuleName = $aryRowData[0];
  2126.         $strVMwarevSphereURL = $aryRowData[1];
  2127.         $strVMwarevSphereUsername = $aryRowData[2];
  2128.         $strVMwarevSpherePassword = $GLOBALS['_LANG'];
  2129.     }
  2130.     else {
  2131.         return 'Server Info Could Not Be Found, please alert us of this issue';
  2132.     }
  2133.  
  2134.     $strErrorMessageArea = 'style="display:none;"';
  2135.     $strErrorMessage = '';
  2136.  
  2137.     if ($_POST['a2'] == 'rs') {
  2138.         $vm = strlen($mstrVMWareWebServerCustomFieldName);
  2139.         $vm->setDebug(0);
  2140.         $vm->Login();
  2141.         $strVMID = $modules_rows;
  2142.  
  2143.         if (0 < strpos($strVMID, 'error!!')) {
  2144.             if (strlen($strVMID) < 1) {
  2145.                 $strErrorMessageArea = '';
  2146.                 $strErrorMessage = 'Server Info Could Not Be Retreived From VMware, please contact us.';
  2147.             }
  2148.         }
  2149.         else {
  2150.             $strErrorMessageArea = '';
  2151.             $strErrorMessage = 'Server Info Could Not Be Retreived From VMware, please contact us.';
  2152.         }
  2153.  
  2154.         if ($strVMID != '') {
  2155.             if ($strErrorMessage == '') {
  2156.                 $vmDetail = decrypt($aryRowData[3]);
  2157.                 $strPowerState = $vmDetail['propSet']['val'];
  2158.  
  2159.                 if (strtolower($strPowerState) == 'poweredon') {
  2160.                     $vm->ResetVM($strVMID);
  2161.                 }
  2162.                 else {
  2163.                     $strErrorMessageArea = '';
  2164.                     $strErrorMessage = 'Server Could Not Be Hard Rebooted Because It Is Off';
  2165.                 }
  2166.             }
  2167.         }
  2168.  
  2169.         $vm->Logout();
  2170.  
  2171.         if ($strErrorMessage == '') {
  2172.             $a2 = 'rs';
  2173.         }
  2174.     }
  2175.  
  2176.     if (0 < strpos($strVMWareServerName, '\\')) {
  2177.         $aryFolderVMData = strpos($strVMID, 'error!!');
  2178.         $strVMWareServerNameDisplay = $strErrorMessage;
  2179.     }
  2180.     else {
  2181.         $strVMWareServerNameDisplay = $strErrorMessage == '';
  2182.     }
  2183.  
  2184.     $pagearray = array(
  2185.         'templatefile' => 'hardrebootserver',
  2186.         'breadcrumb'   => ' > <a href="#">' . $_LANG['VMwareHardRebootServerLink'] . '</a>',
  2187.         'vars'         => array('LANG' => $_LANG, 'servername' => $strVMWareServerNameDisplay, 'a2' => $a2, 'strErrorMessage' => $strErrorMessage, 'strErrorMessageArea' => $strErrorMessageArea)
  2188.         );
  2189.     return $pagearray;
  2190. }
  2191.  
  2192. function aisovmwarededsrv_softrebootserver($params)
  2193. {
  2194.     global $_LANG;
  2195.     global $mstrVMWareWebServerCustomFieldName;
  2196.     $strVMWareServerName = $params['customfields'][$mstrVMWareWebServerCustomFieldName];
  2197.  
  2198.     if (strlen($mstrVMWareWebServerCustomFieldName) < 1) {
  2199.         return 'Server Name Could Not Be Found';
  2200.     }
  2201.  
  2202.     $a2 = '';
  2203.     $intServerID = $params['serverid'];
  2204.     $select_modules = 'SELECT type,ipaddress,username,password FROM tblservers WHERE id = ' . $intServerID;
  2205.     $modules_rows = full_query($select_modules);
  2206.  
  2207.     if ($modules_rows) {
  2208.         $aryRowData = mysql_fetch_row($modules_rows);
  2209.         $strModuleName = $aryRowData[0];
  2210.         $strVMwarevSphereURL = $aryRowData[1];
  2211.         $strVMwarevSphereUsername = $aryRowData[2];
  2212.         $strVMwarevSpherePassword = decrypt($aryRowData[3]);
  2213.     }
  2214.     else {
  2215.         return 'Server Info Could Not Be Found, please alert us of this issue';
  2216.     }
  2217.  
  2218.     $strErrorMessageArea = 'style="display:none;"';
  2219.     $strErrorMessage = '';
  2220.  
  2221.     if ($_POST['a2'] == 'rs') {
  2222.         $vm = $strVMwarevSpherePassword;
  2223.         $vm->setDebug(0);
  2224.         $vm->Login();
  2225.         $strVMID = $vm->FindVMByName($strVMWareServerName);
  2226.  
  2227.         if (0 < strpos($strVMID, 'error!!')) {
  2228.             if (strlen($strVMID) < 1) {
  2229.                 $strErrorMessageArea = '';
  2230.                 $strErrorMessage = 'Server Info Could Not Be Retreived From VMware, please contact us.';
  2231.             }
  2232.         }
  2233.         else {
  2234.             $strErrorMessageArea = '';
  2235.             $strErrorMessage = 'Server Info Could Not Be Retreived From VMware, please contact us.';
  2236.         }
  2237.  
  2238.         if ($strVMID != '') {
  2239.             if ($strErrorMessage == '') {
  2240.                 $vmDetail = $vm->RetrievePropertiesVM($strVMID, 'VirtualMachine', 'guest.toolsStatus');
  2241.                 $strToolsStatus = $vmDetail['propSet']['val'];
  2242.  
  2243.                 if (strtolower($strToolsStatus) == 'toolsok') {
  2244.                 }
  2245.                 else if (strtolower($strToolsStatus) == 'toolsold') {
  2246.                 }
  2247.                 else if (strtolower($strToolsStatus) == 'toolsnotinstalled') {
  2248.                     $strErrorMessageArea = '';
  2249.                     $strErrorMessage = 'VMware Tools are not installed, please install the tools to do a soft reboot.';
  2250.                 }
  2251.                 else if (strtolower($strToolsStatus) == 'toolsnotrunning') {
  2252.                     $strErrorMessageArea = '';
  2253.                     $strErrorMessage = 'VMware Tools are installed, but not running. Please start the VMware tools\' services to do a soft reboot.';
  2254.                 }
  2255.                 else {
  2256.                     $strErrorMessageArea = '';
  2257.                     $strErrorMessage = 'VMware Tools are in an unknown state, please install the tools or check their status and correct it to do a soft reboot.';
  2258.                 }
  2259.             }
  2260.         }
  2261.  
  2262.         if ($strVMID != '') {
  2263.             if ($strErrorMessage == '') {
  2264.                 $vmDetail = mysql_fetch_row($modules_rows);
  2265.                 $strPowerState = $vmDetail['propSet']['val'];
  2266.  
  2267.                 if (strtolower($strPowerState) == 'poweredon') {
  2268.                     $vm->RebootVMGuest($strVMID);
  2269.                 }
  2270.                 else {
  2271.                     $strErrorMessageArea = '';
  2272.                     $strErrorMessage = 'Server Could Not Be Soft Rebooted Because It Is Off';
  2273.                 }
  2274.             }
  2275.         }
  2276.  
  2277.         $vm->Logout();
  2278.  
  2279.         if ($strErrorMessage == '') {
  2280.             $a2 = 'rs';
  2281.         }
  2282.     }
  2283.  
  2284.     if (0 < strpos($strVMWareServerName, '\\')) {
  2285.         $aryFolderVMData = $strVMwarevSphereUsername;
  2286.         $strVMWareServerNameDisplay = $vm;
  2287.     }
  2288.     else {
  2289.         $strVMWareServerNameDisplay = $strVMID;
  2290.     }
  2291.  
  2292.     $pagearray = array(
  2293.         'templatefile' => 'softrebootserver',
  2294.         'breadcrumb'   => ' > <a href="#">' . $_LANG['VMwareSoftRebootServerLink'] . '</a>',
  2295.         'vars'         => array('LANG' => $_LANG, 'servername' => $strVMWareServerNameDisplay, 'a2' => $a2, 'strErrorMessage' => $strErrorMessage, 'strErrorMessageArea' => $strErrorMessageArea)
  2296.         );
  2297.     return $pagearray;
  2298. }
  2299.  
  2300. function aisovmwarededsrv_turnoffserver($params)
  2301. {
  2302.     global $_LANG;
  2303.     global $mstrVMWareWebServerCustomFieldName;
  2304.     $strVMWareServerName = $params['customfields'][$mstrVMWareWebServerCustomFieldName];
  2305.  
  2306.     if (strlen($mstrVMWareWebServerCustomFieldName) < 1) {
  2307.         return 'Server Name Could Not Be Found';
  2308.     }
  2309.  
  2310.     $a2 = '';
  2311.     $intServerID = $params['serverid'];
  2312.     $select_modules = 'SELECT type,ipaddress,username,password FROM tblservers WHERE id = ' . $intServerID;
  2313.     $modules_rows = full_query($select_modules);
  2314.  
  2315.     if ($modules_rows) {
  2316.         $aryRowData = mysql_fetch_row($modules_rows);
  2317.         $strModuleName = $aryRowData[0];
  2318.         $strVMwarevSphereURL = $aryRowData[1];
  2319.         $strVMwarevSphereUsername = $aryRowData[2];
  2320.         $strVMwarevSpherePassword = decrypt($aryRowData[3]);
  2321.     }
  2322.     else {
  2323.         return 'Server Info Could Not Be Found, please alert us of this issue';
  2324.     }
  2325.  
  2326.     $strErrorMessageArea = 'style="display:none;"';
  2327.     $strErrorMessage = '';
  2328.  
  2329.     if ($_POST['a2'] == 'rs') {
  2330.         $vm = $strVMwarevSpherePassword;
  2331.         $vm->setDebug(0);
  2332.         $vm->Login();
  2333.         $strVMID = $vm->FindVMByName($strVMWareServerName);
  2334.  
  2335.         if (0 < strpos($strVMID, 'error!!')) {
  2336.             if (strlen($strVMID) < 1) {
  2337.                 $strErrorMessageArea = '';
  2338.                 $strErrorMessage = 'Server Info Could Not Be Retreived From VMware, please contact us.';
  2339.             }
  2340.         }
  2341.         else {
  2342.             $strErrorMessageArea = '';
  2343.             $strErrorMessage = 'Server Info Could Not Be Retreived From VMware, please contact us.';
  2344.         }
  2345.  
  2346.         if (isset($_POST['harddown'])) {
  2347.             $strDoHardDown = $_POST['harddown'];
  2348.         }
  2349.         else {
  2350.             $strDoHardDown = 'no';
  2351.         }
  2352.  
  2353.         if ($strDoHardDown == 'yes') {
  2354.             if ($strVMID != '') {
  2355.                 if ($strErrorMessage == '') {
  2356.                     $vmDetail = $vm->RetrievePropertiesVM($strVMID, 'VirtualMachine', 'runtime.powerState');
  2357.                     $strPowerState = $vmDetail['propSet']['val'];
  2358.  
  2359.                     if (strtolower($strPowerState) == 'poweredon') {
  2360.                         $vm->StopVM($strVMID);
  2361.                     }
  2362.                     else {
  2363.                         $strErrorMessageArea = '';
  2364.                         $strErrorMessage = 'Server Could Not Be Turned Off Because It Is Off';
  2365.                     }
  2366.                 }
  2367.             }
  2368.         }
  2369.         else {
  2370.             if (isset($_POST['skipvmwaretoolscheck'])) {
  2371.                 $strSkipVMwareToolsCheck = $_POST['skipvmwaretoolscheck'];
  2372.             }
  2373.             else {
  2374.                 $strSkipVMwareToolsCheck = 'no';
  2375.             }
  2376.  
  2377.             if ($strSkipVMwareToolsCheck != 'yes') {
  2378.                 if ($strVMID != '') {
  2379.                     if ($strErrorMessage == '') {
  2380.                         $vmDetail = $vm->RetrievePropertiesVM($strVMID, 'VirtualMachine', 'guest.toolsStatus');
  2381.                         $strToolsStatus = $vmDetail['propSet']['val'];
  2382.  
  2383.                         if (strtolower($strToolsStatus) == 'toolsok') {
  2384.                         }
  2385.                         else if (strtolower($strToolsStatus) == 'toolsold') {
  2386.                         }
  2387.                         else if (strtolower($strToolsStatus) == 'toolsnotinstalled') {
  2388.                             $strErrorMessageArea = '';
  2389.                             $strErrorMessage = 'VMware Tools are not installed, please install the tools to do a soft reboot.';
  2390.                         }
  2391.                         else if (strtolower($strToolsStatus) == 'toolsnotrunning') {
  2392.                             $strErrorMessageArea = '';
  2393.                             $strErrorMessage = 'VMware Tools are installed, but not running. Please start the VMware tools\' services to do a soft reboot.';
  2394.                         }
  2395.                         else {
  2396.                             $strErrorMessageArea = '';
  2397.                             $strErrorMessage = 'VMware Tools are in an unknown state, please install the tools or check their status and correct it to do a soft reboot.';
  2398.                         }
  2399.                     }
  2400.                 }
  2401.             }
  2402.  
  2403.             if ($strVMID != '') {
  2404.                 if ($strErrorMessage == '') {
  2405.                     $vmDetail = $GLOBALS['mstrVMWareWebServerCustomFieldName'];
  2406.                     $strPowerState = $mstrVMWareWebServerCustomFieldName;
  2407.  
  2408.                     if (strtolower($strPowerState) == 'poweredon') {
  2409.                         $vm->ShutdownVMGuest($strVMID);
  2410.                     }
  2411.                     else {
  2412.                         $strErrorMessageArea = '';
  2413.                         $strErrorMessage = 'Server Could Not Be Turned Off Because It Is Off';
  2414.                     }
  2415.                 }
  2416.             }
  2417.         }
  2418.  
  2419.         $vm->Logout();
  2420.  
  2421.         if ($strErrorMessage == '') {
  2422.             $a2 = 'rs';
  2423.         }
  2424.     }
  2425.  
  2426.     if (0 < strpos($strVMWareServerName, '\\')) {
  2427.         $aryFolderVMData = $strModuleName;
  2428.         $strVMWareServerNameDisplay = $aryFolderVMData[count($aryFolderVMData) - 1];
  2429.     }
  2430.     else {
  2431.         $aryRowData;
  2432.     }
  2433.  
  2434.     $pagearray = array(
  2435.         'templatefile' => 'turnoffserver',
  2436.         'breadcrumb'   => ' > <a href="#">' . $_LANG['VMwarePowerOffLink'] . '</a>',
  2437.         'vars'         => array('LANG' => $_LANG, 'servername' => $strVMWareServerNameDisplay, 'a2' => $a2, 'strErrorMessage' => $strErrorMessage, 'strErrorMessageArea' => $strErrorMessageArea)
  2438.         );
  2439.     return $pagearray;
  2440. }
  2441.  
  2442. function aisovmwarededsrv_turnonserver($params)
  2443. {
  2444.     global $_LANG;
  2445.     global $mstrVMWareWebServerCustomFieldName;
  2446.     $strVMWareServerName = $params['customfields'][$mstrVMWareWebServerCustomFieldName];
  2447.  
  2448.     if (strlen($mstrVMWareWebServerCustomFieldName) < 1) {
  2449.         return 'Server Name Could Not Be Found';
  2450.     }
  2451.  
  2452.     $a2 = '';
  2453.     $intServerID = $params['serverid'];
  2454.     $select_modules = 'SELECT type,ipaddress,username,password FROM tblservers WHERE id = ' . $intServerID;
  2455.     $modules_rows = full_query($select_modules);
  2456.  
  2457.     if ($modules_rows) {
  2458.         $aryRowData = mysql_fetch_row($modules_rows);
  2459.         $strModuleName = $aryRowData[0];
  2460.         $strVMwarevSphereURL = $aryRowData[1];
  2461.         $strVMwarevSphereUsername = $aryRowData[2];
  2462.         $strVMwarevSpherePassword = $GLOBALS['_LANG'];
  2463.     }
  2464.     else {
  2465.         return 'Server Info Could Not Be Found, please alert us of this issue';
  2466.     }
  2467.  
  2468.     $strErrorMessageArea = 'style="display:none;"';
  2469.     $strErrorMessage = '';
  2470.  
  2471.     if ($_POST['a2'] == 'rs') {
  2472.         $vm = strlen($mstrVMWareWebServerCustomFieldName);
  2473.         $vm->setDebug(0);
  2474.         $vm->Login();
  2475.         $strVMID = $modules_rows;
  2476.  
  2477.         if (0 < strpos($strVMID, 'error!!')) {
  2478.             if (strlen($strVMID) < 1) {
  2479.                 $strErrorMessageArea = '';
  2480.                 $strErrorMessage = 'Server Info Could Not Be Retreived From VMware, please contact us.';
  2481.             }
  2482.         }
  2483.         else {
  2484.             $strErrorMessageArea = '';
  2485.             $strErrorMessage = 'Server Info Could Not Be Retreived From VMware, please contact us.';
  2486.         }
  2487.  
  2488.         if ($strVMID != '') {
  2489.             if ($strErrorMessage == '') {
  2490.                 $vmDetail = decrypt($aryRowData[3]);
  2491.                 $strPowerState = $vmDetail['propSet']['val'];
  2492.  
  2493.                 if (strtolower($strPowerState) == 'poweredoff') {
  2494.                     $vm->StartVM($strVMID);
  2495.                 }
  2496.                 else {
  2497.                     $strErrorMessageArea = '';
  2498.                     $strErrorMessage = 'Server Could Not Be Turned On Because It Is On';
  2499.                 }
  2500.             }
  2501.         }
  2502.  
  2503.         $vm->Logout();
  2504.  
  2505.         if ($strErrorMessage == '') {
  2506.             $a2 = 'rs';
  2507.         }
  2508.     }
  2509.  
  2510.     if (0 < strpos($strVMWareServerName, '\\')) {
  2511.         $aryFolderVMData = strpos($strVMID, 'error!!');
  2512.         $strVMWareServerNameDisplay = $strErrorMessage;
  2513.     }
  2514.     else {
  2515.         $strVMWareServerNameDisplay = $strErrorMessage == '';
  2516.     }
  2517.  
  2518.     $pagearray = array(
  2519.         'templatefile' => 'turnonserver',
  2520.         'breadcrumb'   => ' > <a href="#">' . $_LANG['VMwarePowerOnLink'] . '</a>',
  2521.         'vars'         => array('LANG' => $_LANG, 'servername' => $strVMWareServerNameDisplay, 'a2' => $a2, 'strErrorMessage' => $strErrorMessage, 'strErrorMessageArea' => $strErrorMessageArea)
  2522.         );
  2523.     return $pagearray;
  2524. }
  2525.  
  2526. function aisovmwarededsrv_createsnapshot($params)
  2527. {
  2528.     global $_LANG;
  2529.     global $mstrVMWareWebServerCustomFieldName;
  2530.     $strVMWareServerName = $params['customfields'][$mstrVMWareWebServerCustomFieldName];
  2531.  
  2532.     if (strlen($mstrVMWareWebServerCustomFieldName) < 1) {
  2533.         return 'Server Name Could Not Be Found';
  2534.     }
  2535.  
  2536.     $a2 = '';
  2537.     $intServerID = $params['serverid'];
  2538.     $select_modules = 'SELECT type,ipaddress,username,password FROM tblservers WHERE id = ' . $intServerID;
  2539.     $modules_rows = full_query($select_modules);
  2540.  
  2541.     if ($modules_rows) {
  2542.         $aryRowData = mysql_fetch_row($modules_rows);
  2543.         $strModuleName = $aryRowData[0];
  2544.         $strVMwarevSphereURL = $aryRowData[1];
  2545.         $strVMwarevSphereUsername = $aryRowData[2];
  2546.         $strVMwarevSpherePassword = decrypt($aryRowData[3]);
  2547.     }
  2548.     else {
  2549.         return 'Server Info Could Not Be Found, please alert us of this issue';
  2550.     }
  2551.  
  2552.     $strErrorMessageArea = 'style="display:none;"';
  2553.     $strErrorMessage = '';
  2554.     exit();
  2555.     $vm = $strVMwarevSpherePassword;
  2556.     $vm->setDebug(0);
  2557.     $vm->Login();
  2558.     $strVMID = $vm->FindVMByName($strVMWareServerName);
  2559.  
  2560.     if (0 < strpos($strVMID, 'error!!')) {
  2561.         if (strlen($strVMID) < 1) {
  2562.             $strErrorMessageArea = '';
  2563.             $strErrorMessage = 'Server Info Could Not Be Retreived From VMware, please contact us.';
  2564.         }
  2565.     }
  2566.     else {
  2567.         $strErrorMessageArea = '';
  2568.         $strErrorMessage = 'Server Info Could Not Be Retreived From VMware, please contact us.';
  2569.     }
  2570.  
  2571.     $result = $vm->CreateVMSnapshot($strVMID, 'testsnapshot', 'test snap shot');
  2572.     $vm->Logout();
  2573.  
  2574.     if (0 < strpos($strVMWareServerName, '\\')) {
  2575.         $aryFolderVMData = explode('\\', $strVMWareServerName);
  2576.         $strVMWareServerNameDisplay = $aryFolderVMData[count($aryFolderVMData) - 1];
  2577.     }
  2578.     else {
  2579.         $strVMWareServerNameDisplay = $strVMWareServerName;
  2580.     }
  2581.  
  2582.     $pagearray = array(
  2583.         'templatefile' => 'createsnapshot',
  2584.         'breadcrumb'   => ' > <a href="#">Create Snapshot</a>',
  2585.         'vars'         => array('LANG' => $_LANG, 'servername' => $strVMWareServerNameDisplay, 'a2' => $a2, 'strErrorMessage' => $strErrorMessage, 'strErrorMessageArea' => $strErrorMessageArea)
  2586.         );
  2587.     return $pagearray;
  2588. }
  2589.  
  2590. function aisovmwarededsrv_listsnapshots($params)
  2591. {
  2592.     global $_LANG;
  2593.     global $mstrVMWareWebServerCustomFieldName;
  2594.     $strVMWareServerName = $strVMWareServerName;
  2595.  
  2596.     if (strlen($mstrVMWareWebServerCustomFieldName) < 1) {
  2597.         return 'Server Name Could Not Be Found';
  2598.     }
  2599.  
  2600.     $a2 = '';
  2601.     $intServerID = $a2;
  2602.     $select_modules = 'SELECT type,ipaddress,username,password FROM tblservers WHERE id = ' . $intServerID;
  2603.     $modules_rows = $intServerID;
  2604.  
  2605.     if ($modules_rows) {
  2606.         $aryRowData = mysql_fetch_row($modules_rows);
  2607.         $strModuleName = mysql_fetch_row($modules_rows);
  2608.         $strVMwarevSphereURL = $aryRowData[0];
  2609.         $strVMwarevSphereUsername = $aryRowData[1];
  2610.         $strVMwarevSpherePassword = decrypt($aryRowData[3]);
  2611.     }
  2612.     else {
  2613.         return 'Server Info Could Not Be Found, please alert us of this issue';
  2614.     }
  2615.  
  2616.     $strErrorMessageArea = 'style="display:none;"';
  2617.     $strErrorMessage = '';
  2618.     exit();
  2619.     $vm = $strErrorMessage;
  2620.     $vm->setDebug(0);
  2621.     $vm->Login();
  2622.     $strVMID = $strVMID;
  2623.  
  2624.     if (0 < strpos($strVMID, 'error!!')) {
  2625.         if (strlen($strVMID) < 1) {
  2626.             $strErrorMessageArea = '';
  2627.             $strErrorMessage = 'Server Info Could Not Be Retreived From VMware, please contact us.';
  2628.         }
  2629.     }
  2630.     else {
  2631.         $strErrorMessageArea = '';
  2632.         $strErrorMessage = 'Server Info Could Not Be Retreived From VMware, please contact us.';
  2633.     }
  2634.  
  2635.     $vmSnapshots = $vmSnapshots;
  2636.     $arySnapshots = $vmSnapshots['propSet']['val'];
  2637.     $vm->Logout();
  2638.  
  2639.     if (0 < strpos($strVMWareServerName, '\\')) {
  2640.         $aryFolderVMData = strpos($strVMWareServerName, '\\');
  2641.         $strVMWareServerNameDisplay = ($aryFolderVMData[count($aryFolderVMData) - 1]);
  2642.     }
  2643.     else {
  2644.         $strVMWareServerNameDisplay = count($aryFolderVMData) - 1;
  2645.     }
  2646.  
  2647.     $pagearray = array(
  2648.         'templatefile' => 'listsnapshots',
  2649.         'breadcrumb'   => ' > <a href="#">List Snapshots</a>',
  2650.         'vars'         => array('LANG' => $_LANG, 'servername' => $strVMWareServerNameDisplay, 'a2' => $a2, 'strErrorMessage' => $strErrorMessage, 'strErrorMessageArea' => $strErrorMessageArea)
  2651.         );
  2652.     return $pagearray;
  2653. }
  2654.  
  2655. function aisovmwarededsrv_vmconsole($params)
  2656. {
  2657.     global $_LANG;
  2658.     global $mstrVMWareWebServerCustomFieldName;
  2659.     $strVMWareServerName = $params['customfields'][$mstrVMWareWebServerCustomFieldName];
  2660.  
  2661.     if (strlen($mstrVMWareWebServerCustomFieldName) < 1) {
  2662.         return 'Server Name Could Not Be Found';
  2663.     }
  2664.  
  2665.     $a2 = '';
  2666.     $intServerID = $params['serverid'];
  2667.     $select_modules = 'SELECT type,ipaddress,username,password FROM tblservers WHERE id = ' . $intServerID;
  2668.     $modules_rows = full_query($select_modules);
  2669.  
  2670.     if ($modules_rows) {
  2671.         $aryRowData = mysql_fetch_row($modules_rows);
  2672.         $strModuleName = $aryRowData[0];
  2673.         $strVMwarevSphereURL = $aryRowData[1];
  2674.         $strVMwarevSphereUsername = $aryRowData[2];
  2675.         $strVMwarevSpherePassword = decrypt($aryRowData[3]);
  2676.     }
  2677.     else {
  2678.         return 'Server Info Could Not Be Found, please alert us of this issue';
  2679.     }
  2680.  
  2681.     $strErrorMessageArea = 'style="display:none;"';
  2682.     $strErrorMessage = '';
  2683.     $vm = $strVMwarevSpherePassword;
  2684.     $vm->setDebug(0);
  2685.     $vm->Login();
  2686.     $strVMID = $vm->FindVMByName($strVMWareServerName);
  2687.  
  2688.     if (0 < strpos($strVMID, 'error!!')) {
  2689.         if (strlen($strVMID) < 1) {
  2690.             $strErrorMessageArea = '';
  2691.             $strErrorMessage = 'Server Info Could Not Be Retreived From VMware, please contact us.';
  2692.         }
  2693.     }
  2694.     else {
  2695.         $strErrorMessageArea = '';
  2696.         $strErrorMessage = 'Server Info Could Not Be Retreived From VMware, please contact us.';
  2697.     }
  2698.  
  2699.     $vm->Logout();
  2700.  
  2701.     if (0 < strpos($strVMWareServerName, '\\')) {
  2702.         $aryFolderVMData = explode('\\', $strVMWareServerName);
  2703.         $strVMWareServerNameDisplay = $aryFolderVMData[count($aryFolderVMData) - 1];
  2704.     }
  2705.     else {
  2706.         $strVMWareServerNameDisplay = $_LANG;
  2707.     }
  2708.  
  2709.     $pagearray = array(
  2710.         'templatefile' => 'vmconsole',
  2711.         'breadcrumb'   => ' > <a href="#">VM Console</a>',
  2712.         'vars'         => array('LANG' => $_LANG, 'servername' => $strVMWareServerNameDisplay, 'a2' => $a2, 'strErrorMessage' => $strErrorMessage, 'strErrorMessageArea' => $strErrorMessageArea)
  2713.         );
  2714.     return $pagearray;
  2715. }
  2716.  
  2717. function aisovmwarededsrv_updatevmwaretools($params)
  2718. {
  2719.     global $_LANG;
  2720.     global $mstrVMWareWebServerCustomFieldName;
  2721.     $strVMWareServerName = $params['customfields'][$mstrVMWareWebServerCustomFieldName];
  2722.  
  2723.     if (strlen($mstrVMWareWebServerCustomFieldName) < 1) {
  2724.         return 'Server Name Could Not Be Found';
  2725.     }
  2726.  
  2727.     $a2 = '';
  2728.     $intServerID = $params['serverid'];
  2729.     $select_modules = 'SELECT type,ipaddress,username,password FROM tblservers WHERE id = ' . $intServerID;
  2730.     $modules_rows = full_query($select_modules);
  2731.  
  2732.     if ($modules_rows) {
  2733.         $aryRowData = mysql_fetch_row($modules_rows);
  2734.         $strModuleName = $aryRowData[0];
  2735.         $strVMwarevSphereURL = $aryRowData[1];
  2736.         $strVMwarevSphereUsername = $aryRowData[2];
  2737.         $strVMwarevSpherePassword = decrypt($aryRowData[3]);
  2738.     }
  2739.     else {
  2740.         return 'Server Info Could Not Be Found, please alert us of this issue';
  2741.     }
  2742.  
  2743.     $vm = $strVMwarevSpherePassword;
  2744.     $vm->setDebug(0);
  2745.     $vm->Login();
  2746.     $strVMID = $vm->FindVMByName($strVMWareServerName);
  2747.  
  2748.     if (0 < strpos($strVMID, 'error!!')) {
  2749.         $strErrorMessageArea = '';
  2750.         $strErrorMessage = 'Server Info Could Not Be Retreived From VMware, please contact us.';
  2751.     }
  2752.  
  2753.     $vmDetail = $vm->RetrievePropertiesVM($strVMID, 'VirtualMachine', 'guest.toolsStatus');
  2754.     $strToolsStatus = $vmDetail['propSet']['val'];
  2755.  
  2756.     if (strtolower($strToolsStatus) == 'toolsok') {
  2757.         $strVmwareToolsStatus = $_LANG['VMwareToolsOk'];
  2758.         $intVmwareToolsStatus = 589;
  2759.     }
  2760.     else if (strtolower($strToolsStatus) == 'toolsold') {
  2761.         $strVmwareToolsStatus = $_LANG['VMwareToolsOld'];
  2762.         $intVmwareToolsStatus = 590;
  2763.     }
  2764.     else if (strtolower($strToolsStatus) == 'toolsnotinstalled') {
  2765.         $strVmwareToolsStatus = $_LANG['VMwareToolsNotInstalled'];
  2766.         $intVmwareToolsStatus = 591;
  2767.     }
  2768.     else if (strtolower($strToolsStatus) == 'toolsnotrunning') {
  2769.         $strVmwareToolsStatus = $_LANG['VMwareToolsNotRunning'];
  2770.         $intVmwareToolsStatus = 592;
  2771.     }
  2772.     else {
  2773.         $strVmwareToolsStatus = $_LANG['VMwareToolsUnknown'];
  2774.         $intVmwareToolsStatus = -1;
  2775.     }
  2776.  
  2777.     if ($intVmwareToolsStatus != 1) {
  2778.         return vmwarededsrvdisplayerrormessage($_LANG['VMwareActionFailedMsg'], $_LANG['VMwareToolsUpdateNotNeeded']);
  2779.     }
  2780.  
  2781.     $vm->Logout();
  2782.     $strErrorMessageArea = 'style="display:none;"';
  2783.     $strErrorMessage = '';
  2784.  
  2785.     if ($_POST['a2'] == 'update') {
  2786.         $vm = $strVMwarevSpherePassword;
  2787.         $vm->setDebug(0);
  2788.         $vm->Login();
  2789.         $strVMID = $vm->FindVMByName($strVMWareServerName);
  2790.  
  2791.         if (0 < strpos($strVMID, 'error!!')) {
  2792.             $strErrorMessageArea = '';
  2793.             $strErrorMessage = 'Server Info Could Not Be Retreived From VMware, please contact us.';
  2794.         }
  2795.  
  2796.         if ($strVMID != '') {
  2797.             if ($strErrorMessage == '') {
  2798.                 $vmDetail = $vm->RetrievePropertiesVM($strVMID, 'VirtualMachine', 'guest.toolsStatus');
  2799.                 $strToolsStatus = $vmDetail['propSet']['val'];
  2800.  
  2801.                 if (strtolower($strToolsStatus) == 'toolsok') {
  2802.                     $strErrorMessageArea = '';
  2803.                     $strErrorMessage = 'VMware Tools are already up to date.';
  2804.                 }
  2805.                 else if (strtolower($strToolsStatus) == 'toolsold') {
  2806.                 }
  2807.                 else if (strtolower($strToolsStatus) == 'toolsnotinstalled') {
  2808.                     $strErrorMessageArea = '';
  2809.                     $strErrorMessage = 'VMware Tools are not installed, please install the tools to do an automatic update.';
  2810.                 }
  2811.                 else if (strtolower($strToolsStatus) == 'toolsnotrunning') {
  2812.                     $strErrorMessageArea = '';
  2813.                     $strErrorMessage = 'VMware Tools are installed, but not running. Please start the VMware tools\' services to do an automatic update.';
  2814.                 }
  2815.                 else {
  2816.                     $strErrorMessageArea = '';
  2817.                     $strErrorMessage = 'VMware Tools are in an unknown state, please install the tools or check their status and correct it to do an automatic update.';
  2818.                 }
  2819.             }
  2820.         }
  2821.  
  2822.         if ($strVMID != '') {
  2823.             if ($strErrorMessage == '') {
  2824.                 $vmDetail = $vm->RetrievePropertiesVM($strVMID, 'VirtualMachine', 'runtime.powerState');
  2825.                 $strPowerState = $vmDetail['propSet']['val'];
  2826.  
  2827.                 if (strtolower($strPowerState) == 'poweredon') {
  2828.                 }
  2829.                 else {
  2830.                     $strErrorMessageArea = '';
  2831.                     $strErrorMessage = 'Server Could Not Be Soft Rebooted Because It Is Off';
  2832.                 }
  2833.             }
  2834.         }
  2835.  
  2836.         if ($strErrorMessage == '') {
  2837.             $vm->UpgradeVMwareTools($strVMID);
  2838.         }
  2839.  
  2840.         $vm->Logout();
  2841.  
  2842.         if ($strErrorMessage == '') {
  2843.             $a2 = 'update';
  2844.         }
  2845.     }
  2846.  
  2847.     if (0 < strpos($strVMWareServerName, '\\')) {
  2848.         $params;
  2849.         $strVMWareServerNameDisplay = $a2;
  2850.     }
  2851.     else {
  2852.         $strVMWareServerNameDisplay = ($intServerID = $params['serverid']);
  2853.     }
  2854.  
  2855.     $pagearray = array(
  2856.         'templatefile' => 'updatevmwaretools',
  2857.         'breadcrumb'   => ' > <a href="#">Update VMware Tools</a>',
  2858.         'vars'         => array('LANG' => $_LANG, 'servername' => $strVMWareServerNameDisplay, 'a2' => $a2, 'strErrorMessage' => $strErrorMessage, 'strErrorMessageArea' => $strErrorMessageArea)
  2859.         );
  2860.     return $pagearray;
  2861. }
  2862.  
  2863. function aisovmwarededsrv_mountvmwaretools($params)
  2864. {
  2865.     global $_LANG;
  2866.     global $mstrVMWareWebServerCustomFieldName;
  2867.     $strVMWareServerName = $params['customfields'][$mstrVMWareWebServerCustomFieldName];
  2868.  
  2869.     if (strlen($mstrVMWareWebServerCustomFieldName) < 1) {
  2870.         return 'Server Name Could Not Be Found';
  2871.     }
  2872.  
  2873.     $a2 = '';
  2874.     $intServerID = $params['serverid'];
  2875.     $select_modules = 'SELECT type,ipaddress,username,password FROM tblservers WHERE id = ' . $intServerID;
  2876.     $modules_rows = full_query($select_modules);
  2877.  
  2878.     if ($modules_rows) {
  2879.         $aryRowData = mysql_fetch_row($modules_rows);
  2880.         $strModuleName = $aryRowData[0];
  2881.         $strVMwarevSphereURL = $aryRowData[1];
  2882.         $strVMwarevSphereUsername = $aryRowData[2];
  2883.         $strVMwarevSpherePassword = decrypt($aryRowData[3]);
  2884.     }
  2885.     else {
  2886.         return 'Server Info Could Not Be Found, please alert us of this issue';
  2887.     }
  2888.  
  2889.     $strErrorMessageArea = 'style="display:none;"';
  2890.     $strErrorMessage = '';
  2891.  
  2892.     if ($_POST['a2'] == 'mount') {
  2893.         $params;
  2894.         $vm->setDebug(0);
  2895.         $vm->Login();
  2896.         $strVMID = $select_modules;
  2897.  
  2898.         if (0 < strpos($strVMID, 'error!!')) {
  2899.             if (strlen($strVMID) < 1) {
  2900.                 $strErrorMessageArea = '';
  2901.                 $strErrorMessage = 'Server Info Could Not Be Retreived From VMware, please contact us.';
  2902.             }
  2903.         }
  2904.         else {
  2905.             $strErrorMessageArea = '';
  2906.             $strErrorMessage = 'Server Info Could Not Be Retreived From VMware, please contact us.';
  2907.         }
  2908.  
  2909.         if ($strVMID != '') {
  2910.             if ($strErrorMessage == '') {
  2911.                 $vmDetail = $strVMwarevSpherePassword;
  2912.                 $strPowerState = $strErrorMessageArea;
  2913.  
  2914.                 if (strtolower($strPowerState) == 'poweredon') {
  2915.                 }
  2916.                 else {
  2917.                     $strErrorMessageArea = '';
  2918.                     $strErrorMessage = 'Could not mount CDROM VMware Tools since VM Is Powred Off';
  2919.                 }
  2920.             }
  2921.         }
  2922.  
  2923.         if ($strErrorMessage == '') {
  2924.             $vm->MountVMwareTools($strVMID);
  2925.         }
  2926.  
  2927.         $vm->Logout();
  2928.  
  2929.         if ($strErrorMessage == '') {
  2930.             $a2 = 'mount';
  2931.         }
  2932.     }
  2933.  
  2934.     if (0 < strpos($strVMWareServerName, '\\')) {
  2935.         $aryFolderVMData = $strVMID;
  2936.         $strVMWareServerNameDisplay = $aryFolderVMData[count($aryFolderVMData) - 1];
  2937.     }
  2938.     else {
  2939.         $strVMWareServerNameDisplay = $strVMID;
  2940.     }
  2941.  
  2942.     $pagearray = array(
  2943.         'templatefile' => 'mountvmwaretools',
  2944.         'breadcrumb'   => ' > <a href="#">' . $_LANG['VMwareMountVMwareToolsLink'] . '</a>',
  2945.         'vars'         => array('LANG' => $_LANG, 'servername' => $strVMWareServerNameDisplay, 'a2' => $a2, 'strErrorMessage' => $strErrorMessage, 'strErrorMessageArea' => $strErrorMessageArea)
  2946.         );
  2947.     return $pagearray;
  2948. }
  2949.  
  2950. function aisovmwarededsrv_unmountvmwaretools($params)
  2951. {
  2952.     global $_LANG;
  2953.     global $mstrVMWareWebServerCustomFieldName;
  2954.     $strVMWareServerName = $params['customfields'][$mstrVMWareWebServerCustomFieldName];
  2955.  
  2956.     if (strlen($mstrVMWareWebServerCustomFieldName) < 1) {
  2957.         return 'Server Name Could Not Be Found';
  2958.     }
  2959.  
  2960.     $a2 = '';
  2961.     $intServerID = $params['serverid'];
  2962.     $select_modules = 'SELECT type,ipaddress,username,password FROM tblservers WHERE id = ' . $intServerID;
  2963.     $modules_rows = full_query($select_modules);
  2964.  
  2965.     if ($modules_rows) {
  2966.         $aryRowData = mysql_fetch_row($modules_rows);
  2967.         $strModuleName = $aryRowData[0];
  2968.         $strVMwarevSphereURL = $aryRowData[1];
  2969.         $strVMwarevSphereUsername = $aryRowData[2];
  2970.         $strVMwarevSpherePassword = decrypt($aryRowData[3]);
  2971.     }
  2972.     else {
  2973.         return 'Server Info Could Not Be Found, please alert us of this issue';
  2974.     }
  2975.  
  2976.     $strErrorMessageArea = 'style="display:none;"';
  2977.     $strErrorMessage = '';
  2978.  
  2979.     if ($_POST['a2'] == 'unmount') {
  2980.         $params;
  2981.         $vm->setDebug(0);
  2982.         $vm->Login();
  2983.         $strVMID = $select_modules;
  2984.  
  2985.         if (0 < strpos($strVMID, 'error!!')) {
  2986.             if (strlen($strVMID) < 1) {
  2987.                 $strErrorMessageArea = '';
  2988.                 $strErrorMessage = 'Server Info Could Not Be Retreived From VMware, please contact us.';
  2989.             }
  2990.         }
  2991.         else {
  2992.             $strErrorMessageArea = '';
  2993.             $strErrorMessage = 'Server Info Could Not Be Retreived From VMware, please contact us.';
  2994.         }
  2995.  
  2996.         if ($strVMID != '') {
  2997.             if ($strErrorMessage == '') {
  2998.                 $vmDetail = $strVMwarevSpherePassword;
  2999.                 $strPowerState = $strErrorMessageArea;
  3000.  
  3001.                 if (strtolower($strPowerState) == 'poweredon') {
  3002.                 }
  3003.                 else {
  3004.                     $strErrorMessageArea = '';
  3005.                     $strErrorMessage = 'Could not unmount CDROM VMware Tools since VM Is Powred Off';
  3006.                 }
  3007.             }
  3008.         }
  3009.  
  3010.         if ($strErrorMessage == '') {
  3011.             $vm->UnMountVMwareTools($strVMID);
  3012.         }
  3013.  
  3014.         $vm->Logout();
  3015.  
  3016.         if ($strErrorMessage == '') {
  3017.             $a2 = 'unmount';
  3018.         }
  3019.     }
  3020.  
  3021.     if (0 < strpos($strVMWareServerName, '\\')) {
  3022.         $aryFolderVMData = $strVMID;
  3023.         $strVMWareServerNameDisplay = $aryFolderVMData[count($aryFolderVMData) - 1];
  3024.     }
  3025.     else {
  3026.         $strVMWareServerNameDisplay = $strVMID;
  3027.     }
  3028.  
  3029.     $pagearray = array(
  3030.         'templatefile' => 'unmountvmwaretools',
  3031.         'breadcrumb'   => ' > <a href="#">' . $_LANG['VMwareUnmountVMwareToolsLink'] . '</a>',
  3032.         'vars'         => array('LANG' => $_LANG, 'servername' => $strVMWareServerNameDisplay, 'a2' => $a2, 'strErrorMessage' => $strErrorMessage, 'strErrorMessageArea' => $strErrorMessageArea)
  3033.         );
  3034.     return $pagearray;
  3035. }
  3036.  
  3037. function aisovmwarededsrv_managednszonefiles($params)
  3038. {
  3039.     global $_LANG;
  3040.     global $mstrVMWareWebServerCustomFieldName;
  3041.     $strVMWareServerName = $params['customfields'][$mstrVMWareWebServerCustomFieldName];
  3042.  
  3043.     if (strlen($mstrVMWareWebServerCustomFieldName) < 1) {
  3044.         return 'Server Name Could Not Be Found';
  3045.     }
  3046.  
  3047.     $a2 = '';
  3048.     $strErrorMessage = '';
  3049.     $strErrorMessageArea = '';
  3050.  
  3051.     if (0 < strpos($strVMWareServerName, '\\')) {
  3052.         $aryFolderVMData = $_LANG;
  3053.         $params;
  3054.     }
  3055.     else {
  3056.         $strVMWareServerNameDisplay = strlen($mstrVMWareWebServerCustomFieldName);
  3057.     }
  3058.  
  3059.     if (is_numeric($_GET['sm'])) {
  3060.         $intStatusMessage = $_GET['sm'];
  3061.     }
  3062.     else {
  3063.         $intStatusMessage = '0';
  3064.     }
  3065.  
  3066.     $pagearray = array(
  3067.         'templatefile' => 'managednszonefiles',
  3068.         'breadcrumb'   => ' > <a href="#">' . $_LANG['VMwareManageDNSZoneFilesLink'] . '</a>',
  3069.         'vars'         => array('LANG' => $_LANG, 'servername' => $strVMWareServerNameDisplay, 'a2' => $a2, 'strErrorMessage' => $strErrorMessage, 'strErrorMessageArea' => $strErrorMessageArea, 'intStatusMessage' => $intStatusMessage)
  3070.         );
  3071.     return $pagearray;
  3072. }
  3073.  
  3074. function aisovmwarededsrv_editdnszonefiles($params)
  3075. {
  3076.     global $_LANG;
  3077.     global $mstrVMWareWebServerCustomFieldName;
  3078.     global $gstrPrimaryDNSServerName;
  3079.     global $gstrSecondaryDNSServerName;
  3080.     $strVMWareServerName = $params['customfields'][$mstrVMWareWebServerCustomFieldName];
  3081.  
  3082.     if (strlen($mstrVMWareWebServerCustomFieldName) < 1) {
  3083.         return 'Server Name Could Not Be Found';
  3084.     }
  3085.  
  3086.     $a2 = '';
  3087.     $strErrorMessage = '';
  3088.     $strErrorMessageArea = '';
  3089.  
  3090.     if (0 < strpos($strVMWareServerName, '\\')) {
  3091.         $aryFolderVMData = explode('\\', $strVMWareServerName);
  3092.         $strVMWareServerNameDisplay = $aryFolderVMData[count($aryFolderVMData) - 1];
  3093.     }
  3094.     else {
  3095.         $strVMWareServerNameDisplay = $strVMWareServerName;
  3096.     }
  3097.  
  3098.     $intUserID = $params['clientsdetails']['id'];
  3099.     $intServiceID = $params['serviceid'];
  3100.  
  3101.     if (isset($_POST['a2'])) {
  3102.         $strAction = $_POST['a2'];
  3103.     }
  3104.     else {
  3105.         $strAction = $_GET['a2'];
  3106.     }
  3107.  
  3108.     if (isset($_POST['dzrid'])) {
  3109.         $intDomainRID = $_POST['dzrid'];
  3110.     }
  3111.     else {
  3112.         $intDomainRID = $_GET['dzrid'];
  3113.     }
  3114.  
  3115.     if (!is_numeric($intDomainRID)) {
  3116.         $intDomainRID = $_POST['zone'];
  3117.     }
  3118.  
  3119.     if (!is_numeric($intDomainRID)) {
  3120.         $intDomainRID = 3019;
  3121.     }
  3122.     else {
  3123.         $intDomainRID = (int) $intDomainRID;
  3124.     }
  3125.  
  3126.     require_once dirname(dirname(dirname(dirname(__FILE__)))) . '/includes/aiso-functions.php';
  3127.  
  3128.     if ($strAction == 's') {
  3129.         if ($strAction == 'g') {
  3130.             $table = 'tblaisodnsrecords';
  3131.             $fields = 'id,txtDomainName';
  3132.             $where = array('id' => $intDomainRID, 'tblclients_id' => $intUserID);
  3133.             $result = select_query($table, $fields, $where, $sort, $sortorder, $limits, $join);
  3134.             $data = mysql_fetch_array($result);
  3135.             $intDomainNameRID = $data[0];
  3136.             $strDomainName = $data[1];
  3137.  
  3138.             if (2 < strlen($strDomainName)) {
  3139.                 $aryTypeData = array();
  3140.  
  3141.                 foreach ($_POST as $name => $value) {
  3142.                     if (substr(strtoupper($name), 0, 4) == 'TYPE') {
  3143.                         $intTypeNumber = (int) substr($name, 4);
  3144.  
  3145.                         if (empty($_POST['delete' . $intTypeNumber])) {
  3146.                             $aryTypeData[$intTypeNumber] = array('typevalue' => $value, 'namevalue' => $_POST['name' . $intTypeNumber], 'datavalue' => $_POST['data' . $intTypeNumber]);
  3147.                         }
  3148.                     }
  3149.                 }
  3150.  
  3151.                 foreach ($aryTypeData as $aryTypeDataItem) {
  3152.                     if (0 < strlen($aryTypeDataItem['typevalue'])) {
  3153.                         if (strtoupper($aryTypeDataItem['typevalue']) == 'MX') {
  3154.                             if (0 < strpos($aryTypeDataItem['datavalue'], ' ')) {
  3155.                                 $aryMXData = explode(' ', $aryTypeDataItem['datavalue']);
  3156.  
  3157.                                 if (CheckForValidNumbers($aryMXData[0]) == true) {
  3158.                                     if (CheckForValidRecordData($aryMXData[1]) == true) {
  3159.                                         $strMXDataToSend = $strMXDataToSend . '@|MX|' . $aryMXData[0] . '|' . $aryMXData[1] . '^';
  3160.                                     }
  3161.                                     else {
  3162.                                         $strAction = 'e';
  3163.                                         $strErrorMessage = 'The MX record "Data" MX server you have entered is invalid. Please make sure its valid and in the format "XX mxserver.com" where XX is the numerical MX preference, then a space, then the MX server host name. Valid characters for the mx server are letters, numbers, a period (.) or a hyphen (-).';
  3164.                                     }
  3165.                                 }
  3166.                                 else {
  3167.                                     $strAction = 'e';
  3168.                                     $strErrorMessage = 'The MX record "Data" MX preference you have entered is invalid, please make sure its a number. Please make sure its valid and in the format "XX mxserver.com" where XX is the numerical MX preference, then a space, then the MX server host name. Valid characters for the mx server are letters, numbers, a period (.) or a hyphen (-).';
  3169.                                 }
  3170.                             }
  3171.                         }
  3172.                         else if (strtoupper($aryTypeDataItem['typevalue']) == 'A') {
  3173.                             $strAName = $aryTypeDataItem['namevalue'];
  3174.  
  3175.                             if (strtoupper($strAName) == strtoupper($strDomainName)) {
  3176.                                 $strAName = '@';
  3177.                             }
  3178.  
  3179.                             if (CheckForValidARecordNameData($aryTypeDataItem['namevalue']) == true) {
  3180.                                 if ($strAName == '@') {
  3181.                                     if (CheckForValidRecordData($aryTypeDataItem['datavalue']) == true) {
  3182.                                         if ($strAction == 'g') {
  3183.                                         }
  3184.                                         else if (preg_match('/^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})$/', $aryTypeDataItem['datavalue'])) {
  3185.                                             if (IsValidIPAddress($aryTypeDataItem['datavalue']) == true) {
  3186.                                                 $strADataToSend = $strADataToSend . $strAName . '|A|' . $aryTypeDataItem['datavalue'] . '^';
  3187.                                             }
  3188.                                             else {
  3189.                                                 $strAction = 'e';
  3190.                                                 $strErrorMessage = 'The A record "Data" IP address you have entered is invalid, please put in a valid IP address.';
  3191.                                             }
  3192.                                         }
  3193.                                         else {
  3194.                                             $strAction = 'e';
  3195.                                             $strErrorMessage = 'The A record "Data" you have entered is invalid, valid characters are letters, numbers, a period (.) or a hyphen (-).';
  3196.                                         }
  3197.                                     }
  3198.                                     else {
  3199.                                         $strAction = 'e';
  3200.                                         $strErrorMessage = 'The A record "Data" you have entered is invalid, valid characters are letters, numbers, a period (.) or a hyphen (-).';
  3201.                                     }
  3202.                                 }
  3203.                             }
  3204.                             else {
  3205.                                 $strADataToSend = $strADataToSend . $strAName . '|A|' . $aryTypeDataItem['datavalue'] . '^';
  3206.                                 $strAction = 'e';
  3207.                                 $strErrorMessage = 'The A record "Data" IP address you have entered is invalid, please put in a valid IP address.';
  3208.                                 $strAction = 'e';
  3209.                                 $strErrorMessage = 'The A record "Data" you have entered is invalid, valid characters are letters, numbers, a period (.) or a hyphen (-).';
  3210.                                 $strAction = 'e';
  3211.                                 $strErrorMessage = 'The A record "Data" you have entered is invalid, valid characters are letters, numbers, a period (.) or a hyphen (-).';
  3212.                                 $strAction = 'e';
  3213.                                 $strErrorMessage = 'The A record "Name" you have entered is invalid, valid characters are letters, numbers, a period (.) or a hyphen (-).';
  3214.                             }
  3215.                         }
  3216.                         else if (strtoupper($aryTypeDataItem['typevalue']) == 'CNAME') {
  3217.                             if (CheckForValidNameData($aryTypeDataItem['namevalue']) == true) {
  3218.                                 if (CheckForValidRecordData($aryTypeDataItem['datavalue']) == true) {
  3219.                                     $strADataToSend = $strADataToSend . $aryTypeDataItem['namevalue'] . '|CNAME|' . $aryTypeDataItem['datavalue'] . '^';
  3220.                                 }
  3221.                                 else {
  3222.                                     $strAction = 'e';
  3223.                                     $strErrorMessage = 'The CNAME record "Data" you have entered is invalid, valid characters are letters, numbers, a period (.) or a hyphen (-).';
  3224.                                 }
  3225.                             }
  3226.                             else {
  3227.                                 $strAction = 'e';
  3228.                                 $strErrorMessage = 'The CNAME record "Name" you have entered is invalid, valid characters are letters, numbers, a period (.) or a hyphen (-).';
  3229.                             }
  3230.                         }
  3231.                         else if (strtoupper($aryTypeDataItem['typevalue']) == 'TXT') {
  3232.                             $strAName = $aryTypeDataItem['namevalue'];
  3233.  
  3234.                             if (strtoupper($strAName) == strtoupper($strDomainName)) {
  3235.                                 if (substr($strAName, -1) != '.') {
  3236.                                     $strAName = $strAName . '.';
  3237.                                 }
  3238.                             }
  3239.  
  3240.                             if (CheckForValidNameDataForTXT($strAName) == true) {
  3241.                                 $strDataValue = str_replace('&quot;', '"', $aryTypeDataItem['datavalue']);
  3242.  
  3243.                                 if (CheckForValidTXTData($strDataValue) == true) {
  3244.                                     if (substr($strDataValue, 0, 1) == '"') {
  3245.                                         $strADataToSend = $strADataToSend . $strAName . '|TXT|' . $strDataValue . '^';
  3246.                                     }
  3247.                                     else {
  3248.                                         $strADataToSend = $strADataToSend . $strAName . '|TXT|"' . $strDataValue . '"^';
  3249.                                     }
  3250.                                 }
  3251.                                 else {
  3252.                                     $strAction = 'e';
  3253.                                     $strErrorMessage = 'The TXT record "Data" you have entered is invalid, valid characters are letters, numbers, underscore (_), period (.), colon (:), equal (=), forward slash (/), tilde (~), space ( ), semi-colon (;), asterisk (*), question mark (?), plus (+), double quote (""), or a hyphen (-).';
  3254.                                 }
  3255.                             }
  3256.                             else {
  3257.                                 $strAction = 'e';
  3258.                                 $strErrorMessage = 'The TXT record "Name" you have entered is invalid, valid characters are letters, numbers, a underscore (_), a period (.) or a hyphen (-).';
  3259.                             }
  3260.                         }
  3261.                     }
  3262.                 }
  3263.  
  3264.                 if ($strAction == 'g') {
  3265.                     $strMXDataToSend = '@|MX|1|ASPMX.L.GOOGLE.COM.^@|MX|5|ALT1.ASPMX.L.GOOGLE.COM.^@|MX|5|ALT2.ASPMX.L.GOOGLE.COM.^@|MX|10|ASPMX2.GOOGLEMAIL.COM.^@|MX|10|ASPMX3.GOOGLEMAIL.COM.^@|MX|10|ASPMX4.GOOGLEMAIL.COM.^@|MX|10|ASPMX5.GOOGLEMAIL.COM.^';
  3266.  
  3267.                     if (substr($strADataToSend, -1) == '^') {
  3268.                         $strADataToSend = $strADataToSend . 'webmail|CNAME|ghs.google.com.^mail|CNAME|ghs.google.com.^';
  3269.                     }
  3270.                     else {
  3271.                         $strADataToSend = $strADataToSend . '^webmail|CNAME|ghs.google.com.^mail|CNAME|ghs.google.com.^';
  3272.                     }
  3273.                 }
  3274.  
  3275.                 if ($strErrorMessage == '') {
  3276.                     $strPrimaryDNSServer = $GLOBALS['smarty']->_tpl_vars['serverdata']['nameserver1'];
  3277.  
  3278.                     if (empty($strPrimaryDNSServer)) {
  3279.                         $strPrimaryDNSServer = $gstrPrimaryDNSServerName;
  3280.                     }
  3281.  
  3282.                     $table = 'tblservers';
  3283.                     $fields = 'localipaddress';
  3284.                     $where = array('hostname' => $strPrimaryDNSServer);
  3285.                     $result = select_query($table, $fields, $where, $sort, $sortorder, $limits, $join);
  3286.                     $data = mysql_fetch_array($result);
  3287.                     $strPrimaryDNSServerIPAddress = $data[0];
  3288.                     $strSecondaryDNSServer = $GLOBALS['smarty']->_tpl_vars['serverdata']['nameserver2'];
  3289.  
  3290.                     if (empty($strSecondaryDNSServer)) {
  3291.                         $strSecondaryDNSServer = $gstrSecondaryDNSServerName;
  3292.                     }
  3293.  
  3294.                     $table = 'tblservers';
  3295.                     $fields = 'localipaddress';
  3296.                     $where = array('hostname' => $strSecondaryDNSServer);
  3297.                     $result = select_query($table, $fields, $where, $sort, $sortorder, $limits, $join);
  3298.                     $data = mysql_fetch_array($result);
  3299.                     $strSecondaryDNSServerIPAddress = $data[0];
  3300.                     $strDNSRecordSaveResult = SendDataToAISOCPService($strPrimaryDNSServerIPAddress, 'REWRITEDNSRECORDENTRIES§' . $strDomainName . '§' . $strPrimaryDNSServer . '§' . $strADataToSend . '§true');
  3301.  
  3302.                     if (0 < strpos(strtolower($strDNSRecordSaveResult), 'dns data saved')) {
  3303.                         $strDNSRecordSaveResult = SendDataToAISOCPService($strPrimaryDNSServerIPAddress, 'REWRITEDNSRECORDMXENTRIES§' . $strDomainName . '§' . $strPrimaryDNSServer . '§' . $strMXDataToSend);
  3304.  
  3305.                         if (0 < strpos(strtolower($strDNSRecordSaveResult), 'dns data saved')) {
  3306.                             $strDNSRecordSaveResult = SendDataToAISOCPService($strPrimaryDNSServerIPAddress, 'RESTARTDNSSERVER§');
  3307.  
  3308.                             if (0 < strpos(strtolower($strDNSRecordSaveResult), 'restarted successfully')) {
  3309.                                 $strDNSRecordSaveResult = SendDataToAISOCPService($strSecondaryDNSServerIPAddress, 'RESTARTSECONDARYDNSSERVERANDDELETEZONEFILE§' . $strDomainName . '§' . $strSecondaryDNSServer . '§');
  3310.                                 $strURLToRedirectTo = 'clientarea.php?action=productdetails&id=' . $intServiceID . '&modop=custom&a=managednszonefiles&sm=2';
  3311.                             }
  3312.                             else {
  3313.                                 $strURLToRedirectTo = 'clientarea.php?action=productdetails&id=' . $intServiceID . '&modop=custom&a=editdnszonefiles&a2=e&dzrid=' . $intDomainNameRID . '&error=10';
  3314.                             }
  3315.                         }
  3316.                         else {
  3317.                             $strURLToRedirectTo = 'clientarea.php?action=productdetails&id=' . $intServiceID . '&modop=custom&a=editdnszonefiles&a2=e&dzrid=' . $intDomainNameRID . '&error=11';
  3318.                         }
  3319.                     }
  3320.                     else {
  3321.                         $strURLToRedirectTo = 'clientarea.php?action=productdetails&id=' . $intServiceID . '&modop=custom&a=editdnszonefiles&a2=e&dzrid=' . $intDomainNameRID . '&error=12';
  3322.                     }
  3323.  
  3324.                     $aryCurrentURL = explode('clientarea.php', GetCurrentURL());
  3325.  
  3326.                     if (substr($aryCurrentURL[0], -1) == '/') {
  3327.                         $strCurrentURL = substr($aryCurrentURL[0], 0, strlen($aryCurrentURL[0]) - 1);
  3328.                     }
  3329.                     else {
  3330.                         $strCurrentURL = $aryCurrentURL[0];
  3331.                     }
  3332.  
  3333.                     Header('HTTP/1.1 301 Moved Permanently');
  3334.                     Header('Location: ' . $strCurrentURL . '/' . $strURLToRedirectTo);
  3335.                     exit();
  3336.                 }
  3337.             }
  3338.             else {
  3339.                 print('Domain not found');
  3340.                 exit();
  3341.             }
  3342.         }
  3343.     }
  3344.     else {
  3345.         $table = 'tblaisodnsrecords';
  3346.         $fields = 'id,txtDomainName';
  3347.         $where = array('id' => $intDomainRID, 'tblclients_id' => $intUserID);
  3348.         $result = 'Location: ' . $strCurrentURL . '/' . $strURLToRedirectTo;
  3349.         $data = 'Location: ' . $strCurrentURL . '/' . $strURLToRedirectTo;
  3350.         $intDomainNameRID = 'Location: ' . $strCurrentURL . '/' . $strURLToRedirectTo;
  3351.         $strDomainName = 'Location: ' . $strCurrentURL . '/' . $strURLToRedirectTo;
  3352.         $aryTypeData = array();
  3353.         $value = 'Location: ' . $strCurrentURL . '/' . $strURLToRedirectTo;
  3354.         $name = 'Location: ' . $strCurrentURL . '/' . $strURLToRedirectTo;
  3355.         $intTypeNumber = (int) substr($name, 4);
  3356.         $aryTypeData[$intTypeNumber] = array('typevalue' => $value, 'namevalue' => $_POST['name' . $intTypeNumber], 'datavalue' => $_POST['data' . $intTypeNumber]);
  3357.         $aryTypeDataItem = 'Location: ' . $strCurrentURL . '/' . $strURLToRedirectTo;
  3358.         $aryMXData = 'Location: ' . $strCurrentURL . '/' . $strURLToRedirectTo;
  3359.         $strMXDataToSend = $strMXDataToSend . '@|MX|' . $aryMXData[0] . '|' . $aryMXData[1] . '^';
  3360.         $strAction = 'e';
  3361.         $strErrorMessage = 'The MX record "Data" MX server you have entered is invalid. Please make sure its valid and in the format "XX mxserver.com" where XX is the numerical MX preference, then a space, then the MX server host name. Valid characters for the mx server are letters, numbers, a period (.) or a hyphen (-).';
  3362.         $strAction = 'e';
  3363.         $strErrorMessage = 'The MX record "Data" MX preference you have entered is invalid, please make sure its a number. Please make sure its valid and in the format "XX mxserver.com" where XX is the numerical MX preference, then a space, then the MX server host name. Valid characters for the mx server are letters, numbers, a period (.) or a hyphen (-).';
  3364.         $strAName = 'Location: ' . $strCurrentURL . '/' . $strURLToRedirectTo;
  3365.         $strAName = '@';
  3366.  
  3367.         $strADataToSend = $strADataToSend . $strAName . '|A|' . $aryTypeDataItem['datavalue'] . '^';
  3368.         $strAction = 'e';
  3369.         $strErrorMessage = 'The A record "Data" IP address you have entered is invalid, please put in a valid IP address.';
  3370.         $strAction = 'e';
  3371.         $strErrorMessage = 'The A record "Data" you have entered is invalid, valid characters are letters, numbers, a period (.) or a hyphen (-).';
  3372.         $strAction = 'e';
  3373.         $strErrorMessage = 'The A record "Data" you have entered is invalid, valid characters are letters, numbers, a period (.) or a hyphen (-).';
  3374.         $strAction = 'e';
  3375.         $strErrorMessage = 'The A record "Name" you have entered is invalid, valid characters are letters, numbers, a period (.) or a hyphen (-).';
  3376.         $strADataToSend = $strADataToSend . $aryTypeDataItem['namevalue'] . '|CNAME|' . $aryTypeDataItem['datavalue'] . '^';
  3377.         $strAction = 'e';
  3378.         $strErrorMessage = 'The CNAME record "Data" you have entered is invalid, valid characters are letters, numbers, a period (.) or a hyphen (-).';
  3379.         $strAction = 'e';
  3380.         $strErrorMessage = 'The CNAME record "Name" you have entered is invalid, valid characters are letters, numbers, a period (.) or a hyphen (-).';
  3381.         $strAName = 'Location: ' . $strCurrentURL . '/' . $strURLToRedirectTo;
  3382.         $strAName = $strAName . '.';
  3383.         $strDataValue = 'Location: ' . $strCurrentURL . '/' . $strURLToRedirectTo;
  3384.  
  3385.         $strADataToSend = $strADataToSend . $strAName . '|TXT|' . $strDataValue . '^';
  3386.  
  3387.         $strADataToSend = $strADataToSend . $strAName . '|TXT|"' . $strDataValue . '"^';
  3388.         $strAction = 'e';
  3389.         $strErrorMessage = 'The TXT record "Data" you have entered is invalid, valid characters are letters, numbers, underscore (_), period (.), colon (:), equal (=), forward slash (/), tilde (~), space ( ), semi-colon (;), asterisk (*), question mark (?), plus (+), double quote (""), or a hyphen (-).';
  3390.         $strAction = 'e';
  3391.         $strErrorMessage = 'The TXT record "Name" you have entered is invalid, valid characters are letters, numbers, a underscore (_), a period (.) or a hyphen (-).';
  3392.         $strMXDataToSend = '@|MX|1|ASPMX.L.GOOGLE.COM.^@|MX|5|ALT1.ASPMX.L.GOOGLE.COM.^@|MX|5|ALT2.ASPMX.L.GOOGLE.COM.^@|MX|10|ASPMX2.GOOGLEMAIL.COM.^@|MX|10|ASPMX3.GOOGLEMAIL.COM.^@|MX|10|ASPMX4.GOOGLEMAIL.COM.^@|MX|10|ASPMX5.GOOGLEMAIL.COM.^';
  3393.         $strADataToSend = $strADataToSend . 'webmail|CNAME|ghs.google.com.^mail|CNAME|ghs.google.com.^';
  3394.         $strADataToSend = $strADataToSend . '^webmail|CNAME|ghs.google.com.^mail|CNAME|ghs.google.com.^';
  3395.         $strPrimaryDNSServer = 'Location: ' . $strCurrentURL . '/' . $strURLToRedirectTo;
  3396.         $strPrimaryDNSServer = 'Location: ' . $strCurrentURL . '/' . $strURLToRedirectTo;
  3397.         $table = 'tblservers';
  3398.         $fields = 'localipaddress';
  3399.         $where = array('hostname' => $strPrimaryDNSServer);
  3400.         $result = 'Location: ' . $strCurrentURL . '/' . $strURLToRedirectTo;
  3401.         $data = 'Location: ' . $strCurrentURL . '/' . $strURLToRedirectTo;
  3402.         $strPrimaryDNSServerIPAddress = 'Location: ' . $strCurrentURL . '/' . $strURLToRedirectTo;
  3403.         $strSecondaryDNSServer = 'Location: ' . $strCurrentURL . '/' . $strURLToRedirectTo;
  3404.         $strSecondaryDNSServer = 'Location: ' . $strCurrentURL . '/' . $strURLToRedirectTo;
  3405.         $table = 'tblservers';
  3406.         $fields = 'localipaddress';
  3407.         $where = array('hostname' => $strSecondaryDNSServer);
  3408.         $result = 'Location: ' . $strCurrentURL . '/' . $strURLToRedirectTo;
  3409.         $data = 'Location: ' . $strCurrentURL . '/' . $strURLToRedirectTo;
  3410.         $strSecondaryDNSServerIPAddress = 'Location: ' . $strCurrentURL . '/' . $strURLToRedirectTo;
  3411.         $strDNSRecordSaveResult = 'Location: ' . $strCurrentURL . '/' . $strURLToRedirectTo;
  3412.         $strDNSRecordSaveResult = 'Location: ' . $strCurrentURL . '/' . $strURLToRedirectTo;
  3413.         $strDNSRecordSaveResult = 'Location: ' . $strCurrentURL . '/' . $strURLToRedirectTo;
  3414.         $strDNSRecordSaveResult = 'Location: ' . $strCurrentURL . '/' . $strURLToRedirectTo;
  3415.         $strURLToRedirectTo = 'clientarea.php?action=productdetails&id=' . $intServiceID . '&modop=custom&a=managednszonefiles&sm=2';
  3416.         $strURLToRedirectTo = 'clientarea.php?action=productdetails&id=' . $intServiceID . '&modop=custom&a=editdnszonefiles&a2=e&dzrid=' . $intDomainNameRID . '&error=10';
  3417.         $strURLToRedirectTo = 'clientarea.php?action=productdetails&id=' . $intServiceID . '&modop=custom&a=editdnszonefiles&a2=e&dzrid=' . $intDomainNameRID . '&error=11';
  3418.         $strURLToRedirectTo = 'clientarea.php?action=productdetails&id=' . $intServiceID . '&modop=custom&a=editdnszonefiles&a2=e&dzrid=' . $intDomainNameRID . '&error=12';
  3419.         $aryCurrentURL = 'Location: ' . $strCurrentURL . '/' . $strURLToRedirectTo;
  3420.         $strCurrentURL = 'Location: ' . $strCurrentURL . '/' . $strURLToRedirectTo;
  3421.         $strCurrentURL = 'Location: ' . $strCurrentURL . '/' . $strURLToRedirectTo;
  3422.         Header('HTTP/1.1 301 Moved Permanently');
  3423.         Header('Location: ' . $strCurrentURL . '/' . $strURLToRedirectTo);
  3424.         exit();
  3425.         print('Domain not found');
  3426.         exit();
  3427.  
  3428.         if ($strAction == 'r') {
  3429.             $table = 'tblaisodnsrecords';
  3430.             $fields = 'id,txtDomainName';
  3431.             $where = array('id' => $intDomainRID, 'tblclients_id' => $intUserID);
  3432.             $result = select_query($table, $fields, $where, $sort, $sortorder, $limits, $join);
  3433.             $data = mysql_fetch_array($result);
  3434.             $intDomainNameRID = $data[0];
  3435.             $strDomainName = $data[1];
  3436.             $strActionText = $_LANG['VMwareEditZoneRecord'];
  3437.  
  3438.             if (2 < strlen($strDomainName)) {
  3439.             }
  3440.             else {
  3441.                 print('Domain not found');
  3442.                 exit();
  3443.             }
  3444.         }
  3445.         else if ($strAction == 'cajax') {
  3446.             $szXmlRequest = file_get_contents('php://input');
  3447.             $objXmlDOM = new nDOMDocument();
  3448.             $objXmlDOM->loadXML($szXmlRequest);
  3449.  
  3450.             if ($objXmlDOM->childNodes->length < 1) {
  3451.                 print('Invalid XML Request String: ' . $szXmlRequest);
  3452.                 exit();
  3453.             }
  3454.  
  3455.             $objRoot = $objXmlDOM->selectSingleNode('//DNSZoneSetting');
  3456.  
  3457.             if (empty($objRoot)) {
  3458.                 print('Invalid XML Request String (node not found): ' . $szXmlRequest);
  3459.                 exit();
  3460.             }
  3461.  
  3462.             if (strlen($objRoot->getAttribute('DATA')) < 1) {
  3463.                 print('No Data');
  3464.                 exit();
  3465.             }
  3466.  
  3467.             if (CheckForValidRecordData($objRoot->getAttribute('DATA')) == False) {
  3468.                 print('Invalid Data');
  3469.                 exit();
  3470.             }
  3471.  
  3472.             $table = 'tblaisodnsrecordsettings';
  3473.             $fields = 'id';
  3474.             $where = array('tblclients_id' => $intUserID);
  3475.             $result = select_query($table, $fields, $where, $sort, $sortorder, $limits, $join);
  3476.             $data = mysql_fetch_array($result);
  3477.             $intRecordID = $data[0];
  3478.  
  3479.             if (is_numeric($intRecordID)) {
  3480.                 $intRecordID = (int) $intRecordID;
  3481.             }
  3482.             else {
  3483.                 $intRecordID = 3019;
  3484.             }
  3485.  
  3486.             if ($intRecordID < 1) {
  3487.                 $array = array('tblclients_id' => $intUserID);
  3488.                 $intRecordID = $GLOBALS['mstrVMWareWebServerCustomFieldName'];
  3489.             }
  3490.  
  3491.             $strNewDataToWorkWith = $strVMWareServerName;
  3492.  
  3493.             if (0 < $intRecordID) {
  3494.                 if ($_GET['t'] == '1') {
  3495.                     $strFieldName = 'txtPrimaryDNSServer';
  3496.                 }
  3497.                 else if ($_GET['t'] == '2') {
  3498.                     $strFieldName = 'txtSecondaryDNSServer';
  3499.                 }
  3500.                 else if ($_GET['t'] == '3') {
  3501.                     $strFieldName = 'txtPrimaryMXServer';
  3502.                 }
  3503.                 else if ($_GET['t'] == '4') {
  3504.                     $strFieldName = 'txtSecondaryMXServer';
  3505.                 }
  3506.                 else if ($_GET['t'] == '5') {
  3507.                     $strFieldName = 'txtWebServerIP';
  3508.                 }
  3509.                 else if ($_GET['t'] == '6') {
  3510.                     $strFieldName = 'txtEmailServerIP';
  3511.                 }
  3512.  
  3513.                 $strDataToSave = '';
  3514.  
  3515.                 if ($_GET['a3'] == 'a') {
  3516.                     $fields = $strFieldName;
  3517.                     $where = array('id' => $intRecordID);
  3518.                     $result = ($intDomainRID = $_POST['dzrid']);
  3519.                     $data = ($intDomainRID = $_GET['dzrid']);
  3520.                     $strCurrentData = is_numeric($intDomainRID);
  3521.  
  3522.                     if (empty($strCurrentData) == true) {
  3523.                         $strDataToSave = $intDomainRID;
  3524.                     }
  3525.                     else if (substr($strCurrentData, -1) == ',') {
  3526.                         $strDataToSave = $strCurrentData . $strNewDataToWorkWith;
  3527.                     }
  3528.                     else {
  3529.                         $strDataToSave = $strCurrentData . ',' . $strNewDataToWorkWith;
  3530.                     }
  3531.  
  3532.                     $array = array($strFieldName => $strDataToSave);
  3533.                     $where = array('id' => $intRecordID);
  3534.                     update_query($table, $array, $where);
  3535.                 }
  3536.                 else if ($_GET['a3'] == 'd') {
  3537.                     $fields = $sort;
  3538.                     $where = array('id' => $intRecordID);
  3539.                     $result = $strDomainName;
  3540.                     $data = $strDomainName;
  3541.                     $strCurrentData = array();
  3542.  
  3543.                     if (strpos($strCurrentData, ',') < 1) {
  3544.                         $strDataToSave = '';
  3545.                     }
  3546.                     else {
  3547.                         $aryCurrentData = explode(',', $strCurrentData);
  3548.  
  3549.                         foreach ($aryCurrentData as $strCurrentDataItem) {
  3550.                             $strCurrentDataItem = $intTypeNumber;
  3551.  
  3552.                             if ($strCurrentDataItem != $strNewDataToWorkWith) {
  3553.                                 if (0 < strlen($strCurrentDataItem)) {
  3554.                                     $strDataToSave = $strDataToSave . $strCurrentDataItem . ',';
  3555.                                 }
  3556.                             }
  3557.                         }
  3558.                     }
  3559.  
  3560.                     $array = array($strFieldName => $strDataToSave);
  3561.                     $where = array('id' => $intRecordID);
  3562.                     update_query($table, $array, $where);
  3563.                 }
  3564.             }
  3565.  
  3566.             $ResponseXML = '<Response>';
  3567.  
  3568.             if (0 < strlen($strDataToSave)) {
  3569.                 $ResponseXML = $ResponseXML . '<NSZoneSettingsResult>1</NSZoneSettingsResult>';
  3570.             }
  3571.  
  3572.             $ResponseXML = $ResponseXML . '</Response>';
  3573.             print($ResponseXML);
  3574.             exit();
  3575.         }
  3576.         else if ($strAction == 'c') {
  3577.             if ($_POST['a3'] == 's') {
  3578.                 $strDomain = (list(, ) = $aryMXData);
  3579.  
  3580.                 if (substr($strDomain, 0, 4) == 'www.') {
  3581.                     $strErrorMessage = 'The domain name you have eneted contains www., please remove it and re-submit.';
  3582.                 }
  3583.  
  3584.                 if (CheckForValidRecordData($strDomain) == false) {
  3585.                     if (0 < strpos($strDomain, '..')) {
  3586.                         if ($strErrorMessage == '') {
  3587.                             $strErrorMessage = 'The domain name you have entered is invalid, please make sure it is correct and has valid characters.';
  3588.                         }
  3589.                     }
  3590.                 }
  3591.                 else {
  3592.                     $strErrorMessage = 'The domain name you have entered is invalid, please make sure it is correct and has valid characters.';
  3593.                 }
  3594.  
  3595.                 $strPrimaryDNS = strtolower(db_escape($_POST['primarydnstxt']));
  3596.  
  3597.                 if (CheckForValidRecordData($strPrimaryDNS) == false) {
  3598.                     if (0 < strpos($strPrimaryDNS, '..')) {
  3599.                         if ($strErrorMessage == '') {
  3600.                             $strErrorMessage = 'The Primary DNS server you have entered is invalid, please make sure it is correct and has valid characters.';
  3601.                         }
  3602.                     }
  3603.                 }
  3604.                 else {
  3605.                     $strErrorMessage = 'The Primary DNS server you have entered is invalid, please make sure it is correct and has valid characters.';
  3606.                 }
  3607.  
  3608.                 $strSecondaryDNS = strtolower(db_escape($_POST['secondarydnstxt']));
  3609.  
  3610.                 if (CheckForValidRecordData($strSecondaryDNS) == false) {
  3611.                     if (0 < strpos($strSecondaryDNS, '..')) {
  3612.                         if ($strErrorMessage == '') {
  3613.                             $strErrorMessage = 'The Secondary DNS server you have entered is invalid, please make sure it is correct and has valid characters.';
  3614.                         }
  3615.                     }
  3616.                 }
  3617.                 else {
  3618.                     $strErrorMessage = 'The Secondary DNS server you have entered is invalid, please make sure it is correct and has valid characters.';
  3619.                 }
  3620.  
  3621.                 $strPrimaryMX = strtoupper($strAName) == 'WEBMAIL';
  3622.  
  3623.                 if (CheckForValidRecordData($strPrimaryMX) == false) {
  3624.                     if (0 < strpos($strPrimaryMX, '..')) {
  3625.                         if ($strErrorMessage == '') {
  3626.                             $strErrorMessage = 'The Primary MX server you have entered is invalid, please make sure it is correct and has valid characters.';
  3627.                         }
  3628.                     }
  3629.                 }
  3630.                 else {
  3631.                     $strErrorMessage = 'The Primary MX server you have entered is invalid, please make sure it is correct and has valid characters.';
  3632.                 }
  3633.  
  3634.                 $strSecondaryMX = $strADataToSend . $strAName . '|A|';
  3635.  
  3636.                 if (CheckForValidRecordData($strSecondaryMX) == false) {
  3637.                     if (0 < strpos($strSecondaryMX, '..')) {
  3638.                         if ($strErrorMessage == '') {
  3639.                             $strErrorMessage = 'The Secondary MX server you have entered is invalid, please make sure it is correct and has valid characters.';
  3640.                         }
  3641.                     }
  3642.                 }
  3643.                 else {
  3644.                     $strErrorMessage = 'The Secondary MX server you have entered is invalid, please make sure it is correct and has valid characters.';
  3645.                 }
  3646.  
  3647.                 $strWebServer = strtolower(db_escape($_POST['webservertxt']));
  3648.  
  3649.                 if (IsValidIPAddress($strWebServer) == false) {
  3650.                     if (0 < strpos($strWebServer, '..')) {
  3651.                         if ($strErrorMessage == '') {
  3652.                             $strErrorMessage = 'The Web Server IP Address you have entered is invalid, please make sure it is correct and has valid numbers.';
  3653.                         }
  3654.                     }
  3655.                 }
  3656.                 else {
  3657.                     $strErrorMessage = 'The Web Server IP Address you have entered is invalid, please make sure it is correct and has valid numbers.';
  3658.                 }
  3659.  
  3660.                 $strEmailServer = true;
  3661.  
  3662.                 if (IsValidIPAddress($strEmailServer) == false) {
  3663.                     if (0 < strpos($strEmailServer, '..')) {
  3664.                         if ($strErrorMessage == '') {
  3665.                             $strErrorMessage = 'The Email Server IP Address you have entered is invalid, please make sure it is correct and has valid numbers.';
  3666.                         }
  3667.                     }
  3668.                 }
  3669.                 else {
  3670.                     $strErrorMessage = 'The Email Server IP Address you have entered is invalid, please make sure it is correct and has valid numbers.';
  3671.                 }
  3672.  
  3673.                 if (CheckIfDomainInRodopiOrWHMCS($strDomain) == true) {
  3674.                     if ($strErrorMessage == '') {
  3675.                         $strErrorMessage = 'The domain name you have entered already exists in our hosting system.';
  3676.                     }
  3677.                 }
  3678.  
  3679.                 if (strlen($strErrorMessage) < 1) {
  3680.                     $strMX1Weight = '10';
  3681.                     $strMX2Weight = '10';
  3682.                     $strPrimaryDNSServer = substr($strAName, -1) != '.';
  3683.  
  3684.                     if (empty($strPrimaryDNSServer)) {
  3685.                         $strPrimaryDNSServer = substr($strAName, -1) != '.';
  3686.                     }
  3687.  
  3688.                     $table = 'tblservers';
  3689.                     $fields = 'localipaddress,ipaddress';
  3690.                     $where = array('hostname' => $strPrimaryDNSServer);
  3691.                     $result = $strDataValue;
  3692.                     $data = -1;
  3693.                     $strPrimaryDNSServerIPAddress = $strADataToSend;
  3694.                     $strPrimaryPublicServerIP = $strDataValue;
  3695.                     $strSecondaryDNSServer = $strADataToSend . $strAName;
  3696.  
  3697.                     if (empty($strSecondaryDNSServer)) {
  3698.                         $strSecondaryDNSServer = $strADataToSend . $strAName . '|TXT|"' . $strDataValue . '"^';
  3699.                     }
  3700.  
  3701.                     $table = 'tblservers';
  3702.                     $fields = 'localipaddress';
  3703.                     $where = array('hostname' => $strSecondaryDNSServer);
  3704.                     $result = $strADataToSend;
  3705.                     $data = $strADataToSend;
  3706.                     $strSecondaryDNSServerIPAddress = $strErrorMessage;
  3707.                     $strDNSServers = $strPrimaryDNS . '^' . $strSecondaryDNS;
  3708.                     $strMXServers = $strMX1Weight . '|' . $strPrimaryMX . '^' . $strMX2Weight . '|' . $strSecondaryMX;
  3709.                     $strDNSRecordData = '@|A|' . $strWebServer . '^www|A|' . $strWebServer . '^ftp|A|' . $strWebServer . '^mail|A|' . $strEmailServer;
  3710.                     $strDataToSendToPrimaryServer = 'CREATEPRIMARYDNSENTRY§' . $intDefaultDNSExpiry . '§' . $intDefaultDNSRefresh . '§' . $intDefaultDNSTTLForNegtive . '§' . $intDefaultDNSTTLMin . '§' . $intDefaultDNSUpdateRetry . '§' . $strDNSDirectory . '§' . $strDNSServers . '§' . $strDomain . '§' . $strMXServers . '§' . $strDNSRecordData;
  3711.                     $strDataToSendToSecondaryServer = 'CREATESECONDARYDNSENTRY§' . $strDomain . '§' . $strDNSDirectory . '§' . $strPrimaryPublicServerIP;
  3712.                     $strDNSRecordSaveResult = $strPrimaryDNSServerIPAddress;
  3713.  
  3714.                     if (0 < strpos(strtolower($strDNSRecordSaveResult), 'entry created successfully')) {
  3715.                         $table = 'tblaisodnsrecords';
  3716.                         $array = array('tblhosting_id' => $intServiceID, 'tblclients_id' => $intUserID, 'txtDomainName' => $strDomain, 'dteRecordCreationDate' => date('Y-m-d H:i:s', time()));
  3717.                         $intNewRecordID = 'REWRITEDNSRECORDMXENTRIES§' . $strDomainName;
  3718.                         $strDNSRecordSaveResult = $strMXDataToSend;
  3719.                         $strURLToRedirectTo = 'clientarea.php?action=productdetails&id=' . $intServiceID . '&modop=custom&a=managednszonefiles&sm=1';
  3720.                     }
  3721.                     else {
  3722.                         $strURLToRedirectTo = 'clientarea.php?action=productdetails&id=' . $intServiceID . '&modop=custom&a=editdnszonefiles&a2=c&dzrid=' . $intDomainNameRID . '&error=2';
  3723.                     }
  3724.  
  3725.                     $aryCurrentURL = strtolower($strDNSRecordSaveResult);
  3726.  
  3727.                     if (substr($aryCurrentURL[0], -1) == '/') {
  3728.                         $strCurrentURL = 'clientarea.php?action=productdetails&id=' . $intServiceID . '&modop=custom&a=managednszonefiles&sm=2';
  3729.                     }
  3730.                     else {
  3731.                         $strCurrentURL = 'clientarea.php?action=productdetails&id=' . $intServiceID . '&modop=custom&a=editdnszonefiles&a2=e&dzrid=' . $intDomainNameRID . '&error=10';
  3732.                     }
  3733.  
  3734.                     Header('HTTP/1.1 301 Moved Permanently');
  3735.                     Header('Location: ' . $strCurrentURL . '/' . $strURLToRedirectTo);
  3736.                     exit();
  3737.                 }
  3738.             }
  3739.  
  3740.             if (!empty($_GET['error'])) {
  3741.                 if ($_GET['error'] == '1') {
  3742.                     $strErrorMessage = 'There was an issue creating the DNS zone record data on the DNS servers, please try again later.';
  3743.                 }
  3744.                 else if ($_GET['error'] == '2') {
  3745.                     $strErrorMessage = 'There was an issue creating the DNS zone record data on the DNS servers, please try again later.';
  3746.                 }
  3747.             }
  3748.  
  3749.             $strNewDNSRecordPage = 'True';
  3750.             $strActionText = (list() = $aryCurrentURL);
  3751.             $strActionDescription = substr($aryCurrentURL[0], 0, strlen($aryCurrentURL[0]) - 1);
  3752.  
  3753.             if ($strErrorMessage == '') {
  3754.                 $strErrorMessageArea = 'style="display:none;"';
  3755.             }
  3756.  
  3757.             $strJavascriptComboBoxData = '';
  3758.             $select_dnsrecordsettings = 'SELECT txtPrimaryDNSServer,txtSecondaryDNSServer,txtPrimaryMXServer,txtSecondaryMXServer,txtWebServerIP,txtEmailServerIP FROM tblaisodnsrecordsettings WHERE tblclients_id = ' . $intUserID;
  3759.             $dnsrecordsettings_rows = $strAction;
  3760.  
  3761.             if ($dnsrecordsettings_rows) {
  3762.                 while ($dnsrecordsetting = mysql_fetch_assoc($dnsrecordsettings_rows)) {
  3763.                     if (!empty($dnsrecordsetting['txtPrimaryDNSServer'])) {
  3764.                         $strPrimaryDNSZoneServers = $dnsrecordsetting['txtPrimaryDNSServer'];
  3765.  
  3766.                         if (0 < strpos($strPrimaryDNSZoneServers, ',')) {
  3767.                             $aryPrimaryDNSZoneServers = $join;
  3768.  
  3769.                             foreach ($aryPrimaryDNSZoneServers as $aryPrimaryDNSZoneServer) {
  3770.                                 if (0 < strlen($aryPrimaryDNSZoneServer)) {
  3771.                                     $strJavascriptComboBoxData .= 'primarydns.addmanual(\'' . $aryPrimaryDNSZoneServer . '\');' . "\n" . '';
  3772.                                 }
  3773.                             }
  3774.                         }
  3775.                         else {
  3776.                             $strJavascriptComboBoxData .= 'primarydns.addmanual(\'' . $strPrimaryDNSZoneServers . '\');' . "\n" . '';
  3777.                         }
  3778.                     }
  3779.  
  3780.                     if (!empty($dnsrecordsetting['txtSecondaryDNSServer'])) {
  3781.                         $strSecondaryDNSZoneServers = $strAction == 'cajax';
  3782.  
  3783.                         if (0 < strpos($strSecondaryDNSZoneServers, ',')) {
  3784.                             $arySecondaryDNSZoneServers = array_reverse(explode(',', $strSecondaryDNSZoneServers));
  3785.  
  3786.                             foreach ($arySecondaryDNSZoneServers as $arySecondaryDNSZoneServer) {
  3787.                                 $arySecondaryDNSZoneServer = $objXmlDOM->childNodes;
  3788.  
  3789.                                 if (0 < strlen($arySecondaryDNSZoneServer)) {
  3790.                                     $strJavascriptComboBoxData .= 'secondarydns.addmanual(\'' . $arySecondaryDNSZoneServer . '\');' . "\n" . '';
  3791.                                 }
  3792.                             }
  3793.                         }
  3794.                         else {
  3795.                             $strJavascriptComboBoxData .= 'secondarydns.addmanual(\'' . $strSecondaryDNSZoneServers . '\');' . "\n" . '';
  3796.                         }
  3797.                     }
  3798.  
  3799.                     if (!empty($dnsrecordsetting['txtPrimaryMXServer'])) {
  3800.                         $strPrimaryMXServers = strlen($objRoot->getAttribute('DATA'));
  3801.  
  3802.                         if (0 < strpos($strPrimaryMXServers, ',')) {
  3803.                             $aryPrimaryMXServers = CheckForValidRecordData($objRoot->getAttribute('DATA')) == False;
  3804.  
  3805.                             foreach ($aryPrimaryMXServers as $aryPrimaryMXServer) {
  3806.                                 $aryPrimaryMXServer = $where;
  3807.  
  3808.                                 if (0 < strlen($aryPrimaryMXServer)) {
  3809.                                     $strJavascriptComboBoxData .= 'primarymx.addmanual(\'' . $aryPrimaryMXServer . '\');' . "\n" . '';
  3810.                                 }
  3811.                             }
  3812.                         }
  3813.                         else {
  3814.                             $strJavascriptComboBoxData .= 'primarymx.addmanual(\'' . $strPrimaryMXServers . '\');' . "\n" . '';
  3815.                         }
  3816.                     }
  3817.  
  3818.                     if (!empty($dnsrecordsetting['txtSecondaryMXServer'])) {
  3819.                         $strSecondaryMXServers = $intRecordID;
  3820.  
  3821.                         if (0 < strpos($strSecondaryMXServers, ',')) {
  3822.                             $arySecondaryMXServers = (int) $intRecordID;
  3823.  
  3824.                             foreach ($arySecondaryMXServers as $arySecondaryMXServer) {
  3825.                                 $arySecondaryMXServer = $array;
  3826.  
  3827.                                 if (0 < strlen($arySecondaryMXServer)) {
  3828.                                     $strJavascriptComboBoxData .= 'secondarymx.addmanual(\'' . $arySecondaryMXServer . '\');' . "\n" . '';
  3829.                                 }
  3830.                             }
  3831.                         }
  3832.                         else {
  3833.                             $strJavascriptComboBoxData .= 'secondarymx.addmanual(\'' . $strSecondaryMXServers . '\');' . "\n" . '';
  3834.                         }
  3835.                     }
  3836.  
  3837.                     if (!empty($dnsrecordsetting['txtWebServerIP'])) {
  3838.                         $strWebServerIPs = $_GET['t'];
  3839.  
  3840.                         if (0 < strpos($strWebServerIPs, ',')) {
  3841.                             $aryWebServerIPs = array_reverse(explode(',', $strWebServerIPs));
  3842.  
  3843.                             foreach ($aryWebServerIPs as $aryWebServerIP) {
  3844.                                 $aryWebServerIP = ($_GET['t']);
  3845.  
  3846.                                 if (0 < strlen($aryWebServerIP)) {
  3847.                                     $strJavascriptComboBoxData .= 'webserver.addmanual(\'' . $aryWebServerIP . '\');' . "\n" . '';
  3848.                                 }
  3849.                             }
  3850.                         }
  3851.                         else {
  3852.                             $strJavascriptComboBoxData .= 'webserver.addmanual(\'' . $strWebServerIPs . '\');' . "\n" . '';
  3853.                         }
  3854.                     }
  3855.  
  3856.                     if (!empty($dnsrecordsetting['txtEmailServerIP'])) {
  3857.                         $strEmailServerIPs = $_GET['a3'];
  3858.  
  3859.                         if (0 < strpos($strEmailServerIPs, ',')) {
  3860.                             $aryEmailServerIPs = array_reverse(explode(',', $strEmailServerIPs));
  3861.  
  3862.                             foreach ($aryEmailServerIPs as $aryEmailServerIP) {
  3863.                                 $aryEmailServerIP = $sortorder;
  3864.  
  3865.                                 if (0 < strlen($aryEmailServerIP)) {
  3866.                                     $strJavascriptComboBoxData .= 'emailserver.addmanual(\'' . $aryEmailServerIP . '\');' . "\n" . '';
  3867.                                 }
  3868.                             }
  3869.                         }
  3870.                         else {
  3871.                             $strJavascriptComboBoxData .= 'emailserver.addmanual(\'' . $strEmailServerIPs . '\');' . "\n" . '';
  3872.                         }
  3873.                     }
  3874.                 }
  3875.             }
  3876.  
  3877.             $pagearray = array(
  3878.                 'templatefile' => 'creatednszonefile',
  3879.                 'breadcrumb'   => ' > <a href="#">Add Zone File</a>',
  3880.                 'vars'         => array('LANG' => $_LANG, 'servername' => $strVMWareSrverNameDisplay, 'a2' => $a2, 'strErrorMessage' => $strErrorMessage, 'strErrorMessageArea' => $strErrorMessageArea, 'strActionText' => $strActionText, 'strActionDescription' => $strActionDescription, 'strJavascriptComboBoxData' => $strJavascriptComboBoxData)
  3881.                 );
  3882.             return $pagearray;
  3883.         }
  3884.         else if ($strAction == 'd') {
  3885.             if (0 < $intDomainRID) {
  3886.                 $table = 'tblaisodnsrecords';
  3887.                 $fields = 'id,txtDomainName';
  3888.                 $where = array('id' => $intDomainRID, 'tblclients_id' => $intUserID);
  3889.                 $result = ($_GET['a3']);
  3890.                 $data = $strFieldName;
  3891.                 $intDomainNameRID = array('id' => $intRecordID);
  3892.                 $strDomainName = $fields;
  3893.                 $strActionText = $limits;
  3894.  
  3895.                 if (2 < strlen($strDomainName)) {
  3896.                     $strPrimaryDNSServer = $data[0];
  3897.  
  3898.                     if (empty($strPrimaryDNSServer)) {
  3899.                         $strPrimaryDNSServer = strpos($strCurrentData, ',') < 1;
  3900.                     }
  3901.  
  3902.                     $table = 'tblservers';
  3903.                     $fields = 'localipaddress';
  3904.                     $where = array('hostname' => $strPrimaryDNSServer);
  3905.                     $result = 0 < strlen($strCurrentDataItem);
  3906.                     $data = $strDataToSave . $strCurrentDataItem;
  3907.                     $strPrimaryDNSServerIPAddress = $strFieldName;
  3908.                     $strSecondaryDNSServer = $GLOBALS['smarty']->_tpl_vars['serverdata']['nameserver2'];
  3909.  
  3910.                     if (empty($strSecondaryDNSServer)) {
  3911.                         $strSecondaryDNSServer = $gstrSecondaryDNSServerName;
  3912.                     }
  3913.  
  3914.                     $table = 'tblservers';
  3915.                     $fields = 'localipaddress';
  3916.                     $where = array('hostname' => $strSecondaryDNSServer);
  3917.                     $result = ($_POST['a3']);
  3918.                     $data = (list() = $_POST);
  3919.                     $strSecondaryDNSServerIPAddress = strtolower(substr(db_escape($_POST['domainname']), 0, 200));
  3920.                     $strDNSRecordSaveResult = false;
  3921.  
  3922.                     if (0 < strpos(strtolower($strDNSRecordSaveResult), 'zone record deleted')) {
  3923.                         $deleterecordsql = 'DELETE FROM tblaisodnsrecords WHERE id = ' . $intDomainNameRID;
  3924.                         $deleterecord_row = db_escape($_POST['primarydnstxt']);
  3925.                         $strDNSRecordSaveResult = 0 < strpos($strPrimaryDNS, '..');
  3926.                         $strURLToRedirectTo = 'clientarea.php?action=productdetails&id=' . $intServiceID . '&modop=custom&a=managednszonefiles&sm=3';
  3927.                     }
  3928.                     else {
  3929.                         $strURLToRedirectTo = 'clientarea.php?action=productdetails&id=' . $intServiceID . '&modop=custom&a=managednszonefiles';
  3930.                     }
  3931.  
  3932.                     $aryCurrentURL = CheckForValidRecordData($strSecondaryDNS);
  3933.  
  3934.                     if (substr($aryCurrentURL[0], -1) == '/') {
  3935.                         $strCurrentURL = strtolower(db_escape($_POST['primarymxtxt']));
  3936.                     }
  3937.                     else {
  3938.                         $strCurrentURL = false;
  3939.                     }
  3940.  
  3941.                     Header('HTTP/1.1 301 Moved Permanently');
  3942.                     Header('Location: ' . $strCurrentURL . '/' . $strURLToRedirectTo);
  3943.                     exit();
  3944.                 }
  3945.                 else {
  3946.                     print('Domain not found');
  3947.                     exit();
  3948.                 }
  3949.             }
  3950.         }
  3951.     }
  3952.  
  3953.     if ($strAction == 'e') {
  3954.         if ($strErrorMessage == '') {
  3955.             if (!empty($_GET['error'])) {
  3956.                 if ($_GET['error'] == '9') {
  3957.                     $strErrorMessage = 'Issue Restarting The Secondary DNS Server';
  3958.                 }
  3959.                 else if ($_GET['error'] == '10') {
  3960.                     $strErrorMessage = 'Issue Restarting The Primary DNS Server';
  3961.                 }
  3962.                 else if ($_GET['error'] == '11') {
  3963.                     $strErrorMessage = 'There was an issue saving the DNS zone MX record data to the DNS servers, please try again later.';
  3964.                 }
  3965.                 else if ($_GET['error'] == '12') {
  3966.                     $strErrorMessage = 'There was an issue saving the DNS zone A record data to the DNS servers, please try again later.';
  3967.                 }
  3968.             }
  3969.         }
  3970.  
  3971.         $table = 'tblaisodnsrecords';
  3972.         $fields = 'id,txtDomainName';
  3973.         $where = array('id' => $intDomainRID, 'tblclients_id' => $intUserID);
  3974.         $result = $strErrorMessage;
  3975.         $data = $strDomain;
  3976.         $intDomainNameRID = $strErrorMessage;
  3977.         $strDomainName = $strErrorMessage;
  3978.         $strActionText = $_LANG['VMwareEditZoneRecord'];
  3979.         $strActionDescription = ($GLOBALS['smarty']);
  3980.  
  3981.         if (2 < strlen($strDomainName)) {
  3982.             $strPrimaryDNSServer = $table;
  3983.  
  3984.             if (empty($strPrimaryDNSServer)) {
  3985.                 $strPrimaryDNSServer = $where;
  3986.             }
  3987.  
  3988.             $table = 'tblservers';
  3989.             $fields = 'localipaddress';
  3990.             $where = array('hostname' => $strPrimaryDNSServer);
  3991.             $result = $strPrimaryDNSServerIPAddress;
  3992.             $data = $strPrimaryPublicServerIP;
  3993.             $strPrimaryDNSServerIPAddress = $strSecondaryDNSServer;
  3994.             $strDNSRecordData = $gstrSecondaryDNSServerName;
  3995.  
  3996.             if (0 < strpos($strDNSRecordData, '§')) {
  3997.                 $aryDNSRecordData = explode('§', $strDNSRecordData);
  3998.                 $arySOARecordData = $fields;
  3999.                 $aryNSRecordData = $join;
  4000.                 $aryMXRecordData = mysql_fetch_array($result);
  4001.                 $aryMiscRecordData = explode('^', $aryDNSRecordData[3]);
  4002.  
  4003.                 if ($strErrorMessage == '') {
  4004.                     $strErrorMessageArea = 'style="display:none;"';
  4005.                 }
  4006.             }
  4007.         }
  4008.         else {
  4009.             print('Domain not found');
  4010.             exit();
  4011.         }
  4012.     }
  4013.     else if ($strAction != '') {
  4014.         print('Domain not found');
  4015.         exit();
  4016.     }
  4017.     else {
  4018.         print('Invalid Action');
  4019.         exit();
  4020.     }
  4021.  
  4022.     $pagearray = array(
  4023.         'templatefile' => 'editdnszonefiles',
  4024.         'breadcrumb'   => ' > <a href="#">Add/Edit Zone File</a>',
  4025.         'vars'         => array('LANG' => $_LANG, 'servername' => $strVMWareSrverNameDisplay, 'a2' => $a2, 'strErrorMessage' => $strErrorMessage, 'strErrorMessageArea' => $strErrorMessageArea, 'aryDNSRecordData' => $aryDNSRecordData, 'strActionText' => $strActionText, 'strDomainName' => $strDomainName, 'arySOARecordData' => $arySOARecordData, 'aryNSRecordData' => $aryNSRecordData, 'dnrid' => $intDomainNameRID, 'aryMXRecordData' => $aryMXRecordData, 'aryMiscRecordData' => $aryMiscRecordData, 'blnNewDNSRecordPage' => $strNewDNSRecordPage, 'strActionDescription' => $strActionDescription)
  4026.         );
  4027.     return $pagearray;
  4028. }
  4029.  
  4030. function aisovmwarededsrv_AdminCustomButtonArray()
  4031. {
  4032.     $buttonarray = array('Reboot Server' => 'reboot', 'Get Power State' => 'powerstate');
  4033.     return $buttonarray;
  4034. }
  4035.  
  4036. function aisovmwarededsrv_reboot($params)
  4037. {
  4038.     global $mstrVMWareWebServerCustomFieldName;
  4039.     $strVMWareServerName = $params['customfields'][$mstrVMWareWebServerCustomFieldName];
  4040.  
  4041.     if (strlen($mstrVMWareWebServerCustomFieldName) < 1) {
  4042.         return 'Server Name Could Not Be Found';
  4043.     }
  4044.  
  4045.     $intServerID = $params['serverid'];
  4046.     $select_modules = 'SELECT type,ipaddress,username,password FROM tblservers WHERE id = ' . $intServerID;
  4047.     $modules_rows = full_query($select_modules);
  4048.  
  4049.     if ($modules_rows) {
  4050.         $aryRowData = mysql_fetch_row($modules_rows);
  4051.         $strModuleName = $aryRowData[0];
  4052.         $strVMwarevSphereURL = $aryRowData[1];
  4053.         $strVMwarevSphereUsername = $aryRowData[2];
  4054.         $strVMwarevSpherePassword = decrypt($aryRowData[3]);
  4055.     }
  4056.     else {
  4057.         return 'Server Info Could Not Be Found, please alert us of this issue';
  4058.     }
  4059.  
  4060.     $vm = $strVMwarevSpherePassword;
  4061.     $vm->setDebug(0);
  4062.     $vm->Login();
  4063.     $strVMID = $vm->FindVMByName($strVMWareServerName);
  4064.  
  4065.     if (0 < strpos($strVMID, 'error!!')) {
  4066.         if (strlen($strVMID) < 1) {
  4067.             $vm->Logout();
  4068.             return 'Server Info Could Not Be Retreived From VMware';
  4069.         }
  4070.     }
  4071.     else {
  4072.         $vm->Logout();
  4073.         return 'Server Info Could Not Be Retreived From VMware';
  4074.     }
  4075.  
  4076.     $vmDetail = $vm->RetrievePropertiesVM($strVMID, 'VirtualMachine', 'runtime.powerState');
  4077.     $strPowerState = $vmDetail['propSet']['val'];
  4078.  
  4079.     if (strtolower($strPowerState) == 'poweredon') {
  4080.         $vm->RebootVMGuest($strVMID);
  4081.         $successful = true;
  4082.     }
  4083.     else {
  4084.         $vm->Logout();
  4085.         return 'Server Could Not Be Guest Rebooted Because It Is Off';
  4086.     }
  4087.  
  4088.     $vm->Logout();
  4089.  
  4090.     if ($successful) {
  4091.         $result = 'success';
  4092.     }
  4093.     else {
  4094.         $result = 'Could Not Reboot Guest For Some Reason';
  4095.     }
  4096.  
  4097.     return $result;
  4098. }
  4099.  
  4100. function aisovmwarededsrv_powerstate($params)
  4101. {
  4102.     global $mstrVMWareWebServerCustomFieldName;
  4103.     $strVMWareServerName = $params['customfields'][$mstrVMWareWebServerCustomFieldName];
  4104.  
  4105.     if (strlen($mstrVMWareWebServerCustomFieldName) < 1) {
  4106.         return 'Server Name Could Not Be Found';
  4107.     }
  4108.  
  4109.     $intServerID = $params['serverid'];
  4110.     $select_modules = 'SELECT type,ipaddress,username,password FROM tblservers WHERE id = ' . $intServerID;
  4111.     $modules_rows = full_query($select_modules);
  4112.  
  4113.     if ($modules_rows) {
  4114.         $aryRowData = mysql_fetch_row($modules_rows);
  4115.         $strModuleName = $aryRowData[0];
  4116.         $strVMwarevSphereURL = $aryRowData[1];
  4117.         $strVMwarevSphereUsername = $aryRowData[2];
  4118.         $strVMwarevSpherePassword = decrypt($aryRowData[3]);
  4119.     }
  4120.     else {
  4121.         return 'Server Info Could Not Be Found, please alert us of this issue';
  4122.     }
  4123.  
  4124.     $vm = $strVMwarevSpherePassword;
  4125.     $vm->setDebug(0);
  4126.     $vm->Login();
  4127.     $strVMID = $vm->FindVMByName($strVMWareServerName);
  4128.  
  4129.     if (0 < strpos($strVMID, 'error!!')) {
  4130.         if (strlen($strVMID) < 1) {
  4131.             $vm->Logout();
  4132.             return 'Server Info Could Not Be Retreived From VMware';
  4133.         }
  4134.     }
  4135.     else {
  4136.         $vm->Logout();
  4137.         return 'Server Info Could Not Be Retreived From VMware';
  4138.     }
  4139.  
  4140.     $vmDetail = ($strVMWareServerName = $params['customfields'][$mstrVMWareWebServerCustomFieldName]);
  4141.     $strPowerState = $mstrVMWareWebServerCustomFieldName;
  4142.  
  4143.     if (strtolower($strPowerState) == 'poweredon') {
  4144.         $result = 'Powered On';
  4145.     }
  4146.     else if (strtolower($strPowerState) == 'poweredoff') {
  4147.         $result = 'Powered Off';
  4148.     }
  4149.     else {
  4150.         $result = full_query($select_modules);
  4151.     }
  4152.  
  4153.     $vm->Logout();
  4154.     return 'Current VM Power State: ' . $result;
  4155. }
  4156.  
  4157. function aisovmwarededsrv_load_language()
  4158. {
  4159.     global $_LANG;
  4160.     $dh = $dh;
  4161.  
  4162.     if (false !== $file2 = false) {
  4163.         $pieces = !is_dir('' . 'lang/' . $file2);
  4164.  
  4165.         if ($pieces[1] == 'txt') {
  4166.             $arrayoflanguagefiles[] = $pieces[0];
  4167.             continue;
  4168.         }
  4169.  
  4170.         continue;
  4171.     }
  4172.  
  4173.     closedir($dh);
  4174.     $language = $_SESSION['Language'];
  4175.  
  4176.     if (!in_array($language, $arrayoflanguagefiles)) {
  4177.         $language = 'English';
  4178.     }
  4179.  
  4180.     if (file_exists(dirname(__FILE__) . '/lang/' . $language . '.txt')) {
  4181.         ob_start();
  4182.         include dirname(__FILE__) . '/lang/' . $language . '.txt';
  4183.         $templang = dirname(__FILE__) . '/lang/' . $language . '.txt';
  4184.         ob_end_clean();
  4185.         eval ($templang);
  4186.     }
  4187. }
  4188.  
  4189. function vmwarededsrvdisplayerrormessage($strErrorTitle, $strErrorMessage)
  4190. {
  4191.     global $_LANG;
  4192.     $pagearray = array(
  4193.         'templatefile' => 'errormessage',
  4194.         'breadcrumb'   => ' > <a href="#">Error</a>',
  4195.         'vars'         => array('LANG' => $_LANG, 'strErrorTitle' => $strErrorTitle, 'strErrorMessage' => $strErrorMessage)
  4196.         );
  4197.     return $pagearray;
  4198. }
  4199.  
  4200. function VMWareGetWHMCSCustomFieldValue($strFieldName, $intPackageRID, $intServiceRID)
  4201. {
  4202.     $table = 'tblcustomfields';
  4203.     $fields = 'id';
  4204.     $where = array('fieldname' => $strFieldName, 'relid' => $intPackageRID);
  4205.     $result = $result;
  4206.     $data = $sort;
  4207.     $intCustomFieldRID = select_query($table, $fields, $where, $sort, $sortorder, $limits, $join);
  4208.  
  4209.     if (!empty($intCustomFieldRID)) {
  4210.         $table = 'tblcustomfieldsvalues';
  4211.         $fields = 'value';
  4212.         $where = array('relid' => $intServiceRID, 'fieldid' => $intCustomFieldRID);
  4213.         $result = $result;
  4214.         $data = $sort;
  4215.         return $data[0];
  4216.     }
  4217. }
  4218.  
  4219. function CheckIfRunningFileIsACronTypeRunForVMwareModule($strServerScriptName, $strDirectorySeparator)
  4220. {
  4221.     $blnBypassError = false;
  4222.  
  4223.     if ($strServerScriptName == dirname(dirname(__FILE__)) . $strDirectorySeparator . 'admin' . $strDirectorySeparator . 'cron.php') {
  4224.         $blnBypassError = true;
  4225.     }
  4226.     else if (substr($strServerScriptName, strrpos($strServerScriptName, $strDirectorySeparator) + 1) == 'cron.php') {
  4227.         $blnBypassError = true;
  4228.     }
  4229.     else if ($strServerScriptName == dirname(dirname(__FILE__)) . $strDirectorySeparator . 'modules' . $strDirectorySeparator . 'registrars' . $strDirectorySeparator . 'directi' . $strDirectorySeparator . 'directisync.php') {
  4230.         $blnBypassError = true;
  4231.     }
  4232.     else if (substr($strServerScriptName, strrpos($strServerScriptName, $strDirectorySeparator) + 1) == 'directisync.php') {
  4233.         $blnBypassError = true;
  4234.     }
  4235.     else if ($strServerScriptName == dirname(dirname(__FILE__)) . $strDirectorySeparator . 'modules' . $strDirectorySeparator . 'registrars' . $strDirectorySeparator . 'distributeit' . $strDirectorySeparator . 'distributeitsync.php') {
  4236.         $blnBypassError = true;
  4237.     }
  4238.     else if (substr($strServerScriptName, strrpos($strServerScriptName, $strDirectorySeparator) + 1) == 'distributeitsync.php') {
  4239.         $blnBypassError = true;
  4240.     }
  4241.     else if ($strServerScriptName == dirname(dirname(__FILE__)) . $strDirectorySeparator . 'modules' . $strDirectorySeparator . 'registrars' . $strDirectorySeparator . 'enom' . $strDirectorySeparator . 'enomsync.php') {
  4242.         $blnBypassError = true;
  4243.     }
  4244.     else if (substr($strServerScriptName, strrpos($strServerScriptName, $strDirectorySeparator) + 1) == 'enomsync.php') {
  4245.         $blnBypassError = true;
  4246.     }
  4247.     else if ($strServerScriptName == dirname(dirname(__FILE__)) . $strDirectorySeparator . 'modules' . $strDirectorySeparator . 'registrars' . $strDirectorySeparator . 'heartinternet' . $strDirectorySeparator . 'heartinternetsync.php') {
  4248.         $blnBypassError = true;
  4249.     }
  4250.     else if (substr($strServerScriptName, strrpos($strServerScriptName, $strDirectorySeparator) + 1) == 'heartinternetsync.php') {
  4251.         $blnBypassError = true;
  4252.     }
  4253.     else if ($strServerScriptName == dirname(dirname(__FILE__)) . $strDirectorySeparator . 'modules' . $strDirectorySeparator . 'registrars' . $strDirectorySeparator . 'internetbs' . $strDirectorySeparator . 'internetbssync.php') {
  4254.         $blnBypassError = true;
  4255.     }
  4256.     else if (substr($strServerScriptName, strrpos($strServerScriptName, $strDirectorySeparator) + 1) == 'internetbssync.php') {
  4257.         $blnBypassError = true;
  4258.     }
  4259.     else if ($strServerScriptName == dirname(dirname(__FILE__)) . $strDirectorySeparator . 'modules' . $strDirectorySeparator . 'registrars' . $strDirectorySeparator . 'ipmirror' . $strDirectorySeparator . 'ipmirrorsync.php') {
  4260.         $blnBypassError = true;
  4261.     }
  4262.     else if (substr($strServerScriptName, strrpos($strServerScriptName, $strDirectorySeparator) + 1) == 'ipmirrorsync.php') {
  4263.         $blnBypassError = true;
  4264.     }
  4265.     else if ($strServerScriptName == dirname(dirname(__FILE__)) . $strDirectorySeparator . 'modules' . $strDirectorySeparator . 'registrars' . $strDirectorySeparator . 'namecheap' . $strDirectorySeparator . 'namecheapsync.php') {
  4266.         $blnBypassError = true;
  4267.     }
  4268.     else if (substr($strServerScriptName, strrpos($strServerScriptName, $strDirectorySeparator) + 1) == 'namecheapsync.php') {
  4269.         $blnBypassError = true;
  4270.     }
  4271.     else if ($strServerScriptName == dirname(dirname(__FILE__)) . $strDirectorySeparator . 'modules' . $strDirectorySeparator . 'registrars' . $strDirectorySeparator . 'netearthone' . $strDirectorySeparator . 'netearthonesync.php') {
  4272.         $blnBypassError = true;
  4273.     }
  4274.     else if (substr($strServerScriptName, strrpos($strServerScriptName, $strDirectorySeparator) + 1) == 'netearthonesync.php') {
  4275.         $blnBypassError = true;
  4276.     }
  4277.     else if ($strServerScriptName == dirname(dirname(__FILE__)) . $strDirectorySeparator . 'modules' . $strDirectorySeparator . 'registrars' . $strDirectorySeparator . 'nominet' . $strDirectorySeparator . 'nominetsync.php') {
  4278.         $blnBypassError = true;
  4279.     }
  4280.     else if (substr($strServerScriptName, strrpos($strServerScriptName, $strDirectorySeparator) + 1) == 'nominetsync.php') {
  4281.         $blnBypassError = true;
  4282.     }
  4283.     else if ($strServerScriptName == dirname(dirname(__FILE__)) . $strDirectorySeparator . 'modules' . $strDirectorySeparator . 'registrars' . $strDirectorySeparator . 'onlinenic' . $strDirectorySeparator . 'onlinenicsync.php') {
  4284.         $blnBypassError = true;
  4285.     }
  4286.     else if (substr($strServerScriptName, strrpos($strServerScriptName, $strDirectorySeparator) + 1) == 'onlinenicsync.php') {
  4287.         $blnBypassError = true;
  4288.     }
  4289.     else if ($strServerScriptName == dirname(dirname(__FILE__)) . $strDirectorySeparator . 'modules' . $strDirectorySeparator . 'registrars' . $strDirectorySeparator . 'opensrs' . $strDirectorySeparator . 'opensrssync.php') {
  4290.         $blnBypassError = true;
  4291.     }
  4292.     else if (substr($strServerScriptName, strrpos($strServerScriptName, $strDirectorySeparator) + 1) == 'opensrssync.php') {
  4293.         $blnBypassError = true;
  4294.     }
  4295.     else if ($strServerScriptName == dirname(dirname(__FILE__)) . $strDirectorySeparator . 'modules' . $strDirectorySeparator . 'registrars' . $strDirectorySeparator . 'registercom' . $strDirectorySeparator . 'registercomsync.php') {
  4296.         $blnBypassError = true;
  4297.     }
  4298.     else if (substr($strServerScriptName, strrpos($strServerScriptName, $strDirectorySeparator) + 1) == 'registercomsync.php') {
  4299.         $blnBypassError = true;
  4300.     }
  4301.     else if ($strServerScriptName == dirname(dirname(__FILE__)) . $strDirectorySeparator . 'modules' . $strDirectorySeparator . 'registrars' . $strDirectorySeparator . 'registercom' . $strDirectorySeparator . 'registercomsync.php') {
  4302.         $blnBypassError = true;
  4303.     }
  4304.     else if (substr($strServerScriptName, strrpos($strServerScriptName, $strDirectorySeparator) + 1) == 'registercomsync.php') {
  4305.         $blnBypassError = true;
  4306.     }
  4307.     else if ($strServerScriptName == dirname(dirname(__FILE__)) . $strDirectorySeparator . 'modules' . $strDirectorySeparator . 'registrars' . $strDirectorySeparator . 'resellercamp' . $strDirectorySeparator . 'resellercampsync.php') {
  4308.         $blnBypassError = true;
  4309.     }
  4310.     else if (substr($strServerScriptName, strrpos($strServerScriptName, $strDirectorySeparator) + 1) == 'resellercampsync.php') {
  4311.         $blnBypassError = true;
  4312.     }
  4313.     else if ($strServerScriptName == dirname(dirname(__FILE__)) . $strDirectorySeparator . 'modules' . $strDirectorySeparator . 'registrars' . $strDirectorySeparator . 'resellerclub' . $strDirectorySeparator . 'resellerclubsync.php') {
  4314.         $blnBypassError = true;
  4315.     }
  4316.     else if (substr($strServerScriptName, strrpos($strServerScriptName, $strDirectorySeparator) + 1) == 'resellerclubsync.php') {
  4317.         $blnBypassError = true;
  4318.     }
  4319.     else if ($strServerScriptName == dirname(dirname(__FILE__)) . $strDirectorySeparator . 'modules' . $strDirectorySeparator . 'registrars' . $strDirectorySeparator . 'resellone' . $strDirectorySeparator . 'resellonesync.php') {
  4320.         $blnBypassError = true;
  4321.     }
  4322.     else if (substr($strServerScriptName, strrpos($strServerScriptName, $strDirectorySeparator) + 1) == 'resellonesync.php') {
  4323.         $blnBypassError = true;
  4324.     }
  4325.     else if ($strServerScriptName == dirname(dirname(__FILE__)) . $strDirectorySeparator . 'modules' . $strDirectorySeparator . 'registrars' . $strDirectorySeparator . 'stargate' . $strDirectorySeparator . 'stargatesync.php') {
  4326.         $blnBypassError = true;
  4327.     }
  4328.     else if (substr($strServerScriptName, strrpos($strServerScriptName, $strDirectorySeparator) + 1) == 'stargatesync.php') {
  4329.         $blnBypassError = true;
  4330.     }
  4331.     else if ($strServerScriptName == dirname(dirname(__FILE__)) . $strDirectorySeparator . 'modules' . $strDirectorySeparator . 'registrars' . $strDirectorySeparator . 'tppinternet' . $strDirectorySeparator . 'tppinternetsync.php') {
  4332.         $blnBypassError = true;
  4333.     }
  4334.     else if (substr($strServerScriptName, strrpos($strServerScriptName, $strDirectorySeparator) + 1) == 'tppinternetsync.php') {
  4335.         $blnBypassError = true;
  4336.     }
  4337.     else if ($strServerScriptName == dirname(dirname(__FILE__)) . $strDirectorySeparator . 'modules' . $strDirectorySeparator . 'servers' . $strDirectorySeparator . 'onappusers' . $strDirectorySeparator . 'cron.php') {
  4338.         $blnBypassError = true;
  4339.     }
  4340.     else if (substr($strServerScriptName, strrpos($strServerScriptName, $strDirectorySeparator) + 1) == 'cron.php') {
  4341.         $blnBypassError = true;
  4342.     }
  4343.     else if ($strServerScriptName == dirname(dirname(__FILE__)) . $strDirectorySeparator . 'control' . $strDirectorySeparator . 'cron.php') {
  4344.         $blnBypassError = true;
  4345.     }
  4346.     else if (substr($strServerScriptName, strrpos($strServerScriptName, $strDirectorySeparator) + 1) == 'cron.php') {
  4347.         $blnBypassError = true;
  4348.     }
  4349.     else if ($strServerScriptName == dirname(dirname(__FILE__)) . $strDirectorySeparator . 'modules' . $strDirectorySeparator . 'admin' . $strDirectorySeparator . 'ip_monitor' . $strDirectorySeparator . 'check.php') {
  4350.         $blnBypassError = true;
  4351.     }
  4352.     else if ($strServerScriptName == dirname(dirname(__FILE__)) . $strDirectorySeparator . 'admin' . $strDirectorySeparator . 'cron.php') {
  4353.         $blnBypassError = true;
  4354.     }
  4355.  
  4356.     return $blnBypassError;
  4357. }
  4358.  
  4359. $mstrReleaseDate = 'June 14th 2012';
  4360.  
  4361. if ($GLOBALS['license'] == 'Dev-7bdd6a5ed79a8a14af40') {
  4362.     $blnAKDLS = true;
  4363. }
  4364. else if ($GLOBALS['license'] == 'Leased-abc367f314a7142c44fd') {
  4365.     $blnAKDLS = true;
  4366. }
  4367. else {
  4368.     $blnAKDLS = false;
  4369. }
  4370.  
  4371. if ($blnAKDLS == false) {
  4372.     $strlLicenseKeyFile = '/aiso-vmware-license.key';
  4373.     $strlLicenseKeyFilePath = dirname(__FILE__);
  4374.     $aryCommandLineArgs = $_SERVER['argv'];
  4375.  
  4376.     if (php_sapi_name() == 'cli') {
  4377.         if (empty($_SERVER['REMOTE_ADDR']) && is_array($aryCommandLineArgs)) {
  4378.             $blnRunningFromCommandLine = true;
  4379.         }
  4380.     }
  4381.     else {
  4382.         $blnRunningFromCommandLine = true;
  4383.         $blnRunningFromCommandLine = false;
  4384.     }
  4385.  
  4386.     if (strlen($_SERVER['SCRIPT_NAME']) < 1) {
  4387.         if (is_array($aryCommandLineArgs)) {
  4388.             $_SERVER['SCRIPT_NAME'] = $aryCommandLineArgs[0];
  4389.         }
  4390.     }
  4391.  
  4392.     $spbas2 = new spbasVMware();
  4393.     if (@file_exists($strlLicenseKeyFilePath . $strlLicenseKeyFile) || @is_file($strlLicenseKeyFilePath . $strlLicenseKeyFile)) {
  4394.         $file_handle = fopen($strlLicenseKeyFilePath . $strlLicenseKeyFile, 'r');
  4395.  
  4396.         while (!feof($file_handle)) {
  4397.             $strLLicenseKey .= fgets($file_handle);
  4398.         }
  4399.  
  4400.         fclose($file_handle);
  4401.     }
  4402.  
  4403.     if (strlen($_POST['hslicensekey']) < 1) {
  4404.         $result = 'empty';
  4405.         $message = 'The License Key is empty. Please make sure that the file \'' . $strlLicenseKeyFile . '\' is writeable by the web server, then copy and paste your license key into the box below and click submit.<br /><br /><form action=\'\' method=\'POST\'><input type=\'text\' size=\'50\' name=\'hslicensekey\'><br /><br /><input type=\'submit\' id=\'submit\' name=\'submit\' value=\'Save\'></form>';
  4406.         $template = 'e1tNRVNTQUdFXX0=';
  4407.         exit(str_replace(array('{[RESULT]}', '{[MESSAGE]}'), array($result, $message), base64_decode($template)));
  4408.     }
  4409.     else if (strlen($_POST['hslicensekey']) < 1) {
  4410.         $result = 'empty';
  4411.         $message = 'The License Key is empty. Please make sure that the file \'' . $strlLicenseKeyFile . '\' is writeable by the web server, then copy and paste your license key into the box below and click submit.<br /><br /><form action=\'\' method=\'POST\'><input type=\'text\' size=\'50\' name=\'hslicensekey\'><br /><br /><input type=\'submit\' id=\'submit\' name=\'submit\' value=\'Save\'></form>';
  4412.         $template = 'e1tNRVNTQUdFXX0=';
  4413.         exit(str_replace(array('{[RESULT]}', '{[MESSAGE]}'), array($result, $message), base64_decode($template)));
  4414.     }
  4415.     else if (0 < strlen($_POST['hslicensekey'])) {
  4416.         $strLLicenseKey = preg_replace('/[^a-zA-Z0-9\\s\\-]/', '', $_POST['hslicensekey']);
  4417.         $h = fopen($strlLicenseKeyFilePath . $strlLicenseKeyFile, 'w');
  4418.  
  4419.         if (fwrite($h, $strLLicenseKey) === false) {
  4420.             exit('Could not write the license key to the license file ' . $strlLicenseKeyFilePath . $strlLicenseKeyFile);
  4421.         }
  4422.         else {
  4423.             fclose($h);
  4424.         }
  4425.     }
  4426.  
  4427.     if (0 < strlen($strLLicenseKey)) {
  4428.         $spbas2->license_key = $strLLicenseKey;
  4429.     }
  4430.  
  4431.     $spbas2->secret_key = 'a15fc43b3792b03b814345aa5bff1298';
  4432.     $spbas2->validate_download_access = true;
  4433.     $spbas2->release_date = $mstrReleaseDate;
  4434.     $spbas2->remote_port = 80;
  4435.     $spbas2->remote_timeout = 10;
  4436.  
  4437.     if (isset($_GET['clear_local_key_cache'])) {
  4438.         $spbas2->clear_cache_local_key();
  4439.     }
  4440.  
  4441.     $spbas2->api_server = 'http://order.heapsoftware.com/api/index.php';
  4442.     $spbas2->local_key_storage = 'filesystem';
  4443.     $spbas2->local_key_path = dirname(__FILE__) . '/';
  4444.     $spbas2->local_key_name = 'aiso-vmware-license.dat';
  4445.     $spbas2->validate();
  4446.     $aryCommandLineArgs = $_SERVER['argv'];
  4447.  
  4448.     if (strlen($_SERVER['SCRIPT_NAME']) < 1) {
  4449.         if (is_array($aryCommandLineArgs)) {
  4450.             $_SERVER['SCRIPT_NAME'] = $aryCommandLineArgs[0];
  4451.         }
  4452.     }
  4453.  
  4454.     if ($spbas2->errors) {
  4455.         $blnBypassError = false;
  4456.  
  4457.         if ($blnRunningFromCommandLine == true) {
  4458.             $blnBypassError = true;
  4459.         }
  4460.  
  4461.         if ($blnBypassError != true) {
  4462.             exit('WHMCS VMware Module ' . $spbas2->errors);
  4463.         }
  4464.     }
  4465.  
  4466.     unset($blnBypassError);
  4467.     unset($spbas2);
  4468. }
  4469.  
  4470. if ($blnAKDLS == false) {
  4471.     require_once dirname(dirname(dirname(dirname(__FILE__)))) . '/includes/nusoap/nusoap.php';
  4472.     if (@file_exists(dirname(dirname(dirname(dirname(__FILE__)))) . '/includes/aiso-vmware-functions.php') || @is_file(dirname(dirname(dirname(dirname(__FILE__)))) . '/includes/aiso-vmware-functions.php')) {
  4473.         exit('WHMCS VMware Module Error: Please delete the file \'includes/aiso-vmware-functions.php\' in your WHMCS install, it is no longer required.');
  4474.     }
  4475. }
  4476. else {
  4477.     require_once dirname(dirname(dirname(dirname(__FILE__)))) . '/includes/aiso-vmware-functions.php';
  4478. }
  4479.  
  4480. define('CHARTS_SOURCE', dirname(dirname(dirname(dirname(__FILE__)))) . '/includes/phpcharts/');
  4481. require_once CHARTS_SOURCE . 'chartclasses.php';
  4482. global $mstrVMWareWebServerCustomFieldName;
  4483. global $mblnNewWHMCSv5TemplateEnabled;
  4484. global $mstrConfigOptionDiskSpace;
  4485. global $mstrConfigOptionBandwidth;
  4486. global $mstrConfigOptionCPUAmount;
  4487. global $mstrConfigOptionRAM;
  4488. global $mstrUserConfigOptionsExtraDiskSpace;
  4489. global $mstrUserConfigOptionsExtraCPU;
  4490. global $mstrUserConfigOptionsExtraRAM;
  4491. global $mstrUserConfigOptionsServerOS;
  4492. global $mstrUserConfigOptionsInstallingCPanel;
  4493. global $mstrUserConfigOptionsExtraBandwidth;
  4494. global $garyVMwareServerOSToTemplateMapping;
  4495. global $gstrVMwareDataStoreNameForNewVMs;
  4496.  
  4497. if ($blnAKDLS == false) {
  4498.     global $maryVMwareServerOSToTemplateMapping;
  4499.     global $mstrVMwareDataStoreNameForNewVMs;
  4500.     require_once dirname(dirname(dirname(dirname(__FILE__)))) . '/includes/aiso-vmware-settings.php';
  4501.     $garyVMwareServerOSToTemplateMapping = $maryVMwareServerOSToTemplateMapping;
  4502.     $gstrVMwareDataStoreNameForNewVMs = $mstrVMwareDataStoreNameForNewVMs;
  4503. }
  4504. else {
  4505.     require_once dirname(dirname(dirname(dirname(__FILE__)))) . '/includes/aiso-variables.php';
  4506.     $mstrVMWareWebServerCustomFieldName = 'Server Name';
  4507.     $mblnNewWHMCSv5TemplateEnabled = True;
  4508. }
  4509.  
  4510. if (!isset($mblnNewWHMCSv5TemplateEnabled)) {
  4511.     $mblnNewWHMCSv5TemplateEnabled = False;
  4512. }
  4513.  
  4514. $mstrConfigOptionDiskSpace = 'configoption1';
  4515. $mstrConfigOptionBandwidth = 'configoption2';
  4516. $mstrConfigOptionCPUAmount = 'configoption3';
  4517. $mstrConfigOptionRAM = 'configoption4';
  4518. $mstrConfigOptionAutoProvisionFolder = 'configoption5';
  4519. $mstrConfigOptionAutoProvisionResourcePool = 'configoption6';
  4520. $mstrConfigOptionAutoProvisionTimezone = 'configoption7';
  4521. $mstrConfigOptionAutoProvisionHWUseUTC = 'configoption8';
  4522. $mstrConfigOptionAutoProvisionDatastore = 'configoption9';
  4523. $mstrUserConfigOptionsExtraDiskSpace = 'Extra GB Disk Space';
  4524. $mstrUserConfigOptionsExtraCPU = 'Extra vCPUs';
  4525. $mstrUserConfigOptionsExtraRAM = 'Extra GB vRAM';
  4526. $mstrUserConfigOptionsServerOS = 'Server OS';
  4527. $mstrUserConfigOptionsExtraBandwidth = 'Extra Mbps Bandwidth';
  4528. $mstrUserConfigOptionsInstallingCPanel = 'Will you be installing cPanel?';
  4529.  
  4530. if (strlen($mstrVMWareWebServerCustomFieldName) < 1) {
  4531.     exit('WHMCS VMware Module Error: VMware Web Server Custom Field Name Not Defined');
  4532. }
  4533.  
  4534. aisovmwarededsrv_load_language();
  4535.  
  4536. ?>
Add Comment
Please, Sign In to add comment