$valor) { $paramInsert[$key] = $valor; } } else { $jsStartup[] = "alert('Servidores OK!');"; foreach ($_POST as $key => $valor) { $paramInsert[$key] = $valor; } } } if (isset($_POST['btGravar'])) { $servers = strripos($_POST['server_address'], " ") ? explode(" ", $_POST['server_address']) : str_replace(","," ",explode(",", $_POST['server_address'])); foreach ($servers as $valor) { $query = "INSERT INTO pbx_agenda_servidores (ip_servidores, porta) " . "VALUES ('{$valor}','{$_POST['server_port']}')"; $sql = pg_query($dbcon, $query); if (!$sql) { $jsStartup[] = "alert('Erro ao salvar a operação no banco de dados local!');"; foreach ($_POST as $key => $valor) { $paramInsert[$key] = $valor; } break; } } $jsStartup[] = "alert('Servidores Cadastrados com Sucesso!');"; } if($acao == 'deleta'){ $result = pg_query($dbcon, "DELETE FROM pbx_agenda_servidores WHERE id_servidor = '$id' "); if(!$result){ $jsStartup[] = "alert('Erro ao excluir o registro!');"; }else{ $jsStartup[] = "alert('Registro Excluído com Sucesso!');"; } } if($acao == 'edita'){ $sql = "SELECT id_servidor, ip_servidores, porta FROM pbx_agenda_servidores WHERE id_servidor = {$id}"; $result = pg_query($dbcon, $sql); $server = pg_fetch_array($result, null, PGSQL_ASSOC); $server_address = $server['ip_servidores']; $server_port = $server['porta']; } if (isset($_POST['btEditar'])) { $sql = "UPDATE pbx_agenda_servidores SET ip_servidores = '{$_POST['server_address']}', porta = '{$_POST['server_port']}' " . "WHERE id_servidor = {$id}"; $result = pg_query($dbcon, $sql); if (!$result) { $jsStartup[] = "alert('Erro ao editar o registro!');"; } else { $jsStartup[] = "alert('Registro Alterado com Sucesso!');"; } } $result = pg_query($dbcon, "SELECT id_servidor, ip_servidores, porta FROM pbx_agenda_servidores WHERE 1=1"); $linhas = ''; while($row = pg_fetch_array($result, null ,PGSQL_ASSOC)){ $editar = sprintf('' . 'Editar Servidor %s', $row['id_servidor'], $row['ip_servidores']); $excluir = sprintf('' . '', $row['ip_servidores'], $row['id_servidor']); $linhas .= sprintf("%s%s%s%s", $row['ip_servidores'], $row['porta'], $editar, $excluir); } $smarty->assign('server_address', $server_address); $smarty->assign('server_port', $server_port); $smarty->assign('linhas',$linhas); $smarty->assign('id_servidor', $_REQUEST['id_servidor']); $smarty->assign('edita', $_GET['acao']); GetTemplate($smarty, 'importaAgenda.tpl'); function TestaConexao($host, $ports) { try { if(empty($ports)){throw new Exception("Informe a porta de conexão!");} if(empty($host)){throw new Exception("Informe o servidor para conexão!");} $host = explode(",", $host); $ports = explode(",", $ports); $res = false; foreach ($host as $numeroip) { $pingando = shell_exec("ping -c 4 $numeroip"); $p = explode(",", $pingando); $res_ping = substr($p[1], 1, 2); if ($res_ping >= 2) { $res = true; }else{ throw new Exception("IP {$numeroip} Não responde ao ping!"); } } foreach ($host as $server) { foreach ($ports as $port) { $connection = @fsockopen($server, $port); if (is_resource($connection)) { $result[] = $server . ':' . $port . ' ' . '(' . getservbyport($port, 'tcp') . ') aberta.' . "\n"; fclose($connection); } else { $result[] = 'Error! - ' . $server . ':' . $port . ' sem resposta.' . "\n"; } } } foreach ($result as $resultado) { if (substr($resultado, 0, 5) == "Error") { $prob = explode(":", $resultado); $res = "IP {$prob[0]} não possui liberacao na porta ". substr($prob[1], 0,4); } else { $res = "Servidores OK!"; } } return $res; } catch (Exception $ex) { return $ex->getMessage(); } } function ValorInicio($arFields) { $arInput = array(); foreach ($arFields as $campo) { $arInput[$campo] = ""; } return $arInput; }