function session_auth() { if (array_key_exists("testid", $_REQUEST)) { return $_REQUEST["testid"]; } $uri = $_SERVER["REQUEST_URI"]; $session_id = $_REQUEST["session_id"]; $session_key = $_REQUEST["session_key"]; $pos = strpos($uri, "session_id="); if ($pos > 0) { $urix = substr($uri, 0, $pos) . substr($uri, $pos + 12 + strlen($session_id), strlen($uri)); $uri = $urix; } if ($pos < 1) { $result = array("error_code" => "403.1", "error_desc" => "SESSION ID is missing."); echo json_encode($result); exit(0); } $pos = strpos($uri, "session_key="); if ($pos > 0) { $urix = substr($uri, 0, $pos) . substr($uri, $pos + 13 + strlen($session_key), strlen($uri)); $uri = $urix; } if ($pos < 1) { $result = array("error_code" => "403.2", "error_desc" => "SESSION KEY is missing."); echo json_encode($result); exit(0); } if (substr($uri, strlen($uri) - 1, 1) == "&" || substr($uri, strlen($uri) - 1, 1) == "?") { $uri = substr($uri, 0, strlen($uri) - 1); } $es = load_ext_model("Mobile_sessions"); $sess = $es->get_session($session_id); if (!$sess) { $result = array("error_code" => "403.3", "error_desc" => "Expired session."); echo json_encode($result); exit(0); } $auth_value = sha256($uri . $sess["session_key"]); if ($session_key != $auth_value) { $result = array("error_code" => "403.4", "error_desc" => "Invalid SESSION KEY."); echo json_encode($result); exit(0); } if (array_key_exists("session_expire_expand", $_GET)) { $exp_date = $_GET["session_expire_expand"]; $es->extend($session_id, $exp_date); } return $sess["id_users"]; }
<?php class EXT_Tf_image_sync_model extends Model { var $tablename = "tf_image_sync"; function add($_url) { $c = new Query(); $c->value("url", $_url); $c->value("date_created", "now()", true); $this->insert($c); } function add_error($_id) { $c = new Query(); $c->where_eq('id', $_id); $c->value('error_cnt', 'error_cnt+1', true); $this->update($c); } } $log_tis = new EXT_Tf_image_sync_model($trail->_settings); load_ext_model("Tf_image_sync", $log_tis);
$c->group = "url"; $c->order = "count desc"; return $this->fetch("sum(count) count, url", $c); } } $log_ref = new EXT_Log_ref_model($settings); load_ext_model("Log_ref", $log_uv); class EXT_Log_pageview_model extends Model { var $tablename = "log_pageview"; function update_pageview($_url) { $q = new Query(); $dat = date("Y-m-d", time()); $q->where("url = '{$_url}'"); $q->where("date8 = '{$dat}'"); if ($this->counts($q)) { $q->value("count", "count+1", 1); $this->update($q); } else { $q = new Query(); $q->value("url", $_url); $q->value("count", "1"); $q->value("date8", $dat); $this->insert($q); } } } $log_pageview = new EXT_Log_pageview_model($settings); load_ext_model("Log_pageview", $log_pageview);
if ($this->fetch_one("id_user", $c)) { return new_confirm_key(); } $c = new Query(); $c->value("id_user", $id); $c->value("expires", "date_add(now(), interval 1 hour)", 1); $c->value("session_key", $ret); $this->insert($c); $c = new Query(); $c->where("id_user = "******"session_key = '" . $ret . "'"); return $this->fetch_one("id, id_user, session_key, unix_timestamp(expires) expires", $c); } function get_session($id) { $c = new Query(); $c->where("id = " . $id); $c->where("expires > now()"); return $this->fetch_one("id_user, session_key, unix_timestamp(expires) expires", $c); } function extend($id, $dat) { $c = new Query(); $c->where("id = " . $id); $c->value("expires", $dat); $this->update($c); } } $log_es = new EXT_Mobile_sessions_model($settings); load_ext_model("Mobile_sessions", $log_es);