4 # FILE: SPT--SPTUser.php
9 # SomeMethod($SomeParameter, $AnotherParameter)
10 # - short description of method
14 # Part of the Scout Portal Toolkit
15 # Copyright 2004 Internet Scout Project
16 # http://scout.wisc.edu
20 # ---- PUBLIC INTERFACE --------------------------------------------------
21 # ---- user interface preference mnemonics
22 # color avoidance flags
32 # content display options
37 # content view options
42 # audio description options
47 # caption type options
55 # call parent constructor
56 $this->
User($UserInfo);
58 # if user is logged in
61 # if user already has a UI preferences record in DB
62 $this->DB->Query(
"SELECT * FROM UserUIPreferences"
63 .
" WHERE UserId = '".$this->
Id().
"'");
64 if ($this->DB->NumRowsSelected())
66 # load in UI preferences
67 $this->UserUIPreferencesCache = $this->DB->FetchRow();
71 # add UI preferences record to DB for user
72 $this->DB->Query(
"INSERT INTO UserUIPreferences"
73 .
" (UserId) VALUES (".$this->
Id().
")");
78 static function EmailWrapper($To, $Subject, $Message, $AdditionalHeaders)
80 # look for "From" address in supplied headers
81 if (strlen($AdditionalHeaders))
83 $HeaderLines = explode(
"\n", $AdditionalHeaders);
85 foreach ($HeaderLines as $Line)
87 $HeaderLine = trim($Line);
88 if (preg_match(
"/^from:/i", $Line))
90 $From = preg_replace(
"/^from:/i",
"", $Line);
94 $Headers[] = $HeaderLine;
99 # use default system admin address if no "From" address found
102 $From = trim($GLOBALS[
"G_SysConfig"]->PortalName())
103 .
" <".trim($GLOBALS[
"G_SysConfig"]->AdminEmail()).
">";
110 $Msg->Subject($Subject);
111 $Msg->Body($Message);
112 $Result = $Msg->Send();
114 # report success to caller
118 # user interface / accessibility preferences
128 {
return $this->
UUPUpdateValue(
"ColorAvoidanceFlags", $NewValue); }
134 {
return $this->
UUPUpdateValue(
"AudioDescriptionLevel", $NewValue); }
136 {
return $this->
UUPUpdateValue(
"AudioDescriptionLanguage", $NewValue); }
138 {
return $this->
UUPUpdateValue(
"VisualDescriptionLanguage", $NewValue); }
140 {
return $this->
UUPUpdateValue(
"ImageDescriptionLanguage", $NewValue); }
142 {
return $this->
UUPUpdateValue(
"UseGraphicAlternatives", $NewValue); }
163 # Clear all keys more than two days old
164 $DB->Query(
"DELETE FROM LoginKeys WHERE NOW() - CreationTime > 172800");
165 $DB->Query(
"DELETE FROM UsedLoginTokens WHERE NOW()-KeyCTime > 172800");
167 # Get the most recently generated key
168 $DB->Query(
"SELECT NOW()-CreationTime as Age,"
169 .
"KeyPair FROM LoginKeys "
170 .
"ORDER BY Age ASC LIMIT 1");
171 $Row =
$DB->FetchRow();
173 # If there is no key in the database, or the key is too old
174 if ( ($Row===FALSE) || ($Row[
"Age"]>=86400) )
176 # Generate a new OpenSSL format keypair
177 $KeyPair = openssl_pkey_new(
179 'private_key_bits' => 512, # Make
this a Sysadmin pref later?
180 'private_key_type' => OPENSSL_KEYTYPE_RSA
183 # Serialize it for storage
184 openssl_pkey_export($KeyPair, $KeyPairDBFormat);
186 # And stick it into the database
187 $DB->Query(
"INSERT INTO LoginKeys "
188 .
"(KeyPair, CreationTime) VALUES ("
189 .
"\"".addslashes($KeyPairDBFormat).
"\","
194 # If we do have a current key in the database,
195 # Convert it to openssl format for usage
196 $KeyPair = openssl_pkey_get_private( $Row[
"KeyPair"] );
210 # Export the keypair as an ASCII signing request (which contains the data we want)
211 openssl_csr_export(openssl_csr_new(array(), $KeyPair), $Export,
false);
217 '/Modulus \([0-9]+ bit\):(.*)Exponent: [0-9]+ \(0x([0-9a-f]+)\)/ms',
218 '/Public-Key: \([0-9]+ bit\).*Modulus:(.*)Exponent: [0-9]+ \(0x([0-9a-f]+)\)/ms',
221 foreach ($Patterns as $Pattern)
223 if (preg_match($Pattern, $Export, $Matches))
225 $Modulus = $Matches[1];
226 $Exponent = $Matches[2];
231 # Clean newlines and whitespace out of the modulus
232 $Modulus = preg_replace(
"/[^0-9a-f]/",
"",$Modulus);
234 # Return key material
235 return array(
"Modulus" => $Modulus,
"Exponent" => $Exponent );
238 # ---- PRIVATE INTERFACE -------------------------------------------------
244 return $this->DB->UpdateValue(
"UserUIPreferences", $FieldName,
245 $NewValue,
"UserId = '".$this->
Id().
"'",
246 $this->UserUIPreferencesCache);