. */ $RecipeInfo['UserAdmin']['Version'] = '2010-06-03'; if (!IsEnabled($EnableAuthorTracking,1)) Abort('$EnableAuthorTracking required for UserAdmin-AuthUser'); $AuthUserPat = "/^\\s*([@\\w][^\\s:]*):([^:\\n]*)(?::|$)/m"; #$AuthUserPat = "/^\\s*([@\\w][^\\s:]*):(.*)/m"; if (strncmp($action, 'user', 4)) return; require_once('useradmin-core.php'); class UserAdminAuthUser extends UserAdmin { var $AuthUserPageName = false; var $PCache = array(); // must be different than the global b/c ['text'] // is not cached in global $PCache var $UCache = array(); var $GCache = array(); // Constructor - set the AuthUserPageName function UserAdminAuthUser($pagename, $pnfmt=false, $opt=array()) { global $AuthUserPageFmt; if (!$pnfmt) { if (isset($AuthUserPageFmt)) $pnfmt = $AuthUserPageFmt; else $pnfmt = '$SiteAdminGroup.AuthUser'; } $this->AuthUserPageName = FmtPagename($pnfmt, $pagename); foreach ($opt as $k=>$v) { switch ($k) { case 'confirm_email': $this->confirm_email = $v; break; } } } // Read a page with caching function _readpage($pn, $usecache=true) { #echo "_readpage($pn): entering
\n"; #echo "PCache[$pn] =
".print_r($PCache[$pn],true)."

\n"; if (!$usecache || empty($this->PCache[$pn])) { #echo "_readpage: Reading
\n"; $page = ReadPage($pn, READPAGE_CURRENT); $this->PCache[$pn] = $page; } else $page = &$PCache[$pn]; #echo "_readpage: returning
".print_r($page,true)."

\n"; return($page); } // Put all users from SiteAdmin.AuthUser in an array: // array( // username -> array('authtokens'=>'string with @groups & passwd-hash' // 'userinfo'=>'ParseArgs string with other fields' // 'authuserline'=>'exact line read from AuthUser' // ), // username2 => array(...), // ) function _readallusers() { if ($this->UCache) return ($this->UCache); $page = $this->_readpage($this->AuthUserPageName); #$users = preg_match_all('/^\\s*(\\w+)\\s*:\\s*([^:]*)(?::(.*?))?$/m', $page['text'], $matches, PREG_SET_ORDER); #echo "page text read=
".$page['text']."

\n"; preg_match_all('/^\\s*([@\\w]+)\\s*:\\s*([^:\\n]*)(?::(.*?))?$/ms', $page['text'], $matches); #echo "matches=
".print_r($matches,true)."

\n"; for ($i = 0; $i < sizeof($matches[0]); $i++) { #echo "Processing ".$matches[0][$i]." (".$matches[1][$i].")
\n"; if (substr($matches[1][$i], 0, 1) == '@') $this->GCache[$matches[1][$i]] = preg_split("/[\\s,]/", $matches[2][$i]); else $this->UCache[$matches[1][$i]] = array('authtokens'=>$matches[2][$i], 'userinfo'=>$matches[3][$i], 'authuserline'=>$matches[0][$i]); } #echo "_readallusers(): GCache=
".print_r($this->GCache,true)."

\n"; #echo "_readallusers(): returning:
".print_r($this->UCache,true)."

\n"; return($this->UCache); } // Read a given username // array( // 'username'=>username // 'userpwhash'=>password-hash // 'groups'=>array('@group1', '@group2', etc.) // 'useremail'=>email // 'other fields'=>... // ) function Read($username) { #echo "Read($username): Entering
\n"; if (!$username) return array(); $users = $this->_readallusers(); // sets $this->GCache too #echo "Users read by _readallusers():
".print_r($users,true)."

\n"; if (!isset($users[$username])) { #echo "user=$username NOT FOUND - returning array()
\n"; return array(); // no user found } if ($user[$username]['parsed']) return ($user[$username]['parsed']); #echo "Found user=$username
\n"; $groups = array(); #echo "authtokens=".$users[$username]['authtokens']."
\n"; $authtoken = strtok($users[$username]['authtokens'], " ,\t"); while ($authtoken !== false) { #echo "authtoken=$authtoken
\n"; if ($authtoken{0} == '@') $groups[] = $authtoken; else $passwd = $authtoken; $authtoken = strtok(" ,\t"); } ### ### FIX LATER TO HANDLE GROUPS ### # Since useradmin-core doesn't yet handle groups I'm removing this complication # foreach ($this->GCache as $g => $members) # if (in_array($username, $members)) $groups[] = $g; #echo "userinfo=".$users[$username]['userinfo']."
\n"; $user = ParseArgs($users[$username]['userinfo']); unset($user['#']); // unneeded and causes errors in useradmin-core $user['username'] = $username; ## UserAdmin-core is not prepared to handle this as an array yet ## converted to a space-separated string... $user['usergroups'] = implode(" ",$groups); $user['userpwhash'] = $passwd; #echo "Read(): Returning:
".print_r($user,true)."

\n"; $this->UCache[$username]['parsed'] = $user; return($user); } // Write the data for a given user back to SiteAdmin.AuthUser function Write($username, $data, $auth='read') { global $IsPagePosted; $olddata = $this->Read($username); $data = array_merge($olddata, $data); Lock(2); $page = $this->_readpage($this->AuthUserPageName, false); if (!$page) Abort("?cannot write to $this->AuthUserPageName"); #echo "UserAdminAuthUser::Write: Data=
".print_r($data,true)."

\n"; #echo "Starting with this text:

\n".print_r($page['text'],true)."

\n"; $new = $page; foreach ($data as $k => $v) { if (!$v) continue; switch ($k) { case 'username': case '#': case '': break; case 'userpwhash': // fall through case 'group': $authtoken .= ' '.$v; break; case 'groups': foreach ($v as $g) $authtoken .= ' '.$g; break; default: $userinfo .= " $k='$v'"; break; } #echo "After $k=>$v: authtoken=$authtoken, userinfo=$userinfo
\n"; } $newline = "$username: $authtoken: $userinfo"; $user = $this->Read($username); #echo "user=
".print_r($user,true)."

\n"; if ($user) $new['text'] = str_replace($this->UCache[$username]['authuserline'], $newline, $new['text']); else $new['text'] .= "\n$newline"; #echo "Would have written this text:

\n".print_r($new['text'],true)."

\n"; UpdatePage($this->AuthUserPageName, $page, $new); Lock(0); return $IsPagePosted; } } $UserAdmin = new UserAdminAuthUser($pagename, null, array());