home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / phpMyAdmin / libraries / sqlvalidator.class.php < prev    next >
Encoding:
PHP Script  |  2008-06-23  |  13.3 KB  |  413 lines

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