Add phpdoc package header to some files.

This commit is contained in:
Michal Čihař
2008-11-24 09:14:31 +00:00
parent bf0f94a626
commit 5d010348da
19 changed files with 170 additions and 148 deletions

View File

@@ -3,6 +3,7 @@
/** /**
* Set of functions used to run config authentication (ie no authentication). * Set of functions used to run config authentication (ie no authentication).
* *
* @package phpMyAdmin-Auth-Config
* @version $Id$ * @version $Id$
*/ */

View File

@@ -5,6 +5,7 @@
* Thanks to Piotr Roszatycki <d3xter at users.sourceforge.net> and * Thanks to Piotr Roszatycki <d3xter at users.sourceforge.net> and
* Dan Wilson who built this patch for the Debian package. * Dan Wilson who built this patch for the Debian package.
* *
* @package phpMyAdmin-Auth-Cookie
* @version $Id$ * @version $Id$
*/ */
@@ -221,7 +222,7 @@ if (top != self) {
// use fieldset, don't show doc link // use fieldset, don't show doc link
PMA_select_language(true, false); PMA_select_language(true, false);
} }
?> ?>
<br /> <br />
<!-- Login form --> <!-- Login form -->

View File

@@ -4,6 +4,7 @@
* Set of functions used to run http authentication. * Set of functions used to run http authentication.
* NOTE: Requires PHP loaded as a Apache module. * NOTE: Requires PHP loaded as a Apache module.
* *
* @package phpMyAdmin-Auth-HTTP
* @version $Id$ * @version $Id$
*/ */

View File

@@ -3,6 +3,7 @@
/** /**
* Set of functions used to run single signon authentication. * Set of functions used to run single signon authentication.
* *
* @package phpMyAdmin-Auth-Signon
* @version $Id$ * @version $Id$
*/ */

View File

@@ -1,5 +1,8 @@
<?php <?php
/**
* @package Swekey
*/
function Swekey_auth_check() function Swekey_auth_check()
{ {
global $cfg; global $cfg;
@@ -8,7 +11,7 @@ function Swekey_auth_check()
if (! isset($_SESSION['SWEKEY'])) { if (! isset($_SESSION['SWEKEY'])) {
$_SESSION['SWEKEY'] = array(); $_SESSION['SWEKEY'] = array();
} }
$_SESSION['SWEKEY']['ENABLED'] = (! empty($confFile) && file_exists($confFile)); $_SESSION['SWEKEY']['ENABLED'] = (! empty($confFile) && file_exists($confFile));
// Load the swekey.conf file the first time // Load the swekey.conf file the first time
@@ -17,21 +20,21 @@ function Swekey_auth_check()
$_SESSION['SWEKEY']['VALID_SWEKEYS'] = array(); $_SESSION['SWEKEY']['VALID_SWEKEYS'] = array();
$valid_swekeys = split("\n",@file_get_contents($confFile)); $valid_swekeys = split("\n",@file_get_contents($confFile));
foreach ($valid_swekeys as $line) { foreach ($valid_swekeys as $line) {
if (ereg("^[0-9A-F]{32}:.+$", $line) != false) if (ereg("^[0-9A-F]{32}:.+$", $line) != false)
{ {
$items = explode(":", $line); $items = explode(":", $line);
if (count($items) == 2) if (count($items) == 2)
$_SESSION['SWEKEY']['VALID_SWEKEYS'][$items[0]] = trim($items[1]); $_SESSION['SWEKEY']['VALID_SWEKEYS'][$items[0]] = trim($items[1]);
} }
else if (ereg("^[A-Z_]+=.*$", $line) != false) { else if (ereg("^[A-Z_]+=.*$", $line) != false) {
$items = explode("=", $line); $items = explode("=", $line);
$_SESSION['SWEKEY']['CONF_'.trim($items[0])] = trim($items[1]); $_SESSION['SWEKEY']['CONF_'.trim($items[0])] = trim($items[1]);
} }
} }
// Set default values for settings // Set default values for settings
if (! isset($_SESSION['SWEKEY']['CONF_SERVER_CHECK'])) if (! isset($_SESSION['SWEKEY']['CONF_SERVER_CHECK']))
$_SESSION['SWEKEY']['CONF_SERVER_CHECK'] = ""; $_SESSION['SWEKEY']['CONF_SERVER_CHECK'] = "";
if (! isset($_SESSION['SWEKEY']['CONF_SERVER_RNDTOKEN'])) if (! isset($_SESSION['SWEKEY']['CONF_SERVER_RNDTOKEN']))
$_SESSION['SWEKEY']['CONF_SERVER_RNDTOKEN'] = ""; $_SESSION['SWEKEY']['CONF_SERVER_RNDTOKEN'] = "";
if (! isset($_SESSION['SWEKEY']['CONF_SERVER_STATUS'])) if (! isset($_SESSION['SWEKEY']['CONF_SERVER_STATUS']))
@@ -41,25 +44,25 @@ function Swekey_auth_check()
if (! isset($_SESSION['SWEKEY']['CONF_ENABLE_TOKEN_CACHE'])) if (! isset($_SESSION['SWEKEY']['CONF_ENABLE_TOKEN_CACHE']))
$_SESSION['SWEKEY']['CONF_ENABLE_TOKEN_CACHE'] = true; $_SESSION['SWEKEY']['CONF_ENABLE_TOKEN_CACHE'] = true;
if (! isset($_SESSION['SWEKEY']['CONF_DEBUG'])) if (! isset($_SESSION['SWEKEY']['CONF_DEBUG']))
$_SESSION['SWEKEY']['CONF_DEBUG'] = false; $_SESSION['SWEKEY']['CONF_DEBUG'] = false;
} }
// check if a web key has been authenticated // check if a web key has been authenticated
if ($_SESSION['SWEKEY']['ENABLED']) { if ($_SESSION['SWEKEY']['ENABLED']) {
if (empty($_SESSION['SWEKEY']['AUTHENTICATED_SWEKEY'])) if (empty($_SESSION['SWEKEY']['AUTHENTICATED_SWEKEY']))
return false; return false;
} }
return true; return true;
} }
function Swekey_auth_error() function Swekey_auth_error()
{ {
if (! isset($_SESSION['SWEKEY'])) if (! isset($_SESSION['SWEKEY']))
return null; return null;
if (! $_SESSION['SWEKEY']['ENABLED']) if (! $_SESSION['SWEKEY']['ENABLED'])
return null; return null;
require_once './libraries/auth/swekey/authentication.inc.php'; require_once './libraries/auth/swekey/authentication.inc.php';
@@ -68,31 +71,31 @@ function Swekey_auth_error()
<script> <script>
function Swekey_GetValidKey() function Swekey_GetValidKey()
{ {
var valids = "<?php var valids = "<?php
foreach ($_SESSION['SWEKEY']['VALID_SWEKEYS'] as $key => $value) foreach ($_SESSION['SWEKEY']['VALID_SWEKEYS'] as $key => $value)
echo $key.','; echo $key.',';
?>"; ?>";
var connected_keys = Swekey_ListKeyIds().split(","); var connected_keys = Swekey_ListKeyIds().split(",");
for (i in connected_keys) for (i in connected_keys)
if (connected_keys[i] != null && connected_keys[i].length == 32) if (connected_keys[i] != null && connected_keys[i].length == 32)
if (valids.indexOf(connected_keys[i]) >= 0) if (valids.indexOf(connected_keys[i]) >= 0)
return connected_keys[i]; return connected_keys[i];
if (connected_keys.length > 0) if (connected_keys.length > 0)
if (connected_keys[0].length == 32) if (connected_keys[0].length == 32)
return "unknown_key_" + connected_keys[0]; return "unknown_key_" + connected_keys[0];
return "none"; return "none";
} }
var key = Swekey_GetValidKey(); var key = Swekey_GetValidKey();
function timedCheck() function timedCheck()
{ {
if (key != Swekey_GetValidKey()) if (key != Swekey_GetValidKey())
{ {
window.location.search = "?swekey_reset"; window.location.search = "?swekey_reset";
} }
else else
setTimeout("timedCheck()",1000); setTimeout("timedCheck()",1000);
@@ -102,14 +105,14 @@ function Swekey_auth_error()
</script> </script>
<?php <?php
if (! empty($_SESSION['SWEKEY']['AUTHENTICATED_SWEKEY'])) if (! empty($_SESSION['SWEKEY']['AUTHENTICATED_SWEKEY']))
return null; return null;
if (count($_SESSION['SWEKEY']['VALID_SWEKEYS']) == 0) if (count($_SESSION['SWEKEY']['VALID_SWEKEYS']) == 0)
return sprintf($GLOBALS['strSwekeyNoKeyId'], $GLOBALS['cfg']['Server']['auth_swekey_config']); return sprintf($GLOBALS['strSwekeyNoKeyId'], $GLOBALS['cfg']['Server']['auth_swekey_config']);
require_once "./libraries/auth/swekey/swekey.php"; require_once "./libraries/auth/swekey/swekey.php";
Swekey_SetCheckServer($_SESSION['SWEKEY']['CONF_SERVER_CHECK']); Swekey_SetCheckServer($_SESSION['SWEKEY']['CONF_SERVER_CHECK']);
Swekey_SetRndTokenServer($_SESSION['SWEKEY']['CONF_SERVER_RNDTOKEN']); Swekey_SetRndTokenServer($_SESSION['SWEKEY']['CONF_SERVER_RNDTOKEN']);
Swekey_SetStatusServer($_SESSION['SWEKEY']['CONF_SERVER_STATUS']); Swekey_SetStatusServer($_SESSION['SWEKEY']['CONF_SERVER_STATUS']);
@@ -121,7 +124,7 @@ function Swekey_auth_error()
$caFile = __FILE__; $caFile = __FILE__;
$pos = strrpos($caFile, '/'); $pos = strrpos($caFile, '/');
if ($pos === false) if ($pos === false)
$pos = strrpos($caFile, '\\'); // windows $pos = strrpos($caFile, '\\'); // windows
$caFile = substr($caFile, 0, $pos + 1).'musbe-ca.crt'; $caFile = substr($caFile, 0, $pos + 1).'musbe-ca.crt';
// echo "\n<!-- $caFile -->\n"; // echo "\n<!-- $caFile -->\n";
// if (file_exists($caFile)) // if (file_exists($caFile))
@@ -131,10 +134,10 @@ function Swekey_auth_error()
if (file_exists($caFile)) if (file_exists($caFile))
Swekey_SetCAFile($caFile); Swekey_SetCAFile($caFile);
else if (! empty($caFile) && (substr($_SESSION['SWEKEY']['CONF_SERVER_CHECK'], 0, 8) == "https://")) else if (! empty($caFile) && (substr($_SESSION['SWEKEY']['CONF_SERVER_CHECK'], 0, 8) == "https://"))
return "Internal Error: CA File $caFile not found"; return "Internal Error: CA File $caFile not found";
$result = null; $result = null;
parse_str($_SERVER['QUERY_STRING']); parse_str($_SERVER['QUERY_STRING']);
if (isset($swekey_id)) { if (isset($swekey_id)) {
unset($_SESSION['SWEKEY']['AUTHENTICATED_SWEKEY']); unset($_SESSION['SWEKEY']['AUTHENTICATED_SWEKEY']);
if (! isset($_SESSION['SWEKEY']['RND_TOKEN'])) { if (! isset($_SESSION['SWEKEY']['RND_TOKEN'])) {
@@ -147,24 +150,24 @@ function Swekey_auth_error()
if (! $res) { if (! $res) {
$result = $GLOBALS['strSwekeyAuthFailed'] . ' (' . Swekey_GetLastError() . ')'; $result = $GLOBALS['strSwekeyAuthFailed'] . ' (' . Swekey_GetLastError() . ')';
} }
else { else {
$_SESSION['SWEKEY']['AUTHENTICATED_SWEKEY'] = $swekey_id; $_SESSION['SWEKEY']['AUTHENTICATED_SWEKEY'] = $swekey_id;
$_SESSION['SWEKEY']['FORCE_USER'] = $_SESSION['SWEKEY']['VALID_SWEKEYS'][$swekey_id]; $_SESSION['SWEKEY']['FORCE_USER'] = $_SESSION['SWEKEY']['VALID_SWEKEYS'][$swekey_id];
return null; return null;
} }
} }
else { else {
$result = $GLOBALS['strSwekeyNoKey']; $result = $GLOBALS['strSwekeyNoKey'];
if ($_SESSION['SWEKEY']['CONF_DEBUG']) if ($_SESSION['SWEKEY']['CONF_DEBUG'])
{ {
$result .= "<br>".$swekey_id; $result .= "<br>".$swekey_id;
} }
unset($_SESSION['SWEKEY']['CONF_LOADED']); // reload the conf file unset($_SESSION['SWEKEY']['CONF_LOADED']); // reload the conf file
} }
} }
} }
else else
unset($_SESSION['SWEKEY']); unset($_SESSION['SWEKEY']);
$_SESSION['SWEKEY']['RND_TOKEN'] = Swekey_GetFastRndToken(); $_SESSION['SWEKEY']['RND_TOKEN'] = Swekey_GetFastRndToken();
if (strlen($_SESSION['SWEKEY']['RND_TOKEN']) != 64) { if (strlen($_SESSION['SWEKEY']['RND_TOKEN']) != 64) {
@@ -185,14 +188,14 @@ function Swekey_auth_error()
if (url.indexOf("?") > 0) if (url.indexOf("?") > 0)
url = url.substr(0, url.indexOf("?")); url = url.substr(0, url.indexOf("?"));
Swekey_SetUnplugUrl(key, "pma_login", url + "?session_to_unset=<?php echo session_id();?>"); Swekey_SetUnplugUrl(key, "pma_login", url + "?session_to_unset=<?php echo session_id();?>");
var otp = Swekey_GetOtp(key, <?php echo '"'.$_SESSION['SWEKEY']['RND_TOKEN'].'"';?>); var otp = Swekey_GetOtp(key, <?php echo '"'.$_SESSION['SWEKEY']['RND_TOKEN'].'"';?>);
window.location.search="?swekey_id=" + key + "&swekey_otp=" + otp; window.location.search="?swekey_id=" + key + "&swekey_otp=" + otp;
} }
</script> </script>
<?php <?php
return $GLOBALS['strSwekeyAuthenticating']; return $GLOBALS['strSwekeyAuthenticating'];
} }
return $result; return $result;
} }
@@ -211,7 +214,7 @@ function Swekey_login($input_name, $input_go)
if (isset($_SESSION['SWEKEY']) && $_SESSION['SWEKEY']['ENABLED']) { if (isset($_SESSION['SWEKEY']) && $_SESSION['SWEKEY']['ENABLED']) {
echo '<script type="text/javascript">'; echo '<script type="text/javascript">';
if (empty($_SESSION['SWEKEY']['FORCE_USER'])) if (empty($_SESSION['SWEKEY']['FORCE_USER']))
echo 'var user = null;'; echo 'var user = null;';
else else
echo 'var user = "'.$_SESSION['SWEKEY']['FORCE_USER'].'";'; echo 'var user = "'.$_SESSION['SWEKEY']['FORCE_USER'].'";';
@@ -221,7 +224,7 @@ function Swekey_login($input_name, $input_go)
{ {
window.open("http://phpmyadmin.net/auth_key"); window.open("http://phpmyadmin.net/auth_key");
} }
var input_username = document.getElementById("<?php echo $input_name; ?>"); var input_username = document.getElementById("<?php echo $input_name; ?>");
var input_go = document.getElementById("<?php echo $input_go; ?>"); var input_go = document.getElementById("<?php echo $input_go; ?>");
var swekey_status = document.createElement('img'); var swekey_status = document.createElement('img');
@@ -240,7 +243,7 @@ function Swekey_login($input_name, $input_go)
input_username.value = user; input_username.value = user;
} }
input_username.readOnly = true; input_username.readOnly = true;
if (input_username.nextSibling == null) if (input_username.nextSibling == null)
input_username.parentNode.appendChild(swekey_status); input_username.parentNode.appendChild(swekey_status);
else else
@@ -267,5 +270,5 @@ if (isset($_GET['swekey_reset']))
{ {
unset($_SESSION['SWEKEY']); unset($_SESSION['SWEKEY']);
} }
?> ?>

View File

@@ -1,16 +1,17 @@
<?php <?php
/** /**
* Library that provides common functions that are used to help integrating Swekey Authentication in a PHP web site * Library that provides common functions that are used to help integrating Swekey Authentication in a PHP web site
* Version 1.0 * Version 1.0
* *
* History: * History:
* 1.2 Use curl (widely installed) to query the server * 1.2 Use curl (widely installed) to query the server
* Fixed a possible tempfile race attack * Fixed a possible tempfile race attack
* Random token cache can now be disabled * Random token cache can now be disabled
* 1.1 Added Swekey_HttpGet function that support faulty servers * 1.1 Added Swekey_HttpGet function that support faulty servers
* Support for custom servers * Support for custom servers
* 1.0 First release * 1.0 First release
* *
* @package Swekey
*/ */
@@ -24,11 +25,11 @@ define ("SWEKEY_ERR_INVALID_OTP",911); // The otp was not correct
/** /**
* Those errors are considered as an attack and your site will be blacklisted during one minute * Those errors are considered as an attack and your site will be blacklisted during one minute
* if you receive one of those errors * if you receive one of those errors
*/ */
define ("SWEKEY_ERR_BADLY_ENCODED_REQUEST",920); define ("SWEKEY_ERR_BADLY_ENCODED_REQUEST",920);
define ("SWEKEY_ERR_INVALID_RND_TOKEN",921); define ("SWEKEY_ERR_INVALID_RND_TOKEN",921);
define ("SWEKEY_ERR_DEV_NOT_FOUND",922); define ("SWEKEY_ERR_DEV_NOT_FOUND",922);
/** /**
* Default values for configuration. * Default values for configuration.
@@ -40,7 +41,7 @@ define ('SWEKEY_DEFAULT_STATUS_SERVER', 'https://auth-status.musbe.net');
/** /**
* The last error of an operation is alway put in this global var * The last error of an operation is alway put in this global var
*/ */
global $gSwekeyLastError; global $gSwekeyLastError;
$gSwekeyLastError = 0; $gSwekeyLastError = 0;
@@ -72,13 +73,13 @@ if (! isset($gSwekeyTokenCacheEnabled))
/** /**
* Change the address of the Check server. * Change the address of the Check server.
* If $server is empty the default value 'http://auth-check.musbe.net' will be used * If $server is empty the default value 'http://auth-check.musbe.net' will be used
* *
* @param server The protocol and hostname to use * @param server The protocol and hostname to use
* @access public * @access public
*/ */
function Swekey_SetCheckServer($server) function Swekey_SetCheckServer($server)
{ {
global $gSwekeyCheckServer; global $gSwekeyCheckServer;
if (empty($server)) if (empty($server))
$gSwekeyCheckServer = SWEKEY_DEFAULT_CHECK_SERVER; $gSwekeyCheckServer = SWEKEY_DEFAULT_CHECK_SERVER;
@@ -88,13 +89,13 @@ function Swekey_SetCheckServer($server)
/** /**
* Change the address of the Random Token Generator server. * Change the address of the Random Token Generator server.
* If $server is empty the default value 'http://auth-rnd-gen.musbe.net' will be used * If $server is empty the default value 'http://auth-rnd-gen.musbe.net' will be used
* *
* @param server The protocol and hostname to use * @param server The protocol and hostname to use
* @access public * @access public
*/ */
function Swekey_SetRndTokenServer($server) function Swekey_SetRndTokenServer($server)
{ {
global $gSwekeyRndTokenServer; global $gSwekeyRndTokenServer;
if (empty($server)) if (empty($server))
$gSwekeyRndTokenServer = SWEKEY_DEFAULT_RND_SERVER; $gSwekeyRndTokenServer = SWEKEY_DEFAULT_RND_SERVER;
@@ -104,13 +105,13 @@ function Swekey_SetRndTokenServer($server)
/** /**
* Change the address of the Satus server. * Change the address of the Satus server.
* If $server is empty the default value 'http://auth-status.musbe.net' will be used * If $server is empty the default value 'http://auth-status.musbe.net' will be used
* *
* @param server The protocol and hostname to use * @param server The protocol and hostname to use
* @access public * @access public
*/ */
function Swekey_SetStatusServer($server) function Swekey_SetStatusServer($server)
{ {
global $gSwekeyStatusServer; global $gSwekeyStatusServer;
if (empty($server)) if (empty($server))
$gSwekeyStatusServer = SWEKEY_DEFAULT_STATUS_SERVER; $gSwekeyStatusServer = SWEKEY_DEFAULT_STATUS_SERVER;
@@ -125,21 +126,21 @@ function Swekey_SetStatusServer($server)
* @access public * @access public
*/ */
function Swekey_SetCAFile($cafile) function Swekey_SetCAFile($cafile)
{ {
global $gSwekeyCA; global $gSwekeyCA;
$gSwekeyCA = $cafile; $gSwekeyCA = $cafile;
} }
/** /**
* Enable or disable the random token caching * Enable or disable the random token caching
* Because everybody has full access to the cache file, it can be a DOS vulnerability * Because everybody has full access to the cache file, it can be a DOS vulnerability
* So disable it if you are running in a non secure enviromnement * So disable it if you are running in a non secure enviromnement
* *
* @param $enable * @param $enable
* @access public * @access public
*/ */
function Swekey_EnableTokenCache($enable) function Swekey_EnableTokenCache($enable)
{ {
global $gSwekeyTokenCacheEnabled; global $gSwekeyTokenCacheEnabled;
$gSwekeyTokenCacheEnabled = ! empty($enable); $gSwekeyTokenCacheEnabled = ! empty($enable);
} }
@@ -147,31 +148,31 @@ function Swekey_EnableTokenCache($enable)
/** /**
* Return the last error. * Return the last error.
* *
* @return The Last Error * @return The Last Error
* @access public * @access public
*/ */
function Swekey_GetLastError() function Swekey_GetLastError()
{ {
global $gSwekeyLastError; global $gSwekeyLastError;
return $gSwekeyLastError; return $gSwekeyLastError;
} }
/** /**
* Return the last result. * Return the last result.
* *
* @return The Last Error * @return The Last Error
* @access public * @access public
*/ */
function Swekey_GetLastResult() function Swekey_GetLastResult()
{ {
global $gSwekeyLastResult; global $gSwekeyLastResult;
return $gSwekeyLastResult; return $gSwekeyLastResult;
} }
/** /**
* Send a synchronous request to the server. * Send a synchronous request to the server.
* This function manages timeout then will not block if one of the server is down * This function manages timeout then will not block if one of the server is down
* *
* @param url The url to get * @param url The url to get
* @param response_code The response code * @param response_code The response code
@@ -179,12 +180,12 @@ function Swekey_GetLastResult()
* @access private * @access private
*/ */
function Swekey_HttpGet($url, &$response_code) function Swekey_HttpGet($url, &$response_code)
{ {
global $gSwekeyLastError; global $gSwekeyLastError;
$gSwekeyLastError = 0; $gSwekeyLastError = 0;
global $gSwekeyLastResult; global $gSwekeyLastResult;
$gSwekeyLastResult = "<not set>"; $gSwekeyLastResult = "<not set>";
// use curl if available // use curl if available
if (function_exists('curl_init')) if (function_exists('curl_init'))
{ {
@@ -205,7 +206,7 @@ function Swekey_HttpGet($url, &$response_code)
else else
error_log("SWEKEY_ERROR:Could not find CA file $gSwekeyCA getting $url"); error_log("SWEKEY_ERROR:Could not find CA file $gSwekeyCA getting $url");
} }
curl_setopt($sess, CURLOPT_SSL_VERIFYHOST, '2'); curl_setopt($sess, CURLOPT_SSL_VERIFYHOST, '2');
curl_setopt($sess, CURLOPT_SSL_VERIFYPEER, '2'); curl_setopt($sess, CURLOPT_SSL_VERIFYPEER, '2');
curl_setopt($sess, CURLOPT_CONNECTTIMEOUT, '20'); curl_setopt($sess, CURLOPT_CONNECTTIMEOUT, '20');
@@ -215,12 +216,12 @@ function Swekey_HttpGet($url, &$response_code)
{ {
curl_setopt($sess, CURLOPT_CONNECTTIMEOUT, '3'); curl_setopt($sess, CURLOPT_CONNECTTIMEOUT, '3');
curl_setopt($sess, CURLOPT_TIMEOUT, '5'); curl_setopt($sess, CURLOPT_TIMEOUT, '5');
} }
curl_setopt($sess, CURLOPT_RETURNTRANSFER, '1'); curl_setopt($sess, CURLOPT_RETURNTRANSFER, '1');
$res=curl_exec($sess); $res=curl_exec($sess);
$response_code = curl_getinfo($sess, CURLINFO_HTTP_CODE); $response_code = curl_getinfo($sess, CURLINFO_HTTP_CODE);
$curlerr = curl_error($sess); $curlerr = curl_error($sess);
curl_close($sess); curl_close($sess);
if ($response_code == 200) if ($response_code == 200)
@@ -229,7 +230,7 @@ function Swekey_HttpGet($url, &$response_code)
return $res; return $res;
} }
if (! empty($response_code)) if (! empty($response_code))
{ {
$gSwekeyLastError = $response_code; $gSwekeyLastError = $response_code;
error_log("SWEKEY_ERROR:Error $gSwekeyLastError ($curlerr) getting $url"); error_log("SWEKEY_ERROR:Error $gSwekeyLastError ($curlerr) getting $url");
@@ -237,41 +238,41 @@ function Swekey_HttpGet($url, &$response_code)
} }
$response_code = 408; // Request Timeout $response_code = 408; // Request Timeout
$gSwekeyLastError = $response_code; $gSwekeyLastError = $response_code;
error_log("SWEKEY_ERROR:Error $curlerr getting $url"); error_log("SWEKEY_ERROR:Error $curlerr getting $url");
return ""; return "";
} }
// use pecl_http if available // use pecl_http if available
if (class_exists('HttpRequest')) if (class_exists('HttpRequest'))
{ {
// retry if one of the server is down // retry if one of the server is down
for ($num=1; $num <= 3; $num++ ) for ($num=1; $num <= 3; $num++ )
{ {
$r = new HttpRequest($url); $r = new HttpRequest($url);
$options = array('timeout' => '3'); $options = array('timeout' => '3');
if (substr($url,0, 6) == "https:") if (substr($url,0, 6) == "https:")
{ {
$sslOptions = array(); $sslOptions = array();
$sslOptions['verifypeer'] = true; $sslOptions['verifypeer'] = true;
$sslOptions['verifyhost'] = true; $sslOptions['verifyhost'] = true;
$capath = __FILE__; $capath = __FILE__;
$name = strrchr($capath, '/'); $name = strrchr($capath, '/');
if (empty($name)) // windows if (empty($name)) // windows
$name = strrchr($capath, '\\'); $name = strrchr($capath, '\\');
$capath = substr($capath, 0, strlen($capath) - strlen($name) + 1).'musbe-ca.crt'; $capath = substr($capath, 0, strlen($capath) - strlen($name) + 1).'musbe-ca.crt';
if (! empty($gSwekeyCA)) if (! empty($gSwekeyCA))
$sslOptions['cainfo'] = $gSwekeyCA; $sslOptions['cainfo'] = $gSwekeyCA;
$options['ssl'] = $sslOptions; $options['ssl'] = $sslOptions;
} }
$r->setOptions($options); $r->setOptions($options);
// try // try
{ {
$reply = $r->send(); $reply = $r->send();
$res = $reply->getBody(); $res = $reply->getBody();
@@ -287,19 +288,19 @@ function Swekey_HttpGet($url, &$response_code)
$gSwekeyLastResult = $res; $gSwekeyLastResult = $res;
return $res; return $res;
} }
// catch (HttpException $e) // catch (HttpException $e)
// { // {
// error_log("SWEKEY_WARNING:HttpException ".$e." getting ".$url); // error_log("SWEKEY_WARNING:HttpException ".$e." getting ".$url);
// } // }
} }
$response_code = 408; // Request Timeout $response_code = 408; // Request Timeout
$gSwekeyLastError = $response_code; $gSwekeyLastError = $response_code;
error_log("SWEKEY_ERROR:Error ".$gSwekeyLastError." getting ".$url); error_log("SWEKEY_ERROR:Error ".$gSwekeyLastError." getting ".$url);
return ""; return "";
} }
global $http_response_header; global $http_response_header;
$res = @file_get_contents($url); $res = @file_get_contents($url);
$response_code = substr($http_response_header[0], 9, 3); //HTTP/1.0 $response_code = substr($http_response_header[0], 9, 3); //HTTP/1.0
@@ -308,15 +309,15 @@ function Swekey_HttpGet($url, &$response_code)
$gSwekeyLastResult = $res; $gSwekeyLastResult = $res;
return $res; return $res;
} }
$gSwekeyLastError = $response_code; $gSwekeyLastError = $response_code;
error_log("SWEKEY_ERROR:Error ".$response_code." getting ".$url); error_log("SWEKEY_ERROR:Error ".$response_code." getting ".$url);
return ""; return "";
} }
/** /**
* Get a Random Token from a Token Server * Get a Random Token from a Token Server
* The RT is a 64 vhars hexadecimal value * The RT is a 64 vhars hexadecimal value
* You should better use Swekey_GetFastRndToken() for performance * You should better use Swekey_GetFastRndToken() for performance
* @access public * @access public
*/ */
@@ -324,26 +325,26 @@ function Swekey_GetRndToken()
{ {
global $gSwekeyRndTokenServer; global $gSwekeyRndTokenServer;
return Swekey_HttpGet($gSwekeyRndTokenServer.'/FULL-RND-TOKEN', $response_code); return Swekey_HttpGet($gSwekeyRndTokenServer.'/FULL-RND-TOKEN', $response_code);
} }
/** /**
* Get a Half Random Token from a Token Server * Get a Half Random Token from a Token Server
* The RT is a 64 vhars hexadecimal value * The RT is a 64 vhars hexadecimal value
* Use this value if you want to make your own Swekey_GetFastRndToken() * Use this value if you want to make your own Swekey_GetFastRndToken()
* @access public * @access public
*/ */
function Swekey_GetHalfRndToken() function Swekey_GetHalfRndToken()
{ {
global $gSwekeyRndTokenServer; global $gSwekeyRndTokenServer;
return Swekey_HttpGet($gSwekeyRndTokenServer.'/HALF-RND-TOKEN', $response_code); return Swekey_HttpGet($gSwekeyRndTokenServer.'/HALF-RND-TOKEN', $response_code);
} }
/** /**
* Get a Half Random Token * Get a Half Random Token
* The RT is a 64 vhars hexadecimal value * The RT is a 64 vhars hexadecimal value
* This function get a new random token and reuse it. * This function get a new random token and reuse it.
* Token are refetched from the server only once every 30 seconds. * Token are refetched from the server only once every 30 seconds.
* You should always use this function to get half random token. * You should always use this function to get half random token.
* @access public * @access public
*/ */
function Swekey_GetFastHalfRndToken() function Swekey_GetFastHalfRndToken()
@@ -357,7 +358,7 @@ function Swekey_GetFastHalfRndToken()
if (isset($_SESSION['rnd-token-date'])) if (isset($_SESSION['rnd-token-date']))
if (time() - $_SESSION['rnd-token-date'] < 30) if (time() - $_SESSION['rnd-token-date'] < 30)
$res = $_SESSION['rnd-token']; $res = $_SESSION['rnd-token'];
// If not we try to get it from a temp file (PHP >= 5.2.1 only) // If not we try to get it from a temp file (PHP >= 5.2.1 only)
if (strlen($res) != 32 && $gSwekeyTokenCacheEnabled) if (strlen($res) != 32 && $gSwekeyTokenCacheEnabled)
{ {
@@ -369,7 +370,7 @@ function Swekey_GetFastHalfRndToken()
if ($modif != false) if ($modif != false)
if (time() - $modif < 30) if (time() - $modif < 30)
{ {
$res = @file_get_contents($cachefile); $res = @file_get_contents($cachefile);
if (strlen($res) != 32) if (strlen($res) != 32)
$res = ""; $res = "";
else else
@@ -378,9 +379,9 @@ function Swekey_GetFastHalfRndToken()
$_SESSION['rnd-token-date'] = $modif; $_SESSION['rnd-token-date'] = $modif;
} }
} }
} }
} }
// If we don't have a valid RT here we have to get it from the server // If we don't have a valid RT here we have to get it from the server
if (strlen($res) != 32) if (strlen($res) != 32)
{ {
@@ -394,29 +395,29 @@ function Swekey_GetFastHalfRndToken()
$file = fopen($cachefile , "x"); $file = fopen($cachefile , "x");
if ($file != FALSE) if ($file != FALSE)
{ {
@fwrite($file, $res); @fwrite($file, $res);
@fclose($file); @fclose($file);
} }
} }
} }
return $res."00000000000000000000000000000000"; return $res."00000000000000000000000000000000";
} }
/** /**
* Get a Random Token * Get a Random Token
* The RT is a 64 vhars hexadecimal value * The RT is a 64 vhars hexadecimal value
* This function generates a unique random token for each call but call the * This function generates a unique random token for each call but call the
* server only once every 30 seconds. * server only once every 30 seconds.
* You should always use this function to get random token. * You should always use this function to get random token.
* @access public * @access public
*/ */
function Swekey_GetFastRndToken() function Swekey_GetFastRndToken()
{ {
$res = Swekey_GetFastHalfRndToken(); $res = Swekey_GetFastHalfRndToken();
if (strlen($res) == 64) if (strlen($res) == 64)
return substr($res, 0, 32).strtoupper(md5("Musbe Authentication Key" + mt_rand() + date(DATE_ATOM))); return substr($res, 0, 32).strtoupper(md5("Musbe Authentication Key" + mt_rand() + date(DATE_ATOM)));
return ""; return "";
} }
@@ -435,11 +436,11 @@ function Swekey_CheckOtp($id, $rt, $otp)
global $gSwekeyCheckServer; global $gSwekeyCheckServer;
$res = Swekey_HttpGet($gSwekeyCheckServer.'/CHECK-OTP/'.$id.'/'.$rt.'/'.$otp, $response_code); $res = Swekey_HttpGet($gSwekeyCheckServer.'/CHECK-OTP/'.$id.'/'.$rt.'/'.$otp, $response_code);
return $response_code == 200 && $res == "OK"; return $response_code == 200 && $res == "OK";
} }
/** /**
* Values that are associated with a key. * Values that are associated with a key.
* The following values can be returned by the Swekey_GetStatus() function * The following values can be returned by the Swekey_GetStatus() function
*/ */
define ("SWEKEY_STATUS_OK",0); define ("SWEKEY_STATUS_OK",0);
define ("SWEKEY_STATUS_NOT_FOUND",1); // The key does not exist in the db define ("SWEKEY_STATUS_NOT_FOUND",1); // The key does not exist in the db
@@ -452,7 +453,7 @@ define ("SWEKEY_STATUS_UNKOWN",201); // We could not connect to the authentica
/** /**
* Values that are associated with a key. * Values that are associated with a key.
* The Javascript Api can also return the following values * The Javascript Api can also return the following values
*/ */
define ("SWEKEY_STATUS_REPLACED",100); // This key has been replaced by a backup key define ("SWEKEY_STATUS_REPLACED",100); // This key has been replaced by a backup key
define ("SWEKEY_STATUS_BACKUP_KEY",101); // This key is a backup key that is not activated yet define ("SWEKEY_STATUS_BACKUP_KEY",101); // This key is a backup key that is not activated yet
@@ -460,7 +461,7 @@ define ("SWEKEY_STATUS_NOTPLUGGED",200); // This key is not plugged in the compu
/** /**
* Return the text corresponding to the integer status of a key * Return the text corresponding to the integer status of a key
* *
* @param status The status * @param status The status
* @return The text corresponding to the status * @return The text corresponding to the status
@@ -483,10 +484,10 @@ function Swekey_GetStatusStr($status)
case SWEKEY_STATUS_UNKOWN : return 'Unknow Status, could not connect to the authentication server'; case SWEKEY_STATUS_UNKOWN : return 'Unknow Status, could not connect to the authentication server';
} }
return 'unknown status '.$status; return 'unknown status '.$status;
} }
/** /**
* If your web site requires a key to login you should check that the key * If your web site requires a key to login you should check that the key
* is still valid (has not been lost or stolen) before requiring it. * is still valid (has not been lost or stolen) before requiring it.
* A key can be authenticated only if its status is SWEKEY_STATUS_OK * A key can be authenticated only if its status is SWEKEY_STATUS_OK
* @param id The id of the swekey * @param id The id of the swekey
@@ -499,8 +500,8 @@ function Swekey_GetStatus($id)
$res = Swekey_HttpGet($gSwekeyStatusServer.'/GET-STATUS/'.$id, $response_code); $res = Swekey_HttpGet($gSwekeyStatusServer.'/GET-STATUS/'.$id, $response_code);
if ($response_code == 200) if ($response_code == 200)
return intval($res); return intval($res);
return SWEKEY_STATUS_UNKOWN; return SWEKEY_STATUS_UNKOWN;
} }
?> ?>

View File

@@ -3,6 +3,7 @@
/** /**
* Set of functions used to build NHibernate dumps of tables * Set of functions used to build NHibernate dumps of tables
* *
* @package phpMyAdmin-Export-Codegen
* @version $Id$ * @version $Id$
*/ */
if (! defined('PHPMYADMIN')) { if (! defined('PHPMYADMIN')) {
@@ -269,7 +270,7 @@ class TableProperty
} }
return implode("\n", $lines); return implode("\n", $lines);
} }
function handleNHibernateXMLBody($db, $table, $crlf) function handleNHibernateXMLBody($db, $table, $crlf)
{ {
$lines=array(); $lines=array();
@@ -295,7 +296,7 @@ class TableProperty
$lines[]="</hibernate-mapping>"; $lines[]="</hibernate-mapping>";
return implode("\n", $lines); return implode("\n", $lines);
} }
function cgGetOption($optionName) function cgGetOption($optionName)
{ {
global $what; global $what;

View File

@@ -1,6 +1,7 @@
<?php <?php
/* vim: set expandtab sw=4 ts=4 sts=4: */ /* vim: set expandtab sw=4 ts=4 sts=4: */
/** /**
* @package phpMyAdmin-Export-CSV
* @version $Id$ * @version $Id$
*/ */
if (! defined('PHPMYADMIN')) { if (! defined('PHPMYADMIN')) {

View File

@@ -3,6 +3,7 @@
/** /**
* Set of functions used to build CSV dumps of tables * Set of functions used to build CSV dumps of tables
* *
* @package phpMyAdmin-Export-CSV
* @version $Id$ * @version $Id$
*/ */
if (! defined('PHPMYADMIN')) { if (! defined('PHPMYADMIN')) {

View File

@@ -3,6 +3,7 @@
/** /**
* Set of functions used to build CSV dumps of tables * Set of functions used to build CSV dumps of tables
* *
* @package phpMyAdmin-Export-HTMLExcel
* @version $Id$ * @version $Id$
*/ */
if (! defined('PHPMYADMIN')) { if (! defined('PHPMYADMIN')) {

View File

@@ -3,6 +3,7 @@
/** /**
* Set of functions used to build CSV dumps of tables * Set of functions used to build CSV dumps of tables
* *
* @package phpMyAdmin-Export-HTMLWord
* @version $Id$ * @version $Id$
*/ */
if (! defined('PHPMYADMIN')) { if (! defined('PHPMYADMIN')) {

View File

@@ -3,6 +3,7 @@
/** /**
* Set of functions used to build dumps of tables * Set of functions used to build dumps of tables
* *
* @package phpMyAdmin-Export-Latex
* @version $Id$ * @version $Id$
*/ */
if (! defined('PHPMYADMIN')) { if (! defined('PHPMYADMIN')) {

View File

@@ -1,8 +1,9 @@
<?php <?php
/* vim: set expandtab sw=4 ts=4 sts=4: */ /* vim: set expandtab sw=4 ts=4 sts=4: */
/** /**
* Set of functions used to build CSV dumps of tables * Set of functions used to build OpenDocument Spreadsheet dumps of tables
* *
* @package phpMyAdmin-Export-ODS
* @version $Id$ * @version $Id$
*/ */
if (! defined('PHPMYADMIN')) { if (! defined('PHPMYADMIN')) {

View File

@@ -1,8 +1,9 @@
<?php <?php
/* vim: set expandtab sw=4 ts=4 sts=4: */ /* vim: set expandtab sw=4 ts=4 sts=4: */
/** /**
* Set of functions used to build CSV dumps of tables * Set of functions used to build OpenDocument Text dumps of tables
* *
* @package phpMyAdmin-Export-ODT
* @version $Id$ * @version $Id$
*/ */
if (! defined('PHPMYADMIN')) { if (! defined('PHPMYADMIN')) {

View File

@@ -3,6 +3,7 @@
/** /**
* Produce a PDF report (export) from a query * Produce a PDF report (export) from a query
* *
* @package phpMyAdmin-Export-PDF
* @version $Id$ * @version $Id$
*/ */
if (! defined('PHPMYADMIN')) { if (! defined('PHPMYADMIN')) {
@@ -292,7 +293,7 @@ class PMA_PDF extends TCPDF
} }
} }
// loop through the data; any column whose contents // loop through the data; any column whose contents
// is greater than the column size is resized // is greater than the column size is resized
/** /**
* @todo force here a LIMIT to avoid reading all rows * @todo force here a LIMIT to avoid reading all rows

View File

@@ -3,6 +3,7 @@
/** /**
* Set of functions used to build SQL dumps of tables * Set of functions used to build SQL dumps of tables
* *
* @package phpMyAdmin-Export-SQL
* @version $Id$ * @version $Id$
*/ */
if (! defined('PHPMYADMIN')) { if (! defined('PHPMYADMIN')) {
@@ -244,13 +245,13 @@ function PMA_exportHeader()
// so that a utility like the mysql client can interpret // so that a utility like the mysql client can interpret
// the file correctly // the file correctly
if (isset($GLOBALS['charset_of_file']) && isset($mysql_charset_map[$GLOBALS['charset_of_file']])) { if (isset($GLOBALS['charset_of_file']) && isset($mysql_charset_map[$GLOBALS['charset_of_file']])) {
// $cfg['AllowAnywhereRecoding'] was true so we got a charset from // $cfg['AllowAnywhereRecoding'] was true so we got a charset from
// the export dialog // the export dialog
$set_names = $mysql_charset_map[$GLOBALS['charset_of_file']]; $set_names = $mysql_charset_map[$GLOBALS['charset_of_file']];
} else { } else {
// by default we use the connection charset // by default we use the connection charset
$set_names = $mysql_charset_map[$GLOBALS['charset']]; $set_names = $mysql_charset_map[$GLOBALS['charset']];
} }
$head .= $crlf $head .= $crlf
. '/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;' . $crlf . '/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;' . $crlf
. '/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;' . $crlf . '/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;' . $crlf
@@ -350,7 +351,7 @@ function PMA_exportDBFooter($db)
} }
if ($procedure_names) { if ($procedure_names) {
$text .= $text .=
PMA_exportComment() PMA_exportComment()
. PMA_exportComment($GLOBALS['strProcedures']) . PMA_exportComment($GLOBALS['strProcedures'])
. PMA_exportComment(); . PMA_exportComment();
@@ -358,13 +359,13 @@ function PMA_exportDBFooter($db)
foreach($procedure_names as $procedure_name) { foreach($procedure_names as $procedure_name) {
if (! empty($GLOBALS['sql_drop_table'])) { if (! empty($GLOBALS['sql_drop_table'])) {
$text .= 'DROP PROCEDURE IF EXISTS ' . PMA_backquote($procedure_name) . $delimiter . $crlf; $text .= 'DROP PROCEDURE IF EXISTS ' . PMA_backquote($procedure_name) . $delimiter . $crlf;
} }
$text .= PMA_DBI_get_definition($db, 'PROCEDURE', $procedure_name) . $delimiter . $crlf . $crlf; $text .= PMA_DBI_get_definition($db, 'PROCEDURE', $procedure_name) . $delimiter . $crlf . $crlf;
} }
} }
if ($function_names) { if ($function_names) {
$text .= $text .=
PMA_exportComment() PMA_exportComment()
. PMA_exportComment($GLOBALS['strFunctions']) . PMA_exportComment($GLOBALS['strFunctions'])
. PMA_exportComment(); . PMA_exportComment();
@@ -372,13 +373,13 @@ function PMA_exportDBFooter($db)
foreach($function_names as $function_name) { foreach($function_names as $function_name) {
if (! empty($GLOBALS['sql_drop_table'])) { if (! empty($GLOBALS['sql_drop_table'])) {
$text .= 'DROP FUNCTION IF EXISTS ' . PMA_backquote($function_name) . $delimiter . $crlf; $text .= 'DROP FUNCTION IF EXISTS ' . PMA_backquote($function_name) . $delimiter . $crlf;
} }
$text .= PMA_DBI_get_definition($db, 'FUNCTION', $function_name) . $delimiter . $crlf . $crlf; $text .= PMA_DBI_get_definition($db, 'FUNCTION', $function_name) . $delimiter . $crlf . $crlf;
} }
} }
if ($event_names) { if ($event_names) {
$text .= $text .=
PMA_exportComment() PMA_exportComment()
. PMA_exportComment($GLOBALS['strEvents']) . PMA_exportComment($GLOBALS['strEvents'])
. PMA_exportComment(); . PMA_exportComment();
@@ -386,7 +387,7 @@ function PMA_exportDBFooter($db)
foreach($event_names as $event_name) { foreach($event_names as $event_name) {
if (! empty($GLOBALS['sql_drop_table'])) { if (! empty($GLOBALS['sql_drop_table'])) {
$text .= 'DROP EVENT ' . PMA_backquote($event_name) . $delimiter . $crlf; $text .= 'DROP EVENT ' . PMA_backquote($event_name) . $delimiter . $crlf;
} }
$text .= PMA_DBI_get_definition($db, 'EVENT', $event_name) . $delimiter . $crlf . $crlf; $text .= PMA_DBI_get_definition($db, 'EVENT', $event_name) . $delimiter . $crlf . $crlf;
} }
} }
@@ -442,7 +443,7 @@ function PMA_getTableDefStandIn($db, $view, $crlf) {
* @param string the end of line sequence * @param string the end of line sequence
* @param string the url to go back in case of error * @param string the url to go back in case of error
* @param boolean whether to include creation/update/check dates * @param boolean whether to include creation/update/check dates
* @param boolean whether to add semicolon and end-of-line at the end * @param boolean whether to add semicolon and end-of-line at the end
* *
* @return string resulting schema * @return string resulting schema
* *
@@ -844,7 +845,7 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
// a possible error: the table has crashed // a possible error: the table has crashed
$tmp_error = PMA_DBI_getError(); $tmp_error = PMA_DBI_getError();
if ($tmp_error) { if ($tmp_error) {
return PMA_exportOutputHandler(PMA_exportComment($GLOBALS['strInUse'] . ' (' . $tmp_error . ')')); return PMA_exportOutputHandler(PMA_exportComment($GLOBALS['strInUse'] . ' (' . $tmp_error . ')'));
} }
if ($result != FALSE) { if ($result != FALSE) {

View File

@@ -1,7 +1,9 @@
<?php <?php
/* vim: set expandtab sw=4 ts=4 sts=4: */ /* vim: set expandtab sw=4 ts=4 sts=4: */
/** /**
* Sample export to Texy! text. * Export to Texy! text.
*
* @package phpMyAdmin-Export-Texy
*/ */
if (! defined('PHPMYADMIN')) { if (! defined('PHPMYADMIN')) {
exit; exit;

View File

@@ -4,6 +4,7 @@
* Set of functions used to build XLS dumps of tables * Set of functions used to build XLS dumps of tables
* *
* @version $Id$ * @version $Id$
* @package phpMyAdmin-Export-XLS
*/ */
if (! defined('PHPMYADMIN')) { if (! defined('PHPMYADMIN')) {
exit; exit;

View File

@@ -4,6 +4,7 @@
* Set of functions used to build YAML dumps of tables * Set of functions used to build YAML dumps of tables
* *
* @version $Id$ * @version $Id$
* @package phpMyAdmin-Export-YAML
*/ */
if (! defined('PHPMYADMIN')) { if (! defined('PHPMYADMIN')) {
exit; exit;