Example #1
0
 public function http_server()
 {
     require_once 'inc/functions/functions.common.auth.php';
     $host = getHttpServer() . getHttpServerRootURL();
     return $host;
     /*
     $host = 'http://'.$_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'];
     if (isset($_SERVER['HTTPS']))
     	$host = str_replace('http:','https:',$host);
     else
     	$host = str_replace(':80','',$host);
     return $host.'/';
     */
 }
/**
 * perform Authentication
 *
 * @param $username
 * @param $password
 * @param $md5password
 * @return int with :
 *                     1 : user authenticated
 *                     0 : user not authenticated
 */
function performAuthentication($username = '', $password = '', $md5password = '')
{
    global $cfg, $db;
    // check username
    if (!isset($username)) {
        return 0;
    }
    if ($username == '') {
        return 0;
    }
    // sql-state
    $sql = "SELECT uid, hits, hide_offline, theme, language_file FROM tf_users WHERE state = 1 AND user_id=" . $db->qstr($username) . " AND password="******"hide_offline"], $cfg["theme"], $cfg["language_file"]) = $result->FetchRow();
    if ($result->RecordCount() == 1) {
        // suc. auth.
        // Add a hit to the user
        $hits++;
        $sql = "SELECT * FROM tf_users WHERE uid = " . $db->qstr($uid);
        $rs = $db->Execute($sql);
        if ($db->ErrorNo() != 0) {
            dbError($sql);
        }
        $rec = array('hits' => $hits, 'last_visit' => $db->DBDate(time()), 'theme' => $cfg['theme'], 'language_file' => $cfg['language_file']);
        $sql = $db->GetUpdateSQL($rs, $rec);
        $result = $db->Execute($sql);
        if ($db->ErrorNo() != 0) {
            dbError($sql);
        }
        $_SESSION['user'] = $username;
        $_SESSION['uid'] = $uid;
        $cfg["user"] = $_SESSION['user'];
        $cfg['uid'] = $uid;
        @session_write_close();
        //Store server root in db
        $sql = "SELECT tf_value FROM tf_settings WHERE tf_key = 'server_name'";
        $server_name = $db->getOne($sql);
        if (!$server_name) {
            $sql = "INSERT INTO tf_settings(tf_key, tf_value) VALUES ('server_name'," . $db->qstr(getHttpServer()) . ")";
            $rs = $db->Execute($sql);
            $sql = "INSERT INTO tf_settings(tf_key, tf_value) VALUES ('server_root'," . $db->qstr(getHttpServerRootURL()) . ")";
            $rs = $db->Execute($sql);
        } else {
            $sql = "UPDATE tf_settings SET tf_value=" . $db->qstr(getHttpServer()) . " WHERE tf_key='server_name' ";
            $rs = $db->Execute($sql);
            $sql = "UPDATE tf_settings SET tf_value=" . $db->qstr(getHttpServerRootURL()) . " WHERE tf_key='server_root' ";
            $rs = $db->Execute($sql);
        }
        return 1;
    } else {
        // wrong credentials
        // log
        AuditAction($cfg["constants"]["access_denied"], "FAILED AUTH: " . $username);
        // unset
        unset($_SESSION['user']);
        unset($_SESSION['uid']);
        unset($cfg["user"]);
        // flush users cookie
        @setcookie("autologin", "", time() - 3600);
        // return
        return 0;
    }
    // return
    return 0;
}