function install_post(&$a) { global $db; $urlpath = $a->get_path(); $dbhost = notags(trim($_POST['dbhost'])); $dbuser = notags(trim($_POST['dbuser'])); $dbpass = notags(trim($_POST['dbpass'])); $dbdata = notags(trim($_POST['dbdata'])); $timezone = notags(trim($_POST['timezone'])); $phpath = notags(trim($_POST['phpath'])); $adminmail = notags(trim($_POST['adminmail'])); require_once "dba.php"; unset($db); $db = new dba($dbhost, $dbuser, $dbpass, $dbdata, true); if (get_db_errno()) { unset($db); $db = new dba($dbhost, $dbuser, $dbpass, '', true); if (!get_db_errno()) { $r = q("CREATE DATABASE '%s'", dbesc($dbdata)); if ($r) { unset($db); $db = new dba($dbhost, $dbuser, $dbpass, $dbdata, true); } } if (get_db_errno()) { notice(t('Could not create/connect to database.') . EOL); return; } } info(t('Connected to database.') . EOL); $tpl = get_intltext_template('htconfig.tpl'); $txt = replace_macros($tpl, array('$dbhost' => $dbhost, '$dbuser' => $dbuser, '$dbpass' => $dbpass, '$dbdata' => $dbdata, '$timezone' => $timezone, '$urlpath' => $urlpath, '$phpath' => $phpath, '$adminmail' => $adminmail)); $result = file_put_contents('.htconfig.php', $txt); if (!$result) { $a->data['txt'] = $txt; } $errors = load_database($db); if ($errors) { $a->data['db_failed'] = true; } else { $a->data['db_installed'] = true; } return; }
function install_post(&$a) { global $db; $dbhost = notags(trim($_POST['dbhost'])); $dbuser = notags(trim($_POST['dbuser'])); $dbpass = notags(trim($_POST['dbpass'])); $dbdata = notags(trim($_POST['dbdata'])); $timezone = notags(trim($_POST['timezone'])); $phpath = notags(trim($_POST['phpath'])); require_once "dba.php"; $db = new dba($dbhost, $dbuser, $dbpass, $dbdata, $true); if (mysqli_connect_errno()) { notice(t('Could not connect to database.') . EOL); return; } else { notice(t('Connected to database.') . EOL); } $tpl = file_get_contents('view/htconfig.tpl'); $txt = replace_macros($tpl, array('$dbhost' => $dbhost, '$dbuser' => $dbuser, '$dbpass' => $dbpass, '$dbdata' => $dbdata, '$timezone' => $timezone, '$phpath' => $phpath)); $result = file_put_contents('.htconfig.php', $txt); if (!$result) { $a->data = $txt; } $errors = load_database($db); if (!$errors) { // Our sessions normally are stored in the database. But as we have only managed // to get it bootstrapped milliseconds ago, we have to apply a bit of trickery so // that you'll see the following important notice (which is stored in the session). session_write_close(); require_once 'session.php'; session_start(); $_SESSION['sysmsg'] = ''; notice(t('Database import succeeded.') . EOL . t('IMPORTANT: You will need to (manually) setup a scheduled task for the poller.') . EOL . t('Please see the file INSTALL.') . EOL); goaway($a->get_baseurl()); } else { $db = null; // start fresh notice(t('Database import failed.') . EOL . t('You may need to import the file "database.sql" manually using phpmyadmin or mysql.') . EOL . t('Please see the file INSTALL.') . EOL); } }
function install_post(&$a) { global $install_wizard_pass, $db; switch ($install_wizard_pass) { case 1: case 2: return; break; // just in case return don't return :) // just in case return don't return :) case 3: $urlpath = $a->get_path(); $dbhost = notags(trim($_POST['dbhost'])); $dbuser = notags(trim($_POST['dbuser'])); $dbpass = notags(trim($_POST['dbpass'])); $dbdata = notags(trim($_POST['dbdata'])); $phpath = notags(trim($_POST['phpath'])); require_once "include/dba.php"; unset($db); $db = new dba($dbhost, $dbuser, $dbpass, $dbdata, true); /*if(get_db_errno()) { unset($db); $db = new dba($dbhost, $dbuser, $dbpass, '', true); if(! get_db_errno()) { $r = q("CREATE DATABASE '%s'", dbesc($dbdata) ); if($r) { unset($db); $db = new dba($dbhost, $dbuser, $dbpass, $dbdata, true); } else { $a->data['db_create_failed']=true; } } else { $a->data['db_conn_failed']=true; return; } }*/ if (get_db_errno()) { $a->data['db_conn_failed'] = true; } return; break; case 4: $urlpath = $a->get_path(); $dbhost = notags(trim($_POST['dbhost'])); $dbuser = notags(trim($_POST['dbuser'])); $dbpass = notags(trim($_POST['dbpass'])); $dbdata = notags(trim($_POST['dbdata'])); $phpath = notags(trim($_POST['phpath'])); $timezone = notags(trim($_POST['timezone'])); $adminmail = notags(trim($_POST['adminmail'])); // connect to db $db = new dba($dbhost, $dbuser, $dbpass, $dbdata, true); $tpl = get_intltext_template('htconfig.tpl'); $txt = replace_macros($tpl, array('$dbhost' => $dbhost, '$dbuser' => $dbuser, '$dbpass' => $dbpass, '$dbdata' => $dbdata, '$timezone' => $timezone, '$urlpath' => $urlpath, '$phpath' => $phpath, '$adminmail' => $adminmail)); $result = file_put_contents('.htconfig.php', $txt); if (!$result) { $a->data['txt'] = $txt; } $errors = load_database($db); if ($errors) { $a->data['db_failed'] = $errors; } else { $a->data['db_installed'] = true; } return; break; } }
function DeleteInstall() { global $txt, $HTTP_SESSION_VARS, $incontext; global $current_smf_version, $sourcedir, $forum_version, $modSettings, $user_info, $db_type; $incontext['page_title'] = $txt['congratulations']; $incontext['sub_template'] = 'delete_install'; $incontext['continue'] = 0; require dirname(__FILE__) . '/Settings.php'; load_database(); chdir(dirname(__FILE__)); require_once $sourcedir . '/Errors.php'; require_once $sourcedir . '/lib/Subs.php'; require_once $sourcedir . '/CommonAPI.php'; require_once $sourcedir . '/Load.php'; require_once $sourcedir . '/Security.php'; require_once $sourcedir . '/lib/Subs-Auth.php'; // Bring a warning over. if (!empty($incontext['account_existed'])) { $incontext['warning'] = $incontext['account_existed']; } smf_db_query(' SET NAMES utf8', array()); // As track stats is by default enabled let's add some activity. smf_db_insert('ignore', '{db_prefix}log_activity', array('date' => 'date', 'topics' => 'int', 'posts' => 'int', 'registers' => 'int'), array(strftime('%Y-%m-%d', time()), 1, 1, !empty($incontext['member_id']) ? 1 : 0), array('date')); // Automatically log them in ;) if (isset($incontext['member_id']) && isset($incontext['member_salt'])) { setLoginCookie(3153600 * 60, $incontext['member_id'], sha1(sha1(strtolower($_POST['username']) . $_POST['password1']) . $incontext['member_salt'])); } $result = smf_db_query(' SELECT value FROM {db_prefix}settings WHERE variable = {string:db_sessions}', array('db_sessions' => 'databaseSession_enable', 'db_error_skip' => true)); if (mysql_num_rows($result) != 0) { list($db_sessions) = mysql_fetch_row($result); } mysql_free_result($result); if (empty($db_sessions)) { if (@version_compare(PHP_VERSION, '4.2.0') == -1) { $HTTP_SESSION_VARS['php_412_bugfix'] = true; } $_SESSION['admin_time'] = time(); } else { $_SERVER['HTTP_USER_AGENT'] = substr($_SERVER['HTTP_USER_AGENT'], 0, 211); smf_db_insert('replace', '{db_prefix}sessions', array('session_id' => 'string', 'last_update' => 'int', 'data' => 'string'), array(session_id(), time(), 'USER_AGENT|s:' . strlen($_SERVER['HTTP_USER_AGENT']) . ':"' . $_SERVER['HTTP_USER_AGENT'] . '";admin_time|i:' . time() . ';'), array('session_id')); } // We're going to want our lovely $modSettings now. $request = smf_db_query(' SELECT variable, value FROM {db_prefix}settings', array('db_error_skip' => true)); // Only proceed if we can load the data. if ($request) { while ($row = mysql_fetch_row($request)) { $modSettings[$row[0]] = $row[1]; } mysql_free_result($request); } updateStats('member'); updateStats('message'); updateStats('topic'); $request = smf_db_query(' SELECT id_msg FROM {db_prefix}messages WHERE id_msg = 1 AND modified_time = 0 LIMIT 1', array('db_error_skip' => true)); if (mysql_num_rows($request) > 0) { updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject'])); } mysql_free_result($request); // Now is the perfect time to fetch the SM files. require_once $sourcedir . '/ScheduledTasks.php'; // Sanity check that they loaded earlier! if (isset($modSettings['recycle_board'])) { $forum_version = $current_smf_version; // The variable is usually defined in index.php so lets just use our variable to do it for us. scheduled_fetchSMfiles(); // Now go get those files! // We've just installed! $user_info['ip'] = $_SERVER['REMOTE_ADDR']; $user_info['id'] = isset($incontext['member_id']) ? $incontext['member_id'] : 0; logAction('install', array('version' => $forum_version), 'admin'); } // Check if we need some stupid MySQL fix. $server_version = smf_db_get_version(); if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) { updateSettings(array('db_mysql_group_by_fix' => '1')); } // Some final context for the template. $incontext['dir_still_writable'] = is_writable(dirname(__FILE__)) && substr(__FILE__, 1, 2) != ':\\'; $incontext['probably_delete_install'] = isset($_SESSION['installer_temp_ftp']) || is_writable(dirname(__FILE__)) || is_writable(__FILE__); return false; }
/** * @brief Handle the actions of the different setup steps. * * @param[in,out] App &$a */ function setup_post(&$a) { global $install_wizard_pass, $db; switch ($install_wizard_pass) { case 1: case 2: return; break; // just in case return don't return :) // just in case return don't return :) case 3: $urlpath = $a->get_path(); $dbhost = trim($_POST['dbhost']); $dbport = intval(trim($_POST['dbport'])); $dbuser = trim($_POST['dbuser']); $dbpass = trim($_POST['dbpass']); $dbdata = trim($_POST['dbdata']); $dbtype = intval(trim($_POST['dbtype'])); $phpath = trim($_POST['phpath']); $adminmail = trim($_POST['adminmail']); $siteurl = trim($_POST['siteurl']); require_once 'include/dba/dba_driver.php'; unset($db); $db = dba_factory($dbhost, $dbport, $dbuser, $dbpass, $dbdata, $dbtype, true); if (!$db->connected) { echo 'Database Connect failed: ' . $db->error; killme(); $a->data['db_conn_failed'] = true; } /*if(get_db_errno()) { unset($db); $db = dba_factory($dbhost, $dbport, $dbuser, $dbpass, '', true); if(! get_db_errno()) { $r = q("CREATE DATABASE '%s'", dbesc($dbdata) ); if($r) { unset($db); $db = new dba($dbhost, $dbport, $dbuser, $dbpass, $dbdata, true); } else { $a->data['db_create_failed']=true; } } else { $a->data['db_conn_failed']=true; return; } }*/ //if(get_db_errno()) { //} return; break; case 4: $urlpath = $a->get_path(); $dbhost = notags(trim($_POST['dbhost'])); $dbport = intval(notags(trim($_POST['dbport']))); $dbuser = notags(trim($_POST['dbuser'])); $dbpass = notags(trim($_POST['dbpass'])); $dbdata = notags(trim($_POST['dbdata'])); $dbtype = intval(notags(trim($_POST['dbtype']))); $phpath = notags(trim($_POST['phpath'])); $timezone = notags(trim($_POST['timezone'])); $adminmail = notags(trim($_POST['adminmail'])); $siteurl = notags(trim($_POST['siteurl'])); if ($siteurl != z_root()) { $test = z_fetch_url($siteurl . "/setup/testrewrite"); if (!$test['success'] || $test['body'] != 'ok') { $a->data['url_fail'] = true; $a->data['url_error'] = $test['error']; return; } } // connect to db $db = dba_factory($dbhost, $dbport, $dbuser, $dbpass, $dbdata, $dbtype, true); if (!$db->connected) { echo 'CRITICAL: DB not connected.'; killme(); } $tpl = get_intltext_template('htconfig.tpl'); $txt = replace_macros($tpl, array('$dbhost' => $dbhost, '$dbport' => $dbport, '$dbuser' => $dbuser, '$dbpass' => $dbpass, '$dbdata' => $dbdata, '$dbtype' => $dbtype, '$timezone' => $timezone, '$siteurl' => $siteurl, '$site_id' => random_string(), '$phpath' => $phpath, '$adminmail' => $adminmail)); $result = file_put_contents('.htconfig.php', $txt); if (!$result) { $a->data['txt'] = $txt; } $errors = load_database($db); if ($errors) { $a->data['db_failed'] = $errors; } else { $a->data['db_installed'] = true; } return; break; } }
$log->lwrite("\t156 AlarmSensor Val :: " . $dd['156']['data']['0']['sensorState']['value'], 1); } else { $log->lwrite("\tData Dump:: Not an AlarmSensor device: " . $d, 3); } } //for // ASSUMING WE JUST RENEWED ALL SENSORS IN THE DATA LOOP ABOVE, DOD NOT USE THE GET() FUNCTION BELOW. // XXX WE SHOULD PROBABLY INTEGRATE LOOOP BELOW IN THE LOOP ABOVE // Loop based on $devices array of LAMPI // $log->lwrite("------------------ SWITCH/DIMMER LOOP ----------------------", 1); $log->lwrite("", 2); $log->lwrite("Count load_devices:: " . count($dev_config), 2); if (count($dev_config) == 0) { $log->lwrite("ERROR LamPI-gate:: No devices read, need to restart MySQL connection", 0); $lampi_config = load_database(); // whole database $dev_config = $lampi_config['devices']; } $dev_config = load_devices(); // Looping through all devices for ($i = 0; $i < count($dev_config); $i++) { if ($dev_config[$i]['brand'] == "7") { // If key does not yet exist, create a record for zway if (!array_key_exists($i, $zway_dev)) { $zway_dev[$i] = array('id' => $dev_config[$i]['id'], 'gui_inValid' => 3, 'gui_old' => $dev_config[$i]['val'], 'gui_val' => $dev_config[$i]['val'], 'unit' => $dev_config[$i]['unit'], 'gaddr' => $dev_config[$i]['gaddr'], 'name' => $dev_config[$i]['name'], 'type' => $dev_config[$i]['type']); } //$dev_config = load_devices(); // Get latest GUI/MySQL values $zway_dev[$i]['gui_old'] = $zway_dev[$i]['gui_val']; $zway_dev[$i]['gui_val'] = $dev_config[$i]['val']; $gui_val = $dev_config[$i]['val'];
/** * Final step, clean up and a complete message! */ function action_deleteInstall() { global $txt, $incontext, $db_character_set; global $current_version, $databases, $forum_version, $modSettings, $user_info, $db_type; // A few items we will load in from settings and make avaialble. global $boardurl, $db_prefix, $cookiename, $mbname, $language; $incontext['page_title'] = $txt['congratulations']; $incontext['sub_template'] = 'delete_install'; $incontext['continue'] = 0; require dirname(__FILE__) . '/Settings.php'; if (!defined('ELK')) { define('ELK', 1); } definePaths(); $db = load_database(); if (!defined('SUBSDIR')) { define('SUBSDIR', dirname(__FILE__) . '/sources/subs'); } chdir(dirname(__FILE__)); require_once SOURCEDIR . '/Errors.php'; require_once SOURCEDIR . '/Logging.php'; require_once SOURCEDIR . '/Subs.php'; require_once SOURCEDIR . '/Load.php'; require_once SUBSDIR . '/Cache.subs.php'; require_once SOURCEDIR . '/Security.php'; require_once SUBSDIR . '/Auth.subs.php'; require_once SUBSDIR . '/Util.class.php'; // Bring a warning over. if (!empty($incontext['account_existed'])) { $incontext['warning'] = $incontext['account_existed']; } if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support'])) { $db->query('', ' SET NAMES {raw:db_character_set}', array('db_character_set' => $db_character_set, 'db_error_skip' => true)); } // As track stats is by default enabled let's add some activity. $db->insert('ignore', '{db_prefix}log_activity', array('date' => 'date', 'topics' => 'int', 'posts' => 'int', 'registers' => 'int'), array(strftime('%Y-%m-%d', time()), 1, 1, !empty($incontext['member_id']) ? 1 : 0), array('date')); // We're going to want our lovely $modSettings now. $request = $db->query('', ' SELECT variable, value FROM {db_prefix}settings', array('db_error_skip' => true)); // Only proceed if we can load the data. if ($request) { while ($row = $db->fetch_row($request)) { $modSettings[$row[0]] = $row[1]; } $db->free_result($request); } // Automatically log them in ;) if (isset($incontext['member_id']) && isset($incontext['member_salt'])) { setLoginCookie(3153600 * 60, $incontext['member_id'], hash('sha256', $incontext['passwd'] . $incontext['member_salt'])); } $result = $db->query('', ' SELECT value FROM {db_prefix}settings WHERE variable = {string:db_sessions}', array('db_sessions' => 'databaseSession_enable', 'db_error_skip' => true)); if ($db->num_rows($result) != 0) { list($db_sessions) = $db->fetch_row($result); } $db->free_result($result); if (empty($db_sessions)) { $_SESSION['admin_time'] = time(); } else { $_SERVER['HTTP_USER_AGENT'] = substr($_SERVER['HTTP_USER_AGENT'], 0, 211); $db->insert('replace', '{db_prefix}sessions', array('session_id' => 'string', 'last_update' => 'int', 'data' => 'string'), array(session_id(), time(), 'USER_AGENT|s:' . strlen($_SERVER['HTTP_USER_AGENT']) . ':"' . $_SERVER['HTTP_USER_AGENT'] . '";admin_time|i:' . time() . ';'), array('session_id')); } updateStats('member'); updateStats('message'); updateStats('topic'); $request = $db->query('', ' SELECT id_msg FROM {db_prefix}messages WHERE id_msg = 1 AND modified_time = 0 LIMIT 1', array('db_error_skip' => true)); if ($db->num_rows($request) > 0) { updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject'])); } $db->free_result($request); // Now is the perfect time to fetch remote files. require_once SUBSDIR . '/ScheduledTask.class.php'; // Sanity check that they loaded earlier! if (isset($modSettings['recycle_board'])) { // The variable is usually defined in index.php so lets just use our variable to do it for us. $forum_version = $current_version; // Now go get those files! $task = new Scheduled_Task(); $task->fetchFiles(); // We've just installed! $user_info['ip'] = $_SERVER['REMOTE_ADDR']; $user_info['id'] = isset($incontext['member_id']) ? $incontext['member_id'] : 0; logAction('install', array('version' => $forum_version), 'admin'); } // Check if we need some stupid MySQL fix. $server_version = $db->db_server_info(); if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) { updateSettings(array('db_mysql_group_by_fix' => '1')); } // Some final context for the template. $incontext['dir_still_writable'] = is_writable(dirname(__FILE__)) && substr(__FILE__, 1, 2) != ':\\'; $incontext['probably_delete_install'] = isset($_SESSION['installer_temp_ftp']) || is_writable(dirname(__FILE__)) || is_writable(__FILE__); return false; }
<?php define('ELK_INSTALL_DIR', '/vagrant/Elkarte/install'); define('TMP_BOARDDIR', '/var/www'); require ELK_INSTALL_DIR . '/installcore.php'; require ELK_INSTALL_DIR . '/CommonCode.php'; // Load settings require TMP_BOARDDIR . '/Settings.php'; definePaths(); $db = load_database(); require TMP_BOARDDIR . '/themes/default/languages/english/Install.english.php'; $modSettings['disableQueryCheck'] = true; $db->query('', ' SET NAMES {string:utf8}', array('db_error_skip' => true, 'utf8' => 'utf8')); $replaces = array('{$db_prefix}' => $db_prefix, '{BOARDDIR}' => TMP_BOARDDIR, '{$boardurl}' => $boardurl, '{$enableCompressedOutput}' => isset($_POST['compress']) ? '1' : '0', '{$databaseSession_enable}' => isset($_POST['dbsession']) ? '1' : '0', '{$current_version}' => CURRENT_VERSION, '{$current_time}' => time(), '{$sched_task_offset}' => 82800 + mt_rand(0, 86399)); foreach ($txt as $key => $value) { if (substr($key, 0, 8) == 'default_') { $replaces['{$' . $key . '}'] = addslashes($value); } } $replaces['{$default_reserved_names}'] = strtr($replaces['{$default_reserved_names}'], array('\\\\n' => '\\n')); // If the UTF-8 setting was enabled, add it to the table definitions. if (!empty($databases[$db_type]['utf8_support'])) { $replaces[') ENGINE=MyISAM;'] = ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;'; } // Populate database $db_table = db_table_install(); $db_wrapper = new DbWrapper($db, $replaces); $db_table_wrapper = new DbTableWrapper($db_table); $exists = array(); require_once ELK_INSTALL_DIR . '/install_1-1.php';
function get_parse() { global $appmsg; global $apperr; global $action; global $icsmsg; global $config_dir; global $log_dir; foreach ($_GET as $ind => $val) { decho("get_parse:: index: {$ind} and val: {$val}<br>", 1); switch ($ind) { case "action": $action = $val; break; case "message": $icsmsg = json_decode($val); $apperr .= "\n ics: " . $icsmsg; break; // ******* URL COMMANDLINE OPTIONS BELOW *** // Initial or repair load of th edatabase for LamPI // Need to specify this option on the URL: http://<my-lampi-url>/frontend_set.php?load // // ******* URL COMMANDLINE OPTIONS BELOW *** // Initial or repair load of th edatabase for LamPI // Need to specify this option on the URL: http://<my-lampi-url>/frontend_set.php?load // case "load": echo "load:: config file: " . $config_dir . "database.cfg\n"; $cfg = read_database($config_dir . "database.cfg"); // Load $cfg Object from File echo " cfg read; "; print_database($cfg); echo " now filling mysql; "; $ret = fill_database($cfg); // Fill the MySQL Database with $cfg object echo " Making backup; "; $ret = file_database($config_dir . "newdbms.cfg", $cfg); // Make backup to other file echo " Backup newdbms.cfg made"; if ($val < 1) { decho("file_database:: value must be >0"); } exit(0); break; case "print": $cfg = load_database(); print_database($cfg); exit(0); break; case "store": $cfg = load_database(); // Fill $cfg from MySQL $ret = file_database($config_dir . "newdbms.cfg", $cfg); // Make backup to other file if ($val < 1) { decho("store:: value must be >0"); } echo "Backup is complete"; exit(0); break; } // Switch ind } // Foreach return 0; }
if (array_key_exists('gas_use', $data)) { $item['gas_use'] = $data['gas_use']; } // If we push this message on the Queue with time==0, it will // be executed in phase 2 $log->lwrite("main:: q_insert action: " . $item['action'] . ", kw_act_use: " . $item['kw_act_use'], 2); $queue->q_insert($item); $log->lwrite("main:: action: " . $item['action'], 2); break; case "load_database": // Load the MySQL Database. // $log->lwrite("main:: action: " . $item['action'], 1); // XXX Should we have to do this, or just assume that $config is already up to date // In which case we should always work with $config and nog with derivates such as $weather $config = load_database(); // load the complete configuration object if ($config == -1) { $log->lwrite("main:: Error loading database, error: " . $apperr); $log->lwrite("main:: FATAL, exiting now\n"); exit(1); } else { $log->lwrite("main:: Loaded the database, err: " . $apperr, 1); } $response = array('tcnt' => $tcnt . "", 'type' => 'raw', 'action' => 'load_database', 'request' => $data['request'], 'response' => $config); if (false === ($message = json_encode($response))) { $log->lwrite("ERROR main:: json_encode failed: <" . $response['tcnt'] . ", " . $response['action'] . ">"); } $log->lwrite("Json encoded console: " . $response['response'], 2); if ($sock->s_send($message) == -1) { $log->lwrite("ERROR main:: failed writing login message on socket");
function dbase_parse($cmd, $message) { global $pisql, $dbhost, $dbuser, $dbpass, $dbname; global $log; // Used by daemon global $apperr, $appmsg; // For ajax usage if (!$pisql || !$pisql->ping()) { $log->lwrite("dbase_parse:: Ping failed, making new pisql connection to server", 1); $pisql = new mysqli($dbhost, $dbuser, $dbpass, $dbname); } // If there is an error if ($pisql->connect_errno) { $log->lwrite("dbase_parse:: Failed to connect to MySQL: (" . $pisql->connect_errno . ") " . $pisql->connect_error, 1); return -1; } // For logging only if (is_array($message)) { $str = ""; foreach ($message as $key => $val) { $str .= " {" . $key . ":" . $val . "},"; } $log->lwrite("dbase_parse:: " . $cmd . ": " . $str, 1); } else { $log->lwrite("dbase_parse:: message: " . $cmd . ": " . $message, 1); } // // Depending on $cmd execute database function switch ($cmd) { // Database case "load_database": $ret = load_database(); break; // Device // Device case "load_devices": $ret = load_devices(); break; case "add_device": $ret = add_device($message); break; case "delete_device": $ret = delete_device($message); break; case "store_device": $ret = store_device($message); break; // Room // Room case "add_room": $ret = add_room($message); break; case "delete_room": $ret = delete_room($message); break; // Scene // Scene case "read_scene": $ret = load_scene($message); break; case "load_scenes": $ret = load_scenes(); break; case "add_scene": $ret = add_scene($message); break; case "delete_scene": $ret = delete_scene($message); break; case "upd_scene": $ret = upd_scene($message); break; case "store_scene": $ret = store_scene($message); break; // Timer // Timer case "add_timer": $ret = add_timer($message); break; case "delete_timer": $ret = delete_timer($message); break; case "store_timer": $ret = store_timer($message); break; // Handset // Handset case "add_handset": $ret = add_handset($message); break; case "delete_handset": $ret = delete_handset($message); break; case "store_handset": $ret = store_handset($message); break; // Weather // Weather case "add_weather": $ret = add_weather($message); break; case "delete_weather": $ret = delete_weather($message); break; // Setting // Setting case "store_setting": $ret = store_setting($message); break; default: } if ($ret >= 0) { // Prepare structure to send back to the calling ajax client (in stdout) $send = array('tcnt' => $ret, 'appmsg' => $appmsg, 'status' => 'OK', 'apperr' => $apperr); $output = json_encode($send); } else { // Functions need to fill apperr themselves! $send = array('tcnt' => $ret, 'appmsg' => $appmsg, 'status' => 'ERR', 'apperr' => $apperr); $output = json_encode($send); } return $output; }
function user_remove_ban($ip) { $ip = str_replace(array('|', '"'), '', $ip); if (empty($ip)) { return false; } $users_ban = load_database('users_ban', 'ipban.db'); if (preg_match_all('~^' . preg_sanitize($ip) . '\\|.*$~im', $users_ban, $c, PREG_SET_ORDER)) { foreach ($c as $v) { $users_ban = str_replace($v[0] . "\n", '', $users_ban); } } return rewritefile('/cdata/ipban.db.php', $users_ban); }
======================================================= */ $ret = 0; // Parse the URL sent by client // post_parse will parse the commands that are sent by the java app on the client // $_POST is used for data that should not be sniffed from URL line, and // for changes sent to the devices // if ($debug>0) $ret = get_parse(); $ret = post_parse(); // Do Processing // XXX Needs some cleaning and better/consistent messaging specification // could also include the setting of debug on the client side switch ($action) { // Functions on the whole database case "load_database": $apperr .= "Load: msg: " . $icsmsg . "\n"; $appmsg = load_database(); if ($appmsg == -1) { $ret = -1; $apperr .= "\nERROR Loading Database"; } else { $ret = 0; $apperr = "Configuration Loaded"; } break; case "store": // What happens if we receive a complex datastructure? $apperr .= "Calling store: icsmsg: {$icsmsg}\n"; $appmsg = store_database($icsmsg); $apperr .= "\nStore "; $ret = 0; break;