summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2012-04-08 23:38:05 +0200
committerFlorian Pritz <bluewind@xinu.at>2012-04-09 20:47:40 +0200
commit1040dbad987e280c61134c83194832224ff870b5 (patch)
tree934bd81c43c992b6faccd3383fe17bb60519ffe0
parent4bbdd1d7737c100668c7adb952ec181f941e6a55 (diff)
Revert "Disable paste box"
Signed-off-by: Florian Pritz <bluewind@xinu.at>
-rw-r--r--application/controllers/file.php3
-rw-r--r--application/views/file/upload_form.php42
-rw-r--r--data/js/upload_form.js64
3 files changed, 86 insertions, 23 deletions
diff --git a/application/controllers/file.php b/application/controllers/file.php
index 466037833..2e8664984 100644
--- a/application/controllers/file.php
+++ b/application/controllers/file.php
@@ -217,7 +217,8 @@ class File extends CI_Controller {
$this->muser->require_access();
if ($this->uri->segment(3)) {
- exit;
+ $this->var->cli_client = true;
+ $this->var->view_dir = "file_plaintext";
}
$extension = $this->input->post('extension');
diff --git a/application/views/file/upload_form.php b/application/views/file/upload_form.php
index e1e4313a5..04f7fd9f4 100644
--- a/application/views/file/upload_form.php
+++ b/application/views/file/upload_form.php
@@ -8,35 +8,33 @@
</form>
<script type="text/javascript">
/* <![CDATA[ */
- var max_upload_size = "<?php echo $max_upload_size; ?>";
- // check file size before uploading if browser support html5
- if (window.File && window.FileList) {
- function checkFileUpload(evt) {
- var f = evt.target.files[0];
- if (f.size > max_upload_size) {
- document.getElementById('upload_button').value = "File too big";
- document.getElementById('upload_button').disabled = true;
- } else {
- document.getElementById('upload_button').value = "Upload";
- document.getElementById('upload_button').disabled = false;
- }
- }
-
- document.getElementById('file').addEventListener('change', checkFileUpload, false);
- }
- /* ]]> */
+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 and search): <input id="textarea_password" type="password" name="password" size="10" /><br />\
+ <input type="submit" value="Paste" name="process" />\
+ </p>\
+ </form>\
+');
+ var upload_url = "<?php echo site_url("file/do_upload/dumb"); ?>";
+ var max_upload_size = "<?php echo $max_upload_size; ?>";
+ /* ]]> */
</script>
+ <script type="text/javascript" src="<?php echo base_url(); ?>data/js/upload_form.js?<?php echo filemtime(FCPATH."/data/js/upload_form.js"); ?>"></script>
</div>
<br />
-<p>Uploads are deleted after <?php echo $upload_max_age; ?> days<?php if($small_upload_size > 0): ?>
+<p>Uploads/pastes are deleted after <?php echo $upload_max_age; ?> days<?php if($small_upload_size > 0): ?>
unless they are smaller than <?php echo format_bytes($small_upload_size); ?>
<?php endif; ?>. Maximum upload size is <?php echo format_bytes($max_upload_size); ?></p>
-<h2>Features</h2>
-<p>For shell uploading and download information for the client go to <a href="<?php echo site_url("file/client"); ?>"><?php echo site_url("file/client"); ?></a></p>
+<p><h2>Features</h2></p>
+<p>For shell uploading/pasting and download information for the client go to <a href="<?php echo site_url("file/client"); ?>"><?php echo site_url("file/client"); ?></a></p>
<p>You can use the <?php echo anchor("file/upload_history", "history"); ?> to find old uploads.</p>
-<p>How to link your uploads:</p>
+<p>How to link your pastes:</p>
<ul>
- <li><span class="example">/&lt;ID&gt;/</span> automatically highlight the uploads</li>
+ <li><span class="example">/&lt;ID&gt;/</span> automatically highlight the paste</li>
<li><span class="example">/&lt;ID&gt;</span> set the detected MIME type and let the browser do the rest</li>
<li><span class="example">/&lt;ID&gt;/plain</span> force the MIME type to be text/plain</li>
<li><span class="example">/&lt;ID&gt;/&lt;file extension&gt;</span> override auto detection and use the supplied file extension or language name for highlighting</li>
diff --git a/data/js/upload_form.js b/data/js/upload_form.js
new file mode 100644
index 000000000..598d86465
--- /dev/null
+++ b/data/js/upload_form.js
@@ -0,0 +1,64 @@
+// check file size before uploading if browser support html5
+if (window.File && window.FileList) {
+ function checkFileUpload(evt) {
+ var f = evt.target.files[0];
+ if (f.size > max_upload_size) {
+ document.getElementById('upload_button').value = "File too big";
+ document.getElementById('upload_button').disabled = true;
+ } else {
+ document.getElementById('upload_button').value = "Upload";
+ document.getElementById('upload_button').disabled = false;
+ }
+ }
+
+ 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 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", upload_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() {
+ if(http.readyState == 4 && http.status == 200) {
+ window.location = http.responseText;
+ }
+ }
+ http.send(body);
+}
+