1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438
|
<?php
/**
* Various checks and message functions used on index page.
*
* Security checks are the idea of Aung Khant <aungkhant[at]yehg.net>, http://yehg.net/lab
* Version check taken from the old setup script by Michal Čihař <michal@cihar.com>
*
* @package phpMyAdmin-setup
* @author Piotr Przybylski <piotrprz@gmail.com>
* @license http://www.gnu.org/licenses/gpl.html GNU GPL 2.0
* @version $Id$
*/
if (!defined('PHPMYADMIN')) {
exit;
}
/**
* Load vendor config.
*/
require_once('./libraries/vendor_config.php');
/**
* Initializes message list
*/
function messages_begin()
{
if (!isset($_SESSION['messages']) || !is_array($_SESSION['messages'])) {
$_SESSION['messages'] = array('error' => array(), 'warning' => array(), 'notice' => array());
} else {
// reset message states
foreach ($_SESSION['messages'] as &$messages) {
foreach ($messages as &$msg) {
$msg['fresh'] = false;
$msg['active'] = false;
}
}
}
}
/**
* Adds a new message to message list
*
* @param string $id unique message identifier
* @param string $type one of: notice, warning, error
* @param string $title language string id (in $str array)
* @param string $message message text
*/
function messages_set($type, $id, $title, $message)
{
$fresh = !isset($_SESSION['messages'][$type][$id]);
$title = PMA_lang($title);
$_SESSION['messages'][$type][$id] = array(
'fresh' => $fresh,
'active' => true,
'title' => $title,
'message' => $message);
}
/**
* Cleans up message list
*/
function messages_end()
{
foreach ($_SESSION['messages'] as &$messages) {
$remove_ids = array();
foreach ($messages as $id => &$msg) {
if ($msg['active'] == false) {
$remove_ids[] = $id;
}
}
foreach ($remove_ids as $id) {
unset($messages[$id]);
}
}
}
/**
* Prints message list, must be called after messages_end()
*/
function messages_show_html()
{
$old_ids = array();
foreach ($_SESSION['messages'] as $type => $messages) {
foreach ($messages as $id => $msg) {
echo '<div class="' . $type . '" id="' . $id . '">' . '<h4>' . $msg['title'] . '</h4>' . $msg['message'] . '</div>';
if (!$msg['fresh'] && $type != 'error') {
$old_ids[] = $id;
}
}
}
echo "\n" . '<script type="text/javascript">';
foreach ($old_ids as $id) {
echo "\nhiddenMessages.push('$id');";
}
echo "\n</script>\n";
}
/**
* Checks for newest phpMyAdmin version and sets result as a new notice
*/
function PMA_version_check()
{
// version check messages should always be visible so let's make
// a unique message id each time we run it
$message_id = uniqid('version_check');
// wait 3s at most for server response, it's enough to get information
// from a working server
$connection_timeout = 3;
$url = 'http://phpmyadmin.net/home_page/version.php';
$context = stream_context_create(array(
'http' => array(
'timeout' => $connection_timeout)));
$data = @file_get_contents($url, null, $context);
if ($data === false) {
if (function_exists('curl_init')) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, $connection_timeout);
$data = curl_exec($ch);
curl_close($ch);
} else {
messages_set('error', $message_id, 'VersionCheck',
PMA_lang('VersionCheckWrapperError'));
return;
}
}
if (empty($data)) {
messages_set('error', $message_id, 'VersionCheck',
PMA_lang('VersionCheckDataError'));
return;
}
/* Format: version\ndate\n(download\n)* */
$data_list = explode("\n", $data);
if (count($data_list) > 1) {
$version = $data_list[0];
$date = $data_list[1];
} else {
$version = $date = '';
}
$version_upstream = version_to_int($version);
if ($version_upstream === false) {
messages_set('error', $message_id, 'VersionCheck',
PMA_lang('VersionCheckInvalid'));
return;
}
$version_local = version_to_int($_SESSION['PMA_Config']->get('PMA_VERSION'));
if ($version_local === false) {
messages_set('error', $message_id, 'VersionCheck',
PMA_lang('VersionCheckUnparsable'));
return;
}
if ($version_upstream > $version_local) {
$version = htmlspecialchars($version);
$date = htmlspecialchars($date);
messages_set('notice', $message_id, 'VersionCheck',
PMA_lang('VersionCheckNewAvailable', $version, $date));
} else {
if ($version_local % 100 == 0) {
messages_set('notice', $message_id, 'VersionCheck',
PMA_lang('VersionCheckNewAvailableSvn', $version, $date));
} else {
messages_set('notice', $message_id, 'VersionCheck',
PMA_lang('VersionCheckNone'));
}
}
}
/**
* Calculates numerical equivalent of phpMyAdmin version string
*
* @param string version
* @return mixed false on failure, integer on success
*/
function version_to_int($version)
{
$matches = array();
if (!preg_match('/^(\d+)\.(\d+)\.(\d+)((\.|-(pl|rc|dev|beta|alpha))(\d+)?)?$/', $version, $matches)) {
return false;
}
if (!empty($matches[6])) {
switch ($matches[6]) {
case 'pl':
$added = 60;
break;
case 'rc':
$added = 30;
break;
case 'beta':
$added = 20;
break;
case 'alpha':
$added = 10;
break;
case 'dev':
$added = 0;
break;
default:
messages_set('notice', 'version_match', 'VersionCheck',
'Unknown version part: ' . htmlspecialchars($matches[6]));
$added = 0;
break;
}
} else {
$added = 50; // for final
}
if (!empty($matches[7])) {
$added = $added + $matches[7];
}
return $matches[1] * 1000000 + $matches[2] * 10000 + $matches[3] * 100 + $added;
}
/**
* Checks whether config file is readable/writable
*
* @param bool &$is_readable
* @param bool &$is_writable
* @param bool &$file_exists
*/
function check_config_rw(&$is_readable, &$is_writable, &$file_exists)
{
$file_path = ConfigFile::getInstance()->getFilePath();
$file_dir = dirname($file_path);
$is_readable = true;
$is_writable = is_dir($file_dir);
if (SETUP_DIR_WRITABLE) {
$is_writable = $is_writable && is_writable($file_dir);
}
$file_exists = file_exists($file_path);
if ($file_exists) {
$is_readable = is_readable($file_path);
$is_writable = $is_writable && is_writable($file_path);
}
}
/**
* Performs various compatibility, security and consistency checks on current config
*
* Outputs results to message list, must be called between messages_begin()
* and messages_end()
*/
function perform_config_checks()
{
$cf = ConfigFile::getInstance();
$blowfish_secret = $cf->get('blowfish_secret');
$blowfish_secret_set = false;
$cookie_auth_used = false;
for ($i = 1, $server_cnt = $cf->getServerCount(); $i <= $server_cnt; $i++) {
$cookie_auth_server = ($cf->getValue("Servers/$i/auth_type") == 'cookie');
$cookie_auth_used |= $cookie_auth_server;
$server_name = $cf->getServerName($i);
if ($server_name == 'localhost') {
$server_name .= " [$i]";
}
if ($cookie_auth_server && $blowfish_secret === null) {
$blowfish_secret = uniqid('', true);
$blowfish_secret_set = true;
$cf->set('blowfish_secret', $blowfish_secret);
}
//
// $cfg['Servers'][$i]['ssl']
// should be enabled if possible
//
if (!$cf->getValue("Servers/$i/ssl")) {
$title = PMA_lang_name('Servers/1/ssl') . " ($server_name)";
messages_set('notice', "Servers/$i/ssl", $title,
PMA_lang('ServerSslMsg'));
}
//
// $cfg['Servers'][$i]['extension']
// warn about using 'mysql'
//
if ($cf->getValue("Servers/$i/extension") == 'mysql') {
$title = PMA_lang_name('Servers/1/extension') . " ($server_name)";
messages_set('notice', "Servers/$i/extension", $title,
PMA_lang('ServerExtensionMsg'));
}
//
// $cfg['Servers'][$i]['auth_type']
// warn about full user credentials if 'auth_type' is 'config'
//
if ($cf->getValue("Servers/$i/auth_type") == 'config'
&& $cf->getValue("Servers/$i/user") != ''
&& $cf->getValue("Servers/$i/password") != '') {
$title = PMA_lang_name('Servers/1/auth_type') . " ($server_name)";
messages_set('warning', "Servers/$i/auth_type", $title,
PMA_lang('ServerAuthConfigMsg', $i) . ' ' .
PMA_lang('ServerSecurityInfoMsg', $i));
}
//
// $cfg['Servers'][$i]['AllowRoot']
// $cfg['Servers'][$i]['AllowNoPassword']
// serious security flaw
//
if ($cf->getValue("Servers/$i/AllowRoot")
&& $cf->getValue("Servers/$i/AllowNoPassword")) {
$title = PMA_lang_name('Servers/1/AllowNoPassword') . " ($server_name)";
messages_set('warning', "Servers/$i/AllowNoPassword", $title,
PMA_lang('ServerNoPasswordMsg') . ' ' .
PMA_lang('ServerSecurityInfoMsg', $i));
}
}
//
// $cfg['blowfish_secret']
// it's required for 'cookie' authentication
//
if ($cookie_auth_used) {
if ($blowfish_secret_set) {
// 'cookie' auth used, blowfish_secret was generated
messages_set('notice', 'blowfish_secret_created', 'blowfish_secret_name',
PMA_lang('BlowfishSecretMsg'));
} else {
$blowfish_warnings = array();
// check length
if (strlen($blowfish_secret) < 8) {
// too short key
$blowfish_warnings[] = PMA_lang('BlowfishSecretLengthMsg');
}
// check used characters
$has_digits = (bool) preg_match('/\d/', $blowfish_secret);
$has_chars = (bool) preg_match('/\S/', $blowfish_secret);
$has_nonword = (bool) preg_match('/\W/', $blowfish_secret);
if (!$has_digits || !$has_chars || !$has_nonword) {
$blowfish_warnings[] = PMA_lang('BlowfishSecretCharsMsg');
}
if (!empty($blowfish_warnings)) {
messages_set('warning', 'blowfish_warnings' . count($blowfish_warnings),
'blowfish_secret_name', implode("<br />", $blowfish_warnings));
}
}
}
//
// $cfg['ForceSSL']
// should be enabled if possible
//
if (!$cf->getValue('ForceSSL')) {
messages_set('notice', 'ForceSSL', 'ForceSSL_name',
PMA_lang('ForceSSLMsg'));
}
//
// $cfg['AllowArbitraryServer']
// should be disabled
//
if ($cf->getValue('AllowArbitraryServer')) {
messages_set('warning', 'AllowArbitraryServer', 'AllowArbitraryServer_name',
PMA_lang('AllowArbitraryServerMsg'));
}
//
// $cfg['LoginCookieValidity']
// should be at most 1800 (30 min)
//
if ($cf->getValue('LoginCookieValidity') > 1800) {
messages_set('warning', 'LoginCookieValidity', 'LoginCookieValidity_name',
PMA_lang('LoginCookieValidityMsg'));
}
//
// $cfg['SaveDir']
// should not be world-accessible
//
if ($cf->getValue('SaveDir') != '') {
messages_set('notice', 'SaveDir', 'SaveDir_name',
PMA_lang('DirectoryNotice'));
}
//
// $cfg['TempDir']
// should not be world-accessible
//
if ($cf->getValue('TempDir') != '') {
messages_set('notice', 'TempDir', 'TempDir_name',
PMA_lang('DirectoryNotice'));
}
//
// $cfg['GZipDump']
// requires zlib functions
//
if ($cf->getValue('GZipDump')
&& (@!function_exists('gzopen') || @!function_exists('gzencode'))) {
messages_set('warning', 'GZipDump', 'GZipDump_name',
PMA_lang('GZipDumpWarning', 'gzencode'));
}
//
// $cfg['BZipDump']
// requires bzip2 functions
//
if ($cf->getValue('BZipDump')
&& (!@function_exists('bzopen') || !@function_exists('bzcompress'))) {
$functions = @function_exists('bzopen')
? '' :
'bzopen';
$functions .= @function_exists('bzcompress')
? ''
: ($functions ? ', ' : '') . 'bzcompress';
messages_set('warning', 'BZipDump', 'BZipDump_name',
PMA_lang('BZipDumpWarning', $functions));
}
//
// $cfg['ZipDump']
// requires zip_open in import
//
if ($cf->getValue('ZipDump') && !@function_exists('zip_open')) {
messages_set('warning', 'ZipDump_import', 'ZipDump_name',
PMA_lang('ZipDumpImportWarning', 'zip_open'));
}
//
// $cfg['ZipDump']
// requires gzcompress in export
//
if ($cf->getValue('ZipDump') && !@function_exists('gzcompress')) {
messages_set('warning', 'ZipDump_export', 'ZipDump_name',
PMA_lang('ZipDumpExportWarning', 'gzcompress'));
}
}
?>
|