= 32 && $b < 255)) ? $c : '.') !== false) && (++$j === 16 || $i === $l - 1)) { $dp .= sprintf('%06X %-23s %-24s %-8s %-8s' . "\n", $i, substr($hx, 0, 23), substr($hx, 24), substr($a, 0, 8), substr($a, 8)); $hx = $a = ''; $j = 0; } } echo "\n" . str_repeat('-', 126) . "\n" . $dp; } function sqpt_hexdump2(&$s) { for ($r = $e = '', $c = $i = 0, $sl = strlen($s) - 1; ($i <= $sl && ($b = ord($s[$i])) !== false && ($d = dechex($b)) !== false); $i++) { $r .= (($b <= 32) | ($b > 126)) ? ' .' : ' ' . $s[$i]; $e .= (strlen($d) == 2) ? ' ' . $d : ' 0' . $d; if ($c++ == 15) { $c = 0; $r .= "\n"; $e .= "\n"; } } print ("\n" . str_repeat('-', 126) . "\n" . $e . "\n" . str_repeat('-', 126) . "\n" . $r . "\n" . str_repeat('-', 126) . "\n"); } function sqpt_hexdump3(&$d) { for ($l = strlen($d), $hx = $a = $dp = '', $i = $j = 0; ($i < $l && false !== ($b = ord($c = substr($d, $i, 1)))); $i++) { $hx .= sprintf('%02x ', $b); $a .= (($b >= 32 && $b < 255)) ? $c : '.'; if (++$j === 16 || $i === $l - 1) { $dp .= sprintf('%06X %-48s %-20s' . "\n", $i, $hx, $a); $hx = $a = ''; $j = 0; } } echo "\n" . str_repeat('-', 126) . "\n" . $dp; } function sqpt_hexdump4(&$d) { for ($hex = $substr = '', $i = 0; $i < strlen($d); $i++) { if (!($i % 4) && $i != 0) $hex .= ' '; if (!($i % 16) && $i != 0) $hex .= ' ' . preg_replace("/[^a-zA-Z0-9!-.<>\/]/", '.', $substr) . "\n" . ($substr = ''); $substr .= $d[$i]; $hex .= dechex(ord($d[$i])); } return "\n" . str_repeat('-', 126) . "\n" . $hex . "\n" . str_repeat('-', 126) . "\n"; ; } function sqpt_readfile($f, $b = false) { sqpt_logg(__FILE__, __FILE__, __FUNCTION__, __LINE__, "reading {$b} bytes of file {$f}"); $fp = null; $d = ''; if (!((false === $b && $b = @filesize($f)) > 0) || !sqpt_exists($f) || !false === ($fp = @fopen($f, 'rb')) || !is_resource($fp)) return false; if ($b > 4096) while (!feof($fp) && strlen($d) < $b) $d .= @fread($fp, 4096); else $d = @fread($fp, $b); @fclose($fp); sqpt_t(__FILE__ . '::' . __FUNCTION__ ); return $d; } function sqpt_exists($f) { sqpt_logg(__FILE__, __FILE__, __FUNCTION__, __LINE__, "checking for file {$f}"); $ret = (((@file_exists($f)) === false && (@realpath($f)) === false) || (@stat($f)) === false) ? false : true; sqpt_t(__FILE__ . '::' . __FUNCTION__ ); return $ret; } function sqpt_pp($title = '', $text = '') { $out = (!empty($text) && is_string($title)) ? "\n[ {$title} ]\n" : ''; if (is_array($text) || is_object($text)) $out = print_r($text, 1); else { if (!empty($text)) { ob_start(); var_dump($text); $out = ob_get_clean(); } else if (is_string($text)) $out = $text; } //echo '
'.htmlspecialchars($text).'
'; $f = 'display:block;padding:5px;margin:10px;font-family: Consolas, Monaco, Courier, monospace; padding: 1px 3px; margin: 0 1px; font-size: 11px; font-weight:normal; font-style:normal; background-color:#FFF;color:#000;border:2px solid #F7F7F7;overflow-x:auto;'; return printf('
%s
', $f, htmlspecialchars($out)); } function sqpt_get_ip(&$h) { static $g = array(); $ip = $h; !isset($g[$h]) && $g[$h] = ((strspn($h, '.0123456789') != strlen($h)) && $h == (long2ip(ip2long($ip = gethostbyname($h))))) ? $h : $ip; error_log(print_r($g, 1)); return $g[$h]; } function sqpt_get_mem_usage($raw = false) { static $v, $m; !isset($m) && $m = sqpt_cf('memory_get_usage'); if ($m === false) return 1; !isset($v) && $v = version_compare(phpversion(), '5.2.0', '>='); $mem = (($v === false) ? memory_get_usage(true) : memory_get_usage()); return (($raw !== false) ? sqpt_bytes($mem) : $mem); } function sqpt_set_mem($mem = false) { sqpt_logg(__FILE__, __FILE__, __FUNCTION__, __LINE__, "setting mem to $mem"); if (sqpt_cf('memory_get_usage') && ((int)@ini_get('memory_limit') < abs(intval($mem)))) @ini_set('memory_limit', $this->_s['mem_limit']); sqpt_t(__FILE__ . '::' . __FUNCTION__ ); return true; } function sqpt_bytes($b = 0) { static $s; if (null === $s) $s = array("B", "Kb", "MB", "GB", "TB", "PB"); $e = floor(log($b) / log(1024)); return sprintf("%.2f " . $s[$e], (($b > 0) ? ($b / pow(1024, floor($e))) : 0)); } function sqpt_tt($id = 'new', $d = false) { static $a = array(); $ct = array_sum(explode(chr(32), microtime())); if (!isset($a[$id])) return $a[$id] = $ct; elseif ($d) return sprintf("%.4f", ($ct - $a[$id])); } function sqpt_t($f = '') { if ((sqpt_tt($f, 1)) == '') return; sqpt_d(4) && error_log('PHP SQPT TIME: [' . sqpt_tt($f, 1) . '] [' . sqpt_tt(__FILE__, 1) . "] [{" . sqpt_get_mem_usage(1) . "}] {$f}", 0); } function sqpt_cf($f) { static $b, $g = array(); is_null($b) && $b = (function_exists('ini_get')) ? explode(',', strtolower(ini_get('disable_functions'))) : array(); /*error_log(print_r(array('g'=>$g,'b'=>$b),1));*/ if (false !== ($f = strtolower($f)) && (in_array($f, $g) || in_array($f, $b))) return (in_array($f, $g)); return (!function_exists($f)) ? !($b[] = $f) : !!($g[] = $f); } function sqpt_d($level = 0) { return (bool)(isset($GLOBALS["sqpt_instance"]) && absint($GLOBALS["sqpt_instance"]->debug) > absint($level)) ? true : false; } function sqpt_logg($f = '', $c = '', $fu = '', $l = '', $m = '') { /* 0 message is sent to PHP's system logger, using the Operating System's system logging mechanism or a file, depending on what the error_log configuration directive is set to. This is the default option. 1 message is sent by email to the address in the destination parameter. This is the only message type where the fourth parameter, extra_headers is used. 2 No longer an option. 3 message is appended to the file destination . A newline is not automatically added to the end of the message string. 4 message is sent directly to the SAPI logging handler. */ sqpt_t($c . '::' . $fu); return error_log("PHP SQPT Notice: {$fu}() {$m}"); } function sqpt_err($f = null, $l = null, $m = '') { return !error_log("PHP SQPT ERROR: {$m} - {$f} [{$l}]", 0); } function sqpt_sockdebug(&$fp) { ob_start(); echo "\n"; $oe = error_reporting(E_ALL & ~ E_WARNING); print_r(array('stream_get_filters' => stream_get_filters(), 'stream_get_wrappers' => stream_get_wrappers(), 'stream_get_transports' => stream_get_transports(), 'stream_get_filters' => stream_get_filters(), 'stream_socket_get_name' => stream_socket_get_name($fp), 'stream_supports_lock' => stream_supports_lock($fp), )); $e1 = $e2 = $e3 = $e4 = array(); $e1 = socket_last_error(); if (is_resource($fp)) $e2 = socket_last_error($fp); $e3 = socket_strerror(null); $e4 = socket_strerror($e2); $e5 = socket_strerror($e1); $e5 = ($e5 == $e4) ? '' : "socket_strerror(socket_last_error()) => {$e5}\n"; $e3 = ($e3 == $e4 || empty($e3)) ? '' : "socket_strerror() => {$e3}\n"; $e4 = "socket_strerror(socket_last_error(fp)) => {$e4}\n"; $e1 = ($e1 == $e2 || empty($e1)) ? '' : "socket_last_error() => {$e1}\n"; $e2 = (!empty($e2)) ? "socket_last_error(fp) => {$e2}\n" : ''; foreach (array($e1, $e2, $e3, $e4, $e5) as $e) if (!empty($e)) echo $e; $s1 = $s2 = $s3 = array(); $s1 = socket_get_status($fp); $s2 = stream_get_meta_data($fp); $s3 = stream_context_get_options($fp); $s1 = (is_array($s1) && sizeof($s1) > 0) ? print_r($s1, 1) : ''; $s2 = (is_array($s2) && sizeof($s2) > 0) ? print_r($s2, 1) : ''; $s3 = (is_array($s3) && sizeof($s3) > 0) ? print_r($s3, 1) : ''; $s3 = (empty($s3)) ? '' : "stream_context_get_options => {$s3}"; $s2 = ($s1 == $s2 || empty($s2)) ? '' : "stream_get_meta_data(fp) => {$s2}"; $s1 = (empty($s1)) ? '' : "socket_get_status(fp) => {$s1}"; foreach (array($s1, $s2, $s3) as $s) if (!empty($s)) echo $s; error_reporting($oe); sqpt_t(__FILE__ . '::' . __FUNCTION__ ); return error_log(ob_get_clean()); } function sqpt_global_debug() { $t = ''; global $_GET, $_POST, $_COOKIE, $_SESSION, $_ENV, $_FILES, $_SERVER, $_REQUEST, $HTTP_POST_FILES, $HTTP_POST_VARS, $HTTP_SERVER_VARS, $HTTP_RAW_POST_DATA, $HTTP_GET_VARS, $HTTP_COOKIE_VARS, $HTTP_ENV_VARS; $gv = create_function('$n', 'global $$n; ob_start(); if ( is_array($$n) && sizeof($$n)>0 && print("[{$n}]\n") ) print_r($$n);return ob_get_clean();'); foreach (array('_GET', '_POST', '_COOKIE', '_SESSION', '_ENV', '_FILES', '_SERVER', '_REQUEST', 'HTTP_POST_FILES', 'HTTP_POST_VARS', 'HTTP_SERVER_VARS', 'HTTP_RAW_POST_DATA', 'HTTP_GET_VARS', 'HTTP_COOKIE_VARS', 'HTTP_ENV_VARS') as $k) $t .= $gv($k); return $t; } /** * sqpt_clean_this() * * @param mixed $aa_wat * @return */ function sqpt_clean_this($aa_wat) { return htmlentities($aa_wat, ENT_QUOTES, 'UTF-8'); } /** * sqpt_post_value() * * @param mixed $v * @return */ function sqpt_post_value($v) { if (is_array($v) && sizeof($v) > 0) { $out = array(); foreach ($v as $k) { if (isset($_POST[$k]) && !empty($_POST[$k])) $out[$k] = $_POST[$k]; } } elseif (isset($_POST[$v]) && !empty($_POST[$v])) $out = $_POST[$v]; return $out; } /** * sqpt_clean_url() * * @param mixed $url * @param mixed $protocols * @param string $context * @return */ function sqpt_clean_url($url, $protocols = array('http', 'https', 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 'telnet'), $context = 'none') { $original_url = $url; $url = trim($url); if ('' == $url) return $url; $url = preg_replace('|[^a-z0-9-~+_.?#=!&;,/:%@$*\'()\\x80-\\xff]|i', '', $url); $url = str_replace(array('%0d', '%0a'), '', $url); $url = str_replace(';//', '://', $url); if (strpos($url, ':') === false) $url = 'http://' . $url; // Replace ampersands and single quotes only when displaying. if ('display' == $context) { $url = preg_replace('/&([^#])(?![a-z]{2,8};)/', '&$1', $url); $url = str_replace("'", ''', $url); } return $url; } /** * sqpt_valid_url() * * @param mixed $url * @return */ function sqpt_valid_url($url) { $url = sqpt_clean_url($url); $ui2 = array(); if (!$ui2 = parse_url($url)) return false; $ui = array_merge(array('scheme' => '', 'host' => '', 'port' => '', 'user' => '', 'pass' => '', 'path' => '', 'query' => '', 'fragment' => ''), $ui2); if (empty($ui['scheme']) || empty($ui['host'])) return false; if (!$fp = curl_init($url)) return false; curl_close($fp); /* * * if (empty($ui['port'])) * { * switch($ui['scheme']) : * case 'http': $ui['port'] = 80; break; * case 'https': $ui['port'] = 443; break; * case 'ftp': $ui['port'] = 21; break; * case 'ftps': $ui['port'] = 990; break; * default: $ui['port'] = 0; break; * endswitch; * } * $data = ''; * $fp = @fsockopen($scheme . $ui['host'], $port, $errno, $errstr, 10); * if ($fid) { * fputs($fid, 'GET ' . (isset($ui['path'])? $ui['path']: '/') . (isset($ui['query'])? '?' . $ui['query']: '') . " HTTP/1.0\r\n" . * 'Host: ' . $ui['host'] . "\r\n\r\n"); * while (!feof($fid)) { $data .= @fgets($fid, 128); } * fclose($fid); * return !empty($data); * } else return false; */ return $url; } /** * sqpt_error_debug() * * @return */ function sqpt_error_debug($vb = false) { // global $_GET,$_POST,$_COOKIE,$_SESSION,$_ENV,$_FILES,$_SERVER,$_REQUEST,$HTTP_POST_FILES,$HTTP_POST_VARS,$HTTP_SERVER_VARS,$HTTP_RAW_POST_DATA,$HTTP_GET_VARS,$HTTP_COOKIE_VARS,$HTTP_ENV_VARS; $oa = array(); global $_GET, $_POST, $_COOKIE, $_SESSION, $_ENV, $_FILES, $_SERVER, $_REQUEST, $HTTP_POST_FILES, $HTTP_POST_VARS, $HTTP_SERVER_VARS, $HTTP_RAW_POST_DATA, $HTTP_GET_VARS, $HTTP_COOKIE_VARS, $HTTP_ENV_VARS; $gv = create_function('$n', 'global $$n;return (( !is_null($$n) && is_array($$n) && sizeof($$n)>0 ) ? $$n : false);'); foreach (array('_GET', '_POST', '_COOKIE', '_SESSION', '_ENV', '_FILES', '_SERVER', '_REQUEST', 'HTTP_POST_FILES', 'HTTP_POST_VARS', 'HTTP_SERVER_VARS', 'HTTP_RAW_POST_DATA', 'HTTP_GET_VARS', 'HTTP_COOKIE_VARS', 'HTTP_ENV_VARS') as $k) { $o = $gv($k); if (is_array($o) && sizeof($o) > 0) $oa[($k{0} == '_' ? substr($k, 1) : $k)] = $o; } if (is_array($_SERVER) && sizeof($_SERVER) > 0 && ($oa['HTTP'] = array()) !== false) foreach ($_SERVER as $k => $v) $oa[$kk][(($kk = (substr($k, 0, 5) == "HTTP_" ? "HTTP" : "SERVER")) == "HTTP" ? substr($k, 5) : $k)] = $v; sqpt_cf('wp_upload_dir') && $oa['UPLOAD'] = wp_upload_dir(); return !!error_log(print_r($oa, 1)); } /** * sqpt_catch_errors() * * @param string $werrors * @return */ function sqpt_catch_errors($werrors = '') { sqpt_logg(__FILE__, __FILE__, __FUNCTION__, __LINE__, 'Starting...'); $error = $errors = $messages = ''; foreach ($werrors->get_error_codes() as $code) { $severity = $werrors->get_error_data($code); foreach ($werrors->get_error_messages($code) as $err) { //error_log('FORM ERROR!!! '.__LINE__.' '.$code.' '.$err); if ('message' == $severity) $messages .= ' ' . $err . "
\n"; else $errors .= ' ' . $err . "
\n"; } } if (!empty($errors) || !empty($messages)) { echo '
'; if (!empty($errors)) echo '
' . apply_filters('login_errors', $errors) . "
\n"; if (!empty($messages)) echo '
' . apply_filters('login_messages', $messages) . "
\n"; echo '
'; } } /** * sqpt_handle_upload() * * @param mixed $file * @param mixed $new_file * @return */ function sqpt_handle_upload(&$file, $new_file) { /** * @param array $file Reference to a single element of $_FILES. Call the function once for each uploaded file. * @param array $overrides Optional. An associative array of names=>values to override default variables with extract( $overrides, EXTR_OVERWRITE ). * @return array On success, returns an associative array of file attributes. On failure, returns $overrides['upload_error_handler'](&$file, $message ) or array( 'error'=>$message ). */ $upload_error_strings = array(UPLOAD_ERR_OK => "File upload successful.", UPLOAD_ERR_INI_SIZE => "The uploaded file exceeds the upload_max_filesize directive in php.ini.", UPLOAD_ERR_FORM_SIZE => "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.", UPLOAD_ERR_PARTIAL => "The uploaded file was only partially uploaded.", UPLOAD_ERR_NO_FILE => "No file was uploaded.", UPLOAD_ERR_NO_TMP_DIR => "Missing a temporary folder.", UPLOAD_ERR_CANT_WRITE => "Failed to write file to disk.", UPLOAD_ERR_EXTENSION => "File upload stopped by extension."); $mimes = array('application/ecmascript', 'application/javascript', 'text/x-js', 'text/css', 'application/json', 'text/plain', 'text/richtext', 'text/rtf', 'text/x-java-source', 'text/x-c', 'application/x-zip', 'application/x-javascript', 'image/pjpeg', 'image/jpeg', 'image/jpg', 'image/gif', 'image/png', 'image/x-png', 'image/bmp', 'image/x-icon'); if (!isset($file) || !isset($file)) return new WP_Error($file['name'], 'ERROR: No file uploaded.'); if ($file['error'] > 0) return new WP_Error($file, $upload_error_strings[$file['error']]); if (!@is_uploaded_file($file['tmp_name'])) return new WP_Error($file['name'], 'Specified file failed upload test.'); if (!($file['size'] > 0)) return new WP_Error($file['name'], 'File is empty. Please upload something more substantial. This error could also be caused by uploads being disabled in your php.ini.'); if ($file['size'] < 3) return new WP_Error($file['name'], 'ERROR: Uploaded file too small! [' . $file['size'] . ']'); if ($file['size'] > 1475237000) return new WP_Error($file['name'], 'ERROR: Uploaded file too big! [' . $file['size'] . ']'); if (!in_array($file['type'], $mimes)) return new WP_Error($file['name'], 'ERROR: Wrong filetype! [' . $file['type'] . ']'); if (!move_uploaded_file($file['tmp_name'], $new_file)) return new WP_Error($file['name'], 'ERROR: Problem with file upload!'); $stat = stat(dirname($new_file)); $perms = $stat['mode'] & 0000666; @chmod($new_file, $perms); return $new_file; } /** * sqpt_show_captcha() * * @param integer $type * @param integer $numletters * @param integer $fontsize * @return */ function sqpt_show_captcha($type = 0, $numletters = 4, $fontsize = 22) { //sqpt_logg(__FILE__, __FILE__, __FUNCTION__, __LINE__, 'Starting...'); if (sqpt_lock()) sqpt_pp('global_debug', sqpt_global_debug()); if (!isset($_SESSION['token'])) { $defaults = array('captcha' => 'false', 'sqpt_show_captcha' => sqpt_show_captcha(3), 'sqpt_show_captcha1' => '', 'token' => md5($_SERVER['SERVER_NAME'] . $_SERVER['REMOTE_ADDR']), 'token_time' => 0); foreach ($defaults as $k => $v) $_SESSION[$k] = $v; } echo ''; if (isset($_SESSION['captcha']) && $_SESSION['captcha'] === 'true') return print '

' . (SQPT_TIMES_ALLOWED - $_SESSION['token_time']) . ' captcha-free uses remaining.  :p


'; $L = $A = $F = $C = $T = array(); $rgb = array(array(204, 0, 0), array(34, 136, 0), array(51, 102, 204), array(141, 214, 210), array(214, 141, 205), array(100, 138, 204)); $g = $fontsize; $capya_string = sqpt_rand_str($numletters, '234679abcdefghijkmnpqrtuvwxyzABCDEFGHJKMNPQRTUVWXYZ'); // the letters and numbers displayed on captcha $capya_bgfile = '/home/askapach/sites/captcha.askapache.com/capya/n.png'; // the background image for the captcha $image = imagecreatefrompng($capya_bgfile); // create image from background image $capya_file = tempnam('/home/askapach/sites/captcha.askapache.com/tmp', 'capyaask'); $capya_uri = 'http://captcha.askapache.com/' . basename($capya_file) . '.jpg?nocache=nocache'; // the public web address to finished captcha $_SESSION['sqpt_show_captcha1'] = $_SESSION['sqpt_show_captcha']; // store the md5 of the captcha string $_SESSION['sqpt_show_captcha'] = md5($capya_string); // store the md5 of the captcha string session_write_close(); // add chars to captcha image for ($i = 0; $i < $numletters; $i++) { $L[] = substr($capya_string, $i, 1); // each char from string into individual variable $A[] = rand(-20, 20); // random angle for each char $F[] = '/home/askapach/sites/captcha.askapache.com/capya/' . rand(1, 10) . ".ttf"; // random font for each char $C[] = rand(0, 5); // random color for each char $T[] = imagecolorallocate($image, $rgb[$C[$i]][0], $rgb[$C[$i]][1], $rgb[$C[$i]][2]); // allocate colors for chars imagettftext($image, $fontsize, $A[$i], $g, $fontsize + 15, $T[$i], $F[$i], $L[$i]); // write chars to image $g += $fontsize + 10; } imagejpeg($image, str_replace('captcha.askapache.com/tmp', 'captcha.askapache.com/htdocs/', $capya_file) . '.jpg'); // save jpeg image to public web folder imagedestroy($image); if ($type == 3) return md5($capya_string); if ($type == 1) echo '

'; else echo '

'; //if ($_SERVER['REMOTE_ADDR'] == '24.123.215.58') {echo '
' . $capya_string . "\n" . md5($_POST['capya']) . "\n";print_r($_SESSION);echo '
';} //if (sqpt_lock()) {echo '
' . $capya_file. " - ".$capya_string . "\n" . md5($_POST['capya']) . "\n";print_r($_SESSION);echo '
';} } /** * sqpt_start_captcha() * * @return */ function sqpt_start_captcha() { //sqpt_logg(__FILE__, __FILE__, __FUNCTION__, __LINE__, 'Starting...'); //if (sqpt_lock()) sqpt_pp('global_debug', sqpt_global_debug()); if (!isset($_SESSION['token'])) { $defaults = array('captcha' => 'false', 'sqpt_show_captcha' => sqpt_show_captcha(3), 'sqpt_show_captcha1' => '', 'token' => md5($_SERVER['SERVER_NAME'] . $_SERVER['REMOTE_ADDR']), 'token_time' => 0); foreach ($defaults as $k => $v) $_SESSION[$k] = $v; } // if ($_SERVER['REMOTE_ADDR'] == '24.123.215.58') { echo '
';		print_r($_SESSION);		print_r($_POST);		echo '
'; } if ($_SERVER['REQUEST_METHOD'] == 'POST') { $cap = md5($_POST['capya']); $errors = new WP_Error(); $_SESSION['token_time']++; if ($_SESSION['token_time'] >= SQPT_TIMES_ALLOWED) { $errors->add('allowed_times', 'ERROR: Re-verify Captcha, thanks!'); $_SESSION['token_time'] = 0; } if ($_SESSION['captcha'] !== 'true') { if (!isset($_POST['capya'])) $errors->add('capya_not_set', 'ERROR: Captcha not set! Please refresh the page (GET) and try again. Thanks!'); else $_SESSION['captcha'] = 'true'; } /* if (strpos("{$_SESSION['sqpt_show_captcha'].$_SESSION['sqpt_show_captcha1']", $_POST['capya']) !== false) )$errors->add('invalid_capya_md5', * 'ERROR: Posted Captcha invalid, please try again. Thanks!'); /* else $_SESSION['captcha'] = 'true';*/ } if ($_POST['token'] != $_SESSION['token'])$errors->add('invalid_token', 'ERROR: Token invalid! Please refresh the page (GET) and try again. Thanks!'); if (is_wp_error($errors) && $errors->get_error_codes()) { $_SESSION['captcha'] = 'false'; sqpt_catch_errors($errors); } else $_SESSION['captcha'] = 'true'; } return (bool)($_SESSION['captcha'] == 'true'); } /** * sqpt_button() * * @param string $text * @param string $href * @param string $title * @return */ function sqpt_button($text = '', $href = '/', $title = '') { printf('%1$s', $text, $href, $title); } /** * sqpt_form_checked() * * @param mixed $checked * @param bool $current * @param bool $echo * @return */ function sqpt_form_checked($checked, $current = true, $echo = true) { return sqpt_form_checked_selected_helper($checked, $current, $echo, 'checked'); } /** * sqpt_form_selected() * * @param mixed $selected * @param bool $current * @param bool $echo * @return */ function sqpt_form_selected($selected, $current = true, $echo = true) { return sqpt_form_checked_selected_helper($selected, $current, $echo, 'selected'); } /** * sqpt_form_checked_selected_helper() * * @param mixed $helper * @param mixed $current * @param mixed $echo * @param mixed $type * @return */ function sqpt_form_checked_selected_helper($helper, $current, $echo, $type) { $result = ($helper == $current) ? " $type='$type'" : ''; if ($echo)echo $result; return $result; } /** * sqpt_form_field() * * @param string $ft * @param string $_title * @param string $_id * @param string $_desc * @param string $_value * @return */ function sqpt_form_field($ft = '', $_title = '', $_id = '', $_desc = '', $_value = '') { if ($_desc != '')$_desc = '

' . $_desc . '

'; switch ($ft) { case 1 : ?>
'; * if ($_SESSION['captcha'] === true) echo '

' . (SQPT_TIMES_ALLOWED - $_SESSION['token_time']) . ' captcha-free uses remaining.  :p

'; * else sqpt_show_captcha(); * if ($_SERVER['REMOTE_ADDR'] == '24.123.215.58') * { * echo '
';
 * print_r($_SESSION);
 * print_r($_POST);
 * echo '
'; * } * echo ''; * } //if(!defined('ASKAPACHE_MY_INC')) require_once 'interface.inc.php'; //$aa = new SwiftSock; //$url='http://services.digg.com/stories?link=https://www.askapache.com'.$l.'&appkey=https://www.askapache.com/'; //print_tcp_trace() //print_r($aa->get_response_headers()); //echo $aa->get_response_body(); * aa_check_captcha() * * @return * function aa_check_captcha() * { * if (!isset($_SESSION['token'])){ * $defaults = array('captcha' => false, 'sqpt_show_captcha' => sqpt_show_captcha(3), 'token' => md5($_SERVER['SERVER_NAME'] . $_SERVER['REMOTE_ADDR']), 'token_time' => 0); * foreach($defaults as $k=>$v)$_SESSION[$k]=$v; * print_r(sqpt_parse_args( $_SESSION, $defaults)); * } * * if ($_SERVER['REQUEST_METHOD'] != 'POST')return ' '; * $error = ''; * $_SESSION['token_time']++; * if ($_SESSION['token_time'] >= SQPT_TIMES_ALLOWED) * { * $error = '

You know what to do. Thanks

'; * $_SESSION['token_time'] = 0; * } * if ($_SESSION['captcha'] !== true) * { * if (!isset($_POST['capya'])) $error .= '

Captcha not set! Please refresh the page (GET) and try again. Thanks

'; * elseif (md5($_POST['capya']) != $_SESSION['sqpt_show_captcha']) $error .= '

Captcha invalid, please try again. Thanks

'; * else $_SESSION['captcha'] = true; * } * if ($_POST['token'] != $_SESSION['token']) $error .= '

Token invalid! Please refresh the page (GET) and try again. Thanks

'; * * $_SESSION['captcha'] = ($error == '' ) ? true : false; * return $error; * } */ //function make_base64_img(){ /*header('Content-Type:text/plain'); * $source_file='/home/askapache/sites/askapache.com/htdocs/z/i/1.gif'; * $handle = fopen($source_file,'rb'); * $file_content = fread($handle,filesize($source_file)); * fclose($handle); * $pix = chunk_split(base64_encode($file_content)); * echo $pix; */ //} /** function aa_randomize_curl($u='https://www.askapache.com/',$s=0) * { * global $aaUSERAGENTS_FF,$aaUSERAGENTS_IE,$aaINTERFACES; * * if($s!=0)return $aaINTERFACES[array_rand($aaINTERFACES)]; * * $aaPOSTS=array(); * $myposts=get_posts("numberposts=-1&orderby=ID"); * foreach($myposts as $post){ * $aaPOSTS[]=get_permalink($post->ID); * } * $FF_HEADERS=array( */ //"Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5", /* * "Accept-Language: en-us,en;q=0.9,de;q=0.8,ja;q=0.8,zh;q=0.7,zh-cn;q=0.6,nl;q=0.5,fr;q=0.5,it;q=0.4,ko;q=0.3,es;q=0.2,ru;q=0.2,pt;q=0.1", * "Accept-Encoding: none", * "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7", * "Keep-Alive: 300", * "Connection: Keep-Alive", * "Pragma:" * ); * * $IE_HEADERS=array( * "Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/msword, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms-application, application/x-shockwave-f", * "Accept-Language: en-us", * "UA-CPU: x86", * "Accept-Encoding: none", * "Connection: keep-alive", * "Pragma:" * ); * * * $U='Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3'; * $H=$FF_HEADERS; * $r=array('URL'=>$u,'IP'=>$aaINTERFACES[array_rand($aaINTERFACES)],'REFERER'=>$aaPOSTS[array_rand($aaPOSTS)], 'USERAGENT'=>$U,'HEADERS'=>$H); * return $r; * } */ /* * function aa_url_exists($url) { * if (!$fp = curl_init($url)) return false; * return true; * } */ /* * function aa_isget_redirected($the_url){ * $AA_MY_HEADERS=array( */ //"Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5", /*"Accept-Language: en-us,en;q=0.9,de;q=0.8,ja;q=0.8,zh;q=0.7,zh-cn;q=0.6,nl;q=0.5,fr;q=0.5,it;q=0.4,ko;q=0.3,es;q=0.2,ru;q=0.2,pt;q=0.1", * "Accept-Encoding: gzip,deflate", * "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7", * "Connection: close", * "Pragma:"); * $redirectedto=$the_url; * * if (!$url_info = parse_url($the_url)) return 'bad url'; * $ch = curl_init(); * curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 22); * curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 0); * curl_setopt ($ch, CURLOPT_URL, $the_url); * curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); * curl_setopt ($ch, CURLOPT_REFERER, $the_url); * curl_setopt ($ch, CURLOPT_FAILONERROR, 0); * curl_setopt ($ch, CURLOPT_VERBOSE, 1); * //curl_setopt ($ch, CURLOPT_MAXCONNECTS, 5); * curl_setopt ($ch, CURLOPT_CUSTOMREQUEST, 'GET'); * curl_setopt ($ch, CURLINFO_HEADER_OUT, 1); * curl_setopt ($ch, CURLOPT_NOBODY, 1); * curl_setopt ($ch, CURLOPT_HTTPHEADER, $AA_MY_HEADERS); * curl_setopt ($ch, CURLOPT_HEADER, 1); * curl_setopt ($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.7) Gecko/20070914 Firefox/2.0.0.7'); * $r=curl_exec ($ch); * $ch_info = curl_getinfo($ch); * * if (curl_errno($ch)){ * error_log(print_r(curl_errno($ch),1)); * error_log(print_r(curl_error($ch),1)); * } * curl_close($ch); * * if( (string)$ch_info['http_code'][0] == '3' ) { * foreach($r as $resp){ * if(false!==strpos($resp, 'Location'))$redirectedto=trim(str_replace('Location:','',$resp)); * } * } * * return $redirectedto; * } */ // Fetches all HTTP requests from the current request // ----------------------------------- /* * function get_request_headers() { * $headers = array(); * echo'

Headers From Sent by You (browser)

'."\n"; * foreach(array_keys($_SERVER) as $skey) { * if( (substr($skey, 0, 5) == "HTTP_") && !empty($_SERVER[$skey]) )$headers[str_replace('HTTP_','',$skey)]=$_SERVER[$skey]; * } * * foreach($headers as $i=>$key){ * echo $i.": ".$key."\n"; * } * echo "\n".'
'; * }// ----------------------------------- */ /* * function aa_file_get_contents_tla($url, $time_out){ * $result = ""; * $url = parse_url($url); * if ($handle = @fsockopen ($url["host"], 80)) { * if(sqpt_cf("socket_set_timeout")) { * socket_set_timeout($handle,$time_out,0); * } else if(sqpt_cf("stream_set_timeout")) { * stream_set_timeout($handle,$time_out,0); * } * fwrite ($handle, "GET $url[path]?$url[query] HTTP/1.0\r\nHost: $url[host]\r\n\r\n"); * while (!feof($handle)) { * $result .= @fread($handle, 40960); * } * fclose($handle); * } * return $result; * } */ /* * function aa_caps($string,$echo=0){ * global $aabadwords; * $final=''; * $words = explode(" ", $string); * if(sizeof($words)>=1){ * for($i=0; $i3) * { * $string = strtolower($words[$i]); * $string = substr_replace($string, strtoupper(substr($string, 0, 1)), 0, 1); * } else $string=$words[$i]; * $final .= "$string "; * } * } * if($echo)echo $final; * else return $final; * } */ /* * * * Run cron.php without crontab: now it's possible. * Submitted by diego on Mon, 26/02/2007 - 00:39. php | scripts * Dear drupal webmaster newbies, this is for you! * Now it's possible to run cron.php regularily, without any access to the server or without any knowledge about servers and crontab! * Just put these simple PHP lines in a block of your Drupal site, better if mostly present, or create a new block with them: * (60*60*6)) * { * $pntr=fopen('lastcron.txt', 'w'); * if(fwrite($pntr, $tmstmp)) * { * mail ("dest","cron OK","OK"); * include ("cron.php"); * } * else * { * mail ("dest","cron FAIL","FAIL"); * } * fclose($pntr); * } * ?> * Of curse replace the lines containing mail ("dest", with your own email address instead of dest. * Then you have to create a text file (lascron.txt) filled with whatever you want (eg: 123456 is ok!) and upload it on the server in the same folder of cron.php (usually the root of your FTP access). Then set file permission to 666 (rw,rw,rw): I've done it with FileZilla, right click on the uploaded file, file attributes, put the flag on write permission for everyone... anyway ... do it, no matter how ;) * Done! * Now 'cron.php' will run more or less regularly, depending on how frequently your site is visited and you'll receive also an email notification. * In the sample I'm tryng to run it every 6 hours and not more frequently: the corresponding code for that is (60*60*6), that calculate the number of seconds in 6 hours. * Note that in the DB, 'variable' table, at the record where 'name' = "cron_last", 'value' field contains a string that can be used instead of the timestamp taken fron the text file (first line mktime();). If you prefer you can modify the script... */ ?>