function formSubmit($_POST) { $formSubmit = array(); $url = $_POST['url']; $ticket = $_POST['ticket']; $ticket = strtolower($ticket); $ticket = ltrim($ticket, 'inc0'); $notes = htmlentities($_POST['notes'], ENT_QUOTES); $db = new SQLite3('./urls/urls.db'); $result = $db->query('SELECT * FROM urls WHERE url = "' . $url . '"'); $arrayDump = $result->fetchArray(); if (!isset($arrayDump['id'])) { $formSubmit['old'] = FALSE; $formSubmit['url'] = $url; $formSubmit['notes'] = $notes; $formSubmit['ticket'] = $ticket; $time = time(); $url = $db->escapeString($url); $notes = $db->escapeString($notes); $ticket = $db->escapeString($ticket); $time = $db->escapeString($time); $subip = $db->escapeString($_SERVER['REMOTE_ADDR']); $command = 'INSERT INTO urls (notes, ticket, url, time, ip) VALUES ("' . $notes . '","' . $ticket . '","' . $url . '","' . $time . '","' . $subip . '")'; $query = $db->exec($command); } else { $formSubmit['ticket'] = $arrayDump['ticket']; $formSubmit['notes'] = $arrayDump['notes']; $formSubmit['url'] = $arrayDump['url']; $formSubmit['old'] = TRUE; } return $formSubmit; }
/** * Cleans entries from journal. * @param array $conditions * @return array of removed items or NULL when performing a full cleanup */ public function clean(array $conditions) { if (!empty($conditions[Cache::ALL])) { $this->database->exec('DELETE FROM CACHE;'); return; } $query = array(); if (!empty($conditions[Cache::TAGS])) { $tags = array(); foreach ((array) $conditions[Cache::TAGS] as $tag) { $tags[] = "'" . $this->database->escapeString($tag) . "'"; } $query[] = 'tag IN(' . implode(', ', $tags) . ')'; } if (isset($conditions[Cache::PRIORITY])) { $query[] = 'priority <= ' . (int) $conditions[Cache::PRIORITY]; } $entries = array(); if (!empty($query)) { $query = implode(' OR ', $query); $result = $this->database->query("SELECT entry FROM cache WHERE {$query}"); if ($result instanceof SQLiteResult) { while ($entry = $result->fetchSingle()) { $entries[] = $entry; } } else { while ($entry = $result->fetchArray(SQLITE3_NUM)) { $entries[] = $entry[0]; } } $this->database->exec("DELETE FROM cache WHERE {$query}"); } return $entries; }
/** * {@inheritdoc} */ public function quote($input, $type = \PDO::PARAM_STR) { if (is_int($input) || is_float($input)) { return $input; } return "'" . $this->_conn->escapeString($input) . "'"; }
public function quote($string) { if (!$this->connected) { $this->connect(); } return $this->dbHandle->escapeString($string); }
function acctstart($input) { require_once "settings.php"; $input = $input; $delimiter1 = "The new session"; $delimiter2 = "has been created"; $pos1 = strpos($input, $delimiter1) + strlen($delimiter1) + 2; $pos2 = strpos($input, $delimiter2) - 2; $sstrlen = $pos2 - $pos1; $sessid = substr($input, $pos1, $sstrlen); exec($vpncmd . " " . $softetherip . " /SERVER /HUB:" . $hubname . " /PASSWORD:"******" /CSV /CMD SessionGet " . $sessid, $SessionGet); if (strpos($SessionGet[0], "rror occurred") != FALSE) { die("Error - SessionGet resulted in error"); } foreach ($SessionGet as $line) { list($key, $val) = explode(",", $line, 2); $result[$key] = $val; } $recheck = 0; dhcptest: sleep(2); exec($vpncmd . " " . $softetherip . " /SERVER /HUB:" . $hubname . " /PASSWORD:"******" /CSV /CMD IpTable", $IpTable); $ok = 0; foreach ($IpTable as $line) { if (strpos($line, $sessid)) { if (strpos($line, "DHCP")) { list(, $key, $val) = explode(",", $line); list($framedip) = explode(" ", $val); #$result2[$key] = $val; $ok = 1; } } } if ($ok == 0) { if ($recheck == 4) { die("Error - could not find session in retrived IpTable data"); } sleep(2); $recheck = $recheck + 1; goto dhcptest; } $db = new SQLite3($database); $db->exec('CREATE TABLE IF NOT EXISTS sessions (sessionid varchar(255), username varchar (255), clientip varchar (255), inputoctets varchar (255), ' . 'outputoctets varchar (255), framedip varchar (255), nasip varchar (255), nasport varchar (255), acctstarttime varchar (255), ' . 'acctsessiontime varchar (255), PRIMARY KEY(sessionid))'); $query = $db->escapeString('INSERT OR REPLACE INTO sessions (sessionid, username, clientip, inputoctets, outputoctets, framedip, nasip, nasport, acctstarttime, acctsessiontime) VALUES ("' . $sessid . '","' . $result["User Name (Authentication)"] . '","' . $result["Client IP Address"] . '",NULL,NULL,"' . $framedip . '","' . $result["Server IP Address (Reported)"] . '","' . $result["Server Port (Reported)"] . '","' . $result["Connection Started at"] . '",NULL)'); $db->exec($query); $sessid = $db->escapeString($sessid); $results = $db->querySingle("SELECT * FROM sessions WHERE sessionid = '" . $sessid . "'", true); $tmpfname = tempnam($tmpdir, "acctstarttmp_"); $handle = fopen($tmpfname, "w"); $packet = "Service-Type = Framed-User" . "\n" . "Framed-Protocol = PPP" . "\n" . "NAS-Port = " . $results['nasport'] . "\n" . "NAS-Port-Type = Async" . "\n" . "User-Name = '" . $results['username'] . "'" . "\n" . "Calling-Station-Id = '" . $results['clientip'] . "'" . "\n" . "Called-Station-Id = '" . $results['nasip'] . "'" . "\n" . "Acct-Session-Id = '" . $sessid . "'" . "\n" . "Framed-IP-Address = " . $results['framedip'] . "\n" . "Acct-Authentic = RADIUS" . "\n" . "Event-Timestamp = " . time() . "\n" . "Acct-Status-Type = Start" . "\n" . "NAS-Identifier = '" . $results['nasip'] . "'" . "\n" . "Acct-Delay-Time = 0" . "\n" . "NAS-IP-Address = " . $results['nasip'] . "\n"; fwrite($handle, $packet); fclose($handle); exec("radclient " . $radiussrv . ":" . $radiusport . " acct " . $radiuspass . " -f " . $tmpfname); unlink($tmpfname); $db->close(); }
public function getStats($playerName) { $playerName = $this->db->escapeString(trim(strtolower($playerName))); $result = $this->db->query("SELECT * FROM tntstats WHERE name = '" . $playerName . "'"); if ($result instanceof \SQLiteResult) { $assoc = $result->fetch(SQLITE_ASSOC); if (isset($assoc["name"]) and $assoc["name"] === $playerName) { return $assoc; } } return null; }
/** * Checks which files of a directory are missing in a SQLite3 database and returns a list of them. * * @arg dir The directory for which to check * @arg dbfile The file containing the database * @arg table The table name of the database * @arg col The column containing the filenames * @arg enckey The encryption key used for the database * @returns A list of files missing from the database, or an empty list */ function missing_files_from_directory($dir, $dbfile, $table, $col, $enckey = NULL) { $missing = array(); $dirscan = scandir($dir, SCANDIR_SORT_ASCENDING); if ($dirscan == false) { // Either $dir is not a directory or scandir had no success return $missing; } try { if (is_string($enckey)) { $db = new SQLite3($dbfile, SQLITE3_OPEN_READONLY, $enckey); } else { $db = new SQLite3($dbfile, SQLITE3_OPEN_READONLY); } } catch (Exception $e) { // Database could not be opened; return empty array return $missing; } foreach ($dirscan as $file) { if (is_dir($file) || is_link($file)) { // Filtering out directories (. and ..) and links { continue; } if ($db->querySingle("SELECT EXISTS(SELECT * FROM " . $table . " WHERE " . $col . " = '" . SQLite3::escapeString($file) . "');")) { // if an entry exists, returns TRUE, otherwise FALSE; invalid or failing queries return FALSE continue; } // entry does not exist; add to array $missing[] = $file; } $db->close(); sort($missing, SORT_LOCALE_STRING | SORT_FLAG_CASE); return $missing; // sort based on the locale, case-insensitive }
function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return SQLite3::escapeString($data); }
function writeEvent($timestamp, $device, $latitude, $longitude, $message) { $this->checkValues($timestamp, $device, $latitude, $longitude, $message); $this->open(); $query = "INSERT INTO " . AzimutDatabase::TABLE_EVENTS . "('" . AzimutDatabase::FIELD_TIMESTAMP . "', '" . AzimutDatabase::FIELD_DEVICE . "', '" . AzimutDatabase::FIELD_LATITUDE . "', '" . AzimutDatabase::FIELD_LONGITUDE . "', '" . AzimutDatabase::FIELD_MESSAGE . "') " . "VALUES(" . $timestamp . ", '" . SQLite3::escapeString($device) . "', " . $latitude . ", " . $longitude . ", '" . SQLite3::escapeString($message) . "')"; return $this->database->exec($query); }
/** * Cleanup cache * * Check if the current cache size exceeds the given requested cache size. * If this is the case purge all cache items from the cache until the cache * is only filled up to $rate percentage. * * @param int $size * @param flaot $rate * @return void */ public function cleanup($size, $rate) { // Check if overall cache size exceeds cache limit $result = $this->db->query('SELECT SUM( size ) as size FROM metadata'); $cacheSize = $result->fetchArray(SQLITE3_NUM); $cacheSize = $cacheSize[0]; $result->finalize(); if ($cacheSize <= $size) { // Cache size does not exceed cache value, so we can exit // immediately. return false; } // Otherwise clear cache values, until we pass the lower size border $maxSize = $size * $rate; $result = $this->db->query('SELECT path, size FROM metadata ORDER BY accessed ASC'); $removed = array(); do { $row = $result->fetchArray(SQLITE3_ASSOC); $cacheSize -= $row['size']; unlink($this->root . ($removed[] = $row['path'])); } while ($cacheSize > $maxSize); $result->finalize(); // Remove entries from database foreach ($removed as $nr => $value) { $removed[$nr] = "'" . $this->db->escapeString($value) . "'"; } $this->db->query('DELETE FROM metadata WHERE path IN ( ' . implode(', ', $removed) . ' )'); }
public function upsert($target, $filename, $content) { if ($this->noop) { return; } $hash = $this->calculateHash($content); $this->db->exec('REPLACE INTO cache VALUES ("' . SQLite3::escapeString($target) . '","' . SQLite3::escapeString($filename) . '", "' . SQLite3::escapeString($hash) . '")'); }
function gvar($ar) { if (isset($_POST[$ar]) && $_POST[$ar] !== '') { return "'" . SQLite3::escapeString($_POST[$ar]) . "'"; } else { return 'NULL'; } }
/** * Run a query on the database; * @param string $query * @return boolean TRUE on success */ public function query($query) { $sqlite = new SQLite3($this->path); // escape query $query = $sqlite->escapeString($query); // run it and return result return $sqlite->query($query); }
function get_credentials($user_id) { $db = init_db(); $user_id = SQLite3::escapeString(strip_tags($user_id)); $query = $db->query("select * from credentials where userid = '{$user_id}'"); $row = $query->fetchArray(SQLITE3_ASSOC); return $row['credentials']; }
function clearData($data) { $data = stripslashes($data); //видаляє екранування символів, повертає рядок з вирізаними зворотніми слешами $data = strip_tags($data); //видаляє HTML і PHP-теги з рядка $data = trim($data); //видаляє пробіли (або інші символи) з початку і кінця рядка $data = SQLite3::escapeString($data); //екранує спецсимволи в рядку для використання в запиті return $data; }
public function deleteCommand($commandID) { // Prepare variables before the query $commandID = SQLite3::escapeString($commandID); // Prepare SQL query $sqlQuery = "DELETE from COMMANDS where ID='" . $commandID . "';"; // Perform SQL query if (!($ret = $this->exec($sqlQuery))) { return false; } else { return true; } }
function insertView($name, $datefrom, $dateuntil, $filter) { global $db; $name = SQLite3::escapeString($name); $datefrom = intval($datefrom); $dateuntil = intval($dateuntil); $filter = SQLite3::escapeString($filter); $ok = $db->exec("INSERT INTO views VALUES('{$name}', {$datefrom}, {$dateuntil}, '{$filter}')"); if (!$ok) { die("Error on {$name}"); } return $ok; }
public function is_changed($target, $filename) { $content = file_get_contents($filename); if ($this->noop) { return $content; } $row = $this->db->querySingle('SELECT hash FROM cache WHERE target = "' . SQLite3::escapeString($target) . '" AND filename = "' . SQLite3::escapeString($filename) . '"', true); if (empty($row)) { return $content; } if ($this->calculateHash($content) != $row['hash']) { return $content; } return false; }
private function makeSchema(&$cols, $map, $prefix = "") { foreach ($map as $key => $val) { $type = gettype($val); if ($type == "array") { $this->makeSchema($cols, $val, $prefix . $key . "."); } else { $key = '"' . SQLite3::escapeString($prefix . $key) . '"'; if ($type == "string") { $val = "'" . SQLite3::escapeString($val) . "'"; } $cols[] = "{$key} {$type} DEFAULT {$val}"; } } }
function _fetch_from_store() { if (!($items = $this->queued_items)) { return; } $prefix_len = strlen($this->prefix); $prefix_sql = SQLite3::escapeString($this->prefix); array_deep($items, 'SQLite3::escapeString'); $items_list = $prefix_sql . join("','{$prefix_sql}", $items); $rowset = $this->db->fetch_rowset("SELECT ds_title, ds_data FROM " . $this->cfg['table_name'] . " WHERE ds_title IN ('{$items_list}')"); $this->db->debug('start', "unserialize()"); foreach ($rowset as $row) { $this->data[substr($row['ds_title'], $prefix_len)] = unserialize($row['ds_data']); } $this->db->debug('stop'); }
function setup() { global $settings; $exec_start = microtime(true); mkdir($settings->data_dir, 0660); touch("{$settings->data_dir}/sqlite.log"); $db = new PDO("sqlite:{$settings->data_dir}/{$settings->database_filename}"); sqlite_gateway::exec("create table users (\r\n\tid integer primary key,\r\n\tusername text,\r\n\tpassword_hash text,\r\n\troles int\r\n);", $db); sqlite_gateway::exec("insert into users (id, username, password_hash, roles) values (\r\n\t1,\r\n\t'admin',\r\n\t'" . SQLite3::escapeString(password_hash("password", PASSWORD_DEFAULT, ["cost" => $settings->password_hash_cost])) . "',\r\n\t" . (ROLE_USER | ROLE_MODERATOR | ROLE_ADMIN) . "\r\n);", $db); sqlite_gateway::exec("create table sessions (\r\n\tid integer primary key,\r\n\tkey text,\r\n\tusername text,\r\n\texpiry_timestamp int\r\n);", $db); sqlite_gateway::exec("create table code_snippets (\r\n\tid integer primary key,\r\n\ttimestamp int,\r\n\tauthor text,\r\n\ttitle text,\r\n\tdescription text,\r\n\tcode text,\r\n\tlanguage text,\r\n\ttags text\r\n);", $db); // insert test data here sqlite_gateway::exec("insert into code_snippets values (?, 1440668479, 'admin', 'test snippet', 'this is a test snippet.', 'function test(x) { console.log(x); }', 'javascript', 'test, function');", $db); // todo display a nice welcome page return microtime(true) - $exec_start; }
/** * Помещает в кэш запрос и результат */ public function set($query, $result, $query_time = NULL) { $query_hash = md5($query); $insert_sql = <<<SQL INSERT OR IGNORE INTO query_cache ( query_hash, cache_datetime, query_time, query, result ) VALUES ('%s', %d, '%F', '%s', '%s'); SQL; $q = sprintf($insert_sql, md5($query), time(), $query_time, SQLite3::escapeString($query), SQLite3::escapeString($this->_packQueryResult($result))); return $this->_db->exec($q); }
/** * Created by PhpStorm. * User: zzt * Date: 11/20/15 * Time: 3:47 PM */ function select($table, $col, $condition) { $db_handle = new SQLite3(FILENAME) or die('Unable to open database'); $result = $db_handle->query($query_string); $row = $result->fetchArray(); echo $row; $user = SQLite3::escapeString($_POST['username']); $pass = SQLite3::escapeString($_POST['password']); $query = <<<INS INSERT INTO {$table} VALUES ( '{$user}', '{$pass}' ) INS; $db_handle->exec($query) or die("Unable to add user {$user}"); $result = $db_handle->query('SELECT * FROM user') or die('Query failed'); while ($row = $result->fetchArray()) { echo "User: {$row['username']}\nPasswd: {$row['password']}\n"; } }
public function addDb($row) { if ($row instanceof Container) { $data = $row->toArray(); } else { $data = $row; } $q = "SELECT * FROM proprietes WHERE partner_id = '" . $data['partner_id'] . "'"; $res = $this->db->query($q); if (false === $res->fetchArray()) { $insert = "INSERT INTO proprietes\n (id, date_create, partner, partner_id, price, address, city, type, bedroom, thumb)\n VALUES (\n '" . $data['id'] . "',\n '" . $data['date_create'] . "',\n 'duproprio',\n '" . \SQLite3::escapeString($data["partner_id"]) . "',\n '" . \SQLite3::escapeString($data["price"]) . "',\n '" . \SQLite3::escapeString($data["address"]) . "',\n '" . \SQLite3::escapeString($data["city"]) . "',\n '" . \SQLite3::escapeString($data["type"]) . "',\n '" . \SQLite3::escapeString($data["bedroom"]) . "',\n '" . \SQLite3::escapeString($data["thumb"]) . "'\n )"; $this->db->exec($insert); } else { $update = "UPDATE proprietes\n SET price = '" . \SQLite3::escapeString($data["price"]) . "',\n address = '" . \SQLite3::escapeString($data["address"]) . "',\n city = '" . \SQLite3::escapeString($data["city"]) . "',\n type = '" . \SQLite3::escapeString($data["type"]) . "',\n bedroom = '" . \SQLite3::escapeString($data["bedroom"]) . "',\n thumb = '" . \SQLite3::escapeString($data["thumb"]) . "'\n WHERE partner_id = '" . \SQLite3::escapeString($data["partner_id"]) . "'"; $this->db->exec($update); } return $row; }
function get_outdated_files($idx, $lang, $filter = null, $value = null) { $sql = 'SELECT a.status, a.name AS file, a.maintainer, c.revision AS en_rev, a.revision AS trans_rev, b.name AS name, a.dir AS dir FROM files a, dirs b LEFT JOIN files c ON c.name = a.name AND c.dir = a.dir WHERE b.id = a.dir AND a.lang="' . $lang . '" AND a.revision != c.revision AND a.revision != "n/a" AND c.lang="en" '; if ($filter == 'dir') { $sql .= 'AND a.dir = ' . (int) $value; } elseif ($filter == 'translator') { $sql .= 'AND a.maintainer = "' . SQLite3::escapeString($value) . '"'; } $sql .= ' ORDER BY b.name'; $result = $idx->query($sql); $tmp = array(); while ($r = $result->fetchArray()) { $tmp[] = array('name' => $r['name'], 'en_rev' => $r['en_rev'], 'trans_rev' => $r['trans_rev'], 'status' => $r['status'], 'maintainer' => $r['maintainer'], 'file' => $r['file']); } return $tmp; }
public function updateBook($ebook) { $qry = "update books\n SET title = '" . SQLite3::escapeString($ebook->title) . "',\n author = '" . SQLite3::escapeString($ebook->author) . "',\n sortauthor = '" . SQLite3::escapeString($ebook->sortauthor) . "',\n summary = '" . SQLite3::escapeString($ebook->summary) . "'\n WHERE md5id = '" . SQLite3::escapeString($ebook->id) . "'"; $this->db->exec($qry); $qry = "select * from books where md5id = '" . $ebook->id . "'"; $res = $this->db->query($qry); $row = $res->fetcharray(); $bookid = $row['id']; $this->db->exec("DELETE FROM taggedbooks WHERE bookid = '{$bookid}'"); foreach ($ebook->tags as $id => $tag) { $qry = "select id from tags where tag = '{$tag}'"; $tagid = $this->db->querySingle($qry); if (!$tagid) { $this->db->exec("insert into tags (tag) values ('{$tag}')"); $tagid = $this->db->querySingle($qry); } $this->db->exec("INSERT INTO taggedbooks (bookid, tagid) values ('{$bookid}', '{$tagid}')"); } }
public static function run() { //find oldest value $oldest = \SYSTEM\SQL\SYS_LOG_OLDEST::Q1(); list($now_month, $now_year) = preg_split("/ /", date("m Y")); //All fine -> abort if ($oldest['year'] >= $now_year && $oldest['month'] >= $now_month) { return cronstatus::CRON_STATUS_SUCCESFULLY; } //create folder if required if (!file_exists(\SYSTEM\CONFIG\config::get(\SYSTEM\CONFIG\config_ids::SYS_CRON_LOG2SQLITE_PATH))) { mkdir(\SYSTEM\CONFIG\config::get(\SYSTEM\CONFIG\config_ids::SYS_CRON_LOG2SQLITE_PATH), 0777, true); } $filename = \SYSTEM\CONFIG\config::get(\SYSTEM\CONFIG\config_ids::SYS_CRON_LOG2SQLITE_PATH) . $oldest['year'] . '.' . $oldest['month'] . '.db'; //extract whole month to file $con = new \SYSTEM\DB\Connection(new \SYSTEM\DB\DBInfoSQLite($filename)); //create table $con->query('CREATE TABLE IF NOT EXISTS `system_log` (' . ' `ID` INT(10) NOT NULL,' . ' `class` TEXT NOT NULL,' . ' `message` TEXT NOT NULL,' . ' `code` INT(11) NOT NULL,' . ' `file` TEXT NOT NULL,' . ' `line` INT(11) NOT NULL,' . ' `trace` TEXT NOT NULL,' . ' `ip` TEXT NOT NULL,' . ' `querytime` DOUBLE NOT NULL,' . ' `time` DATETIME NOT NULL,' . ' `server_name` CHAR(255) NOT NULL,' . ' `server_port` INT(10) NOT NULL,' . ' `request_uri` CHAR(255) NOT NULL,' . ' `post` TEXT NOT NULL,' . ' `http_referer` CHAR(255) NULL DEFAULT NULL,' . ' `http_user_agent` TEXT NOT NULL,' . ' `user` INT(11) NULL DEFAULT NULL,' . ' `thrown` BIT(1) NOT NULL,' . ' PRIMARY KEY (`ID`)' . ');'); //write data as trasaction $con->exec('begin transaction'); set_time_limit(30); $res = \SYSTEM\SQL\SYS_LOG_MONTH::QQ(array($oldest['month'], $oldest['year'])); while ($row = $res->next()) { set_time_limit(30); $row['time'] = array_key_exists('time_pg', $row) ? date("Y-m-d H:i:s", $row['time_pg']) : $row['time']; if (!$con->exec('INSERT OR IGNORE INTO ' . \SYSTEM\SQL\system_log::NAME_MYS . '(`ID`, `class`, `message`, `code`, `file`, `line`, `trace`, `ip`, `querytime`, `time`,' . ' `server_name`, `server_port`, `request_uri`, `post`,' . ' `http_referer`, `http_user_agent`, `user`, `thrown`)' . 'VALUES (' . $row['ID'] . ', \'' . \SQLite3::escapeString($row['class']) . '\', \'' . \SQLite3::escapeString($row['message']) . '\', ' . $row['code'] . ', \'' . \SQLite3::escapeString($row['file']) . '\', ' . $row['line'] . ', \'' . \SQLite3::escapeString($row['trace']) . '\', \'' . $row['ip'] . '\', ' . $row['querytime'] . ', \'' . $row['time'] . '\', \'' . \SQLite3::escapeString($row['server_name']) . '\', ' . ($row['server_port'] ? $row['server_port'] : 'NULL') . ', \'' . \SQLite3::escapeString($row['request_uri']) . '\', \'' . \SQLite3::escapeString($row['post']) . '\', \'' . \SQLite3::escapeString($row['http_referer']) . '\', \'' . \SQLite3::escapeString($row['http_user_agent']) . '\', ' . ($row['user'] ? $row['user'] : '******') . ',' . true . ');')) { new \SYSTEM\LOG\ERROR('failed to insert into log archiev'); return cronstatus::CRON_STATUS_FAIL; } //Delete single if (!\SYSTEM\SQL\SYS_LOG_DEL::QI(array($row['ID']))) { new \SYSTEM\LOG\ERROR('failed to delete log entries'); return cronstatus::CRON_STATUS_FAIL; } } set_time_limit(30); if (!$con->exec('end transaction')) { new \SYSTEM\LOG\ERROR('failed to insert into log archiev'); return cronstatus::CRON_STATUS_FAIL; } return cronstatus::CRON_STATUS_SUCCESFULLY; }
/** * @param string $queryFullText * @param string|null $queryFilters * * @return string */ public function queryJson($queryFullText, $queryFilters = null) { $queryFullText = \SQLite3::escapeString($queryFullText); $sql = "SELECT json,offsets FROM {$this->tableFilter} JOIN (SELECT docid, offsets({$this->tableFullText}) AS offsets\n FROM {$this->tableFullText} WHERE {$this->tableFullText} MATCH '{$queryFullText}') USING (docid)"; if ($queryFilters && strlen($queryFilters) > 0) { $queryFilters = \SQLite3::escapeString($queryFilters); $sql .= " WHERE ({$queryFilters})"; } $result = $this->db->query($sql); $json = $this->jsonStart; $first = true; while ($row = $result->fetchArray(SQLITE3_NUM)) { if (!$first) { $json .= ","; } $json .= '{"value":' . $row[0] . ',"highlights":"' . $row[1] . '"}'; $first = false; } $json .= ']}'; return $json; }
function getSPInfoAllFeeds($spid) { $dbf = "/opt/getMD/var/pub/current/lib/SPReg.sqlite"; $q1 = "select feed.label from feed"; $q2 = "select lang, label from displayName where eid='" . SQLite3::escapeString($spid) . "'"; $feeds = array(); $labels = array(); $db = new SQLite3($dbf); $res = $db->query($q1); while ($row = $res->fetchArray()) { array_push($feeds, $row['label']); } $res = $db->query($q2); while ($row = $res->fetchArray(SQLITE3_ASSOC)) { $labels[$row['lang']] = $row['label']; } $db->close(); $sp = array(); $sp['feeds'] = $feeds; $sp['labels'] = $labels; return $sp; }
function acctstop($input) { require_once "settings.php"; $delimiter1 = "Session"; $delimiter2 = ": The session has been terminated."; $pos1 = strpos($input, $delimiter1) + strlen($delimiter1) + 2; $pos2 = strpos($input, $delimiter2) - 1; $sstrlen = $pos2 - $pos1; $sessid = substr($input, $pos1, $sstrlen); $delimiter1 = "outgoing data size:"; $delimiter2 = "bytes,"; $pos1 = strpos($input, $delimiter1) + strlen($delimiter1) + 1; $pos2 = strpos($input, $delimiter2) - 1; $sstrlen = $pos2 - $pos1; $outdata = substr($input, $pos1, $sstrlen); $delimiter1 = "incoming data size:"; $delimiter2 = "bytes."; $pos1 = strpos($input, $delimiter1) + strlen($delimiter1) + 1; $pos2 = strpos($input, $delimiter2) - 1; $sstrlen = $pos2 - $pos1; $indata = substr($input, $pos1, $sstrlen); $db = new SQLite3($database); $sessid = $db->escapeString($sessid); $results = $db->querySingle("SELECT * FROM sessions WHERE sessionid = '" . $sessid . "'", true); if ($results == FALSE) { die("Error - could not find sessionid"); } list($time1, , $time2) = explode(" ", $results['acctstarttime']); $sessiontime = time() - strtotime($time1 . " " . $time2); $tmpfname = tempnam($tmpdir, "acctstoptmp_"); $handle = fopen($tmpfname, "w"); $packet = "Service-Type = Framed-User" . "\n" . "Framed-Protocol = PPP" . "\n" . "NAS-Port = " . $results['nasport'] . "\n" . "NAS-Port-Type = Async" . "\n" . "User-Name = '" . $results['username'] . "'" . "\n" . "Calling-Station-Id = '" . $results['clientip'] . "'" . "\n" . "Called-Station-Id = '" . $results['nasip'] . "'" . "\n" . "Acct-Session-Id = '" . $sessid . "'" . "\n" . "Framed-IP-Address = " . $results['framedip'] . "\n" . "Acct-Authentic = RADIUS" . "\n" . "Event-Timestamp = " . time() . "\n" . "Acct-Session-Time = " . $sessiontime . "\n" . "Acct-Input-Octets = " . $indata . "\n" . "Acct-Output-Octets = " . $outdata . "\n" . "Acct-Status-Type = Stop" . "\n" . "NAS-Identifier = '" . $results['nasip'] . "'" . "\n" . "Acct-Delay-Time = 0" . "\n" . "NAS-IP-Address = " . $results['nasip'] . "\n"; fwrite($handle, $packet); fclose($handle); exec("radclient " . $radiussrv . ":" . $radiusport . " acct " . $radiuspass . " -f " . $tmpfname); unlink($tmpfname); $db->exec("DELETE FROM sessions WHERE sessionid = '" . $sessid . "' LIMIT 1"); $db->close(); }