<?php
require('includes/config.php');
require('includes/functions.php');
require('includes/ettvd.class.php');
require('includes/smarty/Smarty.class.php');

$start = microtime_float();

if(get_magic_quotes_gpc()) {
   array_stripslashes($_GET);
   array_stripslashes($_POST);
   array_stripslashes($_COOKIE);
}

$script = substr(strrchr($_SERVER['PHP_SELF'], '/'), 1);

if(isset($_COOKIE['ettvd_user']) && isset($_COOKIE['ettvd_pass'])) {
   $user = $_COOKIE['ettvd_user'];
   $pass = $_COOKIE['ettvd_pass'];
   $validated = false;
   for($i = 1; defined('user'.$i.'name'); $i++) {
      if(constant('user'.$i.'name') != $user) continue;

      if(defined('user'.$i.'pass') && md5(constant('user'.$i.'pass')) == $pass) {
         $validated = true;
      }
      break;
   }
   if(!$validated || isset($_REQUEST['logout'])) {
      $expires = time() - 3600;
      setcookie('ettvd_user', false, $expires);
      setcookie('ettvd_pass', false, $expires);

      send('login.php');
   }
} else {
   if($script != 'login.php') {
      send('login.php');
   }
}

define('ERROR', 'class="error"');


$tpl   = new Smarty;
$ettvd = new ettvd($ettvd['host'], $ettvd['port'], $ettvd['pass']);

if($autorefresh > 0) $tpl->assign('autorefresh', $autorefresh);
// $tpl->assign('hubbing', true);
?>