function pmaster_main() { global $gbl, $sgbl, $login, $ghtml; global $argv; ob_start(); $pass = slave_get_db_pass(); $tfile = ltempnam("/tmp", "mastertmp"); $dbf = $sgbl->__var_dbf; $list = parse_opt($argv); $slavepass = $list['slavepass']; add_line_to_master_mycnf(); mysql_connect("localhost", "root", $pass); mysql_query("grant replication slave on *.* to lxlabsslave@'%' identified by '{$slavepass}'"); system("mysqldump --master-data -u root '-p{$pass}' {$dbf} > {$tfile}"); ob_clean(); readfile($tfile); ob_start(); unlink($tfile); ob_clean(); }
function pmaster_main() { global $gbl, $sgbl, $login, $ghtml; global $argv; ob_start(); $pass = slave_get_db_pass(); $tfile = ltempnam("/tmp", "mastertmp"); $dbf = $sgbl->__var_dbf; $list = parse_opt($argv); $slavepass = $list['slavepass']; add_line_to_master_mycnf(); // TODO: REPLACE MYSQL_CONNECT $dblink = mysqli_connect("localhost", "root", $pass, $dbf); mysqli_query($dblink, "GRANT REPLICATION SLAVE ON *.* TO lxlabsslave@'%' IDENTIFIED BY '{$slavepass}'"); system("mysqldump --master-data -u root '-p{$pass}' {$dbf} > {$tfile}"); ob_clean(); readfile($tfile); ob_start(); unlink($tfile); ob_clean(); }
function rrd_graph_server($type, $list, $time) { global $gbl, $sgbl, $login, $ghtml; global $global_dontlogshell; global $global_shell_error; $global_dontlogshell = true; $graphfile = ltempnam("/tmp", "lx_graph"); $color = array("000000", "b54f6f", "00bb00", "a0ad00", "0090bf", "56a656", "00bbbf", "bfbfbf", "458325", "f04050", "a0b2c5", "cf0f00", "a070ad", "cf8085", "af93af", "90bb9f", "00d500", "00ff00", "aaffaa", "00ffff", "aa00ff", "ffff00", "aaff00", "faff00", "0aff00", "6aff00", "eaffa0", "abff0a", "afffaa", "deab3d", "333333", "894367", "234567", "fbdead", "fadec1", "fa3d9c", "f54398", "f278d3", "f512d3", "43f3f9", "f643f9"); if ($time >= 7 * 24 * 3600) { $grid = 'HOUR:12:DAY:2:WEEK:8:0:%X'; } else { if ($time >= 24 * 3600) { $grid = 'MINUTE:30:HOUR:2:HOUR:8:0:%X'; } else { $grid = 'MINUTE:3:MINUTE:30:HOUR:1:0:%X'; } } switch ($type) { case "traffic": $i = 0; foreach ($list as $k => $file) { $i++; $fullpath = "{$sgbl->__path_program_root}/data/{$type}/{$file}.rrd"; if (!lxfile_exists($fullpath)) { continue; } $arg[] = "DEF:dss{$i}={$fullpath}:total:AVERAGE"; if (isset($color[$i])) { $arg[] = "LINE1:dss{$i}#{$color[$i]}:{$k}"; } else { $arg[] = "LINE1:dss{$i}#000000:{$k}"; } } $arglist = array('rrdtool', 'graph', $graphfile, '--start', "-{$time}", '-w', '600', '-h', '200', '--x-grid', $grid, '--vertical-label=Bytes/s'); $arglist = lx_array_merge(array($arglist, $arg)); $ret = call_user_func_array("lxshell_return", $arglist); break; default: $i = 0; foreach ($list as $k => $file) { $i++; $fullpath = "{$sgbl->__path_program_root}/data/{$type}/{$file}.rrd"; $arg[] = "DEF:dss{$i}={$fullpath}:{$type}:AVERAGE"; if (isset($color[$i])) { $arg[] = "LINE1:dss{$i}#{$color[$i]}:{$k}"; } else { $arg[] = "LINE1:dss{$i}#000000:{$k}"; } } $arglist = array('rrdtool', 'graph', $graphfile, '--start', "-{$time}", '-w', '600', '-h', '200', '--x-grid', $grid, "--vertical-label={$type}"); $arglist = lx_array_merge(array($arglist, $arg)); $ret = call_user_func_array("lxshell_return", $arglist); break; } if ($ret) { throw new lxexception("graph_generation_failed", null, $global_shell_error); } $content = lfile_get_contents($graphfile); lunlink($graphfile); $global_dontlogshell = false; return $content; }
function __ac_desc_graph($object) { global $gbl, $sgbl, $login, $ghtml; $subaction = $ghtml->frm_subaction; $selflist = $object->getSelfList(); if (!$ghtml->frm_c_graph_time) { $ghtml->frm_c_graph_time = '1d'; } $object->createShowPropertyList($alist); $object->createShowAlist($alist, $subaction); $nalist = null; if (!isset($alist['property'])) { $alist['property'] = array(); } $nalist = lx_merge_good($nalist, $alist['property']); remove_if_older_than_a_minute_dir("__path_program_htmlbase/tmp/"); $ghtml->print_tab_block($nalist); if ($selflist) { $ghtml->printShowSelectBox($selflist); } if (cse($ghtml->frm_subaction, 'base')) { $core = strtil($ghtml->frm_subaction, "base"); $ghtml->__http_vars['frm_subaction'] = "{$core}traffic"; $subaction = "{$core}traffic"; } $galist = $object->createGraphList(); $ghtml->print_tab_block($galist); $graphtlist = array('1h' => '1h', '12h' => '12h', '1d' => '1d', '2d' => '2d', '1week' => '1week', '1month' => '1month'); $gtlistsec = array('1h' => 3600, '12h' => 12 * 3600, '1d' => 24 * 3600, '2d' => 2 * 24 * 3600, '1week' => 7 * 24 * 3600, '1month' => 30 * 24 * 3600, '1year' => 365 * 24 * 3600); $ghtml->printGraphSelect($graphtlist); lxfile_mkdir("__path_program_htmlbase/tmp"); $tmpgraph = ltempnam("__path_program_htmlbase/tmp/", "graph"); $object->setUpdateSubaction("graph_{$subaction}"); $time = $ghtml->frm_c_graph_time; $object->rrdtime = $gtlistsec[$time]; try { $object->createExtraVariables(); $file = rl_exec_set(null, $object->syncserver, $object); } catch (lxException $e) { $ghtml->print_curvy_table_start(); print "Graph Failed due to {$e->getMessage()} {$e->value}"; $ghtml->print_curvy_table_end(); $object->dbaction = 'clean'; return; } $object->dbaction = 'clean'; lfile_put_contents($tmpgraph, $file); $tmpgraph = basename($tmpgraph); print "<img src=/tmp/{$tmpgraph}>"; }