/** * 发送控制指令 * * @param params params */ protected static function control($params, $cmd) { if (!isset($params["mid"])) { return Error::getRetString(10007); } $mid = $params["mid"]; $uuid = $_GET["uuid"]; $udid = $_GET["udid"]; $db = Db::init(); //验证用户 $user = $db->get_var("select user from user where uuid=\"{$uuid}\""); if (!isset($user)) { return Error::getRetString(10009); } //uuid无效 if ($db->query(<<<EOD select mid from device_modules where mid="{$mid}" and udid="{$udid}" and exists(select udid from user_device where user="******" and udid="{$udid}") EOD )) { //本地验证成功,开始与设备进行通信 $string = file_get_contents("php://input"); return self::sendToDevice($string, $uuid, $udid, $uuid); return Error::getRetString(0); } else { return Error::getRetString(10016); } return Error::getRetString(0, array("uuid" => $uuid, "udid" => $udid, "cmd" => $cmd)); }
static function init() { // override autoloader spl_autoload_register('SnS::autoload'); self::$files_base = dirname(dirname(__FILE__)) . "/files/"; Db::init(); }
public static function run($string, $udid, $email) { $ret = DeviceControl::sendTo($string, $email, $udid, $email); $array = Protocol::decode($ret); if (isset($array["result"])) { $ret_string = $array["result"]; $data = $array["result"]; $json = json_decode($string, true); $mid = $json["params"]["mid"]; $db = Db::init(); switch ($json["method"]) { case "TurnOn": _Notify::add($mid, $_GET["u"], "开启"); $stat = 1; break; case "TurnOff": _Notify::add($mid, $_GET["u"], "关闭"); $stat = 0; break; default: $stat = 0; } $db->query("update device set stat={$stat} where mid='{$mid}'"); } else { if (isset($array["data"])) { $ret_string = $data; } else { $ret_string = $ret; //echo Error::getRetString(-1); } } return $ret_string; }
static function init() { $version_file = APP_PATH . '/../version'; if (file_exists($version_file)) { self::$version = trim(@file_get_contents($version_file)); } $config_file = APP_PATH . '/config/config.php'; if (!file_exists($config_file)) { throw new Exception("No config file"); } $config = (include $config_file); self::$config = $config; self::$env = $config['env']; #self::$context = new stdClass(); self::$context = new Context(); Logger::init($config['logger']); if (isset($config['db'])) { Db::init($config['db']); } if (get_magic_quotes_gpc()) { foreach ($_GET as $k => $v) { $_GET[$k] = Text::stripslashes($v); } foreach ($_POST as $k => $v) { $_POST[$k] = Text::stripslashes($v); } foreach ($_COOKIE as $k => $v) { $_COOKIE[$k] = Text::stripslashes($v); } } $_REQUEST = $_GET + $_POST + $_COOKIE; }
public static function add($mid, $did, $email, $msg) { $db = Db::init(); date_default_timezone_set("Asia/Chongqing"); $name = $db->get_var("select name from device where did='{$did}'"); $msg = $name . " " . $msg; // $time = (string)date("H:i:s"); $time = (string) date("m-d h:ia"); return $db->query("insert into user_notify(mid, did, email, msg, time) select '{$mid}', '{$did}', '{$email}', '{$msg}', '{$time}' from dual"); }
function verify_user($user) { $db = Db::init(); $result = $db->get_results("select user from authorization where stat=1 and user='******'"); //var_dump($result); if (isset($result[0])) { return true; } return false; }
public static function _List($params) { $db = Db::init(); $tdidlist = $db->get_col("select user from authorization where stat=1"); $results = array(); foreach ($tdidlist as $tdid) { $results[] = array("user" => $tdid); } return json_encode(array("code" => 0, "msg" => "ok", "results" => $results)); }
function _turn($params, $code, $all = false) { $db = Db::init(); if ($all == true || isset($params["mid"]) && isset($params["no"])) { $mid = strtoupper($params["mid"]); $no = $params["no"]; $type = substr($mid, 0, 1) . "\n"; if (verify_mid($mid) == false) { //id不存在 return json_encode(array('code' => 30004, 'msg' => "mid no exist")); } $data = $db->get_var('SELECT number FROM "switch_info" where switchid="' . $mid . '"'); if (isset($data)) { $data = sprintf("%02X", $data); switch ($type) { case '1': //电池版开关 $json = array("id" => "{$mid}", "code" => $code, "param" => 1 << $no - 1, "data" => "{$data}", "timeout" => 2000, "response" => 0); break; case '4': //零火版开关 //零火版开关 default: $json = array("id" => "{$mid}", "code" => $code, "param" => 1 << $no - 1, "data" => "{$data}", "timeout" => 500, "response" => 0); break; } for ($i = 0; $i < 100; $i++) { $res = Uart::send(json_encode($json)); if (isset($res["stat"])) { switch ($res["stat"]) { case 0: return json_encode(array('code' => 0, 'msg' => "ok")); break; case 40004: //射频模块正忙 usleep(200000); continue; return json_encode(array('code' => 30006, 'msg' => "system is busy")); default: return json_encode(array('code' => 32004, 'msg' => "communication fault(" . $res["stat"] . ")")); } } } return json_encode(array('code' => 32004, 'msg' => "communication fault(" . $res["stat"] . ")")); } else { //读数据库错误 return json_encode(array('code' => 30005, 'msg' => "read data from database error")); } } else { return json_encode(array('code' => 30003, 'msg' => "params error")); //参数不完整 } }
/** * * @param params params */ public static function _Login($params) { if (is_array($params) && isset($params["account"])) { $account = $params["account"]; $db = Db::init(); $uuid = self::createUUID(); if ($db->query("select email from user where email=\"{$account}\"")) { $db->query("update user set uuid=\"{$uuid}\" where email=\"{$account}\""); return Error::getRetString(0, array("uuid" => $uuid)); } } else { return Error::getRetString(10007); } }
/** * * Simpler Konstruktor * benötigt alle Daten zum Online Banking Account * * @param String $bank_code (Bankleitzahl) * @param String $banking_login (Benutzerkennung) * @param String $banking_pin (Pin) * @param String $account_number (Kontonummer) * @param string $bank_user_name (Name des Kontoinhabers) * @param string $tanmedium_id (Tan-Medium ID z.B. Bezeichnung der Mobilnummer bei Sparkasse) * @param string $locale (Länderkennung) * */ public function __construct($bank_code, $banking_login, $banking_pin, $account_number, $bank_user_name = false, $tanmedium_id = false, $locale = 'DE') { $this->shell = new Exec(); $this->is = ''; $this->config_dir = DIR_AQCONFIG . $bank_code . '/' . $banking_login; if (!DEBUG) { $this->is = ' --noninteractive'; } $this->locale = $locale; if (($this->bank = $this->findBank($bank_code)) === false) { error('Bank ' . $bank_code . ' not available'); } $this->bank_code = $bank_code; $this->banking_login = $banking_login; $this->banking_pin = $banking_pin; $this->bank_user_name = $bank_user_name; if ($account_number === false) { $account_number = $banking_login; } $this->account_number = $account_number; $this->aqcli = 'aqbanking-cli' . $this->is . ' -P "' . $this->config_dir . '/pinfile" -D "' . $this->config_dir . '/config' . '"'; if (!$this->checkConfigDir()) { $this->makePinFile(); $this->decrypt_keyfile(); $this->addUser(); $this->checklogin(); Db::init($this->config_dir); Db::createTables(); if ($tanmedium_id !== false) { $this->setTanmediumId($tanmedium_id); } //echo "\n\n".$tanmedium_id."\n\n"; $this->getItanModes(); $this->getAccSepa(); } else { if ($tanmedium_id !== false) { $this->makePinFile(); $this->decrypt_keyfile(); $this->checklogin(); Db::init($this->config_dir); $this->setTanmediumId($tanmedium_id); } } $this->generateIBAN(); }
function execute(WebApp $app) { // 载入节点数据 require_once API_ROOT . 'StorageExport.php'; $nodes = (new StorageExport())->getNodes(); $curNodeId = Conf::get('node_id'); if (!$curNodeId) { $curNodeId = isset($_SERVER['STORAGE_NODE_ID']) ? intval($_SERVER['STORAGE_NODE_ID']) : 0; if ($curNodeId > 0) { Conf::set('node_id', $curNodeId); } } if (!$curNodeId) { throw new Exception('node.u_args node_id not defined'); } // if (!isset($nodes[$curNodeId])) { // throw new Exception('node.u_curnodeNotFound node_id='.$curNodeId); // } Logger::addBasic(array('node_id' => $curNodeId)); $dbConfs = Conf::get('db.conf'); foreach ($nodes as $node) { // 设定好当前节点的数据库 $cdb = $node['node_db']; $confs = parse_url($cdb); if (!isset($confs['port'])) { $confs['port'] = 3306; } $confs['path'] = trim($confs['path'], '/'); $confs['charset'] = 'utf8'; if (isset($confs['query'])) { parse_str($confs['query'], $args); if (isset($args['charset']) && $args['charset'] != 'utf8') { $confs['charset'] = $args['charset']; } } $key = 'node' . $node['node_id']; $dbConfs['db_pool'][$key] = array('ip' => $confs['host'], 'user' => $confs['user'], 'pass' => $confs['pass'], 'port' => $confs['port'], 'charset' => $confs['charset']); $dbConfs['dbs'][$key] = $key; $dbConfs['db_alias'][$key] = $confs['path']; } Db::init($dbConfs); Conf::set('db.conf', $dbConfs); }
public static function _VerifyUUID($params) { if (is_array($params) && isset($params['uuid']) && isset($params['email'])) { $uuid = $params['uuid']; $email = $params['email']; $db = Db::init(); if ($db->query("select email from user where email=\"{$email}\"")) { $results = $db->get_result("select uuid from user where email=\"{$email}\""); if (isset($results[0])) { foreach ($results as $re) { if ($re['uuid'] === $uuid) { $results = $db->get_result("select mid,vercode,name from udevice where email=\"{$email}\""); return Error::getRetString(0, results); } } } } else { return Error::getRetString(10007); } } }
/** * * @param params 参数列表 */ public static function _Rename($params) { if (is_array($params) && isset($params["user"]) && isset($params["udid"]) && isset($params["name"])) { $user = $params["user"]; $name = $params["name"]; $uuid = $_GET["uuid"]; $udid = $params["udid"]; $db = Db::init(); //执行主机改名 if ($db->query(<<<EOD update user_device set name="{$name}" WHERE EXISTS(SELECT user FROM user WHERE uuid="{$uuid}" and user="******" and priv=3) and user="******" and udid="{$udid}"; EOD )) { return Error::getRetString(0); } else { return Error::getRetString(10016); } } else { return Error::getRetString(10007); } }
public static function _GetDatebase($params) { $db = Db::init(); $res = $db->get_results("SELECT name FROM sqlite_master WHERE type='table' ORDER BY name;"); //var_dump($res); $arr_tables = array(); //遍历表 foreach ($res as $table) { $recodes = $db->get_results("SELECT * FROM {$table->name};"); $arr_tables["{$table->name}"] = array(); //遍历表中所有元素 foreach ($recodes as $rec) { $arr_record = array(); //保存所有元素 foreach ($rec as $class => $value) { $arr_record["{$class}"] = $value; } $arr_tables["{$table->name}"][] = $arr_record; } } return json_encode($arr_tables); }
/** * 使能托管模式 * * @param params params */ public static function _Enable($params) { file_put_contents("./test.txt", "run\n", FILE_APPEND); $db = Db::init(); $time = $params['time']; $results = $db->get_results("select assid from assistant where time='{$time}'"); if (isset($results[0])) { foreach ($results as $re) { $invokes = $db->get_results("select * from assi_info where assid={$re->assid}"); if (isset($invokes[0])) { foreach ($invokes as $invoke) { $row = $db->get_row("select assisEn, notify from device where did='{$invoke->did}'"); //var_dump($invoke); if ($row->assisEn == 1) { file_put_contents("./test.txt", "actionrun\n", FILE_APPEND); Action::run($invoke->cmdline, $invoke->mid, '慧管家'); } } } } } }
/** * 同步登录 * @param array $get * @param array $post */ public static function synlogin($get, $post) { Db::init(array('host' => UC_DBHOST, 'name' => UC_DBNAME, 'user' => UC_DBUSER, 'pass' => UC_DBPW, 'charset' => UC_DBCHARSET, 'persistent' => UC_DBCONNECT), 'ucenter'); $user = Db::read(UC_DBTABLEPRE . 'members', $get['uid'], 'uid'); if ($get['username'] == $user['username'] && $get['password'] == $user['password']) { header('P3P: CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"'); Db::switchDb(); // 是否存在相同用户名的账号 $uid = Db::read(User::$tbl, $user['username'], 'username', 'uid'); if ($uid) { //直接登录 $ret = User::loginNoVerify($get['username']); } else { //创建用户(方法内已自动登录) $data = array('no_verify_data' => true, 'status' => 1, 'username' => $get['username'], 'password' => '', 'uc_password' => $get['password'], 'open_name' => 'ucenter', 'open_uid' => $get['uid'], 'open_username' => $get['username'], 'accredit_time' => $get['password']); $ret = User::create($data); } return API_RETURN_SUCCEED; } else { return API_RETURN_FAILED; } }
/** * * @param params params */ public static function _GetInfo($params) { if (isset($params["email"])) { $db = Db::init(); $email = $params["email"]; //是否已存在 if (!$db->query(<<<EOD select email from user where email="{$email}" EOD )) { return Error::getRetString(10020); } $info = $db->get_row("select * from user where email='{$email}'"); return Error::getRetString(0, array("name" => $info->name, "email" => $info->email, "sex" => $info->sex, "phone" => $info->phone, "QQ" => $info->QQ, "address" => $info->address)); } else { return Error::getRetString(10007); } }
{ protected static $_dbh; /* constructor */ private function __construct() { try { self::$_dbh = new PDO('mysql:host=' . DB_HOST . ';dbname=' . DB_NAME . ';charset=UTF8', DB_USER, DB_PASS); } catch (PDOException $e) { die; } } /* initializes a dababase object if one does not exist */ public static function init() { if (!self::$_dbh) { new Db(); } } /* gets a database handler or create a new one if one does not exist */ public static function getDbh() { self::init(); return self::$_dbh; } /* magic clone */ public function __clone() { } } Db::init();
public static function _GetEnable($params) { if (isset($params["mid"])) { $mid = $params["mid"]; $db = Db::init(); $assid = $db->get_var("select assid from mdevice where mid=\"{$mid}\""); if ($assid == 1) { $ad = true; } else { $ad = false; } return Error::getRetString(0, array("Enable" => $ad)); } else { return Error::getRetString(10007); } }
/** * * @param params params */ public static function _AssisEnable($params) { if (is_array($params) && isset($params["roomid"]) && isset($params["did"]) && isset($params["assisEn"])) { $email = $_GET["u"]; $roomid = $params["roomid"]; $did = $params["did"]; $assisEn = $params["assisEn"]; $db = Db::init(); if ($db->query(<<<EOD UPDATE device set assisEn='{$assisEn}' WHERE EXISTS(SELECT roomid FROM room WHERE roomid="{$roomid}") and did='{$did}' and roomid='{$roomid}'; EOD )) { //成功 return Error::getRetString(0); } else { //区域不存在 return Error::getRetString(10021); } } else { return Error::getRetString(10007); } }
<?php namespace Redaxscript; /* include as needed */ include_once 'includes/Autoloader.php'; include_once 'stubs/hook_function.php'; include_once 'stubs/hook_method.php'; include_once 'TestCase.php'; /* init */ Autoloader::init(); Request::init(); /* set config */ Config::set('type', 'mysql'); Config::set('host', 'redaxscript.com'); Config::set('name', 'd01ae38a'); Config::set('user', 'd01ae38a'); Config::set('password', 'travis'); /* registry and config */ $registry = Registry::getInstance(); $config = Config::getInstance(); /* database and hook */ Db::init($config); Hook::init($registry); /* language */ $language = Language::getInstance(); $language::init('en');
public function __construct() { $this->_db = Db::init(); }
/** * * @param params params */ public static function _ListAll($params) { $uuid = $_GET["uuid"]; $db = Db::init(); $user = $db->get_var("select user from user where uuid=\"{$uuid}\""); if (!isset($user)) { return Error::getRetString(10009); } //uuid无效 $re = array("rooms" => array()); $results = $db->get_results("select roomid,name from user_room where user=\"{$user}\""); if (isset($results[0])) { foreach ($results as $rec) { $roomid = $rec->roomid * 1; $list = array(); $modules = $db->get_results("select * from device_modules where roomid={$roomid}"); //有模块 if (isset($modules[0])) { foreach ($modules as $mod) { $ch_info = array(); $m = $mod->mid; $children = $db->get_results("select * from device_modules_child where mid=\"{$m}\" order by no"); foreach ($children as $child) { $ch_name = $child->name; $ch_no = $child->no * 1; $ch_info[] = array("no" => $ch_no, "name" => $ch_name); } $list[] = array("udid" => $mod->udid, "mid" => $mod->mid, "devclass" => $mod->type, "name" => $ch_info); } } $re["rooms"][] = array("roomid" => $roomid, "name" => $rec->name, "devices" => $list); } } return Error::getRetString(0, $re); }
/** * 执行情景模式 * * @param params params */ public static function _Excute($params) { if (isset($params["sceneid"])) { $sceneid = $params["sceneid"]; $db = Db::init(); $invokes = $db->get_results("select * from scene_info where sceneid={$sceneid}"); if (isset($invokes[0])) { foreach ($invokes as $invoke) { //var_dump($invoke); Action::run($invoke->cmdline, $invoke->mid, $_GET["u"]); } } return Error::getRetString(0); } else { return Error::getRetString(10007); } }
/** * * @param params params */ public static function _List($params) { if (is_array($params) && isset($params["houseid"])) { $db = Db::init(); $email = $_GET["u"]; $houseid = $params["houseid"]; $re = array("rooms" => array()); $results = $db->get_results(<<<EOD select roomid,name from room where houseid={$houseid} and exists(select houseid from house where houseid={$houseid} and email="{$email}") EOD ); if (isset($results[0])) { foreach ($results as $rec) { $re["rooms"][] = array("roomid" => $rec->roomid * 1, "name" => $rec->name); } } return Error::getRetString(0, $re); } else { return Error::getRetString(10007); } }
/** * 修改情景模式 * * @param params params */ public static function _Modify($params) { if (isset($params["name"]) && isset($params["sceneid"]) && is_array($params["invokes"])) { $name = $params["name"]; $sceneid = $params["sceneid"]; $db = Db::init(); $uuid = $_GET["email"]; $user = $db->get_var("select user from user where email=\"{$uuid}\""); if (!isset($user)) { return Error::getRetString(10009); } //uuid无效 $results = $db->get_results('SELECT * FROM scene WHERE sceneid="' . $sceneid . '" and user="******"'); if (!isset($results[0])) { //情景模式不存在 return Error::getRetString(31001); //情景模式名称不存在 } $db->query('UPDATE scene SET `name`=\'' . $name . '\' WHERE `sceneid`=' . $sceneid); //$db->query('INSERT INTO scene (name, user) VALUES ("'.$name.'", "'.$user.'")'); //$scene_id = $db->get_var('select sceneid from scene where name="'.$name.'" and user="******"'); $db->query("delete from scene_info where sceneid={$sceneid};"); //保存情景模式命令行 $invokes = $params["invokes"]; foreach ($invokes as $no => $cmdline) { //处理命令序列 if (isset($cmdline["class"]) && isset($cmdline["method"]) && isset($cmdline["params"]) && isset($cmdline["params"]["did"])) { $lmid = strtoupper($cmdline["params"]["did"]); $udid = $db->get_var("select udid from device_modules where mid=\"{$lmid}\""); $db->query('INSERT INTO scene_info(`sceneid`,`order`,`cmdline`,`mid`,`did`) VALUES (' . $sceneid . ',' . $no . ',\'' . json_encode($cmdline) . '\',\'' . strtoupper($cmdline["params"]["did"]) . '\', \'' . $udid . '\')'); } else { return Error::getRetString(31004); //情景模式invoke列表格式错误。 } } return Error::getRetString(0, array("sceneid" => $sceneid)); //成功 } else { return Error::getRetString(10007); } }
public function __construct() { //initialize connection to database $this->_db = Db::init(); }
private static function getInfo($mid, $time) { $msg = $house_n = $room_n = $user_n = ""; // $email = $_GET["u"]; $db = Db::init(); if ($room = $db->get_row("select roomid, name from device where mid='{$mid}'")) { $room_n = $room->name; if ($house = $db->get_row("select houseid, name, email from room where roomid={$room->roomid}")) { $user = $db->get_row("select name from room where houseid={$house->houseid}"); $msg = $db->get_row("select msg,time from user_notify where mid='{$mid}'"); $house_n = $house->name; $user_n = $user->name; } } $arr = array("house" => (string) $house_n, "room" => (string) $room_n, "user" => (string) $user_n, "time" => (string) $time, "msg" => (string) isset($msg->msg) ? $msg->msg : null); return $arr; //return urldecode(json_encode($arr)); }
/** * * @param params params */ public static function _List($params) { $db = Db::init(); $email = $_GET["u"]; $re = array("houses" => array()); $results = $db->get_results("select houseid,name,mid,vercode from house where email=\"{$email}\""); if (isset($results[0])) { foreach ($results as $rec) { $re["houses"][] = array("houseid" => intval($rec->houseid), "name" => (string) $rec->name, "mid" => (string) $rec->mid, "vercode" => (string) $rec->vercode); } } return Error::getRetString(0, $re); }
<?php require_once __DIR__ . "/libs/db/db.php"; require_once __DIR__ . "/libs/functions.php"; $db = Db::init(); $res = $db->get_results("SELECT name FROM sqlite_master WHERE type='table' ORDER BY name;"); //var_dump($res); $arr_tables = array(); //遍历表 if (is_array($res)) { foreach ($res as $table) { $recodes = $db->get_results("SELECT * FROM {$table->name};"); $arr_tables["{$table->name}"] = array(); //遍历表中所有元素 if (is_array($recodes)) { foreach ($recodes as $rec) { $arr_record = array(); //保存所有元素 foreach ($rec as $class => $value) { $arr_record["{$class}"] = $value; } $arr_tables["{$table->name}"][] = $arr_record; } } } } echo json_encode($arr_tables);