00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00029 class Userdata_XML
00030 {
00031 var $minixml;
00032
00033 function Userdata_XML()
00034 {
00035 $this->prefix = realpath(dirname(__FILE__)."/../");
00036 }
00037
00044
00045 function createFile($vars)
00046 {
00047 $this->file = $this->prefix."/conf/users.xml";
00048
00049 $minixmlpath = $vars['minixml_path'];
00050 $this->minixml = $minixmlpath;
00051 if (!file_exists("$minixmlpath/minixml.inc.php"))
00052 {
00053 $this->file = null;
00054 return null;
00055 }
00056 require_once "$minixmlpath/minixml.inc.php";
00057 $doc = new MiniXMLDoc();
00058 $root =& $doc->getRoot();
00059 $users =& $root->createChild("users");
00060 $users->attribute("version", "1.0");
00061
00062 $fp = @fopen($this->file, "w");
00063 if ($fp)
00064 {
00065 fputs($fp, $doc->toString());
00066 fclose($fp);
00067 }
00068 }
00069
00070
00071
00072 function addUser($username, $password, $class, $params, $opts)
00073 {
00074 require_once ($this->minixml."/minixml.inc.php");
00075 $doc = new MiniXMLDoc();
00076 $doc->fromFile($this->file);
00077 $root =& $doc->getRoot();
00078 $users =& $root->getElement("users");
00079
00080
00081 if (!get_class($users))
00082 {
00083 $users =& $root->createChild("users");
00084 }
00085 if (method_exists($users, "numChildren"))
00086 {
00087 for ($c = 0; $c < $users->numChildren(); $c++)
00088 {
00089 $user =& $users->xchildren[$c];
00090 $id = trim($user->attribute("id"));
00091 if ($id == $username)
00092 {
00093 $users->removeChild($user);
00094 break;
00095 }
00096 }
00097 }
00098
00099 $user =& $users->createChild("user");
00100 $user->attribute("id", $username);
00101 $pw =& $user->createChild("password");
00102 $pw->text($password);
00103 $cls =& $user->createChild("class");
00104 $cls->text($class);
00105
00106 if (is_array($param))
00107 {
00108 $names = array_keys($params);
00109 for ($p = 0; $p < count($names); $p++)
00110 {
00111 $param =& $user->createChild("parameter");
00112 $param->attribute("name", $names[$p]);
00113 $param->text($param[$names[$p]]);
00114 }
00115 }
00116 if (is_array($opts))
00117 {
00118 $names = array_keys($opts);
00119 for ($o = 0; $o < count($names); $o++)
00120 {
00121 $options =& $user->createChild("option");
00122 $option->attribute("name", $names[$p]);
00123 $option->text($opts[$names[$p]]);
00124 }
00125 }
00126
00127
00128 $fp = @fopen($this->file, "w");
00129 if ($fp)
00130 {
00131 fputs($fp, $doc->toString());
00132 fclose($fp);
00133 }
00134 else
00135 {
00136 die("Error: ".$this->file);
00137 }
00138 }
00139
00140
00141
00142 function loadData($file, $username, $password)
00143 {
00144 global $settings;
00145
00146 if (is_null($this->minixml))
00147 {
00148 $this->minixml = $settings->attribute("minixml_path");
00149 }
00150
00151 require_once ($this->minixml."/minixml.inc.php");
00152 $doc = new MiniXMLDoc();
00153 $doc->fromFile($file);
00154 $root =& $doc->getRoot();
00155 $users =& $root->getElement("users");
00156
00157
00158 for ($c = 0; $c < $users->numChildren(); $c++)
00159 {
00160 $user =& $users->xchildren[$c];
00161 $id = $user->attribute("id");
00162 if ($id != $username)
00163 {
00164 continue;
00165 }
00166
00167 $pwn =& $user->getElement("password");
00168 $pw = trim($pwn->text());
00169
00170
00171 if (preg_match('/^\$1\$/', $password))
00172 {
00173 if ($password != $pw)
00174 {
00175 continue;
00176 }
00177 }
00178 elseif (crypt($password, $pw) != $pw)
00179 {
00180 continue;
00181 }
00182
00183 $this->password = $pw;
00184 $class =& $user->getElement("class");
00185 $this->class = trim($class->text());
00186
00187
00188 for ($o = 0; $o < $user->numChildren(); $o++)
00189 {
00190 $child =& $user->xchildren[$o];
00191 if ($child->name() == "option")
00192 {
00193 $this->options[$child->attribute("name")] = $child->text();
00194 }
00195 elseif ($child->name() == "parameter")
00196 {
00197 $this->parameters[$child->attribute("name")] = $child->text();
00198 }
00199 }
00200 $this->allok = true;
00201 }
00202 }
00203
00204 }
00205 ?>