Guest User

Untitled

a guest
Jun 14th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.72 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * @file
  5. * Contains DrupalvmwareapiControllerVMwareController.
  6. */
  7. namespace DrupalvmwareapiController;
  8. use DrupalCoreControllerControllerBase;
  9.  
  10. #require_once("../../nusoap/nusoap.php");
  11.  
  12. /**
  13. * NuSoap is required, and included here.
  14. */
  15.  
  16.  
  17. /**
  18. * Controller routines for book routes.
  19. */
  20. class VMwareController extends ControllerBase {
  21.  
  22. private static $instance = NULL;
  23. private $session_result, $myconnection, $namespace;
  24. private $debug = 0;
  25. private $servicestatus = false;
  26. private $logedin = false;
  27. private $appliances = array();
  28.  
  29. /* process() retries, on error 503, $max_retries times
  30. * every $recursion_timeout seconds
  31. */
  32. private $max_retries = 15;
  33. private $recursion_timeout = 1;
  34. private $logfile = '';
  35.  
  36.  
  37. //public function VMwareAPI ($ip) {
  38. public function __construct ($ip, $user, $password) { //echo $password;exit();
  39. #echo $ip.$user.$password;exit();
  40. require_once './' . drupal_get_path('module', 'vmwareapi') . '/nusoap/nusoap.php';
  41. $this->myconnection = new nusoap_client("https://" . $ip ."/sdk/");
  42. $this->myconnection->timeout = 10;
  43. $this->myconnection->useHTTPPersistentConnection();
  44. $this->myconnection->soap_defencoding = "UTF-8";
  45. $this->namespace = "urn:vim25";
  46. $status = $this->_Login($user, $password);
  47. if (!$status) {
  48. drupal_set_message(
  49. t(
  50. 'Unable to connect to vCenter "@ip", check connection!',
  51. array('@ip' => $ip)
  52. ),
  53. 'error'
  54. );
  55. }
  56. }
  57.  
  58. public function __destruct () {
  59.  
  60. $this->_Logout();
  61. unset($this->myconnection);
  62. }
  63.  
  64. public static function getinstance($ip = NULL, $user, $password)
  65. {
  66. if (!isset(self::$instance)) {
  67. $className = __CLASS__;
  68. self::$instance = new $className($ip, $user, $password);
  69. }
  70. return self::$instance;
  71. }
  72. }
  73.  
  74. <?php
  75. namespace DrupalvmwareapiController;
  76. /**
  77. *
  78. * nusoap_base
  79. *
  80. * @author Dietrich Ayala <dietrich@ganx4.com>
  81. * @author Scott Nichol <snichol@users.sourceforge.net>
  82. * @version $Id: nusoap.php,v 1.123 2010/04/26 20:15:08 snichol Exp $
  83. * @access public
  84. */
  85. class nusoap_base {
  86. /**
  87. * Identification for HTTP headers.
  88. *
  89. * @var string
  90. * @access private
  91. */
  92. var $title = 'NuSOAP';
  93. /**
  94. * Version for HTTP headers.
  95. *
  96. * @var string
  97. * @access private
  98. */
  99. var $version = '0.9.5';
  100. /**
  101. * CVS revision for HTTP headers.
  102. *
  103. * @var string
  104. * @access private
  105. */
  106. var $revision = '$Revision: 1.123 $';
  107. /**
  108. * Current error string (manipulated by getError/setError)
  109. *
  110. * @var string
  111. * @access private
  112. */
  113. var $error_str = '';
  114. /**
  115. * Current debug string (manipulated by debug/appendDebug/clearDebug/getDebug/getDebugAsXMLComment)
  116. *
  117. * @var string
  118. * @access private
  119. */
  120. var $debug_str = '';
  121. /**
  122. * toggles automatic encoding of special characters as entities
  123. * (should always be true, I think)
  124. *
  125. * @var boolean
  126. * @access private
  127. */
  128. var $charencoding = true;
  129. /**
  130. * the debug level for this instance
  131. *
  132. * @var integer
  133. * @access private
  134. */
  135. var $debugLevel;
  136.  
  137. /**
  138. * set schema version
  139. *
  140. * @var string
  141. * @access public
  142. */
  143. var $XMLSchemaVersion = 'http://www.w3.org/2001/XMLSchema';
  144.  
  145. /**
  146. * charset encoding for outgoing messages
  147. *
  148. * @var string
  149. * @access public
  150. */
  151. var $soap_defencoding = 'ISO-8859-1';
  152. //var $soap_defencoding = 'UTF-8';
  153.  
  154. /**
  155. * namespaces in an array of prefix => uri
  156. *
  157. * this is "seeded" by a set of constants, but it may be altered by code
  158. *
  159. * @var array
  160. * @access public
  161. */
  162. var $namespaces = array(
  163. 'SOAP-ENV' => 'http://schemas.xmlsoap.org/soap/envelope/',
  164. 'xsd' => 'http://www.w3.org/2001/XMLSchema',
  165. 'xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
  166. 'SOAP-ENC' => 'http://schemas.xmlsoap.org/soap/encoding/'
  167. );
  168.  
  169. /**
  170. * namespaces used in the current context, e.g. during serialization
  171. *
  172. * @var array
  173. * @access private
  174. */
  175. var $usedNamespaces = array();
  176.  
  177. /**
  178. * XML Schema types in an array of uri => (array of xml type => php type)
  179. * is this legacy yet?
  180. * no, this is used by the nusoap_xmlschema class to verify type => namespace mappings.
  181. * @var array
  182. * @access public
  183. */
  184. var $typemap = array(
  185. 'http://www.w3.org/2001/XMLSchema' => array(
  186. 'string'=>'string','boolean'=>'boolean','float'=>'double','double'=>'double','decimal'=>'double',
  187. 'duration'=>'','dateTime'=>'string','time'=>'string','date'=>'string','gYearMonth'=>'',
  188. 'gYear'=>'','gMonthDay'=>'','gDay'=>'','gMonth'=>'','hexBinary'=>'string','base64Binary'=>'string',
  189. // abstract "any" types
  190. 'anyType'=>'string','anySimpleType'=>'string',
  191. // derived datatypes
  192. 'normalizedString'=>'string','token'=>'string','language'=>'','NMTOKEN'=>'','NMTOKENS'=>'','Name'=>'','NCName'=>'','ID'=>'',
  193. 'IDREF'=>'','IDREFS'=>'','ENTITY'=>'','ENTITIES'=>'','integer'=>'integer','nonPositiveInteger'=>'integer',
  194. 'negativeInteger'=>'integer','long'=>'integer','int'=>'integer','short'=>'integer','byte'=>'integer','nonNegativeInteger'=>'integer',
  195. 'unsignedLong'=>'','unsignedInt'=>'','unsignedShort'=>'','unsignedByte'=>'','positiveInteger'=>''),
  196. 'http://www.w3.org/2000/10/XMLSchema' => array(
  197. 'i4'=>'','int'=>'integer','boolean'=>'boolean','string'=>'string','double'=>'double',
  198. 'float'=>'double','dateTime'=>'string',
  199. 'timeInstant'=>'string','base64Binary'=>'string','base64'=>'string','ur-type'=>'array'),
  200. 'http://www.w3.org/1999/XMLSchema' => array(
  201. 'i4'=>'','int'=>'integer','boolean'=>'boolean','string'=>'string','double'=>'double',
  202. 'float'=>'double','dateTime'=>'string',
  203. 'timeInstant'=>'string','base64Binary'=>'string','base64'=>'string','ur-type'=>'array'),
  204. 'http://soapinterop.org/xsd' => array('SOAPStruct'=>'struct'),
  205. 'http://schemas.xmlsoap.org/soap/encoding/' => array('base64'=>'string','array'=>'array','Array'=>'array'),
  206. 'http://xml.apache.org/xml-soap' => array('Map')
  207. );
  208.  
  209. /**
  210. * XML entities to convert
  211. *
  212. * @var array
  213. * @access public
  214. * @deprecated
  215. * @see expandEntities
  216. */
  217. var $xmlEntities = array('quot' => '"','amp' => '&',
  218. 'lt' => '<','gt' => '>','apos' => "'");
  219.  
  220. /**
  221. * constructor
  222. *
  223. * @access public
  224. */
  225. function nusoap_base() {
  226. $this->debugLevel = $GLOBALS['_transient']['static']['nusoap_base']['globalDebugLevel'];
  227. }
  228. ...................
  229. * @author Dietrich Ayala <dietrich@ganx4.com>
  230. * @author Scott Nichol <snichol@users.sourceforge.net>
  231. * @version $Id: nusoap.php,v 1.123 2010/04/26 20:15:08 snichol Exp $
  232. * @access public
  233. */
  234. class nusoap_client extends nusoap_base {
  235. var $username = ''; // Username for HTTP authentication
  236. var $password = ''; // Password for HTTP authentication
  237. var $authtype = ''; // Type of HTTP authentication
  238. var $certRequest = array(); // Certificate for HTTP SSL authentication
  239. var $requestHeaders = false; // SOAP headers in request (text)
  240. var $responseHeaders = ''; // SOAP headers from response (incomplete namespace resolution) (text)
  241. var $responseHeader = NULL; // SOAP Header from response (parsed)
  242. var $document = ''; // SOAP body response portion (incomplete namespace resolution) (text)
  243. var $endpoint;
  244. var $forceEndpoint = ''; // overrides WSDL endpoint
  245. var $proxyhost = '';
  246. var $proxyport = '';
  247. var $proxyusername = '';
  248. var $proxypassword = '';
  249. var $portName = ''; // port name to use in WSDL
  250. var $xml_encoding = ''; // character set encoding of incoming (response) messages
  251. var $http_encoding = false;
  252. var $timeout = 0; // HTTP connection timeout
  253. var $response_timeout = 30; // HTTP response timeout
  254. var $endpointType = ''; // soap|wsdl, empty for WSDL initialization error
  255. var $persistentConnection = false;
  256. var $defaultRpcParams = false; // This is no longer used
  257. var $request = ''; // HTTP request
  258. var $response = ''; // HTTP response
  259. var $responseData = ''; // SOAP payload of response
  260. var $cookies = array(); // Cookies from response or for request
  261. var $decode_utf8 = true; // toggles whether the parser decodes element content w/ utf8_decode()
  262. var $operations = array(); // WSDL operations, empty for WSDL initialization error
  263. var $curl_options = array(); // User-specified cURL options
  264. var $bindingType = ''; // WSDL operation binding type
  265. var $use_curl = false; // whether to always try to use cURL
  266.  
  267. public function __construct () {
  268. #echo 'soap constructor';exit();
  269. #nusoap_client($endpoint,$wsdl = false,$proxyhost = false,$proxyport = false,$proxyusername = false, $proxypassword = false, $timeout = 0, $response_timeout = 30, $portName = '');
  270. }
  271. /*
  272. * fault related variables
  273. */
  274. /**
  275. * @var fault
  276. * @access public
  277. */
  278. var $fault;
  279. /**
  280. * @var faultcode
  281. * @access public
  282. */
  283. var $faultcode;
  284. /**
  285. * @var faultstring
  286. * @access public
  287. */
  288. var $faultstring;
  289. /**
  290. * @var faultdetail
  291. * @access public
  292. */
  293. var $faultdetail;
  294.  
  295. /**
  296. * constructor
  297. *
  298. * @param mixed $endpoint SOAP server or WSDL URL (string), or wsdl instance (object)
  299. * @param mixed $wsdl optional, set to 'wsdl' or true if using WSDL
  300. * @param string $host optional
  301. * @param string $port optional
  302. * @param string $username optional
  303. * @param string $password optional
  304. * @param integer $timeout set the connection timeout
  305. * @param integer $response_timeout set the response timeout
  306. * @param string $portName optional portName in WSDL document
  307. * @access public
  308. */
  309. function nusoap_client($endpoint,$wsdl = false,$host = false,$port = false,$username = false, $password = false, $timeout = 0, $response_timeout = 30, $portName = ''){
  310.  
  311. parent::nusoap_base();
  312. $this->endpoint = $endpoint;
  313. $this->host = $host;
  314. $this->port = $port;
  315. $this->username = $username;
  316. $this->password = $password;
  317. $this->timeout = $timeout;
  318. $this->response_timeout = $response_timeout;
  319. $this->portName = $portName;
  320.  
  321. $this->debug("ctor wsdl=$wsdl timeout=$timeout response_timeout=$response_timeout");
  322. $this->appendDebug('endpoint=' . $this->varDump($endpoint));
  323.  
  324. // make values
  325. if($wsdl){
  326. if (is_object($endpoint) && (get_class($endpoint) == 'wsdl')) {
  327. $this->wsdl = $endpoint;
  328. $this->endpoint = $this->wsdl->wsdl;
  329. $this->wsdlFile = $this->endpoint;
  330. $this->debug('existing wsdl instance created from ' . $this->endpoint);
  331. $this->checkWSDL();
  332. } else {
  333. $this->wsdlFile = $this->endpoint;
  334. $this->wsdl = null;
  335. $this->debug('will use lazy evaluation of wsdl from ' . $this->endpoint);
  336. }
  337. $this->endpointType = 'wsdl';
  338. } else {
  339. $this->debug("instantiate SOAP with endpoint at $endpoint");
  340. $this->endpointType = 'soap';
  341. }
  342. }
  343.  
  344. $instance = VMwareController::getinstance($host, $user, $pass);
Add Comment
Please, Sign In to add comment