summaryrefslogtreecommitdiffstats
path: root/application
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2011-06-06 16:01:33 +0200
committerFlorian Pritz <bluewind@xinu.at>2011-06-06 16:01:33 +0200
commit606012e782af20f00b7b19a08e924e07c34d7ec5 (patch)
treee31deecd76452cf381b3802991fc8c4b3a911e6f /application
parentc19a41faa3c81a7670b9f9e0c621c2254f7068f7 (diff)
use javascript to allow text pastes
The javascript converts the content of the textarea to a HTTP POST request and sends the text as a file upload. Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'application')
-rw-r--r--application/controllers/file.php6
-rw-r--r--application/views/file/upload_form.php72
2 files changed, 67 insertions, 11 deletions
diff --git a/application/controllers/file.php b/application/controllers/file.php
index fb219f67f..f1a4d6c08 100644
--- a/application/controllers/file.php
+++ b/application/controllers/file.php
@@ -164,6 +164,12 @@ class File extends CI_Controller {
function do_upload()
{
$data = array();
+
+ if ($this->uri->segment(3)) {
+ $this->var->cli_client = true;
+ $this->var->view_dir = "file_plaintext";
+ }
+
$extension = $this->input->post('extension');
if(!isset($_FILES['file']) || $_FILES['file']['error'] !== 0) {
$this->output->set_status_header(400);
diff --git a/application/views/file/upload_form.php b/application/views/file/upload_form.php
index 4f5a01ebc..36c9308b8 100644
--- a/application/views/file/upload_form.php
+++ b/application/views/file/upload_form.php
@@ -23,19 +23,69 @@
document.getElementById('file').addEventListener('change', checkFileUpload, false);
}
+
+function encode64(inp){
+ var key="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
+ var chr1,chr2,chr3,enc3,enc4,i=0,out="";
+ while(i<inp.length){
+ chr1=inp.charCodeAt(i++);if(chr1>127) chr1=88;
+ chr2=inp.charCodeAt(i++);if(chr2>127) chr2=88;
+ chr3=inp.charCodeAt(i++);if(chr3>127) chr3=88;
+ if(isNaN(chr3)) {enc4=64;chr3=0;} else enc4=chr3&63
+ if(isNaN(chr2)) {enc3=64;chr2=0;} else enc3=((chr2<<2)|(chr3>>6))&63
+ out+=key.charAt((chr1>>2)&63)+key.charAt(((chr1<<4)|(chr2>>4))&63)+key.charAt(enc3)+key.charAt(enc4);
+ }
+ return encodeURIComponent(out);
+}
+
+function gen_boundary() {
+ var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
+ var string_length = 40;
+ var randomstring = '';
+ for (var i=0; i<string_length; i++) {
+ var rnum = Math.floor(Math.random() * chars.length);
+ randomstring += chars.substring(rnum,rnum+1);
+ }
+ return randomstring;
+}
+function do_paste() {
+ var http = new XMLHttpRequest();
+ var url = "<?php echo site_url("file/do_upload/dumb"); ?>";
+ var CRLF = "\r\n";
+ var boundary = "--" + gen_boundary();
+ var body = "--" + boundary + CRLF
+ + 'Content-Disposition: form-data; name="file"; filename="stdin"' + CRLF
+ + "Content-Type: text/plain" + CRLF
+ + CRLF
+ + document.getElementById("textarea").value + CRLF
+ + "--" + boundary + "--" + CRLF + CRLF;
+ http.open("POST", url, true);
+
+ //Send the proper header information along with the request
+ http.setRequestHeader("Content-type", "multipart/form-data; boundary=" + boundary);
+ http.setRequestHeader("Authorization", "Basic " + encode64(":" + document.getElementById("textarea_password").value));
+
+ http.onreadystatechange = function() {//Call a function when the state changes.
+ if(http.readyState == 4 && http.status == 200) {
+ window.location = http.responseText;
+ }
+ }
+ http.send(body);
+}
+
+document.write('\
+ <p><b>OR</b></p>\
+ <form action="javascript: do_paste()">\
+ <p>\
+ <textarea id="textarea" name="content" cols="80" rows="20"></textarea><br />\
+ <div style="display: none">Email: <input type="text" name="email" size="20" /></div>\
+ Optional password (for deletion): <input id="textarea_password" type="password" name="password" size="10" /><br />\
+ <input type="submit" value="Paste" name="process" />\
+ </p>\
+ </form>\
+');
/* ]]> */
</script>
-<?php if (false): ?>
- <p><b>OR</b></p>
- <?php echo form_open_multipart('file/do_paste'); ?>
- <p>
- <textarea name="content" cols="80" rows="20"></textarea><br />
- <div style="display: none">Email: <input type="text" name="email" size="20" /></div>
- Optional password (for deletion): <input type="password" name="password" size="10" /><br />
- <input type="submit" value="Paste" name="process" />
- </p>
- </form>
-<?php endif; ?>
</div>
<br />
<p>Uploads/pastes are deleted after <?php echo $upload_max_age; ?> days<?php if($small_upload_size > 0): ?>