Advertisement
Guest User

Untitled

a guest
Apr 1st, 2013
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.88 KB | None | 0 0
  1. <?php
  2. /**
  3. *
  4. * @ This file is created by deZender.Net
  5. * @ deZender (PHP5 Decoder for ionCube Encoder)
  6. *
  7. * @ Version : 1.1.5.0
  8. * @ Author : DeZender
  9. * @ Release on : 09.06.2012
  10. * @ Official site : http://DeZender.Net
  11. *
  12. */
  13.  
  14. require_once( MAINDIR . 'includes' . DS . 'libs' . DS . 'cloudstack' . DS . 'CloudStackClient.php' );
  15. require_once( MAINDIR . 'includes' . DS . 'libs' . DS . 'cloudstack' . DS . 'CloudStackAdmin.php' );
  16. class CloudStack extends VPSModule {
  17. var $onapp_tz = array( 'AX' => 'Europe/Minsk', 'AL' => 'CET', 'DZ' => 'CET', 'AS' => 'Pacific/Samoa', 'AD' => 'CET', 'AO' => 'CET', 'AI' => 'America/Santiago', 'AQ' => 'Asia/Taipei', 'AG' => 'America/Santiago', 'AR' => 'Etc/GMT+2', 'AW' => 'America/Santiago', 'AT' => 'CET', 'BS' => 'America/New_York', 'BH' => 'Africa/Nairobi', 'BB' => 'America/Santiago', 'BY' => 'Europe/Minsk', 'BE' => 'CET', 'BZ' => 'Canada/Saskatchewan', 'BJ' => 'CET', 'BM' => 'America/Santiago', 'BO' => 'America/Santiago', 'BA' => 'CET', 'BW' => 'Europe/Minsk', 'BR' => 'America/Montevideo', 'BN' => 'Asia/Taipei', 'BG' => 'Europe/Minsk', 'BI' => 'Europe/Minsk', 'CM' => 'CET', 'CA' => 'America/New_York', 'CV' => 'Atlantic/Cape_Verde', 'KY' => 'America/New_York', 'CF' => 'CET', 'TD' => 'CET', 'CL' => 'America/Montevideo', 'CN' => 'Asia/Taipei', 'CO' => 'America/New_York', 'KM' => 'Africa/Nairobi', 'CG' => 'CET', 'CD' => 'CET', 'CK' => 'Pacific/Honolulu', 'CR' => 'Canada/Saskatchewan', 'HR' => 'CET', 'CU' => 'America/New_York', 'CY' => 'Europe/Minsk', 'CZ' => 'CET', 'DK' => 'CET', 'DJ' => 'Africa/Nairobi', 'DM' => 'America/Santiago', 'DO' => 'America/Santiago', 'EC' => 'America/New_York', 'EG' => 'Europe/Minsk', 'SV' => 'Canada/Saskatchewan', 'GQ' => 'CET', 'ER' => 'Africa/Nairobi', 'EE' => 'Europe/Minsk', 'ET' => 'Africa/Nairobi', 'FK' => 'America/Montevideo', 'FJ' => 'Pacific/Auckland', 'FI' => 'Europe/Minsk', 'FR' => 'CET', 'GF' => 'America/Montevideo', 'PF' => 'US/Alaska', 'TF' => 'Asia/Karachi', 'GA' => 'CET', 'DE' => 'CET', 'GI' => 'CET', 'GR' => 'Europe/Minsk', 'GD' => 'America/Santiago', 'GP' => 'America/Santiago', 'GU' => 'Pacific/Guam', 'GT' => 'Canada/Saskatchewan', 'GY' => 'America/Santiago', 'HT' => 'America/New_York', 'VA' => 'CET', 'HN' => 'Canada/Saskatchewan', 'HK' => 'Asia/Taipei', 'HU' => 'CET', 'IN' => 'Asia/Bangkok', 'IQ' => 'Africa/Nairobi', 'IL' => 'Europe/Minsk', 'IT' => 'CET', 'JM' => 'America/New_York', 'JP' => 'Asia/Seoul', 'JO' => 'Europe/Minsk', 'KE' => 'Africa/Nairobi', 'KR' => 'Asia/Seoul', 'KW' => 'Africa/Nairobi', 'LV' => 'Europe/Minsk', 'LB' => 'Europe/Minsk', 'LS' => 'Europe/Minsk', 'LY' => 'Europe/Minsk', 'LI' => 'CET', 'LT' => 'Europe/Minsk', 'LU' => 'CET', 'MO' => 'Asia/Taipei', 'MK' => 'CET', 'MG' => 'Africa/Nairobi', 'MW' => 'Europe/Minsk', 'MY' => 'Asia/Taipei', 'MV' => 'Asia/Karachi', 'MT' => 'CET', 'MH' => 'Pacific/Auckland', 'MQ' => 'America/Santiago', 'MU' => 'Asia/Karachi', 'YT' => 'Africa/Nairobi', 'MX' => 'Canada/Saskatchewan', 'MD' => 'Europe/Minsk', 'MC' => 'CET', 'MN' => 'Asia/Taipei', 'ME' => 'CET', 'MS' => 'America/Santiago', 'MZ' => 'Europe/Minsk', 'NA' => 'Europe/Minsk', 'NR' => 'Pacific/Auckland', 'NL' => 'CET', 'AN' => 'America/Santiago', 'NI' => 'Canada/Saskatchewan', 'NE' => 'CET', 'NG' => 'CET', 'NU' => 'Pacific/Samoa', 'MP' => 'Pacific/Guam', 'NO' => 'CET', 'PK' => 'Asia/Karachi', 'PW' => 'Asia/Seoul', 'PS' => 'Europe/Minsk', 'PA' => 'America/New_York', 'PG' => 'Pacific/Guam', 'PY' => 'America/Montevideo', 'PE' => 'America/New_York', 'PH' => 'Asia/Taipei', 'PN' => 'Mexico/BajaNorte', 'PL' => 'CET', 'PT' => 'Atlantic/Cape_Verde', 'PR' => 'America/Santiago', 'QA' => 'Africa/Nairobi', 'RO' => 'Europe/Minsk', 'RU' => 'Pacific/Auckland', 'RW' => 'Europe/Minsk', 'BL' => 'America/Santiago', 'KN' => 'America/Santiago', 'LC' => 'America/Santiago', 'MF' => 'America/Santiago', 'PM' => 'America/Montevideo', 'VC' => 'America/Santiago', 'WS' => 'Pacific/Samoa', 'SM' => 'CET', 'SA' => 'Africa/Nairobi', 'RS' => 'CET', 'SG' => 'Asia/Taipei', 'SK' => 'CET', 'SI' => 'CET', 'SO' => 'Africa/Nairobi', 'ZA' => 'Europe/Minsk', 'GS' => 'Etc/GMT+2', 'ES' => 'CET', 'LK' => 'Asia/Bangkok', 'SD' => 'Africa/Nairobi', 'SR' => 'America/Montevideo', 'SJ' => 'CET', 'SZ' => 'Europe/Minsk', 'SE' => 'CET', 'CH' => 'CET', 'SY' => 'Europe/Minsk', 'TW' => 'Asia/Taipei', 'TJ' => 'Asia/Karachi', 'TZ' => 'Africa/Nairobi', 'TL' => 'Asia/Seoul', 'TK' => 'Pacific/Honolulu', 'TT' => 'America/Santiago', 'TN' => 'CET', 'TR' => 'Europe/Minsk', 'TM' => 'Asia/Karachi', 'TC' => 'America/New_York', 'TV' => 'Pacific/Auckland', 'UG' => 'Africa/Nairobi', 'UA' => 'Europe/Minsk', 'US' => 'Canada/Saskatchewan', 'UM' => 'Pacific/Honolulu', 'UY' => 'Etc/GMT+2', 'UZ' => 'Asia/Karachi', 'VG' => 'America/Santiago', 'VI' => 'America/Santiago', 'WF' => 'Pacific/Auckland', 'YE' => 'Africa/Nairobi', 'ZM' => 'Europe/Minsk', 'ZW' => 'Europe/Minsk' );
  18. private $version = '3.0.x.20121026';
  19. private $description = 'CloudStack provisioning module, learn more at http://hostbillapp.com/features/apps/cloudstack.html <br/><br/>
  20. For metered (hourly) billing to work your Cloudstack needs to have usage server running + daily task needs to be added (Settings->Task list)';
  21. var $serverTemplates = array( );
  22. private $serverFields = array( 'ssl' => true, 'maxaccounts' => false, 'status_url' => false, 'hash' => true, 'password' => false, 'field1' => true );
  23. private $serverFieldsDescription = array( 'username' => 'API Key', 'hash' => 'Secret Key', 'field1' => 'API port (default 8080)' );
  24. private $cache = array( );
  25. private $url = null;
  26. private $api_key = null;
  27. private $api_secret = null;
  28. private $connect_data = null;
  29. protected $admin_api = null;
  30. protected $client_api = null;
  31. private $vm_details = array( );
  32. private $cleanup = array( );
  33. private $lang = array( 'english' => array( 'OnAPPcrtype' => 'Signups of current client' ) );
  34. private $options = array( 'option30' => array( 'name' => 'networking type', 'value' => 'Basic', 'type' => 'select', 'default' => array( 0 => 'Basic', 1 => 'Advanced' ) ), 'option31' => array( 'name' => 'adv networking type', 'value' => 'a3', 'type' => 'select', 'default' => array( 0 => 'a1', 1 => 'a2', 2 => 'a3' ) ), 'option10' => array( 'name' => 'provtype', 'value' => 'Multiple Machines, full management', 'type' => 'select', 'default' => array( 0 => 'Multiple Machines, full management', 1 => 'Single Machine, autocreation' ) ), 'option3' => array( 'name' => 'mem_limit', 'value' => false, 'type' => 'input', 'variable' => 'memory', 'description' => 'Slider available: <a href="http://hostbillapp.com/fastconfig/forms/#onapp" target="_blank">learn more</a>' ), 'option4' => array( 'name' => 'cpu_limit', 'value' => false, 'type' => 'input', 'variable' => 'cpu', 'description' => 'Slider available: <a href="http://hostbillapp.com/fastconfig/forms/#onapp" target="_blank">learn more</a>' ), 'option5' => array( 'name' => 'cpu_share', 'value' => false, 'type' => 'input', 'variable' => 'cpu_share', 'description' => 'Slider available: <a href="http://hostbillapp.com/fastconfig/forms/#onapp" target="_blank">learn more</a>' ), 'option6' => array( 'name' => 'disk_size', 'value' => false, 'type' => 'input', 'variable' => 'disk_size', 'description' => 'Slider available: <a href="http://hostbillapp.com/fastconfig/forms/#onapp" target="_blank">learn more</a>' ), 'option9' => array( 'name' => 'pspeed', 'value' => false, 'type' => 'input', 'variable' => 'rate', 'description' => 'Slider available: <a href="http://hostbillapp.com/fastconfig/forms/#onapp" target="_blank">learn more</a>' ), 'option13' => array( 'name' => 'iplimit', 'value' => '1', 'type' => 'input', 'description' => 'Slider available: <a href="http://hostbillapp.com/fastconfig/forms/#onapp" target="_blank">learn more</a>', 'variable' => 'ip_address', 'default' => '1' ), 'option14' => array( 'name' => 'vmlimit', 'value' => '1', 'type' => 'input', 'default' => '1' ), 'option15' => array( 'name' => 'btlimit', 'value' => '1', 'type' => 'input', 'default' => '1' ), 'option16' => array( 'name' => 'tlimit', 'value' => '', 'type' => 'input', 'default' => '', 'description' => 'Slider available: <a href="http://hostbillapp.com/fastconfig/forms/#onapp" target="_blank">learn more</a>', 'variable' => 'datasent' ), 'option12' => array( 'name' => 'ost', 'value' => '', 'type' => 'input', 'variable' => 'os', 'description' => 'Allow to choose by client using <a href="#" onclick="$(\'#loadostemplates\').click();">Forms:Os</a>', 'default' => 'getOSTemplates' ), 'option22' => array( 'name' => 'networkzone', 'value' => array( 0 => 'Auto-Assign' ), 'type' => 'select', 'default' => array( 0 => 'Auto-Assign' ) ), 'option23' => array( 'name' => 'hypervisorzone', 'variable' => 'hypervisorzone', 'value' => array( 0 => 'Auto-Assign' ), 'type' => 'select', 'default' => array( 0 => 'Auto-Assign' ) ), 'offerha' => array( 'name' => 'OfferHa', 'variable' => 'offerha', 'value' => 0, 'type' => 'checkbox', 'default' => 0 ), 'primarystorage' => array( 'name' => 'primarystorage', 'variable' => 'primarystorage', 'value' => array( 0 => 'shared:Auto-Assign' ), 'type' => 'checkbox', 'default' => array( 0 => 'shared:Auto-Assign' ) ) );
  35. private $details = array( 'option1' => array( 'name' => 'username', 'value' => false, 'type' => 'input', 'default' => false ), 'option4' => array( 'name' => 'domain', 'value' => false, 'type' => 'input', 'default' => false ), 'option2' => array( 'name' => 'password', 'value' => false, 'type' => 'input', 'default' => false ), 'option5' => array( 'name' => 'rootpassword', 'value' => false, 'type' => 'hidden', 'default' => false ), 'option7' => array( 'name' => 'api_key', 'value' => false, 'type' => 'hidden', 'default' => false ), 'option8' => array( 'name' => 'secret_key', 'value' => false, 'type' => 'hidden', 'default' => false ), 'option9' => array( 'name' => 'account_id', 'value' => false, 'type' => 'hidden', 'default' => false ), 'option10' => array( 'name' => 'domain_id', 'value' => false, 'type' => 'hidden', 'default' => false ) );
  36. private $commands = array( 0 => 'Suspend', 1 => 'Terminate', 2 => 'Create', 3 => 'Unsuspend', 4 => 'ChangePackage' );
  37.  
  38. function install() {
  39. }
  40.  
  41. function upgrade(&$old_version) {
  42. $old = explode( '.', $old_version );
  43.  
  44. if (( isset( $old[3] ) && (int)$old[3] < 20120806 )) {
  45. $task = 'custom:' . $this->id . ':call_Daily';
  46. $conf = array( 'name' => 'Module - ' . $this->getModName( ) . ', daily cron call', 'run_every' => 'Time' );
  47. $automation = HBLoader::loadmodel( 'Configuration/AutomationSettings' );
  48. $automation->addCronTask( $task, $conf );
  49. return null;
  50. }
  51.  
  52.  
  53. if (( isset( $old[3] ) && (int)$old[3] < 20121026 )) {
  54. $this->db->exec( 'UPDATE hb_mettered_variables mv
  55. JOIN hb_products p ON p.id=mv.product_id
  56. JOIN hb_products_modules pm ON pm.product_id=p.id
  57. JOIN hb_modules_configuration m ON m.id=pm.module
  58. SET mv.unit_name= \'Hour\'
  59. WHERE m.filename=\'class.cloudstack.php\' AND mv.name IN (\'Snapshot\',\'Template\',\'Volume\',\'Public IP address\')' );
  60. }
  61.  
  62. }
  63.  
  64. function connect($connect) {
  65. if ($connect['secure']) {
  66. $this->url = 'https://';
  67. } else {
  68. $this->url = 'http://';
  69. }
  70.  
  71. $this->url = $this->url . (( !$connect['ip'] && $connect['host'] ) ? $connect['host'] : $connect['ip']);
  72.  
  73. if ($connect['field1']) {
  74. $this->url .= ':' . $connect['field1'];
  75. } else {
  76. $this->url .= ':8080';
  77. }
  78.  
  79. $this->url .= '/client/api';
  80. $this->api_key = $connect['username'];
  81. $this->api_secret = $connect['hash'];
  82. $this->connect_data = $connect;
  83. return $connect;
  84. }
  85.  
  86. function adminApi($result = 'object') {
  87. if (is_null( $this->admin_api )) {
  88. $this->admin_api = new CloudStackAdmin( $this->url, $this->api_key, $this->api_secret );
  89. }
  90.  
  91. $this->admin_api->setResponseMethod( $result );
  92. return $this->admin_api;
  93. }
  94.  
  95. function dropApi() {
  96. $this->admin_api = null;
  97. $this->client_api = null;
  98. }
  99.  
  100. function clientApi($result = 'object') {
  101. if (is_null( $this->client_api )) {
  102. $this->client_api = new CloudStackClient( $this->url, $this->details['option7']['value'], $this->details['option8']['value'] );
  103. }
  104.  
  105. $this->client_api->setResponseMethod( $result );
  106. return $this->client_api;
  107. }
  108.  
  109. function queryAsyncJob($api, $job, &$timelimit = 10) {
  110. if (is_object( $job )) {
  111. $job = (array)$job;
  112. }
  113.  
  114.  
  115. if (empty( $job['jobid'] )) {
  116. if (isset( $job['errortext'] )) {
  117. $this->addError( $job['errortext'] );
  118. }
  119.  
  120. return false;
  121. }
  122.  
  123. $begin = time( );
  124.  
  125. while (time( ) < $begin + $timelimit) {
  126. $job = (array)$api->queryAsyncJobResult( $job['jobid'] );
  127.  
  128. if (( !isset( $job['jobstatus'] ) && $job['errortext'] )) {
  129. return false;
  130. }
  131.  
  132.  
  133. if ($job['jobstatus'] == '1') {
  134. return $job['jobresult'];
  135. }
  136.  
  137.  
  138. if ($job['jobstatus'] == '2') {
  139. return false;
  140. }
  141.  
  142. sleep( 1 );
  143. }
  144.  
  145. return true;
  146. }
  147. .............................................................
  148. .........................
  149. .........
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement