summaryrefslogtreecommitdiff
path: root/index.cgi
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2010-10-07 20:31:34 +0200
committerYorhel <git@yorhel.nl>2010-10-07 20:31:34 +0200
commit9a630f3cfd8e6f280d76e86ac47d9017bde36a8b (patch)
tree7ac3aa4bb508ad10a789cbae8ae38040f1532a94 /index.cgi
parent9b1a86d82292141b7fdb5cf22313af4ce837416a (diff)
Added save-passcode-on-my-computer-option.
Diffstat (limited to 'index.cgi')
-rwxr-xr-xindex.cgi30
1 files changed, 25 insertions, 5 deletions
diff --git a/index.cgi b/index.cgi
index d5af2fc..79f5336 100755
--- a/index.cgi
+++ b/index.cgi
@@ -94,7 +94,8 @@ sub upload {
my $c = $cgi->param('c') ? 1 : 0;
my $p = $cgi->param('p') || undef;
msg('Unknown syntax code.', 'backform') if !grep $s eq $_, @syntax;
- msg('Passcode too long!', 'backform') if length($p) > 64;
+ msg("Oops! I couldn't handle your passcode. It is either too long, or it contains characters I can not handle.", 'backform')
+ if length($p) > 64 or $p && $p !~ /^[a-zA-Z0-9-_\.]+$/;
my $dat = $cgi->param('u') || $cgi->param('f') || '';
$dat =~ s/\x0D\x0A?/\n/g;
msg("Only UTF-8 encoded data is allowed!\nMake sure you're not uploading a binary file.", 'backform')
@@ -108,7 +109,8 @@ sub upload {
$db->do('INSERT INTO pastes (code, syntax, wrap, raw, html, ip, parse_urls, passcode) VALUES(?,?,?,?,?,?,?,?)',
undef, $code, $s, $w, $dat, $html, $ENV{REMOTE_ADDR}, $c, $p);
- print "Status: 303\nLocation: http://$ENV{HTTP_HOST}/$code\nContent-type: text/plain\n\nRedirecting...\n";
+ my $cookie = !$p || !$cgi->param('ps') ? '' : qq|Set-Cookie: secret_passcode=$p; path=/; expires=Wed, 07-Oct-2020 18:06:05 GMT\n|;
+ print "Status: 303\n${cookie}Location: http://$ENV{HTTP_HOST}/$code\nContent-type: text/plain\n\nRedirecting...\n";
exit;
}
@@ -186,14 +188,15 @@ sub form {
</fieldset>
<fieldset>
<legend>▾ Formatting</legend>
- <input type="checkbox" id="w" name="w" value="1" /> <label for="w">allow line wrapping</label><br />
- <input type="checkbox" id="c" name="c" value="1" checked="checked" /> <label for="c">make URLs clickable</label><br />
+ <input type="checkbox" class="check" id="w" name="w" value="1" /> <label for="w">allow line wrapping</label><br />
+ <input type="checkbox" class="check" id="c" name="c" value="1" checked="checked" /> <label for="c">make URLs clickable</label><br />
<i>Syntax highlighting:</i> <input type="text" name="s" id="s" size="10" value="nosyntax" /> <i>Popular: <b class="syntax">%s</b> | <a href="#" onclick="return showall()">Show all &raquo;</a></i>
<div id="syntax" style="display: none">%s</div>
</fieldset>
<fieldset>
<legend>▾ Passcode</legend>
- <label for="p">Passcode:</label> <input type="password" name="p" id="p" size="10" /><br />
+ <label for="p">Passcode:</label> <input type="password" name="p" id="p" size="10" />
+ <input type="checkbox" class="check" id="ps" name="ps" value="1" /> <label for="ps">save on my computer.</label><br />
<i>(Optional, necessary for listing and/or removing your pastes, which is not implemented yet...)</i>
</fieldset>
</form>
@@ -254,6 +257,17 @@ sub html {
document.getElementById('syntax').style.display = document.getElementById('syntax').style.display == 'none' ? '' : 'none';
return false;
}
+ function getCookie(n) {
+ var l = document.cookie.split(';');
+ for(var i=0; i<l.length; i++) {
+ var c = l[i];
+ while(c.charAt(0) == ' ')
+ c = c.substring(1,c.length);
+ if(c.indexOf(n+'=') == 0)
+ return c.substring(n.length+1,c.length);
+ }
+ return null;
+ }
</script>
</head>
<body>
@@ -267,6 +281,12 @@ sub html {
</td></tr>
%s
</table>
+ <script type="text/javascript">
+ var x = document.getElementById('p');
+ if(x) {
+ x.value = getCookie("secret_passcode") || '';
+ }
+ </script>
</body>
</html>
__