Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5c6fdef0b6 | ||
|
|
16c3e42635 | ||
|
|
fbc8445b73 | ||
|
|
cd72ee3124 | ||
|
|
6f3789bfdc | ||
|
|
5b1653ca11 |
3
.hgtags
Normal file
3
.hgtags
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
b66e758d981314bfd9de6dbfe0385785908a884c v1.0.0
|
||||||
|
4db108cffb1f05d2c42ff71e22d6c2330b4f45ad v1.1.0
|
||||||
|
0a90758f5df3d039490b57fad1091af22fb47524 v2.0.0
|
||||||
57
README.md
57
README.md
@@ -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.
|
||||||
|
|||||||
14
app.ini
Normal file
14
app.ini
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
[app]
|
||||||
|
; either "paste" or "short"
|
||||||
|
type = paste
|
||||||
|
; relative path to application, as it seen in browser
|
||||||
|
; must end with '/'
|
||||||
|
baseurl = /
|
||||||
|
; if you decide to put images|css on separate domain, write it here
|
||||||
|
; or leave it same as siteaddress
|
||||||
|
; for now it is only /bg_logo.png for paste and /logo.png for link shortener
|
||||||
|
cdnaddress = http://127.0.0.1/
|
||||||
|
; hostname where app lives, with http(s) prefix
|
||||||
|
siteaddress = http://127.0.0.1/
|
||||||
|
; path, where db created|stored, if not exist, it will be created
|
||||||
|
dbpath = data/db.sqlite
|
||||||
861
index.php
861
index.php
@@ -1,374 +1,487 @@
|
|||||||
<?php
|
<?php
|
||||||
define ('BASEURL', "/"); # must end with '/'
|
|
||||||
define ('KEY_MIN', 3);
|
interface iPaste {
|
||||||
define ('KEY_MAX', 9);
|
public function showindex($text);
|
||||||
define ('DBPATH', 'paste/paste.sqlite');
|
public function eclient();
|
||||||
define ('SITE_ADDRESS', 'http://127.0.0.1/');
|
public function dclient();
|
||||||
define ('CDN_ADDRESS', 'http://127.0.0.1/');
|
public function query_db($q);
|
||||||
define ('APP_ADDRESS', substr(SITE_ADDRESS, 0, -1) . BASEURL);
|
public function store_data($paste);
|
||||||
|
}
|
||||||
function showindex($text) {
|
|
||||||
header('Content-Language: en, ru');
|
class paste implements iPaste {
|
||||||
header('Pragma: no-cache');
|
public function __construct () {
|
||||||
header('Cache-Control: no-cache');
|
if (! file_exists('app.ini')) {
|
||||||
?>
|
print "app.ini not found, unable to run application\n";
|
||||||
<!DOCTYPE html>
|
}
|
||||||
<html lang="ru">
|
|
||||||
<head>
|
$config = parse_ini_file("app.ini");
|
||||||
<style>
|
define ('SITE_ADDRESS', $config["siteaddress"]);
|
||||||
body { background-color: #adc0fc; text-align: center; }
|
define ('BASEURL', $config["baseurl"]);
|
||||||
textarea {
|
define ('APP_ADDRESS', substr(SITE_ADDRESS, 0, -1) . BASEURL);
|
||||||
background-image: url("<?php print CDN_ADDRESS; ?>bg_logo.png");
|
define ('CDN_ADDRESS', $config["cdnaddress"]);
|
||||||
background-repeat: no-repeat;
|
define ('DBPATH', $config["dbpath"]);
|
||||||
background-position: center center;
|
define ('KEY_MIN', 3);
|
||||||
width: 90%;
|
define ('KEY_MAX', 9);
|
||||||
height: 70vh;
|
define ('APP_TYPE', $config["type"]);
|
||||||
}
|
unset ($config);
|
||||||
</style>
|
|
||||||
<title>Paste.</title>
|
if (! file_exists(dirname(DBPATH))) {
|
||||||
</head>
|
mkdir(dirname(DBPATH), 0777, true);
|
||||||
<body>
|
}
|
||||||
<h3>Paste</h3>
|
|
||||||
<form method="post" action="<?php print APP_ADDRESS; ?>" enctype="multipart/form-data">
|
$dbh = new PDO("sqlite:" . DBPATH);
|
||||||
<textarea name="exs" id="textbox" autofocus></textarea><br />
|
|
||||||
<input type="submit" value="Post it!" style="font-size:115%;" /> for
|
$r = $dbh->exec(
|
||||||
<select name="etime" style="font-size: 85%; text-align:left;">
|
"CREATE TABLE IF NOT EXISTS paste (
|
||||||
<option value="1" style="font-size: 85%; text-align:left;">1 Hour</option>
|
id TEXT PRIMARY KEY,
|
||||||
<option value="2" style="font-size: 85%; text-align:left;">12 Hours</option>
|
paste TEXT,
|
||||||
<option value="3" style="font-size: 85%; text-align:left;">1 day</option>
|
time INTEGER,
|
||||||
<option value="4" style="font-size: 85%; text-align:left;">1 week</option>
|
etime INTEGER
|
||||||
<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>
|
);
|
||||||
<option value="7" selected style="font-size: 85%; text-align:left;">6 Months</option>
|
|
||||||
<option value="8" style="font-size: 85%; text-align:left;">1 Year</option>
|
if ($r === false) {
|
||||||
<option value="9" style="font-size: 85%; text-align:left;">2 Years</option>
|
$e = $r->errorInfo();
|
||||||
<option value="10" style="font-size: 85%; text-align:left;">3 Years</option>
|
self::showindex($e[2]);
|
||||||
</select>
|
}
|
||||||
</form>
|
|
||||||
<?php
|
$dbh = null;
|
||||||
if ($text != '') {
|
}
|
||||||
printf (" <p><table align=\"center\" frame=\"void\" border=\"0\"><td>%s</td></table></p>\n", $text);
|
|
||||||
}
|
public function showindex ($text) {
|
||||||
?>
|
header('Content-Language: en, ru');
|
||||||
<p style="font-size: small;">
|
header('Pragma: no-cache');
|
||||||
Console client can be found here: <a href="<?php print APP_ADDRESS; ?>e"><?php print APP_ADDRESS; ?>e</a> thanks <a href="http://sprunge.us">sprunge.us</a> for their client :)<br/>
|
header('Cache-Control: no-cache');
|
||||||
More minimalist console client can be found here: <a href="<?php print APP_ADDRESS; ?>d"><?php print APP_ADDRESS; ?>d</a><br/>
|
|
||||||
<br/>
|
if (APP_TYPE == 'paste') {
|
||||||
2015
|
?>
|
||||||
</p>
|
<!DOCTYPE html>
|
||||||
</body>
|
<html lang="ru">
|
||||||
</html>
|
<head>
|
||||||
<?php
|
<style>
|
||||||
}
|
body { background-color: #adc0fc; text-align: center; }
|
||||||
|
textarea {
|
||||||
function eclient() {
|
background-image: url("<?php print CDN_ADDRESS; ?>bg_logo.png");
|
||||||
header('Content-Language: en, ru');
|
background-repeat: no-repeat;
|
||||||
header('Content-Type: text/plain');
|
background-position: center center;
|
||||||
header('Content-Disposition: attachment; filename="e"');
|
width: 90%;
|
||||||
?>
|
height: 70vh;
|
||||||
#!/bin/bash
|
}
|
||||||
|
</style>
|
||||||
usage() {
|
<title>Slack paste.</title>
|
||||||
description | fmt -s >&2
|
</head>
|
||||||
}
|
<body>
|
||||||
|
<h3>Slack Paste</h3>
|
||||||
description() {
|
<form method="post" action="<?php print APP_ADDRESS; ?>" enctype="multipart/form-data">
|
||||||
cat << HERE
|
<textarea name="exs" id="textbox" autofocus></textarea><br />
|
||||||
|
<input type="submit" value="Post it!" style="font-size:115%;" />
|
||||||
DESCRIPTION
|
for
|
||||||
Upload data and fetch URL from the pastebin <?php print SITE_ADDRESS; ?>
|
<select name="etime" style="font-size:115%; text-align:left;">
|
||||||
|
<option value="1" style="font-size: 85%; text-align:left;">1 Hour</option>
|
||||||
USAGE
|
<option value="2" style="font-size: 85%; text-align:left;">12 Hours</option>
|
||||||
$0 filename.txt
|
<option value="3" style="font-size: 85%; text-align:left;">1 day</option>
|
||||||
$0 text string
|
<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>
|
||||||
piped_data | $0
|
<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>
|
||||||
NOTES
|
<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>
|
||||||
* INPUT METHODS *
|
<option value="10" style="font-size: 85%; text-align:left;">3 Years</option>
|
||||||
$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.
|
</select>
|
||||||
|
</form>
|
||||||
* PRECEDENCE *
|
<?php
|
||||||
STDIN redirection has precedence, then piped input, then a filename as an argument, and finally text strings as an arguments.
|
if ($text != '') {
|
||||||
|
printf (" <p><table align=\"center\" frame=\"void\" border=\"0\"><td>%s</td></table></p>\n", $text);
|
||||||
EXAMPLE:
|
}
|
||||||
echo piped | "$0" arguments.txt < stdin_redirection.txt
|
?>
|
||||||
|
<p style="font-size: small;">
|
||||||
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.
|
Console client can be found here: <a href="<?php print APP_ADDRESS; ?>e"><?php print APP_ADDRESS; ?>e</a> 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/>
|
||||||
* FILENAMES *
|
<br/>
|
||||||
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.
|
2015
|
||||||
--------------------------------------------------------------------------
|
</p>
|
||||||
|
</body>
|
||||||
HERE
|
</html>
|
||||||
exit
|
<?php
|
||||||
}
|
} elseif (APP_TYPE == 'short') {
|
||||||
|
?>
|
||||||
if [ -t 0 ]; then
|
<!DOCTYPE html>
|
||||||
echo Running interactively, checking for arguments... >&2
|
<html lang="ru">
|
||||||
if [ "$*" ]; then
|
<head>
|
||||||
echo Arguments present... >&2
|
<meta charset="UTF-8" />
|
||||||
if [ -f "$*" ]; then
|
<style>
|
||||||
echo Uploading the contents of "$*"... >&2
|
* {
|
||||||
cat "$*"
|
margin: 10px;
|
||||||
else
|
text-align: center;
|
||||||
echo Uploading the text: \""$*"\"... >&2
|
font-size: 14pt;
|
||||||
echo "$*"
|
}
|
||||||
fi | curl -F "exs=<-" <?php print SITE_ADDRESS; ?>
|
html, body {
|
||||||
else
|
background-color: #adc0fc; text-align: center;
|
||||||
echo No arguments found, printing USAGE and exiting. >&2
|
}
|
||||||
usage
|
</style>
|
||||||
fi
|
<title>Link Shortener</title>
|
||||||
else
|
</head>
|
||||||
echo Using input from a pipe or STDIN redirection... >&2
|
<body>
|
||||||
while read -r line ; do
|
<img src="<?php print CDN_ADDRESS; ?>logo.png" />
|
||||||
echo $line
|
|
||||||
done | curl -F "exs=<-" <?php print SITE_ADDRESS; ?>
|
<form method="post" action="<?php print APP_ADDRESS; ?>">
|
||||||
fi
|
Shorten this link:<br />
|
||||||
<?php
|
<input type="text" maxlength="768" name="exs" style="font-size: 110%; width:45%;" autofocus/></br />
|
||||||
exit;
|
<input type="submit" value="Submit" style="font-size: 85%;" />
|
||||||
}
|
for
|
||||||
|
<select name="etime" style="font-size: 85%; text-align:left;">
|
||||||
function dclient() {
|
<option value="1" style="font-size: 85%; text-align:left;">1 Hour</option>
|
||||||
header('Content-Language: en, ru');
|
<option value="2" style="font-size: 85%; text-align:left;">12 Hours</option>
|
||||||
header('Content-Type: text/plain');
|
<option value="3" style="font-size: 85%; text-align:left;">1 day</option>
|
||||||
header('Content-Disposition: attachment; filename="d";');
|
<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>
|
||||||
#!/usr/bin/env bash
|
<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>
|
||||||
if [[ "$1" == "--help" ]]; then
|
<option value="8" style="font-size: 85%; text-align:left;">1 Year</option>
|
||||||
echo "Usage: $0 < file"
|
<option value="9" style="font-size: 85%; text-align:left;">2 Years</option>
|
||||||
echo " echo foo | $0"
|
<option value="10" style="font-size: 85%; text-align:left;">3 Years</option>
|
||||||
elif [[ -f "$1" ]]; then
|
</select>
|
||||||
curl -F "exs=<-" "<?php print SITE_ADDRESS; ?>" <"$1"
|
</form>
|
||||||
else
|
<?php
|
||||||
curl -F "exs=<-" "<?php print SITE_ADDRESS; ?>"
|
if ($text != '') {
|
||||||
fi
|
printf (" <table style=\"margin: 0px auto;\"><td>%s</td></table>\n", $text);
|
||||||
|
}
|
||||||
exit 0
|
?>
|
||||||
';
|
</body>
|
||||||
<?php
|
</html>
|
||||||
exit;
|
<?php
|
||||||
}
|
}
|
||||||
|
}
|
||||||
function gen_id() {
|
|
||||||
$urllen = rand (KEY_MIN, KEY_MAX);
|
public function eclient () {
|
||||||
$string = '';
|
header('Content-Language: en, ru');
|
||||||
$a = Array(); $a = array_merge(range('A', 'Z'), range('a', 'z'));
|
header('Content-Type: text/plain');
|
||||||
|
header('Content-Disposition: attachment; filename="e"');
|
||||||
for($i = 0; $i < $urllen; $i++){
|
?>
|
||||||
$string .= $a[rand (0, count($a) - 1)];
|
#!/bin/bash
|
||||||
}
|
|
||||||
|
usage() {
|
||||||
return($string);
|
description | fmt -s >&2
|
||||||
}
|
}
|
||||||
|
|
||||||
function init_db() {
|
description() {
|
||||||
# we init db, eh? drop db file and re-create it!
|
cat << HERE
|
||||||
if (file_exists(DBPATH)) { unlink(DBPATH); }
|
|
||||||
if (! file_exists(dirname(DBPATH))) { mkdir(dirname(DBPATH), 0777, true); }
|
DESCRIPTION
|
||||||
|
Upload data and fetch URL from the pastebin http://p.dafuq.ru/
|
||||||
$dbh = new PDO("sqlite:" . DBPATH);
|
|
||||||
|
USAGE
|
||||||
$r = $dbh->exec(
|
$0 filename.txt
|
||||||
"CREATE TABLE IF NOT EXISTS paste (
|
$0 text string
|
||||||
id TEXT PRIMARY KEY,
|
$0 < filename.txt
|
||||||
paste TEXT,
|
piped_data | $0
|
||||||
time INTEGER,
|
|
||||||
etime INTEGER
|
NOTES
|
||||||
)"
|
--------------------------------------------------------------------------
|
||||||
);
|
* 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.
|
||||||
if($r === false) {
|
|
||||||
$e = $r->errorInfo();
|
* PRECEDENCE *
|
||||||
showindex($e[2]);
|
STDIN redirection has precedence, then piped input, then a filename as an argument, and finally text strings as an arguments.
|
||||||
}
|
|
||||||
|
EXAMPLE:
|
||||||
$dbh = null;
|
echo piped | "$0" arguments.txt < stdin_redirection.txt
|
||||||
}
|
|
||||||
|
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.
|
||||||
function query_db($id) {
|
|
||||||
if (! file_exists(DBPATH)) {
|
* FILENAMES *
|
||||||
init_db();
|
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.
|
||||||
return false;
|
--------------------------------------------------------------------------
|
||||||
}
|
|
||||||
|
HERE
|
||||||
$dbh = new PDO("sqlite:" . DBPATH);
|
exit
|
||||||
$sth = $dbh->query("SELECT paste FROM paste WHERE id='$id'");
|
}
|
||||||
|
|
||||||
if ($sth === false) {
|
if [ -t 0 ]; then
|
||||||
$e = $r->errorInfo();
|
echo Running interactively, checking for arguments... >&2
|
||||||
showindex($e[2]);
|
if [ "$*" ]; then
|
||||||
exit;
|
echo Arguments present... >&2
|
||||||
}
|
if [ -f "$*" ]; then
|
||||||
|
echo Uploading the contents of "$*"... >&2
|
||||||
$sth->setFetchMode(PDO::FETCH_ASSOC);
|
cat "$*"
|
||||||
$data = $sth->fetch();
|
else
|
||||||
$dbh = null;
|
echo Uploading the text: \""$*"\"... >&2
|
||||||
|
echo "$*"
|
||||||
if ($data === false) {
|
fi | curl -F "exs=<-" <?php print SITE_ADDRESS; ?>
|
||||||
return($data);
|
else
|
||||||
} else {
|
echo No arguments found, printing USAGE and exiting. >&2
|
||||||
if (isset($data['etime']) and ($data['etime'] < time())){
|
usage
|
||||||
return false;
|
fi
|
||||||
}
|
else
|
||||||
|
echo Using input from a pipe or STDIN redirection... >&2
|
||||||
$data = $data['paste'];
|
while read -r line ; do
|
||||||
return($data); # false if no data or no key in db
|
echo $line
|
||||||
}
|
done | curl -F "exs=<-" <?php print SITE_ADDRESS; ?>
|
||||||
}
|
fi
|
||||||
|
<?php
|
||||||
function store_data($paste) {
|
exit;
|
||||||
if (! file_exists(DBPATH)) { init_db(); }
|
}
|
||||||
$dbh = new PDO("sqlite:" . DBPATH);
|
|
||||||
$q = 0;
|
public function dclient () {
|
||||||
|
header('Content-Language: en, ru');
|
||||||
do {
|
header('Content-Type: text/plain');
|
||||||
if ($q > 100) { # assume key-value space depleted if we try more than 100 times
|
header('Content-Disposition: attachment; filename="d";');
|
||||||
$q = false;
|
?>
|
||||||
break;
|
#!/usr/bin/env bash
|
||||||
}
|
|
||||||
$id = gen_id();
|
if [[ "$1" == "--help" ]]; then
|
||||||
$q++;
|
echo "Usage: $0 < file"
|
||||||
} while (! $dbh->query("SELECT id FROM paste WHERE id='$id'"));
|
echo " echo foo | $0"
|
||||||
|
elif [[ -f "$1" ]]; then
|
||||||
if($q === false) {
|
curl -F "exs=<-" "<?php print SITE_ADDRESS; ?>" <"$1"
|
||||||
return('Storage depleted.');
|
else
|
||||||
}
|
curl -F "exs=<-" "<?php print SITE_ADDRESS; ?>"
|
||||||
|
fi
|
||||||
$ctime = time();
|
|
||||||
$etime = $ctime + 14515200;
|
exit 0
|
||||||
|
';
|
||||||
if(isset($_POST['etime'])) {
|
<?php
|
||||||
switch ($_POST['etime']) {
|
exit;
|
||||||
case '1': # 1 hour
|
}
|
||||||
$etime = $ctime + 3600;
|
|
||||||
break;
|
protected function gen_id () {
|
||||||
|
$urllen = rand (KEY_MIN, KEY_MAX);
|
||||||
case '2': # 12 hours
|
$string = '';
|
||||||
$etime = $ctime + 43200;
|
$a = Array(); $a = array_merge(range('A', 'Z'), range('a', 'z'));
|
||||||
break;
|
|
||||||
|
for ($i = 0; $i < $urllen; $i++) {
|
||||||
case '3': # 1 day
|
$string .= $a[rand (0, count($a) - 1)];
|
||||||
$etime = $ctime + 86400;
|
}
|
||||||
break;
|
|
||||||
|
return($string);
|
||||||
case '4': # 1 week
|
}
|
||||||
$etime = $ctime + 604800;
|
|
||||||
break;
|
public function query_db ($q) {
|
||||||
|
$dbh = new PDO("sqlite:" . DBPATH);
|
||||||
case '5': # 1 month
|
$sth = $dbh->query("SELECT paste FROM paste WHERE id='$q'");
|
||||||
$etime = $ctime + 2419200;
|
|
||||||
break;
|
if ($sth === false) {
|
||||||
|
$e = $r->errorInfo();
|
||||||
case '6': # 3 months
|
self::showindex($e[2]);
|
||||||
$etime = $ctime + 7257600;
|
exit;
|
||||||
break;
|
}
|
||||||
|
|
||||||
case '7': # 6 months
|
$sth->setFetchMode(PDO::FETCH_ASSOC);
|
||||||
$etime = $ctime + 14515200;
|
$data = $sth->fetch();
|
||||||
break;
|
$dbh = null;
|
||||||
|
|
||||||
case '8': # 1 year
|
if ($data === false) {
|
||||||
$etime = $ctime + 29030400;
|
return($data);
|
||||||
break;
|
} else {
|
||||||
|
if (isset($data['etime']) and ($data['etime'] < time())){
|
||||||
case '9': # 2 years
|
return false;
|
||||||
$etime = $ctime + 58060800;
|
}
|
||||||
break;
|
|
||||||
|
$data = $data['paste'];
|
||||||
case '10': # 3 years
|
return($data); # false if no data or no key in db
|
||||||
$etime = $ctime + 87091200;
|
}
|
||||||
break;
|
}
|
||||||
|
|
||||||
case '13': # forever
|
public function store_data ($paste) {
|
||||||
$etime = "null";
|
$dbh = new PDO("sqlite:" . DBPATH);
|
||||||
break;
|
$q = 0;
|
||||||
}
|
|
||||||
}
|
do {
|
||||||
|
if ($q > 100) { # assume key-value space depleted if we try more than 100 times
|
||||||
$sth = $dbh->prepare("INSERT INTO paste VALUES('$id', '$paste', $ctime, $etime)");
|
$q = false;
|
||||||
$sth->execute();
|
break;
|
||||||
|
}
|
||||||
if ($sth === false) {
|
|
||||||
$e = $sth->errorInfo();
|
$id = self::gen_id();
|
||||||
showindex($e[2]);
|
$q++;
|
||||||
exit;
|
} while (! $dbh->query("SELECT id FROM paste WHERE id='$id'"));
|
||||||
}
|
|
||||||
|
if ($q === false) {
|
||||||
$dbh = null;
|
return('Storage depleted.');
|
||||||
return($id);
|
}
|
||||||
}
|
|
||||||
|
$ctime = time();
|
||||||
$text = '';
|
$etime = $ctime + 14515200;
|
||||||
|
|
||||||
if (($_SERVER['REQUEST_METHOD'] === 'GET') or ($_SERVER['REQUEST_METHOD'] === 'HEAD')) {
|
if (isset($_POST['etime'])) {
|
||||||
# substr returns empty string (boolean false) on error
|
switch ($_POST['etime']) {
|
||||||
$str = $_SERVER['REQUEST_URI']; $str = substr($str, mb_strlen(BASEURL, 'UTF-8'));
|
case '1': # 1 hour
|
||||||
|
$etime = $ctime + 3600;
|
||||||
if ($str == 'e') {
|
break;
|
||||||
eclient();
|
|
||||||
exit;
|
case '2': # 12 hours
|
||||||
} elseif ($str == 'd') {
|
$etime = $ctime + 43200;
|
||||||
dclient();
|
break;
|
||||||
exit;
|
|
||||||
}
|
case '3': # 1 day
|
||||||
|
$etime = $ctime + 86400;
|
||||||
# pastebin returns raw pate when paste' key prepended with /raw/, let's handle it
|
break;
|
||||||
if (preg_match('/^raw\//', $str) == 1) {
|
|
||||||
$str = substr($str, mb_strlen('raw/', 'UTF-8'));
|
case '4': # 1 week
|
||||||
}
|
$etime = $ctime + 604800;
|
||||||
|
break;
|
||||||
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) {
|
case '5': # 1 month
|
||||||
$response = query_db($str);
|
$etime = $ctime + 2419200;
|
||||||
|
break;
|
||||||
if ($response === false) {
|
|
||||||
$text = 'No such paste.';
|
case '6': # 3 months
|
||||||
} else {
|
$etime = $ctime + 7257600;
|
||||||
header('Content-Type: text/plain');
|
break;
|
||||||
print base64_decode($response);
|
|
||||||
exit;
|
case '7': # 6 months
|
||||||
}
|
$etime = $ctime + 14515200;
|
||||||
}
|
break;
|
||||||
}
|
|
||||||
|
case '8': # 1 year
|
||||||
} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
$etime = $ctime + 29030400;
|
||||||
if (isset($_POST['exs']) and ($_POST['exs'] != '')) {
|
break;
|
||||||
$text = APP_ADDRESS . store_data(base64_encode($_POST['exs']));
|
|
||||||
} elseif (isset($_POST['api_option'])){ # some pastebin API compatibility stuff
|
case '9': # 2 years
|
||||||
if ($_POST['api_option'] == 'paste') {
|
$etime = $ctime + 58060800;
|
||||||
if ((isset($_POST['api_paste_code'])) and ($_POST['api_paste_code'] != '')) {
|
break;
|
||||||
header('Content-Type: text/plain; charset=utf-8');
|
|
||||||
print mb_convert_encoding(APP_ADDRESS . store_data(base64_encode($_POST['api_paste_code'])), 'UTF-8', 'auto');
|
case '10': # 3 years
|
||||||
exit;
|
$etime = $ctime + 87091200;
|
||||||
}
|
break;
|
||||||
} elseif ($_POST['api_option'] == 'show_paste') {
|
|
||||||
if (isset($_POST['api_paste_key'])) {
|
case '13': # forever
|
||||||
$str = $_POST['api_paste_key'];
|
$etime = "null";
|
||||||
|
break;
|
||||||
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 = query_db($str);
|
|
||||||
|
$sth = $dbh->prepare("INSERT INTO paste VALUES('$id', '$paste', $ctime, $etime)");
|
||||||
if ($response === false) {
|
$sth->execute();
|
||||||
header('Content-Type: text/plain; charset=utf-8');
|
|
||||||
print "Bad API request, invalid permission to view this paste or invalid api_paste_key";
|
if ($sth === false) {
|
||||||
exit;
|
$e = $sth->errorInfo();
|
||||||
} else {
|
self::showindex($e[2]);
|
||||||
header('Content-Type: text/plain');
|
exit;
|
||||||
print base64_decode($response);
|
}
|
||||||
exit;
|
|
||||||
}
|
$dbh = null;
|
||||||
}
|
return($id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
/*
|
||||||
# ???
|
* MAIN STARTS HERE
|
||||||
}
|
*/
|
||||||
|
|
||||||
showindex($text);
|
$text = '';
|
||||||
?>
|
$p = new paste;
|
||||||
|
|
||||||
|
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
|
||||||
|
*/
|
||||||
|
?>
|
||||||
|
|||||||
Reference in New Issue
Block a user