Example #1
0
 /**
  * Execute the SQL query.
  *
  * @param  string $sql
  * @throws Exception
  * @return void
  */
 public function query($sql)
 {
     if ($this->isPdo) {
         $sth = $this->sqlite->prepare($sql);
         if (!$sth->execute()) {
             throw new Exception($sth->errorCode() . ': ' . $sth->errorInfo());
         } else {
             $this->result = $sth;
         }
     } else {
         if (!($this->result = $this->sqlite->query($sql))) {
             throw new Exception('Error: ' . $this->sqlite->lastErrorCode() . ': ' . $this->sqlite->lastErrorMsg() . '.');
         }
     }
 }
Example #2
0
<?php

//$address = $_POST["address"];  //sql
$user = isset($_POST['user']) ? $_POST['user'] : '';
$host = isset($_POST['host']) ? $_POST['host'] : '';
$port = isset($_POST['port']) ? $_POST['port'] : '';
$password = isset($_POST['password']) ? $_POST['password'] : '';
$change_password1 = isset($_POST['change_password1']) ? $_POST['change_password1'] : '';
if ($change_password1 == "change_password2") {
    $db = new PDO('sqlite:dbf/nettemp.db');
    $db->exec("UPDATE mail_settings SET port='{$port}'") or die($db->lastErrorMsg());
    $db->exec("UPDATE mail_settings SET host='{$host}'") or die($db->lastErrorMsg());
    $db->exec("UPDATE mail_settings SET user='******'") or die($db->lastErrorMsg());
    $db->exec("UPDATE mail_settings SET password='******'") or die($db->lastErrorMsg());
    header("location: " . $_SERVER['REQUEST_URI']);
    exit;
}
?>



<?php 
$db = new PDO('sqlite:dbf/nettemp.db');
$sth = $db->prepare("select * from mail_settings ");
$sth->execute();
$result = $sth->fetchAll();
foreach ($result as $a) {
    ?>

    <table>
    <tr>
{
	_log(__FILE__ . " - line " . __LINE__ . ": Connected to database");
}*/
_log(__FILE__ . " - line " . __LINE__ . ": " . isset($_REQUEST['oper']) ? $_REQUEST['oper'] : "No operation found!");
if (isset($_REQUEST['oper'])) {
    try {
        switch ($_REQUEST['oper']) {
            case 'del':
                _log(__FILE__ . " - line " . __LINE__ . ": Request for deletion: " . print_r($_REQUEST, TRUE));
                // explode, then implode adding quotes
                $deleteUUID = explode(",", utf8_decode($_REQUEST['id']));
                $deleteParameters = '"' . implode('","', $deleteUUID) . '"';
                if ($db->query("DELETE FROM Obstacles WHERE UUID IN (" . $deleteParameters . ")")) {
                    _log(__FILE__ . " - line " . __LINE__ . ": Obstacle(s) deleted: " . $deleteParameters);
                } else {
                    _log(__FILE__ . " - line " . __LINE__ . ": Error deleting position(s) \"" . $deleteParameters . "\"! " . $db->lastErrorMsg());
                    exit(0);
                }
                break;
            case 'edit':
                updateRow();
                break;
            case 'add':
                addRow();
                // unsupported
                break;
        }
    } catch (PDOException $e) {
        _log(__FILE__ . " - line " . __LINE__ . ": Some query failed: " . PDO_PREFIX . SQLITE_DB_FILENAME . ": " . $e->getMessage());
        exit(0);
        // flag jQueryGrid that this failed
Example #4
0
<?php

$senderrors = isset($_POST['senderrors']) ? $_POST['senderrors'] : '';
$sende = isset($_POST['sende']) ? $_POST['sende'] : '';
if ($sende == "sende") {
    $db = new PDO('sqlite:dbf/nettemp.db');
    $db->exec("UPDATE mail_settings SET error='{$senderrors}' WHERE id='1'") or die($db->lastErrorMsg());
    header("location: " . $_SERVER['REQUEST_URI']);
    exit;
}
?>
<span class="belka">&nbsp Other <span class="okno">
<?php 
$db = new PDO('sqlite:dbf/nettemp.db');
$sth = $db->prepare("select * from mail_settings ");
$sth->execute();
$result = $sth->fetchAll();
foreach ($result as $a) {
    ?>

<form action="" method="post">
    <td>Send readings errors</td>
    <td><input type="checkbox" name="senderrors" value="on" <?php 
    echo $a['error'] == 'on' ? 'checked="checked"' : '';
    ?>
 onclick="this.form.submit()" /></td>
    <input type="hidden" name="sende" value="sende" />
</form>
<?php 
}
?>
Example #5
0
<?php

$gpioad = isset($_POST['gpioad']) ? $_POST['gpioad'] : '';
$add = isset($_POST['add']) ? $_POST['add'] : '';
$gpio = isset($_POST['gpio']) ? $_POST['gpio'] : '';
if ($add == "ADD") {
    $db = new PDO('sqlite:dbf/nettemp.db');
    if (!empty($gpioad)) {
        $db->exec("INSERT INTO gpio (gpio, name, status) VALUES ('{$gpio}','new_{$gpio}','OFF')") or die($db->lastErrorMsg());
    } else {
        $db->exec("DELETE FROM gpio WHERE gpio='{$gpio}'") or die($db->lastErrorMsg());
    }
    $db = NULL;
    header("location: " . $_SERVER['REQUEST_URI']);
    exit;
}
?>
<span class="belka">&nbsp Free gpio <span class="okno">
<?php 
exec("/usr/local/bin/gpio -v |grep B+", $bplus);
exec("/usr/local/bin/gpio -v |grep 'Model B, Revision: 2'", $btwo);
exec("/usr/local/bin/gpio -v |grep 'Model B, Revision: 1'", $bone);
exec("/usr/local/bin/gpio -v |grep 'Model 2, Revision: 1.1'", $two);
if (!empty($bplus[0]) || !empty($two[0])) {
    $gpiolist = array(4, 17, 27, 22, 5, 6, 13, 19, 26, 18, 23, 24, 25, 12, 16, 20, 21);
} elseif (!empty($btwo[0])) {
    $gpiolist = array(4, 17, 27, 22, 18, 23, 24, 25, 28, 29, 30, 31);
} elseif (!empty($bone[0])) {
    $gpiolist = array(4, 17, 27, 22, 18, 23, 24, 25);
} else {
    $gpiolist = array(4, 17, 21, 22, 18, 23, 24, 25);
Example #6
0
File: fw.php Project: kstach/test
<?php

$fw_onoff = isset($_POST['fw_onoff']) ? $_POST['fw_onoff'] : '';
$onoff = isset($_POST['onoff']) ? $_POST['onoff'] : '';
if ($onoff == "onoff") {
    $db = new PDO('sqlite:dbf/nettemp.db');
    $db->exec("UPDATE settings SET fw='{$fw_onoff}' WHERE id='1'") or die($db->lastErrorMsg());
    if ($fw_onoff != "on") {
        shell_exec("/bin/bash modules/security/fw/fw off");
    }
    header("location: " . $_SERVER['REQUEST_URI']);
    exit;
}
$db = new PDO('sqlite:dbf/nettemp.db');
$sth = $db->prepare("select * from settings ");
$sth->execute();
$result = $sth->fetchAll();
foreach ($result as $a) {
    $fw = $a["fw"];
}
?>
<span class="belka">&nbsp Firewall settings<span class="okno">



<table>

<tr> <td><h2>Firewall</h2></td>
    <form action="" method="post">
    <td><input type="checkbox" name="fw_onoff" value="on" <?php 
echo $fw == 'on' ? 'checked="checked"' : '';
Example #7
0
?>
 
<?php 
// SQLite - usuwanie alarmu
if (!empty($del_alarm) && $_POST['del_alarm1'] == "del_alarm2") {
    $db = new PDO('sqlite:dbf/nettemp.db');
    $db->exec("UPDATE sensors SET alarm='off' WHERE id='{$del_alarm}'") or die($db->lastErrorMsg());
    header("location: " . $_SERVER['REQUEST_URI']);
    exit;
}
?>
 
<?php 
if (!empty($tmp_id) && $_POST['ok'] == "ok") {
    $db = new PDO('sqlite:dbf/nettemp.db');
    $db->exec("UPDATE sensors SET tmp_min='{$tmp_min_new}' WHERE id='{$tmp_id}'") or die($db->lastErrorMsg());
    $db->exec("UPDATE sensors SET tmp_max='{$tmp_max_new}' WHERE id='{$tmp_id}'") or die($db->lastErrorMsg());
    header("location: " . $_SERVER['REQUEST_URI']);
    exit;
}
$triggernotice_checkbox = isset($_POST['triggernotice_checkbox']) ? $_POST['triggernotice_checkbox'] : '';
$xtriggernoticeon = isset($_POST['xtriggernoticeon']) ? $_POST['xtriggernoticeon'] : '';
if ($xtriggernoticeon == "xtriggernoticeON") {
    //exec("/usr/local/bin/gpio reset $gpio_post ");
    $db = new PDO('sqlite:dbf/nettemp.db') or die("cannot open the database");
    $db->exec("UPDATE gpio SET trigger_notice='{$triggernotice_checkbox}' WHERE gpio='{$gpio_post}'") or die("exec error");
    $db = NULL;
    header("location: " . $_SERVER['REQUEST_URI']);
    exit;
}
?>
Example #8
0
        $db->exec("DELETE FROM sensors WHERE rom='{$usun_rom_nw}'") or die($db->lastErrorMsg());
        //plik rrd
        $rep_del_db = str_replace(" ", "_", $usun_rom_nw);
        $name_rep_del_db = "{$rep_del_db}.rrd";
        //echo $name_rep_del_db;
        unlink("db/{$name_rep_del_db}");
        header("location: " . $_SERVER['REQUEST_URI']);
        exit;
    }
    ?>
      
<?php 
    // SQLite - sekcja zmiany nazwy
    if (!empty($name_new) && !empty($name_id) && $_POST['id_name2'] == "id_name3") {
        $db = new PDO('sqlite:dbf/nettemp.db');
        $db->exec("UPDATE sensors SET name='{$name_new}' WHERE id='{$name_id}'") or die($db->lastErrorMsg());
        if (!empty($color)) {
            $db->exec("UPDATE sensors SET color='{$color}' WHERE id='{$name_id}'") or die($db->lastErrorMsg());
        }
        header("location: " . $_SERVER['REQUEST_URI']);
        exit;
    }
    ?>
 

<?php 
    //read  digitemrc file and 1-wire bus
    foreach (glob("tmp/.digitemp*") as $file_digi) {
        //$file_digi = "tmp/.digitemprc";
        $file_digi2 = file($file_digi);
        foreach ($file_digi2 as $line_digi) {
{
	_log(__FILE__ . " - line " . __LINE__ . ": Connected to database");
}*/
_log(__FILE__ . " - line " . __LINE__ . ": " . isset($_REQUEST['oper']) ? $_REQUEST['oper'] : "No operation found!");
if (isset($_REQUEST['oper'])) {
    try {
        switch ($_REQUEST['oper']) {
            case 'del':
                _log(__FILE__ . " - line " . __LINE__ . ": Inventory request for deletion: " . print_r($_REQUEST, TRUE));
                // explode, then implode adding quotes
                $deleteUUID = explode(",", utf8_decode($_REQUEST['id']));
                $deleteParameters = '"' . implode('","', $deleteUUID) . '"';
                if ($db->query("DELETE FROM Inventory WHERE UUID IN (" . $deleteParameters . ")")) {
                    _log(__FILE__ . " - line " . __LINE__ . ": Inventory(s) deleted: " . $deleteParameters);
                } else {
                    _log(__FILE__ . " - line " . __LINE__ . ": Error deleting inventory(s) \"" . $deleteParameters . "\"! " . $db->lastErrorMsg());
                    exit(0);
                }
                break;
            case 'edit':
                updateRow();
                break;
            case 'add':
                addRow();
                // unsupported
                break;
        }
    } catch (PDOException $e) {
        _log(__FILE__ . " - line " . __LINE__ . ": Some query failed: " . PDO_PREFIX . SQLITE_DB_FILENAME . ": " . $e->getMessage());
        exit(0);
        // flag jQueryGrid that this failed
Example #10
0
// SQLite - update
if ($notif_update1 == "notif_update2") {
    $db = new PDO('sqlite:dbf/snmp.db');
    $db->exec("UPDATE recipient SET sms_alarm='{$notif_update_sms}' WHERE id='{$notif_update}'") or die($db->lastErrorMsg());
    $db->exec("UPDATE recipient SET mail_alarm='{$notif_update_mail}' WHERE id='{$notif_update}'") or die($db->lastErrorMsg());
    header("location: " . $_SERVER['REQUEST_URI']);
    exit;
}
?>
	

<?php 
// SQLite - del
if (!empty($snmp_id) && $_POST['snmp_del1'] == "snmp_del2") {
    $db = new PDO('sqlite:dbf/snmp.db');
    $db->exec("DELETE FROM snmp WHERE id='{$snmp_id}'") or die($db->lastErrorMsg());
    header("location: " . $_SERVER['REQUEST_URI']);
    exit;
}
?>


<span class="belka">&nbsp Add sensor over SNMP<span class="okno">
<table>
<tr><td></td><td>name</td><td>community</td><td>host</td><td>OID</td><td>Divider</td></tr>
<tr>	
	<form action="" method="post">
	<td></td>
	<td><input type="text" name="snmp_name" size="10" value="" /></td>
	<td><input type="text" name="snmp_community" size="7" value="" /></td>
	<td><input type="text" name="snmp_host" size="7" value="" /></td>
Example #11
0
    exec("sh modules/sms/sms_scan");
    exec("rm tmp/gammu_identify");
    header("location: " . $_SERVER['REQUEST_URI']);
    exit;
}
//   $dd = $_POST["dd"];
//	if (!empty($dd) && ($_POST['dd1'] == "dd2") ){
//   	$db = new PDO('sqlite:dbf/nettemp.db');
//   	$db->exec("DELETE FROM sms_settings WHERE id='$dd'") or die ($db->lastErrorMsg());
//   	header("location: " . $_SERVER['REQUEST_URI']);
//   	exit();
//   }
$sd = $_POST["sd"];
if ($_POST['sd1'] == "sd2") {
    $db = new PDO('sqlite:dbf/nettemp.db');
    $db->exec("UPDATE sms_settings SET default_dev='off'") or die($db->lastErrorMsg());
    $db->exec("UPDATE sms_settings SET default_dev='on' WHERE id='{$sd}'") or die($db->lastErrorMsg());
    $sth = $db->prepare("SELECT * FROM sms_settings WHERE id='{$sd}'");
    $sth->execute();
    $result = $sth->fetchAll();
    foreach ($result as $sdd) {
        $ssd1 = $sdd['dev'];
        $fh = fopen('tmp/gammurc', 'w');
        fwrite($fh, "[gammu]\n");
        fwrite($fh, "port={$ssd1}\n");
        fwrite($fh, "connection=at\n");
        fclose($fh);
    }
    exec("gammu -c tmp/gammurc identify > tmp/gammu_identify");
    header("location: " . $_SERVER['REQUEST_URI']);
    exit;
Example #12
0
<?php

$am_onoff = isset($_POST['am_onoff']) ? $_POST['am_onoff'] : '';
$onoff = isset($_POST['onoff']) ? $_POST['onoff'] : '';
if ($onoff == "onoff") {
    $db = new PDO('sqlite:dbf/nettemp.db');
    $db->exec("UPDATE settings SET authmod='{$am_onoff}' WHERE id='1'") or die($db->lastErrorMsg());
    if ($am_onoff == "on") {
        shell_exec("sudo lighttpd-enable-mod auth");
        shell_exec("sudo service lighttpd reload");
    }
    if ($am_onoff != "on") {
        shell_exec("sudo lighttpd-disable-mod auth");
        shell_exec("sudo service lighttpd reload");
    }
    header("location: " . $_SERVER['REQUEST_URI']);
    exit;
}
$db = new PDO('sqlite:dbf/nettemp.db');
$sth = $db->prepare("select * from settings ");
$sth->execute();
$result = $sth->fetchAll();
foreach ($result as $a) {
    $am = $a["authmod"];
}
?>
<span class="belka">&nbsp Authmod - WWW access <span class="okno">



<table>
Example #13
0
<?php

$test_mail = isset($_POST['test_mail']) ? $_POST['test_mail'] : '';
$mail_test1 = isset($_POST['mail_test1']) ? $_POST['mail_test1'] : '';
if ($mail_test1 == "mail_test2") {
    $test_mail1 = escapeshellarg($test_mail);
    $cmd = "modules/mail/mail_test {$test_mail1} 'Test from your nettemp device' 'Test mail from Your nettemp device.'";
    shell_exec($cmd);
    $db = new PDO('sqlite:dbf/nettemp.db');
    $db->exec("UPDATE mail_settings SET test_mail='{$test_mail}'") or die($db->lastErrorMsg());
}
?>

<?php 
$db = new PDO('sqlite:dbf/nettemp.db');
$sth = $db->prepare("select * from mail_settings ");
$sth->execute();
$result = $sth->fetchAll();
foreach ($result as $a) {
    ?>

<table>
<tr>	
    <form action="settings" method="post">
    <td>Send test mail to:</td>
    <td><input type="text" name="test_mail" size="25" value="<?php 
    echo $a["test_mail"];
    ?>
" /></td>
    <input type="hidden" name="mail_test1" value="mail_test2" />
    <td><input type="image" src="media/ico/Actions-edit-redo-icon.png"  /></td>
Example #14
0
     header("location: " . $_SERVER['REQUEST_URI']);
     exit;
 }
 $ss_onoff = isset($_POST['ss_onoff']) ? $_POST['ss_onoff'] : '';
 $ss_onoff1 = isset($_POST['ss_onoff1']) ? $_POST['ss_onoff1'] : '';
 if ($ss_onoff1 == "ss_onoff2") {
     $db = new PDO('sqlite:dbf/nettemp.db');
     $db->exec("UPDATE settings SET sms='{$ss_onoff}' WHERE id='1'") or die($db->lastErrorMsg());
     header("location: " . $_SERVER['REQUEST_URI']);
     exit;
 }
 $ms_onoff = isset($_POST['ms_onoff']) ? $_POST['ms_onoff'] : '';
 $ms_onoff1 = isset($_POST['ms_onoff1']) ? $_POST['ms_onoff1'] : '';
 if ($ms_onoff1 == "ms_onoff2") {
     $db = new PDO('sqlite:dbf/nettemp.db');
     $db->exec("UPDATE settings SET mail='{$ms_onoff}' WHERE id='1'") or die($db->lastErrorMsg());
     header("location: " . $_SERVER['REQUEST_URI']);
     exit;
 }
 $db = new PDO('sqlite:dbf/nettemp.db');
 $sth = $db->prepare("select * from settings WHERE id='1'");
 $sth->execute();
 $result = $sth->fetchAll();
 foreach ($result as $a) {
     $rrd = $a["rrd"];
     $hc = $a["highcharts"];
     $ss = $a["sms"];
     $ms = $a["mail"];
     $gpio = $a["gpio"];
     $lcd = $a["lcd"];
 }
Example #15
0
$notif_update1 = isset($_POST['notif_update1']) ? $_POST['notif_update1'] : '';
if ($notif_update1 == "notif_update2") {
    $db = new PDO('sqlite:dbf/nettemp.db');
    $db->exec("UPDATE recipient SET sms_alarm='{$notif_update_sms}' WHERE id='{$notif_update}'") or die($db->lastErrorMsg());
    $db->exec("UPDATE recipient SET mail_alarm='{$notif_update_mail}' WHERE id='{$notif_update}'") or die($db->lastErrorMsg());
    header("location: " . $_SERVER['REQUEST_URI']);
    exit;
}
?>
	

<?php 
// SQLite - usuwanie notification
if (!empty($notif_del) && $_POST['notif_del1'] == "notif_del2") {
    $db = new PDO('sqlite:dbf/nettemp.db');
    $db->exec("DELETE FROM recipient WHERE id='{$notif_del}'") or die($db->lastErrorMsg());
    header("location: " . $_SERVER['REQUEST_URI']);
    exit;
}
?>


<span class="belka">&nbsp Add user<span class="okno">
<table>
<tr>
<td><img src="media/ico/User-Preppy-Blue-icon.png"> Name</td>
<td><img src="media/ico/message-icon.png"> Email</td>
<td><img src="media/ico/phone-blue-glow-icon.png"> Telephone</td>
<td><img src="media/ico/message-icon.png"></td>
<td><img src="media/ico/phone-blue-glow-icon.png"></td>
<td></td>
Example #16
0
if (!empty($smsc) && $_POST['smsc1'] == "smsc2") {
    $db = new PDO('sqlite:dbf/nettemp.db');
    $db->exec("UPDATE sms_settings SET smsc='{$smsc}' WHERE default_dev='on'") or die($db->lastErrorMsg());
    $set_smsc = "gammu -c tmp/gammurc setsmsc 1 {$smsc}";
    shell_exec($set_smsc);
    header("location: " . $_SERVER['REQUEST_URI']);
    exit;
}
?>
 

<?php 
$sms_test = $_POST["sms_test"];
if ($_POST['sms_test1'] == "sms_test2") {
    $db = new PDO('sqlite:dbf/nettemp.db');
    $db->exec("UPDATE sms_settings SET sms_test='{$sms_test}' WHERE default_dev='on'") or die($db->lastErrorMsg());
    $cmd = "modules/sms/sms_test";
    shell_exec($cmd);
}
?>


<?php 
$db = new PDO('sqlite:dbf/nettemp.db');
$sth = $db->prepare("select * from sms_settings WHERE default_dev='on' ");
$sth->execute();
$result = $sth->fetchAll();
foreach ($result as $a) {
    ?>
<table><tr>
<form action="" method="post"> 	
Example #17
0
    $dbnew = new PDO("sqlite:db/{$host_name}.sql");
    $dbnew->exec('CREATE TABLE def (time DATETIME DEFAULT CURRENT_TIMESTAMP, value INTEEGER)');
    $dbnew == NULL;
    header("location: " . $_SERVER['REQUEST_URI']);
    exit;
} elseif ($host_add1 == "host_add2") {
    echo " Please input name and IP";
}
?>
	

<?php 
// SQLite - del
if (!empty($host_name) && $_POST['host_del1'] == "host_del2") {
    $db = new PDO('sqlite:dbf/hosts.db');
    $db->exec("DELETE FROM hosts WHERE name='{$host_name}'") or die($db->lastErrorMsg());
    unlink("db/{$host_name}.sql");
    header("location: " . $_SERVER['REQUEST_URI']);
    exit;
}
?>


<span class="belka">&nbsp Add host to monitoring<span class="okno">
<table>
<tr><td></td><td>name</td><td>ip or name</td><td>type</td></tr>
<tr>	
	<form action="" method="post">
	<td></td>
	<td><input type="text" name="host_name" size="10" value="" /></td>
	<td><input type="text" name="host_ip" size="7" value="" /></td>