'Opn', 'Bogus' => 'Bgs', 'Feedback' => 'Fbk', 'No Feedback' => 'NoF', 'Wont fix' => 'Wfx', 'Duplicate' => 'Dup', 'Critical' => 'Ctl', 'Assigned' => 'Asn', 'Analyzed' => 'Ana', 'Verified' => 'Ver', 'Suspended' => 'Sus', 'Closed' => 'Csd', 'Spam' => 'Spm', 'Re-Opened' => 'ReO', 'To be documented' => 'Tbd', ); $bug_types = array( 'Bug' => 'Bug', 'Feature/Change Request' => 'Req', 'Documentation Problem' => 'Doc', ); // Used in show_state_options() $state_types = array ( 'Open' => 2, 'Closed' => 2, 'Re-Opened' => 1, 'Duplicate' => 1, 'Critical' => 1, 'Assigned' => 1, 'Not Assigned' => 0, 'Analyzed' => 1, 'Verified' => 1, 'Suspended' => 1, 'Wont fix' => 1, 'No Feedback' => 1, 'Feedback' => 1, 'Old Feedback' => 0, 'Stale' => 0, 'Fresh' => 0, 'Bogus' => 1, 'To be documented' => 1, 'Spam' => 1, 'All' => 0, ); /** * Authentication */ function verify_password($user, $pass) { global $errors; $post = http_build_query( array( 'token' => getenv('AUTH_TOKEN'), 'username' => $user, 'password' => $pass, ) ); $opts = array( 'method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => $post, ); $ctx = stream_context_create(array('http' => $opts)); $s = file_get_contents('https://master.php.net/fetch/cvsauth.php', false, $ctx); $a = @unserialize($s); if (!is_array($a)) { $errors[] = "Failed to get authentication information.\nMaybe master is down?\n"; return false; } if (isset($a['errno'])) { $errors[] = "Authentication failed: {$a['errstr']}\n"; return false; } return true; } function bugs_authenticate (&$user, &$pw, &$logged_in, &$is_trusted_developer) { global $auth_user, $ROOT_DIR; // Default values $user = ''; $pw = ''; $logged_in = false; $is_trusted_developer = false; // Set username and password if (!empty($_POST['pw'])) { if (empty($_POST['user'])) { $user = ''; } else { $user = htmlspecialchars($_POST['user']); } $pw = $_POST['pw']; // Remember password / user next time if (isset($_POST['save'])) { # non-developers don't have $user set if (DEVBOX) { $domain = null; } else { $domain = '.php.net'; } setcookie('MAGIC_COOKIE', base64_encode("{$user}:{$pw}"), time() + 3600 * 24 * 12, '/', $domain); } } elseif (isset($auth_user) && is_object($auth_user) && $auth_user->handle) { $user = $auth_user->handle; $pw = $auth_user->password; } elseif (isset($_COOKIE['MAGIC_COOKIE'])) { @list($user, $pw) = explode(':', base64_decode($_COOKIE['MAGIC_COOKIE']), 2); if ($pw === null) { $pw = ''; } } // Authentication and user level check // User levels are: reader (0), commenter/patcher/etc. (edit = 3), submitter (edit = 2), developer (edit = 1) if ($user != '' && $pw != '' && verify_password($user, $pw)) { $logged_in = 'developer'; $auth_user->handle = $user; $auth_user->email = "{$user}@php.net"; $auth_user->name = $user; } else { $auth_user->email = isset($_POST['in']['email']) ? $_POST['in']['email'] : ''; $auth_user->handle = ''; $auth_user->name = ''; } // Check if developer is trusted if ($logged_in == 'developer') { require_once "{$ROOT_DIR}/include/trusted-devs.php"; $is_trusted_developer = in_array($user, $trusted_developers); } } /** * Fetches pseudo packages from database * * @param string $project define what project pseudo packages are returned * @param bool $return_disabled whether to return read-only items, defaults to true * * @return array array of pseudo packages */ function get_pseudo_packages ($project, $return_disabled = true) { require_once 'Tree/Tree.php'; $where = "project IN ('', '$project')"; if (!$return_disabled) $where.= " AND disabled = 0"; $pseudo_pkgs = array(); $tree = Tree::setup ( 'Memory_MDB2simple', DATABASE_DSN, array ( 'order' => 'id', 'whereAddOn' => $where, 'table' => 'bugdb_pseudo_packages', 'columnNameMaps' => array ( 'parentId' => 'parent', ), ) ); $tree->setup(); foreach ($tree->data as $data) { if (isset($data['children'])) { $pseudo_pkgs[$data['name']] = array($data['long_name'], $data['disabled']); foreach ($data['children'] as $child) { $pseudo_pkgs[$child['name']] = array("    {$child['long_name']}", $child['disabled']); } } else if (!isset($pseudo_pkgs[$data['name']])) $pseudo_pkgs[$data['name']] = array($data['long_name'], $data['disabled']); } return $pseudo_pkgs; } /* Primitive check for SPAM. Add more later. */ function is_spam($string) { if (substr_count(strtolower($string), 'http://') > 5) { return true; } if (preg_match("/(asian)|(spy)|(bdsm)|(massage)|(mortage)|(sex)|(11nong)|(oxycontin)|(distance-education)|(sismatech)|(justiceplan)|(prednisolone)|(baclofen)|(diflucan)|(unbra.se)|(objectis)/i", $string)) { return true; } if (preg_match("~/Members/~", $string)) { return true; } return false; } /** * Obfuscates email addresses to hinder spammer's spiders * * Turns "@" into character entities that get interpreted as "at" and * turns "." into character entities that get interpreted as "dot". * * @param string $txt the email address to be obfuscated * @param string $format how the output will be displayed ('html', 'text') * * @return string the altered email address */ function spam_protect($txt, $format = 'html') { /* php.net addresses are not protected! */ if (preg_match('/^(.+)@php\.net/i', $txt)) { return $txt; } if ($format == 'html') { $translate = array( '@' => ' at ', '.' => ' dot ', ); } else { $translate = array( '@' => ' at ', '.' => ' dot ', ); } return strtr($txt, $translate); } /** * Escape strings so they can be used as literals in queries * * @param string|array $in data to be sanitized. If it's an array, each element is sanitized. * * @return string|array the sanitized data * * @see oneof(), field(), txfield() */ function escapeSQL($in) { global $dbh; if (is_array($in)) { $out = array(); foreach ($in as $key => $value) { $out[$key] = $dbh->escape($value); } return $out; } else { return $dbh->escape($in); } } /** * Goes through each variable submitted and returns the value * from the first variable which has a non-empty value * * Handy function for when you're dealing with user input or a default. * * @param mixed as many variables as you wish to check * * @return mixed the value, if any * * @see escapeSQL(), field(), txfield() */ function oneof() { foreach (func_get_args() as $arg) { if ($arg) { return $arg; } } } /** * Returns the data from the field requested and sanitizes * it for use as HTML * * If the data from a form submission exists, that is used. * But if that's not there, the info is obtained from the database. * * @param string $n the name of the field to be looked for * * @return mixed the data requested * * @see escapeSQL(), oneof(), txfield() */ function field($n) { return oneof(isset($_POST['in']) ? htmlspecialchars($_POST['in'][$n]) : null, htmlspecialchars($GLOBALS['bug'][$n])); } /** * Escape string so it can be used as HTML * * @param string $in the string to be sanitized * * @return string the sanitized string * * @see txfield() */ function clean($in) { return htmlspecialchars($in, ENT_QUOTES, 'UTF-8', false); } /** * Returns the data from the field requested and sanitizes * it for use as plain text * * If the data from a form submission exists, that is used. * But if that's not there, the info is obtained from the database. * * @param string $n the name of the field to be looked for * * @return mixed the data requested * * @see clean() */ function txfield($n, $bug = null, $in = null) { $one = (isset($in) && isset($in[$n])) ? $in[$n] : false; if ($one) { return $one; } $two = (isset($bug) && isset($bug[$n])) ? $bug[$n] : false; if ($two) { return $two; } } /** * Prints age \n"; } echo '\n"; } /** * Prints bug type ' . "\n"; } foreach ($RESOLVE_REASONS as $val) { if (empty($val['package_name'])) { $sel = ($current == $val['name']) ? " selected='selected'" : ''; echo "\n"; } } } /** * Prints PHP version number \n"; } elseif (!$current && $show_any == 1) { $current = 'Any'; } elseif (!$current) { $current = $default; } if (!is_array($bug_items)) return; foreach ($bug_items as $key => $value) { if ($show_any == 1 || $key != 'Any') { echo "\n"; if ($key == $current) { $use++; } } } } /** * Prints a series of radio inputs to determine how the search * term should be looked for * * @param string $current the users present selection * * @return void */ function show_boolean_options($current) { $options = array('any', 'all', 'raw'); while (list($val, $type) = each($options)) { echo '$type \n"; } } /** * Display errors or warnings as a