public function connect($parameters, $selectDB = false) { $file = $parameters['filepath']; $this->dbConn = empty($parameters['key']) ? new SQLite3($file, SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE) : new SQLite3($file, SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE, $parameters['key']); $this->dbConn->busyTimeout(60000); $this->databaseName = $parameters['database']; }
public function setUp() { $app = (require __DIR__ . '/../../../../src/app.php'); $this->path = sys_get_temp_dir() . '/sismo.db'; @unlink($this->path); $this->db = new \SQLite3($this->path); $this->db->busyTimeout(1000); $this->db->exec($app['db.schema']); }
/** * Constructor * * @param array $connectionData Connection Data passed from the CHOQ_DB handler */ public function __construct(array $connectionData) { if (!self::isAvailable()) { error("SQLite3 and/or SQLite Extension not installed - Update your PHP configuration"); } $path = $connectionData["path"]; if (!is_dir(dirname($path)) or !is_writable(dirname($path))) { error("Directory path '" . dirname($path) . "' does not exist or is not writeable. Create or update directory chmod"); } $this->sqlite = new SQLite3($path, SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE); $this->testError(); $this->sqlite->busyTimeout(5000); }
function cleanup_listeners_othermounts($maxagelimitstamp_othermounts, $fingerprint, $mountpoint) { $db = new SQLite3('load.db'); $db->busyTimeout(100); $db->exec("DELETE FROM t_listeners WHERE timestamp < {$maxagelimitstamp_othermounts} AND fingerprint = '{$fingerprint}' AND mountpoint != '{$mountpoint}'"); $db->close(); }
/** * @return SQLite3 */ protected function db() { global $mudoco_conf; if (!$this->_db) { $this->_db = new SQLite3($mudoco_conf['MUDOCO_STORAGE_NONCE_SQLITE_FILE']); if ($this->_db) { if ($this->_db->busyTimeout(2000)) { $this->_db->exec('CREATE TABLE IF NOT EXISTS nonce (cnonce VARCHAR(32) PRIMARY KEY, nonce VARCHAR(32), expire INTEGER, fingerprint VARCHAR(32));'); $this->_db->exec('CREATE INDEX IF NOT EXISTS idx_expire ON nonce(expire);'); $this->_db->exec('CREATE INDEX IF NOT EXISTS idx_nonce ON nonce(nonce);'); } // !important : do not release busyTimeout() } } return $this->_db; }
public function __construct($filename, $flags = null, $encryptionKey = null, $busyTimeout = null, array $userDefinedFunctions = array(), array $userDefinedExtensions = array()) { if (null === $flags) { $flags = \SQLITE3_OPEN_READWRITE | \SQLITE3_OPEN_CREATE; } $this->_conn = new SQLite3($filename, $flags, $encryptionKey); if (null !== $busyTimeout) { $this->_conn->busyTimeout($busyTimeout); } else { $this->_conn->busyTimeout(60000); } foreach ($userDefinedFunctions as $fn => $data) { $this->_conn->createFunction($fn, $data['callback'], $data['numArgs']); } foreach ($userDefinedExtensions as $extension) { $this->_conn->loadExtension($extension); } }
function dbconnect() { global $plexWatch; if (!class_exists('SQLite3')) { die("<div class=\"alert alert-warning \">php5-sqlite is not installed. Please install this requirement and restart your webserver before continuing.</div>"); } $db = new SQLite3($plexWatch['plexWatchDb']); $db->busyTimeout(10 * 1000); return $db; }
/** * This method makes sure to connect to the database properly * * @param string $strHost * @param string $strUsername * @param string $strPass * @param string $strDbName * @param int $intPort * * @throws class_exception * @return bool */ public function dbconnect($strHost, $strUsername, $strPass, $strDbName, $intPort) { if ($strDbName == "") { return false; } $this->strDbFile = _projectpath_ . '/dbdumps/' . $strDbName . '.db3'; try { $this->linkDB = new SQLite3(_realpath_ . $this->strDbFile); $this->_pQuery('PRAGMA encoding = "UTF-8"', array()); //TODO deprecated in sqlite, so may be removed $this->_pQuery('PRAGMA short_column_names = ON', array()); $this->_pQuery("PRAGMA journal_mode = TRUNCATE", array()); if (method_exists($this->linkDB, "busyTimeout")) { $this->linkDB->busyTimeout(5000); } return true; } catch (Exception $e) { throw new class_exception("Error connecting to database: " . $e, class_exception::$level_FATALERROR); } }
public function __construct() { global $db; if (!$db) { $db = new SQLite3('ct_database.db'); $db->busyTimeout(5000); } //$db->exec('DROP TABLE reindex'); //$db->exec('DROP TABLE product'); $this->initTableProduct(); $this->initTableReindex(); }
public function __construct($cid, $year, $month) { $this->cid = $cid; $this->datetime['month'] = $month; $this->datetime['year'] = $year; /** * Load settings from vars.php (contained in $settings[]). */ if ((include 'vars.php') === false) { $this->output(null, 'The configuration file could not be read.'); } /** * $cid is the channel ID used in vars.php and is passed along in the URL so * that channel specific settings can be identified and loaded. */ if (empty($settings[$this->cid])) { $this->output(null, 'This channel has not been configured.'); } foreach ($settings[$this->cid] as $key => $value) { $this->{$key} = $value; } date_default_timezone_set($this->timezone); /** * Open the database connection. */ try { $sqlite3 = new SQLite3($this->database, SQLITE3_OPEN_READONLY); $sqlite3->busyTimeout(0); } catch (Exception $e) { $this->output(null, basename(__FILE__) . ':' . __LINE__ . ', sqlite3 says: ' . $e->getMessage()); } /** * Set SQLite3 PRAGMAs: * query_only = ON - Disable all changes to database files. * temp_store = MEMORY - Temporary tables and indices are kept in memory. */ $pragmas = ['query_only' => 'ON', 'temp_store' => 'MEMORY']; foreach ($pragmas as $key => $value) { $sqlite3->exec('PRAGMA ' . $key . ' = ' . $value); } /** * Make stats! */ echo $this->make_html($sqlite3); $sqlite3->close(); }
function get_node_info($nodename, $value) { global $workdir; $db = new SQLite3("{$workdir}/var/db/nodes.sqlite"); $db->busyTimeout(5000); if (!$db) { return; } $sql = "SELECT {$value} FROM nodelist WHERE nodename=\"{$nodename}\""; $result = $db->query($sql); //->fetchArray(SQLITE3_ASSOC); $row = array(); while ($res = $result->fetchArray(SQLITE3_ASSOC)) { if (!isset($res["{$value}"])) { return; } return $res["{$value}"]; } }
protected function _connect() { $db = $this->profile['database']; if (preg_match('/^(app|lib|var|temp|www)\\:/', $db)) { $path = jFile::parseJelixPath($db); } else { if ($db[0] == '/' || preg_match('!^[a-z]\\:(\\\\|/)[a-z]!i', $db)) { if (file_exists($db) || file_exists(dirname($db))) { $path = $db; } else { throw new Exception('sqlite3 connector: unknown database path scheme'); } } else { $path = jApp::varPath('db/sqlite3/' . $db); } } $sqlite = new SQLite3($path); // Load extensions if needed if (isset($this->profile['extensions'])) { $list = preg_split('/ *, */', $this->profile['extensions']); foreach ($list as $ext) { try { $sqlite->loadExtension($ext); } catch (Exception $e) { throw new Exception('sqlite3 connector: error while loading sqlite extension ' . $ext); } } } // set timeout if (isset($this->profile['busytimeout'])) { $timeout = intval($this->profile['busytimeout']); if ($timeout) { $sqlite->busyTimeout($timeout); } } return $sqlite; }
session_regenerate_id(true); session_start(); } if (@$_GET['logout']) { session_regenerate_id(true); } // For debug purposes -> get random demo package from server if (isset($_GET['demoPackages'])) { $demoFiles = glob(dirname(__FILE__) . '/demoData/*.json'); die(file_get_contents($demoFiles[rand(0, count($demoFiles) - 1)])); } $errorMessages = array(); // try to get access to the database try { $db = new SQLite3(dirname(__FILE__) . '/' . DB_FILE, SQLITE3_OPEN_READWRITE); $db->busyTimeout(1000 * intval(ini_get('max_execution_time'))); // check table packages to be available in the right structure if ($stmt = @$db->prepare('PRAGMA table_info(packages)')) { $result = $stmt->execute(); $givenStructure = array(); while ($row = $result->fetchArray(SQLITE3_ASSOC)) { $givenStructure[$row['name']] = $row['type']; } $neededStructure = array('id' => 'INTEGER', 'room' => 'TEXT', 'to_client' => 'TEXT', 'time' => 'INTEGER', 'data' => 'TEXT'); if (count($neededStructure) == count($givenStructure)) { // check all fields foreach ($neededStructure as $name => $type) { // check whether col exists if (!isset($givenStructure[$name])) { $errorMessages[] = 'Database table \'packages\' does not match the needed scheme. [Column \'' . $name . '\' is missing]'; http_response_code(500);
$bandwidth = $_GET['bw']; $bandwidthlimit = $_GET['bwl']; $mountpoints = $_GET['mnt']; $load = $_GET['load']; $loadlimit = $_GET['loadl']; $tstampnow = time(); include "functions.php"; init_db(); error_reporting(E_ALL); if (!isset($loadlimit)) { $loadlimit = 77; } if (!isset($ip, $bandwidth, $bandwidthlimit, $mountpoints, $load, $loadlimit)) { exit; } $maxage = 3600 * 24 * 31; $maxagelimitstamp = $tstampnow - $maxage; cleanup_pool($maxagelimitstamp); $a_mountpoints = preg_split("/[|,]+/", $mountpoints); $listeners = 99; $db = new SQLite3('load.db'); $db->busyTimeout(3000); foreach ($a_mountpoints as $mountpoint) { $a_listeners_per_mountpoint = preg_split("/[@]+/", $mountpoint); $listeners = $a_listeners_per_mountpoint[0]; $mnt = $a_listeners_per_mountpoint[1]; $target = $ip . "_" . $mnt; $db->exec("REPLACE INTO t_pool (\n\ttarget,\n\tmachineip,\n\tbandwidth,\n\tbandwidthlimit,\n\tlisteners,\n\tmountpoint,\n\tload,\n\tloadlimit,\n\ttimestamp) VALUES (\n\t'{$target}',\n\t'{$ip}',\n\t{$bandwidth},\n\t{$bandwidthlimit},\n\t{$listeners},\n\t'{$mnt}',\n\t{$load},\n\t{$loadlimit},\n\t{$tstampnow})"); } $db->close(); #echo $db->lastErrorMsg();
function sqliteConnect() { $s = new SQLite3("../wowsuchbots.db"); $s->busyTimeout(1000); return $s; }
function show_logs() { global $workdir; $db = new SQLite3("{$workdir}/var/db/cbsdtaskd.sqlite"); $db->busyTimeout(5000); $sql = "SELECT id,st_time,end_time,cmd,status,errcode,logfile FROM taskd WHERE owner='cbsdweb' ORDER BY id DESC;"; $result = $db->query($sql); //->fetchArray(SQLITE3_ASSOC); $row = array(); $i = 0; ?> <table class="images"> <thead> <tr> <th>id</th> <th>cmd</th> <th>start time</th> <th>end time</th> <th>status</th> <th>errcode</th> <th>logfile</th> <th>logsize</th> </tr> </thead><tbody> <?php while ($res = $result->fetchArray(SQLITE3_ASSOC)) { if (!isset($res['id'])) { continue; } $id = $res['id']; $cmd = $res['cmd']; $start_time = $res['st_time']; $end_time = $res['end_time']; $status = $res['status']; $errcode = $res['errcode']; $logfile = $res['logfile']; if (file_exists($logfile)) { $tmplogsize = filesize($logfile); $logsize = human_filesize($tmplogsize, 0); } else { $logsize = 0; } $i++; switch ($status) { case 0: //pending $hdr = '<tr style="background-color:#51FF5F">'; break; case 1: //in progress $hdr = '<tr style="background-color:#F3FF05">'; break; case 2: //complete switch ($errcode) { case 0: $hdr = '<tr style="background-color:#EDECEA">'; break; default: //errcode not 0 $hdr = '<tr style="background-color:#FFA7A1">'; break; } break; } $s_time = date("Y-M-d H:i", strtotime($start_time)); $e_time = date("Y-M-d H:i", strtotime($end_time)); if ($logsize != 0) { $logfiletd = "<td><a href=\"showtasklog.php?log={$logfile}\">{$logfile}</a></td>"; } else { $logfiletd = "<td>{$logfile}</td>"; } $str = <<<EOF \t\t\t<td>{$id}</td> \t\t\t<td>{$cmd}</td> \t\t\t<td>{$s_time}</td> \t\t\t<td>{$e_time}</td> \t\t\t<td>{$status}</td> \t\t\t<td>{$errcode}</td> \t\t\t{$logfiletd} \t\t\t<td>{$logsize}</td> \t\t\t</tr> EOF; echo $hdr . $str; } echo "</tbody></table>"; }
function Parser_SQlite_Connect($vDBFile) { $vDB = new SQLite3($vDBFile); if (!$vDB) { AddLog2('Parser SQlite Error: cant open ' . $vDBFile); return false; } $vDB->exec('PRAGMA cache_size=20000'); $vDB->exec('PRAGMA synchronous=OFF'); $vDB->exec('PRAGMA count_changes=OFF'); $vDB->exec('PRAGMA journal_mode=MEMORY'); $vDB->exec('PRAGMA temp_store=MEMORY'); $vDB->busyTimeout(10000); return $vDB; }
<?php $db = new SQLite3('../../db/' . $_GET["db"]); error_log(exec('pwd')); $order = array("\r\n", "\n", "\r"); $replace = '<br />'; error_log('before urldecode ' . $_GET["query"]); $query = str_replace($order, $replace, urldecode($_GET["query"])); error_log($query); if ($db->busyTimeout(4000)) { $results = $db->query($query); if ($results) { error_log('request ok'); } else { error_log('error in request : ' . $query); } } else { error_log('after busyTimeout '); } //$db->close(); if (substr(strtolower($query), 0, 6) != "update" && substr(strtolower($query), 0, 6) != 'insert') { error_log('boucle'); $retour = ''; while ($line = $results->fetchArray()) { $content = ''; foreach ($line as $key => $val) { $content .= ($content ? ',' : '') . '"' . $key . '" : "' . str_replace($order, $replace, str_replace('"', '\\"', $val)) . '"'; } $retour .= ($retour ? ',' : '') . '{' . $content . '}'; } print '[' . $retour . ']';
<?php error_reporting(E_ALL ^ E_NOTICE); $db = new SQLite3("/media/daten/heizung/openhr20.sqlite"); $db->busyTimeout(60000); $TIMEZONE = "Europe/Berlin"; $RRD_ENABLE = true; $PLOTS_DIR = "plots"; $RRD_DAYS = array(3, 7, 30, 90); // translation table for valve names // example: $room_name = array(0x8 => 'Wohnzimmer Rechts', 0x9 => 'Wohnzimmer Links', 0xb => 'Daddelzimmer', 0xc => 'Schlafzimmer Rechts', 0xd => 'Schlafzimmer Links', 0xe => 'Badezimmer', 0xa => 'Küche'); // translation table for timers name (weekdays) $timer_names = array('Woche', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag', 'Sonntag'); // symbols for 4 temperature mode // unicode version with nice moon/sun symbols, have problem on mobile Opera browser $symbols = array('x', '☾', '☀', '☼ //Comfort '); $refresh_value = 15; // refresh time for command queue pending wait $chart_hours = 48; // chart contain values from last 12 hours $warning_age = 8 * 60; // maximum data age for warning $error_age = 20 * 60; // maximum data age for error
function show_jails($nodelist = "local") { global $workdir; $pieces = explode(" ", $nodelist); ?> <table class="images"> <thead> <tr> <th>node</th> <th>jname</th> <th>ip4_addr</th> <th>status</th> <th>action</th> <th>remove</th> <th>console</th> </tr> </thead> <tbody> <?php foreach ($pieces as $nodename) { if (!$nodename) { $nodename = $nodelist; } $db = new SQLite3("{$workdir}/var/db/{$nodename}.sqlite"); $db->busyTimeout(5000); if (!$db) { return; } $sql = "SELECT jname,ip4_addr,status FROM jails WHERE emulator != \"bhyve\";"; $result = $db->query($sql); //->fetchArray(SQLITE3_ASSOC); $row = array(); $i = 0; if ($nodename != "local") { $nodeip = get_node_info($nodename, "ip"); $idle = check_locktime($nodeip); } else { $idle = 1; } if ($idle == 0) { $hdr = '<tr style="background-color:#D6D2D0">'; } else { $hdr = '<tr>'; } while ($res = $result->fetchArray(SQLITE3_ASSOC)) { if (!isset($res['jname'])) { continue; } $jname = $res['jname']; $ip4_addr = $res['ip4_addr']; $status = $res['status']; $i++; if ($idle != 0) { switch ($status) { case 0: //off $statuscolor = "#EDECEA"; $action = "<form action=\"jstart.php\" method=\"post\"><input type=\"hidden\" name=\"jname\" value=\"{$jname}\"/> <input type=\"submit\" name=\"start\" value=\"Start\"></form>"; break; case 1: //running $statuscolor = "#51FF5F"; $action = "<form action=\"jstop.php\" method=\"post\"><input type=\"hidden\" name=\"jname\" value=\"{$jname}\"/> <input type=\"submit\" name=\"stop\" value=\"Stop\"></form>"; break; default: $statuscolor = "#D6D2D0"; $action = "maintenance"; break; } } else { $statuscolor = "#D6D2D0"; $action = "offline"; } if ($idle != 0) { $status_td = "<td><a href=\"jstatus.php?jname={$jname}\">{$jname}</a></td>"; $remove_td = "<td><a href=\"jremove.php?jname={$jname}\">Remove</a></td>"; } else { $status_td = "<td>{$jname}</td>"; $remove_td = "<td>Remove</td>"; } $str = <<<EOF \t\t\t\t{$hdr} \t\t\t\t<td><strong>{$nodename}</strong></td> \t\t\t\t{$status_td} \t\t\t\t<td>{$ip4_addr}</td> \t\t\t\t<td style="background-color:{$statuscolor}">{$status}</td> \t\t\t\t<td>{$action}</td> \t\t\t\t{$remove_td} EOF; if ($status == 1) { $tmp = str_replace("/", ",", $ip4_addr); $ipw = explode(",", $tmp); $console = '<a href="http://'; $console .= $ipw[0] . ":8000"; $console .= '">Console</a>'; } else { $console = "Not running"; } $str .= <<<EOF \t\t\t\t<td>{$console}</td> \t\t\t\t</tr> EOF; echo $str; } } echo "</tbody></table>"; }
function show_bhyvevm($nodelist = "local") { global $workdir; $pieces = explode(" ", $nodelist); ?> <table class="images"> <thead> <tr> <th>node</th> <th>vm</th> <th>vm_ram</th> <th>vm_cpus</th> <th>vm_os_type</th> <th>status</th> <th>action</th> <th>remove</th> </tr> </thead> <tbody> <?php foreach ($pieces as $nodename) { if (!$nodename) { $nodename = $nodelist; } $db = new SQLite3("{$workdir}/var/db/{$nodename}.sqlite"); $db->busyTimeout(5000); $sql = "SELECT jname,vm_ram,vm_cpus,vm_os_type FROM bhyve;"; $result = $db->query($sql); //->fetchArray(SQLITE3_ASSOC); $row = array(); $i = 0; if ($nodename != "local") { $nodeip = get_node_info($nodename, "ip"); $idle = check_locktime($nodeip); } else { $idle = 1; } if ($idle == 0) { $hdr = '<tr style="background-color:#D6D2D0">'; } else { $hdr = '<tr>'; } while ($res = $result->fetchArray(SQLITE3_ASSOC)) { if (!isset($res['jname'])) { continue; } $jname = $res['jname']; $vm_ram = $res['vm_ram'] / 1024 / 1024; $vm_cpus = $res['vm_cpus']; $vm_os_type = $res['vm_os_type']; $status = check_vmonline($jname); $i++; if ($idle != 0) { switch ($status) { case 0: //off $statuscolor = "#EDECEA"; $action = "<form action=\"bstart.php\" method=\"post\"><input type=\"hidden\" name=\"jname\" value=\"{$jname}\"/> <input type=\"submit\" name=\"start\" value=\"Start\"></form>"; break; case 1: //running $statuscolor = "#51FF5F"; $action = "<form action=\"bstop.php\" method=\"post\"><input type=\"hidden\" name=\"jname\" value=\"{$jname}\"/> <input type=\"submit\" name=\"stop\" value=\"Stop\"></form>"; break; default: $action = "maintenance"; break; } } else { $statuscolor = "#D6D2D0"; $action = "offline"; } if ($idle != 0) { $status_td = "<td><a href=\"bstatus.php?jname={$jname}\">{$jname}</a></td>"; $remove_td = "<td><a href=\"bremove.php?jname={$jname}\">Remove</a></td>"; } else { $status_td = "<td>{$jname}</td>"; $remove_td = "<td>Remove</td>"; } $str = <<<EOF \t\t\t{$hdr} \t\t\t<td><strong>{$nodename}</strong></td> \t\t\t{$status_td} \t\t\t<td>{$vm_ram}</td><td>{$vm_cpus}</td> \t\t\t<td>{$vm_os_type}</td> \t\t\t<td style="background-color:{$statuscolor}">{$status}</td> \t\t\t<td>{$action}</td> \t\t\t{$remove_td} \t\t\t</tr> EOF; echo $str; } } echo "</tbody></table>"; }
public function __construct() { /** * Explicitly set the locale to C (POSIX) for all categories so there hopefully * won't be any unexpected results between platforms. */ setlocale(LC_ALL, 'C'); /** * Use the default value until a user specified timezone is loaded. */ date_default_timezone_set($this->timezone); /** * Read options from the command line. Print the manual on invalid input. */ $options = getopt('b:c:e:i:n:o:s'); ksort($options); $options_keys = implode('', array_keys($options)); if (!preg_match('/^(bc?i?o|c|c?(e|i|i?o|n|s))$/', $options_keys)) { $this->print_manual(); } /** * Some options require additional settings to be set in the configuration file. * Add those to the list. */ if (array_key_exists('i', $options)) { array_push($this->settings_list_required, 'parser', 'logfile_dateformat'); } if (array_key_exists('o', $options) || array_key_exists('s', $options)) { $this->settings_list_required[] = 'channel'; } /** * Read the configuration file. */ if (array_key_exists('c', $options)) { $this->read_config($options['c']); } else { $this->read_config(dirname(__FILE__) . '/sss.conf'); } /** * After the configuration file has been read we can update the used timezone * and the level of console output messages with user specified values. */ if (!date_default_timezone_set($this->timezone)) { output::output('critical', __METHOD__ . '(): invalid timezone: \'' . $this->timezone . '\''); } /** * Prior to having the updated value of $outputbits take effect there were no * message types other than critical events, which cannot be suppressed. */ output::set_outputbits($this->outputbits); /** * Export settings from the configuration file in the format vars.php accepts * them. */ if (array_key_exists('s', $options)) { $this->export_settings(); } /** * Open the database connection. Always needed from this point forward. */ try { $sqlite3 = new SQLite3($this->database, SQLITE3_OPEN_READWRITE); $sqlite3->busyTimeout(60000); } catch (Exception $e) { output::output('critical', basename(__FILE__) . ':' . __LINE__ . ', sqlite3 says: ' . $e->getMessage()); } /** * Set SQLite3 PRAGMAs: * journal_mode = OFF - Disable the rollback journal completely. * synchronous = OFF - Continue without syncing as soon as data is handed off * to the operating system. * temp_store = MEMORY - Temporary tables and indices are kept in memory. */ $pragmas = ['journal_mode' => 'OFF', 'synchronous' => 'OFF', 'temp_store' => 'MEMORY']; foreach ($pragmas as $key => $value) { $sqlite3->exec('PRAGMA ' . $key . ' = ' . $value); } output::output('notice', __METHOD__ . '(): succesfully connected to database: \'' . $this->database . '\''); /** * The following options are listed in order of execution. Ie. "i" before "o", * "b" before "o". */ if (array_key_exists('b', $options) && preg_match('/^\\d+$/', $options['b'])) { $this->settings['sectionbits'] = (int) $options['b']; } if (array_key_exists('e', $options)) { $this->export_nicks($sqlite3, $options['e']); } if (array_key_exists('i', $options)) { $this->parse_log($sqlite3, $options['i']); } if (array_key_exists('n', $options)) { $this->import_nicks($sqlite3, $options['n']); /** * Run maintenance after import. */ $this->do_maintenance($sqlite3); } if (array_key_exists('o', $options)) { $this->make_html($sqlite3, $options['o']); } $sqlite3->close(); output::output('notice', __METHOD__ . '(): kthxbye'); }
<td width="99" align="right" valign="bottom"><a href="logout.php">Log Out</a></td> </tr> </table> </td> </tr> <tr> <td height="10" valign="top"> <div align="center"> <h6>Note: Refresh the page to update the graphs with new datapoints.</h6></div></td> </tr> <tr> <td height="77" width="1170" valign="top"><div class="cssbox"><p> <?php session_start(); $db = new SQLite3($_SERVER['DOCUMENT_ROOT'] . '/yieldbuddy/www/sql/yieldbuddy.sqlite3'); $db->busyTimeout(2000); $results = $db->query('SELECT * FROM Sensors_Log'); $rownum = 0; while ($row = $results->fetchArray()) { $Time_array[$rownum] = $row[0]; $pH1_array[$rownum] = $row[1]; $pH2_array[$rownum] = $row[2]; $Temp_array[$rownum] = $row[3]; $RH_array[$rownum] = $row[4]; $TDS1_array[$rownum] = $row[5]; $TDS2_array[$rownum] = $row[6]; $CO2_array[$rownum] = $row[7]; $Light_array[$rownum] = $row[8]; #echo $Time_array[$rownum]; $dates = explode("-", $Time_array[$rownum]); #echo "</br>";
<?php $channel = $_GET['channel']; $command = $_GET['command']; $xmlfile = "switch.xml"; openlog("noolite-php", LOG_NDELAY, LOG_LOCAL0); include 'switchlamp.php'; if ($channel < 1 || $channel > 64) { if ($LOGGING) { syslog("LOG_WARNING", "Channel " . $channel . " out of range"); } exit; } $db = new SQLite3("lamps.db", SQLITE3_OPEN_READWRITE); $db->busyTimeout(1000); $db->exec("PRAGMA synchronous=OFF;"); $db->exec("PRAGMA journal_mode=MEMORY;"); $switches = simplexml_load_file($xmlfile); if (!$switches) { syslog(LOG_ERR, "Couldn't open XML file " . $xmlfile); exit; } $items = $switches->xpath("channel[@id=" . $channel . "]"); if (count($items) > 0) { if (count($items) == 1) { $item = $items[0]; } else { $success = 0; foreach ($items as $i => $subitem) { if ($subitem["command"] == $command) { $item = $items[$i];
if ($submit == "Restore Defaults") { $command = "restoredefaults"; } if ($submit == "Save Email Settings") { $smtp_server = $_GET["smtp_server"]; $smtp_port = $_GET["smtp_port"]; $login_email = $_GET["login_email"]; $login_email_password = $_GET["login_email_password"]; $recipient_email = $_GET["recipient_email"]; $command = "saveemailsettings," . $login_email . "," . $login_email_password . "," . $recipient_email . "," . $smtp_server . "," . $smtp_port; } if ($submit == "Save Camera Settings") { $camera_address = $_GET["camera_address"]; session_start(); $db = new SQLite3($_SERVER['DOCUMENT_ROOT'] . '/yieldbuddy/www/sql/yieldbuddy.sqlite3'); $db->busyTimeout(4000); $alarmsql_query = "UPDATE Camera SET connectback_address='" . $camera_address . "'"; $query = $db->exec($alarmsql_query); if (!$query) { echo "Error saving changes: '{$error}'"; } } if ($submit == "Save pH1 Settings") { $pH1Value_Low = $_GET["pH1Value_Low"]; $pH1Value_High = $_GET["pH1Value_High"]; $command = "setpH1," . $pH1Value_Low . "," . $pH1Value_High; } if ($submit == "Save pH2 Settings") { $pH2Value_Low = $_GET["pH2Value_Low"]; $pH2Value_High = $_GET["pH2Value_High"]; $command = "setpH2," . $pH2Value_Low . "," . $pH2Value_High;
<?php include '../../codebase/connector/db_sqlite3.php'; include '../../codebase/connector/gantt_connector.php'; // SQLite $dbtype = "SQLite3"; $res = new SQLite3(dirname(__FILE__) . "/samples.sqlite"); $res->busyTimeout(1000); // Mysql // $dbtype = "MySQL"; // $res=mysql_connect("192.168.1.251", "gantt", "gantt"); // mysql_select_db("gantttest");
/* This file is for user to upload their own notes in the canvas * So if the users' session is in the database, just update the information of * images of that user. * if not exist, create a new record to store it. */ session_start(); $ses_id = session_id(); // var_dump($ses_id); // echo "</br>"; // Get the base64 image string $image_str = $_POST['image_str']; // play with database $db_name = 'my_database.db'; $db = new SQLite3($db_name) or die('unable to connect database'); $db->busyTimeout(5000); // test whether this user exists $query = "select user_id from sessions where session_id = '{$ses_id}'"; $result = $db->query($query)->fetchArray(); if (!$result) { $query1 = "select max(user_id) from images"; $tmp = $db->query($query1)->fetchArray(); $cur_user; if (!is_array($tmp)) { $cur_user = 1; } else { $cur_user = $tmp[0] + 1; } $db->exec("insert into sessions (session_id, user_id) values ('{$ses_id}','{$cur_user}')"); $db->exec("insert into images (user_id, image_str, submit_time) values ('{$cur_user}','{$image_str}',time('now'))"); } else {
// Hardware-pairs a Pico remote to a set of Caseta dimmers. // Useful for bypassing SmartThings' considerable latency and establishing // instant and reliable Pico-to-Caseta communication. // Pass a negative number for the caseta ID to remove instead of add. $pico = intval(@$_REQUEST["pico"]) or emsg('No pico parameter'); $raw_caseta = intval(@$_REQUEST["caseta"]) or emsg('No caseta parameter'); $op = $raw_caseta >= 0 ? "lutron_pico_add" : "lutron_pico_del"; $caseta = abs($raw_caseta); function emsg($msg) { echo $msg; exit; } $db = "/database/apron.db"; $dbh = new SQLite3($db); $dbh->busyTimeout(5000); $device_result = $dbh->query("SELECT masterId FROM lutronDevice WHERE lNodeId = {$pico}"); $row = $device_result->fetchArray(SQLITE3_ASSOC) or emsg("No such device."); $pico_master = $row["masterId"]; $device_result->finalize(); $device_result = $dbh->query("SELECT masterId FROM lutronDevice WHERE lNodeId = {$caseta}"); $row = $device_result->fetchArray(SQLITE3_ASSOC) or emsg("No such device."); $caseta_master = $row["masterId"]; $device_result->finalize(); $dbh->close(); unset($dbh); $cmd = "aprontest --{$op} {$caseta_master} -m {$pico_master} | sed 's/[[:space:]][[:space:]]*/ /g' | grep '^[[:space:]][[:alnum:]]*: [A-Za-z0-9\\-_]*\$' | sed 's/^ //'"; $output = `{$cmd}`; $lines = explode(PHP_EOL, $output); $data = array("cmd" => $cmd, "serial" => $pico, "op" => $op, "value" => $caseta); $result = array();
function fetch_node_inv($dbfilepath) { global $allncpu, $allcpufreq, $allphysmem, $allnodes, $nodetable, $alljails, $knownfreq, $workdir; ?> <form id="editor" action="save.php" method="post"> <div class="buttons"> <input id="edit-area-cancel" name="yt0" type="button" value="Cancel"> <input id="edit-area-ok" type="submit" name="save" value="Commit"> </div> </form> <?php $stat = file_exists($dbfilepath); if (!$stat) { $nodetable .= "<tr><td bgcolor=\"#CCFFCC\">{$allnodes}</td><td colspan=10><center>{$dbfilepath} not found</center></td></tr>"; return 0; } $db = new SQLite3($dbfilepath); $db->busyTimeout(5000); $results = $db->query('SELECT COUNT(*) FROM jails;'); if (!$results instanceof Sqlite3Result) { $numjails = 0; } else { while ($row = $results->fetchArray()) { $numjails = $row[0]; } } $gwinfo = ""; $netres = $db->query('SELECT ip4,ip6,mask4,mask6 FROM net;'); if (!$netres instanceof Sqlite3Result) { echo "Error: {$dbfilepath}"; $gwinfo = "unable to fetch net info"; } else { while ($row = $netres->fetchArray()) { for ($i = 0; $i < 4; $i++) { if (isset($row[$i])) { $gwinfo .= $row[$i] . " "; } } } } $netres = $db->query('SELECT * FROM gw;'); if (!$netres instanceof Sqlite3Result) { } else { while ($row = $netres->fetchArray()) { for ($i = 0; $i < 4; $i++) { if (isset($row[$i])) { $gwinfo .= $row[$i] . " "; } } } } $results = $db->query('SELECT nodename,nodeip,fs,ncpu,physmem,cpufreq,osrelease FROM local;'); if (!$results instanceof Sqlite3Result) { $nodetable .= <<<EOF \t\t<tr> \t\t\t<td bgcolor="#CCFFCC">{$allnodes}</td><td colspan=10></td> \t\t</tr> EOF; } else { while ($row = $results->fetchArray()) { list($nodename, $nodeip, $fs, $ncpu, $physmem, $cpufreq, $osrelease) = $row; $descrfile = $workdir . "/var/db/nodedescr/" . $nodename . ".descr"; $desc = ""; if (file_exists($descrfile)) { $fp = fopen($descrfile, "r"); $size = filesize($descrfile); if ($size > 0) { $desc = fread($fp, filesize($descrfile)); } fclose($fp); } $locfile = $workdir . "/var/db/nodedescr/" . $nodename . ".location"; $loc = ""; if (file_exists($locfile)) { $fp = fopen($locfile, "r"); $size = filesize($locfile); if ($size > 0) { $loc = fread($fp, filesize($locfile)); } fclose($fp); } $notesfile = $workdir . "/var/db/nodedescr/" . $nodename . ".notes"; $notes = ""; if (file_exists($notesfile)) { $fp = fopen($notesfile, "r"); $size = filesize($notesfile); if ($size > 0) { $notes = fread($fp, filesize($notesfile)); } fclose($fp); } $idle = check_locktime($nodeip); if ($idle == 0) { $hdr = '<tr rel="${nodename}" style="background-color:#D6D2D0">'; } else { $hdr = '<tr rel="${nodename}">'; } $nodetable .= <<<EOF \t\t\t{$hdr} \t\t\t\t<td bgcolor="#CCFFCC" class="node-name" data-file="descr" data-type="text">{$nodename}</td> \t\t\t\t<td data-togle="toolkip" title="{$gwinfo}">{$nodeip}</td> \t\t\t\t<td class="edited" data-file="descr" data-type="textarea">{$desc}</td> \t\t\t\t<td class="edited" data-file="location" data-type="text">{$loc}</td> \t\t\t\t<td>{$osrelease}</td> \t\t\t\t<td>{$fs}</td> \t\t\t\t<td>{$physmem}</td> \t\t\t\t<td>{$ncpu}</td> \t\t\t\t<td>{$cpufreq}</td> \t\t\t\t<td>{$numjails}</td> \t\t\t\t<td class="edited" data-file="notes" data-type="textarea">{$notes}</td> \t\t\t</tr> EOF; $allncpu += $ncpu; $allphysmem += $physmem; $allcpufreq += $cpufreq; $alljails += $numjails; if ($cpufreq > 1) { $knownfreq++; } } } $db->close(); }
public function close() { $this->sdb->busyTimeout(0); $this->sdb->close(); return true; }