[ PHPXref.com ] [ Generated: Sun Jul 20 20:47:44 2008 ] [ TUTOS 1.2 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/php/ -> admin_show.php (source)

   1  <?php
   2  /**
   3   * Copyright 2001 - 2004 by Gero Kohnert
   4   *
   5   * @modulegroup ADMIN
   6   * @module admin_show
   7   * @package BASE
   8   */
   9   include  'webelements.p3';
  10   include  'permission.p3';
  11   require_once  'db/table.pinc';
  12  
  13   /* Check if user is allowed to use it */
  14   check_user();
  15   loadmodules("admin","show");
  16   loadlayout();
  17  
  18   /**
  19    * FROM http://www.php.net/manual/en/function.session-set-save-handler.php
  20    */
  21   function unserialize_session($val)
  22   {
  23     // not entirely foolproof, but replace the pipe with something obscure
  24     $replacer = chr(254).chr(254).chr(254);
  25     $repRegex = '/(")([A-Za-z0-9_]*?)(\|)/';
  26     $val = preg_replace($repRegex,'$1$2'.$replacer,$val);
  27  
  28     // split the semi-serialized data into keys and values
  29     $splitRegex = '/([^;}][A-Za-z0-9_]*?)\|/';
  30     $splitArray = preg_split($splitRegex, $val, -1,
  31                                PREG_SPLIT_DELIM_CAPTURE);
  32  
  33     // remove offset 0 -- always empty
  34     array_shift($splitArray);
  35  
  36     // build a useful array
  37     $usefulArray = array();
  38     while ($var = array_shift($splitArray)) {
  39         $val = array_shift($splitArray);
  40         $val = str_replace($replacer, '|', $val);
  41         $usefulArray[$var] = unserialize($val);
  42     }
  43     return $usefulArray;
  44   }
  45   /* ---------------------------------------------------------------------------
  46    *
  47    */
  48   Function getTableCount($tbl,&$dbconn) {
  49     $q = "SELECT count(*) as c from ". $dbconn->prefix . $tbl;
  50     $r = @$dbconn->exec($q,0);
  51     if ( ($r == -1) || (1 != $r->numrows()) ) {
  52       return "";
  53     }
  54     $cnt = $r->get(0, "c");
  55     $r->free();
  56     return $cnt;
  57   }
  58   /* ---------------------------------------------------------------------------
  59    *
  60    */
  61   Function getinfo(&$table) {
  62     global  $dbconn;
  63  
  64     foreach($table as $i => $f) {
  65       $table[$i]['count'] = 0;
  66       $table[$i]['count'] = getTableCount($f[name],$dbconn);
  67     }
  68   }
  69  
  70  
  71   /**
  72    * display a admin page
  73    */
  74   class admin_show extends layout {
  75     Function SubTableStart() {
  76       return "<table width=\"100%\" class=\"single\" border=\"1\" cellpadding=\"3\" cellspacing=\"0\">\n";
  77     }
  78     Function SubTableEnd() {
  79       return "</table>\n";
  80     }
  81     /**
  82      *
  83      */
  84     Function login_info() {
  85       global $lang,$tutos;
  86  
  87       echo "<tr>\n";
  88       echo " <th colspan=\"6\">". menulink("user_overview.php",$lang['AdminLoginInfo'],$lang['AdminLoginInfo']) ."</th>\n";
  89       echo "</tr>\n";
  90       echo "<tr><td colspan=\"6\">\n";
  91       echo $this->SubTableStart();
  92       echo "<tr>\n";
  93       echo $this->orderHeader("", $lang['AdrName'],$this->link2);
  94       echo $this->orderHeader("login", $lang['User'],$this->link2);
  95       echo $this->orderHeader("last_seen", $lang['UserLastSeen'],$this->link2);
  96       echo $this->orderHeader("last_host", $lang['UserLastHost'],$this->link2);
  97       echo $this->orderHeader("disabled", $lang['UserDisabled'],$this->link2);
  98       echo "</tr>\n";
  99  
 100       $result = $this->dbconn->Exec($this->q);
 101       $n = $result->numrows();
 102       $a = 0;
 103       $line = 1;
 104       while ( ($a < $n) && ( $a < $tutos[maxshow])) {
 105         echo $this->OverviewRowStart($line);
 106         $adr = new tutos_user($this->dbconn);
 107         $uid = $result->get($a, "id");
 108         $adr = $adr->read($uid,$adr,1);
 109         echo " <td colspan=\"1\">". $adr->getLink() ."&nbsp;</td>";
 110         echo " <td colspan=\"1\" align=\"right\">". makelink("user_new.php?uid=".$uid ,$result->get($a, "login")) ."</td>";
 111         $ls = $result->getDateTime($a, "last_seen");
 112         echo " <td colspan=\"1\">". $ls->getLinkDateTime() ."</td>";
 113         $x1 =  $result->get($a, "last_host");
 114         if (strstr($x1,".") && !strstr($x1," ")) {
 115           $x2 =  @gethostbyaddr($x1);
 116         } else {
 117           $x2=$x1;
 118         }
 119         echo " <td colspan=\"1\">&nbsp;". $x1 .($x2 != $x1 ? "<br />(".$x2.")":"") ."</td>";
 120         echo " <td align=\"center\">". ($adr->disabled == 0 ? $lang['no']:$lang['yes']) ."</td>";
 121         echo $this->OverviewRowEnd($line++);
 122         unset($adr);
 123         $a++;
 124       }
 125       $result->free();
 126       echo $this->SubTableEnd();
 127       echo "</td></tr>\n";
 128     }
 129     /**
 130      * TUTOS base Table Info
 131      */
 132     Function table_info() {
 133       global $lang,$tutos;
 134  
 135       if ($tutos[useacl] == 1) {
 136         $url['acl'] = "acl_overview.php";
 137       }
 138       $url['teams'] = "team_overview.php";
 139       $url['addresses'] = "address_overview.php";
 140       $url['products'] = "product_overview.php";
 141       $url['timetrack'] = "timetrack_select.php";
 142       $url['calendar'] = "app_select.php";
 143       $url['companies'] = "company_overview.php";
 144       $url['tutos_dbs'] = "database_overview.php";
 145       $url['history'] = "history_show.php";
 146       $url['messages'] = "message_overview.php";
 147       $url['people'] = "user_overview.php";
 148  
 149       $table = array();
 150       @include ("db/table.pinc");
 151  
 152       echo "<tr>\n";
 153       echo " <th>". $lang['AdminDBTable'] ."</th>\n";
 154       echo " <th>". $lang['AdminDBCount'] ."</th>\n";
 155       echo " <th>". $lang['AdminDBTable'] ."</th>\n";
 156       echo " <th>". $lang['AdminDBCount'] ."</th>\n";
 157       echo " <th>". $lang['AdminDBTable'] ."</th>\n";
 158       echo " <th>". $lang['AdminDBCount'] ."</th>\n";
 159       echo "</tr>\n";
 160  
 161       getinfo($table);
 162       @ksort($table);
 163       $c = 0;
 164       foreach ($table as $i => $f) {
 165         if ( $c == 0 ) {
 166           echo "<tr>\n";
 167         }
 168         if ( isset($url[$f[name]]) ) {
 169           echo " <td align=\"right\">". $this->dbconn->prefix . makelink($url[$f[name]],$f[name],$f[Desc]) ."</td>";
 170         } else {
 171           echo " <td align=\"right\">". $this->dbconn->prefix . $f[name] ."</td>";
 172         }
 173         echo " <td align=\"right\">". $f['count'] ."</td>";
 174         if ( $c == 2 ) {
 175           echo "</tr>\n";
 176           $c = 0;
 177         } else {
 178           $c++;
 179         }
 180       }
 181       if ($c != 0) {
 182         echo " <td colspan=\"". (3 - $c) * 2 ."\">&nbsp;</td></tr>\n";
 183       }
 184     }
 185     /**
 186      *
 187      */
 188     Function sessions_info() {
 189       global $lang,$tutos;
 190  
 191       $n = new DateTime();
 192       $ts = $n->getTimeStamp();
 193  
 194       $handle = opendir($tutos[sessionpath]);
 195       if (! $handle ){
 196         return;
 197       }
 198  
 199       # Sessions
 200       echo "<tr>\n";
 201       echo " <th colspan=\"6\">Sessions</th>\n";
 202       echo "</tr>\n";
 203       echo "<tr><td colspan=\"6\">\n";
 204       echo $this->SubTableStart();
 205       echo "<tr>\n";
 206       echo $this->orderHeader("", $lang['AdrName'],"",1);
 207       echo $this->orderHeader("", "Path","",1);
 208       echo $this->orderHeader("", "Server","",1);
 209       echo $this->orderHeader("", $lang['UserLastSeen'],"",1);
 210       echo $this->orderHeader("", $lang['UserLastHost'],"",1);
 211       echo $this->orderHeader("", $lang['ClientBrowser'],"",1);
 212       echo $this->orderHeader("", $lang['AdminKillSession'],"",1);
 213       echo "</tr>\n";
 214       $line = 0;
 215       while (false !== ($file = readdir($handle))) { 
 216         if ( ! ereg("^sess_",$file) ) {
 217           continue;
 218         }
 219         $filename =  $tutos[sessionpath] ."/". $file;
 220         if ( filesize($filename) == 0 ) {
 221           continue;
 222         }
 223         if ( ! is_readable($filename) ) {
 224           continue;
 225         }
 226         $x = fopen($filename,'ro');
 227         $contents = fread ($x, filesize ($filename));
 228         fclose($x);
 229         $data = unserialize_session($contents);
 230  
 231         if (!isset($data['userid'])) {
 232           continue;
 233         }
 234         if (!isset($data['username'])) {
 235           continue;
 236         }
 237         if (!isset($data['path'])) {
 238           $data['path'] ="?";
 239         }
 240         if (!isset($data['client'])) {
 241           $data['client'] ="?";
 242         }
 243         if (!isset($data['server'])) {
 244           $data['server'] ="?";
 245         }
 246         if ($data['dbnr'] != $this->dbconn->db->id) {
 247           continue;
 248         }
 249         echo $this->OverviewRowStart($line);
 250         echo "<td colspan=\"1\">". makelink("address_show.php?id=".$data['userid'],$data['username']) ."</td>\n";
 251         echo "<td colspan=\"1\">". $data['path'] ."</td>\n";
 252         echo "<td colspan=\"1\">". $data['server'] ."</td>\n";
 253         echo "<td colspan=\"1\" align=\"right\">". ($ts - $data['lastseen']) ." seconds ago</td>\n";
 254  
 255         $x1 =  $data['lasthost'];
 256         if (strstr($x1,".") && !strstr($x1," ")) {
 257           $x2 =  @gethostbyaddr($x1);
 258         } else {
 259           $x2=$x1;
 260         }
 261         echo "<td colspan=\"1\">". $x1.($x2 != $x1 ? "<br />(".$x2.")":"") ."</td>\n";
 262         echo "<td colspan=\"1\">". $data['client'] ."</td>\n";
 263         $u= addUrlParameter($this->link2,"action=kill");
 264         $u= addUrlParameter($u,"mark=".$file);
 265         echo "<td colspan=\"1\" align=\"center\">&nbsp;". makelink($u,"kill") ."</td>\n";
 266         echo $this->OverviewRowEnd($line++);
 267  #       print_r ($data);
 268       }
 269       echo $this->SubTableEnd();
 270       echo "</td></tr>\n";
 271       closedir($handle); 
 272     }
 273     /**
 274      *
 275      */
 276     Function info() {
 277       global $lang,$tutos;
 278  
 279       $this->link2 = "admin_show.php";
 280       if ( ! $this->user->isAdmin() ) {
 281         echo $this->error("Only admins are allowed to see this");
 282         if ( $tutos[demo] == 1 ) {
 283           echo $this->error("exceptionally enabled for this demo");
 284         } else {
 285           return;
 286         }
 287       }
 288       echo $this->DataTableStart();
 289       echo "<tr>\n";
 290       echo " <th colspan=\"6\">". $lang['AdminDBInfo'] ." : ". $this->dbconn->db->alias ."</th>\n";
 291       echo "</tr>\n";
 292       echo "<tr>\n";
 293       echo $this->showfield($lang['AdminDBName']);
 294       echo $this->showdata($this->dbconn->db->getLink($this->dbconn->db->name),2);
 295       echo $this->showfield($lang['AdminDBUser']);
 296       echo $this->showdata($this->dbconn->db->user,2);
 297       echo "</tr>\n";
 298  
 299       echo "<tr>\n";
 300       if ( $this->dbconn->gettype() == "Oracle" ) {
 301         echo $this->showfield($lang['AdminDBHome']);
 302         echo $this->showdata($this->dbconn->db->home,5);
 303       } else {
 304         echo $this->showfield($lang['AdminDBHost']);
 305         echo $this->showdata($this->dbconn->db->host,2);
 306         if ( $this->dbconn->gettype() == "Postgres" ) {
 307           echo $this->showfield($lang['AdminDBPort']);
 308           echo $this->showdata($this->dbconn->db->port,2);
 309         } else {
 310           echo " <td colspan=\"3\">&nbsp;</td>\n";
 311         }
 312       }
 313       echo "</tr>\n";
 314  
 315       echo "<tr>\n";
 316       echo $this->showfield($lang['AdminDBInfo']);
 317       echo $this->showdata($this->dbconn->moreinfo(),6);
 318       echo "</tr>\n";
 319  
 320       # The baseurl for this installation
 321       echo "<tr>\n";
 322       echo $this->showfield("BaseURL");
 323       echo $this->showdata(makelink(getBaseUrl(true),getBaseUrl(true)),6);
 324       echo "</tr>\n";
 325  
 326       $this->table_info();
 327  
 328       echo "<tr>\n";
 329       echo " <th colspan=\"4\">Known Modules</th>\n";
 330       echo " <th>". $lang['AdminDBTable'] ."</th>\n";
 331       echo " <th>" .$lang['AdminDBCount'] ."</th>\n";
 332       echo "</tr>\n";
 333       $line = 0;
 334       foreach ($tutos[modules] as $i => $f) {
 335         echo $this->OverviewRowStart($line);
 336         $table = array();
 337         echo " <td valign=\"top\" align=\"left\">";
 338         if ($tutos[$f['perm']] == 0) {
 339           echo "<strike>\n";
 340         }
 341         if ( isset ($f['overview']) ) {
 342           echo makelink($f['overview'],$f[name]);
 343         } else {
 344           echo $f[name];
 345         }
 346         if ($tutos[$f['perm']] == 0) {
 347           echo "</strike>\n";
 348         }
 349         echo "</td>\n";
 350         echo " <td valign=\"top\" colspan=\"2\" align=\"left\">". $f[Desc] ."</td>\n";
 351  
 352         echo " <td valign=\"top\" align=\"left\">&nbsp;";
 353         if (isset($f[file])) {
 354           if (file_exists(dirname($tutos['base'] ."/". $tutos[modules][$i][file]) ."/mtable.pinc") ) {
 355             include dirname($tutos['base'] ."/". $tutos[modules][$i][file]) ."/mtable.pinc";
 356           }
 357           echo $f[file];
 358         } else {
 359           echo "-";
 360         }
 361         echo "</td>\n";
 362         echo " <td align=\"right\">&nbsp;";
 363         $pre = "";
 364         foreach($table as $i2 => $f2) {
 365           echo $pre. $this->dbconn->prefix . $f2[name];
 366           $pre = "<br />\n";
 367         }
 368         echo "</td>\n";
 369         echo " <td align=\"right\">&nbsp;";
 370         $pre = "";
 371         foreach($table as $i2 => $f2) {
 372           echo $pre . getTableCount($f2[name],$this->dbconn);
 373           $pre = "<br />\n";
 374         }
 375         echo "</td>\n";
 376         echo $this->OverviewRowEnd($line++);
 377       }
 378  
 379  
 380       echo "<tr><td colspan=\"7\">&nbsp;</td></tr>\n";
 381       $this->login_info();
 382       echo "<tr><td colspan=\"7\">&nbsp;</td></tr>\n";
 383       $this->sessions_info();
 384  
 385       echo $this->DataTableEnd();
 386     }
 387     /**
 388      * navigation
 389      */
 390     Function navigate() {
 391     }
 392     /**
 393      * action
 394      */
 395     Function action() {
 396       global $msg,$lang,$tutos;
 397  
 398       if ( $_GET['action'] == "kill" ) {
 399         $file = $_GET['mark'];
 400         if ( ! ereg("^sess_",$file) ) {
 401           return;
 402         }
 403         $filename =  $tutos[sessionpath] ."/". $file;
 404         if ( filesize($filename) == 0 ) {
 405           return;
 406         }
 407         if ( ! is_readable($filename) ) {
 408           return;
 409         }
 410         $x = fopen($filename,'ro');
 411         $contents = fread ($x, filesize ($filename));
 412         fclose($x);
 413         $data = unserialize_session($contents);
 414  
 415         if (!isset($data['userid'])) {
 416           return;
 417         }
 418         if (!isset($data['username'])) {
 419           return;
 420         }
 421         if ( ! $this->user->isAdmin() ) {
 422           $msg .= "Session for ". $data['username'] ." NOT killed\nOnly superusers are allowed to kill sessions";
 423         } else {
 424           $msg .= "Session for ". $data['username'] ." killed";
 425             unlink($filename);
 426         }
 427       }
 428     }
 429     /**
 430      * preparation
 431      */
 432     Function prepare() {
 433       global $tutos,$lang;
 434  
 435       $this->name = $lang['AdminShow'];
 436       $this->q = "SELECT * from ". $this->dbconn->prefix ."people WHERE last_seen is not null";
 437       # sorting
 438       $xxx = "";
 439       order_parse($this->q,$xxx,$xxx,$xxx,"last_seen DESC");
 440       # display default sortorder
 441       if (!isset($_GET['xf'])) {
 442         $_GET['xf'] = "last_seen";
 443         $_GET['xo'] = 2;
 444       }
 445  
 446  
 447       $x = array( url => "user_new.php",
 448                   text => $lang['UserCreate'],
 449                   info => $lang['UserCreate'],
 450                   category => array("user","new")
 451                 );
 452       $this->addMenu($x);
 453       if ($tutos[useacl] == 1) {
 454         $x = array( url => "acl_overview.php",
 455                     text => $lang['ACLOverview'],
 456                     info => $lang['ACLOverview'],
 457                     category => array("admin")
 458                   );
 459       $this->addMenu($x);
 460       }
 461       if ($tutos[usesync] == 1) {
 462         $x = array( url => "admin_sync.php",
 463                     text => $lang['AdminDBSync'],
 464                     info => $lang['AdminDBSync'],
 465                     category => array("admin")
 466                   );
 467         $this->addMenu($x);
 468       }
 469  
 470       $x = array( url => "admin/phpinfo.php",
 471                   text => "< PHP - Info >",
 472                   info => "PHP - Info for this TUTOS",
 473                   'target' => "admin",
 474                   category => array("admin")
 475                 );
 476       $this->addMenu($x);
 477  
 478  
 479       if ( $this->user->isadmin() && function_exists("eaccelerator")) {
 480         $x = array( url => "admin/eaccelerator.php",
 481                     text => "< Eaccelerator Info >",
 482                     info => "Info about optimization",
 483                    'target' => "admin",
 484                    category => array("admin")
 485         );
 486         $this->addMenu($x);
 487       }
 488  
 489  
 490       $x = array( url => "module_overview.php",
 491                   text => "Modules",
 492                   info => "a list of all TUTOS modules",
 493  #                 'target' => "_blank",
 494                   category => array("admin")
 495                 );
 496       $this->addMenu($x);
 497     }
 498   }
 499