Exemplo n.º 1
0
require_once 'DBConnector.class.php';
$dbcon = new DBConnector();
$remote = $_SERVER['REMOTE_ADDR'];
$isAllowed = false;
$newJSON = '{}';
$oldJSON = '';
if (isset($_REQUEST['json'])) {
    $oldJSON = $_REQUEST['json'];
    trace("db old: {$oldJSON}");
}
for ($t = 0; $t < 300; $t++) {
    //~ echo("waiting for db change...<br>");
    //~ $array = ['username' => 'stweil', 'quux' => 'baz'];
    //~ $newJSON = json_encode($array);
    $database = array();
    $table = $dbcon->query('select * from setting');
    $data = array();
    while ($row = $table->fetchArray(SQLITE3_ASSOC)) {
        array_push($data, $row);
    }
    $database['setting'] = $data;
    $table = $dbcon->query('select * from address');
    $data = array();
    while ($row = $table->fetchArray(SQLITE3_ASSOC)) {
        array_push($data, $row);
        $isAllowed = $isAllowed || $row['address'] == $remote;
    }
    if (!$isAllowed) {
        // Some unauthorized host tried to read the database.
        // Don't return any data.
        break;
Exemplo n.º 2
0
 public static function remember_user($remember_token)
 {
     $db_connection = new DBConnector();
     $obj_query = $db_connection->query("SELECT userid FROM remember WHERE token = '" . hash('sha256', $remember_token) . "' and expires > " . time() . ";");
     if ($obj_query->num_rows == 1) {
         $obj = $obj_query->fetch_object();
         $_SESSION['user_logged_in'] = true;
         $_SESSION['user_id'] = $obj->userid;
         Account::$user_is_logged_in = true;
     }
 }
Exemplo n.º 3
0
 /**
  * Execute the given SQL query.
  *
  * @param string $sql The SQL query to execute
  * @param int $errorLevel The level of error reporting to enable for the query
  * @return SS_Query
  */
 public function query($sql, $errorLevel = E_USER_ERROR)
 {
     return $this->connector->query($sql, $errorLevel);
 }
Exemplo n.º 4
0
 }
 //~ var_dump($_SERVER);
 $db = new DBConnector('palma-test.db');
 $db->resetTables();
 //~ http://stackoverflow.com/questions/1964233/does-sqlite3-support-a-trigger-to-automatically-update-an-updated-on-datetime
 //~ https://www.sqlite.org/lang_createtrigger.html
 // TODO: Test database triggers (can be used in db.php).
 //~ $db->createFunction('dbModifiedCallback', 'dbModifiedCallback', 0);
 // {AFTER | BEFORE} {DELETE | INSERT | UPDATE } ON table
 //~ $db->exec("CREATE TRIGGER dbchange AFTER UPDATE ON user
 //~ BEGIN
 //~ dbModifiedCallback();
 //~ END");
 //~ $db = new DBConnector('palma.db');
 echo "Tables=" . $db->querySingle('SELECT count(*) FROM sqlite_master WHERE type="table"') . "\n";
 var_dump($db->query("SELECT * from sqlite_master"));
 $address = $db->ipAddress();
 $db->addUser('testuser1', $address);
 //~ $db->addUser('testuser2', $address);
 //~ $db->addUser('testuser3', $address);
 //~ $db->addUser('testuser4', $address);
 $users = $db->getUsers();
 $db->enableUser('testuser1');
 var_dump($users);
 $db->delUser('haenger', $address);
 $db->delUser('ivwz', $address);
 $db->delUser('skrieg', $address);
 $db->delUser('testuser1', $address);
 $db->delUser('testuser2', $address);
 $db->delUser('testuser3', $address);
 $db->delUser('testuser4', $address);