function run() { // HowTo: A simple Advisory system in 3 easy steps. // Step 1: Get some variables to evaluate on $this->variables = array_merge(PMA_DBI_fetch_result('SHOW GLOBAL STATUS', 0, 1), PMA_DBI_fetch_result('SHOW GLOBAL VARIABLES', 0, 1)); if (PMA_DRIZZLE) { $this->variables = array_merge($this->variables, PMA_DBI_fetch_result("SELECT concat('Com_', variable_name), variable_value\n FROM data_dictionary.GLOBAL_STATEMENTS", 0, 1)); } // Add total memory to variables as well include_once 'libraries/sysinfo.lib.php'; $sysinfo = getSysInfo(); $memory = $sysinfo->memory(); $this->variables['system_memory'] = $memory['MemTotal']; // Step 2: Read and parse the list of rules $this->parseResult = $this->parseRulesFile(); // Step 3: Feed the variables to the rules and let them fire. Sets $runResult $this->runRules(); return array('parse' => array('errors' => $this->parseResult['errors']), 'run' => $this->runResult); }
$sysinfo = getSysInfo(); } if (!$cpuload) { $cpuload = $sysinfo->loadavg(); } if (PHP_OS == 'Linux') { $ret[$chart_id][$node_id][$point_id]['idle'] = $cpuload['idle']; $ret[$chart_id][$node_id][$point_id]['busy'] = $cpuload['busy']; } else { $ret[$chart_id][$node_id][$point_id]['value'] = $cpuload['loadavg']; } break; case 'memory': if (!$sysinfo) { include_once 'libraries/sysinfo.lib.php'; $sysinfo = getSysInfo(); } if (!$memory) { $memory = $sysinfo->memory(); } $ret[$chart_id][$node_id][$point_id]['value'] = $memory[$pName]; break; } /* switch */ } /* foreach */ } /* foreach */ } /* foreach */ // Retrieve all required status variables
/** * show system information @ingroup pages */ function systemInfo() { global $PH; require_once confGet('DIR_STREBER') . 'render/render_list.inc.php'; $system_info = getSysInfo(); $page = new Page(); $page->tabs['admin'] = array('target' => "index.php?go=systemInfo", 'title' => __('Admin', 'top navigation tab'), 'bg' => "misc"); $page->cur_tab = 'admin'; $page->crumbs[] = new NaviCrumb(array('target_id' => 'systemInfo')); $page->title = __("System information"); $page->type = __("Admin"); #$page->title_minor=get('go'); echo new PageHeader(); echo new PageContentOpen(); $block = new PageBlock(array('title' => __('Overview'), 'id' => 'overview')); $block->render_blockStart(); echo "<div class=text>"; foreach ($system_info as $label => $value) { echo "<div class=labeled><label>{$label}:</label> <span>{$value}</span></div>"; } echo "</div>"; global $auth; echo "<br>"; echo "<h2>Timezone detection</h2>"; echo "<div class=text>"; echo "<ul>"; echo "<li> time-offset for user: "******"sec"; echo "<li> renderDateHtml(): " . renderDateHtml($auth->cur_user->last_login) . ""; echo "<li> original db-string (should be GMT): " . $auth->cur_user->last_login; echo "<li> strToClienttime(): " . strToClientTime($auth->cur_user->last_login); echo "<li> gmdate:(strToClientTime) " . gmdate("H:i:s", strToClientTime($auth->cur_user->last_login)); echo "<li> strToTime(): " . strToTime($auth->cur_user->last_login); echo "<li> date(strToTime): " . date("H:i:s", strToTime($auth->cur_user->last_login)); echo "</ul>"; echo "</div>"; $block->render_blockEnd(); echo new PageContentClose(); echo new PageHtmlEnd(); }
function workspaceRestore($backupFilename, $targetWorkspace, $overwrite) { $tempDirectory = tempnam(__FILE__, ''); if (file_exists($tempDirectory)) { unlink($tempDirectory); } if (file_exists($tempDirectory)) { G::rm_dir($tempDirectory); } G::mk_dir($tempDirectory); G::LoadThirdParty('pear/Archive', 'Tar'); $tar = new Archive_Tar($backupFilename); $res = $tar->extract($tempDirectory); $metadataFilename = $tempDirectory . PATH_SEP . 'metadata.txt'; if (!file_exists($metadataFilename)) { /* Look for legacy backups, where metadata was stored as a file with the * workspace name, such as workflow.txt * This means the backup filename must be the same as the metadata file. */ $info = pathinfo($backupFilename); /* Check if it's a compressed backup, in which case we need to remove * both the gz and the tar extensions. */ if ($info['extension'] == "gz") { $info = pathinfo(basename($backupFilename, '.' . $info['extension'])); } $wsNameFromTar = basename($backupFilename, '.' . $info['extension']); $metadataFilename = $tempDirectory . PATH_SEP . $wsNameFromTar . '.txt'; if (!file_exists($metadataFilename)) { throw new Exception("Metadata file was not found in backup"); } } $metadata = unserialize(file_get_contents($metadataFilename)); $backupWorkspace = $metadata['WORKSPACE_NAME']; $changeWorkspace = isset($targetWorkspace); if (!$changeWorkspace) { $targetWorkspace = $backupWorkspace; } else { echo "Restoring from workspace: " . pakeColor::colorize($backupWorkspace, 'INFO') . "\n"; } echo "Restoring to workspace: " . pakeColor::colorize($targetWorkspace, 'INFO') . "\n"; //moving the site files $backupWorkspaceDir = $tempDirectory . PATH_SEP . $backupWorkspace; $targetWorkspaceDir = PATH_DATA . 'sites' . PATH_SEP . $targetWorkspace; if (!$overwrite && file_exists($targetWorkspaceDir)) { $overwrite = strtolower(prompt('Workspace already exists, do you want to overwrite? [Y/n]')); if (array_search(trim($overwrite), array("y", "")) === false) { die; } $overwrite = true; } printf("Moving files to %s \n", pakeColor::colorize($targetWorkspaceDir, 'INFO')); /* We already know we will be overwriting the new workspace if we reach this * point, so remove the workspace directory if it exists. */ if (file_exists($targetWorkspaceDir)) { G::rm_dir($targetWorkspaceDir); } if (!rename($backupWorkspaceDir, $targetWorkspaceDir)) { throw new Exception("There was an error moving from {$backupWorkspaceDir} to {$targetWorkspaceDir}"); } $dbOpt = @explode(SYSTEM_HASH, G::decrypt(HASH_INSTALLATION, SYSTEM_HASH)); $dbHostname = $dbOpt[0]; /* TODO: Check if database exists after updateDBfile */ $config = updateDBfile($targetWorkspaceDir, $targetWorkspace, $dbHostname, $changeWorkspace); G::LoadSystem('dbMaintenance'); $oDbMaintainer = new DataBaseMaintenance($dbOpt[0], $dbOpt[1], $dbOpt[2]); $dbName = $config['DB_NAME']; $dbUser = $config['DB_USER']; $dbPass = $config['DB_PASS']; restoreDB($dbHostname, $oDbMaintainer, $metadata['DB_NAME'], $dbName, $dbUser, $dbPass, $tempDirectory, $overwrite); $dbName = $config['DB_RBAC_NAME']; $dbUser = $config['DB_RBAC_USER']; $dbPass = $config['DB_RBAC_PASS']; restoreDB($dbHostname, $oDbMaintainer, $metadata['DB_RBAC_NAME'], $dbName, $dbUser, $dbPass, $tempDirectory, $overwrite); $dbName = $config['DB_REPORT_NAME']; $dbUser = $config['DB_REPORT_USER']; $dbPass = $config['DB_REPORT_PASS']; restoreDB($dbHostname, $oDbMaintainer, $metadata['DB_REPORT_NAME'], $dbName, $dbUser, $dbPass, $tempDirectory, $overwrite); echo "\n"; $wsInfo = getSysInfo(); $wsInfo['WORKSPACE_NAME'] = $targetWorkspace; $wsInfo = array_merge($wsInfo, $config); printInfoSites($metadata, $wsInfo); return true; }