From: Roland Häder <roland@mxchange.org>
Date: Sat, 3 Nov 2012 22:15:03 +0000 (+0000)
Subject: Addded more fields to server_name_log table, fixed out-dated ext-admins
X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=6a5589c1a7793b19dbce958053d6fea41eaee533;p=mailer.git

Addded more fields to server_name_log table, fixed out-dated ext-admins
---

diff --git a/inc/extensions/ext-sql_patches.php b/inc/extensions/ext-sql_patches.php
index 72fa99753d..12fe7602de 100644
--- a/inc/extensions/ext-sql_patches.php
+++ b/inc/extensions/ext-sql_patches.php
@@ -940,12 +940,26 @@ INDEX (`history_last_used` DESC)",
 `server_name_id` BIGINT (20) NOT NULL AUTO_INCREMENT,
 `server_name` VARCHAR (255) NOT NULL DEFAULT 'invalid',
 `server_name_added` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
+`server_name_remote_addr` VARCHAR (15) NOT NULL DEFAULT '0.0.0.0',
+`server_name_ua` TINYTEXT NULL DEFAULT NULL,
+`server_name_referrer` TINYTEXT NULL DEFAULT NULL,
+`server_name_counter` BIGINT (20) NOT NULL DEFAULT 0,
 PRIMARY KEY (`server_name_id`)
 ", 'Logging of wrong SERVER_NAME');
 
 				// Update notes (these will be set as task text!)
 				setExtensionUpdateNotes("Loggen von falschen <strong>SERVER_NAME</strong> Eintr&auml;gen hinzugef&uuml;gt.");
 				break;
+
+			case '0.9.2': // SQL queries for v0.9.2
+				addExtensionAddTableColumnSql('server_name_log', 'server_name_remote_addr', "VARCHAR (15) NOT NULL DEFAULT '0.0.0.0'");
+				addExtensionAddTableColumnSql('server_name_log', 'server_name_counter', 'BIGINT (20) NOT NULL DEFAULT 0');
+				addExtensionAddTableColumnSql('server_name_log', 'server_name_ua', 'TINYTEXT NULL DEFAULT NULL');
+				addExtensionAddTableColumnSql('server_name_log', 'server_name_referrer', 'TINYTEXT NULL DEFAULT NULL');
+
+				// Update notes (these will be set as task text!)
+				setExtensionUpdateNotes("Sorry, hatte noch IP-Nummer, User-Agent, aufrufende Seite und Z&auml;hler vergessen.");
+				break;
 		} // END - switch
 		break;
 
diff --git a/inc/http-functions.php b/inc/http-functions.php
index 317ba55e83..4085f73176 100644
--- a/inc/http-functions.php
+++ b/inc/http-functions.php
@@ -859,11 +859,37 @@ function getContentType () {
 
 // Logs wrong SERVER_NAME attempts
 function logWrongServerNameRedirect () {
-	// Is ext-sql_patches at least version 0.9.1?
-	if (isExtensionInstalledAndNewer('sql_patches', '0.9.1')) {
-		// Then log it away
-		SQL_QUERY("INSERT INTO `{?_MYSQL_PREFIX?}_server_name_log` (`server_name`) VALUES('{%pipe,detectServerName%}')",
-			__FUNCTION__, __LINE__);
+	// Is ext-sql_patches at least version 0.9.2?
+	if (isExtensionInstalledAndNewer('sql_patches', '0.9.2')) {
+		// Is there an entry?
+		if (countSumTotalData(detectServerName(), 'server_name_log', 'server_name_id', 'server_name', TRUE, sprintf(" AND `server_name_remote_addr`='%s' AND `server_name_ua`='%s' AND `server_name_referrer`='%s'", SQL_ESCAPE(detectRemoteAddr(TRUE)), SQL_ESCAPE(detectUserAgent(TRUE)), SQL_ESCAPE(detectReferer(TRUE)))) == 1) {
+			// Update counter, as all are the same
+			SQL_QUERY_ESC("UPDATE
+	`{?_MYSQL_PREFIX?}_server_name_log`
+SET
+	`server_name_counter`=`server_name_counter`+1
+WHERE
+	`server_name`='%s' AND
+	`server_name_remote_addr`='%s' AND
+	`server_name_ua`='%s' AND
+	`server_name_referrer`='%s'
+LIMIT 1",
+				array(
+					detectServerName(),
+					detectRemoteAddr(TRUE),
+					detectUserAgent(TRUE),
+					detectReferer(TRUE)
+				), __FUNCTION__, __LINE__);
+		} else {
+			// Then log it away
+			SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_server_name_log` (`server_name`, `server_name_remote_addr`, `server_name_ua`, `server_name_referral`) VALUES('%s','%s', '%s', '%s')",
+				array(
+					detectServerName(),
+					detectRemoteAddr(TRUE),
+					detectUserAgent(TRUE),
+					detectReferer(TRUE)
+				), __FUNCTION__, __LINE__);
+		}
 	} // END - if
 }
 
diff --git a/inc/libs/admins_functions.php b/inc/libs/admins_functions.php
index 955748eb9a..31cfefdd20 100644
--- a/inc/libs/admins_functions.php
+++ b/inc/libs/admins_functions.php
@@ -513,9 +513,12 @@ function sendAdminsEmails ($subject, $template, $content, $userid) {
 
 	// No entries found?
 	if (SQL_HASZERONUMS($result)) {
-		// Create new entry (to all admins)
-		SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_admins_mails` (`admin_id`, `mail_template`) VALUES (NULL, '%s')",
-			array($template), __FUNCTION__, __LINE__);
+		// Is ext-admins' version at least 0.7.9?
+		if (isExtensionInstalledAndNewer('admins', '0.7.9')) {
+			// Create new entry (to all admins)
+			SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_admins_mails` (`admin_id`, `mail_template`) VALUES (NULL, '%s')",
+				array($template), __FUNCTION__, __LINE__);
+		} // END - if
 
 		// Select all email adresses (default)
 		$result = SQL_QUERY('SELECT `email` FROM `{?_MYSQL_PREFIX?}_admins` ORDER BY `id` ASC',
@@ -551,6 +554,9 @@ function sendAdminsEmails ($subject, $template, $content, $userid) {
 					$userid
 				));
 			}
+
+			// Abort here as below while() loop will cause problems
+			return;
 		} elseif (($adminId == '0') || (empty($adminId))) {
 			// Select all email adresses
 			$result = SQL_QUERY('SELECT `email` FROM `{?_MYSQL_PREFIX?}_admins` ORDER BY `id` ASC',
diff --git a/inc/wrapper-functions.php b/inc/wrapper-functions.php
index e0244d0af4..ce8ad10999 100644
--- a/inc/wrapper-functions.php
+++ b/inc/wrapper-functions.php
@@ -214,12 +214,12 @@ function isDirectory ($FQFN) {
 }
 
 // "Getter" for the real remote IP number
-function detectRealIpAddress () {
+function detectRealIpAddress ($alwaysReal = FALSE) {
 	// Get remote ip from environment
 	$remoteAddr = determineRealRemoteAddress();
 
 	// Is removeip installed?
-	if (isExtensionActive('removeip')) {
+	if ((isExtensionActive('removeip')) && ($alwaysReal === FALSE)) {
 		// Then anonymize it
 		$remoteAddr = getAnonymousRemoteAddress($remoteAddr);
 	} // END - if
@@ -229,12 +229,12 @@ function detectRealIpAddress () {
 }
 
 // "Getter" for remote IP number
-function detectRemoteAddr () {
+function detectRemoteAddr ($alwaysReal = FALSE) {
 	// Get remote ip from environment
 	$remoteAddr = determineRealRemoteAddress(TRUE);
 
 	// Is removeip installed?
-	if (isExtensionActive('removeip')) {
+	if ((isExtensionActive('removeip')) && ($alwaysReal === FALSE)) {
 		// Then anonymize it
 		$remoteAddr = getAnonymousRemoteAddress($remoteAddr);
 	} // END - if
@@ -244,12 +244,12 @@ function detectRemoteAddr () {
 }
 
 // "Getter" for remote hostname
-function detectRemoteHostname () {
+function detectRemoteHostname ($alwaysReal = FALSE) {
 	// Get remote ip from environment
 	$remoteHost = getenv('REMOTE_HOST');
 
 	// Is removeip installed?
-	if (isExtensionActive('removeip')) {
+	if ((isExtensionActive('removeip')) && ($alwaysReal === FALSE)) {
 		// Then anonymize it
 		$remoteHost = getAnonymousRemoteHost($remoteHost);
 	} // END - if
@@ -274,12 +274,12 @@ function detectUserAgent ($alwaysReal = FALSE) {
 }
 
 // "Getter" for referer
-function detectReferer () {
+function detectReferer ($alwaysReal = FALSE) {
 	// Get remote ip from environment
 	$referer = getenv('HTTP_REFERER');
 
 	// Is removeip installed?
-	if (isExtensionActive('removeip')) {
+	if ((isExtensionActive('removeip')) && ($alwaysReal === TRUE)) {
 		// Then anonymize it
 		$referer = getAnonymousReferer($referer);
 	} // END - if