⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 reprofunctions.php

📁 这是国外的resip协议栈
💻 PHP
📖 第 1 页 / 共 2 页
字号:
                // print "Query -- $query<br />\nResult -- $result<br />\n";		$state = TRUE;		while (($myrow = mysql_fetch_array($result))) {			// print "Row -- ";			// print_r($myrow);			$newRow = array($myrow['id'],$myrow['aor'],$myrow['forwardType'],$myrow['forwardDestination'],$myrow['voicemail']);			// print "<br />New Row --";			// print_r($newRow);			$resources[] = $newRow;			// print "<br />Resource -- ";			// print_r($resources);		}    } else {    	$state = FALSE;   	}        mysql_free_result($result);	mysql_close($db);	return $state;}/*Purpose: gets the shared salt from the database to use in creating authenticationtokens.return values are:	TRUE == salt successfully retrieved	FALSE == error while retreiving salt*/function getSalt(&$salt) {    $db = mysql_connect("localhost","apache","apache") or die(mysql_error());    mysql_select_db("repro",$db) or die (mysql_error());    $query="select value from Parameters where parameter='salt'";    $result = mysql_query($query) or die(mysql_error());        $count=mysql_num_rows($result);        if ($count == 1) {        // we matched, so lets get the state of the user        $salt = mysql_result($result,0,"value");        $state = TRUE;    } else {		$salt = ""; 		$state = FALSE; }		    mysql_free_result($result);	mysql_close($db);	return $state;}/*Purpose: clears authentication cookiesreturn values are:	TRUE == no errors reported from setcookie	FALSE == errors were reported*/function clearCookies() {dbgSquirt("==============Function: Clear Cookies ==============");dbgSquirt('Cookie --' . dbgShowFile($_COOKIE));  $result = setcookie("user","",mktime(12,0,0,1,1,1970));  $result1 = setcookie("authentication","",mktime(12,0,0,1,1,1970));  return ($result && $result1);}/*Purpose: checks whether the current cookies validate the user or if additional         authentication is needed.	 if the cookies are unset or are blank, $ignoreBlanks is checked.	 if $ignoreBlanks is TRUE, no error is reported in this case.	 if $ignoreBlanks is FALSE, then this case is treated as an error.	 ...in either case, blank or unset cookies will result in $forceLogin	    being true.return values are:	TRUE == no errors reported	FALSE == errors were reportedmutates the following:	$forceLogin: TRUE == cookies contain valid authentication data	             FALSE == user is NOT authenticated	$error: "" == no errors	        otherwise contains displayable text of error*/function checkCookies(&$forceLogin,&$error,$ignoreBlanks) {  $forceLogin = TRUE;  $error = "";  global $sessionDuration;  dbgSquirt("==============Function: checkCoookies ==============");  dbgSquirt('Cookie --' . dbgShowFile($_COOKIE));  if (isset($_COOKIE['user']) && !empty($_COOKIE['user']) &&      isset($_COOKIE['authentication']) && !empty($_COOKIE['authentication'])) {    // both user and authentication cookies are set and non-blank    // dbgSquirt("Cookies set and non-empty");    $userCookie = $_COOKIE['user'];    $authenticationCookie = $_COOKIE['authentication'];    $time = time();    // dbgSquirt("Getting salt");    if (getSalt($salt)) {      // dbgSquirt("...salt gotten");      // dbgSquirt("Encrypting");      if (sha1($userCookie . $salt) == $authenticationCookie) {	// authentication passed	// so reset expiration on cookies	// dbgSquirt("Cookie matches encryption");	// dbgSquirt("Resetting cookies");	// dbgSquirt("Time -- $time");	// dbgSquirt("Time + Duration -- ". ($time+$sessionDuration));	$result = setcookie("user",$userCookie,$time+$sessionDuration);	$result1 = setcookie("authentication",$authenticationCookie,			     $time+$sessionDuration);	if ((TRUE == $result) && (TRUE == $result1)) {	  // everything worked	  // dbgSquirt("Everything worked ... no need to forceLogin");	  $forceLogin = FALSE;	} else {	  $error = "Internal error -- problem while creating cookies.  Please contact an administrator.";	}      } else {	// credentials in cookies don't match.	// dbgSquirt("Cookie does NOT match encryption");	$error = "Authentication error -- The supplied credentials don't match our stored values. Please reauthenticate and try again.";      }    } else {      // dbgSquirt("...error while getting salt");      // error while trying to get salt value      $error = "Internal error -- unable to validate supplied credentials. Please reauthenticate and try again.";    }  } else {    // cookies were unset or contained empty values    // dbgSquirt("Cookies unset or empty");    if (FALSE == $ignoreBlanks) {      $error = "Please log in."; }  }  dbgSquirt("Returning -- ". empty($error));  return(empty($error));}/*Purpose: change the fullname saved for a userreturn values are:	TRUE = change succeeded.	FALSE = change failed. */function updateFullname($username, $newFullname) {    $db = mysql_connect("localhost","apache","apache") or die(mysql_error());    mysql_select_db("repro",$db) or die (mysql_error());    $query="update Users set fullname = '$newFullname' where username = '$username'";    $result = mysql_query($query) or die(mysql_error());    $count = mysql_affected_rows();	    if ((1 == $count) && (TRUE == $result)) {        // no error and 1 row updated      $state = TRUE;    } else {      $state = FALSE; }		    mysql_close($db);    return $state;}/*Purpose: Create an encrypted password based on the username and supplied          cleartext password.Returns encrypted password */function createPassword($username, $password) {  $encryptedPassword = md5($username . "::" . $password);  return $encryptedPassword;}/*Purpose: change the password saved for a userNote:    expects the password to come in already encryptedreturn values are:	TRUE = change succeeded.	FALSE = change failed. */function updatePassword($username, $newPassword) {  dbgSquirt("============= Function: updatePassword ===========");  $db = mysql_connect("localhost","apache","apache") or die(mysql_error());  mysql_select_db("repro",$db) or die (mysql_error());  $query="update Users set password = '$newPassword' where username = '$username'";  dbgSquirt("Query -- $query");  $result = mysql_query($query) or die(mysql_error());      $count = mysql_affected_rows();	  if ((1 == $count) && (TRUE == $result)) {    // no error and 1 row updated    $state = TRUE;  } else {    $state = FALSE; }		  mysql_close($db);  return $state;}/*Purpose: change the email saved for a userreturn values are:	TRUE = change succeeded.	FALSE = change failed. */function updateEmail($username, $newEmail) {  dbgSquirt("============= Function: updateEmail ===========");  $db = mysql_connect("localhost","apache","apache") or die(mysql_error());  mysql_select_db("repro",$db) or die (mysql_error());  $query="update Users set email = '$newEmail' where username = '$username'";  dbgSquirt("Query -- $query");  $result = mysql_query($query) or die(mysql_error());      $count = mysql_affected_rows();	  if ((1 == $count) && (TRUE == $result)) {    // no error and 1 row updated    $state = TRUE;  } else {    $state = FALSE; }		  mysql_close($db);  return $state;}/*Purpose: Delete a resourceNote: to limit risk this function makes sure the resourceId that is being  flagged for deletion is owned by the user passed in (which should be the  username from the authentication cookies)return values are:	TRUE = delete succeeded.	FALSE = delete failed. */function deleteResource($username, $resourceId) {  dbgSquirt("============= Function: deleteResource ===========");  $db = mysql_connect("localhost","apache","apache") or die(mysql_error());  mysql_select_db("repro",$db) or die (mysql_error());  // first we need to get the userid from the username  $query="select id from Users where username = '$username'";  dbgSquirt("Query -- $query");  $result = mysql_query($query) or die(mysql_error());    $count=mysql_num_rows($result);    dbgSquirt("Rows -- $count");    if ($count == 1) {      // we matched, so lets get the userid of the user      $userid = mysql_result($result,0,"id");      mysql_free_result($result);              // delete the resource      $query = "delete from Resources where userid = '$userid' and id = '$resourceId'";      dbgSquirt("Query2 -- $query");      $result = mysql_query($query) or die(mysql_error());      $count = mysql_affected_rows();      dbgSquirt("Rows -- $count");	      if ((1 == $count) && (TRUE == $result)) {        // no error and 1 row deleted (should only be 1 row since id is	// the primary key)	$state = TRUE;      } else {	$state = FALSE; }    } else {      $state = FALSE; }    mysql_free_result($result);    mysql_close($db);    return $state;}/*Purpose: update a resource based on the resourceIdreturn values are:	TRUE = update succeeded.	FALSE = update failed. */function updateResource($resourceId,$username,$resource,$forwardType,			$forward,$voicemail) {  dbgSquirt("============= Function: updateResource ===========");  $db = mysql_connect("localhost","apache","apache") or die(mysql_error());  mysql_select_db("repro",$db) or die (mysql_error());  // first we need to get the userid from the username  $query="select id from Users where username = '$username'";  dbgSquirt("Query -- $query");  $result = mysql_query($query) or die(mysql_error());  $count=mysql_num_rows($result);  dbgSquirt("Rows -- $count");  if ($count == 1) {    // we matched, so lets get the userid of the user    $userid = mysql_result($result,0,"id");    mysql_free_result($result);            // delete the resource    $query = "update Resources set aor='$resource',forwardType='$forwardType',forwardDestination='$forward',voicemail='$voicemail' where userid = '$userid' and id = '$resourceId'";    dbgSquirt("Query2 -- $query");    $result = mysql_query($query) or die(mysql_error());    $count = mysql_affected_rows();    dbgSquirt("Rows -- $count");	    if ((1 == $count) && (TRUE == $result)) {      // no error and 1 row modified (should only be 1 row since id is      // the primary key)      $state = TRUE;    } else {      $state = FALSE; }  } else {    $state = FALSE; }  mysql_free_result($result);  mysql_close($db);  return $state;}?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -