5 Commits

Author SHA1 Message Date
eleksir
ee4ac8a429 Added tag v2.1.0 for changeset 6db9ff3d18c2 2017-03-26 01:44:16 +03:00
eleksir
5c6fdef0b6 * Changed EOL to UNIX type
* Refactor code to respect OOP coding style, now we have interface and class here!
2017-03-26 01:43:27 +03:00
eleksir
16c3e42635 Added tag v2.0.0 for changeset 0a90758f5df3 2017-03-18 16:15:31 +03:00
eleksir
fbc8445b73 Added link shortener feature.
Now app can either handle pastes or shorten links, but not both.
2017-03-18 16:14:52 +03:00
eleksir
cd72ee3124 Added tag v1.1.0 for changeset 4db108cffb1f 2017-03-18 12:21:00 +03:00
4 changed files with 544 additions and 386 deletions

View File

@@ -1 +1,4 @@
b66e758d981314bfd9de6dbfe0385785908a884c v1.0.0 b66e758d981314bfd9de6dbfe0385785908a884c v1.0.0
4db108cffb1f05d2c42ff71e22d6c2330b4f45ad v1.1.0
0a90758f5df3d039490b57fad1091af22fb47524 v2.0.0
6db9ff3d18c27c2f7c08ed4104d6cbc05ca8bf86 v2.1.0

View File

@@ -1,9 +1,11 @@
## Paste. ## ## Paste. ##
This is pastebin replacement. It does not use ads, it is opensource it is relatively small. This is pastebin replacement. It does not use ads, it is opensource, it is relatively small.
And it has minimal pastebin API stub, at least pastebinit can paste to it with minimal config changes. And it has minimal pastebin API stub, at least pastebinit can paste to it with minimal config changes.
Besides pastebinit there are 2 cli clients available on main page of this app. Besides pastebinit there are 2 cli clients available on main page of this app.
And as a bonus this app can short links too! But it either shorts links **or** stores paste, not both at same time.
### How do I get set up? ### ### How do I get set up? ###
This paste utilizes PDO SQLite driver, well, at least for now :) and mbstrings. This paste utilizes PDO SQLite driver, well, at least for now :) and mbstrings.
@@ -11,7 +13,11 @@ Tested php versions are 5.6.30 and 7.0.12. Paste uses **paste/paste.sqlite** fil
Tested on apache/fcgid (windows) for dev and nginx/php-fpm for prod. Tested on apache/fcgid (windows) for dev and nginx/php-fpm for prod.
Default installation assumes that paste runs as / app on site, but you can change it (BASEURL) in index.php. Default installation assumes that paste runs as / app on site, but you can change it (BASEURL) in app.ini.
#### Settings for paste mode ####
edit app.ini and set correct address, base url, db path, application type (type = paste)
Nginx config snippet: Nginx config snippet:
``` ```
@@ -43,7 +49,39 @@ location / {
} }
``` ```
Database initialises automatically :) Database initializes automatically :)
#### Settings for link shortener mode ####
edit app.ini and set correct address, base url, db path, application type (type = short)
Nginx config snippet:
```
# limit links size to ~ 50k
client_max_body_size 64k;
rewrite "^/([a-z|A-Z]*)$" /index.php?$1;
location / {
root /var/www/htdocs/empty;
index index.php;
location ~ \.php$ {
if ($request_method !~ ^(GET|HEAD|POST)$ ) {
return 499;
}
root /var/www/htdocs;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
#NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
fastcgi_index index.php;
include fastcgi.conf;
fastcgi_pass php;
}
}
```
Database initializes automatically :)
### Contribution guidelines ### ### Contribution guidelines ###
@@ -52,7 +90,7 @@ Clean code, preferably with comments for some quirky places.
### PasteBinIt configuration ### ### PasteBinIt configuration ###
default pastebin site, __~/.pastebinit.xml__: default pastebin site, __~/.pastebinit.xml__:
``` ```xml
<pastebinit> <pastebinit>
<pastebin>http://your.site</pastebin> <pastebin>http://your.site</pastebin>
<author>Stephane Graber</author> <author>Stephane Graber</author>
@@ -61,7 +99,7 @@ default pastebin site, __~/.pastebinit.xml__:
</pastebinit> </pastebinit>
``` ```
and how to work with it __~/.pastebinit.d/your.site.conf__: and how to work with it __~/.pastebinit.d/your.site.conf__:
``` ```ini
[pastebin] [pastebin]
basename = your.site basename = your.site
regexp = http://((([a-zA-Z0-9\-_\.]*)(your\.site))) regexp = http://((([a-zA-Z0-9\-_\.]*)(your\.site)))
@@ -115,4 +153,11 @@ diff -ruN pastebin.com.conf your.site.conf
-page = /api/api_post.php -page = /api/api_post.php
+page = / +page = /
regexp = (.*) regexp = (.*)
``` ```
### TODO ###
* Make one app that shorten links, stores paste, stores pictures (yes! image hosting).
* Configurable features (not everyone wants all features enabled).
* Before implementing picture storage, there should be made authorization.
* Sane and clear API.

View File

@@ -1,15 +1,14 @@
[app] [app]
; either "paste" or "shortener" ; either "paste" or "short"
; reserved for future releases, not used
type = paste type = paste
; relative path to application, as it seen in browser ; relative path to application, as it seen in browser
; must end with '/' ; must end with '/'
baseurl = / baseurl = /
; if you decide to put images|css on separate domain, write it here ; if you decide to put images|css on separate domain, write it here
; or leave it same as siteaddress ; or leave it same as siteaddress
; for now it is only /bg_logo.png ; for now it is only /bg_logo.png for paste and /logo.png for link shortener
cdnaddress = http://127.0.0.1/ cdnaddress = http://127.0.0.1/
; hostname where app lives, with http(s) prefix ; hostname where app lives, with http(s) prefix
siteaddress = http://127.0.0.1/ siteaddress = http://127.0.0.1/
; path, where db created|stored, if not exist, it will be created ; path, where db created|stored, if not exist, it will be created
dbpath = paste/paste.sqlite dbpath = data/db.sqlite

863
index.php
View File

@@ -1,376 +1,487 @@
<?php <?php
$config = parse_ini_file("app.ini");
define ('SITE_ADDRESS', $config["siteaddress"]); interface iPaste {
define ('BASEURL', $config["baseurl"]); public function showindex($text);
define ('APP_ADDRESS', substr(SITE_ADDRESS, 0, -1) . BASEURL); public function eclient();
define ('CDN_ADDRESS', $config["cdnaddress"]); public function dclient();
define ('DBPATH', $config["dbpath"]); public function query_db($q);
define ('KEY_MIN', 3); public function store_data($paste);
define ('KEY_MAX', 9); }
unset ($config);
class paste implements iPaste {
function showindex($text) { public function __construct () {
header('Content-Language: en, ru'); if (! file_exists('app.ini')) {
header('Pragma: no-cache'); print "app.ini not found, unable to run application\n";
header('Cache-Control: no-cache'); }
?>
<!DOCTYPE html> $config = parse_ini_file("app.ini");
<html lang="ru"> define ('SITE_ADDRESS', $config["siteaddress"]);
<head> define ('BASEURL', $config["baseurl"]);
<style> define ('APP_ADDRESS', substr(SITE_ADDRESS, 0, -1) . BASEURL);
body { background-color: #adc0fc; text-align: center; } define ('CDN_ADDRESS', $config["cdnaddress"]);
textarea { define ('DBPATH', $config["dbpath"]);
background-image: url("<?php print CDN_ADDRESS; ?>bg_logo.png"); define ('KEY_MIN', 3);
background-repeat: no-repeat; define ('KEY_MAX', 9);
background-position: center center; define ('APP_TYPE', $config["type"]);
width: 90%; unset ($config);
height: 70vh;
} if (! file_exists(dirname(DBPATH))) {
</style> mkdir(dirname(DBPATH), 0777, true);
<title>Slack paste.</title> }
</head>
<body> $dbh = new PDO("sqlite:" . DBPATH);
<h3>Slack Paste</h3>
<form method="post" action="<?php print APP_ADDRESS; ?>" enctype="multipart/form-data"> $r = $dbh->exec(
<textarea name="exs" id="textbox" autofocus></textarea><br /> "CREATE TABLE IF NOT EXISTS paste (
<input type="submit" value="Post it!" style="font-size:115%;" /> for id TEXT PRIMARY KEY,
<select name="etime" style="font-size: 85%; text-align:left;"> paste TEXT,
<option value="1" style="font-size: 85%; text-align:left;">1 Hour</option> time INTEGER,
<option value="2" style="font-size: 85%; text-align:left;">12 Hours</option> etime INTEGER
<option value="3" style="font-size: 85%; text-align:left;">1 day</option> )"
<option value="4" style="font-size: 85%; text-align:left;">1 week</option> );
<option value="5" style="font-size: 85%; text-align:left;">1 Month</option>
<option value="6" style="font-size: 85%; text-align:left;">3 Months</option> if ($r === false) {
<option value="7" selected style="font-size: 85%; text-align:left;">6 Months</option> $e = $r->errorInfo();
<option value="8" style="font-size: 85%; text-align:left;">1 Year</option> self::showindex($e[2]);
<option value="9" style="font-size: 85%; text-align:left;">2 Years</option> }
<option value="10" style="font-size: 85%; text-align:left;">3 Years</option>
</select> $dbh = null;
</form> }
<?php
if ($text != '') { public function showindex ($text) {
printf (" <p><table align=\"center\" frame=\"void\" border=\"0\"><td>%s</td></table></p>\n", $text); header('Content-Language: en, ru');
} header('Pragma: no-cache');
?> header('Cache-Control: no-cache');
<p style="font-size: small;">
Console client can be found here: <a href="<?php print APP_ADDRESS; ?>e"><?php print APP_ADDRESS; ?>e</a>&nbsp; &nbsp; thanks <a href="http://sprunge.us">sprunge.us</a> for their client :)<br/> if (APP_TYPE == 'paste') {
More minimalist console client can be found here: <a href="<?php print APP_ADDRESS; ?>d"><?php print APP_ADDRESS; ?>d</a><br/> ?>
<br/> <!DOCTYPE html>
2015 <html lang="ru">
</p> <head>
</body> <style>
</html> body { background-color: #adc0fc; text-align: center; }
<?php textarea {
} background-image: url("<?php print CDN_ADDRESS; ?>bg_logo.png");
background-repeat: no-repeat;
function eclient() { background-position: center center;
header('Content-Language: en, ru'); width: 90%;
header('Content-Type: text/plain'); height: 70vh;
header('Content-Disposition: attachment; filename="e"'); }
?> </style>
#!/bin/bash <title>Slack paste.</title>
</head>
usage() { <body>
description | fmt -s >&2 <h3>Slack Paste</h3>
} <form method="post" action="<?php print APP_ADDRESS; ?>" enctype="multipart/form-data">
<textarea name="exs" id="textbox" autofocus></textarea><br />
description() { <input type="submit" value="Post it!" style="font-size:115%;" />
cat << HERE for
<select name="etime" style="font-size:115%; text-align:left;">
DESCRIPTION <option value="1" style="font-size: 85%; text-align:left;">1 Hour</option>
Upload data and fetch URL from the pastebin http://p.dafuq.ru/ <option value="2" style="font-size: 85%; text-align:left;">12 Hours</option>
<option value="3" style="font-size: 85%; text-align:left;">1 day</option>
USAGE <option value="4" style="font-size: 85%; text-align:left;">1 week</option>
$0 filename.txt <option value="5" style="font-size: 85%; text-align:left;">1 Month</option>
$0 text string <option value="6" style="font-size: 85%; text-align:left;">3 Months</option>
$0 < filename.txt <option value="7" selected style="font-size: 85%; text-align:left;">6 Months</option>
piped_data | $0 <option value="8" style="font-size: 85%; text-align:left;">1 Year</option>
<option value="9" style="font-size: 85%; text-align:left;">2 Years</option>
NOTES <option value="10" style="font-size: 85%; text-align:left;">3 Years</option>
-------------------------------------------------------------------------- </select>
* INPUT METHODS * </form>
$0 can accept piped data, STDIN redirection [<filename.txt], text strings following the command as arguments, or filenames as arguments. Only one of these methods can be used at a time, so please see the note on precedence. Also, note that using a pipe or STDIN redirection will treat tabs as spaces, or disregard them entirely (if they appear at the beginning of a line). So I suggest using a filename as an argument if tabs are important either to the function or readability of the code. <?php
if ($text != '') {
* PRECEDENCE * printf (" <p><table align=\"center\" frame=\"void\" border=\"0\"><td>%s</td></table></p>\n", $text);
STDIN redirection has precedence, then piped input, then a filename as an argument, and finally text strings as an arguments. }
?>
EXAMPLE: <p style="font-size: small;">
echo piped | "$0" arguments.txt < stdin_redirection.txt Console client can be found here: <a href="<?php print APP_ADDRESS; ?>e"><?php print APP_ADDRESS; ?>e</a>&nbsp; &nbsp; thanks <a href="http://sprunge.us">sprunge.us</a> for their client :)<br/>
More minimalist console client can be found here: <a href="<?php print APP_ADDRESS; ?>d"><?php print APP_ADDRESS; ?>d</a><br/>
In this example, the contents of file_as_stdin_redirection.txt would be uploaded. Both the piped_text and the file_as_argument.txt are ignored. If there is piped input and arguments, the arguments will be ignored, and the piped input uploaded. <br/>
2015
* FILENAMES * </p>
If a filename is misspelled or doesn\'t have the necessary path description, it will NOT generate an error, but will instead treat it as a text string and upload it. </body>
-------------------------------------------------------------------------- </html>
<?php
HERE } elseif (APP_TYPE == 'short') {
exit ?>
} <!DOCTYPE html>
<html lang="ru">
if [ -t 0 ]; then <head>
echo Running interactively, checking for arguments... >&2 <meta charset="UTF-8" />
if [ "$*" ]; then <style>
echo Arguments present... >&2 * {
if [ -f "$*" ]; then margin: 10px;
echo Uploading the contents of "$*"... >&2 text-align: center;
cat "$*" font-size: 14pt;
else }
echo Uploading the text: \""$*"\"... >&2 html, body {
echo "$*" background-color: #adc0fc; text-align: center;
fi | curl -F "exs=<-" <?php print SITE_ADDRESS; ?> }
else </style>
echo No arguments found, printing USAGE and exiting. >&2 <title>Link Shortener</title>
usage </head>
fi <body>
else <img src="<?php print CDN_ADDRESS; ?>logo.png" />
echo Using input from a pipe or STDIN redirection... >&2
while read -r line ; do <form method="post" action="<?php print APP_ADDRESS; ?>">
echo $line Shorten this link:<br />
done | curl -F "exs=<-" <?php print SITE_ADDRESS; ?> <input type="text" maxlength="768" name="exs" style="font-size: 110%; width:45%;" autofocus/></br />
fi <input type="submit" value="Submit" style="font-size: 85%;" />
<?php for
exit; <select name="etime" style="font-size: 85%; text-align:left;">
} <option value="1" style="font-size: 85%; text-align:left;">1 Hour</option>
<option value="2" style="font-size: 85%; text-align:left;">12 Hours</option>
function dclient() { <option value="3" style="font-size: 85%; text-align:left;">1 day</option>
header('Content-Language: en, ru'); <option value="4" style="font-size: 85%; text-align:left;">1 week</option>
header('Content-Type: text/plain'); <option value="5" style="font-size: 85%; text-align:left;">1 Month</option>
header('Content-Disposition: attachment; filename="d";'); <option value="6" style="font-size: 85%; text-align:left;">3 Months</option>
?> <option value="7" selected style="font-size: 85%; text-align:left;">6 Months</option>
#!/usr/bin/env bash <option value="8" style="font-size: 85%; text-align:left;">1 Year</option>
<option value="9" style="font-size: 85%; text-align:left;">2 Years</option>
if [[ "$1" == "--help" ]]; then <option value="10" style="font-size: 85%; text-align:left;">3 Years</option>
echo "Usage: $0 < file" </select>
echo " echo foo | $0" </form>
elif [[ -f "$1" ]]; then <?php
curl -F "exs=<-" "<?php print SITE_ADDRESS; ?>" <"$1" if ($text != '') {
else printf (" <table style=\"margin: 0px auto;\"><td>%s</td></table>\n", $text);
curl -F "exs=<-" "<?php print SITE_ADDRESS; ?>" }
fi ?>
</body>
exit 0 </html>
'; <?php
<?php }
exit; }
}
public function eclient () {
function gen_id() { header('Content-Language: en, ru');
$urllen = rand (KEY_MIN, KEY_MAX); header('Content-Type: text/plain');
$string = ''; header('Content-Disposition: attachment; filename="e"');
$a = Array(); $a = array_merge(range('A', 'Z'), range('a', 'z')); ?>
#!/bin/bash
for($i = 0; $i < $urllen; $i++){
$string .= $a[rand (0, count($a) - 1)]; usage() {
} description | fmt -s >&2
}
return($string);
} description() {
cat << HERE
function init_db() {
# we init db, eh? drop db file and re-create it! DESCRIPTION
if (file_exists(DBPATH)) { unlink(DBPATH); } Upload data and fetch URL from the pastebin http://p.dafuq.ru/
if (! file_exists(dirname(DBPATH))) { mkdir(dirname(DBPATH), 0777, true); }
USAGE
$dbh = new PDO("sqlite:" . DBPATH); $0 filename.txt
$0 text string
$r = $dbh->exec( $0 < filename.txt
"CREATE TABLE IF NOT EXISTS paste ( piped_data | $0
id TEXT PRIMARY KEY,
paste TEXT, NOTES
time INTEGER, --------------------------------------------------------------------------
etime INTEGER * INPUT METHODS *
)" $0 can accept piped data, STDIN redirection [<filename.txt], text strings following the command as arguments, or filenames as arguments. Only one of these methods can be used at a time, so please see the note on precedence. Also, note that using a pipe or STDIN redirection will treat tabs as spaces, or disregard them entirely (if they appear at the beginning of a line). So I suggest using a filename as an argument if tabs are important either to the function or readability of the code.
);
* PRECEDENCE *
if($r === false) { STDIN redirection has precedence, then piped input, then a filename as an argument, and finally text strings as an arguments.
$e = $r->errorInfo();
showindex($e[2]); EXAMPLE:
} echo piped | "$0" arguments.txt < stdin_redirection.txt
$dbh = null; In this example, the contents of file_as_stdin_redirection.txt would be uploaded. Both the piped_text and the file_as_argument.txt are ignored. If there is piped input and arguments, the arguments will be ignored, and the piped input uploaded.
}
* FILENAMES *
function query_db($q) { If a filename is misspelled or doesn\'t have the necessary path description, it will NOT generate an error, but will instead treat it as a text string and upload it.
if (! file_exists(DBPATH)) { --------------------------------------------------------------------------
init_db();
return false; HERE
} exit
}
$dbh = new PDO("sqlite:" . DBPATH);
$sth = $dbh->query("SELECT paste FROM paste WHERE id='$q'"); if [ -t 0 ]; then
echo Running interactively, checking for arguments... >&2
if ($sth === false) { if [ "$*" ]; then
$e = $r->errorInfo(); echo Arguments present... >&2
showindex($e[2]); if [ -f "$*" ]; then
exit; echo Uploading the contents of "$*"... >&2
} cat "$*"
else
$sth->setFetchMode(PDO::FETCH_ASSOC); echo Uploading the text: \""$*"\"... >&2
$data = $sth->fetch(); echo "$*"
$dbh = null; fi | curl -F "exs=<-" <?php print SITE_ADDRESS; ?>
else
if ($data === false) { echo No arguments found, printing USAGE and exiting. >&2
return($data); usage
} else { fi
if (isset($data['etime']) and ($data['etime'] < time())){ else
return false; echo Using input from a pipe or STDIN redirection... >&2
} while read -r line ; do
echo $line
$data = $data['paste']; done | curl -F "exs=<-" <?php print SITE_ADDRESS; ?>
return($data); # false if no data or no key in db fi
} <?php
} exit;
}
function store_data($paste) {
if (! file_exists(DBPATH)) { init_db(); } public function dclient () {
$dbh = new PDO("sqlite:" . DBPATH); header('Content-Language: en, ru');
$q = 0; header('Content-Type: text/plain');
header('Content-Disposition: attachment; filename="d";');
do { ?>
if ($q > 100) { # assume key-value space depleted if we try more than 100 times #!/usr/bin/env bash
$q = false;
break; if [[ "$1" == "--help" ]]; then
} echo "Usage: $0 < file"
$id = gen_id(); echo " echo foo | $0"
$q++; elif [[ -f "$1" ]]; then
} while (! $dbh->query("SELECT id FROM paste WHERE id='$id'")); curl -F "exs=<-" "<?php print SITE_ADDRESS; ?>" <"$1"
else
if($q === false) { curl -F "exs=<-" "<?php print SITE_ADDRESS; ?>"
return('Storage depleted.'); fi
}
exit 0
$ctime = time(); ';
$etime = $ctime + 14515200; <?php
exit;
if(isset($_POST['etime'])) { }
switch ($_POST['etime']) {
case '1': # 1 hour protected function gen_id () {
$etime = $ctime + 3600; $urllen = rand (KEY_MIN, KEY_MAX);
break; $string = '';
$a = Array(); $a = array_merge(range('A', 'Z'), range('a', 'z'));
case '2': # 12 hours
$etime = $ctime + 43200; for ($i = 0; $i < $urllen; $i++) {
break; $string .= $a[rand (0, count($a) - 1)];
}
case '3': # 1 day
$etime = $ctime + 86400; return($string);
break; }
case '4': # 1 week public function query_db ($q) {
$etime = $ctime + 604800; $dbh = new PDO("sqlite:" . DBPATH);
break; $sth = $dbh->query("SELECT paste FROM paste WHERE id='$q'");
case '5': # 1 month if ($sth === false) {
$etime = $ctime + 2419200; $e = $r->errorInfo();
break; self::showindex($e[2]);
exit;
case '6': # 3 months }
$etime = $ctime + 7257600;
break; $sth->setFetchMode(PDO::FETCH_ASSOC);
$data = $sth->fetch();
case '7': # 6 months $dbh = null;
$etime = $ctime + 14515200;
break; if ($data === false) {
return($data);
case '8': # 1 year } else {
$etime = $ctime + 29030400; if (isset($data['etime']) and ($data['etime'] < time())){
break; return false;
}
case '9': # 2 years
$etime = $ctime + 58060800; $data = $data['paste'];
break; return($data); # false if no data or no key in db
}
case '10': # 3 years }
$etime = $ctime + 87091200;
break; public function store_data ($paste) {
$dbh = new PDO("sqlite:" . DBPATH);
case '13': # forever $q = 0;
$etime = "null";
break; do {
} if ($q > 100) { # assume key-value space depleted if we try more than 100 times
} $q = false;
break;
$sth = $dbh->prepare("INSERT INTO paste VALUES('$id', '$paste', $ctime, $etime)"); }
$sth->execute();
$id = self::gen_id();
if ($sth === false) { $q++;
$e = $sth->errorInfo(); } while (! $dbh->query("SELECT id FROM paste WHERE id='$id'"));
showindex($e[2]);
exit; if ($q === false) {
} return('Storage depleted.');
}
$dbh = null;
return($id); $ctime = time();
} $etime = $ctime + 14515200;
$text = ''; if (isset($_POST['etime'])) {
switch ($_POST['etime']) {
if (($_SERVER['REQUEST_METHOD'] === 'GET') or ($_SERVER['REQUEST_METHOD'] === 'HEAD')) { case '1': # 1 hour
# substr returns empty string (boolean false) on error $etime = $ctime + 3600;
$str = $_SERVER['REQUEST_URI']; $str = substr($str, mb_strlen(BASEURL, 'UTF-8')); break;
if ($str == 'e') { case '2': # 12 hours
eclient(); $etime = $ctime + 43200;
exit; break;
} elseif ($str == 'd') {
dclient(); case '3': # 1 day
exit; $etime = $ctime + 86400;
} break;
# pastebin returns raw pate when paste' key prepended with /raw/, let's handle it case '4': # 1 week
if (preg_match('/^raw\//', $str) == 1) { $etime = $ctime + 604800;
$str = substr($str, mb_strlen('raw/', 'UTF-8')); break;
}
case '5': # 1 month
if ((mb_strlen($str, 'UTF-8') >= KEY_MIN) and ((mb_strlen($str, 'UTF-8') <= KEY_MAX))) { $etime = $ctime + 2419200;
if (preg_match('/^[a-z|A-Z]+$/', $str) == 1) { break;
$response = query_db($str);
case '6': # 3 months
if ($response === false) { $etime = $ctime + 7257600;
$text = 'No such paste.'; break;
} else {
header('Content-Type: text/plain'); case '7': # 6 months
print base64_decode($response); $etime = $ctime + 14515200;
exit; break;
}
} case '8': # 1 year
} $etime = $ctime + 29030400;
break;
} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_POST['exs']) and ($_POST['exs'] != '')) { case '9': # 2 years
$text = APP_ADDRESS . store_data(base64_encode($_POST['exs'])); $etime = $ctime + 58060800;
} elseif (isset($_POST['api_option'])){ # some pastebin API compatibility stuff break;
if ($_POST['api_option'] == 'paste') {
if ((isset($_POST['api_paste_code'])) and ($_POST['api_paste_code'] != '')) { case '10': # 3 years
header('Content-Type: text/plain; charset=utf-8'); $etime = $ctime + 87091200;
print mb_convert_encoding(APP_ADDRESS . store_data(base64_encode($_POST['api_paste_code'])), 'UTF-8', 'auto'); break;
exit;
} case '13': # forever
} elseif ($_POST['api_option'] == 'show_paste') { $etime = "null";
if (isset($_POST['api_paste_key'])) { break;
$str = $_POST['api_paste_key']; }
}
if ((mb_strlen($str, 'UTF-8') >= KEY_MIN) and ((mb_strlen($str, 'UTF-8') <= KEY_MAX))) {
if (preg_match('/^[a-z|A-Z]+$/', $str) == 1) { $sth = $dbh->prepare("INSERT INTO paste VALUES('$id', '$paste', $ctime, $etime)");
$response = query_db($str); $sth->execute();
if ($response === false) { if ($sth === false) {
header('Content-Type: text/plain; charset=utf-8'); $e = $sth->errorInfo();
print "Bad API request, invalid permission to view this paste or invalid api_paste_key"; self::showindex($e[2]);
exit; exit;
} else { }
header('Content-Type: text/plain');
print base64_decode($response); $dbh = null;
exit; return($id);
} }
} }
}
}
} /*
} * MAIN STARTS HERE
} else { */
# ???
} $text = '';
$p = new paste;
showindex($text);
?> if (($_SERVER['REQUEST_METHOD'] === 'GET') or ($_SERVER['REQUEST_METHOD'] === 'HEAD')) {
# substr returns empty string (boolean false) on error
$str = $_SERVER['REQUEST_URI']; $str = substr($str, mb_strlen(BASEURL, 'UTF-8'));
if (APP_TYPE == 'paste') {
if ($str == 'e') {
$p->eclient();
exit;
} elseif ($str == 'd') {
$p->dclient();
exit;
}
# pastebin returns raw paste when paste' key prepended with /raw/, let's handle it
if (preg_match('/^raw\//', $str) == 1) {
$str = substr($str, mb_strlen('raw/', 'UTF-8'));
}
}
if ((mb_strlen($str, 'UTF-8') >= KEY_MIN) and ((mb_strlen($str, 'UTF-8') <= KEY_MAX))) {
if (preg_match('/^[a-z|A-Z]+$/', $str) == 1) {
$response = $p->query_db($str);
if ($response === false) {
$text = 'No such paste.';
} else {
$response = base64_decode($response);
if (APP_TYPE == 'paste') {
header('Content-Type: text/plain');
print $response;
exit;
} elseif (APP_TYPE == 'short') {
header( "Location: " . $response, true, 301 );
}
}
}
}
} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_POST['exs']) and ($_POST['exs'] != '')) {
if (APP_TYPE == 'short') {
# I don't like loops :)
if ((preg_match('/^https?\:/', $_POST['exs']) == 1) or
(preg_match('/^s?ftps?\:/', $_POST['exs']) == 1) or
# Looks like shorten links other than http(s) or ftp is not good idea at all, but we CAN do this too.
(preg_match('/^ldaps?\:/', $_POST['exs']) == 1) or
(preg_match('/^ircs?\:/', $_POST['exs']) == 1) or
(preg_match('/^xmpp\:/', $_POST['exs']) == 1) or
(preg_match('/^mailto\:/', $_POST['exs']) == 1) or
(preg_match('/^rtmp\:/', $_POST['exs']) == 1) or
(preg_match('/^rtsp\:/', $_POST['exs']) == 1) or
(preg_match('/^rtp\:/', $_POST['exs']) == 1) or
(preg_match('/^soutcast\:/', $_POST['exs']) == 1) or
(preg_match('/^icecast\:/', $_POST['exs']) == 1) or
(preg_match('/^magnet\:/', $_POST['exs']) == 1) or
(preg_match('/^ed2k\:/', $_POST['exs']) == 1) or
(preg_match('/^ssh\:/', $_POST['exs']) == 1) or
(preg_match('/^svn\:/', $_POST['exs']) == 1) or
(preg_match('/^hg\:/', $_POST['exs']) == 1) or
(preg_match('/^git\:/', $_POST['exs']) == 1) or
(preg_match('/^smb\:/', $_POST['exs']) == 1) or
(preg_match('/^ipp\:/', $_POST['exs']) == 1) or
(preg_match('/^chrome\:/', $_POST['exs']) == 1) or # i'm doubt if this really working, but anyway
(preg_match('/^vivaldi\:/', $_POST['exs']) == 1) or # i'm doubt if this really working, but anyway
(preg_match('/^opera\:/', $_POST['exs']) == 1) or # i'm doubt if this really working, but anyway
(preg_match('/^about\:/', $_POST['exs']) == 1) or # i'm doubt if this really working, but anyway
(preg_match('/^skype\:/', $_POST['exs']) == 1)) {
$text = APP_ADDRESS . $p->store_data(base64_encode($_POST['exs']));
} else {
$text = 'Unable to short your link.';
}
} elseif (APP_TYPE == 'paste') {
$text = APP_ADDRESS . $p->store_data(base64_encode($_POST['exs']));
}
} elseif ((APP_TYPE == 'paste') and (isset($_POST['api_option']))) { # some pastebin API compatibility stuff
if ($_POST['api_option'] == 'paste') {
if ((isset($_POST['api_paste_code'])) and ($_POST['api_paste_code'] != '')) {
header('Content-Type: text/plain; charset=utf-8');
print mb_convert_encoding(APP_ADDRESS . $p->store_data(base64_encode($_POST['api_paste_code'])), 'UTF-8', 'auto');
exit;
}
} elseif ($_POST['api_option'] == 'show_paste') {
if (isset($_POST['api_paste_key'])) {
$str = $_POST['api_paste_key'];
if ((mb_strlen($str, 'UTF-8') >= KEY_MIN) and ((mb_strlen($str, 'UTF-8') <= KEY_MAX))) {
if (preg_match('/^[a-z|A-Z]+$/', $str) == 1) {
$response = $p->query_db($str);
if ($response === false) {
header('Content-Type: text/plain; charset=utf-8');
print "Bad API request, invalid permission to view this paste or invalid api_paste_key";
exit;
} else {
header('Content-Type: text/plain');
print base64_decode($response);
exit;
}
}
}
}
}
}
}
$p->showindex($text);
/*
* END OF MAIN
*/
?>