public static function run() { $o = self::getInstance(); $SID = $_COOKIE["SID"]; if (!$SID) { return null; } try { if ($SID && !preg_match("/^[a-z0-9]+\$/", $SID)) { throw new Exception("SID contains incorrect characters"); } $SID = preg_replace("/[^a-z0-9]/", "", $SID); if (!$SID) { throw new Exception("SID is empty"); } if ($rw = DB::f1("select * from users_sessions where sid=:SID", array("SID" => $SID))) { $rw_session = $rw; } else { throw new Exception("Auth session not found"); } $Q = new UsersExec(); $Q->where("id", $rw_session["user_id"]); if ($rw = $Q->f1()) { $user = $rw; $user["rw_session"] = $rw; if ($user["settings"]["rememberme"]) { setcookie("SID", $SID, time() + $o->CONFIG["rememberme_time"], "/", $o->CONFIG["cookie_domain"]); } else { setcookie("SID", $SID, 0, "/", $o->CONFIG["cookie_domain"]); } if ($o->CONFIG["enable_online"]) { $online_file = $o->CONFIG["online_cache_dir"] . "/" . (int) (time() / $o->CONFIG["online_interval"]) % 2 . "/" . $user->id; touch($online_file); } $o->user = $user; return true; } else { throw new Exception("User id=" . $rw_session["user_id"] . " not found"); } } catch (Exception $e) { DEBUG::log("Auth Exception: " . $e->getMessage(), __CLASS__); if ($SID) { DB::q("delete from users_sessions where sid=:SID", array("SID" => $SID)); } $_COOKIE["SID"] = ""; setcookie("SID", "", time() - 86400, "/", $o->CONFIG["cookie_domain"]); } }
private function processComplex($code) { list($output, $openParen, $closeParen) = $this->extractParen($code); DEBUG::log("Next Code : " . $output); $flag = false; $output = $this->execute($output); list($raw_sig, $r) = $this->createRawSignature($output, false); if (isset($this->symbolTable[$raw_sig])) { $newcode = substr($code, 0, $openParen) . "(" . $output . ")" . substr($code, $closeParen + 1, strlen($code)); } else { $newcode = substr($code, 0, $openParen) . $output . substr($code, $closeParen + 1, strlen($code)); } DEBUG::log("Old Code : " . htmlentities($code) . " , New Code : " . htmlentities($newcode)); return $newcode; }
protected function query($query, $opts = null, $connection_id = null) { if (isset($connection_id)) { $db = $this->setupConnection($connection_id); } elseif ($this->current_connection_id == null) { $db = $this->setConnection($this->CONFIG["default_connection_id"]); } else { $db = $this->dbs[$this->current_connection_id]; } if (!isset($db) || !$db instanceof PDO) { throw new Exception(__CLASS__ . "::" . __METHOD__ . ": error while retreiving connection, can't get connection"); } if (class_exists("DEBUG")) { DEBUG::log_start("PDO QUERY"); } $is_insert = 0; if (preg_match("/^insert/i", trim($query))) { $is_insert = 1; } try { if ($is_insert) { $db->beginTransaction(); } if (isset($opts)) { $res = $db->prepare($query); $res->execute($opts); } else { $res = $db->query($query); } if ($is_insert) { $insert_id = $db->lastInsertId(); $db->commit(); } if (class_exists("DEBUG")) { DEBUG::log_end($query . (isset($opts) ? " with opts: " . join(",", $opts) : " without opts"), "PDO", "PDO QUERY"); } if ($is_insert && $insert_id) { return $insert_id; } return $res; } catch (PDOException $e) { if ($is_insert) { $db->rollback(); } $error = "PDOException: " . $e->getMessage() . "\nOccurs in query: " . $query . (isset($opts) ? " with opts: " . join(",", $opts) : " without opts"); if ($this->CONFIG["errformat"] == "html") { $out = "<div style='margin: 10px; border: 1px solid #dedede; padding: 5px; font-size: 0.85em;'>" . str_replace("\n", "<br />", $error) . "</div>"; } else { $out = "<!-- {$error} -->\n"; } if ($this->CONFIG["errformat"] != "none") { echo $out; } if (class_exists("DEBUG")) { DEBUG::log($error, "PDOException"); } } return null; }
public function setSuccess($msg, $autoredirect = 0, $autoredirect_url = null) { $this->CID = "success"; $this->CHDATA[$this->CID]["autoredirect"] = $autoredirect; $this->CHDATA[$this->CID]["autoredirect_url"] = $autoredirect_url; $this->CHDATA[$this->CID]["msg"] = $msg; DEBUG::log("msg=" . $msg, __METHOD__); }
public function __construct($app) { $this->app = $app; $this->CONFIG = $this->app->getCONFIG("channels", $this->app->CID); DEBUG::log("CID=" . $this->app->CID . ", page=" . $this->app->page . ", action=" . $this->app->action, __METHOD__); }