Search:

CWIS Developers Documentation

  • Main Page
  • Classes
  • Files
  • File List
  • File Members

SPTUser.php

Go to the documentation of this file.
00001 <?PHP
00002 
00003 #
00004 #   FILE:  SPT--SPTUser.php
00005 #
00006 #   METHODS PROVIDED:
00007 #       SPTUser()
00008 #           - constructor
00009 #       SomeMethod($SomeParameter, $AnotherParameter)
00010 #           - short description of method
00011 #
00012 #   AUTHOR:
00013 #
00014 #   Part of the Scout Portal Toolkit
00015 #   Copyright 2004 Internet Scout Project
00016 #   http://scout.wisc.edu
00017 #
00018 
00019 class SPTUser extends User {
00020     # ---- PUBLIC INTERFACE --------------------------------------------------
00021     # ---- user interface preference mnemonics
00022     # color avoidance flags
00023     const UIPREF_AVOID_RED =           1;
00024     const UIPREF_AVOID_REDGREEN =      2;
00025     const UIPREF_AVOID_BLUEYELLOW =    4;
00026     const UIPREF_AVOID_GREENYELLOW =   8;
00027     const UIPREF_AVOID_ORANGE =        16;
00028     const UIPREF_AVOID_REDBLACK =      32;
00029     const UIPREF_AVOID_PURPLEGREY =    64;
00030     const UIPREF_AVOID_USEMAXMONOCHR = 128;
00031 
00032     # content display options
00033     const UIPREF_CONTENTDENSITY_NOPREFERENCE =  0;
00034     const UIPREF_CONTENTDENSITY_DETAILED =  1;
00035     const UIPREF_CONTENTDENSITY_OVERVIEW =  2;
00036 
00037     # content view options
00038     const UIPREF_CONTENTVIEW_NOPREFERENCE =  0;
00039     const UIPREF_CONTENTVIEW_TEXTINTENSIVE =  1;
00040     const UIPREF_CONTENTVIEW_IMAGEINTENSIVE =  2;
00041 
00042     # audio description options
00043     const UIPREF_AUDIODESCRIPTION_NONE =  0;
00044     const UIPREF_AUDIODESCRIPTION_STANDARD =  1;
00045     const UIPREF_AUDIODESCRIPTION_EXPANDED =  2;
00046 
00047     # caption type options
00048     const UIPREF_CAPTIONTYPE_NONE =  0;
00049     const UIPREF_CAPTIONTYPE_VERBATIM =  1;
00050     const UIPREF_CAPTIONTYPE_REDUCEDREADINGLEVEL =  2;
00051 
00052     # object constructor
00053     function SPTUser($UserInfo = NULL)
00054     {
00055         global $Session;
00056 
00057         # create database handle for parent and local use
00058         $DB = new SPTDatabase();
00059         $this->DB = $DB;
00060 
00061         # if no user info supplied
00062         if ($UserInfo == NULL)
00063         {
00064             # if session is available in global context
00065             if (isset($Session))
00066             {
00067                 # call parent constructor with global session
00068                 $this->User($Session);
00069             }
00070             else
00071             {
00072                 # call parent constructor with our own session
00073                 $OurSession = new Session($this->DB);
00074                 $this->User($OurSession);
00075             }
00076         }
00077         else
00078         {
00079             # call parent constructor with our DB handle
00080             $this->User($this->DB, $UserInfo);
00081         }
00082 
00083         # if user is logged in
00084         if ($this->IsLoggedIn())
00085         {
00086             # if user already has a UI preferences record in DB
00087             $DB->Query("SELECT * FROM UserUIPreferences WHERE UserId = '".$this->Id()."'");
00088             if ($DB->NumRowsSelected())
00089             {
00090                 # load in UI preferences
00091                 $this->UserUIPreferencesCache = $DB->FetchRow();
00092             }
00093             else
00094             {
00095                 # add UI preferences record to DB for user
00096                 $DB->Query("INSERT INTO UserUIPreferences (UserId) VALUES (".$this->Id().")");
00097             }
00098         }
00099     }
00100 
00101     # user interface / accessibility preferences
00102     function PrefFontSize($NewValue = DB_NOVALUE)
00103             {  return $this->UUPUpdateValue("FontSize", $NewValue);  }
00104     function PrefFontTypeFace($NewValue = DB_NOVALUE)
00105             {  return $this->UUPUpdateValue("FontTypeFace", $NewValue);  }
00106     function PrefFontColor($NewValue = DB_NOVALUE)
00107             {  return $this->UUPUpdateValue("FontColor", $NewValue);  }
00108     function PrefBackgroundColor($NewValue = DB_NOVALUE)
00109             {  return $this->UUPUpdateValue("BackgroundColor", $NewValue);  }
00110     function PrefColorAvoidanceFlags($NewValue = DB_NOVALUE)
00111             {  return $this->UUPUpdateValue("ColorAvoidanceFlags", $NewValue);  }
00112     function PrefContentDensity($NewValue = DB_NOVALUE)
00113             {  return $this->UUPUpdateValue("ContentDensity", $NewValue);  }
00114     function PrefContentView($NewValue = DB_NOVALUE)
00115             {  return $this->UUPUpdateValue("ContentView", $NewValue);  }
00116     function PrefAudioDescriptionLevel($NewValue = DB_NOVALUE)
00117             {  return $this->UUPUpdateValue("AudioDescriptionLevel", $NewValue);  }
00118     function PrefAudioDescriptionLanguage($NewValue = DB_NOVALUE)
00119             {  return $this->UUPUpdateValue("AudioDescriptionLanguage", $NewValue);  }
00120     function PrefVisualDescriptionLanguage($NewValue = DB_NOVALUE)
00121             {  return $this->UUPUpdateValue("VisualDescriptionLanguage", $NewValue);  }
00122     function PrefImageDescriptionLanguage($NewValue = DB_NOVALUE)
00123             {  return $this->UUPUpdateValue("ImageDescriptionLanguage", $NewValue);  }
00124     function PrefUseGraphicAlternatives($NewValue = DB_NOVALUE)
00125             {  return $this->UUPUpdateValue("UseGraphicAlternatives", $NewValue);  }
00126     function PrefSignLanguage($NewValue = DB_NOVALUE)
00127             {  return $this->UUPUpdateValue("SignLanguage", $NewValue);  }
00128     function PrefCaptionType($NewValue = DB_NOVALUE)
00129             {  return $this->UUPUpdateValue("CaptionType", $NewValue);  }
00130     function PrefCaptionRate($NewValue = DB_NOVALUE)
00131             {  return $this->UUPUpdateValue("CaptionRate", $NewValue);  }
00132 
00142     static function GetCryptKey()
00143     {
00144         $DB = new Database();
00145 
00146         # Clear all keys more than two days old
00147         $DB->Query("DELETE FROM LoginKeys WHERE NOW() - CreationTime > 172800");
00148         $DB->Query("DELETE FROM UsedLoginTokens WHERE NOW()-KeyCTime > 172800");
00149 
00150         # Get the most recently generated key
00151         $DB->Query("SELECT NOW()-CreationTime as Age,"
00152                    ."KeyPair FROM LoginKeys "
00153                    ."ORDER BY Age ASC LIMIT 1");
00154         $Row = $DB->FetchRow();
00155 
00156         # If there is no key in the database, or the key is too old
00157         if ( ($Row===FALSE) || ($Row["Age"]>=86400) )
00158         {
00159             # Generate a new OpenSSL format keypair
00160             $KeyPair = openssl_pkey_new(
00161                 array(
00162                     'private_key_bits' => 512, # Make this a Sysadmin pref later?
00163                     'private_key_type' => OPENSSL_KEYTYPE_RSA
00164                     ));
00165 
00166             # Serialize it for storage
00167             openssl_pkey_export($KeyPair, $KeyPairDBFormat);
00168 
00169             # And stick it into the database
00170             $DB->Query("INSERT INTO LoginKeys "
00171                        ."(KeyPair, CreationTime) VALUES ("
00172                        ."\"".addslashes($KeyPairDBFormat)."\","
00173                        ."NOW())");
00174         }
00175         else
00176         {
00177             # If we do have a current key in the database,
00178             #  Convert it to openssl format for usage
00179             $KeyPair = openssl_pkey_get_private( $Row["KeyPair"] );
00180         }
00181 
00182         return $KeyPair;
00183     }
00184 
00191     static function ExtractPubKeyParameters($KeyPair)
00192     {
00193         # Export the keypair as an ASCII signing request (which contains the data we want)
00194         openssl_csr_export(openssl_csr_new(array(), $KeyPair), $Export, false);
00195 
00196         $Modulus  = "";
00197         $Exponent = "";
00198 
00199         $Patterns = array(
00200             '/Modulus \([0-9]+ bit\):(.*)Exponent: [0-9]+ \(0x([0-9a-f]+)\)/ms',
00201             '/Public-Key: \([0-9]+ bit\).*Modulus:(.*)Exponent: [0-9]+ \(0x([0-9a-f]+)\)/ms',
00202             );
00203 
00204         foreach ($Patterns as $Pattern)
00205         {
00206             if (preg_match($Pattern, $Export, $Matches))
00207             {
00208                 $Modulus = $Matches[1];
00209                 $Exponent = $Matches[2];
00210                 break;
00211             }
00212         }
00213 
00214         # Clean newlines and whitespace out of the modulus
00215         $Modulus = preg_replace("/[^0-9a-f]/","",$Modulus);
00216 
00217         # Return key material
00218         return array( "Modulus" => $Modulus, "Exponent" => $Exponent );
00219     }
00220 
00221     # ---- PRIVATE INTERFACE -------------------------------------------------
00222 
00223     var $DB;
00224     var $UserUIPreferencesCache;
00225 
00226     function UUPUpdateValue($FieldName, $NewValue)
00227     {
00228         return $this->DB->UpdateValue("UserUIPreferences", $FieldName,
00229                 $NewValue, "UserId = '".$this->Id()."'",
00230                 $this->UserUIPreferencesCache);
00231     }
00232 }
00233 
00234 ?>

CWIS logo doxygen
Copyright 2010 Internet Scout