From 3157fc4d0029387be6de495a6546efbb3ee49282 Mon Sep 17 00:00:00 2001 From: Nozomi Anzai Date: Thu, 6 Oct 2011 04:45:58 +0000 Subject: [PATCH] rearrange to read easier - add empty rows - add comments - based on one coding rule - sort parameters by their order in pgpool.conf (definePgpoolConfParam.php) --- changePassword.php | 20 +- command.php | 86 ++++--- common.php | 264 ++++++++++---------- config.php | 428 +++++++++++++++------------------ definePgpoolConfParam.php | 371 ++++++++++++++++------------ index.php | 2 +- innerLog.php | 8 +- innerNodeServerStatus.php | 13 +- innerSummary.php | 14 +- innerSystemCatalog.php | 26 +- login.php | 62 ++--- nodeServerStatus.php | 2 +- nodeStatus.php | 86 ++++--- pgconfig.php | 382 ++++++++++++++++------------- procInfo.php | 24 +- queryCache.php | 93 +++---- status.php | 130 +++++----- systemDb.php | 413 ++++++++++++++++--------------- templates/config.tpl | 10 +- templates/error.tpl | 2 - templates/login.tpl | 4 +- templates/menu.tpl | 1 - templates/nodeServerStatus.tpl | 11 +- templates/nodeStatus.tpl | 25 +- templates/pgconfig.tpl | 242 ++++++++++++++----- version.php | 2 +- 26 files changed, 1503 insertions(+), 1218 deletions(-) diff --git a/changePassword.php b/changePassword.php index c9915ab..5f835b8 100644 --- a/changePassword.php +++ b/changePassword.php @@ -40,23 +40,23 @@ if(isset($_POST['action'])) { switch ( $action ) { case 'update': - + if(!isset($_POST['password']) || !isset($_POST['password2'])) { $tpl->display('changePassword.tpl'); break; } - + $password = $_POST['password']; $password2 = $_POST['password2']; - + if($password == '' || $password2 == '') { $tpl->assign('error', $message['errPasswordMismatch']); $tpl->display('changePassword.tpl'); break; } - + if($password === $password2) { - + $passFile = @file(_PGPOOL2_PASSWORD_FILE); if($passFile == false) { $errorCode = 'e6001'; @@ -64,7 +64,7 @@ switch ( $action ) { $tpl->display('error.tpl'); exit(); } - + if( ! is_writable(_PGPOOL2_PASSWORD_FILE) ) { $errorCode = 'e6003'; $tpl->assign('errorCode', $errorCode); @@ -72,19 +72,19 @@ switch ( $action ) { exit(); } $fw = fopen(_PGPOOL2_PASSWORD_FILE, 'w'); - + for($i=0; $idisplay('login.tpl'); break; diff --git a/command.php b/command.php index 01dab2d..0c67c57 100644 --- a/command.php +++ b/command.php @@ -32,29 +32,35 @@ require_once('common.php'); * @param srgs $num * @return array */ -function execPcp($command, $num='') { +function execPcp($command, $num='') +{ $pcpStatus = array ( - '0' => 'SUCCESS', - '1' => 'UNKNOWNERR', - '2' => 'EOFERR', - '3' => 'NOMEMERR', - '4' => 'READERR', - '5' => 'WRITEERR', - '6' => 'TIMEOUTERR', - '7' => 'INVALERR', - '8' => 'CONNERR', - '9' => 'NOCONNERR', - '10' => 'SOCKERR', - '11' => 'HOSTERR', - '12' => 'BACKENDERR', - '13' => 'AUTHERR', + '0' => 'SUCCESS', + '1' => 'UNKNOWNERR', + '2' => 'EOFERR', + '3' => 'NOMEMERR', + '4' => 'READERR', + '5' => 'WRITEERR', + '6' => 'TIMEOUTERR', + '7' => 'INVALERR', + '8' => 'CONNERR', + '9' => 'NOCONNERR', + '10' => 'SOCKERR', + '11' => 'HOSTERR', + '12' => 'BACKENDERR', + '13' => 'AUTHERR', '127' => 'COMMANDERROR' ); $param = readPcpInfo(); $param['hostname'] = _PGPOOL2_PCP_HOSTNAME; - $args = " " . $param['pcp_timeout'] . " " . $param['hostname'] . " " . $param['pcp_port'] . " ". $_SESSION[SESSION_LOGIN_USER] . " '" . $_SESSION[SESSION_LOGIN_USER_PASSWORD] . "' " . $num; + $args = " " . $param['pcp_timeout'] . + " " . $param['hostname'] . + " " . $param['pcp_port'] . + " ". $_SESSION[SESSION_LOGIN_USER] . + " '" . $_SESSION[SESSION_LOGIN_USER_PASSWORD] . "' " . + $num; switch ($command) { case 'PCP_NODE_COUNT': @@ -66,47 +72,47 @@ function execPcp($command, $num='') { $cmd = _PGPOOL2_PCP_DIR . '/pcp_node_info' . $args; $ret = exec($cmd, $output, $return_var); break; - + case 'PCP_ATTACH_NODE': $cmd = _PGPOOL2_PCP_DIR . '/pcp_attach_node' . $args; $ret = exec($cmd, $output, $return_var); break; - + case 'PCP_DETACH_NODE': $cmd = _PGPOOL2_PCP_DIR . '/pcp_detach_node' . $args; $ret = exec($cmd, $output, $return_var); break; - + case 'PCP_PROC_COUNT': $cmd = _PGPOOL2_PCP_DIR . '/pcp_proc_count' . $args; $ret = exec($cmd, $output, $return_var); break; - + case 'PCP_PROC_INFO': $cmd = _PGPOOL2_PCP_DIR . '/pcp_proc_info' . $args; $ret = exec($cmd, $output, $return_var); $ret = $output; break; - + case 'PCP_START_PGPOOL': - $configOption = ' -f ' . _PGPOOL2_CONFIG_FILE . ' -F ' . _PGPOOL2_PASSWORD_FILE; - - if(isPipe($num)) { - $cmdOption = $configOption . $num . ' > /dev/null &'; - } else { - $cmdOption = $configOption . $num . ' 2>&1 &'; - } - - /* we should not check pid file here. - * let pgpool handle bogus pid file + $configOption = ' -f ' . _PGPOOL2_CONFIG_FILE . + ' -F ' . _PGPOOL2_PASSWORD_FILE; + + if(isPipe($num)) { + $cmdOption = $configOption . $num . ' > /dev/null &'; + } else { + $cmdOption = $configOption . $num . ' 2>&1 &'; + } + + /* we should not check pid file here. + * let pgpool handle bogus pid file * if(DoesPgpoolPidExist()) { * return array('FAIL'=> ''); * } - */ + */ $cmd = _PGPOOL2_COMMAND . $cmdOption; - //var_dump($cmd);exit; $ret = exec($cmd, $output, $return_var); - if($return_var == 0) { + if ($return_var == 0) { return array($pcpStatus[$return_var] => $output); } else { return array('FAIL' => $output); @@ -115,18 +121,18 @@ function execPcp($command, $num='') { case 'PCP_RELOAD_PGPOOL': $cmdOption = $num; - $cmdOption = $cmdOption . ' -f ' . _PGPOOL2_CONFIG_FILE - . ' -F ' . _PGPOOL2_PASSWORD_FILE . ' reload'; + $cmdOption = $cmdOption . + ' -f ' . _PGPOOL2_CONFIG_FILE . + ' -F ' . _PGPOOL2_PASSWORD_FILE . ' reload'; $cmd = _PGPOOL2_COMMAND . $cmdOption . ' 2>&1 &'; $ret = exec($cmd, $output, $return_var); - if($return_var == 0) { + if ($return_var == 0) { return array($pcpStatus[$return_var] => $output); } else { return array('FAIL' => $output); } break; - case 'PCP_STOP_PGPOOL': $cmd = _PGPOOL2_PCP_DIR . '/pcp_stop_pgpool' . $args; $ret = exec($cmd, $output, $return_var); @@ -148,8 +154,8 @@ function execPcp($command, $num='') { * * @return array */ -function readPcpInfo() { - +function readPcpInfo() +{ $params = readConfigParams(array('pcp_port', 'pcp_timeout')); return $params; } diff --git a/common.php b/common.php index 274439d..11f3c13 100644 --- a/common.php +++ b/common.php @@ -46,7 +46,7 @@ define('SMARTY_COMPILE_DIR', dirname(__FILE__) . '/templates_c' ); $tpl = new Smarty(); $tpl->assign('version', $version); -if(!file_exists('conf/pgmgt.conf.php')) { +if (!file_exists('conf/pgmgt.conf.php')) { include('lang/en.lang.php'); $tpl->assign('message', $message); $tpl->display('pgmgtNotFound.tpl'); @@ -59,7 +59,7 @@ require_once('conf/pgmgt.conf.php'); * Check login */ $isLogin = FALSE; -if(isset($_SESSION[SESSION_LOGIN_USER])) { +if (isset($_SESSION[SESSION_LOGIN_USER])) { $isLogin = TRUE; $tpl->assign('isLogin', $isLogin); } @@ -68,21 +68,21 @@ if(isset($_SESSION[SESSION_LOGIN_USER])) { * Check pgmgt.conf.php Parameter */ $errors = array(); -if( !defined('_PGPOOL2_LANG') - || !defined('_PGPOOL2_CONFIG_FILE') - || !defined('_PGPOOL2_PASSWORD_FILE') - || !defined('_PGPOOL2_COMMAND') - || !defined('_PGPOOL2_PCP_DIR') - || !defined('_PGPOOL2_PCP_HOSTNAME') - || !defined('_PGPOOL2_STATUS_REFRESH_TIME')) { - - include('lang/en.lang.php'); - $tpl->assign('message', $message); - $errorCode = 'e7'; - $tpl->assign('errorCode', $errorCode); - $tpl->display('error.tpl'); - exit(); - } +if (!defined('_PGPOOL2_LANG') || + !defined('_PGPOOL2_CONFIG_FILE') || + !defined('_PGPOOL2_PASSWORD_FILE') || + !defined('_PGPOOL2_COMMAND') || + !defined('_PGPOOL2_PCP_DIR') || + !defined('_PGPOOL2_PCP_HOSTNAME') || + !defined('_PGPOOL2_STATUS_REFRESH_TIME')) +{ + include('lang/en.lang.php'); + $tpl->assign('message', $message); + $errorCode = 'e7'; + $tpl->assign('errorCode', $errorCode); + $tpl->display('error.tpl'); + exit(); +} /** * Create message catalog list @@ -90,17 +90,17 @@ if( !defined('_PGPOOL2_LANG') $messageList = array(); $res_dir = opendir('lang/'); -while($file_name = readdir( $res_dir )) { - if(preg_match('/.*\.lang\.php$/', $file_name)) { - if(@is_file('lang/' . $file_name)) { +while ($file_name = readdir( $res_dir )) { + if (preg_match('/.*\.lang\.php$/', $file_name)) { + if (@is_file('lang/' . $file_name)) { include('lang/' . $file_name); - $messageList[$message['lang']] = $message['strLang']; + $messageList[$message['lang']] = $message['strLang']; + } else { $errorCode = 'e2'; $tpl->assign('errorCode', $errorCode); $tpl->display('error.tpl'); exit(); - } } } @@ -123,18 +123,18 @@ $_SESSION[SESSION_MESSAGE] = $message; */ function openDBConnection($param) { - $host= $param['hostname']; - $port = $param['port']; - $dbname = $param['dbname']; - $user = $param['user']; + $host = $param['hostname']; + $port = $param['port']; + $dbname = $param['dbname']; + $user = $param['user']; $password = $param['password']; - if($host != '') { + if ($host != '') { $conStr = "host=$host port=$port dbname=$dbname user=$user password=$password" ; } else { $conStr = "port=$port dbname=$dbname user=$user password=$password" ; } - + $con = @pg_connect($conStr); return $con; } @@ -156,10 +156,11 @@ function closeDBConnection($connection) * @param string $sql * @return resource */ -function execQuery($conn, $sql) { +function execQuery($conn, $sql) +{ $rs = @pg_query($conn, $sql); - if(!pg_result_status($rs) == PGSQL_TUPLES_OK) { - return false; + if (!pg_result_status($rs) == PGSQL_TUPLES_OK) { + return FALSE; } return $rs; @@ -170,33 +171,36 @@ function execQuery($conn, $sql) { * * @return string */ -function selectLanguage($selectLang, $messageList) { - if( $selectLang == null || $selectLang == 'auto') { +function selectLanguage($selectLang, $messageList) +{ + if ($selectLang == NULL || $selectLang == 'auto') { if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { $acceptLanguages = $_SERVER['HTTP_ACCEPT_LANGUAGE']; } else { $acceptLanguages = FALSE; } - - $lang = null; - - if($acceptLanguages == FALSE) { + + $lang = NULL; + + if ($acceptLanguages == FALSE) { $lang = 'en'; + } else { $langList = split(',|;', $acceptLanguages); - foreach($langList as $acceptLanguage) { - foreach(array_keys($messageList) as $messageLanguage) { - if( $acceptLanguage == $messageLanguage ) { + foreach ($langList as $acceptLanguage) { + foreach (array_keys($messageList) as $messageLanguage) { + if ($acceptLanguage == $messageLanguage ) { $lang = $messageLanguage; break; } } - if( $lang != null) break; + if ($lang != NULL) { break; } } } } else { $lang = $selectLang; } + $_SESSION[SESSION_LANG] = $lang; return $lang; } @@ -206,14 +210,14 @@ function selectLanguage($selectLang, $messageList) { * * @return bool */ -function isParallelMode() { - +function isParallelMode() +{ $params = readConfigParams(array('parallel_mode')); - if($params['parallel_mode'] == 'true') { - return true; + if ($params['parallel_mode'] == 'true') { + return TRUE; } else { - return false; + return FALSE; } } @@ -222,15 +226,17 @@ function isParallelMode() { * * @return bool */ -function NodeActive($num) { +function NodeActive($num) +{ $healthCheckDb = 'template1'; - + $params = readHealthCheckParam(); - + $healthCheckUser = $params['health_check_user']; $backendHostName = $params['backend_hostname'][$num]; - $backendPort = $params['backend_port'][$num]; - if($backendHostName != '') { + $backendPort = $params['backend_port'][$num]; + + if ($backendHostName != '') { $conStr = "dbname=$healthCheckDb user=$healthCheckUser host=$backendHostName port=$backendPort" ; } else { $conStr = "dbname=$healthCheckDb port=$backendPort user=$healthCheckUser" ; @@ -238,7 +244,7 @@ function NodeActive($num) { $conn = @pg_connect($conStr); - if($conn == FALSE) { + if ($conn == FALSE) { @pg_close($conn); return FALSE; } else { @@ -252,21 +258,24 @@ function NodeActive($num) { * * @return integer */ -function NodeStandby($num) { +function NodeStandby($num) +{ - $params = readConfigParams(array('master_slave_mode','master_slave_sub_mode')); + $params = readConfigParams(array('master_slave_mode','master_slave_sub_mode')); - if ($params['master_slave_mode'] != 'true' || $params['master_slave_sub_mode'] != 'stream') - return -1; + if ($params['master_slave_mode'] != 'true' || $params['master_slave_sub_mode'] != 'stream') { + return -1; + } $healthCheckDb = 'template1'; - + $params = readHealthCheckParam(); - + $healthCheckUser = $params['health_check_user']; $backendHostName = $params['backend_hostname'][$num]; - $backendPort = $params['backend_port'][$num]; - if($backendHostName != '') { + $backendPort = $params['backend_port'][$num]; + + if ($backendHostName != '') { $conStr = "dbname=$healthCheckDb user=$healthCheckUser host=$backendHostName port=$backendPort" ; } else { $conStr = "dbname=$healthCheckDb port=$backendPort user=$healthCheckUser" ; @@ -274,40 +283,42 @@ function NodeStandby($num) { $conn = @pg_connect($conStr); - if($conn == FALSE) { + if ($conn == FALSE) { @pg_close($conn); return -1; - } + } - $res = pg_query($conn, 'SELECT pg_is_in_recovery()'); - if(!pg_result_status($res) == PGSQL_TUPLES_OK) { + $res = pg_query($conn, 'SELECT pg_is_in_recovery()'); + if (!pg_result_status($res) == PGSQL_TUPLES_OK) { return -1; } - $rr = pg_fetch_array($res); + $rr = pg_fetch_array($res); - if ($rr[0][0] == 't') - $r = 1; - else - $r = 0; + if ($rr[0][0] == 't') { + $r = 1; + } else { + $r = 0; + } - @pg_free_result($res); - @pg_close($conn); - return $r; + @pg_free_result($res); + @pg_close($conn); + return $r; } /** - * Read parameter from pgpool.conf using health check + * Read parameter from pgpool.conf using health check * * @return array */ -function readHealthCheckParam() { - +function readHealthCheckParam() +{ + $params = readConfigParams(array('health_check_user', - 'backend_hostname', - 'backend_port', - 'backend_weight')); - + 'backend_hostname', + 'backend_port', + 'backend_weight')); + return $params; } @@ -316,13 +327,14 @@ function readHealthCheckParam() { * * @return bool */ -function DoesPgpoolPidExist() { +function DoesPgpoolPidExist() +{ $params = readConfigParams(array('pid_file_name')); $pidFile = $params['pid_file_name']; - if( file_exists($pidFile) ) { - return true; + if (file_exists($pidFile) ) { + return TRUE; } - return false; + return FALSE; } /** @@ -330,8 +342,9 @@ function DoesPgpoolPidExist() { * * @return bool */ -function readLogDir() { - +function readLogDir() +{ + $params = readConfigParams(array('logdir')); return $params['logdir']; } @@ -341,14 +354,14 @@ function readLogDir() { * * @return bool */ -function isReplicationMode() { - +function isReplicationMode() +{ $params = readConfigParams(array('replication_mode')); - if($params['replication_mode'] == 'true') { - return true; + if ($params['replication_mode'] == 'true') { + return TRUE; } else { - return false; + return FALSE; } } @@ -357,14 +370,14 @@ function isReplicationMode() { * * @return bool */ -function isMasterSlaveMode() { - +function isMasterSlaveMode() +{ $params = readConfigParams(array('master_slave_mode')); - if($params['master_slave_mode'] == 'true') { - return true; + if ($params['master_slave_mode'] == 'true') { + return TRUE; } else { - return false; + return FALSE; } } @@ -375,13 +388,13 @@ function isMasterSlaveMode() { * @param array $paramList * @return array */ -function readConfigParams($paramList = FALSE) { - +function readConfigParams($paramList = FALSE) +{ $results = array(); $configParam = array(); - + $configFile = @file(_PGPOOL2_CONFIG_FILE); - if($configFile == false) { + if ($configFile == FALSE) { $errTpl = new Smarty(); $errTpl->assign('message', $_SESSION[SESSION_MESSAGE]); $errorCode = 'e4'; @@ -389,62 +402,65 @@ function readConfigParams($paramList = FALSE) { $errTpl->display('error.tpl'); exit(); } - + foreach ($configFile as $line_num => $line) { $line = trim($line); - if(preg_match("/^\w/", $line)) { + if (preg_match("/^\w/", $line)) { list($key, $value) = explode("=", $line); - + $key = trim($key); $value = trim($value); - - if(preg_match("/^backend_hostname/", $key)) { + + if (preg_match("/^backend_hostname/", $key)) { $num = str_replace('backend_hostname', '', $key); $configParam['backend_hostname'][$num] = str_replace("'", "", $value); - } - else if(preg_match("/^backend_port/", $key)) { + + } elseif (preg_match("/^backend_port/", $key)) { $num = str_replace('backend_port', '', $key); $configParam['backend_port'][$num] = $value; - } - else if(preg_match("/^backend_weight/", $key)) { + + } elseif (preg_match("/^backend_weight/", $key)) { $num = str_replace('backend_weight', '', $key); $configParam['backend_weight'][$num] = $value; - } - else if(preg_match("/^backend_data_directory/", $key)) { + + } elseif (preg_match("/^backend_data_directory/", $key)) { $num = str_replace('backend_data_directory', '', $key); $configParam['backend_data_directory'][$num] =str_replace("'", "", $value); - } - else { + + } else { $configParam[$key] = str_replace("'", "", $value); } } } - - if(is_array($paramList)) { - foreach($paramList as $key) { - if(isset($configParam[$key])) { + + if (is_array($paramList)) { + foreach ($paramList as $key) { + if (isset($configParam[$key])) { $results[$key] = $configParam[$key]; } else { include('definePgpoolConfParam.php'); - if(!preg_match("/^backend_hostname/", $key) - && !preg_match("/^backend_port/", $key) - && !preg_match("/^backend_weight/", $key) - && !preg_match("/^backend_data_directory/", $key)) { + if(!preg_match("/^backend_hostname/", $key) && + !preg_match("/^backend_port/", $key) && + !preg_match("/^backend_weight/", $key) && + !preg_match("/^backend_data_directory/", $key)) + { $results[$key] = $pgpoolConfigParam[$key]['default']; } } } + } else { $results = $configParam; } - + return $results; - + } -function isPipe($str) +function isPipe($str) + { - return (strpos($str, '|') !== FALSE); + return (strpos($str, '|') !== FALSE); } ?> diff --git a/config.php b/config.php index ef81b69..f68953d 100644 --- a/config.php +++ b/config.php @@ -26,290 +26,143 @@ require_once('common.php'); $tpl->assign('help', basename( __FILE__, '.php')); -if(!isset($_SESSION[SESSION_LOGIN_USER])) { +if (!isset($_SESSION[SESSION_LOGIN_USER])) { header('Location: login.php'); exit(); } -if(isset($_POST['action'])) { +if (isset($_POST['action'])) { $action = $_POST['action']; } else { $action = FALSE; } -$errors = array(); +global $g_msg_nodef; +$g_msg_nodef = $message['errNoDefined']; + +global $g_msg_notfound; +$g_msg_notfound = $message['errFileNotFound']; + +global $g_post; +$g_post = $_POST; + +global $params; $params = array(); -/** +global $errors; +$errors = array(); + +/* * Read current parameter */ -if( defined('_PGPOOL2_LANG')) - $params['lang'] = _PGPOOL2_LANG; -else - $errors['lang'] = $message['errNoDefined']; - -if( defined('_PGPOOL2_CONFIG_FILE')) - $params['pgpool_config_file'] = _PGPOOL2_CONFIG_FILE; -else - $errors['pgpool_config_file'] = $message['errNoDefined']; - -if( defined('_PGPOOL2_PASSWORD_FILE')) - $params['password_file'] = _PGPOOL2_PASSWORD_FILE; -else - $errors['password_file'] = $message['errNoDefined']; - -if( defined('_PGPOOL2_COMMAND')) - $params['pgpool_command'] = _PGPOOL2_COMMAND; -else - $errors['pgpool_command'] = $message['errNoDefined']; - -if( defined('_PGPOOL2_CMD_OPTION_C')) - $params['c'] = _PGPOOL2_CMD_OPTION_C; -else - $errors['c'] = $message['errNoDefined']; - -if( defined('_PGPOOL2_CMD_OPTION_LARGE_D')) - $params['D'] = _PGPOOL2_CMD_OPTION_LARGE_D; -else - $errors['D'] = $message['errNoDefined']; - -if( defined('_PGPOOL2_CMD_OPTION_D')) - $params['d'] = _PGPOOL2_CMD_OPTION_D; -else - $errors['d'] = $message['errNoDefined']; - -if( defined('_PGPOOL2_CMD_OPTION_M')) - $params['m'] = _PGPOOL2_CMD_OPTION_M; -else - $errors['m'] = $message['errNoDefined']; - -if( defined('_PGPOOL2_CMD_OPTION_N')) - $params['n'] = _PGPOOL2_CMD_OPTION_N; -else - $errors['n'] = $message['errNoDefined']; - -if( defined('_PGPOOL2_LOG_FILE')) - $params['pgpool_logfile'] = _PGPOOL2_LOG_FILE; -else - $errors['pgpool_logfile'] = $message['errNoDefined']; - -if( defined('_PGPOOL2_PCP_DIR')) - $params['pcp_client_dir'] = _PGPOOL2_PCP_DIR; -else - $errors['pcp_client_dir'] = $message['errNoDefined']; - -if( defined('_PGPOOL2_PCP_HOSTNAME')) - $params['pcp_hostname'] = _PGPOOL2_PCP_HOSTNAME; -else - $errors['pcp_hostname'] = $message['errNoDefined']; - -if( defined('_PGPOOL2_STATUS_REFRESH_TIME')) - $params['pcp_refresh_time'] = _PGPOOL2_STATUS_REFRESH_TIME; -else - $errors['pcp_refresh_time'] = $message['errNoDefined']; - +$params['lang'] = (defined('_PGPOOL2_LANG')) ? + _PGPOOL2_LANG : $message['errNoDefined']; +$params['pgpool_config_file'] = (defined('_PGPOOL2_CONFIG_FILE')) ? + _PGPOOL2_CONFIG_FILE : $message['errNoDefined']; +$params['password_file'] = (defined('_PGPOOL2_PASSWORD_FILE')) ? + _PGPOOL2_PASSWORD_FILE : $message['errNoDefined']; +$params['pgpool_command'] = (defined('_PGPOOL2_COMMAND')) ? + _PGPOOL2_COMMAND : $message['errNoDefined']; +$params['c'] = (defined('_PGPOOL2_CMD_OPTION_C')) ? + _PGPOOL2_CMD_OPTION_C : $message['errNoDefined']; +$params['d'] = (defined('_PGPOOL2_CMD_OPTION_D')) ? + _PGPOOL2_CMD_OPTION_D : $message['errNoDefined']; +$params['D'] = (defined('_PGPOOL2_CMD_OPTION_LARGE_D')) ? + _PGPOOL2_CMD_OPTION_LARGE_D : $message['errNoDefined']; +$params['m'] = (defined('_PGPOOL2_CMD_OPTION_M')) ? + _PGPOOL2_CMD_OPTION_M : $message['errNoDefined']; +$params['n'] = (defined('_PGPOOL2_CMD_OPTION_N')) ? + _PGPOOL2_CMD_OPTION_N : $message['errNoDefined']; +$params['pgpool_logfile'] = (defined('_PGPOOL2_LOG_FILE')) ? + _PGPOOL2_LOG_FILE : $message['errNoDefined']; +$params['pcp_client_dir'] = (defined('_PGPOOL2_PCP_DIR')) ? + _PGPOOL2_PCP_DIR : $message['errNoDefined']; +$params['pcp_hostname'] = (defined('_PGPOOL2_PCP_HOSTNAME')) ? + _PGPOOL2_PCP_HOSTNAME : $message['errNoDefined']; +$params['pcp_refresh_time'] = (defined('_PGPOOL2_STATUS_REFRESH_TIME')) ? + _PGPOOL2_STATUS_REFRESH_TIME : $message['errNoDefined']; + switch ( $action ) { case 'update': - - $key = 'lang'; - if(isset($_POST[$key])) { - $params[$key] = $_POST[$key]; - } else { - $errors[$key] = $message['errNoDefined']; - } - - $key = 'pgpool_config_file'; - if(isset($_POST[$key])) { - $params[$key] = $_POST[$key]; - } else { - $errors[$key] = $message['errNoDefined']; - } - if(!@is_file($params[$key])) { - $errors[$key] = $message['errFileNotFound']; - } - - $key = 'password_file'; - if(isset($_POST[$key])) { - $params[$key] = $_POST[$key]; - } else { - $errors[$key] = $message['errNoDefined']; - } - if(!@is_file($params[$key])) { - $errors[$key] = $message['errFileNotFound']; - } - - $key = 'pgpool_command'; - if(isset($_POST[$key])) { - $params[$key] = $_POST[$key]; - } else { - $errors[$key] = $message['errNoDefined']; - } - if(!is_executable($params[$key])) { - $errors[$key] = $message['errFileNotFound']; - } - - $key = 'c'; - if(isset($_POST[$key])) { - $params[$key] = 1; - } else { - $params[$key] = 0; - } - - $key = 'D'; - if(isset($_POST[$key])) { - $params[$key] = 1; - } else { - $params[$key] = 0; - } - $key = 'd'; - if(isset($_POST[$key])) { - $params[$key] = 1; - } else { - $params[$key] = 0; - } - - $key = 'm'; - if(isset($_POST[$key])) { - $params[$key] = $_POST[$key]; - } else { - $errors[$key] = $message['errNoDefined']; - } - - $key = 'n'; - if(isset($_POST[$key])) { - $params[$key] = 1; - } else { - $params[$key] = 0; - } - - $key = 'pgpool_logfile'; - if(isset($_POST[$key])) { - $params[$key] = $_POST[$key]; - } else { - $errors[$key] = $message['errNoDefined']; - } - if($params[$key] != '' && isPipe($params[$key])) { - // pipe - $tmp_str = trim($params[$key]); - if(($tmp_str[0] != '|') || ($tmp_str[strlen($tmp_str) - 1] == '|')) { - $errors[$key] = $message['errIllegalPipe']; - } - } else if($params[$key] != '' && !is_writable(dirname($params[$key]))) { - // file - $errors[$key] = $message['errFileNotWritable']; - } + setValue('lang'); + setValue('pgpool_config_file'); + setValue('password_file'); - $key = 'pcp_client_dir'; - if(isset($_POST[$key])) { - $params[$key] = $_POST[$key]; - } else { - $errors[$key] = $message['errNoDefined']; - } - - $key = 'pcp_hostname'; - if(isset($_POST[$key])) { - $params[$key] = $_POST[$key]; - } else { - $errors[$key] = $message['errNoDefined']; + setValue('pgpool_command'); + if (!is_executable($params['pgpool_command'])) { + $errors['pgpool_command'] = $message['errFileNotFound']; } - if(!preg_match("/^[0-9a-zA-Z\._\-]+$/", $params[$key])) { - $errors[$key] = $message['errIllegalHostname']; + + setBool('c'); + setBool('D'); + setBool('d'); + setValue('m'); + setBool('n'); + + setValue('pgpool_logfile'); + // pipe + if ($params['pgpool_logfile'] != '' && isPipe($params['pgpool_logfile'])) { + $tmp_str = trim($params['pgpool_logfile']); + if ($tmp_str[0] != '|' || $tmp_str[strlen($tmp_str) - 1] == '|') { + $errors['pgpool_logfile'] = $message['errIllegalPipe']; + } + // file + } elseif ($params['pgpool_logfile'] != '' && !is_writable(dirname($params['pgpool_logfile']))) { + $errors['pgpool_logfile'] = $message['errFileNotWritable']; } - - $key = 'pcp_refresh_time'; - if(isset($_POST[$key])) { - $params[$key] = $_POST[$key]; - } else { - $errors[$key] = $message['errNoDefined']; + + setValue('pcp_client_dir'); + + setValue('pcp_hostname'); + if (!preg_match("/^[0-9a-zA-Z\._\-]+$/", $params['pcp_hostname'])) { + $errors[$key] = $message['errIllegalHostname']; } - if( !is_numeric($params[$key] )) { - $errors[$key] = $message['errShouldBeInteger']; + + setValue('pcp_refresh_time'); + if (!is_numeric($params['pcp_refresh_time'] )) { + $errors['pcp_refresh_time'] = $message['errShouldBeInteger']; } else { - if ( $params[$key] < 0) { - $errors[$key] = $message['errShouldBeZeroOrMore']; + if ($params['pcp_refresh_time'] < 0) { + $errors['pcp_refresh_time'] = $message['errShouldBeZeroOrMore']; } } - if( count($errors) == 0 ) { - + /* + * If no error, write conf/pgmgt.conf.php. + */ + if (count($errors) == 0 ) { $pgmgtConfigFile = dirname(__FILE__) . '/conf/pgmgt.conf.php'; - - if( ! is_writable($pgmgtConfigFile)) { + + if (!is_writable($pgmgtConfigFile)) { $errorCode = 'e5003'; $tpl->assign('errorCode', $errorCode); $tpl->display('error.tpl'); exit(); } - - $fp = fopen( $pgmgtConfigFile, "w"); - if($fp == false) { + + $result = writePgmtConf($pgmgtConfigFile); + if (!$result) { $errorCode = 'e5001'; $tpl->assign('errorCode', $errorCode); $tpl->display('error.tpl'); exit(); } - $str = "\n"; - fputs($fp, $str); - fclose($fp); - $tpl->assign('status', 'success'); } else { $tpl->assign('errors', $errors); } - - /** + + /* * reload message catalog */ $lang = selectLanguage($params['lang'], $messageList); include('lang/' . $lang . '.lang.php'); $tpl->assign('message', $message); break; - + default: } @@ -319,4 +172,105 @@ $tpl->assign('params', $params); $tpl->assign('errors', $errors); $tpl->display('config.tpl'); +/* --------------------------------------------------------------------- */ +/* Functions */ +/* --------------------------------------------------------------------- */ + +function setValue($key) +{ + global $g_post; + global $g_err_msg; + global $params; + + if (isset($g_post[$key])) { + $params[$key] = $g_post[$key]; + } else { + $params[$key] = $g_msg_nodef; + } + + if (strpos($key, 'file') !== FALSE) { + fileError($key); + } +} + +function setBool($key) +{ + global $g_post; + global $prams; + + if (isset($g_post[$key])) { + $params[$key] = 1; + } else { + $params[$key] = 0; + } +} + +function fileError($key) +{ + global $params; + global $errors; + global $g_msg_notfound; + + if (!@is_file($params[$key])) { + $errors[$key] = $g_msg_notfound; + } +} + +function writePgmtConf($pgmgtConfigFile) +{ + global $params; + + $fp = fopen($pgmgtConfigFile, "w"); + if ($fp == FALSE) { + return FALSE; + } + + $str = "\n"; + fputs($fp, $str); + + fclose($fp); + return TRUE; +} ?> diff --git a/definePgpoolConfParam.php b/definePgpoolConfParam.php index 0422b34..3fdfaa6 100644 --- a/definePgpoolConfParam.php +++ b/definePgpoolConfParam.php @@ -30,6 +30,12 @@ $strreg = '^[0-9a-zA-Z_\-]+$'; $dirreg = '^\/[0-9a-zA-Z\._\/\-]+$'; $hostreg = "^[0-9a-zA-Z\._\-]*$"; +#------------------------------------------------------------------------------ +# CONNECTIONS +#------------------------------------------------------------------------------ + +# - pgpool Connection Settings - + $key = 'listen_addresses'; $pgpoolConfigParam[$key]['type'] ='C'; $pgpoolConfigParam[$key]['default'] ='localhost'; @@ -46,11 +52,98 @@ $pgpoolConfigParam[$key]['type'] ='C'; $pgpoolConfigParam[$key]['default'] ='/tmp'; $pgpoolConfigParam[$key]['regexp'] = "$dirreg"; +# - pgpool Communication Manager Connection Settings - + +$key = 'pcp_port'; +$pgpoolConfigParam[$key]['type'] ='N'; +$pgpoolConfigParam[$key]['default'] =9898; +$pgpoolConfigParam[$key]['min'] = 1024; +$pgpoolConfigParam[$key]['max'] = 65535; + +$key = 'pcp_socket_dir'; +$pgpoolConfigParam[$key]['type'] ='C'; +$pgpoolConfigParam[$key]['default'] ='/tmp'; +$pgpoolConfigParam[$key]['regexp'] = "$dirreg"; + +# - Backend Connection Settings - + $key = 'backend_socket_dir'; $pgpoolConfigParam[$key]['type'] ='C'; $pgpoolConfigParam[$key]['default'] ='/tmp'; $pgpoolConfigParam[$key]['regexp'] = "$dirreg"; +$key = 'pcp_timeout'; +$pgpoolConfigParam[$key]['type'] ='N'; +$pgpoolConfigParam[$key]['default'] ='10'; +$pgpoolConfigParam[$key]['min'] = 0; +$pgpoolConfigParam[$key]['max'] = 65535; + +$key = 'backend_hostname'; +$pgpoolConfigBackendParam[$key]['type'] ='C'; +$pgpoolConfigBackendParam[$key]['default'] =''; +$pgpoolConfigBackendParam[$key]['regexp'] = "^[0-9a-zA-Z\._\-]*$"; + +$key = 'backend_port'; +$pgpoolConfigBackendParam[$key]['type'] ='N'; +$pgpoolConfigBackendParam[$key]['default'] ='5432'; +$pgpoolConfigBackendParam[$key]['min'] = 1024; +$pgpoolConfigBackendParam[$key]['max'] = 65535; + +$key = 'backend_weight'; +$pgpoolConfigBackendParam[$key]['type'] ='F'; +$pgpoolConfigBackendParam[$key]['default'] ='1'; +$pgpoolConfigBackendParam[$key]['min'] = 0.0; +$pgpoolConfigBackendParam[$key]['max'] = 100.0; + +$key = 'backend_data_directory'; +$pgpoolConfigBackendParam[$key]['type'] ='C'; +$pgpoolConfigBackendParam[$key]['default'] =''; +$pgpoolConfigBackendParam[$key]['regexp'] = ".*"; + +# - Authentication - + +$key = 'enable_pool_hba'; +$pgpoolConfigParam[$key]['type'] ='B'; +$pgpoolConfigParam[$key]['default'] =false; + +$key = 'authentication_timeout'; +$pgpoolConfigParam[$key]['type'] ='N'; +$pgpoolConfigParam[$key]['default'] ='60'; +$pgpoolConfigParam[$key]['min'] = 0; +$pgpoolConfigParam[$key]['max'] = 10000; + +# - SSL Connections - + +$key = 'ssl'; +$pgpoolConfigParam[$key]['type'] ='B'; +$pgpoolConfigParam[$key]['default'] = false; + +$key = 'ssl_key'; +$pgpoolConfigParam[$key]['type'] ='C'; +$pgpoolConfigParam[$key]['default'] =''; +$pgpoolConfigParam[$key]['regexp'] = "^(|\/[0-9a-zA-Z_\/\.\-]*)$"; + +$key = 'ssl_cert'; +$pgpoolConfigParam[$key]['type'] ='C'; +$pgpoolConfigParam[$key]['default'] =''; +$pgpoolConfigParam[$key]['regexp'] = "^(|\/[0-9a-zA-Z_\/\.\-]*)$"; + +$key = 'ssl_ca_cert'; +$pgpoolConfigParam[$key]['type'] ='C'; +$pgpoolConfigParam[$key]['default'] =''; +$pgpoolConfigParam[$key]['regexp'] = "^(|\/[0-9a-zA-Z_\/\.\-]*)$"; + +$key = 'ssl_ca_cert_dir'; +$pgpoolConfigParam[$key]['type'] ='C'; +$pgpoolConfigParam[$key]['default'] =''; +$pgpoolConfigParam[$key]['regexp'] = "^(|\/[0-9a-zA-Z_\/\.\-]*)$"; + +#------------------------------------------------------------------------------ +# POOLS +#------------------------------------------------------------------------------ + +# - Pool size - + $key = 'num_init_children'; $pgpoolConfigParam[$key]['type'] ='N'; $pgpoolConfigParam[$key]['default'] ='32'; @@ -63,19 +156,21 @@ $pgpoolConfigParam[$key]['default'] ='4'; $pgpoolConfigParam[$key]['min'] = 1; $pgpoolConfigParam[$key]['max'] = 65535; +# - Life time - + $key = 'child_life_time'; $pgpoolConfigParam[$key]['type'] ='N'; $pgpoolConfigParam[$key]['default'] ='300'; $pgpoolConfigParam[$key]['min'] = 0; $pgpoolConfigParam[$key]['max'] = 65535; -$key = 'connection_life_time'; +$key = 'child_max_connections'; $pgpoolConfigParam[$key]['type'] ='N'; $pgpoolConfigParam[$key]['default'] ='0'; $pgpoolConfigParam[$key]['min'] = 0; $pgpoolConfigParam[$key]['max'] = 65535; -$key = 'child_max_connections'; +$key = 'connection_life_time'; $pgpoolConfigParam[$key]['type'] ='N'; $pgpoolConfigParam[$key]['default'] ='0'; $pgpoolConfigParam[$key]['min'] = 0; @@ -87,54 +182,112 @@ $pgpoolConfigParam[$key]['default'] ='0'; $pgpoolConfigParam[$key]['min'] = 0; $pgpoolConfigParam[$key]['max'] = 65535; -$key = 'authentication_timeout'; -$pgpoolConfigParam[$key]['type'] ='N'; -$pgpoolConfigParam[$key]['default'] ='60'; -$pgpoolConfigParam[$key]['min'] = 0; -$pgpoolConfigParam[$key]['max'] = 10000; +#------------------------------------------------------------------------------ +# LOGS +#------------------------------------------------------------------------------ -$key = 'logdir'; +# - What to log - + +$key = 'print_timestamp'; +$pgpoolConfigParam[$key]['type'] ='B'; +$pgpoolConfigParam[$key]['default'] =true; + +$key = 'log_connections'; +$pgpoolConfigParam[$key]['type'] = 'B'; +$pgpoolConfigParam[$key]['default'] = false; + +$key = 'log_hostname'; +$pgpoolConfigParam[$key]['type'] = 'B'; +$pgpoolConfigParam[$key]['default'] = false; + +$key = 'log_statement'; +$pgpoolConfigParam[$key]['type'] ='B'; +$pgpoolConfigParam[$key]['default'] =false; + +$key = 'log_per_node_statement'; +$pgpoolConfigParam[$key]['type'] ='B'; +$pgpoolConfigParam[$key]['default'] =false; + +$key = 'log_standby_delay'; $pgpoolConfigParam[$key]['type'] ='C'; -$pgpoolConfigParam[$key]['default'] ='/tmp'; -$pgpoolConfigParam[$key]['regexp'] = "$dirreg"; +$pgpoolConfigParam[$key]['default'] ='none'; +$pgpoolConfigParam[$key]['regexp'] = "^[always|if_over_threshold|none]+$"; + +#------------------------------------------------------------------------------ +# FILE LOCATIONS +#------------------------------------------------------------------------------ $key = 'pid_file_name'; $pgpoolConfigParam[$key]['type'] ='C'; $pgpoolConfigParam[$key]['default'] ='/var/run/pgpool/pgpool.pid'; $pgpoolConfigParam[$key]['regexp'] = "$dirreg"; -$key = 'pcp_timeout'; -$pgpoolConfigParam[$key]['type'] ='N'; -$pgpoolConfigParam[$key]['default'] ='10'; -$pgpoolConfigParam[$key]['min'] = 0; -$pgpoolConfigParam[$key]['max'] = 65535; +$key = 'logdir'; +$pgpoolConfigParam[$key]['type'] ='C'; +$pgpoolConfigParam[$key]['default'] ='/tmp'; +$pgpoolConfigParam[$key]['regexp'] = "$dirreg"; + +#------------------------------------------------------------------------------ +# CONNECTION POOLING +#------------------------------------------------------------------------------ + +$key = 'connection_cache'; +$pgpoolConfigParam[$key]['type'] ='B'; +$pgpoolConfigParam[$key]['default'] =true; + +$key = 'reset_query_list'; +$pgpoolConfigParam[$key]['type'] ='C'; +$pgpoolConfigParam[$key]['default'] ='ABORT; DISCARD ALL'; +$pgpoolConfigParam[$key]['regexp'] = "^[0-9a-zA-Z; ]+$"; + +#------------------------------------------------------------------------------ +# REPLICATION MODE +#------------------------------------------------------------------------------ $key = 'replication_mode'; $pgpoolConfigParam[$key]['type'] ='B'; $pgpoolConfigParam[$key]['default'] =false; +$key = 'replicate_select'; +$pgpoolConfigParam[$key]['type'] ='B'; +$pgpoolConfigParam[$key]['default'] =false; + $key = 'replication_timeout'; $pgpoolConfigParam[$key]['type'] ='N'; $pgpoolConfigParam[$key]['default'] =5000; $pgpoolConfigParam[$key]['min'] = 0; $pgpoolConfigParam[$key]['max'] = 65535; -$key = 'load_balance_mode'; +$key = 'insert_lock'; $pgpoolConfigParam[$key]['type'] ='B'; $pgpoolConfigParam[$key]['default'] =false; +$key = 'lobj_lock_table'; +$pgpoolConfigParam[$key]['type'] ='C'; +$pgpoolConfigParam[$key]['default'] =''; +$pgpoolConfigParam[$key]['regexp'] = ".*"; + +# - Degenerate handling - + $key = 'replication_stop_on_mismatch'; $pgpoolConfigParam[$key]['type'] ='B'; $pgpoolConfigParam[$key]['default'] =false; -$key = 'replicate_select'; +$key = 'failover_if_affected_tuples_mismatch'; $pgpoolConfigParam[$key]['type'] ='B'; $pgpoolConfigParam[$key]['default'] =false; -$key = 'reset_query_list'; -$pgpoolConfigParam[$key]['type'] ='C'; -$pgpoolConfigParam[$key]['default'] ='ABORT; DISCARD ALL'; -$pgpoolConfigParam[$key]['regexp'] = "^[0-9a-zA-Z; ]+$"; +#------------------------------------------------------------------------------ +# LOAD BALANCING MODE +#------------------------------------------------------------------------------ + +$key = 'load_balance_mode'; +$pgpoolConfigParam[$key]['type'] ='B'; +$pgpoolConfigParam[$key]['default'] =false; + +$key = 'ignore_leading_white_space'; +$pgpoolConfigParam[$key]['type'] ='B'; +$pgpoolConfigParam[$key]['default'] =true; $key = 'white_function_list'; $pgpoolConfigParam[$key]['type'] ='C'; @@ -146,9 +299,9 @@ $pgpoolConfigParam[$key]['type'] ='C'; $pgpoolConfigParam[$key]['default'] =''; $pgpoolConfigParam[$key]['regexp'] = "^[0-9a-zA-Z_,]*$"; -$key = 'print_timestamp'; -$pgpoolConfigParam[$key]['type'] ='B'; -$pgpoolConfigParam[$key]['default'] =true; +#------------------------------------------------------------------------------ +# MASTER/SLAVE MODE +#------------------------------------------------------------------------------ $key = 'master_slave_mode'; $pgpoolConfigParam[$key]['type'] ='B'; @@ -159,69 +312,32 @@ $pgpoolConfigParam[$key]['type'] ='C'; $pgpoolConfigParam[$key]['default'] ='slony'; $pgpoolConfigParam[$key]['regexp'] = "^[slony|stream]+$"; +# - Streaming - + $key = 'delay_threshold'; $pgpoolConfigParam[$key]['type'] ='N'; $pgpoolConfigParam[$key]['default'] = 0; $pgpoolConfigParam[$key]['min'] = 0; $pgpoolConfigParam[$key]['max'] = 65535; -$key = 'log_standby_delay'; -$pgpoolConfigParam[$key]['type'] ='C'; -$pgpoolConfigParam[$key]['default'] ='none'; -$pgpoolConfigParam[$key]['regexp'] = "^[always|if_over_threshold|none]+$"; - -$key = 'connection_cache'; -$pgpoolConfigParam[$key]['type'] ='B'; -$pgpoolConfigParam[$key]['default'] =true; - -$key = 'health_check_timeout'; -$pgpoolConfigParam[$key]['type'] ='N'; -$pgpoolConfigParam[$key]['default'] =20; -$pgpoolConfigParam[$key]['min'] = 0; -$pgpoolConfigParam[$key]['max'] = 65535; - -$key = 'health_check_period'; -$pgpoolConfigParam[$key]['type'] ='N'; -$pgpoolConfigParam[$key]['default'] =0; -$pgpoolConfigParam[$key]['min'] = 0; -$pgpoolConfigParam[$key]['max'] = 65535; - -$key = 'health_check_user'; -$pgpoolConfigParam[$key]['type'] ='C'; -$pgpoolConfigParam[$key]['default'] ='nodoby'; -$pgpoolConfigParam[$key]['regexp'] = "^[0-9a-zA-Z_\.\-]+$"; - -$key = 'insert_lock'; -$pgpoolConfigParam[$key]['type'] ='B'; -$pgpoolConfigParam[$key]['default'] =false; - -$key = 'ignore_leading_white_space'; -$pgpoolConfigParam[$key]['type'] ='B'; -$pgpoolConfigParam[$key]['default'] =true; +#------------------------------------------------------------------------------ +# PARALLEL MODE AND QUERY CACHE +#------------------------------------------------------------------------------ $key = 'parallel_mode'; $pgpoolConfigParam[$key]['type'] ='B'; $pgpoolConfigParam[$key]['default'] =false; -$key = 'log_connections'; -$pgpoolConfigParam[$key]['type'] = 'B'; -$pgpoolConfigParam[$key]['default'] = false; - -$key = 'log_hostname'; -$pgpoolConfigParam[$key]['type'] = 'B'; -$pgpoolConfigParam[$key]['default'] = false; - -$key = 'log_statement'; -$pgpoolConfigParam[$key]['type'] ='B'; -$pgpoolConfigParam[$key]['default'] =false; - $key = 'enable_query_cache'; $pgpoolConfigParam[$key]['type'] ='B'; $pgpoolConfigParam[$key]['default'] =false; -$key = 'enable_pool_hba'; -$pgpoolConfigParam[$key]['type'] ='B'; -$pgpoolConfigParam[$key]['default'] =false; +$key = 'pgpool2_hostname'; +$pgpoolConfigParam[$key]['type'] ='C'; +$pgpoolConfigParam[$key]['default'] = 'localhost'; +$pgpoolConfigParam[$key]['regexp'] = $hostreg; + +# - System DB info - $key = 'system_db_hostname'; $pgpoolConfigParam[$key]['type'] ='C'; @@ -254,43 +370,48 @@ $pgpoolConfigParam[$key]['type'] ='C'; $pgpoolConfigParam[$key]['default'] =''; $pgpoolConfigParam[$key]['regexp'] = ".*"; -$key = 'pcp_port'; +#------------------------------------------------------------------------------ +# HEALTH CHECK +#------------------------------------------------------------------------------ + +$key = 'health_check_period'; $pgpoolConfigParam[$key]['type'] ='N'; -$pgpoolConfigParam[$key]['default'] =9898; -$pgpoolConfigParam[$key]['min'] = 1024; +$pgpoolConfigParam[$key]['default'] =0; +$pgpoolConfigParam[$key]['min'] = 0; $pgpoolConfigParam[$key]['max'] = 65535; -$key = 'pcp_socket_dir'; -$pgpoolConfigParam[$key]['type'] ='C'; -$pgpoolConfigParam[$key]['default'] ='/tmp'; -$pgpoolConfigParam[$key]['regexp'] = "$dirreg"; +$key = 'health_check_timeout'; +$pgpoolConfigParam[$key]['type'] ='N'; +$pgpoolConfigParam[$key]['default'] =20; +$pgpoolConfigParam[$key]['min'] = 0; +$pgpoolConfigParam[$key]['max'] = 65535; -$key = 'pgpool2_hostname'; +$key = 'health_check_user'; $pgpoolConfigParam[$key]['type'] ='C'; -$pgpoolConfigParam[$key]['default'] = 'localhost'; -$pgpoolConfigParam[$key]['regexp'] = $hostreg; +$pgpoolConfigParam[$key]['default'] ='nodoby'; +$pgpoolConfigParam[$key]['regexp'] = "^[0-9a-zA-Z_\.\-]+$"; -$key = 'backend_hostname'; -$pgpoolConfigBackendParam[$key]['type'] ='C'; -$pgpoolConfigBackendParam[$key]['default'] =''; -$pgpoolConfigBackendParam[$key]['regexp'] = "^[0-9a-zA-Z\._\-]*$"; +#------------------------------------------------------------------------------ +# FAILOVER AND FAILBACK +#----------------------------------------------------------------------------- -$key = 'backend_port'; -$pgpoolConfigBackendParam[$key]['type'] ='N'; -$pgpoolConfigBackendParam[$key]['default'] ='5432'; -$pgpoolConfigBackendParam[$key]['min'] = 1024; -$pgpoolConfigBackendParam[$key]['max'] = 65535; +$key = 'failover_command'; +$pgpoolConfigParam[$key]['type'] ='C'; +$pgpoolConfigParam[$key]['default'] =''; +$pgpoolConfigParam[$key]['regexp'] = ".*"; -$key = 'backend_data_directory'; -$pgpoolConfigBackendParam[$key]['type'] ='C'; -$pgpoolConfigBackendParam[$key]['default'] =''; -$pgpoolConfigBackendParam[$key]['regexp'] = ".*"; +$key = 'failback_command'; +$pgpoolConfigParam[$key]['type'] ='C'; +$pgpoolConfigParam[$key]['default'] =''; +$pgpoolConfigParam[$key]['regexp'] = ".*"; -$key = 'backend_weight'; -$pgpoolConfigBackendParam[$key]['type'] ='F'; -$pgpoolConfigBackendParam[$key]['default'] ='1'; -$pgpoolConfigBackendParam[$key]['min'] = 0.0; -$pgpoolConfigBackendParam[$key]['max'] = 100.0; +$key = 'fail_over_on_backend_error'; +$pgpoolConfigParam[$key]['type'] ='B'; +$pgpoolConfigParam[$key]['default'] =true; + +#------------------------------------------------------------------------------ +# ONLINE RECOVERY +#------------------------------------------------------------------------------ $key = 'recovery_user'; $pgpoolConfigParam[$key]['type'] ='C'; @@ -318,60 +439,10 @@ $pgpoolConfigParam[$key]['default'] = 90; $pgpoolConfigParam[$key]['min'] = 0; $pgpoolConfigParam[$key]['max'] = 65535; -$key = 'failover_command'; -$pgpoolConfigParam[$key]['type'] ='C'; -$pgpoolConfigParam[$key]['default'] =''; -$pgpoolConfigParam[$key]['regexp'] = ".*"; - -$key = 'failback_command'; -$pgpoolConfigParam[$key]['type'] ='C'; -$pgpoolConfigParam[$key]['default'] =''; -$pgpoolConfigParam[$key]['regexp'] = ".*"; - $key = 'client_idle_limit_in_recovery'; $pgpoolConfigParam[$key]['type'] ='N'; $pgpoolConfigParam[$key]['default'] ='0'; $pgpoolConfigParam[$key]['min'] = -1; $pgpoolConfigParam[$key]['max'] = 65535; -$key = 'fail_over_on_backend_error'; -$pgpoolConfigParam[$key]['type'] ='B'; -$pgpoolConfigParam[$key]['default'] =true; - -$key = 'failover_if_affected_tuples_mismatch'; -$pgpoolConfigParam[$key]['type'] ='B'; -$pgpoolConfigParam[$key]['default'] =false; - -$key = 'log_per_node_statement'; -$pgpoolConfigParam[$key]['type'] ='B'; -$pgpoolConfigParam[$key]['default'] =false; - -$key = 'lobj_lock_table'; -$pgpoolConfigParam[$key]['type'] ='C'; -$pgpoolConfigParam[$key]['default'] =''; -$pgpoolConfigParam[$key]['regexp'] = ".*"; - -$key = 'ssl'; -$pgpoolConfigParam[$key]['type'] ='B'; -$pgpoolConfigParam[$key]['default'] = false; - -$key = 'ssl_key'; -$pgpoolConfigParam[$key]['type'] ='C'; -$pgpoolConfigParam[$key]['default'] =''; -$pgpoolConfigParam[$key]['regexp'] = "^(|\/[0-9a-zA-Z_\/\.\-]*)$"; - -$key = 'ssl_cert'; -$pgpoolConfigParam[$key]['type'] ='C'; -$pgpoolConfigParam[$key]['default'] =''; -$pgpoolConfigParam[$key]['regexp'] = "^(|\/[0-9a-zA-Z_\/\.\-]*)$"; - -$key = 'ssl_ca_cert'; -$pgpoolConfigParam[$key]['type'] ='C'; -$pgpoolConfigParam[$key]['default'] =''; -$pgpoolConfigParam[$key]['regexp'] = "^(|\/[0-9a-zA-Z_\/\.\-]*)$"; - -$key = 'ssl_ca_cert_dir'; -$pgpoolConfigParam[$key]['type'] ='C'; -$pgpoolConfigParam[$key]['default'] =''; -$pgpoolConfigParam[$key]['regexp'] = "^(|\/[0-9a-zA-Z_\/\.\-]*)$"; ?> diff --git a/index.php b/index.php index 869f918..fe6eb22 100644 --- a/index.php +++ b/index.php @@ -26,7 +26,7 @@ require_once('common.php'); $tpl->assign('help', basename( __FILE__, '.php')); -if(!isset($_SESSION[SESSION_LOGIN_USER])) { +if (!isset($_SESSION[SESSION_LOGIN_USER])) { header('Location: login.php'); exit(); } else { diff --git a/innerLog.php b/innerLog.php index b86e41b..63d3002 100644 --- a/innerLog.php +++ b/innerLog.php @@ -25,18 +25,18 @@ require_once('common.php'); -if(!isset($_SESSION[SESSION_LOGIN_USER])) { +if (!isset($_SESSION[SESSION_LOGIN_USER])) { exit(); } $pgpoolLog = _PGPOOL2_LOG_FILE; -if($pgpoolLog == '') { +if ($pgpoolLog == '') { $logDir = readLogDir(); $pgpoolLog = "$logDir/pgpool.log"; } $logFile = @file($pgpoolLog); -if($logFile == false) { +if ($logFile == false) { $errorCode = 'e8001'; $tpl->assign('errorCode', $errorCode); $tpl->display('innerError.tpl'); @@ -44,7 +44,7 @@ if($logFile == false) { } $logSplitFile = array(); -for($i=0; $i $hostname) { $result[$num]['hostname'] = $backendHostName[$num]; - $result[$num]['port'] = $backendPort[$num]; - - if(NodeActive($num)) { + $result[$num]['port'] = $backendPort[$num]; + + if (NodeActive($num)) { $result[$num]['status'] = TRUE; } else { $result[$num]['status'] = FALSE; diff --git a/innerSummary.php b/innerSummary.php index e22bcf5..41ac49d 100644 --- a/innerSummary.php +++ b/innerSummary.php @@ -25,17 +25,17 @@ require_once('common.php'); -if(!isset($_SESSION[SESSION_LOGIN_USER])) { +if (!isset($_SESSION[SESSION_LOGIN_USER])) { exit(); } $params = readConfigParams(array('parallel_mode', - 'master_slave_mode', - 'master_slave_sub_mode', - 'enable_query_cache', - 'replication_mode', - 'load_balance_mode', - 'health_check_period')); + 'master_slave_mode', + 'master_slave_sub_mode', + 'enable_query_cache', + 'replication_mode', + 'load_balance_mode', + 'health_check_period')); $tpl->assign('params', $params); $tpl->display('innerSummary.tpl'); diff --git a/innerSystemCatalog.php b/innerSystemCatalog.php index 1cbeee1..a8736f1 100644 --- a/innerSystemCatalog.php +++ b/innerSystemCatalog.php @@ -25,43 +25,46 @@ require_once('common.php'); -if(!isset($_SESSION[SESSION_LOGIN_USER])) { +if (!isset($_SESSION[SESSION_LOGIN_USER])) { exit(); } $pgCatalog = pg_escape_string($_GET['catalog']); $nodeNum = $_GET['num']; -if($pgCatalog == '') { +if ($pgCatalog == '') { return; } -$params =readHealthCheckParam(); +// Set Parameters +$params = readHealthCheckParam(); $dbParams['hostname'] = $params['backend_hostname'][$nodeNum]; -$dbParams['port'] = $params['backend_port'][$nodeNum]; -$dbParams['dbname'] = 'template1'; -$dbParams['user'] = $params['health_check_user']; -$dbParams['password'] =''; +$dbParams['port'] = $params['backend_port'][$nodeNum]; +$dbParams['dbname'] = 'template1'; +$dbParams['user'] = $params['health_check_user']; +$dbParams['password'] =''; $tpl->assign('hostname', $dbParams['hostname'] ); -$tpl->assign('port', $dbParams['port'] ); +$tpl->assign('port', $dbParams['port'] ); +// Get Data From Database $conn = openDBConnection($dbParams); -$sql = 'show pool_status'; +$sql = 'SHOW pool_status'; $rs = execQuery($conn, $sql); -if(!pg_result_status($rs) == PGSQL_TUPLES_OK) { +if (!pg_result_status($rs) == PGSQL_TUPLES_OK) { $sql = "SELECT * FROM $pgCatalog"; $rs = execQuery($conn, $sql); $tpl->assign('catalog', $pgCatalog); + } else { $tpl->assign('catalog', 'pool_status'); } -if(!pg_result_status($rs) == PGSQL_TUPLES_OK) { +if (!pg_result_status($rs) == PGSQL_TUPLES_OK) { $errorCode = 'e8001'; $tpl->assign('errorCode', $errorCode); $tpl->display('innerError.tpl'); @@ -72,6 +75,7 @@ $results = pg_fetch_all($rs); closeDBConnection($conn); +// Show $tpl->assign('results', $results); $tpl->display('innerSystemCatalog.tpl'); diff --git a/login.php b/login.php index cd5380c..becabd6 100644 --- a/login.php +++ b/login.php @@ -26,65 +26,69 @@ require_once('common.php'); require_once('command.php'); -$success = false; +$success = FALSE; -if(isset($_SESSION[SESSION_LOGIN_USER])) { - $success = true; +if (isset($_SESSION[SESSION_LOGIN_USER])) { + $success = TRUE; } -if($success == false) { - if(isset($_POST['username'])) { +// Do login +if ($success == FALSE) { + if (isset($_POST['username'])) { $username = $_POST['username']; } else { $tpl->display('login.tpl'); exit(); } - - if(isset($_POST['password'])) { + + if (isset($_POST['password'])) { $password = $_POST['password']; } - + $md5password = md5($password); - - if( !file_exists(_PGPOOL2_PASSWORD_FILE)) { + + if (!file_exists(_PGPOOL2_PASSWORD_FILE)) { $errorCode = 'e7001'; $tpl->assign('errorCode', $errorCode); $tpl->display('error.tpl'); exit(); } - + + // Check each rows in pcp.conf to search $fp = fopen(_PGPOOL2_PASSWORD_FILE, 'r'); - $regexp = '^' . $username.":".$md5password; - - if($fp != null) { - while( !feof($fp) ) { + $regexp = "^{$username}:{$md5password}"; + + if ($fp != NULL) { + while (!feof($fp) ) { $line = fgets($fp); - if( preg_match("/$regexp/", $line) ) { - $_SESSION[SESSION_LOGIN_USER] = $username; + if (preg_match("/$regexp/", $line) ) { + $_SESSION[SESSION_LOGIN_USER] = $username; $_SESSION[SESSION_LOGIN_USER_PASSWORD] = $password; - $success = true; + $success = TRUE; } } } fclose($fp); -} -if(!$success) { - $tpl->display('login.tpl'); - exit(); + // If login falied, show login page again. + if (!$success) { + $tpl->display('login.tpl'); + exit(); + } } +// If user has already logined, show nodeStatus page. $tpl->assign('isLogin', TRUE); $tpl->assign('viewPHP', 'nodeStatus.php'); $refreshTime = 5000; -if( _PGPOOL2_STATUS_REFRESH_TIME >= 0 ) { +if (_PGPOOL2_STATUS_REFRESH_TIME >= 0 ) { $refreshTime = _PGPOOL2_STATUS_REFRESH_TIME * 1000; } -if(DoesPgpoolPidExist()) { - $tpl->assign('pgpoolIsActive', true); +if (DoesPgpoolPidExist()) { + $tpl->assign('pgpoolIsActive', TRUE); } else { - $tpl->assign('pgpoolIsActive', false); + $tpl->assign('pgpoolIsActive', FALSE); } $tpl->assign('c', _PGPOOL2_CMD_OPTION_C); @@ -93,9 +97,9 @@ $tpl->assign('d', _PGPOOL2_CMD_OPTION_D); $tpl->assign('m', _PGPOOL2_CMD_OPTION_M); $tpl->assign('n', _PGPOOL2_CMD_OPTION_N); -$tpl->assign('pgpoolConf', _PGPOOL2_CONFIG_FILE); -$tpl->assign('pcpConf', _PGPOOL2_PASSWORD_FILE); -$tpl->assign('refreshTime', $refreshTime); +$tpl->assign('pgpoolConf', _PGPOOL2_CONFIG_FILE); +$tpl->assign('pcpConf', _PGPOOL2_PASSWORD_FILE); +$tpl->assign('refreshTime', $refreshTime); $tpl->assign('msgStopPgpool', $message['msgStopPgpool']); $tpl->assign('help', 'status'); $tpl->display('status.tpl'); diff --git a/nodeServerStatus.php b/nodeServerStatus.php index 18c6d7f..b370245 100644 --- a/nodeServerStatus.php +++ b/nodeServerStatus.php @@ -26,7 +26,7 @@ require_once('common.php'); $tpl->assign('help', basename( __FILE__, '.php')); -if(!isset($_SESSION[SESSION_LOGIN_USER])) { +if (!isset($_SESSION[SESSION_LOGIN_USER])) { header('Location: login.php'); exit(); } diff --git a/nodeStatus.php b/nodeStatus.php index 88c487e..eb042d3 100644 --- a/nodeStatus.php +++ b/nodeStatus.php @@ -27,14 +27,14 @@ require_once('common.php'); require_once('command.php'); $tpl->assign('help', basename( __FILE__, '.php')); -$MAX_VALUE = 2147483647; +$MAX_VALUE = PHP_INT_MAX; -if(!isset($_SESSION[SESSION_LOGIN_USER])) { +if (!isset($_SESSION[SESSION_LOGIN_USER])) { exit(); } $ret = execPcp('PCP_NODE_COUNT'); -if(!array_key_exists('SUCCESS', $ret)) { +if (!array_key_exists('SUCCESS', $ret)) { $errorCode = 'e1002'; $tpl->assign('errorCode', $errorCode); $tpl->display('innerError.tpl'); @@ -45,68 +45,76 @@ if(!array_key_exists('SUCCESS', $ret)) { $tpl->assign('nodeCount', $nodeCount); -$isParallelMode = isParallelMode(); +$isParallelMode = isParallelMode(); $isReplicationMode = isReplicationMode(); $isMasterSlaveMode = isMasterSlaveMode(); $nodeInfo = array(); -$node_alive = false; +$node_alive = FALSE; -for($i=0; $i<$nodeCount; $i++) { +for ($i = 0; $i<$nodeCount; $i++) { $ret = execPcp('PCP_NODE_INFO', $i); - if(!array_key_exists('SUCCESS', $ret)) { + if (!array_key_exists('SUCCESS', $ret)) { $errorCode = 'e1003'; $tpl->assign('errorCode', $errorCode); $tpl->display('innerError.tpl'); exit(); + } else { $ret = $ret['SUCCESS']; } + $nodeInfo[$i] = explode(" ", $ret); $nodeInfo[$i][3] = sprintf('%.3f', $nodeInfo[$i][3]); - /* node is active? */ - if ($nodeInfo[$i][2] != 3) - $node_alive = true; + + /* node is active? */ + if ($nodeInfo[$i][2] != 3) { + $node_alive = TRUE; + } } for ($i = 0; $i < $nodeCount; $i++) { - if ($node_alive == false) { - if (($isReplicationMode || $isMasterSlaveMode) && - NodeActive($i)) - array_push($nodeInfo[$i], 'return'); - else - array_push($nodeInfo[$i], 'none'); - } else if( $isParallelMode ) { + if ($node_alive == FALSE) { + if (($isReplicationMode || $isMasterSlaveMode) && NodeActive($i)) { + array_push($nodeInfo[$i], 'return'); + } else { + array_push($nodeInfo[$i], 'none'); + } + + } elseif( $isParallelMode ) { array_push($nodeInfo[$i], 'none'); + } else { switch($nodeInfo[$i][2]) { - case 1: - case 2: - if($isReplicationMode || $isMasterSlaveMode) { - array_push($nodeInfo[$i], 'disconnect'); - } else { - array_push($nodeInfo[$i], 'none'); - } - break; - case 3: - if($isReplicationMode || $isMasterSlaveMode) { - if(NodeActive($i)) { - array_push($nodeInfo[$i], 'return'); - } else { - array_push($nodeInfo[$i], 'recovery'); + case 1: + case 2: + if ($isReplicationMode || $isMasterSlaveMode) { + array_push($nodeInfo[$i], 'disconnect'); + } else { + array_push($nodeInfo[$i], 'none'); } - } else { - array_push($nodeInfo[$i], 'none'); - } - break; + break; + + case 3: + if ($isReplicationMode || $isMasterSlaveMode) { + if (NodeActive($i)) { + array_push($nodeInfo[$i], 'return'); + } else { + array_push($nodeInfo[$i], 'recovery'); + } + } else { + array_push($nodeInfo[$i], 'none'); + } + break; } } - $nodeInfo[$i][5] = NodeStandby($i); + + $nodeInfo[$i][5] = NodeStandby($i); } -$tpl->assign('refreshTime', _PGPOOL2_STATUS_REFRESH_TIME*1000); -$tpl->assign('nodeInfo', $nodeInfo); -$tpl->assign('parallelMode', $isParallelMode); +$tpl->assign('refreshTime', _PGPOOL2_STATUS_REFRESH_TIME*1000); +$tpl->assign('nodeInfo', $nodeInfo); +$tpl->assign('parallelMode', $isParallelMode); $tpl->assign('msgStopPgpool', $message['msgStopPgpool']); $tpl->display('nodeStatus.tpl'); diff --git a/pgconfig.php b/pgconfig.php index dd886ee..13a8caf 100644 --- a/pgconfig.php +++ b/pgconfig.php @@ -28,7 +28,7 @@ require('definePgpoolConfParam.php'); $tpl->assign('help', basename( __FILE__, '.php')); -if(!isset($_SESSION[SESSION_LOGIN_USER])) { +if (!isset($_SESSION[SESSION_LOGIN_USER])) { header('Location: login.php'); exit(); } @@ -36,106 +36,122 @@ if(!isset($_SESSION[SESSION_LOGIN_USER])) { $configParam = array(); $error = array(); -if(isset($_POST['action'])) { +if (isset($_POST['action'])) { $action = $_POST['action']; } else { $action = FALSE; } -if($action == 'add') { - foreach($pgpoolConfigParam as $key => $value) { - if($pgpoolConfigParam[$key]['type'] == 'B') { - if(isset($_POST[$key])) { - $configValue[$key] = 'true'; +/* --------------------------------------------------------------------- */ +/* Add or Cancel */ +/* --------------------------------------------------------------------- */ + +switch ($action) { + case 'add': + + foreach ($pgpoolConfigParam as $key => $value) { + if ($pgpoolConfigParam[$key]['type'] == 'B') { + if (isset($_POST[$key])) { + $configValue[$key] = 'true'; + } else { + $configValue[$key] = 'false'; + } } else { - $configValue[$key] = 'false'; + $configValue[$key] = trim($_POST[$key]); } + } + + if (isset($_POST['backend_hostname'])) { + $configValue['backend_hostname'] = $_POST['backend_hostname']; } else { - $configValue[$key] = trim($_POST[$key]); + $configValue['backend_hostname'] = array(); + + } + if (isset($_POST['backend_port'])) { + $configValue['backend_port'] = $_POST['backend_port']; + } else { + $configValue['backend_port'] = array(); + } + + if (isset($_POST['backend_weight'])) { + $configValue['backend_weight'] = $_POST['backend_weight']; + } else { + $configValue['backend_weight'] = array(); } - } - if(isset($_POST['backend_hostname'])) { - $configValue['backend_hostname'] = $_POST['backend_hostname']; - } else { - $configValue['backend_hostname'] = array(); - } - if(isset($_POST['backend_port'])) { - $configValue['backend_port'] = $_POST['backend_port']; - } else { - $configValue['backend_port'] = array(); - } - if(isset($_POST['backend_weight'])) { - $configValue['backend_weight'] = $_POST['backend_weight']; - } else { - $configValue['backend_weight'] = array(); - } - if(isset($_POST['backend_data_directory'])) { - $configValue['backend_data_directory'] = $_POST['backend_data_directory']; - } else { - $configValue['backend_data_directory'] = array(); - } - $tpl->assign('params', $configValue); - $tpl->assign('isAdd', true); - $tpl->display('pgconfig.tpl'); - return; -} else if( $action == 'cancel') { - foreach($pgpoolConfigParam as $key => $value) { - if($pgpoolConfigParam[$key]['type'] == 'B') { - if(isset($_POST[$key])) { - $configValue[$key] = 'true'; + if (isset($_POST['backend_data_directory'])) { + $configValue['backend_data_directory'] = $_POST['backend_data_directory']; + } else { + $configValue['backend_data_directory'] = array(); + } + + $tpl->assign('params', $configValue); + $tpl->assign('isAdd', TRUE); + $tpl->display('pgconfig.tpl'); + + return; + + case 'cancel': + + foreach ($pgpoolConfigParam as $key => $value) { + if ($pgpoolConfigParam[$key]['type'] == 'B') { + if (isset($_POST[$key])) { + $configValue[$key] = 'true'; + } else { + $configValue[$key] = 'false'; + } } else { - $configValue[$key] = 'false'; + $configValue[$key] = trim($_POST[$key]); } - } else { - $configValue[$key] = trim($_POST[$key]); } - } - if(isset($_POST['backend_hostname'])) { - $configValue['backend_hostname'] = $_POST['backend_hostname']; - } - if(isset($_POST['backend_port'])) { - $configValue['backend_port'] = $_POST['backend_port']; - } - if(isset($_POST['backend_weight'])) { - $configValue['backend_weight'] = $_POST['backend_weight']; - } - if(isset($_POST['backend_data_directory'])) { - $configValue['backend_data_directory'] = $_POST['backend_data_directory']; - } + if (isset($_POST['backend_hostname'])) { + $configValue['backend_hostname'] = $_POST['backend_hostname']; + } + if (isset($_POST['backend_port'])) { + $configValue['backend_port'] = $_POST['backend_port']; + } + if (isset($_POST['backend_weight'])) { + $configValue['backend_weight'] = $_POST['backend_weight']; + } + if (isset($_POST['backend_data_directory'])) { + $configValue['backend_data_directory'] = $_POST['backend_data_directory']; + } + + array_pop($configValue['backend_hostname']); + array_pop($configValue['backend_port']); + array_pop($configValue['backend_weight']); + array_pop($configValue['backend_data_directory']); + $tpl->assign('params', $configValue); + $tpl->assign('isAdd', FALSE); + $tpl->display('pgconfig.tpl'); - array_pop($configValue['backend_hostname']); - array_pop($configValue['backend_port']); - array_pop($configValue['backend_weight']); - array_pop($configValue['backend_data_directory']); - $tpl->assign('params', $configValue); - $tpl->assign('isAdd', false); - $tpl->display('pgconfig.tpl'); - return; + return; } -$configValue = readConfigParams(); +/* --------------------------------------------------------------------- */ +/* Update or Delete */ +/* --------------------------------------------------------------------- */ /** * check $configFile */ - -foreach($pgpoolConfigParam as $key => $value) { - if( ! isset($configValue[$key]) ) { +$configValue = readConfigParams(); +foreach ($pgpoolConfigParam as $key => $value) { + if (!isset($configValue[$key]) ) { $configValue[$key] = $value['default']; } } -switch( $action ) { +switch ($action) { case 'update': - + /** * copy from POST data to $configValue except backend value */ - foreach($pgpoolConfigParam as $key => $value) { - if($pgpoolConfigParam[$key]['type'] == 'B') { - if(isset($_POST[$key])) { + foreach ($pgpoolConfigParam as $key => $value) { + if ($pgpoolConfigParam[$key]['type'] == 'B') { + if (isset($_POST[$key])) { $configValue[$key] = 'true'; } else { $configValue[$key] = 'false'; @@ -144,92 +160,99 @@ switch( $action ) { $configValue[$key] = trim($_POST[$key]); } } - + /** * Confirmations of value except backend host */ - foreach($pgpoolConfigParam as $key => $value) { + foreach( $pgpoolConfigParam as $key => $value) { check($key, $value, $configValue, $error); } - + /** - * copy backend value from POST data to $configValue + * copy backend value from POST data to $configValue */ - foreach($pgpoolConfigBackendParam as $key => $value) { - if(isset($_POST[$key])) { + foreach ($pgpoolConfigBackendParam as $key => $value) { + if (isset($_POST[$key])) { $configValue[$key] = $_POST[$key]; } } /** * check backend value */ - if(isset($configValue['backend_hostname'])) { - for( $i = 0; $i < count($configValue['backend_hostname']); $i++) { - $hostname = $configValue['backend_hostname'][$i]; - $port = $configValue['backend_port'][$i]; - $weight = $configValue['backend_weight'][$i]; - $data_directory = $configValue['backend_data_directory'][$i]; - + if (isset($configValue['backend_hostname'])) { + for ($i = 0; $i < count($configValue['backend_hostname']); $i++) { + $hostname = $configValue['backend_hostname'][$i]; + $port = $configValue['backend_port'][$i]; + $weight = $configValue['backend_weight'][$i]; + $data_directory = $configValue['backend_data_directory'][$i]; + $result = FALSE; - $result = checkString ($hostname, - $pgpoolConfigBackendParam['backend_hostname']['regexp']); - if(!$result) { + + // backend_hostname + $result = checkString($hostname, + $pgpoolConfigBackendParam['backend_hostname']['regexp']); + if (!$result) { $error['backend_hostname'][$i] = TRUE; } else { $error['backend_hostname'][$i] = FALSE; - } + } + + // backend_port $result = checkInteger($port, - $pgpoolConfigBackendParam['backend_port']['min'], - $pgpoolConfigBackendParam['backend_port']['max']); - if(!$result) { + $pgpoolConfigBackendParam['backend_port']['min'], + $pgpoolConfigBackendParam['backend_port']['max']); + if (!$result) { $error['backend_port'][$i] = TRUE; } else { $error['backend_port'][$i] = FALSE; } - $result = checkFloat ($weight, - $pgpoolConfigBackendParam['backend_weight']['min'], - $pgpoolConfigBackendParam['backend_weight']['max']); - if(!$result) { + + // backend_weight + $result = checkFloat($weight, + $pgpoolConfigBackendParam['backend_weight']['min'], + $pgpoolConfigBackendParam['backend_weight']['max']); + if (!$result) { $error['backend_weight'][$i] = TRUE; } else { $error['backend_weight'][$i] = FALSE; } - // check backend_data_directory - $result = checkString ($data_directory, - $pgpoolConfigBackendParam['backend_data_directory']['regexp']); - if(!$result) { + // backend_data_directory + $result = checkString($data_directory, + $pgpoolConfigBackendParam['backend_data_directory']['regexp']); + if (!$result) { $error['backend_data_directory'][$i] = TRUE; } else { $error['backend_data_directory'][$i] = FALSE; - } - + } + } } - + $isError = FALSE; - foreach($error as $key => $value) { - if(preg_match("/^backend_hostname/", $key) - || preg_match("/^backend_port/", $key) - || preg_match("/^backend_weight/", $key) - || preg_match("/^backend_data_directory/", $key)) { - for($i=0; $i < count($value); $i++) { - if($value[$i] == TRUE) { + foreach ($error as $key => $value) { + if (preg_match("/^backend_hostname/", $key) || + preg_match("/^backend_port/", $key) || + preg_match("/^backend_weight/", $key) || + preg_match("/^backend_data_directory/", $key)) + { + for ($i = 0; $i < count($value); $i++) { + if ($value[$i] == TRUE) { $isError = TRUE; } } + } else { if ($value == TRUE) { $isError = TRUE; } } - if($isError) { - break; - } + + if ($isError) { break; } } - - if( !$isError) { - if(is_writable(_PGPOOL2_CONFIG_FILE)) { + + if (!$isError) { + if (is_writable(_PGPOOL2_CONFIG_FILE)) { writeConfigFile($configValue, $pgpoolConfigParam); $configValue = readConfigParams(); $tpl->assign('status', 'success'); @@ -239,27 +262,30 @@ switch( $action ) { $tpl->display('error.tpl'); exit(); } - } else { + + } else { $tpl->assign('status', 'fail'); } break; - + case 'delete': $num = $_POST['num']; - deleteBackendHost($num, $configValue); - if(is_writable(_PGPOOL2_CONFIG_FILE)) { - writeConfigFile($configValue, $pgpoolConfigParam); - $configValue = readConfigParams(); - } else { - $errorCode = 'e4003'; - $tpl->assign('errorCode', $errorCode); - $tpl->display('error.tpl'); - exit(); - } + deleteBackendHost($num, $configValue); + + if (is_writable(_PGPOOL2_CONFIG_FILE)) { + writeConfigFile($configValue, $pgpoolConfigParam); + $configValue = readConfigParams(); + + } else { + $errorCode = 'e4003'; + $tpl->assign('errorCode', $errorCode); + $tpl->display('error.tpl'); + exit(); + } break; - + case 'reset': default: } @@ -269,6 +295,10 @@ $tpl->assign('error', $error); $tpl->display('pgconfig.tpl'); +/* --------------------------------------------------------------------- */ +/* Functions */ +/* --------------------------------------------------------------------- */ + /** * check POST value * @@ -277,10 +307,11 @@ $tpl->display('pgconfig.tpl'); * @param array $configParam * @param string $error */ -function check($key, $value, &$configParam ,&$error) { +function check($key, $value, &$configParam ,&$error) +{ $type = $value['type']; - $result = false; - switch($type) { + $result = FALSE; + switch ($type) { case 'B': $result = checkBoolean($configParam[$key]); break; @@ -294,8 +325,8 @@ function check($key, $value, &$configParam ,&$error) { $result = checkInteger($configParam[$key], $value['min'], $value['max']); break; } - if(!$result) { - $error[$key] = true; + if (!$result) { + $error[$key] = TRUE; } } @@ -308,10 +339,10 @@ function check($key, $value, &$configParam ,&$error) { */ function checkString($str, $pattern) { - if(preg_match("/$pattern/", $str)) { - return true; + if (preg_match("/$pattern/", $str)) { + return TRUE; } else { - return false; + return FALSE; } } @@ -325,16 +356,17 @@ function checkString($str, $pattern) */ function checkInteger($str, $min, $max) { - if(is_numeric($str)) { + if (is_numeric($str)) { $minLen = strlen($min); $maxLen = strlen($max); - if($str < $min || $str > $max) { - return false; + + if ($str < $min || $str > $max) { + return FALSE; } else { - return true; + return TRUE; } } - return false; + return FALSE; } /** @@ -347,13 +379,13 @@ function checkInteger($str, $min, $max) */ function checkFloat($str, $min, $max) { - if(is_numeric($str)) { - if($str < $min || $str > $max) { - return false; + if (is_numeric($str)) { + if ($str < $min || $str > $max) { + return FALSE; } - return true; + return TRUE; } - return false; + return FALSE; } /** @@ -364,10 +396,10 @@ function checkFloat($str, $min, $max) */ function checkBoolean($str) { - if($str == 'true' || $str == 'false') { - return true; + if ($str == 'true' || $str == 'false') { + return TRUE; } else { - return false; + return FALSE; } } @@ -379,22 +411,25 @@ function checkBoolean($str) */ function writeConfigFile($configValue, $pgpoolConfigParam) { - $configFile = @file(_PGPOOL2_CONFIG_FILE); $removeBackendConfigFile = array(); - - for($i=0; $i < count($configFile); $i++) { + + for ($i = 0; $i < count($configFile); $i++) { $line = $configFile[$i]; - if(preg_match("/^\w/", $line)) { + + if (preg_match("/^\w/", $line)) { list($key, $value) = explode("=", $line); $key = trim($key); - if(!preg_match("/^backend_hostname/", $key) - && !preg_match("/^backend_port/", $key) - && !preg_match("/^backend_weight/", $key) - && !preg_match("/^backend_data_directory/", $key)) { + + if (!preg_match("/^backend_hostname/", $key) && + !preg_match("/^backend_port/", $key) && + !preg_match("/^backend_weight/", $key) && + !preg_match("/^backend_data_directory/", $key)) + { $removeBackendConfigFile[] = $line; } + } else { $removeBackendConfigFile[] = $line; } @@ -402,14 +437,14 @@ function writeConfigFile($configValue, $pgpoolConfigParam) $configFile = $removeBackendConfigFile; - foreach($pgpoolConfigParam as $key => $value) { + foreach ($pgpoolConfigParam as $key => $value) { $isWrite = FALSE; - for($j=0; $j diff --git a/procInfo.php b/procInfo.php index b2e8e09..546860d 100644 --- a/procInfo.php +++ b/procInfo.php @@ -25,38 +25,40 @@ require_once('command.php'); -if(!isset($_SESSION[SESSION_LOGIN_USER])) { +if (!isset($_SESSION[SESSION_LOGIN_USER])) { exit(); } $ret = execPcp('PCP_PROC_COUNT'); -if(!array_key_exists('SUCCESS', $ret)) { +if (!array_key_exists('SUCCESS', $ret)) { $errorCode = 'e1004'; $tpl->assign('errorCode', $errorCode); $tpl->display('innerError.tpl'); exit(); + } else { - $procPids = explode(" ", $ret['SUCCESS']); + $procPids = explode(" ", $ret['SUCCESS']); } -for($i=0; $iassign('errorCode', $errorCode); $tpl->display('innerError.tpl'); exit(); - } else { + } else { $ret = $ret['SUCCESS']; - - if(count($ret) > 0) { - foreach($ret as $line) { + + if (count($ret) > 0) { + foreach ($ret as $line) { $data = split(" ", $line); -/* +/* $dateFormat = $message['strDateFormat']; - $data[2] = date($dateFormat, $data[2]); + $data[2] = date($dateFormat, $data[2]); $data[3] = date($dateFormat, $data[3]); */ $procInfo[$procPid][] = $data; diff --git a/queryCache.php b/queryCache.php index 5c82f18..6bc14d7 100644 --- a/queryCache.php +++ b/queryCache.php @@ -26,26 +26,26 @@ require_once('common.php'); $tpl->assign('help', basename( __FILE__, '.php')); -if(!isset($_SESSION[SESSION_LOGIN_USER])) { +if (!isset($_SESSION[SESSION_LOGIN_USER])) { header('Location: login.php'); exit(); } readConfigParams(); -if(isset($_GET['action'])) { +if (isset($_GET['action'])) { $action=$_GET['action']; } else { $action = ''; } -if(isset($_GET['col'])) { +if (isset($_GET['col'])) { $col = $_GET{'col'}; } else { $col = ''; } -if(isset($_GET['sort'])) { +if (isset($_GET['sort'])) { $sort = $_GET{'sort'}; } else { $sort = ''; @@ -55,37 +55,38 @@ $tpl->assign('col', $col); $tpl->assign('sort', $sort); $sysDbParam = readConfigParams(array('system_db_hostname', - 'system_db_port', - 'system_db_dbname', - 'system_db_schema', - 'system_db_user', - 'system_db_password')); + 'system_db_port', + 'system_db_dbname', + 'system_db_schema', + 'system_db_user', + 'system_db_password')); $sysDbParam['hostname'] = $sysDbParam['system_db_hostname']; -$sysDbParam['port'] = $sysDbParam['system_db_port']; -$sysDbParam['dbname'] = $sysDbParam['system_db_dbname']; -$sysDbParam['user'] = $sysDbParam['system_db_user']; +$sysDbParam['port'] = $sysDbParam['system_db_port']; +$sysDbParam['dbname'] = $sysDbParam['system_db_dbname']; +$sysDbParam['user'] = $sysDbParam['system_db_user']; $sysDbParam['password'] = $sysDbParam['system_db_password']; $sysDbSchema = $sysDbParam['system_db_schema']; $conn = openDBConnection($sysDbParam); -if($conn == false) { +if ($conn == FALSE) { $errorCode = 'e2001'; $tpl->assign('errorCode', $errorCode); $tpl->display('error.tpl'); exit(); } -if($action == 'delete') { - if(isset($_POST['hash'])) { +if ($action == 'delete') { + if (isset($_POST['hash'])) { $hashArray = $_POST['hash']; } else { $hashArray = FALSE; } - if($hashArray != FALSE) { + + if ($hashArray != FALSE) { $sql = "DELETE FROM $sysDbSchema.query_cache WHERE "; - for($i=0; $iassign('errorCode', $errorCode); $tpl->display('error.tpl'); @@ -171,11 +174,11 @@ $result = pg_fetch_all($rs); closeDBConnection($conn); -if($result) { - $dateFormat = $message['strDateFormat']; - for($i=0; $iassign('queryCache', $result); } diff --git a/status.php b/status.php index fea3368..db4cc49 100644 --- a/status.php +++ b/status.php @@ -29,19 +29,19 @@ $tpl->assign('help', basename( __FILE__, '.php')); $viewPHP = 'nodeStatus.php'; $refreshTime = 5000; -if(isset($_POST['nodeNumber'])) { +if (isset($_POST['nodeNumber'])) { $nodeNumber = $_POST['nodeNumber']; } else { $nodeNumber = -1; } -if(!isset($_SESSION[SESSION_LOGIN_USER])) { +if (!isset($_SESSION[SESSION_LOGIN_USER])) { header('Location: login.php'); exit(); } -if(isset($_POST['action'])) { +if (isset($_POST['action'])) { $action = $_POST['action']; } else { $action = FALSE; @@ -56,75 +56,82 @@ $tpl->assign('D', _PGPOOL2_CMD_OPTION_LARGE_D); $tpl->assign('d', _PGPOOL2_CMD_OPTION_D); $tpl->assign('m', _PGPOOL2_CMD_OPTION_M); $tpl->assign('n', _PGPOOL2_CMD_OPTION_N); -if(isPipe(_PGPOOL2_LOG_FILE)) - $tpl->assign('pipe', 1); -else - $tpl->assign('pipe', 0); + +if (isPipe(_PGPOOL2_LOG_FILE)) { + $tpl->assign('pipe', 1); +} else { + $tpl->assign('pipe', 0); +} switch ($action) { case 'start': $args = ' '; - if(isset($_POST['c'])) { + if (isset($_POST['c'])) { $args = $args . "-c "; } - if(isset($_POST['D'])) { + if (isset($_POST['D'])) { $args = $args . "-D "; } - if(isset($_POST['d'])) { + if (isset($_POST['d'])) { $args = $args . "-d "; } - if(isset($_POST['n'])) { + if (isset($_POST['n'])) { $pgpoolLog = _PGPOOL2_LOG_FILE; - if($pgpoolLog == '') { + if ($pgpoolLog == '') { $logDir = readLogDir(); $pgpoolLog = "$logDir/pgpool.log"; } - if(isPipe($pgpoolLog)) - $args = "$args -n 2>&1 $pgpoolLog "; - else - $args = "$args -n > $pgpoolLog "; + if (isPipe($pgpoolLog)) { + $args = "$args -n 2>&1 $pgpoolLog "; + } else { + $args = "$args -n > $pgpoolLog "; + } } + $ret = execPcp('PCP_START_PGPOOL', $args); - if(!array_key_exists('SUCCESS', $ret)) { + if (!array_key_exists('SUCCESS', $ret)) { $tpl->assign('pgpoolStatus', 'pgpool start failed.'); $tpl->assign('pgpoolMessage', $ret); } else { - for($i=0; $i<10; $i++) { + for ($i = 0; $i < 10; $i++) { if(DoesPgpoolPidExist()) { break; } else { sleep(1); } } - if(DoesPgpoolPidExist()) { + + if (DoesPgpoolPidExist()) { $tpl->assign('pgpoolStatus', 'pgpool start succeed'); } else { $tpl->assign('pgpoolStatus', 'pgpool start failed. pgpool.pid not found'); } $tpl->assign('pgpoolMessage', $ret['SUCCESS']); } - + break; case 'stop': $m = $_POST['stop_mode']; $ret = execPcp('PCP_STOP_PGPOOL', $m); - if(!array_key_exists('SUCCESS', $ret)) { + if (!array_key_exists('SUCCESS', $ret)) { $errorCode = 'e1006'; $tpl->assign('errorCode', $errorCode); $tpl->display('error.tpl'); exit(); + } else { - for($i=0; $i<10; $i++) { - if(DoesPgpoolPidExist()) { + for ($i = 0; $i < 10; $i++) { + if (DoesPgpoolPidExist()) { sleep(1); } else { break; } } - if(DoesPgpoolPidExist()) { + + if (DoesPgpoolPidExist()) { $tpl->assign('pgpoolStatus', 'pgpool stop failed. pgpool.pid exists.'); } else { $tpl->assign('pgpoolStatus', 'pgpool stop succeed'); @@ -140,65 +147,69 @@ switch ($action) { $m = $_POST['restart_mode']; $ret = execPcp('PCP_STOP_PGPOOL', $m); - if(!array_key_exists('SUCCESS', $ret)) { + if (!array_key_exists('SUCCESS', $ret)) { $errorCode = 'e1006'; $tpl->assign('errorCode', $errorCode); $tpl->display('error.tpl'); exit(); + } else { - for($i=0; $i<10; $i++) { - if(DoesPgpoolPidExist()) { + for($i = 0; $i < 10; $i++) { + if (DoesPgpoolPidExist()) { sleep(1); } else { break; } } } - - if(DoesPgpoolPidExist() ) { - $tpl->assign('pgpoolStatus', 'pgpool restart failed. pgpool.pid exists.'); - break; + + if (DoesPgpoolPidExist()) { + $tpl->assign('pgpoolStatus', 'pgpool restart failed. pgpool.pid exists.'); + break; } - + /** * Start pgpool */ $args = ' '; - if(isset($_POST['c'])) { + if (isset($_POST['c'])) { $args = $args . "-c "; } - if(isset($_POST['D'])) { + if (isset($_POST['D'])) { $args = $args . "-D "; } - if(isset($_POST['d'])) { + if (isset($_POST['d'])) { $args = $args . "-d "; } - if(isset($_POST['n'])) { + if (isset($_POST['n'])) { $pgpoolLog = _PGPOOL2_LOG_FILE; - if($pgpoolLog == '') { + if ($pgpoolLog == '') { $logDir = readLogDir(); $pgpoolLog = "$logDir/pgpool.log"; } - if(isPipe($pgpoolLog)) - $args = "$args -n 2>&1 $pgpoolLog "; - else - $args = "$args -n > $pgpoolLog "; - } + if (isPipe($pgpoolLog)) { + $args = "$args -n 2>&1 $pgpoolLog "; + } else { + $args = "$args -n > $pgpoolLog "; + } + } + $ret = execPcp('PCP_START_PGPOOL', $args); - if(!array_key_exists('SUCCESS', $ret)) { + if (!array_key_exists('SUCCESS', $ret)) { $tpl->assign('pgpoolStatus', 'pgpool restart failed.'); $tpl->assign('pgpoolMessage', $ret); + } else { - for($i=0; $i<10; $i++) { - if(DoesPgpoolPidExist()) { + for ($i = 0; $i < 10; $i++) { + if (DoesPgpoolPidExist()) { $tpl->assign('pgpoolStatus', 'pgpool restart succeed'); break; } else { sleep(1); } } - if(!DoesPgpoolPidExist()) { + if (!DoesPgpoolPidExist()) { $tpl->assign('pgpoolStatus', 'pgpool restart failed. pgpool.pid not found'); } $tpl->assign('pgpoolMessage', $ret['SUCCESS']); @@ -216,7 +227,7 @@ switch ($action) { case 'return': $ret = execPcp('PCP_ATTACH_NODE', $nodeNumber); - if(!array_key_exists('SUCCESS', $ret)) { + if (!array_key_exists('SUCCESS', $ret)) { $errorCode = 'e1010'; $tpl->assign('errorCode', $errorCode); $tpl->display('error.tpl'); @@ -225,8 +236,8 @@ switch ($action) { break; case 'recovery': - $ret = execPcp('PCP_RECOVERY_NODE', $nodeNumber); - if(!array_key_exists('SUCCESS', $ret)) { + $ret = execPcp('PCP_RECOVERY_NODE', $nodeNumber); + if (!array_key_exists('SUCCESS', $ret)) { $errorCode = 'e1012'; $tpl->assign('errorCode', $errorCode); $tpl->display('error.tpl'); @@ -237,43 +248,46 @@ switch ($action) { case 'detach': $ret = execPcp('PCP_DETACH_NODE', $nodeNumber); - if(!array_key_exists('SUCCESS', $ret)) { + if (!array_key_exists('SUCCESS', $ret)) { $errorCode = 'e1007'; $tpl->assign('errorCode', $errorCode); $tpl->display('error.tpl'); exit(); } break; - + case 'summary': $viewPHP = 'innerSummary.php'; break; + case 'proc': $viewPHP = 'procInfo.php'; break; + case 'node': $viewPHP = 'nodeStatus.php'; break; + case 'log': $viewPHP = 'innerLog.php'; break; } -if(DoesPgpoolPidExist()) { - $tpl->assign('pgpoolIsActive', true); +if (DoesPgpoolPidExist()) { + $tpl->assign('pgpoolIsActive', TRUE); } else { - $tpl->assign('pgpoolIsActive', false); + $tpl->assign('pgpoolIsActive', FALSE); } $tpl->assign('viewPHP', $viewPHP); -if( _PGPOOL2_STATUS_REFRESH_TIME >= 0 ) { +if (_PGPOOL2_STATUS_REFRESH_TIME >= 0 ) { $refreshTime = _PGPOOL2_STATUS_REFRESH_TIME * 1000; } -$tpl->assign('pgpoolConf', _PGPOOL2_CONFIG_FILE); -$tpl->assign('pcpConf', _PGPOOL2_PASSWORD_FILE); -$tpl->assign('refreshTime', $refreshTime); +$tpl->assign('pgpoolConf', _PGPOOL2_CONFIG_FILE); +$tpl->assign('pcpConf', _PGPOOL2_PASSWORD_FILE); +$tpl->assign('refreshTime', $refreshTime); $tpl->assign('msgStopPgpool', $message['msgStopPgpool']); $tpl->display('status.tpl'); diff --git a/systemDb.php b/systemDb.php index a3dfdf4..90d015b 100644 --- a/systemDb.php +++ b/systemDb.php @@ -26,32 +26,33 @@ require_once('common.php'); $tpl->assign('help', basename( __FILE__, '.php')); -if(!isset($_SESSION[SESSION_LOGIN_USER])) { +if (!isset($_SESSION[SESSION_LOGIN_USER])) { header('Location: login.php'); exit(); } -if( ! file_exists(_PGPOOL2_CONFIG_FILE)) { +if (!file_exists(_PGPOOL2_CONFIG_FILE)) { $errorCode = 'e3006'; $tpl->assign('errorCode', $errorCode); $tpl->display('error.tpl'); exit(); } + $sysDbParam = readConfigParams(array('system_db_hostname', - 'system_db_port', - 'system_db_dbname', - 'system_db_schema', - 'system_db_user', - 'system_db_password')); + 'system_db_port', + 'system_db_dbname', + 'system_db_schema', + 'system_db_user', + 'system_db_password')); $sysDbParam['hostname'] = $sysDbParam['system_db_hostname']; -$sysDbParam['port'] = $sysDbParam['system_db_port']; -$sysDbParam['dbname'] = $sysDbParam['system_db_dbname']; -$sysDbParam['user'] = $sysDbParam['system_db_user']; +$sysDbParam['port'] = $sysDbParam['system_db_port']; +$sysDbParam['dbname'] = $sysDbParam['system_db_dbname']; +$sysDbParam['user'] = $sysDbParam['system_db_user']; $sysDbParam['password'] = $sysDbParam['system_db_password']; $conn = openDBConnection($sysDbParam); -if($conn == false) { +if ($conn == FALSE) { $errorCode = 'e3001'; $tpl->assign('errorCode', $errorCode); $tpl->display('error.tpl'); @@ -60,58 +61,60 @@ if($conn == false) { $sysDbSchema = $sysDbParam['system_db_schema']; -if(isset($_GET['dbname'])) { +if (isset($_GET['dbname'])) { $dbname = pg_escape_string($_GET['dbname']); } else { $dbname = ''; } -if(isset($_GET['schema_name'])) { +if (isset($_GET['schema_name'])) { $schema_name = pg_escape_string($_GET['schema_name']); } else { $schema_name = ''; } -if(isset($_GET['table_name'])) { +if (isset($_GET['table_name'])) { $table_name = pg_escape_string($_GET['table_name']); } else { $table_name = ''; } -$result = null; +$result = NULL; + +if ($dbname && $schema_name && $table_name) { + $sql = "SELECT * FROM $sysDbSchema.dist_def ". + "WHERE dbname='$dbname' AND schema_name='$schema_name' AND table_name = '$table_name'"; -if($dbname && $schema_name && $table_name) { - $sql = "SELECT * FROM $sysDbSchema.dist_def WHERE dbname='$dbname' AND schema_name='$schema_name' AND table_name = '$table_name'"; $rs = execQuery($conn, $sql); - if($rs == false) { + if ($rs == FALSE) { $errorCode = 'e3002'; $tpl->assign('errorCode', $errorCode); $tpl->display('error.tpl'); exit(); - } + } - if(pg_num_rows($rs) > 0) { + if (pg_num_rows($rs) > 0) { $result = pg_fetch_array($rs, 0); - - $col_lists = var_sql2php($result['col_list']); + + $col_lists = var_sql2php($result['col_list']); $type_lists = var_sql2php($result['type_list']); - - $col_list = "'" . $col_lists[0] . "'"; - $type_list = "'" . $type_lists[0] . "'"; - - for($i=1; $iassign('isUpdate', true); + + $tpl->assign('isUpdate', TRUE); } } $tpl->assign('result', $result); -if(isset($_POST['action'])) { +if (isset($_POST['action'])) { $action = $_POST['action']; } else { $action = FALSE; @@ -119,256 +122,273 @@ if(isset($_POST['action'])) { $error = FALSE; -switch( $action ) { - +switch ($action) { + case 'add': - $dbname = $_POST['dbname']; - $schema_name = $_POST['schema_name']; - $table_name = $_POST['table_name']; - $col_name = $_POST['col_name']; - $col_list = $_POST['col_list']; - $type_list = $_POST['type_list']; + $dbname = $_POST['dbname']; + $schema_name = $_POST['schema_name']; + $table_name = $_POST['table_name']; + $col_name = $_POST['col_name']; + $col_list = $_POST['col_list']; + $type_list = $_POST['type_list']; $dist_def_func = $_POST['dist_def_func']; - - $col_list = str_replace('\\', '', $col_list); + + $col_list = str_replace('\\', '', $col_list); $type_list = str_replace('\\', '', $type_list); - - $col_lists = explode_csv($col_list, FALSE, ',', '\'', array()); + + $col_lists = explode_csv($col_list, FALSE, ',', '\'', array()); $type_lists = explode_csv($type_list, FALSE, ',', '\'', array()); - - if($dbname == '' - || $schema_name == '' - || $table_name == '' - || $col_name == '' - || $col_list == '' - || $type_list == '' - || $dist_def_func == '') { - $tpl->assign('error', $message['errInputEverything']); - $error = TRUE; - break; + + if ($dbname == '' || + $schema_name == '' || + $table_name == '' || + $col_name == '' || + $col_list == '' || + $type_list == '' || + $dist_def_func == '') + { + $tpl->assign('error', $message['errInputEverything']); + $error = TRUE; + break; } - - if(count($col_lists) != count($type_lists)) { + + if (count($col_lists) != count($type_lists)) { $tpl->assign('error', $message['errNotSameLength']); $error = TRUE; break; } - - for($i=0; $iassign('error', $message['errNotSameLength']); $error = TRUE; break 2; } } - - for($i=0; $iassign('errorCode', $errorCode); $tpl->display('error.tpl'); exit(); - } + } $count = pg_fetch_row($rs, 0); - - if($count[0] > 0) { + + if ($count[0] > 0) { $tpl->assign('error', $message['errAlreadyExist']); $error = TRUE; break; } - - $sql = "INSERT INTO $sysDbSchema.dist_def VALUES('$dbname', '$schema_name', '$table_name', '$col_name', ARRAY[$col_list], ARRAY[$type_list], '$dist_def_func')"; - + + $sql = "INSERT INTO $sysDbSchema.dist_def VALUES ". + "('$dbname', '$schema_name', '$table_name', '$col_name', ". + "ARRAY[$col_list], ARRAY[$type_list], '$dist_def_func')"; + $rs = execQuery($conn, $sql); - if($rs == false) { + if ($rs == FALSE) { $errorCode = 'e3003'; $tpl->assign('errorCode', $errorCode); $tpl->display('error.tpl'); exit(); - } + } + break; - + case 'update': - $tpl->assign('isUpdate', true); - - $dbname = $_POST['dbname']; - $schema_name = $_POST['schema_name']; - $table_name = $_POST['table_name']; - $col_name = $_POST['col_name']; - $col_list = $_POST['col_list']; - $type_list = $_POST['type_list']; + $tpl->assign('isUpdate', TRUE); + + $dbname = $_POST['dbname']; + $schema_name = $_POST['schema_name']; + $table_name = $_POST['table_name']; + $col_name = $_POST['col_name']; + $col_list = $_POST['col_list']; + $type_list = $_POST['type_list']; $dist_def_func = $_POST['dist_def_func']; - - $col_list = str_replace('\\', '', $col_list); + + $col_list = str_replace('\\', '', $col_list); $type_list = str_replace('\\', '', $type_list); - - $col_lists = explode_csv($col_list, FALSE, ',', '\'', array()); + + $col_lists = explode_csv($col_list, FALSE, ',', '\'', array()); $type_lists = explode_csv($type_list, FALSE, ',', '\'', array()); - - if($dbname == '' - || $schema_name == '' - || $table_name == '' - || $col_name == '' - || $col_list == '' - || $type_list == '' - || $dist_def_func == '') { - $tpl->assign('error', $message['errInputEverything']); - $error = TRUE; - break; + + if ($dbname == '' || + $schema_name == '' || + $table_name == '' || + $col_name == '' || + $col_list == '' || + $type_list == '' || + $dist_def_func == '') + { + $tpl->assign('error', $message['errInputEverything']); + $error = TRUE; + break; } - - if(count($col_lists) != count($type_lists)) { + + if (count($col_lists) != count($type_lists)) { $tpl->assign('error', $message['errNotSameLength']); $error = TRUE; break; } - - $err = false; - - for($i=0; $iassign('error', $message['errNotSameLength']); $error = TRUE; break 2; } } - - for($i=0; $iassign('errorCode', $errorCode); $tpl->display('error.tpl'); exit(); - } - $tpl->assign('isUpdate', false); + } + $tpl->assign('isUpdate', FALSE); break; } + case 'delete': - $dbname = pg_escape_string($_POST['dbname']); + $dbname = pg_escape_string($_POST['dbname']); $schema_name = pg_escape_string($_POST['schema_name']); - $table_name = pg_escape_string($_POST['table_name']); - - if($dbname && $schema_name && $table_name) { - $sql = "DELETE FROM $sysDbSchema.dist_def WHERE " - . "dbname = '$dbname' AND " - . "schema_name = '$schema_name' AND " - . "table_name = '$table_name'"; - + $table_name = pg_escape_string($_POST['table_name']); + + if ($dbname && $schema_name && $table_name) { + $sql = "DELETE FROM $sysDbSchema.dist_def WHERE ". + "dbname = '$dbname' AND ". + "schema_name = '$schema_name' AND ". + "table_name = '$table_name'"; + $rs = execQuery($conn, $sql); - if($rs == false) { + if ($rs == FALSE) { $errorCode = 'e3005'; $tpl->assign('errorCode', $errorCode); $tpl->display('error.tpl'); exit(); - } + } break; } - case 'cancel': - default: + + case 'cancel': + default: } -if($error == TRUE) { - $result['dbname'] = $dbname; - $result['schema_name'] = $schema_name; - $result['table_name'] = $table_name; - $result['col_name'] = $col_name; - $result['col_list'] = $col_list; - $result['type_list'] = $type_list; +if ($error == TRUE) { + $result['dbname'] = $dbname; + $result['schema_name'] = $schema_name; + $result['table_name'] = $table_name; + $result['col_name'] = $col_name; + $result['col_list'] = $col_list; + $result['type_list'] = $type_list; $result['dist_def_func'] = $dist_def_func; - $tpl->assign('result', $result); + + $tpl->assign('result', $result); } $sql = "SELECT * FROM $sysDbSchema.dist_def ORDER BY dbname"; $rs = execQuery($conn, $sql); -if($rs == false) { +if ($rs == FALSE) { $errorCode = 'e3002'; $tpl->assign('errorCode', $errorCode); $tpl->display('error.tpl'); exit(); -} +} $result = pg_fetch_all($rs); closeDBConnection($conn); -if($result) { +if ($result) { $arrayResult = array(); foreach($result as $rc) { - $rc['col_list'] = var_sql2php($rc['col_list']); - $rc['type_list'] = var_sql2php($rc['type_list']); + $rc['col_list'] = var_sql2php($rc['col_list']); + $rc['type_list'] = var_sql2php($rc['type_list']); $rc['listLength'] = count($rc['col_list']); array_push($arrayResult, $rc); } - + $tpl->assign('systemDb', $arrayResult); } $tpl->display('systemDb.tpl'); -function explode_csv($STR,$SQL = FALSE,$DELIMITER = ',',$ENCLOSURE = '"',$BRACKETS = array('{','}')) { - $column = 0; +/* --------------------------------------------------------------------- */ +/* Functions */ +/* --------------------------------------------------------------------- */ + +function explode_csv($STR, $SQL = FALSE, $DELIMITER = ',', $ENCLOSURE = '"', $BRACKETS = array('{','}')) +{ + $column = 0; $enclose = FALSE; - $escape = FALSE; - $braket = 0; + $escape = FALSE; + $braket = 0; settype($ROW[$column],'string'); - for($i = 0; $i < mb_strlen($STR); $i++) { + + for ($i = 0; $i < mb_strlen($STR); $i++) { $C = mb_substr($STR,$i,1); - if(isset($BRACKETS[0])) { + + if (isset($BRACKETS[0])) { $brakets0 = $BRACKETS[0]; } else { - $brakets0 = null; + $brakets0 = NULL; } - if(isset($BRACKETS[1])) { + + if (isset($BRACKETS[1])) { $brakets1 = $BRACKETS[1]; } else { - $brakets1 = null; + $brakets1 = NULL; } - - switch($C) { + + switch ($C) { case $DELIMITER: if($enclose || $braket > 0) { $ROW[$column] .= $C; @@ -378,12 +398,12 @@ function explode_csv($STR,$SQL = FALSE,$DELIMITER = ',',$ENCLOSURE = '"',$BRACKE } $escape = FALSE; break; - + case $ENCLOSURE: - if($escape || $braket) { + if ($escape || $braket) { $ROW[$column] .= $C; } else { - if($enclose) { + if ($enclose) { $enclose = FALSE; } else { $enclose = TRUE; @@ -391,53 +411,56 @@ function explode_csv($STR,$SQL = FALSE,$DELIMITER = ',',$ENCLOSURE = '"',$BRACKE } $escape = FALSE; break; - + case '\\': $ROW[$column] .= $C; $escape = TRUE; break; - + case $brakets0: $ROW[$column] .= $C; - if($SQL && !$escape) { + if ($SQL && !$escape) { $braket++; } $escape = FALSE; break; - + case $brakets1: $ROW[$column] .= $C; - if($SQL && !$escape) { + if ($SQL && !$escape) { $braket--; } $escape = FALSE; break; - + default: $ROW[$column] .= $C; $escape = FALSE; } } + return($ROW); } -function var_sql2php($VAL) { - if(mb_ereg('^\{(.*)\}$',$VAL,$match) !== FALSE) { - $VAL = array_map('var_sql2php',explode_csv($match[1],TRUE)); +function var_sql2php($VAL) +{ + if (mb_ereg('^\{(.*)\}$',$VAL,$match) !== FALSE) { + $VAL = array_map('var_sql2php', explode_csv($match[1],TRUE)); } return($VAL); } -function array2sql($var) { - if(!is_array($var)) { +function array2sql($var) +{ + if (!is_array($var)) { return ''; } - + $str = ''; - $str = "'" . $var[0] . "'"; - - for($i=1; $i{$message.msgUpdateFailed|escape} - {/if} + {/if}

{$message.strSetting|escape}

@@ -131,19 +131,19 @@ - {elseif $params.m == 'f'} + {elseif $params.m == 'f'} - {elseif $params.m == 'i'} + {elseif $params.m == 'i'} - {else} + {else} - {/if} + {/if} {if $errors.pgpool_logfile != null}{else}{/if} diff --git a/templates/error.tpl b/templates/error.tpl index 50f7343..05a24a9 100644 --- a/templates/error.tpl +++ b/templates/error.tpl @@ -25,9 +25,7 @@ {$message.$errorCode|escape} - -