function bones_form_system_theme_settings_alter(&$form, $form_state) { $grid_size = theme_get_setting('grid_size'); $col_number = get_columns(); $form['advanced_settings'] = array('#type' => 'vertical_tabs', '#title' => t('Advanced Theme Settings'), '#description' => t('Customize widths of the Preface and Postscript regions.'), '#collapsible' => TRUE, '#collapsed' => FALSE, '#weight' => -10, '#prefix' => t('<h3> Advanced Settings </h3>')); // Styles $form['advanced_settings']['styles'] = array('#type' => 'fieldset', '#title' => t('Styles'), '#collapsible' => TRUE, '#collapsed' => FALSE); $form['advanced_settings']['styles']['style'] = array('#type' => 'select', '#title' => t('Style'), '#default_value' => theme_get_setting('style'), '#options' => array(1 => t('Style 1'), 2 => t('Style 2'), 3 => t('Style 3'), 4 => t('Style 4'), 5 => t('Style 5'))); // Grid Settings $form['advanced_settings']['grid_settings'] = array('#type' => 'fieldset', '#title' => t('Grid Settings'), '#collapsible' => TRUE, '#collapsed' => FALSE, '#weight' => -10); $form['advanced_settings']['grid_settings']['grid_size'] = array('#type' => 'select', '#title' => t('Grid Size'), '#default_value' => theme_get_setting('grid_size'), '#options' => array(12 => t('12 columns'))); $form['advanced_settings']['grid_settings']['sidebar_grid_settings'] = array('#type' => 'fieldset', '#title' => t('Sidebar Grid Settings'), '#description' => t('Customize the Sidebars.'), '#collapsible' => TRUE, '#collapsed' => FALSE, '#attributes' => array('class' => array('form-inline')), '#prefix' => t('<h3> Sidebar Grid Settings </h3>')); $form['advanced_settings']['grid_settings']['sidebar_grid_settings']['sidebar_layout'] = array('#type' => 'select', '#title' => t('Sidebar Layout'), '#default_value' => theme_get_setting('sidebar_layout'), '#options' => array('sidebars-both-first' => t('Both Sidebars First'), 'sidebars-both-second' => t('Both Sidebars Second'), 'sidebars-split' => t('Split Sidebars'))); $form['advanced_settings']['grid_settings']['sidebar_grid_settings']['sidebar_first_width'] = array('#type' => 'select', '#title' => t('Sidebar First'), '#default_value' => theme_get_setting('sidebar_first_width'), '#options' => $col_number); $form['advanced_settings']['grid_settings']['sidebar_grid_settings']['sidebar_second_width'] = array('#type' => 'select', '#title' => t('Sidebar Second'), '#default_value' => theme_get_setting('sidebar_second_width'), '#options' => $col_number); $form['advanced_settings']['grid_settings']['preface_settings'] = array('#type' => 'fieldset', '#title' => t('More Grid Settings'), '#description' => t('Customize widths of the Preface regions. Note that all four values combined should ideally add up to ' . $grid_size . '.'), '#collapsible' => TRUE, '#collapsed' => FALSE, '#attributes' => array('class' => array('form-inline')), '#prefix' => t('<h3> Preface Grid Widths </h3>')); $form['advanced_settings']['grid_settings']['postscript_settings'] = array('#type' => 'fieldset', '#title' => t('More Grid Settings'), '#description' => t('Customize widths of the Postscript regions. Note that all four values combined should ideally add up to ' . $grid_size . '.'), '#collapsible' => TRUE, '#collapsed' => FALSE, '#attributes' => array('class' => array('form-inline')), '#prefix' => t('<h3> Postscript Grid Widths </h3>')); for ($region_count = 1; $region_count <= 4; $region_count++) { $form['advanced_settings']['grid_settings']['preface_settings']['preface_' . $region_count . '_grid_width'] = array('#type' => 'select', '#title' => t('Preface ' . $region_count), '#default_value' => theme_get_setting('preface_' . $region_count . '_grid_width'), '#options' => $col_number); $form['advanced_settings']['grid_settings']['postscript_settings']['postscript_' . $region_count . '_grid_width'] = array('#type' => 'select', '#title' => t('Postscript ' . $region_count), '#default_value' => theme_get_setting('postscript_' . $region_count . '_grid_width'), '#options' => $col_number); } // Misc Settings (Facebook, Twitter, etc.) $form['advanced_settings']['misc_settings'] = array('#type' => 'fieldset', '#title' => t('Misc Settings'), '#collapsible' => TRUE, '#collapsed' => FALSE); $form['advanced_settings']['misc_settings']['twitter'] = array('#type' => 'textfield', '#title' => t('Twitter URL'), '#size' => 10, '#default_value' => theme_get_setting('twitter')); $form['advanced_settings']['misc_settings']['facebook'] = array('#type' => 'textfield', '#title' => t('Facebook URL'), '#size' => 10, '#default_value' => theme_get_setting('facebook')); }
public function Login($params = array()) { global $login_system_schema; if (isset($login_system_schema) && $login_system_schema != "") { $this->setSchema($login_system_schema); } $this->setFromArray($params); $this->dbGet($params); if ($this->table != "") { $cols = get_columns($this->table, $this->schema); if ($cols != NULL) { $this->params = $cols; } } $this->init($params); }
function disk_list() { $partitions = array(); // Fetch partition information from df command // I would have used disk_free_space() and disk_total_space() here but // there appears to be no way to get a list of partitions in PHP? $output = array(); exec('/bin/df --block-size=1', $output, $return_var); if ($return_var) { return FALSE; } foreach ($output as $line) { $columns = get_columns($line); // Only process 6 column rows // (This has the bonus of ignoring the first row which is 7) if (count($columns) == 6) { $partition = $columns[5]; $partitions[$partition]['Temporary']['bool'] = in_array($columns[0], array('tmpfs', 'devtmpfs')); $partitions[$partition]['Partition']['text'] = $partition; $partitions[$partition]['FileSystem']['text'] = $columns[0]; if (is_numeric($columns[1]) && is_numeric($columns[2]) && is_numeric($columns[3])) { // Reset the power unit so it is recalculated based on the size unset($power); $partitions[$partition]['Size']['value'] = $columns[1]; $partitions[$partition]['Size']['text'] = si_unit($columns[1], $power, 1024, 1) . 'B'; $partitions[$partition]['Free']['value'] = $columns[3]; $partitions[$partition]['Free']['text'] = si_unit($columns[3], $power, 1024, 1) . 'B'; $partitions[$partition]['Used']['value'] = $columns[2]; $partitions[$partition]['Used']['text'] = si_unit($columns[2], $power, 1024, 1) . 'B'; $partitions[$partition]['Used']['min'] = 0; $partitions[$partition]['Used']['max'] = $columns[1]; $partitions[$partition]['Used']['positive'] = FALSE; } else { // Fallback if we don't get numerical values $partitions[$partition]['Size']['text'] = $columns[1]; $partitions[$partition]['Used']['text'] = $columns[2]; $partitions[$partition]['Free']['text'] = $columns[3]; } } } return $partitions; }
/** * Fix the database columns. * * - Add removed columns * - Remove added columns */ function columns(&$error, $selected) { global $umil; foreach ($this->db_cleaner->data->tables as $table_name => $data) { // Don't touch this table if ($table_name == PROFILE_FIELDS_DATA_TABLE) { continue; } $existing_columns = get_columns($table_name); if ($existing_columns === false) { // Table doesn't exist, don't handle here. continue; } $columns = array_unique(array_merge(array_keys($data['COLUMNS']), $existing_columns)); foreach ($columns as $column) { if (isset($selected[$table_name . '_' . $column])) { if (!isset($data['COLUMNS'][$column]) && in_array($column, $existing_columns)) { $result = $umil->table_column_remove($table_name, $column); if (stripos($result, 'SQL ERROR')) { $error[] = $result; } } else { if (isset($data['COLUMNS'][$column]) && !in_array($column, $existing_columns)) { // This can return an error under some circumstances, like when trying to add an auto-increment field (hope to hell nobody drops one of those) $result = $umil->table_column_add($table_name, $column, $data['COLUMNS'][$column]); if (stripos($result, 'SQL ERROR')) { $error[] = $result; } // We can re-add *some* keys if (isset($data['KEYS'])) { if (in_array($column, $data['KEYS'])) { if ($data['KEYS'][$column][0] == 'INDEX' && $data['KEYS'][$column][1] == $column) { $result = $umil->table_index_add($table_name, $column, $column); if (stripos($result, 'SQL ERROR')) { $error[] = $result; } } } } } } } } } }
function check_columns($link) { global $dbtables, $dbtables_can_update, $errors, $page, $webimroot; $need_to_create_columns = false; foreach ($dbtables as $id => $columns) { $curr_columns = get_columns($id, $link); if ($curr_columns === false) { return false; } $tocreate = array_diff(array_keys($columns), $curr_columns); if (count($tocreate) != 0) { $cannot_update = array_diff($tocreate, $dbtables_can_update[$id]); if (count($cannot_update) != 0) { $errors[] = "Key columns are absent in table `{$id}'. Unable to continue installation."; $page['nextstep'] = getlocal("install.kill_tables"); $page['nextstepurl'] = "{$webimroot}/install/dbperform.php?act=dt"; $page['nextnotice'] = getlocal("install.kill_tables.notice"); return false; } $need_to_create_columns = true; } } if ($need_to_create_columns) { $page['nextstep'] = getlocal("install.4.create"); $page['nextstepurl'] = "{$webimroot}/install/dbperform.php?act=addcolumns"; $page['nextnotice'] = getlocal("install.4.notice"); return false; } $page['done'][] = getlocal("install.4.done"); return true; }
foreach ($interfaces as $interface => $details) { if (!isset($details['Connected']['bool']) || !$details['Connected']['bool'] || !isset($details['IP Address']['text'])) { unset($interfaces[$interface]); } } // Calculate the webserver port $port = 80; if (isset($_SERVER['SERVER_PORT'])) { // If this has been triggered by a web page $port = $_SERVER['SERVER_PORT']; } else { // If this has been triggered by the CLI exec('/usr/sbin/apache2ctl -S 2>/dev/null', $output); foreach ($output as $line) { if (strpos($line, 'port') !== FALSE && strpos($line, 'berryio') !== FALSE) { $cols = get_columns($line); if (count($cols) >= 2) { $port = $cols[1]; } } } } $port = $port == 80 ? '' : ':' . $port; // Load the email functions require_once FUNCTIONS . 'email.php'; // Send email if (count($interfaces) < 1) { $content .= message('No IP address to email at this time'); } elseif (email_view(NAME . ' IP Address', 'ip', array('interfaces' => $interfaces, 'port' => $port))) { $content .= message(EMAIL_TO . ' has been notified of the ' . NAME . ' IP address', 'email_status'); } else {
$tocreate = array_diff(array_keys($dbtables), $curr_tables); foreach ($tocreate as $id) { create_table($id, $link); } } else { if ($act == "dt") { # comment this line to be able to drop tables show_install_err("For security reasons, removing tables is disabled by default"); foreach (array_keys($dbtables) as $id) { mysql_query("DROP TABLE IF EXISTS {$id}", $link) or show_install_err(' Query failed: ' . mysql_error($link)); } } else { if ($act == "addcolumns") { $absent = array(); foreach ($dbtables as $id => $columns) { $curr_columns = get_columns($id, $link); if ($curr_columns === false) { show_install_err($errors[0]); } $tocreate = array_diff(array_keys($columns), $curr_columns); foreach ($tocreate as $v) { $absent[] = "{$id}.{$v}"; } } if (in_array("{$mysqlprefix}chatmessage.agentId", $absent)) { runsql("ALTER TABLE {$mysqlprefix}chatmessage ADD agentId int NOT NULL DEFAULT 0 AFTER ikind", $link); runsql("update {$mysqlprefix}chatmessage, {$mysqlprefix}chatoperator set agentId = operatorid where agentId = 0 AND ikind = 2 AND (vclocalename = tname OR vccommonname = tname)", $link); } if (in_array("{$mysqlprefix}chatthread.agentId", $absent)) { runsql("ALTER TABLE {$mysqlprefix}chatthread ADD agentId int NOT NULL DEFAULT 0 AFTER agentName", $link); runsql("update {$mysqlprefix}chatthread, {$mysqlprefix}chatoperator set agentId = operatorid where agentId = 0 AND (vclocalename = agentName OR vccommonname = agentName)", $link);
function print_tabley($title, $table, $cols) { if (!isset($cols)) { $cols = get_columns($table); } $alt = new alternator("FFFFFF", "EEEEEE"); $needsExtra = count($cols) % 2; echo "<h3>{$title}</h3>\n"; echo "<table cellpadding=\"5\">\n"; echo "<tr><td bgcolor=\"{$alt->getValue()}\"></td>"; foreach ($cols as $col) { echo "<td bgcolor=\"{$alt->getValue()}\">{$col}</td>"; } echo "</tr>\n"; foreach ($table as $idx => $row) { if ($needsExtra == 1) { $alt->getValue(); } echo "<tr><td bgcolor=\"{$alt->getValue()}\">{$idx}</td>\n"; foreach ($cols as $col) { $val = $row[$col]; echo "<td bgcolor=\"{$alt->getValue()}\">{$val}</td>\n"; } echo "</tr>\n"; } echo "</table>\n"; }
function get_role_rights($role_id) { $modules = get_modules(); $module_rights = db::get_single_values_array("SELECT module_id FROM " . TABLE_ROLES_TO_MODULES . " WHERE role_id = " . $role_id); $submodule_rights = db::get_single_values_array("SELECT submodule_id FROM " . TABLE_ROLES_TO_SUBMODULES . " WHERE role_id = " . $role_id); $command_rights = db::get_single_values_array("SELECT command_id FROM " . TABLE_ROLES_TO_COMMANDS . " WHERE role_id = " . $role_id); $column_rights = db::get_single_values_array("SELECT column_id FROM " . TABLE_ROLES_TO_COLUMNS . " WHERE role_id = " . $role_id); $result = array(); $result[] = '<table style="width: 100%;">'; if (count($modules)) { foreach ($modules as $module_id => $module_name) { $result[] = '<tr style="background-color: #d3d3d3;">'; $result[] = '<td style="width: 100px;">'; $result[] = '<i>модуль</i>'; $result[] = '</td>'; $result[] = '<td colspan="100">'; // $result[] = '<div class="module">'; $result[] = '<div class="module_name"><label for="module[' . $module_id . ']">' . $module_name . '</label></div>'; $result[] = '<input type="checkbox" ' . (in_array($module_id, $module_rights) ? 'checked="checked"' : '') . ' name="module[' . $module_id . ']" class="module_checkbox" id="module[' . $module_id . ']">'; $result[] = '</td>'; // $result[] = '<div class="clear"></div>'; $result[] = '</tr>'; $submodules = get_submodules($module_id); if (count($submodules)) { foreach ($submodules as $submodule_id => $submodule_name) { $result[] = '<tr>'; $result[] = '<td>'; $result[] = '</td>'; $result[] = '<td style="width: 100px;">'; $result[] = '<i>подмодуль</i>'; $result[] = '</td>'; $result[] = '<td colspan="2">'; // $result[] = '<div class="submodule">'; $result[] = '<div class="submodule_name"><label for="submodule[' . $submodule_id . ']">' . $submodule_name . '</label></div>'; $result[] = '<input type="checkbox" ' . (in_array($submodule_id, $submodule_rights) ? 'checked="checked"' : '') . ' name="submodule[' . $submodule_id . ']" class="submodule_checkbox" id="submodule[' . $submodule_id . ']">'; // $result[] = '</div>'; $result[] = '</tr>'; $commands = get_commands($submodule_id); if (count($commands)) { $result[] = '<tr>'; $result[] = '<td>'; $result[] = '</td>'; $result[] = '<td>'; $result[] = '</td>'; $result[] = '<td style="width: 100px;">'; $result[] = '<i>команды</i>'; $result[] = '</td>'; $result[] = '<td>'; foreach ($commands as $command_id => $command_name) { $result[] = '<div class="command_wrap">'; $result[] = '<div class="command_name"><label for="command[' . $command_id . ']">' . $command_name . '</label></div>'; $result[] = '<input type="checkbox" ' . (in_array($command_id, $command_rights) ? 'checked="checked"' : '') . ' name="command[' . $command_id . ']" class="command_checkbox" id="command[' . $command_id . ']">'; $result[] = '</div>'; } $result[] = '</td>'; $result[] = '</tr>'; } $columns = get_columns($submodule_id); if (count($columns)) { $result[] = '<tr style="background-color: lightCyan;">'; $result[] = '<td>'; $result[] = '</td>'; $result[] = '<td>'; $result[] = '</td>'; $result[] = '<td style="width: 100px;">'; $result[] = '<i>колонки</i>'; $result[] = '</td>'; $result[] = '<td>'; foreach ($columns as $column_id => $column_name) { $result[] = '<div class="column_wrap">'; $result[] = '<div class="column_name"><label for="column[' . $column_id . ']">' . $column_name . '</label></div>'; $result[] = '<input type="checkbox" ' . (in_array($column_id, $column_rights) ? 'checked="checked"' : '') . ' name="column[' . $column_id . ']" class="column_checkbox" id="column[' . $column_id . ']">'; $result[] = '</div>'; } $result[] = '</td>'; $result[] = '</tr>'; } $result[] = '</td>'; } // $result[] = '</tr>'; } // $result[] = '</div>'; // $result[] = '</tr>'; // $result[] = '<div class="clear"></div>'; } } $result[] = '</table>'; return join($result, "\n"); }
/** * Returns list of tables that are unmodified or empty. * * @static * @return array of table names, empty if unknown */ protected static function guess_unmodified_empty_tables() { $data = self::get_tabledata(); $structure = self::get_tablestructure(); $prefix = get_config('dbprefix'); $unmodifiedorempties = array(); if (is_mysql()) { $records = get_records_sql_array("SHOW TABLE STATUS LIKE ?", array($prefix . '%')); foreach ($records as $info) { $tablename = strtolower($info->Name); if (strpos($tablename, $prefix) !== 0) { // incorrect table match caused by _ continue; } if (!empty($info->auto_increment)) { $tablename = substr($tablename, strlen($prefix)); if ($info->auto_increment === 1) { $unmodifiedorempties[$tablename] = $tablename; } } } unset($records); } else { if (is_postgres()) { $tables = get_tables_from_xmldb(); foreach ($tables as $table) { $tablename = $table->getName(); $columns = get_columns($tablename); if (!record_exists($tablename) && empty($data[$tablename])) { $unmodifiedorempties[$tablename] = $tablename; continue; } if (isset($columns['ID']) && isset($columns['ID']->auto_increment)) { if ($columns['ID']->auto_increment == 1) { $unmodifiedorempties[$tablename] = $tablename; } else { if (isset($structure[$tablename]['ID']->auto_increment) && $columns['ID']->auto_increment == $structure[$tablename]['ID']->auto_increment) { $unmodifiedorempties[$tablename] = $tablename; } } } } } } return $unmodifiedorempties; }
$HOMEPHONE = false; $WORKPHONE = false; $CELLPHONE = false; $SKILLLEVEL = false; $POSITION = false; $JERSEYSIZE = false; $JERSEYNUMBER1 = false; $JERSEYNUMBER2 = false; $JERSEYNUMBER3 = false; $PAYMENTPLAN = false; $DRILLEAGUE = false; $USAHOCKEYMEMBERSHIP = false; $SEASON_NAME = get_season_name($SEASON); $REPORT_NAME = $SEASON_NAME; initialize_db_columns(); $DB_COLUMNS = 'registrationId,' . get_columns() . ' fName, lName'; initialize_report(); run_report(); $smarty->assign('SEASON_ID', $SEASON); $smarty->assign('SEASON_NAME', $SEASON_NAME); $smarty->assign('PAGE_NAME', $REPORT_NAME); // Build the page require 'global_begin.php'; $smarty->display('admin/report.tpl'); require 'global_end.php'; /* * ******************************************************************************** * ******************************************************************************** * **************************L O C A L F U N C T I O N S************************** * ******************************************************************************** * ********************************************************************************
function network_list() { $interfaces = array(); // Fetch connectivity information from ip command $output = array(); exec('/sbin/ip addr list', $output, $return_var); if ($return_var) { return FALSE; } foreach ($output as $line) { $columns = get_columns($line); // Look for new device names if (is_numeric($line[0]) && isset($columns[1])) { // Get device name $interface = rtrim($columns[1], ':'); // Set Defaults $interfaces[$interface]['Interface']['text'] = $interface; $interfaces[$interface]['Media']['text'] = 'Unknown'; $interfaces[$interface]['Connected']['bool'] = FALSE; $interfaces[$interface]['Link']['bool'] = FALSE; } // Fetch Mac Address (watch out for inet6 lines as these also include the word link) if (strpos($line, 'link') !== FALSE && strpos($line, 'inet6') === FALSE && isset($columns[1])) { $interfaces[$interface]['Mac Address']['text'] = $columns[1]; } // Fetch IP Address (also used to determine if interface is connected) if (strpos($line, 'inet ') !== FALSE && isset($columns[1])) { list($interfaces[$interface]['IP Address']['text']) = explode('/', $columns[1]); $interfaces[$interface]['Connected']['bool'] = TRUE; } // Fetch IPv6 Address (also used to determine if interface is connected) if (strpos($line, 'inet6') !== FALSE && isset($columns[1])) { list($interfaces[$interface]['IPv6 Address']['text']) = explode('/', $columns[1]); $interfaces[$interface]['Connected']['bool'] = TRUE; } } // Fetch connectivity information on wireless devices from iwconfig command // Should really use iw here but it doesn't work with some cards // The reason for the redirect is to ignore non wireless cards $output = array(); exec('/sbin/iwconfig', $output, $return_var); if ($return_var) { return FALSE; } foreach ($output as $line) { // Explode out the columns $columns = get_columns($line); // Look for new device name if (isset($line[0]) && $line[0] != ' ') { // Get device name $interface = $columns[0]; // Set Defaults $interfaces[$interface]['Interface']['text'] = $interface; $interfaces[$interface]['Media']['text'] = 'Wireless'; } // Fetch Access Point Mac Address if (strpos($line, 'Access Point:') !== FALSE) { $interfaces[$interface]['Link']['bool'] = strpos($line, 'Not-Associated') === FALSE; } // Fetch ESSID if (strpos($line, 'ESSID') !== FALSE && isset($columns[3])) { $interfaces[$interface]['ESSID']['text'] = substr($columns[3], 7, -1); } // Fetch Bit Rate if (strpos($line, 'Bit Rate') !== FALSE && isset($columns[1]) && isset($columns[2])) { $interfaces[$interface]['Bit Rate']['text'] = substr($columns[1], 5) . $columns[2]; } // Fetch Link Quality if (strpos($line, 'Link Quality') !== FALSE && isset($columns[1])) { // Is it a ratio? if (strpos(substr($columns[1], 8), '/') !== FALSE) { $interfaces[$interface]['Quality']['text'] = substr($columns[1], 8); $interfaces[$interface]['Quality']['min'] = 0; $interfaces[$interface]['Quality']['positive'] = TRUE; list($interfaces[$interface]['Quality']['value'], $interfaces[$interface]['Quality']['max']) = explode('/', $interfaces[$interface]['Quality']['text']); } elseif (is_numeric(substr($columns[1], 8)) && isset($columns[2])) { $interfaces[$interface]['Quality']['text'] = substr($columns[1], 8) . $columns[2]; } else { $interfaces[$interface]['Quality']['text'] = substr($columns[1], 8); } } // Fetch Signal Level if (strpos($line, 'Signal level') !== FALSE && isset($columns[3])) { // Is it a ratio? if (strpos(substr($columns[3], 6), '/') !== FALSE) { $interfaces[$interface]['Signal']['text'] = substr($columns[3], 6); $interfaces[$interface]['Signal']['min'] = 0; $interfaces[$interface]['Signal']['positive'] = TRUE; list($interfaces[$interface]['Signal']['value'], $interfaces[$interface]['Signal']['max']) = explode('/', $interfaces[$interface]['Signal']['text']); } elseif (is_numeric(substr($columns[3], 6)) && isset($columns[4])) { $interfaces[$interface]['Signal']['text'] = substr($columns[3], 6) . $columns[4]; } else { $interfaces[$interface]['Signal']['text'] = substr($columns[3], 6); } } // Fetch Noise Level if (strpos($line, 'Noise level') !== FALSE && isset($columns[5])) { // Is it a ratio? if (strpos(substr($columns[5], 6), '/') !== FALSE) { $interfaces[$interface]['Noise']['text'] = substr($columns[5], 6); $interfaces[$interface]['Noise']['min'] = 0; $interfaces[$interface]['Noise']['positive'] = FALSE; list($interfaces[$interface]['Noise']['value'], $interfaces[$interface]['Noise']['max']) = explode('/', $interfaces[$interface]['Noise']['text']); } elseif (is_numeric(substr($columns[5], 6)) && isset($columns[6])) { $interfaces[$interface]['Noise']['text'] = substr($columns[5], 6) . $columns[6]; } else { $interfaces[$interface]['Noise']['text'] = substr($columns[5], 6); } } } // Fetch connectivity information on wired devices from ethtool command foreach ($interfaces as $interface => $details) { // Ignore wireless connections if ($details['Media']['text'] != 'Wireless') { $output = array(); exec('sudo /sbin/ethtool ' . $interface, $output, $return_var); if ($return_var) { return FALSE; } foreach ($output as $line) { // Explode out the columns $columns = get_columns($line); // Fetch Speed if (strpos($line, 'Speed') !== FALSE && isset($columns[1])) { $interfaces[$interface]['Media']['text'] = 'Wired'; $interfaces[$interface]['Bit Rate']['text'] = $columns[1]; } // Fetch Duplex if (strpos($line, 'Duplex') !== FALSE && isset($columns[1])) { $interfaces[$interface]['Media']['text'] = 'Wired'; $interfaces[$interface]['Duplex']['text'] = $columns[1]; } // Fetch Link if (strpos($line, 'Link') !== FALSE && isset($columns[2])) { $interfaces[$interface]['Media']['text'] = 'Wired'; $interfaces[$interface]['Link']['bool'] = $columns[2] == 'yes'; } } } } // Remove any garbage information foreach ($interfaces as $interface => $details) { if (!$interfaces[$interface]['Link']['bool']) { unset($interfaces[$interface]['Duplex']); unset($interfaces[$interface]['Bit Rate']); unset($interfaces[$interface]['ESSID']); unset($interfaces[$interface]['Quality']); unset($interfaces[$interface]['Noise']); unset($interfaces[$interface]['Signal']); } if (!$interfaces[$interface]['Connected']['bool']) { unset($interfaces[$interface]['IP Address']); unset($interfaces[$interface]['IPv6 Address']); } } return $interfaces; }
/** * Validate all columns in the database */ function columns() { global $umil; // Time to start going through the database and listing any extra/missing fields $last_output_table = ''; foreach ($this->db_cleaner->data->tables as $table_name => $data) { // We shouldn't mess with profile fields here. Users probably will not know what this table does or what would happen if they remove fields added to it. if ($table_name == PROFILE_FIELDS_DATA_TABLE) { continue; } if ($umil->table_exists($table_name) === false) { continue; } $existing_columns = get_columns($table_name); if ($existing_columns === false) { // Table doesn't exist, don't handle here. continue; } $columns = array_unique(array_merge(array_keys($data['COLUMNS']), $existing_columns)); sort($columns); foreach ($columns as $column) { if (!isset($data['COLUMNS'][$column]) && in_array($column, $existing_columns) || isset($data['COLUMNS'][$column]) && !in_array($column, $existing_columns)) { // Output the table block if it's not been done yet if ($last_output_table != $table_name) { $last_output_table = $table_name; $this->_section_data[$table_name] = array('NAME' => $table_name, 'TITLE' => 'COLUMNS'); } // Add the data $this->_section_data[$table_name]['ITEMS'][] = array('NAME' => $column, 'FIELD_NAME' => $table_name . '_' . $column, 'MISSING' => !in_array($column, $existing_columns) ? true : false, 'FIND' => append_sid("" . STK_ROOT_PATH . "finder." . PHP_EXT . "", 'col=' . $column . '')); if ($this->_has_changes === false) { $this->_has_changes = true; } } } } $this->success_message = 'DATABASE_TABLES_SUCCESS'; }
function memory_get_free() { $locations = array(); // Fetch location information from free command // Should probably rewrite this to cat /proc/meminfo $output = array(); exec('/usr/bin/free --bytes --old', $output, $return_var); if ($return_var) { return FALSE; } foreach ($output as $line) { $columns = get_columns($line); // Only process 4 or more column rows // Ignore row with column titles if (count($columns) >= 4 && $columns[0] != 'total') { if (rtrim($columns[0], ':') == 'Mem') { $mem = $columns[3]; } } } return $mem; }
public function definition() { global $DB; $mform =& $this->_form; switch ($_SESSION['report_type']) { case 'custom_user': $table_columns = get_columns(report::$valid_tables['user']); $table_columns['user']['user.position'] = 'Position'; $calc_type = array('total' => 'Total number of users', 'dept' => 'Total number of users per department', 'city' => 'Total number of users per city', 'min_dept' => 'Department with fewest users'); break; case 'custom_course': $table_columns = get_columns(report::$valid_tables['course']); $table_columns = array_merge($table_columns, get_columns('course_categories')); $calc_type = array('total' => 'Total number of courses', 'min_num' => 'Category with fewest courses', 'max_num' => 'Category with the most courses'); break; case 'custom_completions': $table_columns = get_columns(report::$valid_tables['course']); $table_columns = array_merge($table_columns, get_columns(report::$valid_tables['user'])); $table_columns = array_merge($table_columns, get_columns(report::$valid_tables['course_completions'])); $table_columns['course_completions']['course_completions.total_minutes'] = 'training time (Minutes)'; $table_columns['user']['user.position'] = 'Position'; $calc_type = array('total' => 'Total Sum of training minutes', 'category' => 'Sum of training minutes per category', 'user' => 'Sum of training minutes per user', 'min_time' => 'shortest completion time', 'max_time' => 'Longest completion time'); break; default: break; } $calc_type = array_prepend($calc_type, '-', '-'); // functionality: user selects columns to include -> generator joins // tables as necessary. Conditions are implied based on the tables // involved (i.e. User.first name, course_completions.* -> join on // userid) $all_cols = array(); foreach ($table_columns as $table => $columns) { $count = count($columns); if ($count > 10) { $count = $count / 2; } asort($columns); $select_col = $mform->addElement('select', $table . '_columns', 'Select ' . $table . ' columns:', $columns, array('size' => $count)); $select_col->setMultiple(true); $all_cols = array_merge($all_cols, $columns); } $tab_cols = array_prepend($all_cols, '-', '-'); $ops = report::$operators; $ops = array_prepend($ops, '-', '-'); $calcs = report::$calculations; $calcs = array_prepend($calcs, '-', '-'); $calc_items = array(); $calc_items[] = $mform->createElement('select', 'calc_type', 'Select Calculation: ', $calc_type); $calcnum = 1; $calcoptions = array(); $calcoptions[] = array(); $calcoptions[] = array(); $calcoptions[] = array(); $this->repeat_elements($calc_items, $calcnum, $calcoptions, 'calc_num', 'calc_add', $calcnum, 'Add Calculation'); $where_items = array(); $where_items[] = $mform->createElement('select', 'where_col', 'Select column to filter on: ', $tab_cols); $where_items[] = $mform->createElement('select', 'where_op', 'Select filter operation: ', $ops); $where_items[] = $mform->createElement('text', 'where_filter', 'Enter a value by: '); $mform->setType('where_filter', PARAM_NOTAGS); $where_items[] =& $mform->createElement('static', 'where_example', '', '<b>e.g. DD-MM-YYYY, trainee3, Business Writing: Email<b><br>'); $wherenum = 1; $whereoptions = array(); $whereoptions[] = array(); $whereoptions[] = array(); $whereoptions[] = array(); $this->repeat_elements($where_items, $wherenum, $whereoptions, 'where_num', 'where_add', $wherenum, 'Add Filter'); $select_order = $mform->addElement('select', 'order_by', get_string('select_order_by', 'block_dial_reports'), $tab_cols); $this->add_action_buttons(true, get_string('generate_report', 'block_dial_reports')); }
function memory_list() { // Fixed memory amounts $memory_cpu = memory_cpu(); $memory_gpu = memory_gpu(); $locations = array(); // Fetch location information from free command // Should probably rewrite this to cat /proc/meminfo $output = array(); exec('/usr/bin/free --bytes --old', $output, $return_var); if ($return_var) { return FALSE; } foreach ($output as $line) { $columns = get_columns($line); // Only process 4 or more column rows // Ignore row with column titles if (count($columns) >= 4 && $columns[0] != 'total') { $location = rtrim($columns[0], ':'); // Tidyup abbreviations used in free command if ($location == 'Mem') { $location = 'RAM'; } if (is_numeric($columns[1]) && is_numeric($columns[2]) && is_numeric($columns[3])) { // Reset the power unit so it is recalculated based on the size unset($power); // Include onboard GPU memory if ($memory_cpu && $memory_gpu && $location == 'RAM') { $reserved = $memory_cpu - $columns[1]; $used = $columns[2] + $memory_gpu + $reserved; // RAM (Total) $locations[$location]['Virtual']['bool'] = !($location == 'RAM'); $locations[$location]['Type']['text'] = $location; $locations[$location]['Size']['value'] = $memory_cpu + $memory_gpu; $locations[$location]['Size']['text'] = si_unit($memory_cpu + $memory_gpu, $power, 1024, 1) . 'B'; $locations[$location]['Free']['value'] = $columns[3]; $locations[$location]['Free']['text'] = si_unit($columns[3], $power, 1024, 1) . 'B'; $locations[$location]['Used']['value'] = $used; $locations[$location]['Used']['text'] = si_unit($used, $power, 1024, 1) . 'B'; $locations[$location]['Used']['min'] = 0; $locations[$location]['Used']['max'] = $memory_cpu + $memory_gpu; $locations[$location]['Used']['positive'] = FALSE; $locations[$location]['Used']['absolute'] = TRUE; // RAM (GPU) $locations[$location . ' (GPU)']['Virtual']['bool'] = !($location == 'RAM'); $locations[$location . ' (GPU)']['Type']['text'] = $location . ' (GPU)'; $locations[$location . ' (GPU)']['Used']['value'] = $memory_gpu; $locations[$location . ' (GPU)']['Used']['text'] = si_unit($memory_gpu, $power, 1024, 1) . 'B'; $locations[$location . ' (GPU)']['Used']['min'] = 0; $locations[$location . ' (GPU)']['Used']['max'] = $columns[3] + $memory_gpu; $locations[$location . ' (GPU)']['Used']['positive'] = FALSE; $locations[$location . ' (GPU)']['Used']['absolute'] = FALSE; // RAM (Reserved) $locations[$location . ' (Reserved)']['Virtual']['bool'] = !($location == 'RAM'); $locations[$location . ' (Reserved)']['Type']['text'] = $location . ' (Reserved)'; $locations[$location . ' (Reserved)']['Used']['value'] = $reserved; $locations[$location . ' (Reserved)']['Used']['text'] = si_unit($reserved, $power, 1024, 1) . 'B'; $locations[$location . ' (Reserved)']['Used']['min'] = 0; $locations[$location . ' (Reserved)']['Used']['max'] = $columns[3] + $reserved; $locations[$location . ' (Reserved)']['Used']['positive'] = FALSE; $locations[$location . ' (Reserved)']['Used']['absolute'] = FALSE; } else { $locations[$location]['Virtual']['bool'] = !($location == 'RAM'); $locations[$location]['Type']['text'] = $location; $locations[$location]['Size']['value'] = $columns[1]; $locations[$location]['Size']['text'] = si_unit($columns[1], $power, 1024, 1) . 'B'; $locations[$location]['Free']['value'] = $columns[3]; $locations[$location]['Free']['text'] = si_unit($columns[3], $power, 1024, 1) . 'B'; $locations[$location]['Used']['value'] = $columns[2]; $locations[$location]['Used']['text'] = si_unit($columns[2], $power, 1024, 1) . 'B'; $locations[$location]['Used']['min'] = 0; $locations[$location]['Used']['max'] = $columns[1]; $locations[$location]['Used']['positive'] = FALSE; $locations[$location]['Used']['absolute'] = TRUE; } // If we know the buffers and the cache we can calculate the app if (isset($columns[5]) && is_numeric($columns[5]) && is_numeric($columns[6]) && is_numeric($columns[6])) { $apps = $columns[1] - $columns[3] - $columns[5] - $columns[6]; $locations[$location . ' (Apps)']['Virtual']['bool'] = !($location == 'RAM'); $locations[$location . ' (Apps)']['Type']['text'] = $location . ' (Apps)'; $locations[$location . ' (Apps)']['Used']['value'] = $apps; $locations[$location . ' (Apps)']['Used']['text'] = si_unit($apps, $power, 1024, 1) . 'B'; $locations[$location . ' (Apps)']['Used']['min'] = 0; $locations[$location . ' (Apps)']['Used']['max'] = $columns[3] + $apps; $locations[$location . ' (Apps)']['Used']['positive'] = FALSE; $locations[$location . ' (Apps)']['Used']['absolute'] = FALSE; } // Buffer calulations if (isset($columns[5]) && is_numeric($columns[5])) { $locations[$location . ' (Buffers)']['Virtual']['bool'] = !($location == 'RAM'); $locations[$location . ' (Buffers)']['Type']['text'] = $location . ' (Buffers)'; $locations[$location . ' (Buffers)']['Used']['value'] = $columns[5]; $locations[$location . ' (Buffers)']['Used']['text'] = si_unit($columns[5], $power, 1024, 1) . 'B'; $locations[$location . ' (Buffers)']['Used']['min'] = 0; $locations[$location . ' (Buffers)']['Used']['max'] = $columns[3] + $columns[5]; $locations[$location . ' (Buffers)']['Used']['positive'] = FALSE; $locations[$location . ' (Buffers)']['Used']['absolute'] = FALSE; } elseif (isset($columns[5])) { $locations[$location . ' (Cache)']['Used']['text'] = $columns[5]; } // Cache calulations if (isset($columns[6]) && is_numeric($columns[6])) { $locations[$location . ' (Cache)']['Virtual']['bool'] = !($location == 'RAM'); $locations[$location . ' (Cache)']['Type']['text'] = $location . ' (Cache)'; $locations[$location . ' (Cache)']['Used']['value'] = $columns[6]; $locations[$location . ' (Cache)']['Used']['text'] = si_unit($columns[6], $power, 1024, 1) . 'B'; $locations[$location . ' (Cache)']['Used']['min'] = 0; $locations[$location . ' (Cache)']['Used']['max'] = $columns[3] + $columns[6]; $locations[$location . ' (Cache)']['Used']['positive'] = FALSE; $locations[$location . ' (Cache)']['Used']['absolute'] = FALSE; } elseif (isset($columns[6])) { $locations[$location . ' (Cache)']['Used']['text'] = $columns[6]; } } else { // Fallback if we don't get numerical values $locations[$location]['Virtual']['bool'] = !($location == 'RAM'); $locations[$location]['Type']['text'] = $location; $locations[$location]['Size']['text'] = $columns[1]; $locations[$location]['Used']['text'] = $columns[2]; $locations[$location]['Free']['text'] = $columns[3]; } } } return $locations; }