From 96aad27c4fbcf83f3052a4c62a5e0fb6e280d131 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Tue, 15 Feb 2011 18:18:13 +0100 Subject: rework cli_client support Signed-off-by: Florian Pritz --- application/controllers/file.php | 71 ++++++++++------------- application/models/file_mod.php | 25 ++++---- application/views/file_plaintext/client.php | 12 ++++ application/views/file_plaintext/delete_form.php | 2 + application/views/file_plaintext/deleted.php | 2 + application/views/file_plaintext/footer.php | 0 application/views/file_plaintext/header.php | 0 application/views/file_plaintext/html_footer.php | 5 ++ application/views/file_plaintext/html_header.php | 21 +++++++ application/views/file_plaintext/non_existent.php | 1 + application/views/file_plaintext/show_url.php | 2 + application/views/file_plaintext/too_big.php | 2 + application/views/file_plaintext/upload_error.php | 2 + application/views/file_plaintext/upload_form.php | 4 ++ 14 files changed, 97 insertions(+), 52 deletions(-) create mode 100644 application/views/file_plaintext/client.php create mode 100644 application/views/file_plaintext/delete_form.php create mode 100644 application/views/file_plaintext/deleted.php create mode 100644 application/views/file_plaintext/footer.php create mode 100644 application/views/file_plaintext/header.php create mode 100644 application/views/file_plaintext/html_footer.php create mode 100644 application/views/file_plaintext/html_header.php create mode 100644 application/views/file_plaintext/non_existent.php create mode 100644 application/views/file_plaintext/show_url.php create mode 100644 application/views/file_plaintext/too_big.php create mode 100644 application/views/file_plaintext/upload_error.php create mode 100644 application/views/file_plaintext/upload_form.php (limited to 'application') diff --git a/application/controllers/file.php b/application/controllers/file.php index f8a19f88d..c3d297716 100644 --- a/application/controllers/file.php +++ b/application/controllers/file.php @@ -24,6 +24,12 @@ class File extends CI_Controller { } elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'libcurl') !== false) { $this->var->cli_client = "curl"; } + + if ($this->var->cli_client) { + $this->var->view_dir = "file_plaintext"; + } else { + $this->var->view_dir = "file"; + } } function index() @@ -38,9 +44,6 @@ class File extends CI_Controller { $this->do_paste(); } elseif ($id != "file" && $this->file_mod->id_exists($id)) { $this->file_mod->download(); - } elseif ($this->var->cli_client) { - $this->file_mod->check_client_version(); - die("No upload or unknown ID requested.\n"); } elseif ($id && $id != "file") { $this->file_mod->non_existent(); } else { @@ -56,9 +59,9 @@ class File extends CI_Controller { $data['client_link_deb'] = base_url().'data/client/deb/'; $data['client_link_slackware'] = base_url().'data/client/slackware/'; - $this->load->view('file/header', $data); - $this->load->view('file/client', $data); - $this->load->view('file/footer', $data); + $this->load->view($this->var->view_dir.'/header', $data); + $this->load->view($this->var->view_dir.'/client', $data); + $this->load->view($this->var->view_dir.'/footer', $data); } function upload_form() @@ -68,9 +71,9 @@ class File extends CI_Controller { $data['small_upload_size'] = $this->config->item('small_upload_size'); $data['max_upload_size'] = $this->config->item('upload_max_size'); - $this->load->view('file/header', $data); - $this->load->view('file/upload_form', $data); - $this->load->view('file/footer', $data); + $this->load->view($this->var->view_dir.'/header', $data); + $this->load->view($this->var->view_dir.'/upload_form', $data); + $this->load->view($this->var->view_dir.'/footer', $data); } // Allow CLI clients to query the server for the maxium filesize so they can @@ -91,31 +94,21 @@ class File extends CI_Controller { $data["id"] = $id; if ($password != "NULL") { if ($this->file_mod->delete_id($id)) { - if ($this->var->cli_client) { - echo $id." deleted\n"; - die(); - } else { - $this->load->view('file/header', $data); - $this->load->view('file/deleted', $data); - $this->load->view('file/footer', $data); - return; - } + $this->load->view($this->var->view_dir.'/header', $data); + $this->load->view($this->var->view_dir.'/deleted', $data); + $this->load->view($this->var->view_dir.'/footer', $data); + return; } else { - if ($this->var->cli_client) { - echo 'Couldn\'t delete '.$id."\n"; - die(); - } else { - $data["msg"] = "Deletion failed. Is the password correct?"; - } + $data["msg"] = "Deletion failed. Is the password correct?"; } - } - if ($this->var->cli_client) { - die(); } else { - $this->load->view('file/header', $data); - $this->load->view('file/delete_form', $data); - $this->load->view('file/footer', $data); + if ($id && !$this->file_mod->id_exists($id)) { + $data["msg"] = "Unkown ID."; + } } + $this->load->view($this->var->view_dir.'/header', $data); + $this->load->view($this->var->view_dir.'/delete_form', $data); + $this->load->view($this->var->view_dir.'/footer', $data); } // Take the content from post instead of a file @@ -142,9 +135,9 @@ class File extends CI_Controller { } // TODO: Display nice error for cli clients if(strlen($content) > $this->config->item('upload_max_size')) { - $this->load->view('file/header', $data); - $this->load->view('file/too_big'); - $this->load->view('file/footer'); + $this->load->view($this->var->view_dir.'/header', $data); + $this->load->view($this->var->view_dir.'/too_big'); + $this->load->view($this->var->view_dir.'/footer'); return; } @@ -169,9 +162,9 @@ class File extends CI_Controller { $extension = $this->input->post('extension'); // TODO: Display nice error for cli clients if(!isset($_FILES['file'])) { - $this->load->view('file/header', $data); - $this->load->view('file/upload_error'); - $this->load->view('file/footer'); + $this->load->view($this->var->view_dir.'/header', $data); + $this->load->view($this->var->view_dir.'/upload_error'); + $this->load->view($this->var->view_dir.'/footer'); return; } if ($_FILES['file']['error'] !== 0) { @@ -181,9 +174,9 @@ class File extends CI_Controller { $filesize = filesize($_FILES['file']['tmp_name']); // TODO: Display nice error for cli clients if ($filesize > $this->config->item('upload_max_size')) { - $this->load->view('file/header', $data); - $this->load->view('file/too_big'); - $this->load->view('file/footer'); + $this->load->view($this->var->view_dir.'/header', $data); + $this->load->view($this->var->view_dir.'/too_big'); + $this->load->view($this->var->view_dir.'/footer'); return; } diff --git a/application/models/file_mod.php b/application/models/file_mod.php index f781e1676..dfb203226 100644 --- a/application/models/file_mod.php +++ b/application/models/file_mod.php @@ -126,15 +126,14 @@ class File_mod extends CI_Model { } if ($this->var->cli_client) { - echo $data['url']."\n"; + $redirect = false; + } + if ($redirect) { + redirect($data['url']); } else { - if ($redirect) { - redirect($data['url']); - } else { - $this->load->view('file/header', $data); - $this->load->view('file/show_url', $data); - $this->load->view('file/footer', $data); - } + $this->load->view($this->var->view_dir.'/header', $data); + $this->load->view($this->var->view_dir.'/show_url', $data); + $this->load->view($this->var->view_dir.'/footer', $data); } } @@ -142,9 +141,9 @@ class File_mod extends CI_Model { { $data["title"] = "Not Found"; $this->output->set_status_header(404); - $this->load->view('file/header', $data); - $this->load->view('file/non_existent', $data); - $this->load->view('file/footer', $data); + $this->load->view($this->var->view_dir.'/header', $data); + $this->load->view($this->var->view_dir.'/non_existent', $data); + $this->load->view($this->var->view_dir.'/footer', $data); } function check_client_version() @@ -239,7 +238,7 @@ class File_mod extends CI_Model { } else { $data['timeout'] = "never"; } - echo $this->load->view('file/html_header', $data, true); + echo $this->load->view($this->var->view_dir.'/html_header', $data, true); $this->load->library("MemcacheLibrary"); if (! $cached = $this->memcachelibrary->get($filedata['hash'].'_'.$mode)) { ob_start(); @@ -260,7 +259,7 @@ class File_mod extends CI_Model { $this->memcachelibrary->set($filedata['hash'].'_'.$mode, $cached, 100); } echo $cached; - echo $this->load->view('file/html_footer', $data, true); + echo $this->load->view($this->var->view_dir.'/html_footer', $data, true); } else { if ($mode == 'plain') { header("Content-Type: text/plain\n"); diff --git a/application/views/file_plaintext/client.php b/application/views/file_plaintext/client.php new file mode 100644 index 000000000..188f23379 --- /dev/null +++ b/application/views/file_plaintext/client.php @@ -0,0 +1,12 @@ +Shell: + curl -n -F "file=@/home/user/foo" (binary safe) + cat file | curl -n -F "file=@-;filename=stdin" (binary safe) + +Client: +Development (git): http://git.server-speed.net/users/flo/fb +Latest release: +GPG sigs, older versions: + +If you want to use authentication (needed for deleting) add the following to your ~/.netrc: + machine paste.xinu.at password my_secret_password + diff --git a/application/views/file_plaintext/delete_form.php b/application/views/file_plaintext/delete_form.php new file mode 100644 index 000000000..ba736078c --- /dev/null +++ b/application/views/file_plaintext/delete_form.php @@ -0,0 +1,2 @@ + + diff --git a/application/views/file_plaintext/deleted.php b/application/views/file_plaintext/deleted.php new file mode 100644 index 000000000..7c8a2a44e --- /dev/null +++ b/application/views/file_plaintext/deleted.php @@ -0,0 +1,2 @@ + has been deleted. + diff --git a/application/views/file_plaintext/footer.php b/application/views/file_plaintext/footer.php new file mode 100644 index 000000000..e69de29bb diff --git a/application/views/file_plaintext/header.php b/application/views/file_plaintext/header.php new file mode 100644 index 000000000..e69de29bb diff --git a/application/views/file_plaintext/html_footer.php b/application/views/file_plaintext/html_footer.php new file mode 100644 index 000000000..ddc460a39 --- /dev/null +++ b/application/views/file_plaintext/html_footer.php @@ -0,0 +1,5 @@ + + + + + diff --git a/application/views/file_plaintext/html_header.php b/application/views/file_plaintext/html_header.php new file mode 100644 index 000000000..52ffab007 --- /dev/null +++ b/application/views/file_plaintext/html_header.php @@ -0,0 +1,21 @@ + + + + <?php echo $title; ?> + + + + +
+ New | + Raw | + Plain | + Currently: | + Timeout: +
+ Code | + Render Markdown +
+
+ + diff --git a/application/views/file_plaintext/non_existent.php b/application/views/file_plaintext/non_existent.php new file mode 100644 index 000000000..7da92e954 --- /dev/null +++ b/application/views/file_plaintext/non_existent.php @@ -0,0 +1 @@ +I'm sorry, but the requested file doesn't exist. diff --git a/application/views/file_plaintext/show_url.php b/application/views/file_plaintext/show_url.php new file mode 100644 index 000000000..bb94d7422 --- /dev/null +++ b/application/views/file_plaintext/show_url.php @@ -0,0 +1,2 @@ + + diff --git a/application/views/file_plaintext/too_big.php b/application/views/file_plaintext/too_big.php new file mode 100644 index 000000000..d27a0295c --- /dev/null +++ b/application/views/file_plaintext/too_big.php @@ -0,0 +1,2 @@ +Sorry, the file you uploaded is too big. + diff --git a/application/views/file_plaintext/upload_error.php b/application/views/file_plaintext/upload_error.php new file mode 100644 index 000000000..8386b871b --- /dev/null +++ b/application/views/file_plaintext/upload_error.php @@ -0,0 +1,2 @@ +An error occured while uploading. Most likely your file is too big. + diff --git a/application/views/file_plaintext/upload_form.php b/application/views/file_plaintext/upload_form.php new file mode 100644 index 000000000..12d506253 --- /dev/null +++ b/application/views/file_plaintext/upload_form.php @@ -0,0 +1,4 @@ +Uploads/pastes are deleted after 5 days 0): ?> unless they are smaller than . +Maximum upload size is . + + -- cgit v1.2.3-24-g4f1b