/** * Formats interval like 10 per hour * * @param integer $num number to format * @param integer $precision required precision * * @return string formatted string */ function ADVISOR_bytime($num, $precision) { if ($num >= 1) { // per second $per = __('per second'); } elseif ($num * 60 >= 1) { // per minute $num = $num * 60; $per = __('per minute'); } elseif ($num * 60 * 60 >= 1) { // per hour $num = $num * 60 * 60; $per = __('per hour'); } else { $num = $num * 60 * 60 * 24; $per = __('per day'); } $num = round($num, $precision); if ($num == 0) { $num = '<' . PMA\libraries\Util::pow(10, -$precision); } return "{$num} {$per}"; }
/** * Get Ajax return when $_REQUEST['type'] === 'setval' * * @param Array $variable_doc_links documentation links * * @return null */ function PMA_getAjaxReturnForSetVal($variable_doc_links) { $response = PMA\libraries\Response::getInstance(); $value = $_REQUEST['varValue']; $matches = array(); if (isset($variable_doc_links[$_REQUEST['varName']][3]) && $variable_doc_links[$_REQUEST['varName']][3] == 'byte' && preg_match('/^\\s*(\\d+(\\.\\d+)?)\\s*(mb|kb|mib|kib|gb|gib)\\s*$/i', $value, $matches)) { $exp = array('kb' => 1, 'kib' => 1, 'mb' => 2, 'mib' => 2, 'gb' => 3, 'gib' => 3); $value = floatval($matches[1]) * PMA\libraries\Util::pow(1024, $exp[mb_strtolower($matches[3])]); } else { $value = PMA\libraries\Util::sqlAddSlashes($value); } if (!is_numeric($value)) { $value = "'" . $value . "'"; } if (!preg_match("/[^a-zA-Z0-9_]+/", $_REQUEST['varName']) && $GLOBALS['dbi']->query('SET GLOBAL ' . $_REQUEST['varName'] . ' = ' . $value)) { // Some values are rounded down etc. $varValue = $GLOBALS['dbi']->fetchSingleRow('SHOW GLOBAL VARIABLES WHERE Variable_name="' . PMA\libraries\Util::sqlAddSlashes($_REQUEST['varName']) . '";', 'NUM'); $response->addJSON('variable', PMA_formatVariable($_REQUEST['varName'], $varValue[1], $variable_doc_links)); } else { $response->setRequestStatus(false); $response->addJSON('error', __('Setting variable failed')); } }
/** * Based on IP Pattern Matcher * Originally by J.Adams <*****@*****.**> * Found on <https://www.php.net/manual/en/function.ip2long.php> * Modified for phpMyAdmin * * Matches: * xxx.xxx.xxx.xxx (exact) * xxx.xxx.xxx.[yyy-zzz] (range) * xxx.xxx.xxx.xxx/nn (CIDR) * * Does not match: * xxx.xxx.xxx.xx[yyy-zzz] (range, partial octets not supported) * * @param string $testRange string of IP range to match * @param string $ipToTest string of IP to test against range * * @return boolean whether the IP mask matches * * @access public */ function PMA_ipv4MaskTest($testRange, $ipToTest) { $result = true; $match = preg_match('|([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)/([0-9]+)|', $testRange, $regs); if ($match) { // performs a mask match $ipl = ip2long($ipToTest); $rangel = ip2long($regs[1] . '.' . $regs[2] . '.' . $regs[3] . '.' . $regs[4]); $maskl = 0; for ($i = 0; $i < 31; $i++) { if ($i < $regs[5] - 1) { $maskl = $maskl + PMA\libraries\Util::pow(2, 30 - $i); } // end if } // end for if (($maskl & $rangel) == ($maskl & $ipl)) { return true; } return false; } // range based $maskocts = explode('.', $testRange); $ipocts = explode('.', $ipToTest); // perform a range match for ($i = 0; $i < 4; $i++) { if (preg_match('|\\[([0-9]+)\\-([0-9]+)\\]|', $maskocts[$i], $regs)) { if ($ipocts[$i] > $regs[2] || $ipocts[$i] < $regs[1]) { $result = false; } // end if } else { if ($maskocts[$i] != $ipocts[$i]) { $result = false; } // end if } // end if/else } //end for return $result; }
/** * Test forpow * * @return void */ public function testNegativeExpGmppow() { if (function_exists('gmp_pow')) { $this->assertEquals(false, PMA\libraries\Util::pow(2, -2, 'gmp_pow')); } else { $this->markTestSkipped('function gmp_pow() does not exist'); } }