From 40970e2cb0480cd0016a0a4f88b69d33b9c95c22 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Mon, 9 Apr 2012 00:27:17 +0200 Subject: muser: fix handling of cli clients without account Signed-off-by: Florian Pritz --- application/controllers/file.php | 11 ++--------- application/models/file_mod.php | 12 ++++++++++++ application/models/muser.php | 6 ++++-- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/application/controllers/file.php b/application/controllers/file.php index 8de08b77b..ca58c8c0e 100644 --- a/application/controllers/file.php +++ b/application/controllers/file.php @@ -36,14 +36,7 @@ class File extends CI_Controller { $this->var->latest_client = trim(file_get_contents(FCPATH.'data/client/latest')); } - // official client uses "fb-client/$version" as useragent - $clients = array("fb-client", "libcurl", "pyfb"); - foreach ($clients as $client) { - if (isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], $client) !== false) { - $this->var->cli_client = true; - break; - } - } + $this->var->cli_client = $this->file_mod->is_cli_client(); if ($this->var->cli_client) { $this->var->view_dir = "file_plaintext"; @@ -51,7 +44,7 @@ class File extends CI_Controller { $this->var->view_dir = "file"; } - if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) { + if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW']) && $_SERVER['PHP_AUTH_USER'] && $_SERVER['PHP_AUTH_PW']) { if (!$this->muser->login($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'])) { // TODO: better message echo "login failed.\n"; diff --git a/application/models/file_mod.php b/application/models/file_mod.php index 2b4142890..f804ede9b 100644 --- a/application/models/file_mod.php +++ b/application/models/file_mod.php @@ -175,6 +175,18 @@ class File_mod extends CI_Model { return true; } + function is_cli_client() + { + // official client uses "fb-client/$version" as useragent + $clients = array("fb-client", "libcurl", "pyfb"); + foreach ($clients as $client) { + if (isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], $client) !== false) { + return true; + } + } + return false; + } + // download a given ID // TODO: make smaller function download() diff --git a/application/models/muser.php b/application/models/muser.php index 5ba4b4922..0fc99ab85 100644 --- a/application/models/muser.php +++ b/application/models/muser.php @@ -56,13 +56,15 @@ class Muser extends CI_Model { if ($this->logged_in()) { return true; } else { - if ($this->file->var->cli_client) { - echo "FileBin requires you to have an account, please go to the homepage for more information."; + if ($this->file_mod->is_cli_client()) { + echo "FileBin requires you to have an account, please go to the homepage for more information.\n"; + exit(); } else { $this->session->set_flashdata("uri", $this->uri->uri_string()); redirect('user/login'); } } + exit(); } function hash_password($password) -- cgit v1.2.3-24-g4f1b