PageRenderTime 67ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/phpmyadmin/libraries/sqlvalidator.class.php

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