Browse Source

Added Execution time

causefx 7 years ago
parent
commit
fafa83d65a

+ 1 - 0
api/functions.php

@@ -11,6 +11,7 @@ foreach (glob(__DIR__ . DIRECTORY_SEPARATOR . 'functions' . DIRECTORY_SEPARATOR
 $GLOBALS['root'] = dirname(__DIR__, 1);
 $GLOBALS['uuid'] = '';
 $GLOBALS['rememberMeDays'] = '99';
+$GLOBALS['timeExecution'] = timeExecution();
 // Add in default and custom settings
 configLazy();
 // Define Logs and files after db location is set

+ 4 - 1
api/functions/homepage-connect-functions.php

@@ -2375,7 +2375,10 @@ function testAPIConnection($array)
 					//prettyPrint($provider);
 					if ($provider->auth()->attempt($username, $password, true)) {
 						// Passed.
-						//$user = $provider->search()->find($username);
+						$user = $provider->search()->find($username);
+						//return $user->getFirstAttribute('cn');
+						//return $user->getGroups(['cn']);
+						//return $user;
 						//return $user->getUserPrincipalName();
 						//return $user->getGroups(['cn']);
 						return true;

+ 2 - 0
api/functions/log-functions.php

@@ -18,6 +18,8 @@ function writeLoginLog($username, $authType)
 
 function writeLog($type = 'error', $message, $username = null)
 {
+	$GLOBALS['timeExecution'] = timeExecution($GLOBALS['timeExecution']);
+	$message = $message . ' [Execution Time: ' . formatSeconds($GLOBALS['timeExecution']) . ']';
 	$username = ($username) ? $username : $GLOBALS['organizrUser']['username'];
 	if (file_exists($GLOBALS['organizrLog'])) {
 		$getLog = str_replace("\r\ndate", "date", file_get_contents($GLOBALS['organizrLog']));

+ 56 - 0
api/functions/normal-functions.php

@@ -645,4 +645,60 @@ function checkOverrideURL($url, $override)
 	} else {
 		return $url . $override;
 	}
+}
+
+function clearPOSTPassword($array)
+{
+	if (isset($array['data'])) {
+		foreach ($array['data'] as $k => $v) {
+			// clear password from array
+			if ($k == 'password') {
+				$array['data'][$k] = '*******';
+			}
+		}
+	}
+	if (isset($array['data']['data'])) {
+		foreach ($array['data']['data'] as $k => $v) {
+			// clear password from array
+			if ($k == 'password') {
+				$array['data']['data'][$k] = '*******';
+			}
+		}
+	}
+	return $array;
+}
+
+function timeExecution($previous = null)
+{
+	if (!$previous) {
+		return microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"];
+	} else {
+		return (microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"]) - $previous;
+	}
+}
+
+function formatSeconds($seconds)
+{
+	$hours = 0;
+	$milliseconds = str_replace("0.", '', $seconds - floor($seconds));
+	if ($seconds > 3600) {
+		$hours = floor($seconds / 3600);
+	}
+	$seconds = $seconds % 3600;
+	$time = str_pad($hours, 2, '0', STR_PAD_LEFT)
+		. gmdate(':i:s', $seconds)
+		. ($milliseconds ? '.' . $milliseconds : '');
+	$parts = explode(':', $time);
+	$timeExtra = explode('.', $parts[2]);
+	if ($parts[0] !== '00') { // hours
+		return $time;
+	} elseif ($parts[1] !== '00') { // mins
+		return $parts[1] . 'min(s) ' . $timeExtra[0] . 's';
+	} elseif ($timeExtra[0] !== '00') { // secs
+		return substr($parts[2], 0, 5) . 's | ' . substr($parts[2], 0, 7) * 1000 . 'ms';
+	} else {
+		return substr($parts[2], 0, 7) * 1000 . 'ms';
+	}
+	//return $timeExtra[0] . 's ' . (number_format(('0.' . substr($timeExtra[1], 0, 4)), 4, '.', '') * 1000) . 'ms';
+	//return (number_format(('0.' . substr($timeExtra[1], 0, 4)), 4, '.', '') * 1000) . 'ms';
 }

+ 1 - 3
api/index.php

@@ -1,5 +1,4 @@
 <?php
-$generationTime = -microtime(true);
 //include functions
 require_once 'functions.php';
 //Set result array
@@ -1341,8 +1340,7 @@ if (!$result) {
 	$result['error'] = "An error has occurred";
 }
 $result['generationDate'] = $GLOBALS['currentTime'];
-$generationTime += microtime(true);
-$result['generationTime'] = (sprintf('%f', $generationTime) * 1000) . 'ms';
+$result['generationTime'] = formatSeconds(timeExecution());
 //return JSON array
 if ($pretty) {
 	echo '<pre>' . safe_json_encode($result, JSON_PRETTY_PRINT) . '</pre>';