Browse Source

Some additional beautification

tags/3.5.1
Michael Vogel 2 years ago
parent
commit
6fd54df940
1 changed files with 55 additions and 51 deletions
  1. 55
    51
      include/auth_ejabberd.php

+ 55
- 51
include/auth_ejabberd.php View File

@@ -152,29 +152,31 @@ class exAuth {
152 152
 		if (!isset($aCommand[1])) {
153 153
 			$this->writeLog("[exAuth] invalid isuser command, no username given");
154 154
 			fwrite(STDOUT, pack("nn", 2, 0));
155
+			return;
156
+		}
157
+
158
+		// Now we check if the given user is valid
159
+		$sUser = str_replace(array("%20", "(a)"), array(" ", "@"), $aCommand[1]);
160
+		$this->writeDebugLog("[debug] checking isuser for ". $sUser."@".$aCommand[2]);
161
+
162
+		// If the hostnames doesn't match, we try to check remotely
163
+		if ($a->get_hostname() != $aCommand[2])
164
+			$found = $this->check_user($aCommand[2], $aCommand[1], true);
165
+		else {
166
+			$sQuery = "SELECT `uid` FROM `user` WHERE `nickname`='".dbesc($sUser)."'";
167
+			$this->writeDebugLog("[debug] using query ". $sQuery);
168
+			$r = q($sQuery);
169
+			$found = dbm::is_result($r);
170
+		}
171
+
172
+		if ($found) {
173
+			// The user is okay
174
+			$this->writeLog("[exAuth] valid user: ". $sUser);
175
+			fwrite(STDOUT, pack("nn", 2, 1));
155 176
 		} else {
156
-			// Now we check if the given user is valid
157
-			$sUser = str_replace(array("%20", "(a)"), array(" ", "@"), $aCommand[1]);
158
-			$this->writeDebugLog("[debug] checking isuser for ". $sUser."@".$aCommand[2]);
159
-
160
-			// If the hostnames doesn't match, we try to check remotely
161
-			if ($a->get_hostname() != $aCommand[2])
162
-				$found = $this->check_user($aCommand[2], $aCommand[1], true);
163
-			else {
164
-				$sQuery = "SELECT `uid` FROM `user` WHERE `nickname`='".dbesc($sUser)."'";
165
-				$this->writeDebugLog("[debug] using query ". $sQuery);
166
-				$r = q($sQuery);
167
-				$found = dbm::is_result($r);
168
-			}
169
-			if ($found) {
170
-				// The user is okay
171
-				$this->writeLog("[exAuth] valid user: ". $sUser);
172
-				fwrite(STDOUT, pack("nn", 2, 1));
173
-			} else {
174
-				// The user isn't okay
175
-				$this->writeLog("[exAuth] invalid user: ". $sUser);
176
-				fwrite(STDOUT, pack("nn", 2, 0));
177
-			}
177
+			// The user isn't okay
178
+			$this->writeLog("[exAuth] invalid user: ". $sUser);
179
+			fwrite(STDOUT, pack("nn", 2, 0));
178 180
 		}
179 181
 	}
180 182
 
@@ -218,39 +220,41 @@ class exAuth {
218 220
 		if (sizeof($aCommand) != 4) {
219 221
 			$this->writeLog("[exAuth] invalid auth command, data missing");
220 222
 			fwrite(STDOUT, pack("nn", 2, 0));
221
-		} else {
222
-			// We now check if the password match
223
-			$sUser = str_replace(array("%20", "(a)"), array(" ", "@"), $aCommand[1]);
224
-			$this->writeDebugLog("[debug] doing auth for ".$sUser."@".$aCommand[2]);
225
-
226
-			// If the hostnames doesn't match, we try to authenticate remotely
227
-			if ($a->get_hostname() != $aCommand[2])
228
-				$Error = !$this->check_credentials($aCommand[2], $aCommand[1], $aCommand[3], true);
229
-			else {
230
-				$sQuery = "SELECT `uid`, `password` FROM `user` WHERE `nickname`='".dbesc($sUser)."'";
231
-				$this->writeDebugLog("[debug] using query ". $sQuery);
232
-				if ($oResult = q($sQuery)) {
233
-					$uid = $oResult[0]["uid"];
234
-					$Error = ($oResult[0]["password"] != hash('whirlpool',$aCommand[3]));
235
-				} else {
236
-					$this->writeLog("[MySQL] invalid query: ". $sQuery);
237
-					$Error = true;
238
-					$uid = -1;
239
-				}
240
-				if ($Error) {
241
-					$oConfig = q("SELECT `v` FROM `pconfig` WHERE `uid` = %d AND `cat` = 'xmpp' AND `k`='password' LIMIT 1;", intval($uid));
242
-					$this->writeLog("[exAuth] got password ".$oConfig[0]["v"]);
243
-					$Error = ($aCommand[3] != $oConfig[0]["v"]);
244
-				}
223
+			return;
224
+		}
225
+
226
+		// We now check if the password match
227
+		$sUser = str_replace(array("%20", "(a)"), array(" ", "@"), $aCommand[1]);
228
+		$this->writeDebugLog("[debug] doing auth for ".$sUser."@".$aCommand[2]);
229
+
230
+		// If the hostnames doesn't match, we try to authenticate remotely
231
+		if ($a->get_hostname() != $aCommand[2])
232
+			$Error = !$this->check_credentials($aCommand[2], $aCommand[1], $aCommand[3], true);
233
+		else {
234
+			$sQuery = "SELECT `uid`, `password` FROM `user` WHERE `nickname`='".dbesc($sUser)."'";
235
+			$this->writeDebugLog("[debug] using query ". $sQuery);
236
+			if ($oResult = q($sQuery)) {
237
+				$uid = $oResult[0]["uid"];
238
+				$Error = ($oResult[0]["password"] != hash('whirlpool',$aCommand[3]));
239
+			} else {
240
+				$this->writeLog("[MySQL] invalid query: ". $sQuery);
241
+				$Error = true;
242
+				$uid = -1;
245 243
 			}
246 244
 			if ($Error) {
247
-				$this->writeLog("[exAuth] authentification failed for user ".$sUser."@". $aCommand[2]);
248
-				fwrite(STDOUT, pack("nn", 2, 0));
249
-			} else {
250
-				$this->writeLog("[exAuth] authentificated user ".$sUser."@".$aCommand[2]);
251
-				fwrite(STDOUT, pack("nn", 2, 1));
245
+				$oConfig = q("SELECT `v` FROM `pconfig` WHERE `uid` = %d AND `cat` = 'xmpp' AND `k`='password' LIMIT 1;", intval($uid));
246
+				$this->writeLog("[exAuth] got password ".$oConfig[0]["v"]);
247
+				$Error = ($aCommand[3] != $oConfig[0]["v"]);
252 248
 			}
253 249
 		}
250
+
251
+		if ($Error) {
252
+			$this->writeLog("[exAuth] authentification failed for user ".$sUser."@". $aCommand[2]);
253
+			fwrite(STDOUT, pack("nn", 2, 0));
254
+		} else {
255
+			$this->writeLog("[exAuth] authentificated user ".$sUser."@".$aCommand[2]);
256
+			fwrite(STDOUT, pack("nn", 2, 1));
257
+		}
254 258
 	}
255 259
 
256 260
 	/**

Loading…
Cancel
Save