qstr($username)." AND password="; if ((isset($md5password)) && (strlen($md5password) == 32)) /* md5-password */ $sql .= $db->qstr($md5password); elseif (isset($password)) /* plaintext-password */ $sql .= $db->qstr(md5($password)); else /* no password */ return 0; // exec query $result = $db->Execute($sql); if ($db->ErrorNo() != 0) dbError($sql); list($uid, $hits, $cfg["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(); 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; } /** * get image-code * * @param $rstr * @param $rnd * @return string */ function loginImageCode($rstr, $rnd) { return substr((hexdec(md5($_SERVER['HTTP_USER_AGENT'].$rstr.$rnd.date("F j")))), 3, 6); } /** * first Login * * @param $username * @param $password */ function firstLogin($username = '', $password = '') { global $cfg, $db; if (!isset($username)) return 0; if (!isset($password)) return 0; if ($username == '') return 0; if ($password == '') return 0; $create_time = time(); // This user is first in DB. Make them super admin. // this is The Super USER, add them to the user table $record = array( 'user_id'=>strtolower($username), 'password'=>md5($password), 'hits'=>1, 'last_visit'=>$create_time, 'time_created'=>$create_time, 'user_level'=>2, 'hide_offline'=>0, 'theme'=>$cfg["default_theme"], 'language_file'=>$cfg["default_language"], 'state'=>1 ); $sTable = 'tf_users'; $sql = $db->GetInsertSql($sTable, $record); $result = $db->Execute($sql); if ($db->ErrorNo() != 0) dbError($sql); // Test and setup some paths for the TF settings // path $tfPath = $cfg["path"]; if (!is_dir($cfg["path"])) $tfPath = getcwd() . "/downloads/"; // settings $settings = array( "path" => $tfPath, "pythonCmd" => $cfg["pythonCmd"], "perlCmd" => $cfg["perlCmd"], "bin_php" => $cfg["bin_php"], "bin_grep" => $cfg["bin_grep"], "bin_awk" => $cfg["bin_awk"], "bin_du" => $cfg["bin_du"], "bin_wget" => $cfg["bin_wget"], "bin_unrar" => $cfg["bin_unrar"], "bin_unzip" => $cfg["bin_unzip"], "bin_cksfv" => $cfg["bin_cksfv"], "bin_vlc" => $cfg["bin_vlc"], "bin_uudeview" => $cfg["bin_uudeview"], "btclient_transmission_bin" => $cfg["btclient_transmission_bin"], "bin_netstat" => $cfg["bin_netstat"], "bin_sockstat" => $cfg["bin_sockstat"] ); // binaries to test $binaries = array( "pythonCmd" => $cfg["pythonCmd"], "perlCmd" => $cfg["perlCmd"], "bin_php" => $cfg["bin_php"], "bin_grep" => $cfg["bin_grep"], "bin_awk" => $cfg["bin_awk"], "bin_du" => $cfg["bin_du"], "bin_wget" => $cfg["bin_wget"], "bin_unrar" => $cfg["bin_unrar"], "bin_unzip" => $cfg["bin_unzip"], "bin_cksfv" => $cfg["bin_cksfv"], "bin_vlc" => $cfg["bin_vlc"], "bin_uudeview" => $cfg["bin_uudeview"], "btclient_transmission_bin" => $cfg["btclient_transmission_bin"], "bin_netstat" => $cfg["bin_netstat"], "bin_sockstat" => $cfg["bin_sockstat"] ); // bins for which $bins = array( "pythonCmd" => "python", "perlCmd" => "perl", "bin_php" => "php", "bin_grep" => "grep", "bin_awk" => "awk", "bin_du" => "du", "bin_wget" => "wget", "bin_unrar" => "unrar", "bin_unzip" => "unzip", "bin_cksfv" => "cksfv", "bin_vlc" => "vlc", "bin_uudeview" => "uudeview", "btclient_transmission_bin" => "transmissioncli", "bin_netstat" => "netstat", "bin_sockstat" => "sockstat" ); // check foreach ($binaries as $key => $value) { if (!is_file($value)) { $bin = ""; $bin = @trim(shell_exec("which ".$bins[$key])); if ($bin != "") $settings[$key] = $bin; } } // save saveSettings('tf_settings', $settings); AuditAction($cfg["constants"]["update"], "Initial Settings Updated for first login."); } ?>