summaryrefslogtreecommitdiffstats
path: root/application/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'application/controllers')
-rw-r--r--application/controllers/Api.php (renamed from application/controllers/api.php)0
-rw-r--r--application/controllers/Main.php (renamed from application/controllers/file/file_default.php)18
-rw-r--r--application/controllers/Tools.php (renamed from application/controllers/tools.php)12
-rw-r--r--application/controllers/User.php (renamed from application/controllers/user.php)24
-rw-r--r--application/controllers/api/api_controller.php6
-rw-r--r--application/controllers/api/v2/file.php30
-rw-r--r--application/controllers/api/v2/user.php32
-rw-r--r--application/controllers/file/Multipaste.php (renamed from application/controllers/file/multipaste.php)6
-rw-r--r--application/controllers/index.html3
9 files changed, 64 insertions, 67 deletions
diff --git a/application/controllers/api.php b/application/controllers/Api.php
index 9540f1ff7..9540f1ff7 100644
--- a/application/controllers/api.php
+++ b/application/controllers/Api.php
diff --git a/application/controllers/file/file_default.php b/application/controllers/Main.php
index 9ef7d0880..2e8ab3851 100644
--- a/application/controllers/file/file_default.php
+++ b/application/controllers/Main.php
@@ -7,7 +7,7 @@
*
*/
-class File_default extends MY_Controller {
+class Main extends MY_Controller {
function __construct()
{
@@ -19,9 +19,9 @@ class File_default extends MY_Controller {
function index()
{
- if ($this->input->is_cli_request()) {
- $this->load->library("../controllers/tools");
- return $this->tools->index();
+ if (is_cli()) {
+ output_cli_usage();
+ exit;
}
// Try to guess what the user would like to do.
@@ -74,6 +74,7 @@ class File_default extends MY_Controller {
function _download()
{
+ session_write_close();
$id = $this->uri->segment(1);
$lexer = urldecode($this->uri->segment(2));
@@ -171,7 +172,7 @@ class File_default extends MY_Controller {
// autodetect the lexer for highlighting if the URL contains a / after the ID (/ID/)
// /ID/lexer disables autodetection
- $autodetect_lexer = !$lexer && substr_count(ltrim($this->uri->uri_string(), "/"), '/') >= 1;
+ $autodetect_lexer = !$lexer && preg_match('/^[^?]*\/(\?.*)?$/', $_SERVER['REQUEST_URI']);
$autodetect_lexer = $is_multipaste ? true : $autodetect_lexer;
if ($autodetect_lexer) {
$lexer = $pygments->autodetect_lexer();
@@ -376,7 +377,7 @@ class File_default extends MY_Controller {
$this->muser->require_session();
// keep the upload but require the user to login
$last_upload = $this->session->userdata("last_upload");
- if ($last_upload === false) {
+ if ($last_upload === NULL) {
$last_upload = array(
"ids" => [],
"lexer" => "",
@@ -469,6 +470,7 @@ class File_default extends MY_Controller {
function thumbnail()
{
+ session_write_close();
$id = $this->uri->segment(3);
if (!$this->mfile->valid_id($id)) {
@@ -566,7 +568,7 @@ class File_default extends MY_Controller {
private function _append_multipaste_queue()
{
$ids = $this->input->post_array("ids");
- if ($ids === false) {
+ if ($ids === null) {
$ids = [];
}
@@ -778,7 +780,7 @@ class File_default extends MY_Controller {
$last_upload = $this->session->userdata("last_upload");
- if ($last_upload === false) {
+ if ($last_upload === NULL) {
throw new \exceptions\PublicApiException("file/claim_id/last_upload-failed", "Failed to get last upload data, unable to claim uploads");
}
diff --git a/application/controllers/tools.php b/application/controllers/Tools.php
index 9e0ddfb5f..bb481db80 100644
--- a/application/controllers/tools.php
+++ b/application/controllers/Tools.php
@@ -19,17 +19,7 @@ class Tools extends MY_Controller {
function index()
{
- echo "php index.php <controller> <function> [arguments]\n";
- echo "\n";
- echo "Functions:\n";
- echo " file cron Cronjob\n";
- echo " file nuke_id <ID> Nukes all IDs sharing the same hash\n";
- echo " user cron Cronjob\n";
- echo " tools update_database Update/Initialise the database\n";
- echo "\n";
- echo "Functions that shouldn't have to be run:\n";
- echo " file clean_stale_files Remove files without database entries\n";
- echo " file update_file_metadata Update filesize and mimetype in database\n";
+ output_cli_usage();
exit;
}
diff --git a/application/controllers/user.php b/application/controllers/User.php
index d87b544c7..892bbe1b6 100644
--- a/application/controllers/user.php
+++ b/application/controllers/User.php
@@ -16,7 +16,7 @@ class User extends MY_Controller {
function index()
{
- if ($this->input->is_cli_request()) {
+ if (is_cli()) {
$this->load->library("../controllers/tools");
return $this->tools->index();
}
@@ -55,7 +55,7 @@ class User extends MY_Controller {
$this->data['redirect_uri'] = $redirect_uri;
- if ($this->input->post('process') !== false) {
+ if ($this->input->post('process') !== null) {
$username = $this->input->post('username');
$password = $this->input->post('password');
@@ -82,10 +82,10 @@ class User extends MY_Controller {
$userid = $this->muser->get_userid();
$comment = $this->input->post("comment");
- $comment = $comment === false ? "" : $comment;
+ $comment = $comment === null ? "" : $comment;
$access_level = $this->input->post("access_level");
- if ($access_level === false) {
+ if ($access_level === null) {
$access_level = "apikey";
}
@@ -188,7 +188,7 @@ class User extends MY_Controller {
$this->data['redirect_uri'] = "/";
- if ($process !== false) {
+ if ($process !== null) {
$username = $this->input->post("username");
$email = $this->input->post("email");
$password = $this->input->post("password");
@@ -302,15 +302,15 @@ class User extends MY_Controller {
$this->duser->require_implemented("can_reset_password");
$key = $this->uri->segment(3);
- if ($_SERVER["REQUEST_METHOD"] == "GET" && $key === false) {
+ if ($_SERVER["REQUEST_METHOD"] == "GET" && $key === null) {
return $this->_reset_password_username_form();
}
- if ($key === false) {
+ if ($key === null) {
return $this->_reset_password_send_mail();
}
- if ($key !== false) {
+ if ($key !== null) {
return $this->_reset_password_form();
}
}
@@ -381,7 +381,7 @@ class User extends MY_Controller {
$userid = $query["user"];
- if ($process !== false) {
+ if ($process !== null) {
$password = $this->input->post("password");
$password_confirm = $this->input->post("password_confirm");
@@ -462,7 +462,7 @@ class User extends MY_Controller {
{
$this->muser->require_access();
- if ($this->input->post("process") !== false) {
+ if ($this->input->post("process") !== null) {
$this->_save_profile();
}
@@ -584,7 +584,7 @@ class User extends MY_Controller {
foreach (array_keys($value_processor) as $field) {
$value = $this->input->post($field);
- if ($value !== false) {
+ if ($value !== null) {
$new_value = $value_processor[$field]($value);
if ($new_value !== null) {
$data[$field] = $new_value;
@@ -619,7 +619,7 @@ class User extends MY_Controller {
$this->data["hash"] = false;
$this->data["password"] = $password;
- if ($process !== false) {
+ if ($process !== null) {
if (!$password || $password !== $password_confirm) {
$error[]= "No password or passwords don't match.";
} else {
diff --git a/application/controllers/api/api_controller.php b/application/controllers/api/api_controller.php
index 2b9054b17..d615d6cec 100644
--- a/application/controllers/api/api_controller.php
+++ b/application/controllers/api/api_controller.php
@@ -9,6 +9,10 @@
namespace controllers\api;
-abstract class api_controller extends \CI_Controller {
+abstract class api_controller {
+ public function __construct() {
+ $this->CI =& get_instance();
+ }
+
}
diff --git a/application/controllers/api/v2/file.php b/application/controllers/api/v2/file.php
index 15a43fc45..3d4103f1c 100644
--- a/application/controllers/api/v2/file.php
+++ b/application/controllers/api/v2/file.php
@@ -13,13 +13,13 @@ class file extends \controllers\api\api_controller {
{
parent::__construct();
- $this->load->model('mfile');
- $this->load->model('mmultipaste');
+ $this->CI->load->model('mfile');
+ $this->CI->load->model('mmultipaste');
}
public function upload()
{
- $this->muser->require_access("basic");
+ $this->CI->muser->require_access("basic");
$files = getNormalizedFILES();
@@ -29,12 +29,12 @@ class file extends \controllers\api\api_controller {
\service\files::verify_uploaded_files($files);
- $limits = $this->muser->get_upload_id_limits();
- $userid = $this->muser->get_userid();
+ $limits = $this->CI->muser->get_upload_id_limits();
+ $userid = $this->CI->muser->get_userid();
$urls = array();
foreach ($files as $file) {
- $id = $this->mfile->new_id($limits[0], $limits[1]);
+ $id = $this->CI->mfile->new_id($limits[0], $limits[1]);
\service\files::add_uploaded_file($userid, $id, $file["tmp_name"], $file["name"]);
$ids[] = $id;
$urls[] = site_url($id).'/';
@@ -49,7 +49,7 @@ class file extends \controllers\api\api_controller {
public function get_config()
{
return array(
- "upload_max_size" => $this->config->item("upload_max_size"),
+ "upload_max_size" => $this->CI->config->item("upload_max_size"),
"max_files_per_request" => intval(ini_get("max_file_uploads")),
"max_input_vars" => intval(ini_get("max_input_vars")),
"request_max_size" => return_bytes(ini_get("post_max_size")),
@@ -58,8 +58,8 @@ class file extends \controllers\api\api_controller {
public function history()
{
- $this->muser->require_access("apikey");
- $history = \service\files::history($this->muser->get_userid());
+ $this->CI->muser->require_access("apikey");
+ $history = \service\files::history($this->CI->muser->get_userid());
foreach ($history['multipaste_items'] as $key => $item) {
foreach ($item['items'] as $inner_key => $item) {
unset($history['multipaste_items'][$key]['items'][$inner_key]['sort_order']);
@@ -73,8 +73,8 @@ class file extends \controllers\api\api_controller {
public function delete()
{
- $this->muser->require_access("apikey");
- $ids = $this->input->post_array("ids");
+ $this->CI->muser->require_access("apikey");
+ $ids = $this->CI->input->post_array("ids");
$ret = \service\files::delete($ids);
$ret = ensure_json_keys_contain_objects($ret, array("errors", "deleted"));
@@ -84,10 +84,10 @@ class file extends \controllers\api\api_controller {
public function create_multipaste()
{
- $this->muser->require_access("basic");
- $ids = $this->input->post_array("ids");
- $userid = $this->muser->get_userid();
- $limits = $this->muser->get_upload_id_limits();
+ $this->CI->muser->require_access("basic");
+ $ids = $this->CI->input->post_array("ids");
+ $userid = $this->CI->muser->get_userid();
+ $limits = $this->CI->muser->get_upload_id_limits();
return \service\files::create_multipaste($ids, $userid, $limits);
}
diff --git a/application/controllers/api/v2/user.php b/application/controllers/api/v2/user.php
index 655dc62f3..677a870c4 100644
--- a/application/controllers/api/v2/user.php
+++ b/application/controllers/api/v2/user.php
@@ -13,31 +13,31 @@ class user extends \controllers\api\api_controller {
{
parent::__construct();
- $this->load->model('muser');
+ $this->CI->load->model('muser');
}
public function apikeys()
{
- $this->muser->require_access("full");
- return \service\user::apikeys($this->muser->get_userid());
+ $this->CI->muser->require_access("full");
+ return \service\user::apikeys($this->CI->muser->get_userid());
}
public function create_apikey()
{
- $username = $this->input->post("username");
- $password = $this->input->post("password");
+ $username = $this->CI->input->post("username");
+ $password = $this->CI->input->post("password");
if ($username && $password) {
- if (!$this->muser->login($username, $password)) {
+ if (!$this->CI->muser->login($username, $password)) {
throw new \exceptions\NotAuthenticatedException("user/login-failed", "Login failed");
}
}
- $this->muser->require_access("full");
+ $this->CI->muser->require_access("full");
- $userid = $this->muser->get_userid();
- $comment = $this->input->post("comment");
- $comment = $comment === false ? "" : $comment;
- $access_level = $this->input->post("access_level");
+ $userid = $this->CI->muser->get_userid();
+ $comment = $this->CI->input->post("comment");
+ $comment = $comment === null ? "" : $comment;
+ $access_level = $this->CI->input->post("access_level");
$key = \service\user::create_apikey($userid, $comment, $access_level);
@@ -48,16 +48,16 @@ class user extends \controllers\api\api_controller {
public function delete_apikey()
{
- $this->muser->require_access("full");
+ $this->CI->muser->require_access("full");
- $userid = $this->muser->get_userid();
- $key = $this->input->post("delete_key");
+ $userid = $this->CI->muser->get_userid();
+ $key = $this->CI->input->post("delete_key");
- $this->db->where('user', $userid)
+ $this->CI->db->where('user', $userid)
->where('key', $key)
->delete('apikeys');
- $affected = $this->db->affected_rows();
+ $affected = $this->CI->db->affected_rows();
assert($affected >= 0 && $affected <= 1);
if ($affected == 1) {
diff --git a/application/controllers/file/multipaste.php b/application/controllers/file/Multipaste.php
index 50367697c..cc8ab8819 100644
--- a/application/controllers/file/multipaste.php
+++ b/application/controllers/file/Multipaste.php
@@ -20,7 +20,7 @@ class Multipaste extends MY_Controller {
$this->muser->require_access("basic");
$ids = $this->input->post_array("ids");
- if ($ids === false) {
+ if ($ids === null) {
$ids = [];
}
@@ -58,7 +58,7 @@ class Multipaste extends MY_Controller {
$ids = $this->input->post_array('ids');
$process = $this->input->post('process');
- if ($ids === false) {
+ if ($ids === null) {
$ids = [];
}
@@ -89,7 +89,7 @@ class Multipaste extends MY_Controller {
$this->muser->require_access("basic");
$ids = $this->input->post_array('ids');
- if ($ids === false) {
+ if ($ids === null) {
$ids = [];
}
diff --git a/application/controllers/index.html b/application/controllers/index.html
index c942a79ce..b702fbc39 100644
--- a/application/controllers/index.html
+++ b/application/controllers/index.html
@@ -1,3 +1,4 @@
+<!DOCTYPE html>
<html>
<head>
<title>403 Forbidden</title>
@@ -7,4 +8,4 @@
<p>Directory access is forbidden.</p>
</body>
-</html> \ No newline at end of file
+</html>