diff options
-rw-r--r-- | application/controllers/file.php | 8 | ||||
-rw-r--r-- | application/controllers/tools.php | 4 | ||||
-rw-r--r-- | application/controllers/user.php | 4 | ||||
-rw-r--r-- | application/core/MY_Controller.php | 7 |
4 files changed, 14 insertions, 9 deletions
diff --git a/application/controllers/file.php b/application/controllers/file.php index 328fc551f..e1f37e0e8 100644 --- a/application/controllers/file.php +++ b/application/controllers/file.php @@ -1066,7 +1066,7 @@ class File extends MY_Controller { // Removes old files function cron() { - if (!$this->input->is_cli_request()) return; + $this->_require_cli_request(); $tarball_dir = $this->config->item("upload_path")."/special/multipaste-tarballs"; if (is_dir($tarball_dir)) { @@ -1124,7 +1124,7 @@ class File extends MY_Controller { /* remove files without database entries */ function clean_stale_files() { - if (!$this->input->is_cli_request()) return; + $this->_require_cli_request(); $upload_path = $this->config->item("upload_path"); $outer_dh = opendir($upload_path); @@ -1178,7 +1178,7 @@ class File extends MY_Controller { function nuke_id() { - if (!$this->input->is_cli_request()) return; + $this->_require_cli_request(); $id = $this->uri->segment(3); @@ -1196,7 +1196,7 @@ class File extends MY_Controller { function update_file_metadata() { - if (!$this->input->is_cli_request()) return; + $this->_require_cli_request(); $chunk = 500; diff --git a/application/controllers/tools.php b/application/controllers/tools.php index 664a9e324..845597b08 100644 --- a/application/controllers/tools.php +++ b/application/controllers/tools.php @@ -14,9 +14,7 @@ class Tools extends MY_Controller { parent::__construct(); $this->load->model('mfile'); - if (!$this->input->is_cli_request()) { - throw new \exceptions\PublicApiException("api/cli-only", "This can only be called via CLI"); - } + $this->_require_cli_request(); } function index() diff --git a/application/controllers/user.php b/application/controllers/user.php index e1c01051a..5d506f9d7 100644 --- a/application/controllers/user.php +++ b/application/controllers/user.php @@ -586,7 +586,7 @@ class User extends MY_Controller { function cron() { - if (!$this->input->is_cli_request()) return; + $this->_require_cli_request(); if ($this->config->item('actions_max_age') == 0) return; @@ -641,7 +641,7 @@ class User extends MY_Controller { function add_user() { - if (!$this->input->is_cli_request()) return; + $this->_require_cli_request(); $this->duser->require_implemented("can_register_new_users"); $error = array(); diff --git a/application/core/MY_Controller.php b/application/core/MY_Controller.php index 79d258c37..ede6577da 100644 --- a/application/core/MY_Controller.php +++ b/application/core/MY_Controller.php @@ -105,4 +105,11 @@ class MY_Controller extends CI_Controller { $this->data["user_logged_in"] = $this->muser->logged_in(); $this->data['redirect_uri'] = $this->uri->uri_string(); } + + protected function _require_cli_request() + { + if (!$this->input->is_cli_request()) { + throw new \exceptions\PublicApiException("api/cli-only", "This function can only be accessed via the CLI interface"); + } + } } |