public static function main($argv) { global $coach; list($tid) = $argv; if ($tid) { if (!get_alt_col('teams', 'team_id', $tid, 'name')) { fatal('Invalid team'); } $team = new Team($tid); $ALLOW_EDIT = is_object($coach) && ($team->owned_by_coach_id == $coach->coach_id || $coach->mayManageObj(T_OBJ_TEAM, $tid)) && !$team->is_retired; # Show team action boxes? } else { $team = null; $ALLOW_EDIT = false; } if ($ALLOW_EDIT && isset($_POST['action']) && isset($_POST['pid'])) { $pid = (int) $_POST['pid']; switch ($_POST['action']) { case 'delete': status(self::delete((int) $pid)); break; case 'new': case 'edit': status(self::edit((int) $pid, $_POST['title'], $_POST['about'])); break; } } self::printList($team, $ALLOW_EDIT); return true; }
/** * Constructor */ public function __construct($conf = array()) { // ldap extension is needed if (!function_exists('ldap_connect')) { fatal("To use the LDAP authenticator, you need PHP with LDAP support."); } // Defaults, override in config $default_conf['server'] = ''; $default_conf['port'] = 389; $default_conf['usertree'] = ''; $default_conf['grouptree'] = ''; $default_conf['userfilter'] = '(&(uid=%{user})(objectClass=posixAccount))'; $default_conf['groupfilter'] = '(&(objectClass=posixGroup)(memberUID=%{uid}))'; $default_conf['version'] = 3; $default_conf['starttls'] = 0; $default_conf['referrals'] = 0; $default_conf['deref'] = LDAP_DEREF_NEVER; $default_conf['binddn'] = ''; $default_conf['bindpw'] = ''; $default_conf['userscope'] = 'sub'; $default_conf['groupscope'] = 'sub'; $default_conf['groupkey'] = 'cn'; $default_conf['debug'] = 0; foreach ($conf as $key => $val) { if (array_key_exists($key, $default_conf)) { $default_conf[$key] = $val; } } // Set configuration $this->conf = $default_conf; }
function login_do_http_auth() { global $LOGIN_PASSWORD, $LOGIN_USERNAME; global $_SERVER; if ($_SERVER['REMOTE_USER']) { is_logged_in(true); return; } if (!$_SERVER['PHP_AUTH_USER']) { is_logged_in(false); return; } $status = authenticate($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']); if (!succeeds($status)) { is_logged_in(false); if (!fatal($status)) { if ($_SERVER['PHP_AUTH_USER']) { http_401(); } } else { print "Error logging in: " . auth_error(); } } else { $LOGIN_USERNAME = $_SERVER['PHP_AUTH_USER']; $LOGIN_PASSWORD = $_SERVER['PHP_AUTH_PW']; is_logged_in(true); } }
static function log($category, $message) { require_once THRIFT_ROOT . '/Thrift.php'; require_once THRIFT_ROOT . '/protocol/TBinaryProtocol.php'; require_once THRIFT_ROOT . '/transport/TSocket.php'; require_once THRIFT_ROOT . '/transport/TFramedTransport.php'; require_once THRIFT_ROOT . '/packages/scribe/scribe.php'; switch ($category) { case 'general': case 'accounts': case 'actions': case 'status': case 'security': case 'debug': case 'history': case 'regulation': case 'specials': break; default: fatal(); } if (!is_string($message)) { if (is_array($message)) { if (!isset($message['ts'])) { $message['ts'] = time(); } if (!isset($message['client_ip'])) { $message['client_ip'] = Utils::get_client_ip(); } if (!isset($message['user_id']) && Auth::is_logged()) { $message['user_id'] = Auth::get_user_id(); } if (!isset($message['user_name']) && Auth::is_logged()) { $message['user_name'] = Auth::get_user_name(); } $oauth_client_id = Auth::get_oauth_client_id(); if (!isset($message['oauth_client_id']) && !empty($oauth_client_id)) { $message['oauth_client_id'] = $oauth_client_id; } } $message = json_encode($message); } try { $log_entry = new \LogEntry(array('category' => $category, 'message' => $message)); $messages = array($log_entry); $socket = new \TSocket(SCRIBE_HOST, SCRIBE_PORT, FALSE); $transport = new \TFramedTransport($socket); $protocol = new \TBinaryProtocolAccelerated($transport, FALSE, FALSE); $client = new \scribeClient($protocol, $protocol); $transport->open(); $client->send_log($messages); $transport->close(); } catch (\TException $e) { return FALSE; } return TRUE; }
function main() { $opts = getopt("cath"); if (isset($opts['h']) || !isset($opts['a']) && !isset($opts['t'])) { usage(); } if (isset($opts['a']) && isset($opts['t'])) { fatal("can't use -a and -t together"); } $mode = isset($opts['t']) ? 'tx' : 'address'; if (isset($opts['c'])) { switch ($mode) { case "tx": echo <<<'EOD' DROP TABLE t_shortlinks; CREATE TABLE t_shortlinks ( shortcut bytea NOT NULL PRIMARY KEY, hash bytea NOT NULL REFERENCES transactions ); ALTER TABLE public.t_shortlinks OWNER TO blockupdate; GRANT SELECT ON TABLE t_shortlinks TO "www-data"; EOD; break; case "address": echo <<<'EOD' DROP TABLE a_shortlinks; CREATE TABLE a_shortlinks ( shortcut bytea NOT NULL PRIMARY KEY, hash160 bytea NOT NULL REFERENCES keys ); ALTER TABLE public.a_shortlinks OWNER TO blockupdate; GRANT SELECT ON TABLE a_shortlinks TO "www-data"; EOD; break; } } $fh = fopen("php://stdin", "r"); while ($line = trim(fgets($fh))) { $arr = explode(" ", $line); if ($mode == "tx") { $shortcut_hex = decodeBase58($arr[0]); $tx_hex = $arr[1]; echo "INSERT INTO t_shortlinks(shortcut, hash) VALUES (decode('{$shortcut_hex}', 'hex'), decode('{$tx_hex}', 'hex'));\n"; } elseif ($mode == "address") { $shortcut_hex = decodeBase58($arr[0]); $hash160_hex = addressToHash160($arr[1]); echo "INSERT INTO a_shortlinks(shortcut, hash160) VALUES (decode('{$shortcut_hex}', 'hex'), decode('{$hash160_hex}', 'hex'));\n"; } } }
function queues_set_qnostate($exten, $qnostate) { global $astman; // Update the settings in ASTDB if ($astman) { $astman->database_put("AMPUSER", $exten . "/queues/qnostate", $qnostate); } else { fatal("Cannot connect to Asterisk Manager with " . $amp_conf["AMPMGRUSER"] . "/" . $amp_conf["AMPMGRPASS"]); } }
public function __call($method, $args) { if (!method_exists($this->base, $method)) { fatal('"%s" method does not exist.', $method); } if ($this->base instanceof View\Template) { return call_user_func_array([$this->base, $method], $args); } fatal('Class is not an instance of View\\Template'); }
function load_image($imagekey) { if (1 !== preg_match('/[0-9a-f]{40}/', $imagekey)) { fatal('Invalid image key.'); } $im = imagecreatefrompng("uploads/{$imagekey}.png"); if (!$im) { fatal('Failed to load image.'); } return $im; }
public function get_original_url() { if (!isset($_GET['url'])) { fatal("Proxy URL rewriter error: url GET parameter not found."); } $this->original_url = base64_decode($_GET['url'], TRUE); if (!is_string($this->original_url)) { fatal("Proxy URL rewriter error: url GET parameter is invalidly base64 encoded."); } $this->warnx("URL [{$this->original_url}]"); }
public function __call($method, $args) { if (!isset($args[0])) { if (!isset($this->cache[$method])) { fatal('"%s" is not set.', $method); } return $this->cache[$method]; } $this->cache[$method] = $args[0]; return $this; }
function replaceTextInFile($sFilepath, $dPairs) { $s = file_get_contents($sFilepath); if (!$s) { echo "Could not read file {$sFilepath}"; fatal(__LINE__); } foreach ($dPairs as $sFrom => $sTo) { $s = str_replace($sFrom, $sTo, $s); } file_put_contents($sFilepath, $s); }
function load_conf() { // Load default configuration require_once APP_ROOT . "config_default.php"; if ((include_once APP_ROOT . "config.php") !== 1) { fatal(APP_ROOT . "config.php is missing!<br>\n\tUnfortunately, Munkireport does not work without it</p>"); } // Convert auth_config to config item if (isset($auth_config)) { $conf['auth']['auth_config'] = $auth_config; } $GLOBALS['conf'] =& $conf; }
public function __construct() { global $config; if (!file_exists($this->configFile)) { fatal("Could not open config file"); } $json = file($this->configFile); if (!$json) { fatal("Could not open file: " . $this->configFile); } $config = json_decode($json); if (!$config) { fatal("Could not decode json string" . json_last_error_msg()); } }
/** * Makes everything go. * * @return void */ function init($url) { // process the request URL $manager = new PathManager($url); $route = $manager->build_route(); $instance = $manager->controller_instance($route->controller); if ($instance === FALSE) { fatal("Fatal Error: Cannot find a controller called '{$route->controller}'.", 404); } elseif (method_exists($instance, $route->action) === FALSE) { fatal("Fatal Error: Controller '{$route->controller}' does not respond to action '{$route->action}'.", 404); } $action = $route->action; sys()->getData->add($route->params); $instance->{$action}($route->params); render($route); }
function getdbh() { if (!isset($GLOBALS['dbh'])) { try { $GLOBALS['dbh'] = new PDO(conf('pdo_dsn'), conf('pdo_user'), conf('pdo_pass'), conf('pdo_opts')); } catch (PDOException $e) { fatal('Connection failed: ' . $e->getMessage()); } // Set error mode $GLOBALS['dbh']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // Store database name in config array if (preg_match('/.*dbname=([^;]+)/', conf('pdo_dsn'), $result)) { $GLOBALS['conf']['dbname'] = $result[1]; } } return $GLOBALS['dbh']; }
public static function logViewPage() { global $coach, $lng; if (!is_object($coach) || $coach->ring != Coach::T_RING_GLOBAL_ADMIN) { fatal("Sorry. Only site administrators and commissioners are allowed to access this section."); } title($lng->getTrn('name', 'LogSubSys')); echo "<table style='width:100%;'>\n"; echo "<tr><td><i>Date</i></td><td><i>Message</i></td></tr><tr><td colspan='2'><hr></td></tr>\n"; $query = "SELECT * FROM log WHERE date > SUBDATE(NOW(), INTERVAL " . LOG_HIST_LENGTH . " MONTH) ORDER BY date DESC"; $result = mysql_query($query); $logs = array(); while ($l = mysql_fetch_object($result)) { echo "<tr><td>" . textdate($l->date) . "</td><td>{$l->msg}</td></tr>\n"; } echo "</table>\n"; }
function sec_admin() { global $rules, $settings, $DEA, $coach, $lng, $admin_menu; global $leagues, $divisions, $tours; if (!is_object($coach)) { fatal('Please login.'); } if (!isset($_GET['subsec'])) { $_GET['subsec'] = '_NONE_'; } $IS_GLOBAL_ADMIN = $coach->ring == Coach::T_RING_GLOBAL_ADMIN; $ONLY_FOR_GLOBAL_ADMIN = "Note: This feature may only be used by <i>global</i> administrators."; # Used string in a few common feature/action boxes. // Deny un-authorized users. if (!in_array($_GET['subsec'], array_keys($admin_menu))) { fatal("Sorry. Your access level does not allow you opening the requested page."); } switch ($_GET['subsec']) { case 'usr_man': include 'admin/admin_usr_man.php'; break; case 'ct_man': include 'admin/admin_ct_man.php'; break; case 'nodes': include 'admin/admin_nodes.php'; break; case 'schedule': include 'admin/admin_schedule.php'; break; case 'import': include 'admin/admin_import.php'; break; case 'log': Module::run('LogSubSys', array('logViewPage')); break; case 'cpanel': include 'admin/admin_cpanel.php'; break; default: fatal('The requested admin page does not exist.'); } echo "<br><br>"; HTMLOUT::dnt(); }
public function getTrn($key, $doc = false) { if (!$doc) { $doc = self::main; } if (!in_array($doc, array_keys($this->docs))) { fatal("Failed to look up key '{$key}' in the translation document '{$doc}'. {$doc} is not loaded/exists. The available documents are: " . implode(', ', array_keys($this->docs))); } $xpath = new DOMXpath($this->docs[$doc]); $query = $xpath->query("//{$this->lang}/{$key}"); if ($query->length == 0) { # Try fallback language $query = $xpath->query("//" . self::fallback . "/{$key}"); if ($query->length == 0) { return (string) "TRANSLATION ERR ! {$key}"; } } return (string) $query->item(0)->nodeValue; }
/** * \brief Get the top-of-tree folder_pk for the current user. * Fail if there is no user session. * * \return folder_pk for the current user */ function GetUserRootFolder() { global $PG_CONN; /* validate inputs */ $user_pk = Auth::getUserId(); /* everyone has a user_pk, even if not logged in. But verify. */ if (empty($user_pk)) { return "__FILE__:__LINE__ GetUserRootFolder(Not logged in)<br>"; } /* Get users root folder */ $sql = "select root_folder_fk from users where user_pk={$user_pk}"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); $UsersRow = pg_fetch_assoc($result); $root_folder_fk = $UsersRow['root_folder_fk']; pg_free_result($result); if (empty($root_folder_fk)) { $text = _("Missing root_folder_fk for user "); fatal("<h2>" . $text . $user_pk . "</h2>", __FILE__, __LINE__); } return $root_folder_fk; }
public static function main($argv) # argv = argument vector (array). { /* Let $argv[0] be the name of the function we wish main() to call. Let the remaining contents of $argv be the arguments of that function, in the correct order. Please note only static functions are callable through main(). */ global $coach; $IS_LOCAL_OR_GLOBAL_ADMIN = (isset($coach) && ($coach->ring == Coach::T_RING_GLOBAL_ADMIN || $coach->ring == Coach::T_RING_LOCAL_ADMIN)); // Deny un-authorized users. if (!$IS_LOCAL_OR_GLOBAL_ADMIN) fatal("Sorry. Your access level does not allow you opening the requested page."); ?> <div class="module_schedule"> <? self::inlineCSS(); $step = 1; if (isset($_GET['step'])) { $step = $_GET['step']; } if (isset($_POST['step'])) { $step = $_POST['step']; } switch ($step) { case '2': self::step2(); break; default: self::step1(); break; } ?> </div> <? return true; }
public static function profile($pid) { if ($pid < 0) { fatal('Sorry, star players to do have regular player profiles.'); } global $lng, $coach, $settings; $p = new self($pid); $team = new Team($p->owned_by_team_id); /* Argument(s) passed to generating functions. */ $ALLOW_EDIT = is_object($coach) && ($team->owned_by_coach_id == $coach->coach_id || $coach->isNodeCommish(T_NODE_LEAGUE, $team->f_lid)) && !$team->is_retired; /* Player pages consist of the output of these generating functions. */ $p->_handleActions($ALLOW_EDIT); # Handles any actions/request sent. $p->_head($team); $p->_about($ALLOW_EDIT); $p->_achievements(); $p->_matchBest(); $p->_recentGames(); $p->_injuryHistory(); if (!$settings['hide_ES_extensions']) { $p->_ES(); } }
/** * Sends an HTTP POST request * * @param string $host Host address * @param string $port Port number * @param string $path Request path * @param string $header Request header * @param string $body Request body * @return Answer of remote host */ function send_http_post($host, $port, $path, $header, $body) { # Open the connection using Internet socket connection $fp = @fsockopen($host, $port, $errno, $errstr); if (!$fp) { fatal("<p>Unable to establish connection to <tt>{$host}</tt> " . "(port <tt>{$port}</tt>):</p><pre>{$errstr}</pre>"); } # Send HTTP message headers fwrite($fp, "POST {$path} HTTP/1.0\r\n"); fwrite($fp, $header); fwrite($fp, "\r\n"); # Send HTTP message body fwrite($fp, $body); # Read response from the server $buf = ''; $length = false; while (!feof($fp)) { $buf .= fread($fp, 8192); # Parse the HTTP answer $answer = parse_answer($buf); # Find out about content length if (!$length) { if ($answer[0] == 200) { $length = $answer[1]['content-length']; } } # Was response fully transmitted or not if ($length) { if (strlen($buf) == strlen($answer[3]) + $length) { break; } } } fclose($fp); return $answer; }
fatal("You must setup properly AMPDBFILE in {$amportalconf}"); } if (isset($amp_conf["AMPDBFILE"]) == "") { fatal("AMPDBFILE in {$amportalconf} cannot be blank"); } require_once 'DB/sqlite3.php'; $datasource = "sqlite3:///" . $amp_conf["AMPDBFILE"] . "?mode=0666"; $db = DB::connect($datasource); break; default: fatal("Unknown SQL engine: [{$db_engine}]"); } if (DB::isError($db)) { out(_("FAILED")); debug($db->userinfo); fatal(_("database connection failure"), "failed trying to connect to the configured database"); } out(_("OK")); // Check to see if email should be sent // $cm =& cronmanager::create($db); $cm->run_jobs(); $email = $cm->get_email(); if ($email) { $text = ""; // clear email flag $nt->delete('freepbx', 'NOEMAIL'); // set to false, if no updates are needed then it will not be // set to true and no email will go out even though the hash // may have changed. //
} } if (empty($SQL)) { fatal("Ошибка вывода в таблицу"); } // Выходные данные в базу данных // Уничтожение таблицы if (isset($db_drop)) { $drop_tbl_SQL = "DROP TABLE IF EXISTS {$db_table}"; if (!mysql_query($drop_tbl_SQL)) { fatal("Ошибка при удалении таблицы"); } } //Создание таблицы if (!mysql_query($tbl_SQL)) { fatal("Ошибка при создании таблицы"); } $sql_pref = "INSERT INTO " . $db_table . " SET "; $err = ""; $nmb = 0; // число вставленных строк foreach ($SQL as $sql) { $sql = $sql_pref . $sql; if (!mysql_query($sql)) { $err .= "<b>SQL ошибка в</b> :<br>{$sql} <br>"; } else { $nmb++; } } if (empty($err)) { echo <<<SUCC
<?php include 'common.php'; if (isset($_POST['submit']) && isset($_POST['width']) && isset($_POST['height'])) { $width = (int) $_POST['width']; $height = (int) $_POST['height']; if ($width <= 0 || $width > MAX_IM_SIZE) { fatal('Invalid width'); } else { if ($height <= 0 || $height > MAX_IM_SIZE) { fatal('Invalid height'); } } $im = imagecreatetruecolor($width, $height); if (!$im) { fatal('Failed to create image.'); } $bgcolor = imagecolorallocate($im, 255, 255, 255); imagefill($im, 0, 0, $bgcolor); imagetruecolortopalette($im, false, 256); imagesavealpha($im, false); $imagekey = create_image_key(); save_image($im, $imagekey); imagedestroy($im); header("Location: ?op=edit&imagekey={$imagekey}"); } else { ?> <div class="article"> <h2>Create your new pixel art!</h2> <form action="?op=new" method="POST"> <label for="width">Image width (max <?php
$body .= "<input type='hidden' name='delete' value='2' />\n"; $body .= sprintf("<input type='hidden' name='tid' value='%d' />\n", $arg_tid); $body .= sprintf("<input type='hidden'" . " name='split_id' value='%d' />\n", $arg_split_id); $body .= "Confirm? <input type='submit' value='delete' />\n"; $body .= "</form>\n"; pfinish(); } if ($arg_delete == 2) { query("delete from splits where split_id = ?", $arg_split_id); flash("deleted"); $t = sprintf("trans.php?tid=%d", $arg_tid); redirect($t); } $q = query("select acct_id, trans_id, ref, name, memo, amount," . " to_char (posted, 'YYYY-MM-DD') as posted," . " trans_type" . " from raw_trans" . " where tid = ?", $arg_tid); if (($r = fetch($q)) == NULL) { fatal("invalid tid"); } $db_acct_id = trim($r->acct_id); $db_trans_id = trim($r->trans_id); $db_ref = trim($r->ref); $db_name = trim($r->name); $db_memo = trim($r->memo); $db_total_amount = 0 + $r->amount; $db_posted = trim($r->posted); $db_trans_type = trim($r->trans_type); $q = query("select name2" . " from trans" . " where tid = ?", $arg_tid); if (($r = fetch($q)) != NULL) { $db_name2 = trim($r->name2); } else { $db_name2 = ""; }
print "<p><b>Insert data into the database.... </b><p>"; if( count( $items ) == 0 ) fatal('No data to import into the MySQL table.'); else { // // Connect to the database if( !( $link = mysql_connect("localhost", "root", "") ) ) fatal("Could not connect to local MySQL server."); if( !mysql_select_db( "phpbit", $link ) )//是否打开数据库连接 { mysql_close( $link ); fatal("Could not select database <b>phpbit</b>."); } // // Prepare query //$comma = ''; //$query = "INSERT INTO student ( sid, password, name ) VALUES "; foreach( $items as $item ) { $sid = addslashes( $item['sid'] ); $password = addslashes( $item['password'] ); $name = addslashes( $item['name'] );
foreach (explode('</OBJECT>', $document) as $page) { $pagenumber++; if (matches_terms($page, $terms) && strstr($page, '<OBJECT ')) { // extract the page value so that we know what page we are on, // Brad Neuberg, bkn3@columbia.edu if (!preg_match('|<PARAM name="PAGE" value="([^"]*)"\\s*\\/>|', $page, $match)) { fatal("page value not set on page number {$pagenumber} in {$page}!"); } $pageFile = $match[1]; // extract the page width and height, Brad Neuberg, bkn3@columbia.edu if (!preg_match('/width="([^"]*)"/', $page, $match)) { fatal("page width not set!"); } $pageWidth = $match[1]; if (!preg_match('/height="([^"]*)"/', $page, $match)) { fatal("page height not set!"); } $pageHeight = $match[1]; $page_new = ''; foreach (explode('</WORD>', $page) as $token) { if (matches_terms($token, $terms)) { list($junk, $keep) = explode('<WORD ', $token); $token = " {$tag_pre}<WORD {$keep}</WORD>{$tag_post} "; } else { $token = preg_replace('/<[^<]*>/', '', $token); //mark-up $token = preg_replace('/[\\&\\#\\d+;]/', ' ', $token); //non-ascii chars $token = preg_replace('/\\s+/', ' ', $token); //white space }
function error2() { fatal('Fake error!', 501); }
function die_freepbx($text, $extended_text = "", $type = "FATAL") { $trace = print_r(debug_backtrace(), true); if (function_exists('fatal')) { // "custom" error handler // fatal may only take one param, so we suppress error messages because it doesn't really matter @fatal($text . "\n" . $trace, $extended_text, $type); } else { if (isset($_SERVER['REQUEST_METHOD'])) { // running in webserver echo "<h1>" . $type . " ERROR</h1>\n"; echo "<h3>" . $text . "</h3>\n"; if (!empty($extended_text)) { echo "<p>" . $extended_text . "</p>\n"; } echo "<h4>" . _("Trace Back") . "</h4>"; echo "<pre>{$trace}</pre>"; } else { // CLI echo "[{$type}] " . $text . " " . $extended_text . "\n"; echo "Trace Back:\n"; echo $trace; } } // always ensure we exit at this point exit(1); }