/** * Handle on_project_user_removed event * * @param Project $project * @param User $user * @return null */ function resources_handle_on_project_user_removed($project, $user) { $rows = db_execute('SELECT id FROM ' . TABLE_PREFIX . 'project_objects WHERE project_id = ?', $project->getId()); if (is_foreachable($rows)) { $object_ids = array(); foreach ($rows as $row) { $object_ids[] = (int) $row['id']; } // foreach $user_id = $user->getId(); // Assignments cleanup db_execute('DELETE FROM ' . TABLE_PREFIX . 'assignments WHERE user_id = ? AND object_id IN (?)', $user_id, $object_ids); cache_remove('object_starred_by_' . $user_id); cache_remove('object_assignments_*'); cache_remove('object_assignments_*_rendered'); // Starred objects cleanup db_execute('DELETE FROM ' . TABLE_PREFIX . 'starred_objects WHERE user_id = ? AND object_id IN (?)', $user_id, $object_ids); cache_remove('object_starred_by_' . $user_id); // Subscriptions cleanup db_execute('DELETE FROM ' . TABLE_PREFIX . 'subscriptions WHERE user_id = ? AND parent_id IN (?)', $user_id, $object_ids); cache_remove('user_subscriptions_' . $user_id); // remove pinned project PinnedProjects::unpinProject($project, $user); } // if }
function upgrade_log($v = false) { if (!$v) { $v = upgrade_version_num(); } return db_execute('insert into sitellite_upgrade values (?, ?, now())', $v, session_username()); }
/** * on_object_deleted handler implemenation * * @param AngieObject $object * @return null */ function source_handle_on_object_deleted($object) { if (instance_of($object, 'Ticket') || instance_of($object, 'Discussion') || instance_of($object, 'Milestone') || instance_of($object, 'Task')) { db_execute('DELETE FROM ' . TABLE_PREFIX . 'commit_project_objects WHERE object_id = ? AND project_id = ?', $object->getId(), $object->getProjectId()); } // if }
function syslog_db_execute($sql, $log = TRUE) { global $syslog_cnn, $cnn_id; /* use cacti function if using Cacti db */ if ($syslog_cnn == $cnn_id) { return db_execute($sql, $log); } $sql = str_replace(" ", " ", str_replace("\n", "", str_replace("\r", "", str_replace("\t", " ", $sql)))); if (read_config_option("log_verbosity") == POLLER_VERBOSITY_DEBUG) { cacti_log("DEBUG: SQL Exec: \"" . $sql . "\"", FALSE); } $errors = 0; while (1) { $query = $syslog_cnn->Execute($sql); if ($query || $syslog_cnn->ErrorNo() == 1032) { return 1; } else { if ($log || read_config_option("log_verbosity") == POLLER_VERBOSITY_DEBUG) { if (substr_count($syslog_cnn->ErrorMsg(), "Deadlock") || $syslog_cnn->ErrorNo() == 1213 || $syslog_cnn->ErrorNo() == 1205) { $errors++; if ($errors > 30) { cacti_log("ERROR: Too many Lock/Deadlock errors occurred! SQL:'" . str_replace("\n", "", str_replace("\r", "", str_replace("\t", " ", $sql))) . "'", TRUE); return 0; } else { usleep(500000); continue; } } else { cacti_log("ERROR: A DB Exec Failed!, Error:'" . $syslog_cnn->ErrorNo() . "', SQL:\"" . str_replace("\n", "", str_replace("\r", "", str_replace("\t", " ", $sql))) . "'", FALSE); return 0; } } } } }
function rrdclean_check_upgrade() { global $config; $files = array('index.php', 'plugins.php', 'rrdcleaner.php'); if (isset($_SERVER['PHP_SELF']) && !in_array(basename($_SERVER['PHP_SELF']), $files)) { return; } $current = plugin_rrdclean_version(); $current = $current['version']; $old = db_fetch_row("SELECT * FROM plugin_config WHERE directory='rrdclean'"); if (sizeof($old) && $current != $old["version"]) { /* if the plugin is installed and/or active */ if ($old["status"] == 1 || $old["status"] == 4) { /* re-register the hooks */ plugin_rrdclean_install(); /* perform a database upgrade */ rrdclean_database_upgrade(); } # stub for updating tables #$_columns = array_rekey(db_fetch_assoc("SHOW COLUMNS FROM <table>"), "Field", "Field"); #if (!in_array("<new column>", $_columns)) { # db_execute("ALTER TABLE <table> ADD COLUMN <new column> VARCHAR(40) NOT NULL DEFAULT '' AFTER <old column>"); #} # new hooks #api_plugin_register_hook('rrdclean', 'config_settings', 'rrdclean_config_settings', 'setup.php'); #if (api_plugin_is_enabled('rrdclean')) { # may sound ridiculous, but enables new hooks # api_plugin_enable_hooks('rrdclean'); #} # register new version $info = plugin_rrdclean_version(); $id = db_fetch_cell("SELECT id FROM plugin_config WHERE directory='rrdclean'"); db_execute("UPDATE plugin_config\r\n\t\t\tSET name='" . $info["longname"] . "',\r\n\t\t\tauthor='" . $info["author"] . "',\r\n\t\t\twebpage='" . $info["homepage"] . "',\r\n\t\t\tversion='" . $info["version"] . "'\r\n\t\t\tWHERE id='{$id}'"); } }
/** * Saves auth control data for a certain control id * * Saves auth control data for a certain control id * * @return 1 on success, 0 on error */ function auth_control_data_save($data, $category = "SYSTEM", $enable_user_edit = 0, $plugin_id = 0, $control_id = 0) { /* Validate input */ if (!is_array($data)) { return 0; } if (!is_numeric($enable_user_edit)) { return 0; } if (($enable_user_edit < 0) || ($enable_user_edit > 1)) { $enable_user_edit = 0; } if (!is_numeric($plugin_id)) { return 0; } if (!is_numeric($control_id)) { return 0; } if (empty($control_id)) { $control_id = $_SESSION["sess_user_id"]; } /* Create SQL Query */ $username = db_fetch_cell("SELECT username FROM user_auth WHERE id = " . $control_id, "username"); $sql = "REPLACE INTO `auth_data` (`control_id`,`plugin_id`,`category`,`name`,`value`,`enable_user_edit`,`updated_when`,`updated_by`) VALUES "; foreach ($data as $name => $value) { $sql .= "(" . $control_id . "," . $plugin_id . ",'" . $category . "','" . $name . "','" . $value . "'," . $enable_user_edit . ",NOW(),'" . $username . "'),"; } $sql = substr($sql,0,strlen($sql) - 1); /* Execute query and return */ return db_execute($sql); }
/** * Log a search query. */ function logSearch($query, $results, $ts = false, $ip = false, $ctype = false, $domain = false) { if (!$ts) { $ts = date('YmdHis'); } if (!$ip) { $ip = $_SERVER['REMOTE_ADDR']; } if (!$ctype) { $ctype = 'all'; } elseif (is_array($ctype)) { $ctype = join(', ', $ctype); } if (!$domain) { $domain = 'all'; } elseif (is_array($domain)) { $domain = join(', ', $domain); } $res = db_execute('insert into sitesearch_log (id, query, results, ts, ip, ctype, domain) values (null, ?, ?, ?, ?, ?, ?)', $query, $results, $ts, $ip, $ctype, $domain); if (!$res) { $this->error = db_error(); } return $res; }
/** * on_object_deleted handler implemenation * * @param AngieObject $object * @return null */ function incoming_mail_handle_on_object_deleted($object) { if (instance_of($object, 'Project')) { db_execute('UPDATE ' . TABLE_PREFIX . 'incoming_mailboxes SET enabled=0 WHERE project_id = ?', $object->getId()); } // if }
function api_device_remove_multi($device_ids) { $devices_to_delete = ''; $i = 0; if (sizeof($device_ids)) { /* build the list */ foreach ($device_ids as $device_id) { if ($i == 0) { $devices_to_delete .= $device_id; } else { $devices_to_delete .= ', ' . $device_id; } /* poller commands go one at a time due to trashy logic */ db_execute_prepared('DELETE FROM poller_item WHERE host_id = ?', array($device_id)); db_execute_prepared('DELETE FROM poller_reindex WHERE host_id = ?', array($device_id)); db_execute_prepared('DELETE FROM poller_command WHERE command LIKE ?', array($device_id . ':%')); $i++; } db_execute("DELETE FROM host WHERE id IN ({$devices_to_delete})"); db_execute("DELETE FROM host_graph WHERE host_id IN ({$devices_to_delete})"); db_execute("DELETE FROM host_snmp_query WHERE host_id IN ({$devices_to_delete})"); db_execute("DELETE FROM host_snmp_cache WHERE host_id IN ({$devices_to_delete})"); db_execute("DELETE FROM graph_tree_items WHERE host_id IN ({$devices_to_delete})"); db_execute("DELETE FROM reports_items WHERE host_id IN ({$devices_to_delete})"); /* for people who choose to leave data sources around */ db_execute("UPDATE data_local SET host_id=0 WHERE host_id IN ({$devices_to_delete})"); db_execute("UPDATE graph_local SET host_id=0 WHERE host_id IN ({$devices_to_delete})"); } }
function api_poller_cache_item_add($host_id, $host_field_override, $local_data_id, $poller_action_id, $data_source_item_name, $num_rrd_items, $arg1 = "", $arg2 = "", $arg3 = "") { $host = db_fetch_row("select\n\t\thost.id,\n\t\thost.hostname,\n\t\thost.snmp_community,\n\t\thost.snmp_version,\n\t\thost.snmp_username,\n\t\thost.snmp_password,\n\t\thost.snmp_port,\n\t\thost.snmp_timeout,\n\t\thost.disabled\n\t\tfrom host\n\t\twhere host.id={$host_id}"); /* the $host_field_override array can be used to override certain host fields in the poller cache */ if (isset($host)) { $host = array_merge($host, $host_field_override); } if (isset($host["id"]) || isset($host_id)) { if (isset($host)) { if ($host["disabled"] == "on") { return true; } } else { if ($poller_action_id == 0) { return true; } $host["id"] = 0; $host["snmp_community"] = ""; $host["snmp_timeout"] = ""; $host["snmp_username"] = ""; $host["snmp_password"] = ""; $host["snmp_version"] = ""; $host["snmp_port"] = ""; $host["hostname"] = "None"; } if ($poller_action_id == 0) { if ($host["snmp_version"] < 1 || $host["snmp_version"] > 3 || $host["snmp_community"] == "" && $host["snmp_version"] != 3) { return true; } } return db_execute("insert into poller_item (local_data_id,host_id,action,hostname,\n\t\t\tsnmp_community,snmp_version,snmp_timeout,snmp_username,snmp_password,snmp_port,rrd_name,rrd_path,\n\t\t\trrd_num,arg1,arg2,arg3) values ({$local_data_id}," . $host["id"] . ",{$poller_action_id},'" . $host["hostname"] . "',\n\t\t\t'" . $host["snmp_community"] . "','" . $host["snmp_version"] . "','" . $host["snmp_timeout"] . "',\n\t\t\t'" . $host["snmp_username"] . "','" . $host["snmp_password"] . "','" . $host["snmp_port"] . "',\n\t\t\t'{$data_source_item_name}','" . addslashes(clean_up_path(get_data_source_path($local_data_id, true))) . "',\n\t\t\t'{$num_rrd_items}','{$arg1}','{$arg2}','{$arg3}')"); } }
function color_remove() { /* ================= input validation ================= */ input_validate_input_number(get_request_var("id")); /* ==================================================== */ db_execute("delete from colors where id=" . $_GET["id"]); }
/** * on_object_deleted handler implemenation * * @param AngieObject $object * @return null */ function invoicing_handle_on_object_deleted($object) { if (instance_of($object, 'TimeRecord')) { db_execute('DELETE FROM ' . TABLE_PREFIX . 'invoice_time_records WHERE time_record_id = ?', $object->getId()); } // if }
function create_user($email, $username, $password, $password_confirm, $firstname, $lastname) { if (!ereg(".+@.+\\..+", $email)) { return "Invalid email address"; } if (empty($username)) { return "Empty username"; } if (empty($password) || empty($password_confirm)) { return "Empty password"; } if (strcmp($password, $password_confirm)) { return "Passwords don't match"; } if (empty($firstname)) { return "Empty first name"; } if (empty($lastname)) { return "Empty last name"; } if (db_fetch("select email from sitellite_user where email = ?", $email)) { return "Email address is already in system"; } if (db_fetch("select username from sitellite_user where username = ?", $username)) { return "Username is already in system"; } // All the data checks out, let's insert this mofo if (!db_execute("insert into sitellite_user (email, password, firstname, lastname, username, role, team, expires, lang) values (?, ?, ?, ?, ?, ?, ?, ?, ?)", $email, crypt($password), $firstname, $lastname, $username, '', '', 0, 'en')) { return "User creation failed"; } return ''; // Everything is peachy! *gulp* }
function onSubmit($vals) { //echo '<pre>'; //print_r ($vals); //exit; $duration = (strtotime($vals['ended']) - strtotime($vals['started'])) / 60 / 60; $res = db_execute('insert into timetracker_entry (id, project_id, task_description, started, duration) values (null, ?, ?, ?, ?)', $vals['project'], $vals['description'], $vals['started'], $duration); if (!$res) { return '<p>Unknown error: ' . db_error() . '</p>'; } $eid = db_lastid(); if (!is_array($vals['users'])) { $vals['users'] = preg_split('/, ?/', $vals['users']); } foreach ($vals['users'] as $user) { db_execute('insert into timetracker_user_entry (id, user_id, entry_id) values (null, ?, ?)', $user, $eid); } header('Location: ' . site_prefix() . '/index/timetracker-app/added.entry'); exit; }
function api_graph_remove_multi($local_graph_ids) { /* initialize variables */ $ids_to_delete = ''; $i = 0; /* build the array */ if (sizeof($local_graph_ids)) { foreach ($local_graph_ids as $local_graph_id) { if ($i == 0) { $ids_to_delete .= $local_graph_id; } else { $ids_to_delete .= ', ' . $local_graph_id; } $i++; if ($i % 1000 == 0) { db_execute("DELETE FROM graph_templates_graph WHERE local_graph_id IN ({$ids_to_delete})"); db_execute("DELETE FROM graph_templates_item WHERE local_graph_id IN ({$ids_to_delete})"); db_execute("DELETE FROM graph_tree_items WHERE local_graph_id IN ({$ids_to_delete})"); db_execute("DELETE FROM reports_items WHERE local_graph_id IN ({$ids_to_delete})"); db_execute("DELETE FROM graph_local WHERE id IN ({$ids_to_delete})"); $i = 0; $ids_to_delete = ''; } } if ($i > 0) { db_execute("DELETE FROM graph_templates_graph WHERE local_graph_id IN ({$ids_to_delete})"); db_execute("DELETE FROM graph_templates_item WHERE local_graph_id IN ({$ids_to_delete})"); db_execute("DELETE FROM graph_tree_items WHERE local_graph_id IN ({$ids_to_delete})"); db_execute("DELETE FROM reports_items WHERE local_graph_id IN ({$ids_to_delete})"); db_execute("DELETE FROM graph_local WHERE id IN ({$ids_to_delete})"); } } }
function delete($id) { $res = db_execute('delete from sitellite_msg_queue where id = ?', $id); if (!$res) { $this->error = db_error(); } return $res; }
function onSubmit($vals) { db_execute('update sitepresenter_slide set title = ?, body = ? where id = ?', $vals['title'], $vals['body'], $vals['id']); header('Location: ' . site_prefix() . '/index/sitepresenter-slides-action?id=' . $vals['presentation']); exit; }
function flowview_delete_filter() { global $config, $colors; db_execute("DELETE FROM plugin_flowview_queries WHERE id=" . get_request_var_request('query')); raise_message('flow_deleted'); header("Location: flowview.php"); exit; }
function delete($id) { $res = db_execute('delete from sitellite_bookmark where user = ? and id = ?', session_username(), $id); if (!$res) { $this->error = db_error(); } return $res; }
function make_topup_request_mtn($origmsisdn, $destMsisdn, $sequenceid, $amount, $tarifftypeid, $serviceproviderid, $sdesc, $operator, $statusId, $txRefId, $seqstatus, $seqtxRefdId, $lasseq, $origBalance, $destBalance, $voucherPIN, $voucherSerial, $responseCode, $responseMessage) { $length = 15; $transId = getToken($length); $log_req = "insert into top_request_main (transaction_id,origmsisdn,destmsisdn,sequence_value,amount,tarriftypeid,serviceproviderid,description,operator,status_id,txrefid,seqstatus,seqtxrefid,lasseq,origbalance,destbalance,VOUCHERPIN,VOUCHERSERIAL,responsecode,responsemessage) values ('{$transId}','{$origmsisdn}','{$destMsisdn}',{$sequenceid},{$amount},{$tarifftypeid},{$serviceproviderid},'{$sdesc}','{$operator}','{$statusId}','{$txRefId}','{$seqstatus}','{$seqtxRefdId}','{$lasseq}','{$origBalance}','{$destBalance}','{$voucherPIN}','{$voucherSerial}','{$responseCode}','{$responseMessage}')"; $sql = db_execute($log_req); return $sql; }
function onSubmit($vals) { db_execute('update siteinvoice_client set code = ?, name = ?, contact_name = ?, contact_email = ?, contact_phone = ?, address = ? where id = ?', $vals['code'], $vals['name'], $vals['contact_name'], $vals['contact_email'], $vals['contact_phone'], $vals['address'], $vals['id']); page_title('SiteInvoice - Client Updated'); echo '<p><a href="' . site_prefix() . '/index/siteinvoice-clients-action">Continue</a></p>'; }
function flowview_delete_filter() { db_execute('DELETE FROM plugin_flowview_queries WHERE id=' . get_request_var_request('query')); db_execute('DELETE FROM plugin_flowview_schedules WHERE savedquery=' . get_request_var_request('query')); raise_message('flow_deleted'); header('Location: flowview.php?tab=filters&header=false'); exit; }
function onSubmit($vals) { // process the form db_execute('INSERT INTO digger_comments (story, user, comment_date, comments) VALUES (?, ?, NOW(), ?)', $vals['id'], session_username(), $vals['comments']); $cid = db_lastid(); // return back to main page header('Location: /index/digger-comments-action/id.' . $vals['id'] . '#digger-comment-' . $cid); exit; }
function onSubmit($vals) { db_execute('insert into siteinvoice_client (id, code, name, contact_name, contact_email, contact_phone, address) values (null, ?, ?, ?, ?, ?, ?)', $vals['code'], $vals['name'], $vals['contact_name'], $vals['contact_email'], $vals['contact_phone'], $vals['address']); page_title('SiteInvoice - Client Added'); echo '<p><a href="' . site_prefix() . '/index/siteinvoice-clients-action">Continue</a></p>'; }
function writeForms($fileName) { $dbResult = db_execute($this->getQuery()); $f = fopen($fileName, 'w'); foreach ($dbResult as $r) { fprintf($f, $this->format($r) . "\r\n"); } fclose($f); }
/** * Delete templates by module name * * @param string $name * @return boolean */ function deleteByModule($name) { $delete = EmailTemplates::delete(array('module = ?', $name)); if ($delete && !is_error($delete)) { db_execute('DELETE FROM ' . TABLE_PREFIX . 'email_template_translations WHERE module = ?', $name); } // if return $delete; }
function onSubmit($vals) { db_execute('insert into shoutbox (id, name, url, ip_address, posted_on, message) values (null, ?, ?, ?, now(), ?)', $vals['name'], $vals['url'], $_SERVER['REMOTE_ADDR'], $vals['message']); header('Location: ' . $_SERVER['HTTP_REFERER']); exit; }
function settings_check_upgrade() { $current = plugin_settings_version(); $current = $current['version']; $old = read_config_option('plugin_settings_version'); if ($current != $old) { // settings_setup_table (); } db_execute("REPLACE INTO settings (name, value) VALUES ('plugin_settings_version', '{$current}')"); }
function db_install_execute($cacti_version, $sql) { $sql_install_cache = isset($_SESSION["sess_sql_install_cache"]) ? $_SESSION["sess_sql_install_cache"] : array(); if (db_execute($sql)) { $sql_install_cache[sizeof($sql_install_cache)][$cacti_version][1] = $sql; } else { $sql_install_cache[sizeof($sql_install_cache)][$cacti_version][0] = $sql; } $_SESSION["sess_sql_install_cache"] = $sql_install_cache; }
function onSubmit($vals) { // update devnotes_config table and respond if ($vals['notes'] == 'date') { $vals['notes'] = $vals['notes_date']; } db_execute('update devnotes_config set notes = ?, contact = ?, ignore_list = ?', $vals['notes'], $vals['contact'], $vals['ignore_list']); header('Location: ' . site_prefix() . '/index/devnotes-admin-action'); exit; }