PageRenderTime 62ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/pma/libraries/sqlvalidator.class.php

https://bitbucket.org/pavolve/masterskayaludmila
PHP | 439 lines | 189 code | 59 blank | 191 comment | 21 complexity | 5ea7cbefb06f9d6f19aa894513259905 MD5 | raw file
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * PHP interface to MimerSQL Validator
  5. *
  6. * Copyright 2002, 2003 Robin Johnson <robbat2@users.sourceforge.net>
  7. * http://www.orbis-terrarum.net/?l=people.robbat2
  8. *
  9. * All data is transported over HTTP-SOAP
  10. * And uses either the PEAR SOAP Module or PHP SOAP extension
  11. *
  12. * Install instructions for PEAR SOAP:
  13. * Make sure you have a really recent PHP with PEAR support
  14. * run this: "pear install Mail_Mime Net_DIME SOAP"
  15. *
  16. * @access public
  17. *
  18. * @package PhpMyAdmin
  19. */
  20. if (! defined('PHPMYADMIN')) {
  21. exit;
  22. }
  23. /**
  24. * Load SOAP client.
  25. */
  26. if (class_exists('SOAPClient')) {
  27. $GLOBALS['sqlvalidator_error'] = false;
  28. $GLOBALS['sqlvalidator_soap'] = 'PHP';
  29. } else {
  30. @include_once 'SOAP/Client.php';
  31. if (class_exists('SOAP_Client')) {
  32. $GLOBALS['sqlvalidator_soap'] = 'PEAR';
  33. $GLOBALS['sqlvalidator_error'] = false;
  34. } else {
  35. $GLOBALS['sqlvalidator_soap'] = 'NONE';
  36. $GLOBALS['sqlvalidator_error'] = true;
  37. PMA_warnMissingExtension('soap');
  38. }
  39. }
  40. if (!$GLOBALS['sqlvalidator_error']) {
  41. // Ok, we have SOAP Support, so let's use it!
  42. /**
  43. * @package PhpMyAdmin
  44. */
  45. class PMA_SQLValidator
  46. {
  47. var $url;
  48. var $service_name;
  49. var $wsdl;
  50. var $output_type;
  51. var $username;
  52. var $password;
  53. var $calling_program;
  54. var $calling_program_version;
  55. var $target_dbms;
  56. var $target_dbms_version;
  57. var $connectionTechnology;
  58. var $connection_technology_version;
  59. var $interactive;
  60. var $service_link = null;
  61. var $session_data = null;
  62. /**
  63. * Private functions - You don't need to mess with these
  64. */
  65. /**
  66. * Service opening
  67. *
  68. * @param string URL of Mimer SQL Validator WSDL file
  69. *
  70. * @return object Object to use
  71. *
  72. * @access private
  73. */
  74. function _openService($url)
  75. {
  76. if ($GLOBALS['sqlvalidator_soap'] == 'PHP') {
  77. $obj = new SOAPClient($url);
  78. } else {
  79. $obj = new SOAP_Client($url, true);
  80. }
  81. return $obj;
  82. } // end of the "openService()" function
  83. /**
  84. * Service initializer to connect to server
  85. *
  86. * @param object Service object
  87. * @param string Username
  88. * @param string Password
  89. * @param string Name of calling program
  90. * @param string Version of calling program
  91. * @param string Target DBMS
  92. * @param string Version of target DBMS
  93. * @param string Connection Technology
  94. * @param string version of Connection Technology
  95. * @param integer boolean of 1/0 to specify if we are an interactive system
  96. *
  97. * @return object stdClass return object with data
  98. *
  99. * @access private
  100. */
  101. function _openSession($obj, $username, $password,
  102. $calling_program, $calling_program_version,
  103. $target_dbms, $target_dbms_version,
  104. $connection_technology, $connection_technology_version,
  105. $interactive)
  106. {
  107. $use_array = array(
  108. "a_userName" => $username,
  109. "a_password" => $password,
  110. "a_callingProgram" => $calling_program,
  111. "a_callingProgramVersion" => $calling_program_version,
  112. "a_targetDbms" => $target_dbms,
  113. "a_targetDbmsVersion" => $target_dbms_version,
  114. "a_connectionTechnology" => $connection_technology,
  115. "a_connectionTechnologyVersion" => $connection_technology_version,
  116. "a_interactive" => $interactive,
  117. );
  118. if ($GLOBALS['sqlvalidator_soap'] == 'PHP') {
  119. $ret = $obj->__soapCall("openSession", $use_array);
  120. } else {
  121. $ret = $obj->call("openSession", $use_array);
  122. }
  123. return $ret;
  124. } // end of the "_openSession()" function
  125. /**
  126. * Validator sytem call
  127. *
  128. * @param object Service object
  129. * @param object Session object
  130. * @param string SQL Query to validate
  131. * @param string Data return type
  132. *
  133. * @return object stClass return with data
  134. *
  135. * @access private
  136. */
  137. function _validateSQL($obj, $session, $sql, $method)
  138. {
  139. $use_array = array(
  140. "a_sessionId" => $session->sessionId,
  141. "a_sessionKey" => $session->sessionKey,
  142. "a_SQL" => $sql,
  143. "a_resultType" => $this->output_type,
  144. );
  145. if ($GLOBALS['sqlvalidator_soap'] == 'PHP') {
  146. $res = $obj->__soapCall("validateSQL", $use_array);
  147. } else {
  148. $res = $obj->call("validateSQL", $use_array);
  149. }
  150. return $res;
  151. } // end of the "validateSQL()" function
  152. /**
  153. * Validator sytem call
  154. *
  155. * @param string SQL Query to validate
  156. *
  157. * @return object stdClass return with data
  158. *
  159. * @access private
  160. *
  161. * @see validateSQL()
  162. */
  163. function _validate($sql)
  164. {
  165. $ret = $this->_validateSQL($this->service_link, $this->session_data,
  166. $sql, $this->output_type);
  167. return $ret;
  168. } // end of the "validate()" function
  169. /**
  170. * Public functions
  171. */
  172. /**
  173. * Constructor
  174. *
  175. * @access public
  176. */
  177. function __construct()
  178. {
  179. $this->url = 'http://sqlvalidator.mimer.com/v1/services';
  180. $this->service_name = 'SQL99Validator';
  181. $this->wsdl = '?wsdl';
  182. $this->output_type = 'html';
  183. $this->username = 'anonymous';
  184. $this->password = '';
  185. $this->calling_program = 'PHP_SQLValidator';
  186. $this->calling_program_version = PMA_VERSION;
  187. $this->target_dbms = 'N/A';
  188. $this->target_dbms_version = 'N/A';
  189. $this->connection_technology = 'PHP';
  190. $this->connection_technology_version = phpversion();
  191. $this->interactive = 1;
  192. $this->service_link = null;
  193. $this->session_data = null;
  194. } // end of the "PMA_SQLValidator()" function
  195. /**
  196. * Sets credentials
  197. *
  198. * @param string the username
  199. * @param string the password
  200. *
  201. * @access public
  202. */
  203. function setCredentials($username, $password)
  204. {
  205. $this->username = $username;
  206. $this->password = $password;
  207. } // end of the "setCredentials()" function
  208. /**
  209. * Sets the calling program
  210. *
  211. * @param string the calling program name
  212. * @param string the calling program revision
  213. *
  214. * @access public
  215. */
  216. function setCallingProgram($calling_program, $calling_program_version)
  217. {
  218. $this->calling_program = $calling_program;
  219. $this->calling_program_version = $calling_program_version;
  220. } // end of the "setCallingProgram()" function
  221. /**
  222. * Appends the calling program
  223. *
  224. * @param string the calling program name
  225. * @param string the calling program revision
  226. *
  227. * @access public
  228. */
  229. function appendCallingProgram($calling_program, $calling_program_version)
  230. {
  231. $this->calling_program .= ' - ' . $calling_program;
  232. $this->calling_program_version .= ' - ' . $calling_program_version;
  233. } // end of the "appendCallingProgram()" function
  234. /**
  235. * Sets the target DBMS
  236. *
  237. * @param string the target DBMS name
  238. * @param string the target DBMS revision
  239. *
  240. * @access public
  241. */
  242. function setTargetDbms($target_dbms, $target_dbms_version)
  243. {
  244. $this->target_dbms = $target_dbms;
  245. $this->target_dbms_version = $target_dbms_version;
  246. } // end of the "setTargetDbms()" function
  247. /**
  248. * Appends the target DBMS
  249. *
  250. * @param string the target DBMS name
  251. * @param string the target DBMS revision
  252. *
  253. * @access public
  254. */
  255. function appendTargetDbms($target_dbms, $target_dbms_version)
  256. {
  257. $this->target_dbms .= ' - ' . $target_dbms;
  258. $this->target_dbms_version .= ' - ' . $target_dbms_version;
  259. } // end of the "appendTargetDbms()" function
  260. /**
  261. * Sets the connection technology used
  262. *
  263. * @param string the connection technology name
  264. * @param string the connection technology revision
  265. *
  266. * @access public
  267. */
  268. function setConnectionTechnology($connection_technology, $connection_technology_version)
  269. {
  270. $this->connection_technology = $connection_technology;
  271. $this->connection_technology_version = $connection_technology_version;
  272. } // end of the "setConnectionTechnology()" function
  273. /**
  274. * Appends the connection technology used
  275. *
  276. * @param string the connection technology name
  277. * @param string the connection technology revision
  278. *
  279. * @access public
  280. */
  281. function appendConnectionTechnology($connection_technology, $connection_technology_version)
  282. {
  283. $this->connection_technology .= ' - ' . $connection_technology;
  284. $this->connection_technology_version .= ' - ' . $connection_technology_version;
  285. } // end of the "appendConnectionTechnology()" function
  286. /**
  287. * Sets whether interactive mode should be used or not
  288. *
  289. * @param integer whether interactive mode should be used or not
  290. *
  291. * @access public
  292. */
  293. function setInteractive($interactive)
  294. {
  295. $this->interactive = $interactive;
  296. } // end of the "setInteractive()" function
  297. /**
  298. * Sets the output type to use
  299. *
  300. * @param string the output type to use
  301. *
  302. * @access public
  303. */
  304. function setOutputType($output_type)
  305. {
  306. $this->output_type = $output_type;
  307. } // end of the "setOutputType()" function
  308. /**
  309. * Starts service
  310. *
  311. * @access public
  312. */
  313. function startService()
  314. {
  315. $this->service_link = $this->_openService($this->url . '/' . $this->service_name . $this->wsdl);
  316. } // end of the "startService()" function
  317. /**
  318. * Starts session
  319. *
  320. * @access public
  321. */
  322. function startSession()
  323. {
  324. $this->session_data = $this->_openSession($this->service_link, $this->username, $this->password,
  325. $this->calling_program, $this->calling_program_version,
  326. $this->target_dbms, $this->target_dbms_version,
  327. $this->connection_technology, $this->connection_technology_version,
  328. $this->interactive);
  329. if (isset($this->session_data) && ($this->session_data != null)
  330. && ($this->session_data->target != $this->url)) {
  331. // Reopens the service on the new URL that was provided
  332. $url = $this->session_data->target;
  333. $this->startService();
  334. }
  335. } // end of the "startSession()" function
  336. /**
  337. * Do start service and session
  338. *
  339. * @access public
  340. */
  341. function start()
  342. {
  343. $this->startService();
  344. $this->startSession();
  345. } // end of the "start()" function
  346. /**
  347. * Call to determine just if a query is valid or not.
  348. *
  349. * @param string SQL statement to validate
  350. *
  351. * @return string Validator string from Mimer
  352. *
  353. * @see _validate
  354. */
  355. function isValid($sql)
  356. {
  357. $res = $this->_validate($sql);
  358. return $res->standard;
  359. } // end of the "isValid()" function
  360. /**
  361. * Call for complete validator response
  362. *
  363. * @param string SQL statement to validate
  364. *
  365. * @return string Validator string from Mimer
  366. *
  367. * @see _validate
  368. */
  369. function validationString($sql)
  370. {
  371. $res = $this->_validate($sql);
  372. return $res->data;
  373. } // end of the "validationString()" function
  374. } // end class PMA_SQLValidator
  375. //add an extra check to ensure that the class was defined without errors
  376. if (!class_exists('PMA_SQLValidator')) {
  377. $GLOBALS['sqlvalidator_error'] = true;
  378. }
  379. } // end else
  380. ?>