function inet_pton($ip) { # ipv4 # check for a IPv4-mapped address if (preg_match('#^::ffff:([0-9A-F]{1,4}):([0-9A-F]{1,4})$#i', $ip, $match)) { $match[1] = str_pad($match[1], 4, '0', STR_PAD_LEFT); $match[2] = str_pad($match[2], 4, '0', STR_PAD_LEFT); $ip1 = hexdec(substr($match[1], 0, 2)); $ip2 = hexdec(substr($match[1], 2)); $ip3 = hexdec(substr($match[2], 0, 2)); $ip4 = hexdec(substr($match[2], 2)); $ip = pack('N', NET::ip2long("{$ip1}.{$ip2}.{$ip3}.{$ip4}")); } else { if (strpos($ip, '.') !== FALSE) { # check for a hybrid IPv4-compatible address $pos = strrpos($ip, ':'); if ($pos !== FALSE) { $ip = substr($ip, $pos + 1); } # finally make the binary code $ip = pack('N', NET::ip2long($ip)); } else { if (strpos($ip, ':') !== FALSE) { # fix shortened ip's $c = substr_count($ip, ':'); if ($c < 7) { $ip = str_replace('::', str_pad('::', 9 - $c, ':'), $ip); } # now fix the group lengths $ip = explode(':', $ip); $res = ''; foreach ($ip as $seg) { $res .= str_pad($seg, 4, '0', STR_PAD_LEFT); } # finally make the binary code $ip = pack('H' . strlen($res), $res); } } } return $ip; }
/** * for Test email configuration * @autor Alvaro <*****@*****.**> */ public function testConnection($params) { G::LoadClass('net'); G::LoadThirdParty('phpmailer', 'class.smtp'); if ($_POST['typeTest'] == 'MAIL') { define("SUCCESSFUL", 'SUCCESSFUL'); define("FAILED", 'FAILED'); $mail_to = $_POST['mail_to']; $send_test_mail = $_POST['send_test_mail']; $_POST['FROM_NAME'] = $mail_to; $_POST['FROM_EMAIL'] = $mail_to; $_POST['MESS_ENGINE'] = 'MAIL'; $_POST['MESS_SERVER'] = 'localhost'; $_POST['MESS_PORT'] = 25; $_POST['MESS_ACCOUNT'] = $mail_to; $_POST['MESS_PASSWORD'] = ''; $_POST['TO'] = $mail_to; $_POST['SMTPAuth'] = true; try { $resp = $this->sendTestMail(); } catch (Exception $error) { $resp = new stdclass(); $resp->status = false; $resp->msg = $error->getMessage(); } $response = array('success' => $resp->status); if ($resp->status == false) { $response['msg'] = G::LoadTranslation('ID_SENDMAIL_NOT_INSTALLED'); } echo G::json_encode($response); die; } $step = $_POST['step']; $server = $_POST['server']; $user = $_POST['user']; $passwd = $_POST['passwd']; $passwdHide = $_POST['passwdHide']; if (trim($passwdHide) != '') { $passwd = $passwdHide; $passwdHide = ''; } $passwdDec = G::decrypt($passwd, 'EMAILENCRYPT'); $auxPass = explode('hash:', $passwdDec); if (count($auxPass) > 1) { if (count($auxPass) == 2) { $passwd = $auxPass[1]; } else { array_shift($auxPass); $passwd = implode('', $auxPass); } } $_POST['passwd'] = $passwd; $port = $_POST['port']; $auth_required = $_POST['req_auth']; $UseSecureCon = $_POST['UseSecureCon']; $SendaTestMail = $_POST['SendaTestMail']; $Mailto = $_POST['eMailto']; $SMTPSecure = $_POST['UseSecureCon']; $Server = new NET($server); $smtp = new SMTP(); $timeout = 10; $hostinfo = array(); $srv = $_POST['server']; switch ($step) { case 1: $this->success = $Server->getErrno() == 0; $this->msg = $this->result ? 'success' : $Server->error; break; case 2: $Server->scannPort($port); $this->success = $Server->getErrno() == 0; //'Successfull'.$smtp->status; $this->msg = $this->result ? '' : $Server->error; break; case 3: //try to connect to host if (preg_match('/^(.+):([0-9]+)$/', $srv, $hostinfo)) { $server = $hostinfo[1]; $port = $hostinfo[2]; } else { $host = $srv; } $tls = strtoupper($SMTPSecure) == 'tls'; $ssl = strtoupper($SMTPSecure) == 'ssl'; $this->success = $smtp->Connect(($ssl ? 'ssl://' : '') . $server, $port, $timeout); $this->msg = $this->result ? '' : $Server->error; break; case 4: //try login to host if ($auth_required == 'true') { try { if (preg_match('/^(.+):([0-9]+)$/', $srv, $hostinfo)) { $server = $hostinfo[1]; $port = $hostinfo[2]; } else { $server = $srv; } if (strtoupper($UseSecureCon) == 'TLS') { $tls = 'tls'; } if (strtoupper($UseSecureCon) == 'SSL') { $tls = 'ssl'; } $tls = strtoupper($UseSecureCon) == 'tls'; $ssl = strtoupper($UseSecureCon) == 'ssl'; $server = $_POST['server']; if (strtoupper($UseSecureCon) == 'SSL') { $resp = $smtp->Connect('ssl://' . $server, $port, $timeout); } else { $resp = $smtp->Connect($server, $port, $timeout); } if ($resp) { $hello = $_SERVER['SERVER_NAME']; $smtp->Hello($hello); if (strtoupper($UseSecureCon) == 'TLS') { $smtp->Hello($hello); } if ($smtp->Authenticate($user, $passwd)) { $this->success = true; } else { $this->success = false; $this->msg = $smtp->error['error']; } } else { $this->success = false; $this->msg = $smtp->error['error']; } } catch (Exception $e) { $this->success = false; $this->msg = $e->getMessage(); } } else { $this->success = true; $this->msg = 'No authentication required!'; } break; case 5: if ($SendaTestMail == 'true') { try { $_POST['FROM_NAME'] = 'Process Maker O.S. [Test mail]'; $_POST['FROM_EMAIL'] = $user; $_POST['MESS_ENGINE'] = 'PHPMAILER'; $_POST['MESS_SERVER'] = $server; $_POST['MESS_PORT'] = $port; $_POST['MESS_ACCOUNT'] = $user; $_POST['MESS_PASSWORD'] = $passwd; $_POST['TO'] = $Mailto; if ($auth_required == 'true') { $_POST['SMTPAuth'] = true; } else { $_POST['SMTPAuth'] = false; } if (strtolower($_POST["UseSecureCon"]) != "no") { $_POST["SMTPSecure"] = $_POST["UseSecureCon"]; } if ($_POST['UseSecureCon'] == 'ssl') { $_POST['MESS_SERVER'] = 'ssl://' . $_POST['MESS_SERVER']; } $resp = $this->sendTestMail(); if ($resp->status == '1') { $this->success = true; } else { $this->success = false; $this->msg = $smtp->error['error']; } } catch (Exception $e) { $this->success = false; $this->msg = $e->getMessage(); } } else { $this->success = true; $this->msg = 'jump this step'; } break; } }
/** * Test DataBase Connection * @var string $dataCon. Data for DataBase Connection * @var string $returnArray. Flag for url * * @author Brayan Pereyra (Cochalo) <*****@*****.**> * @copyright Colosa - Bolivia * * @return void */ public function testConnection($dataCon, $returnArray = false) { $resp = array(); $respTest = array(); $resp['resp'] = false; $dataCon = array_change_key_case($dataCon, CASE_UPPER); $flagTns = $dataCon["DBS_TYPE"] == "oracle" && $dataCon["DBS_CONNECTION_TYPE"] == "TNS" ? 1 : 0; G::LoadClass('net'); if ($flagTns == 0) { $Server = new \NET($dataCon['DBS_SERVER']); // STEP 1 : Resolving Host Name $respTest['0'] = array(); $respTest['0']['test'] = G::loadTranslation('RESOLVING_NAME') . ' ' . $dataCon['DBS_SERVER']; if ($Server->getErrno() != 0) { if ($returnArray) { $respTest['0']['error'] = G::loadTranslation('ID_ERROR_HOST_NAME_FAILED') . ' : ' . $Server->error; } else { $resp['message'] = G::loadTranslation('ID_ERROR_HOST_NAME_FAILED') . ' : ' . $Server->error; return $resp; } } // STEP 2 : Checking port $respTest['1'] = array(); $respTest['1']['test'] = G::loadTranslation('ID_CHECK_PORT') . ' ' . $dataCon['DBS_PORT']; $Server->scannPort($dataCon['DBS_PORT']); if ($Server->getErrno() != 0) { if ($returnArray) { $respTest['1']['error'] = G::loadTranslation('ID_CHECK_PORT_FAILED') . ' : ' . $Server->error; } else { $resp['message'] = G::loadTranslation('ID_CHECK_PORT_FAILED') . ' : ' . $Server->error; return $resp; } } // STEP 3 : Trying to connect to host $respTest['2'] = array(); $respTest['2']['test'] = G::loadTranslation('ID_CONNECTING_TO_HOST') . ' ' . $dataCon['DBS_SERVER'] . ($dataCon['DBS_PORT'] != '' ? ':' . $dataCon['DBS_PORT'] : ''); $Server->loginDbServer($dataCon['DBS_USERNAME'], $dataCon['DBS_PASSWORD']); $Server->setDataBase($dataCon['DBS_DATABASE_NAME'], $dataCon['DBS_PORT']); if ($Server->errno == 0) { $response = $Server->tryConnectServer($dataCon['DBS_TYPE']); if ($response->status != 'SUCCESS') { if ($returnArray) { $respTest['2']['error'] = G::loadTranslation('ID_CONNECTING_TO_HOST_FAILED') . ' : ' . $Server->error; } else { $resp['message'] = G::loadTranslation('ID_CONNECTING_TO_HOST_FAILED') . ' : ' . $Server->error; return $resp; } } } else { if ($returnArray) { $respTest['2']['error'] = G::loadTranslation('ID_CONNECTING_TO_HOST_FAILED') . ' : ' . $Server->error; } else { $resp['message'] = G::loadTranslation('ID_CONNECTING_TO_HOST_FAILED') . ' : ' . $Server->error; return $resp; } } // STEP 4 : Trying to open database $respTest['3'] = array(); $respTest['3']['test'] = G::loadTranslation('ID_OPEN_DATABASE') . ' [' . $dataCon['DBS_DATABASE_NAME'] . ']'; $Server->loginDbServer($dataCon['DBS_USERNAME'], $dataCon['DBS_PASSWORD']); $Server->setDataBase($dataCon['DBS_DATABASE_NAME'], $dataCon['DBS_PORT']); if ($Server->errno == 0) { $response = $Server->tryConnectServer($dataCon['DBS_TYPE']); if ($response->status == 'SUCCESS') { $response = $Server->tryOpenDataBase($dataCon['DBS_TYPE']); if ($response->status != 'SUCCESS') { if ($returnArray) { $respTest['3']['error'] = G::loadTranslation('ID_CONNECTING_TO_DATABASE_FAILED') . ' : ' . $Server->error; } else { $resp['message'] = G::loadTranslation('ID_CONNECTING_TO_DATABASE_FAILED') . ' : ' . $Server->error; return $resp; } } } else { if ($returnArray) { $respTest['3']['error'] = G::loadTranslation('ID_CONNECTING_TO_DATABASE_FAILED') . ' : ' . $Server->error; } else { $resp['message'] = G::loadTranslation('ID_CONNECTING_TO_DATABASE_FAILED') . ' : ' . $Server->error; return $resp; } } } else { if ($returnArray) { $respTest['3']['error'] = G::loadTranslation('ID_CONNECTING_TO_DATABASE_FAILED') . ' : ' . $Server->error; } else { $resp['message'] = G::loadTranslation('ID_CONNECTING_TO_DATABASE_FAILED') . ' : ' . $Server->error; return $resp; } } } else { $net = new \NET(); //STEP 0: Trying to open database type TNS $respTest["0"] = array(); $respTest["0"]["test"] = G::loadTranslation('ID_TEST_DATABASE_ORACLE_TNS') . ' ' . $dataCon["DBS_TNS"]; $net->loginDbServer($dataCon["DBS_USERNAME"], $dataCon["DBS_PASSWORD"]); if ($net->errno == 0) { $arrayServerData = array("connectionType" => $dataCon["DBS_CONNECTION_TYPE"], "tns" => $dataCon["DBS_TNS"]); $response = $net->tryConnectServer($dataCon["DBS_TYPE"], $arrayServerData); if ($response->status == "SUCCESS") { $response = $net->tryOpenDataBase($dataCon["DBS_TYPE"], $arrayServerData); if ($response->status != "SUCCESS") { if ($returnArray) { $respTest["0"]["error"] = G::loadTranslation('ID_TEST_ERROR_ORACLE_TNS') . ', ' . $net->error; } else { $resp["message"] = G::loadTranslation('ID_TEST_ERROR_ORACLE_TNS') . ', ' . $net->error; //Return return $resp; } } } else { if ($returnArray) { $respTest["0"]["error"] = G::loadTranslation('ID_TEST_ERROR_ORACLE_TNS') . ', ' . $net->error; } else { $resp["message"] = G::loadTranslation('ID_TEST_ERROR_ORACLE_TNS') . ', ' . $net->error; //Return return $resp; } } } else { if ($returnArray) { $respTest["0"]["error"] = G::loadTranslation('ID_TEST_ERROR_ORACLE_TNS') . ', ' . $net->error; } else { $resp["message"] = G::loadTranslation('ID_TEST_ERROR_ORACLE_TNS') . ', ' . $net->error; //Return return $resp; } } } if ($returnArray) { return $respTest; } else { // CORRECT CONNECTION $resp['resp'] = true; return $resp; } }
private static function flood() { global $db, $prefix, $MAIN_CFG; $ip = NET::get_ip(); $ipn = $db->binary_safe($ip); $delay = $MAIN_CFG['_security']['delay']; $flood_time = $flood_count = 0; $log = array(); $time = time(); if (!isset($_SESSION['SECURITY']['flood_start'])) { $db->sql_query('DELETE FROM ' . $prefix . '_security_flood WHERE flood_time <= ' . $time); } else { $_SESSION['SECURITY']['flood_start'] = false; } if ($MAIN_CFG['_security']['debug'] || empty($_SESSION['SECURITY']['flood_time'])) { # try to load time from log if ($row = $db->sql_ufetchrow('SELECT * FROM ' . $prefix . '_security_flood WHERE flood_ip =' . $ipn, SQL_ASSOC)) { if (!empty($row)) { $flood_time = $row['flood_time']; $flood_count = $row['flood_count']; if (!empty($row['log']) && $MAIN_CFG['_security']['debug']) { $log = unserialize($row['log']); } } } } else { $flood_time = $_SESSION['SECURITY']['flood_time']; $flood_count = $_SESSION['SECURITY']['flood_count']; } if ($flood_time >= $time) { # die with message and report ++$flood_count; if ($flood_count <= 5) { if (empty($_SESSION['SECURITY']['shield']) && $flood_count > 2 && $flood_count <= 5) { Security::flood_log($ipn, !empty($row), $delay, $time, $log, $flood_count); global $LNG; get_lang('errors'); $flood_time = ($flood_count + 1) * 2 / $delay; header($_SERVER['SERVER_PROTOCOL'] . ' 503 Service Unavailable'); header('Retry-After: ' . $flood_time); $msg = sprintf($LNG['_SECURITY_MSG']['_FLOOD'], $flood_time); if ($flood_count == 5) { $msg .= $LNG['_SECURITY_MSG']['Last_warning']; } $msg = sprintf(_JS_ALERT, $msg); cpg_error($msg, 'Flood Protection'); } } else { if ($MAIN_CFG['_security']['debug']) { if (!empty($log)) { $log = Security::log_serializer($log); } else { if (!empty($_SESSION['FLOODING'])) { $log = Security::log_serializer($_SESSION['FLOODING']); } } $log = "'{$log}'"; if (!empty($_SESSION['SECURITY']['shield'])) { if ($_SESSION['SECURITY']['shield'] == 4) { list(, $ip4) = unpack('N', $ip); $db->sql_query('UPDATE ' . $prefix . "_security SET log={$log} WHERE ban_type=8 AND (ban_ipv4_s = {$ip4} OR (ban_ipv4_s < {$ip4} AND ban_ipv4_e >= {$ip4}))"); } else { $mac = strlen($ip) == 16 ? ' OR ban_ipn=' . $db->binary_safe(substr($ip, -8)) : ''; $db->sql_query('UPDATE ' . $prefix . "_security SET log={$log} WHERE ban_type=8 AND (ban_ipn={$ipn}{$mac})"); } $flood_time = $_SESSION['SECURITY']['flood_time'] = 0; $flood_count = $_SESSION['SECURITY']['flood_count'] = 0; return; } } else { $log = 'DEFAULT'; } $db->sql_query('INSERT INTO ' . $prefix . "_security (ban_ipn, ban_type, ban_time, ban_details, log) VALUES ({$ipn}, '7', '" . ($time + $MAIN_CFG['_security']['bantime']) . "', 'Flooding detected by User-Agent:\n{$_SERVER['HTTP_USER_AGENT']}', {$log})", TRUE, TRUE); global $SESS; if (is_object($SESS)) { $SESS->destroy(); } cpg_error('', 803); } } else { $log = null; $flood_count = 0; $_SESSION['FLOODING'] = array(); } Security::flood_log($ipn, !empty($row), $delay, $time, $log, $flood_count); }
public function __construct() { global $db, $user_prefix, $prefix, $MAIN_CFG, $SESS; if ($this->user_id) { return false; } $cookiename = $MAIN_CFG['cookie']['member']; # MySQL has an SQL99 ISO incompatibility because it rtrim()s # one specific binary data char (\x00 or \x20 version depended) # Due to that we must pad our string with another character. $visitor_ip = $db->binary_safe(NET::get_ip()); # Load Member cookie $m_cookie = isset($_COOKIE[$cookiename]) ? $_COOKIE[$cookiename] : false; # Member Logout if ($m_cookie && !defined('ADMIN_PAGES') && isset($_GET['op']) && $_GET['op'] == 'logout') { global $CPG_SESS; unset($CPG_SESS['session_start']); # re-initialize session $_SESSION['CPG_USER'] = false; $m_cookie = explode(':', base64_decode($m_cookie)); $db->sql_query('DELETE FROM ' . $prefix . "_session WHERE host_addr={$visitor_ip} AND guest<>1"); $db->sql_query('UPDATE ' . $user_prefix . '_users SET user_session_time=' . time() . ' WHERE user_id=' . intval($m_cookie[0])); $this->setmemcookie(); $m_cookie = false; } elseif (!$m_cookie && isset($_POST['ulogin'])) { $m_cookie = $this->loginmember($visitor_ip); } $uid = 1; $pwd = ''; if ($m_cookie) { $m_cookie = explode(':', base64_decode($m_cookie)); $uid = intval($m_cookie[0]); $pwd = $m_cookie[2]; } $uid = $uid > 1 ? $uid : 1; # If the current session already has the Member details # load them else query the database if (isset($_SESSION['CPG_USER']) && is_array($_SESSION['CPG_USER']) && $_SESSION['CPG_USER']['user_id'] == $uid && $_SESSION['CPG_USER']['user_password'] == $pwd) { $member = $_SESSION['CPG_USER']; } else { $result = $db->sql_query('SELECT * FROM ' . $user_prefix . '_users WHERE user_id=' . $uid); if ($db->sql_numrows($result) < 1) { $this->setmemcookie(); $db->sql_freeresult($result); $result = $db->sql_query('SELECT * FROM ' . $user_prefix . '_users WHERE user_id=1'); } $member = $db->sql_fetchrow($result, SQL_ASSOC); $db->sql_freeresult($result); if ($member['user_id'] > 1 && ($member['user_password'] != $pwd || $member['user_password'] == '' || intval($member['user_level']) < 1)) { $this->setmemcookie(); $member = $db->sql_ufetchrow('SELECT * FROM ' . $user_prefix . '_users WHERE user_id=1', SQL_ASSOC); $db->sql_freeresult($result); } } $this->user_id = $member['user_id']; if ($this->user_id > 1) { // if ($this->user_id > 1 && !isset($member['_mem_of_groups'])) { $member['_mem_of_groups'] = array(); $result = $db->sql_uquery('SELECT g.group_id, g.group_name, g.group_single_user FROM ' . $prefix . '_bbgroups AS g INNER JOIN ' . $prefix . '_bbuser_group AS ug ON (ug.group_id=g.group_id AND ug.user_id=' . $this->user_id . ' AND ug.user_pending=0)'); while (list($g_id, $g_name, $single) = $db->sql_fetchrow($result, SQL_NUM)) { $member['_mem_of_groups'][$g_id] = $single ? '' : $g_name; } } else { $member['user_dst'] = $member['user_timezone'] = 0; } $member['user_ip'] = $visitor_ip; $_SESSION['CPG_USER'] = $member; $this->members[$this->user_id] =& $_SESSION['CPG_USER']; // $this->members[$this->user_id] = $member; $this->admin_id = false; }
function testConnection($type, $server, $user, $passwd, $port = 'none', $dbName = "") { if ($port == 'none' || $port == '' || $port == 0) { //setting defaults ports switch ($type) { case 'mysql': $port = 3306; break; case 'pgsql': $port = 5432; break; case 'mssql': $port = 1433; break; case 'oracle': $port = 1521; break; } } G::LoadClass('net'); $Server = new NET($server); if ($Server->getErrno() == 0) { $Server->scannPort($port); if ($Server->getErrno() == 0) { $Server->loginDbServer($user, $passwd); $Server->setDataBase($dbName, $port); if ($Server->errno == 0) { $response = $Server->tryConnectServer($type); if ($response->status == 'SUCCESS') { if ($Server->errno == 0) { $message = ""; $response = $Server->tryConnectServer($type); $connDatabase = @mysql_connect($server, $user, $passwd); $dbNameTest = "PROCESSMAKERTESTDC"; $db = @mysql_query("CREATE DATABASE " . $dbNameTest, $connDatabase); $success = false; if (!$db) { $message = mysql_error(); } else { $usrTest = "wfrbtest"; $chkG = "GRANT ALL PRIVILEGES ON `" . $dbNameTest . "`.* TO " . $usrTest . "@'%' IDENTIFIED BY 'sample' WITH GRANT OPTION"; $ch = @mysql_query($chkG, $connDatabase); if (!$ch) { $message = mysql_error(); } else { $sqlCreateUser = "******" . $user . "_usertest'@'%' IDENTIFIED BY 'sample'"; $result = @mysql_query($sqlCreateUser, $connDatabase); if (!$result) { $message = mysql_error(); } else { $success = true; $message = G::LoadTranslation('ID_SUCCESSFUL_CONNECTION'); } $sqlDropUser = "******" . $user . "_usertest'@'%'"; @mysql_query($sqlDropUser, $connDatabase); @mysql_query("DROP USER " . $usrTest . "@'%'", $connDatabase); } @mysql_query("DROP DATABASE " . $dbNameTest, $connDatabase); } return array($success, $message != "" ? $message : $Server->error); } else { return array(false, $Server->error); } } else { return array(false, $Server->error); } } else { return array(false, $Server->error); } } else { return array(false, $Server->error); } } else { return array(false, $Server->error); } }
} $content .= "{$i}: " . $session['uname'] . " > <a href=\"{$session['url']}\"> {$session['module']}</a><br />\n"; } unset($online[3]); } $online_num = count($online[1]); if ($online_num > 0) { $content .= '<img src="images/blocks/visitors.gif" alt="" /> <span class="content"><b>' . _BVIS . ':</b></span><br />'; for ($i = 1; $i <= $online_num; $i++) { $session = $online[1][$i - 1]; if ($i < 10 && $online_num > 99) { $content .= '00'; } else { if ($i < 10 && $online_num > 9 || $i < 99 && $online_num > 99) { $content .= '0'; } } /* or use: Asian Pacific http://apnic.net/apnic-bin/whois.pl?searchtext= Europe http://ripe.net/whois?searchtext= Latin America http://lacnic.net/cgi-bin/lacnic/whois?query= Brazil https://registro.br/cgi-bin/nicbr/whois?qr= Korea http://whois.nida.or.kr/whois/webapisvc?VALUE= */ $content .= "{$i}: " . (is_admin() ? '<a href="http://ws.arin.net/cgi-bin/whois.pl?queryinput=' . NET::decode_ip($session['host_addr']) . '" target="_blank" title="Query ARIN Whois">' . (strlen(NET::decode_ip($session['host_addr'])) > 17 ? substr(NET::decode_ip($session['host_addr']), 0, 17) . '...' : NET::decode_ip($session['host_addr'])) . '</a> >' : '') . " <a href=\"{$session['url']}\"> {$session['module']}</a><br />\n"; } unset($online[1]); } if ($hidden > 0) { $content .= '<span class="content"><b>' . _BHID . ':</b></span> ' . $hidden; }
function getDBVersion() { $sMySQLVersion = '?????'; if (defined("DB_HOST")) { G::LoadClass('net'); G::LoadClass('dbConnections'); $dbNetView = new NET(DB_HOST); $dbNetView->loginDbServer(DB_USER, DB_PASS); $dbConns = new dbConnections(''); $availdb = ''; foreach ($dbConns->getDbServicesAvailables() as $key => $val) { if ($availdb != '') { $availdb .= ', '; } $availdb .= $val['name']; } try { $sMySQLVersion = $dbNetView->getDbServerVersion('mysql'); } catch (Exception $oException) { $sMySQLVersion = '?????'; } } return $sMySQLVersion; }
/** * Test connection by step * * @param array $arrayData Data * @param int $step Step * * return array Return array with result of test connection by step */ public function testConnectionByStep(array $arrayData, $step = 0) { try { \G::LoadClass("net"); \G::LoadThirdParty("phpmailer", "class.smtp"); //MAIL if ($arrayData["MESS_ENGINE"] == "MAIL") { $arrayDataMail = array(); $eregMail = "/^[0-9a-zA-Z]+(?:[._][0-9a-zA-Z]+)*@[0-9a-zA-Z]+(?:[._-][0-9a-zA-Z]+)*\\.[0-9a-zA-Z]{2,3}\$/"; $arrayDataMail["FROM_EMAIL"] = $arrayData["MESS_FROM_MAIL"] != "" && preg_match($eregMail, $arrayData["MESS_FROM_MAIL"]) ? $arrayData["MESS_FROM_MAIL"] : ""; $arrayDataMail["FROM_NAME"] = $arrayData["MESS_FROM_NAME"] != "" ? $arrayData["MESS_FROM_NAME"] : \G::LoadTranslation("ID_MESS_TEST_BODY"); $arrayDataMail["MESS_ENGINE"] = "MAIL"; $arrayDataMail["MESS_SERVER"] = "localhost"; $arrayDataMail["MESS_PORT"] = 25; $arrayDataMail["MESS_ACCOUNT"] = $arrayData["MAIL_TO"]; $arrayDataMail["MESS_PASSWORD"] = ""; $arrayDataMail["TO"] = $arrayData["MAIL_TO"]; $arrayDataMail["MESS_RAUTH"] = true; $arrayTestMailResult = array(); try { $arrayTestMailResult = $this->sendTestMail($arrayDataMail); } catch (Exception $e) { $arrayTestMailResult["status"] = false; $arrayTestMailResult["message"] = $e->getMessage(); } $arrayResult = array("result" => $arrayTestMailResult["status"], "message" => ""); if ($arrayTestMailResult["status"] == false) { $arrayResult["message"] = \G::LoadTranslation("ID_SENDMAIL_NOT_INSTALLED"); } //Return return $arrayResult; } //PHPMAILER $server = $arrayData["MESS_SERVER"]; $user = $arrayData["MESS_ACCOUNT"]; $passwd = $arrayData["MESS_PASSWORD"]; $fromMail = $arrayData["MESS_FROM_MAIL"]; $passwdHide = $arrayData["MESS_PASSWORD"]; if (trim($passwdHide) != "") { $passwd = $passwdHide; $passwdHide = ""; } $passwdDec = \G::decrypt($passwd, "EMAILENCRYPT"); $auxPass = explode("hash:", $passwdDec); if (count($auxPass) > 1) { if (count($auxPass) == 2) { $passwd = $auxPass[1]; } else { array_shift($auxPass); $passwd = implode("", $auxPass); } } $arrayData["MESS_PASSWORD"] = $passwd; $port = (int) $arrayData["MESS_PORT"]; $auth_required = (int) $arrayData["MESS_RAUTH"]; $useSecureCon = $arrayData["SMTPSECURE"]; $sendTestMail = (int) $arrayData["MESS_TRY_SEND_INMEDIATLY"]; $mailTo = $arrayData["MAIL_TO"]; $smtpSecure = $arrayData["SMTPSECURE"]; $serverNet = new \NET($server); $smtp = new \SMTP(); $timeout = 10; $hostinfo = array(); $srv = $arrayData["MESS_SERVER"]; $arrayResult = array(); switch ($step) { case 1: $arrayResult["result"] = $serverNet->getErrno() == 0; $arrayResult["message"] = $serverNet->error; break; case 2: $serverNet->scannPort($port); $arrayResult["result"] = $serverNet->getErrno() == 0; $arrayResult["message"] = $serverNet->error; break; case 3: //Try to connect to host if (preg_match("/^(.+):([0-9]+)\$/", $srv, $hostinfo)) { $server = $hostinfo[1]; $port = $hostinfo[2]; } else { $host = $srv; } $tls = strtoupper($smtpSecure) == "tls"; $ssl = strtoupper($smtpSecure) == "ssl"; $arrayResult["result"] = $smtp->Connect(($ssl ? "ssl://" : "") . $server, $port, $timeout); $arrayResult["message"] = $serverNet->error; break; case 4: //Try login to host if ($auth_required == 1) { try { if (preg_match("/^(.+):([0-9]+)\$/", $srv, $hostinfo)) { $server = $hostinfo[1]; $port = $hostinfo[2]; } else { $server = $srv; } if (strtoupper($useSecureCon) == "TLS") { $tls = "tls"; } if (strtoupper($useSecureCon) == "SSL") { $tls = "ssl"; } $tls = strtoupper($useSecureCon) == "tls"; $ssl = strtoupper($useSecureCon) == "ssl"; $server = $arrayData["MESS_SERVER"]; if (strtoupper($useSecureCon) == "SSL") { $resp = $smtp->Connect("ssl://" . $server, $port, $timeout); } else { $resp = $smtp->Connect($server, $port, $timeout); } if ($resp) { $hello = $_SERVER["SERVER_NAME"]; $smtp->Hello($hello); if (strtoupper($useSecureCon) == "TLS") { $smtp->Hello($hello); } if ($smtp->Authenticate($user, $passwd)) { $arrayResult["result"] = true; } else { if (strtoupper($useSecureCon) == "TLS") { $arrayResult["result"] = true; } else { $arrayResult["result"] = false; $smtpError = $smtp->getError(); $arrayResult["message"] = $smtpError["error"]; } } } else { $arrayResult["result"] = false; $smtpError = $smtp->getError(); $arrayResult["message"] = $smtpError["error"]; } } catch (Exception $e) { $arrayResult["result"] = false; $arrayResult["message"] = $e->getMessage(); } } else { $arrayResult["result"] = true; $arrayResult["message"] = "No authentication required!"; } break; case 5: if ($sendTestMail == 1) { try { $arrayDataPhpMailer = array(); $eregMail = "/^[0-9a-zA-Z]+(?:[._][0-9a-zA-Z]+)*@[0-9a-zA-Z]+(?:[._-][0-9a-zA-Z]+)*\\.[0-9a-zA-Z]{2,3}\$/"; $arrayDataPhpMailer["FROM_EMAIL"] = $fromMail != "" && preg_match($eregMail, $fromMail) ? $fromMail : ""; $arrayDataPhpMailer["FROM_NAME"] = $arrayData["MESS_FROM_NAME"] != "" ? $arrayData["MESS_FROM_NAME"] : \G::LoadTranslation("ID_MESS_TEST_BODY"); $arrayDataPhpMailer["MESS_ENGINE"] = "PHPMAILER"; $arrayDataPhpMailer["MESS_SERVER"] = $server; $arrayDataPhpMailer["MESS_PORT"] = $port; $arrayDataPhpMailer["MESS_ACCOUNT"] = $user; $arrayDataPhpMailer["MESS_PASSWORD"] = $passwd; $arrayDataPhpMailer["TO"] = $mailTo; if ($auth_required == 1) { $arrayDataPhpMailer["MESS_RAUTH"] = true; } else { $arrayDataPhpMailer["MESS_RAUTH"] = false; } if (strtolower($arrayData["SMTPSECURE"]) != "no") { $arrayDataPhpMailer["SMTPSecure"] = $arrayData["SMTPSECURE"]; } $arrayTestMailResult = $this->sendTestMail($arrayDataPhpMailer); if ($arrayTestMailResult["status"] . "" == "1") { $arrayResult["result"] = true; } else { $arrayResult["result"] = false; $smtpError = $smtp->getError(); $arrayResult["message"] = $smtpError["error"]; } } catch (Exception $e) { $arrayResult["result"] = false; $arrayResult["message"] = $e->getMessage(); } } else { $arrayResult["result"] = true; $arrayResult["message"] = "Jump this step"; } break; } if (!isset($arrayResult["message"])) { $arrayResult["message"] = ""; } //Return return $arrayResult; } catch (\Exception $e) { $arrayResult = array(); $arrayResult["result"] = false; $arrayResult["message"] = $e->getMessage(); //Return return $arrayResult; } }
public static function broadcast($ip, $cidr) { if ($cidr > 32) { return false; } if ($ip = FILTER::ipv4($ip, true)) { return long2ip(NET::ip2long($ip, true) - (0xffffffff << 32 - $cidr) - 1); } return false; }
function get_infoOnPM($workspace) { $infoPM = array(); $Fields = getSysInfo(); $Fields['WORKSPACE_NAME'] = $workspace; if (defined("DB_HOST")) { G::LoadClass('net'); G::LoadClass('dbConnections'); $dbNetView = new NET(DB_HOST); $dbNetView->loginDbServer(DB_USER, DB_PASS); $dbConns = new dbConnections(''); $availdb = ''; foreach ($dbConns->getDbServicesAvailables() as $key => $val) { if ($availdb != '') { $availdb .= ', '; } $availdb .= $val['name']; } try { $sMySQLVersion = $dbNetView->getDbServerVersion('mysql'); } catch (Exception $oException) { $sMySQLVersion = 'Unknown'; } $Fields['DATABASE'] = $dbNetView->dbName(DB_ADAPTER) . ' (Version ' . $sMySQLVersion . ')'; $Fields['DATABASE_SERVER'] = DB_HOST; $Fields['DATABASE_NAME'] = DB_NAME; $Fields['AVAILABLE_DB'] = $availdb; } else { $Fields['DATABASE'] = "Not defined"; $Fields['DATABASE_SERVER'] = $info_db['adap']; $Fields['DATABASE_NAME'] = "Not defined"; $Fields['AVAILABLE_DB'] = "Not defined"; } $info_db = get_DirDB($workspace); $Fields['MYSQL_DATA_DIR'] = $info_db['datadir']; $Fields['PLUGINS_LIST'] = get_plugins(); $Fields['DB_ADAPTER'] = $info_db['DB_ADAPTER']; $Fields['DB_HOST'] = $info_db['DB_HOST']; $Fields['DB_NAME'] = $info_db['DB_NAME']; $Fields['DB_USER'] = $info_db['DB_USER']; $Fields['DB_PASS'] = $info_db['DB_PASS']; $Fields['DB_RBAC_HOST'] = $info_db['DB_RBAC_HOST']; $Fields['DB_RBAC_NAME'] = $info_db['DB_RBAC_NAME']; $Fields['DB_RBAC_USER'] = $info_db['DB_RBAC_USER']; $Fields['DB_RBAC_PASS'] = $info_db['DB_RBAC_PASS']; $Fields['DB_REPORT_HOST'] = $info_db['DB_REPORT_HOST']; $Fields['DB_REPORT_NAME'] = $info_db['DB_REPORT_NAME']; $Fields['DB_REPORT_USER'] = $info_db['DB_REPORT_USER']; $Fields['DB_REPORT_PASS'] = $info_db['DB_REPORT_PASS']; $infoPM = $Fields; return $infoPM; }
} else { $ip = getenv('REMOTE_ADDR'); } } $redhat = ''; if (file_exists('/etc/redhat-release')) { $fnewsize = filesize('/etc/redhat-release'); $fp = fopen('/etc/redhat-release', 'r'); $redhat = trim(fread($fp, $fnewsize)); fclose($fp); } $redhat .= " (" . PHP_OS . ")"; if (defined("DB_HOST")) { G::LoadClass('net'); G::LoadClass('dbConnections'); $dbNetView = new NET(DB_HOST); $dbNetView->loginDbServer(DB_USER, DB_PASS); $dbConns = new dbConnections(''); $availdb = ''; foreach ($dbConns->getDbServicesAvailables() as $key => $val) { if ($availdb != '') { $availdb .= ', '; } $availdb .= $val['name']; } try { $sMySQLVersion = $dbNetView->getDbServerVersion(DB_ADAPTER); } catch (Exception $oException) { $sMySQLVersion = '?????'; } }
//mac = substr($ip,-8) $ip = $db->binary_safe($ip); $db->sql_query('DELETE FROM ' . $prefix . "_security WHERE ban_ipn={$ip} AND ban_type=8"); } } } $db->optimize_table($prefix . '_security'); } else { $ip = $ip2 = false; if (!empty($_POST['ban_ipv4_s'])) { # y.y.y.y/cidr? if ($ip = NET::ipv4_cidr($_POST['ban_ipv4_s'])) { switch ($ip) { case is_array($ip): $network = NET::network($ip['ipv4'], $ip['cidr']); $broadcast = NET::broadcast($network, $ip['cidr']); $ip = inet_pton($network); $ip2 = inet_pton($broadcast); break; case -1: cpg_error(sprintf(_ERROR_BAD_FORMAT, 'IPv4')); break; case -2: cpg_error(sprintf(_ERROR_BAD_FORMAT, 'CIDR')); break; default: break; } } else { if (!FILTER::ipv4($_POST['ban_ipv4_s'], true)) { cpg_error(sprintf(_ERROR_BAD_FORMAT, 'IPv4 start'));
public static function doBody($url, $method, $body, $header) { global $LastBODYURL; global $LastBODYMethod; global $LastBODYImpl; global $LastHeadersSent; global $last_http_response; global $LastHeadersReceived; global $LastBODYResponse; $LastBODYURL = $url; $LastBODYMethod = $method; $LastBODYImpl = false; $LastHeadersSent = false; $last_http_response = false; $LastHeadersReceived = false; $LastBODYResponse = false; // Prefer curl because it checks if it works before trying $LastBODYResponse = NET::bodyCurl($url, $method, $body, $header); $LastBODYImpl = "CURL"; if ($LastBODYResponse !== false) { return $LastBODYResponse; } $LastBODYResponse = NET::bodySocket($url, $method, $body, $header); $LastBODYImpl = "Socket"; if ($LastBODYResponse !== false) { return $LastBODYResponse; } $LastBODYResponse = NET::bodyStream($url, $method, $body, $header); $LastBODYImpl = "Stream"; if ($LastBODYResponse !== false) { return $LastBODYResponse; } $LastBODYImpl = "Error"; error_log("Unable to {$method} Url={$url}"); error_log("Header: {$header}"); error_log("Body: {$body}"); throw new \Exception("Unable to {$method} {$url}"); }
if (count($auxPass) > 1) { if (count($auxPass) == 2) { $passwd = $auxPass[1]; } else { array_shift($auxPass); $passwd = implode('', $auxPass); } } $_POST['passwd'] = $passwd; $step = $_POST['step']; $auth_required = $_POST['auth_required']; $send_test_mail = $_POST['send_test_mail']; $mail_to = $_POST['mail_to']; $SMTPSecure = $_POST['SMTPSecure']; $timeout = 10; $Server = new NET($srv); $smtp = new SMTP(); switch ($step) { case 1: if ($Server->getErrno() == 0) { print SUCCESSFUL . ','; } else { print FAILED . ',' . $Server->error; } break; case 2: if ($port == 0) { $port = $smtp->SMTP_PORT; } $Server->scannPort($port); if ($Server->getErrno() == 0) {
function html_comments($pid) { global $CONFIG, $USER, $CURRENT_ALBUM_DATA, $username, $FAVPICS, $CURRENT_PIC_DATA, $THEME_DIR; global $template_image_comments, $template_add_your_comment, $db; $html = ''; if (!$CONFIG['enable_smilies']) { $tmpl_comment_edit_box = template_extract_block($template_image_comments, 'edit_box_no_smilies', '{EDIT}'); template_extract_block($template_image_comments, 'edit_box_smilies'); template_extract_block($template_add_your_comment, 'input_box_smilies'); } else { $tmpl_comment_edit_box = template_extract_block($template_image_comments, 'edit_box_smilies', '{EDIT}'); template_extract_block($template_image_comments, 'edit_box_no_smilies'); template_extract_block($template_add_your_comment, 'input_box_no_smilies'); } $tmpl_comments_buttons = template_extract_block($template_image_comments, 'buttons', '{BUTTONS}'); $tmpl_comments_ipinfo = template_extract_block($template_image_comments, 'ipinfo', '{IPINFO}'); $result = $db->sql_query("SELECT msg_id, msg_author, msg_body, msg_date, author_id, author_md5_id, msg_raw_ip, msg_hdr_ip FROM {$CONFIG['TABLE_COMMENTS']} WHERE pid='{$pid}' ORDER BY msg_id ASC", false, __FILE__, __LINE__); while ($row = $db->sql_fetchrow($result)) { $user_can_edit = GALLERY_ADMIN_MODE || USER_ID > 1 && USER_ID == $row['author_id'] && USER_CAN_POST_COMMENTS || USER_ID < 2 && USER_CAN_POST_COMMENTS && $USER['ID'] == $row['author_md5_id']; $comment_buttons = $user_can_edit ? $tmpl_comments_buttons : ''; $comment_edit_box = $user_can_edit ? $tmpl_comment_edit_box : ''; $comment_ipinfo = $row['msg_raw_ip'] && GALLERY_ADMIN_MODE ? $tmpl_comments_ipinfo : ''; if ($CONFIG['enable_smilies']) { $comment_body = set_smilies(make_clickable($row['msg_body'])); $smilies = smilies_table('onerow', 'msg_body', "f{$row['msg_id']}"); } else { $comment_body = make_clickable($row['msg_body']); $smilies = ''; } $params = array('{EDIT}' => &$comment_edit_box, '{BUTTONS}' => &$comment_buttons, '{IPINFO}' => &$comment_ipinfo); $template = template_eval($template_image_comments, $params); $info = ''; if (!in_array($pid, $FAVPICS)) { $info = '<a href="' . URL::index('&file=addfav&pid=' . $CURRENT_PIC_DATA['pid']) . '" >' . ADDFAV . '</a>'; } else { $info = '<a href="' . URL::index('&file=addfav&pid=' . $CURRENT_PIC_DATA['pid']) . '" >' . REMFAV . '</a>'; } $params = array('{MSG_AUTHOR}' => $row['msg_author'], '{MSG_ID}' => $row['msg_id'], '{MSG_TYPE}' => GALLERY_ADMIN_MODE ? 'text' : 'hidden', '{EDIT_TITLE}' => COM_EDIT_TITLE, '{CONFIRM_DELETE}' => CONFIRM_DELETE_COM, '{DELETE_LINK}' => URL::index("&file=delete"), '{DELETE_TEXT}' => DELETE . ' ' . COMMENT, '{MSG_DATE}' => localised_date($row['msg_date'], COMMENT_DATE_FMT), '{MSG_BODY}' => &$comment_body, '{MSG_BODY_RAW}' => $row['msg_body'], '{OK}' => OK, '{SMILIES}' => $smilies, '{HDR_IP}' => NET::decode_ip($row['msg_hdr_ip']), '{RAW_IP}' => NET::decode_ip($row['msg_raw_ip']), '{ACTION}' => 'action="' . URL::index('&file=db_input') . '" enctype="multipart/form-data" accept-charset="utf-8"', '{ADDFAVLINK}' => URL::index("&file=addfav&pid={$pid}"), '{ADDFAVTEXT}' => $info, '{THEMEDIR}' => $THEME_DIR); $html .= template_eval($template, $params); } if (USER_CAN_POST_COMMENTS && $CURRENT_ALBUM_DATA['comments']) { if (USER_ID > 1) { $username_input = '<input type="hidden" name="msg_author" value="' . CPG_USERNAME . '" />'; template_extract_block($template_add_your_comment, 'username_input', $username_input); // $username = ''; } else { $username = isset($USER['name']) ? '"' . htmlprepare($USER['name']) . '"' : '"' . YOUR_NAME . '" onclick="javascript:this.value=\'\';"'; } if (!in_array($pid, $FAVPICS)) { $info = '<a href="' . URL::index('&file=addfav&pid=' . $CURRENT_PIC_DATA['pid']) . '" >' . ADDFAV . '</a>'; } else { $info = '<a href="' . URL::index('&file=addfav&pid=' . $CURRENT_PIC_DATA['pid']) . '" >' . REMFAV . '</a>'; } $params = array('{ADD_YOUR_COMMENT}' => ADD_YOUR_COMMENT, '{NAME}' => COM_NAME, '{COMMENT}' => COMMENT, '{PIC_ID}' => $pid, '{username}' => $username, '{MAX_COM_LENGTH}' => $CONFIG['max_com_size'], '{OK}' => OK, '{SMILIES}' => '', '{ACTION}' => 'action="' . URL::index("&file=db_input") . '" enctype="multipart/form-data" accept-charset="utf-8"', '{ADDFAVLINK}' => URL::index("&file=addfav&pid={$pid}"), '{ADDFAVTEXT}' => $info); if ($CONFIG['enable_smilies']) { $params['{SMILIES}'] = smilies_table('onerow', 'message', 'post'); } // if ($CONFIG['enable_smilies']) $params['{SMILIES}'] = generate_smilies(); $html .= template_eval($template_add_your_comment, $params); } if (USER_ID > 1 or $CONFIG['allow_anon_fullsize'] or USER_IS_ADMIN) { return $html; } }
private function _getSystemInfo() { G::LoadClass("system"); if (getenv('HTTP_CLIENT_IP')) { $ip = getenv('HTTP_CLIENT_IP'); } else { if (getenv('HTTP_X_FORWARDED_FOR')) { $ip = getenv('HTTP_X_FORWARDED_FOR'); } else { $ip = getenv('REMOTE_ADDR'); } } $redhat = ''; if (file_exists('/etc/redhat-release')) { $fnewsize = filesize('/etc/redhat-release'); $fp = fopen('/etc/redhat-release', 'r'); $redhat = trim(fread($fp, $fnewsize)); fclose($fp); } $redhat .= " (" . PHP_OS . ")"; if (defined("DB_HOST")) { G::LoadClass('net'); G::LoadClass('dbConnections'); $dbNetView = new NET(DB_HOST); $dbNetView->loginDbServer(DB_USER, DB_PASS); $dbConns = new dbConnections(''); $availdb = ''; foreach ($dbConns->getDbServicesAvailables() as $key => $val) { if ($availdb != '') { $availdb .= ', '; } $availdb .= $val['name']; } try { $sMySQLVersion = $dbNetView->getDbServerVersion(DB_ADAPTER); } catch (Exception $oException) { $sMySQLVersion = '?????'; } } $sysSection = G::loadTranslation('ID_SYSTEM_INFO'); $pmSection = 'ProcessMaker Information'; $properties = array(); $ee = class_exists('pmLicenseManager') ? " - Enterprise Edition" : ''; $properties[] = array('ProcessMaker Ver.', System::getVersion() . $ee, $pmSection); $properties[] = array('Operating System', $redhat, $sysSection); $properties[] = array('Time Zone', defined('TIME_ZONE') ? TIME_ZONE : "Unknown", $sysSection); $properties[] = array('Web Server', getenv('SERVER_SOFTWARE'), $sysSection); $properties[] = array('Server Name', getenv('SERVER_NAME'), $pmSection); $properties[] = array('Server IP Address', $this->lookup($ip), $sysSection); $properties[] = array('PHP Version', phpversion(), $sysSection); if (defined("DB_HOST")) { $properties[] = array('Data Base', $dbNetView->dbName(DB_ADAPTER) . ' (Version ' . $sMySQLVersion . ')', $pmSection); $properties[] = array('Data Base Server', DB_HOST, $pmSection); $properties[] = array('Data Base Name', DB_NAME, $pmSection); $properties[] = array('Available DB Engines', $availdb, $sysSection); } else { $properties[] = array('Data Base', "Not defined", $pmSection); $properties[] = array('Data Base Server', "Not defined", $pmSection); $properties[] = array('Data Base Name', "Not defined", $pmSection); $properties[] = array('Available DB Engines', "Not defined", $sysSection); } $properties[] = array('Workspace', defined("SYS_SYS") ? SYS_SYS : "Not defined", $pmSection); $properties[] = array('Server Protocol', getenv('SERVER_PROTOCOL'), $sysSection); $properties[] = array('Server Port', getenv('SERVER_PORT'), $sysSection); //$properties[] = array('Remote Host', getenv ('REMOTE_HOST'), $sysSection); $properties[] = array('Server Addr.', getenv('SERVER_ADDR'), $sysSection); $properties[] = array('User\'s Browser', getenv('HTTP_USER_AGENT'), $sysSection); return $properties; }
/** * Get metadata from this workspace * * @param string $path the directory where to create the sql files * @return array information about this workspace */ public function getMetadata() { $Fields = array_merge(System::getSysInfo(), $this->getDBInfo()); $Fields['WORKSPACE_NAME'] = $this->name; if (isset($this->dbHost)) { //TODO: This code stopped working with the refactoring //require_once ("propel/Propel.php"); //G::LoadClass('dbConnections'); //$dbConns = new dbConnections(''); //$availdb = ''; //foreach( $dbConns->getDbServicesAvailables() as $key => $val ) { //if(!empty($availdb)) // $availdb .= ', '; // $availdb .= $val['name']; //} G::LoadClass('net'); $dbNetView = new NET($this->dbHost); $dbNetView->loginDbServer($this->dbUser, $this->dbPass); try { $sMySQLVersion = $dbNetView->getDbServerVersion('mysql'); } catch (Exception $oException) { $sMySQLVersion = 'Unknown'; } $Fields['DATABASE'] = $dbNetView->dbName($this->dbAdapter) . ' (Version ' . $sMySQLVersion . ')'; $Fields['DATABASE_SERVER'] = $this->dbHost; $Fields['DATABASE_NAME'] = $this->dbName; $Fields['AVAILABLE_DB'] = "Not defined"; //$Fields['AVAILABLE_DB'] = $availdb; } else { $Fields['DATABASE'] = "Not defined"; $Fields['DATABASE_SERVER'] = "Not defined"; $Fields['DATABASE_NAME'] = "Not defined"; $Fields['AVAILABLE_DB'] = "Not defined"; } return $Fields; }
private function _getSystemInfo() { G::LoadClass("system"); if (getenv('HTTP_CLIENT_IP')) { $ip = getenv('HTTP_CLIENT_IP'); } else { if (getenv('HTTP_X_FORWARDED_FOR')) { $ip = getenv('HTTP_X_FORWARDED_FOR'); } else { $ip = getenv('REMOTE_ADDR'); } } $redhat = ''; if (file_exists('/etc/redhat-release')) { $fnewsize = filesize('/etc/redhat-release'); $fp = fopen('/etc/redhat-release', 'r'); $redhat = trim(fread($fp, $fnewsize)); fclose($fp); } $redhat .= " (" . PHP_OS . ")"; if (defined("DB_HOST")) { G::LoadClass('net'); G::LoadClass('dbConnections'); $dbNetView = new NET(DB_HOST); $dbNetView->loginDbServer(DB_USER, DB_PASS); $dbConns = new dbConnections(''); $availdb = ''; foreach ($dbConns->getDbServicesAvailables() as $key => $val) { if ($availdb != '') { $availdb .= ', '; } $availdb .= $val['name']; } try { $sMySQLVersion = $dbNetView->getDbServerVersion(DB_ADAPTER); } catch (Exception $oException) { $sMySQLVersion = '?????'; } } if (file_exists(PATH_HTML . "lib/versions")) { $versions = json_decode(file_get_contents(PATH_HTML . "lib/versions"), true); $pmuiVer = $versions["pmui_ver"]; $mafeVer = $versions["mafe_ver"]; $pmdynaformVer = $versions["pmdynaform_ver"]; } else { $pmuiVer = $mafeVer = $pmdynaformVer = "(unknown)"; } $sysSection = G::loadTranslation('ID_SYSTEM_INFO'); $pmSection = G::LoadTranslation('ID_PROCESS_INFORMATION'); $properties = array(); $ee = class_exists('pmLicenseManager') ? " - Enterprise Edition" : ''; $systemName = 'ProcessMaker'; if (defined('SYSTEM_NAME')) { $systemName = SYSTEM_NAME; } $properties[] = array($systemName . ' Ver.', System::getVersion() . $ee, $pmSection); $properties[] = array("PMUI JS Lib. Ver.", $pmuiVer, $pmSection); $properties[] = array("MAFE JS Lib. Ver.", $mafeVer, $pmSection); $properties[] = array("PM Dynaform JS Lib. Ver.", $pmdynaformVer, $pmSection); if (file_exists(PATH_DATA . 'log/upgrades.log')) { $properties[] = array(G::LoadTranslation('ID_UPGRADES_PATCHES'), '<a href="#" onclick="showUpgradedLogs(); return false;">' . G::LoadTranslation('ID_UPGRADE_VIEW_LOG') . '</a>', $pmSection); } else { $properties[] = array(G::LoadTranslation('ID_UPGRADES_PATCHES'), G::LoadTranslation('ID_UPGRADE_NEVER_UPGRADE'), $pmSection); } $properties[] = array(G::LoadTranslation('ID_OPERATING_SYSTEM'), $redhat, $sysSection); $properties[] = array(G::LoadTranslation('ID_TIME_ZONE'), defined('TIME_ZONE') ? TIME_ZONE : "Unknown", $sysSection); $properties[] = array(G::LoadTranslation('ID_WEB_SERVER'), getenv('SERVER_SOFTWARE'), $sysSection); $properties[] = array(G::LoadTranslation('ID_SERVER_NAME'), getenv('SERVER_NAME'), $pmSection); $properties[] = array(G::LoadTranslation('ID_SERVER_IP'), $this->lookup($ip), $sysSection); $properties[] = array(G::LoadTranslation('ID_PHP_VERSION'), phpversion(), $sysSection); if (defined("DB_HOST")) { $properties[] = array(G::LoadTranslation('ID_DATABASE'), $dbNetView->dbName(DB_ADAPTER) . ' (Version ' . $sMySQLVersion . ')', $pmSection); $properties[] = array(G::LoadTranslation('ID_DATABASE_SERVER'), DB_HOST, $pmSection); $properties[] = array(G::LoadTranslation('ID_DATABASE_NAME'), DB_NAME, $pmSection); $properties[] = array(G::LoadTranslation('ID_AVAILABLE_DB'), $availdb, $sysSection); } else { $properties[] = array(G::LoadTranslation('ID_DATABASE'), "Not defined", $pmSection); $properties[] = array(G::LoadTranslation('ID_DATABASE_SERVER'), "Not defined", $pmSection); $properties[] = array(G::LoadTranslation('ID_DATABASE_NAME'), "Not defined", $pmSection); $properties[] = array(G::LoadTranslation('ID_AVAILABLE_DB'), "Not defined", $sysSection); } $properties[] = array(G::LoadTranslation('ID_WORKSPACE'), defined("SYS_SYS") ? SYS_SYS : "Not defined", $pmSection); $properties[] = array(G::LoadTranslation('ID_SERVER_PROTOCOL'), getenv('SERVER_PROTOCOL'), $sysSection); $properties[] = array(G::LoadTranslation('ID_SERVER_PORT'), getenv('SERVER_PORT'), $sysSection); //$sysSection[] = array('Remote Host', getenv ('REMOTE_HOST'), $sysSection); $properties[] = array(G::LoadTranslation('ID_SERVER_NAME'), getenv('SERVER_ADDR'), $sysSection); $properties[] = array(G::LoadTranslation('ID_USER_BROWSER'), getenv('HTTP_USER_AGENT'), $sysSection); return $properties; }
} } else { echo FAILED . "," . $Server->error; } } else { echo FAILED . "," . $Server->error; } break; default: echo "finished"; break; } } else { $connectionType = $_POST["connectionType"]; $tns = $_POST["tns"]; $net = new NET(); switch ($step) { case 1: $net->loginDbServer($user, $passwd); if ($net->errno == 0) { $arrayServerData = array("connectionType" => $connectionType, "tns" => $tns); $response = $net->tryConnectServer($type, $arrayServerData); if ($response->status == "SUCCESS") { $response = $net->tryOpenDataBase($type, $arrayServerData); if ($response->status == "SUCCESS") { echo SUCCESSFULL . "," . $net->error; } else { echo FAILED . "," . $net->error; } } else { echo FAILED . "," . $net->error;
/** * Test DataBase Connection * @var string $dataCon. Data for DataBase Connection * @var string $returnArray. Flag for url * * @author Brayan Pereyra (Cochalo) <*****@*****.**> * @copyright Colosa - Bolivia * * @return void */ public function testConnection($dataCon, $returnArray = false) { $resp = array(); $respTest = array(); $resp['resp'] = false; $dataCon = array_change_key_case($dataCon, CASE_UPPER); $flagTns = ($dataCon["DBS_TYPE"] == "oracle" && $dataCon["DBS_CONNECTION_TYPE"] == "TNS")? 1 : 0; G::LoadClass( 'net' ); if ($flagTns == 0) { $Server = new \NET($dataCon['DBS_SERVER']); // STEP 1 : Resolving Host Name $respTest['0'] = array(); $respTest['0']['test'] = 'Resolving Host Name ' . $dataCon['DBS_SERVER']; if ($Server->getErrno() != 0) { if ($returnArray) { $respTest['0']['error'] = "Error Testing Connection: Resolving Host Name FAILED : " . $Server->error; } else { $resp['message'] = "Error Testing Connection: Resolving Host Name FAILED : " . $Server->error; return $resp; } } // STEP 2 : Checking port $respTest['1'] = array(); $respTest['1']['test'] = 'Checking port ' . $dataCon['DBS_PORT']; $Server->scannPort($dataCon['DBS_PORT']); if ($Server->getErrno() != 0) { if ($returnArray) { $respTest['1']['error'] = "Error Testing Connection: Checking port FAILED : " . $Server->error; } else { $resp['message'] = "Error Testing Connection: Checking port FAILED : " . $Server->error; return $resp; } } // STEP 3 : Trying to connect to host $respTest['2'] = array(); $respTest['2']['test'] = 'Connecting to host ' . $dataCon['DBS_SERVER'] . (($dataCon['DBS_PORT'] != '') ? ':'.$dataCon['DBS_PORT'] : ''); $Server->loginDbServer($dataCon['DBS_USERNAME'], $dataCon['DBS_PASSWORD']); $Server->setDataBase($dataCon['DBS_DATABASE_NAME'], $dataCon['DBS_PORT']); if ($Server->errno == 0) { $response = $Server->tryConnectServer($dataCon['DBS_TYPE']); if ($response->status != 'SUCCESS') { if ($returnArray) { $respTest['2']['error'] = "Error Testing Connection: Connecting to host FAILED : " . $Server->error; } else { $resp['message'] = "Error Testing Connection: Connecting to host FAILED : " . $Server->error; return $resp; } } } else { if ($returnArray) { $respTest['2']['error'] = "Error Testing Connection: Connecting to host FAILED : " . $Server->error; } else { $resp['message'] = "Error Testing Connection: Connecting to host FAILED : " . $Server->error; return $resp; } } // STEP 4 : Trying to open database $respTest['3'] = array(); $respTest['3']['test'] = 'Opening database [' . $dataCon['DBS_DATABASE_NAME'] . ']'; $Server->loginDbServer($dataCon['DBS_USERNAME'], $dataCon['DBS_PASSWORD']); $Server->setDataBase($dataCon['DBS_DATABASE_NAME'], $dataCon['DBS_PORT']); if ($Server->errno == 0) { $response = $Server->tryConnectServer($dataCon['DBS_TYPE']); if ($response->status == 'SUCCESS') { $response = $Server->tryOpenDataBase($dataCon['DBS_TYPE']); if ($response->status != 'SUCCESS') { if ($returnArray) { $respTest['3']['error'] = "Error Testing Connection: Opening database FAILED : " . $Server->error; } else { $resp['message'] = "Error Testing Connection: Opening database FAILED : " . $Server->error; return $resp; } } } else { if ($returnArray) { $respTest['3']['error'] = "Error Testing Connection: Opening database FAILED : " . $Server->error; } else { $resp['message'] = "Error Testing Connection: Opening database FAILED : " . $Server->error; return $resp; } } } else { if ($returnArray) { $respTest['3']['error'] = "Error Testing Connection: Opening database FAILED : " . $Server->error; } else { $resp['message'] = "Error Testing Connection: Opening database FAILED : " . $Server->error; return $resp; } } } else { $net = new \NET(); //STEP 0: Trying to open database type TNS $respTest["0"] = array(); $respTest["0"]["test"] = "Test TNS: " . $dataCon["DBS_TNS"]; $net->loginDbServer($dataCon["DBS_USERNAME"], $dataCon["DBS_PASSWORD"]); if ($net->errno == 0) { $arrayServerData = array("connectionType" => $dataCon["DBS_CONNECTION_TYPE"], "tns" => $dataCon["DBS_TNS"]); $response = $net->tryConnectServer($dataCon["DBS_TYPE"], $arrayServerData); if ($response->status == "SUCCESS") { $response = $net->tryOpenDataBase($dataCon["DBS_TYPE"], $arrayServerData); if ($response->status != "SUCCESS") { if ($returnArray) { $respTest["0"]["error"] = "Error Testing Connection: Opening database type TNS FAILED, " . $net->error; } else { $resp["message"] = "Error Testing Connection: Opening database type TNS FAILED, " . $net->error; //Return return $resp; } } } else { if ($returnArray) { $respTest["0"]["error"] = "Error Testing Connection: Opening database type TNS FAILED, " . $net->error; } else { $resp["message"] = "Error Testing Connection: Opening database type TNS FAILED, " . $net->error; //Return return $resp; } } } else { if ($returnArray) { $respTest["0"]["error"] = "Error Testing Connection: Opening database type TNS FAILED, " . $net->error; } else { $resp["message"] = "Error Testing Connection: Opening database type TNS FAILED, " . $net->error; //Return return $resp; } } } if ($returnArray) { return $respTest; } else { // CORRECT CONNECTION $resp['resp'] = true; return $resp; } }
case 'mysql': $port = 3306; break; case 'pgsql': $port = 5432; break; case 'mssql': $port = 1433; break; case 'oracle': $port = 1521; break; } } G::LoadClass('net'); $Server = new NET($server); define("SUCCESSFULL", 'SUCCESSFULL'); define("FAILED", 'FAILED'); switch ($step) { case 1: if ($Server->getErrno() == 0) { print SUCCESSFULL . ','; } else { print FAILED . ',' . $Server->error; } break; case 2: $Server->scannPort($port); if ($Server->getErrno() == 0) { print SUCCESSFULL . ','; } else {
/** * Test DataBase Connection * @var string $dataCon. Data for DataBase Connection * @var string $returnArray. Flag for url * * @author Brayan Pereyra (Cochalo) <*****@*****.**> * @copyright Colosa - Bolivia * * @return void */ public function testConnection($dataCon, $returnArray = false) { $resp = array(); $respTest = array(); $resp['resp'] = false; $dataCon = array_change_key_case($dataCon, CASE_UPPER); G::LoadClass( 'net' ); $Server = new \NET($dataCon['DBS_SERVER']); // STEP 1 : Resolving Host Name $respTest['0'] = array(); $respTest['0']['test'] = 'Resolving Host Name ' . $dataCon['DBS_SERVER']; if ($Server->getErrno() != 0) { if ($returnArray) { $respTest['0']['error'] = "Error Testing Connection: Resolving Host Name FAILED : " . $Server->error; } else { $resp['message'] = "Error Testing Connection: Resolving Host Name FAILED : " . $Server->error; return $resp; } } // STEP 2 : Checking port $respTest['1'] = array(); $respTest['1']['test'] = 'Checking port ' . $dataCon['DBS_PORT']; $Server->scannPort($dataCon['DBS_PORT']); if ($Server->getErrno() != 0) { if ($returnArray) { $respTest['1']['error'] = "Error Testing Connection: Checking port FAILED : " . $Server->error; } else { $resp['message'] = "Error Testing Connection: Checking port FAILED : " . $Server->error; return $resp; } } // STEP 3 : Trying to connect to host $respTest['2'] = array(); $respTest['2']['test'] = 'Trying to connect to host ' . $dataCon['DBS_SERVER'] . (($dataCon['DBS_PORT'] != '') ? ':'.$dataCon['DBS_PORT'] : ''); $Server->loginDbServer($dataCon['DBS_USERNAME'], $dataCon['DBS_PASSWORD']); $Server->setDataBase($dataCon['DBS_DATABASE_NAME'], $dataCon['DBS_PORT']); if ($Server->errno == 0) { $response = $Server->tryConnectServer($dataCon['DBS_TYPE']); if ($response->status != 'SUCCESS') { if ($returnArray) { $respTest['2']['error'] = "Error Testing Connection: Trying to connect to host FAILED : " . $Server->error; } else { $resp['message'] = "Error Testing Connection: Trying to connect to host FAILED : " . $Server->error; return $resp; } } } else { if ($returnArray) { $respTest['2']['error'] = "Error Testing Connection: Trying to connect to host FAILED : " . $Server->error; } else { $resp['message'] = "Error Testing Connection: Trying to connect to host FAILED : " . $Server->error; return $resp; } } // STEP 4 : Trying to open database $respTest['3'] = array(); $respTest['3']['test'] = 'Trying to open database [' . $dataCon['DBS_DATABASE_NAME'] . ']'; $Server->loginDbServer($dataCon['DBS_USERNAME'], $dataCon['DBS_PASSWORD']); $Server->setDataBase($dataCon['DBS_DATABASE_NAME'], $dataCon['DBS_PORT']); if ($Server->errno == 0) { $response = $Server->tryConnectServer($dataCon['DBS_TYPE']); if ($response->status == 'SUCCESS') { $response = $Server->tryOpenDataBase($dataCon['DBS_TYPE']); if ($response->status != 'SUCCESS') { if ($returnArray) { $respTest['3']['error'] = "Error Testing Connection: Trying to open database FAILED : " . $Server->error; } else { $resp['message'] = "Error Testing Connection: Trying to open database FAILED : " . $Server->error; return $resp; } } } else { if ($returnArray) { $respTest['3']['error'] = "Error Testing Connection: Trying to open database FAILED : " . $Server->error; } else { $resp['message'] = "Error Testing Connection: Trying to open database FAILED : " . $Server->error; return $resp; } } } else { if ($returnArray) { $respTest['3']['error'] = "Error Testing Connection: Trying to open database FAILED : " . $Server->error; } else { $resp['message'] = "Error Testing Connection: Trying to open database FAILED : " . $Server->error; return $resp; } } if ($returnArray) { return $respTest; } else { // CORRECT CONNECTION $resp['resp'] = true; return $resp; } }