Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ee4ac8a429 | ||
|
|
5c6fdef0b6 | ||
|
|
16c3e42635 |
2
.hgtags
2
.hgtags
@@ -1,2 +1,4 @@
|
|||||||
b66e758d981314bfd9de6dbfe0385785908a884c v1.0.0
|
b66e758d981314bfd9de6dbfe0385785908a884c v1.0.0
|
||||||
4db108cffb1f05d2c42ff71e22d6c2330b4f45ad v1.1.0
|
4db108cffb1f05d2c42ff71e22d6c2330b4f45ad v1.1.0
|
||||||
|
0a90758f5df3d039490b57fad1091af22fb47524 v2.0.0
|
||||||
|
6db9ff3d18c27c2f7c08ed4104d6cbc05ca8bf86 v2.1.0
|
||||||
|
|||||||
107
index.php
107
index.php
@@ -1,6 +1,20 @@
|
|||||||
<?php
|
<?php
|
||||||
$config = parse_ini_file("app.ini");
|
|
||||||
|
|
||||||
|
interface iPaste {
|
||||||
|
public function showindex($text);
|
||||||
|
public function eclient();
|
||||||
|
public function dclient();
|
||||||
|
public function query_db($q);
|
||||||
|
public function store_data($paste);
|
||||||
|
}
|
||||||
|
|
||||||
|
class paste implements iPaste {
|
||||||
|
public function __construct () {
|
||||||
|
if (! file_exists('app.ini')) {
|
||||||
|
print "app.ini not found, unable to run application\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
$config = parse_ini_file("app.ini");
|
||||||
define ('SITE_ADDRESS', $config["siteaddress"]);
|
define ('SITE_ADDRESS', $config["siteaddress"]);
|
||||||
define ('BASEURL', $config["baseurl"]);
|
define ('BASEURL', $config["baseurl"]);
|
||||||
define ('APP_ADDRESS', substr(SITE_ADDRESS, 0, -1) . BASEURL);
|
define ('APP_ADDRESS', substr(SITE_ADDRESS, 0, -1) . BASEURL);
|
||||||
@@ -9,10 +23,32 @@ define ('DBPATH', $config["dbpath"]);
|
|||||||
define ('KEY_MIN', 3);
|
define ('KEY_MIN', 3);
|
||||||
define ('KEY_MAX', 9);
|
define ('KEY_MAX', 9);
|
||||||
define ('APP_TYPE', $config["type"]);
|
define ('APP_TYPE', $config["type"]);
|
||||||
|
|
||||||
unset ($config);
|
unset ($config);
|
||||||
|
|
||||||
function showindex($text) {
|
if (! file_exists(dirname(DBPATH))) {
|
||||||
|
mkdir(dirname(DBPATH), 0777, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
$dbh = new PDO("sqlite:" . DBPATH);
|
||||||
|
|
||||||
|
$r = $dbh->exec(
|
||||||
|
"CREATE TABLE IF NOT EXISTS paste (
|
||||||
|
id TEXT PRIMARY KEY,
|
||||||
|
paste TEXT,
|
||||||
|
time INTEGER,
|
||||||
|
etime INTEGER
|
||||||
|
)"
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($r === false) {
|
||||||
|
$e = $r->errorInfo();
|
||||||
|
self::showindex($e[2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$dbh = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function showindex ($text) {
|
||||||
header('Content-Language: en, ru');
|
header('Content-Language: en, ru');
|
||||||
header('Pragma: no-cache');
|
header('Pragma: no-cache');
|
||||||
header('Cache-Control: no-cache');
|
header('Cache-Control: no-cache');
|
||||||
@@ -117,7 +153,7 @@ function showindex($text) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function eclient() {
|
public function eclient () {
|
||||||
header('Content-Language: en, ru');
|
header('Content-Language: en, ru');
|
||||||
header('Content-Type: text/plain');
|
header('Content-Type: text/plain');
|
||||||
header('Content-Disposition: attachment; filename="e"');
|
header('Content-Disposition: attachment; filename="e"');
|
||||||
@@ -186,7 +222,7 @@ fi
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
function dclient() {
|
public function dclient () {
|
||||||
header('Content-Language: en, ru');
|
header('Content-Language: en, ru');
|
||||||
header('Content-Type: text/plain');
|
header('Content-Type: text/plain');
|
||||||
header('Content-Disposition: attachment; filename="d";');
|
header('Content-Disposition: attachment; filename="d";');
|
||||||
@@ -208,7 +244,7 @@ exit 0
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
function gen_id() {
|
protected function gen_id () {
|
||||||
$urllen = rand (KEY_MIN, KEY_MAX);
|
$urllen = rand (KEY_MIN, KEY_MAX);
|
||||||
$string = '';
|
$string = '';
|
||||||
$a = Array(); $a = array_merge(range('A', 'Z'), range('a', 'z'));
|
$a = Array(); $a = array_merge(range('A', 'Z'), range('a', 'z'));
|
||||||
@@ -220,42 +256,13 @@ function gen_id() {
|
|||||||
return($string);
|
return($string);
|
||||||
}
|
}
|
||||||
|
|
||||||
function init_db() {
|
public function query_db ($q) {
|
||||||
# we init db, eh? drop db file and re-create it!
|
|
||||||
if (file_exists(DBPATH)) { unlink(DBPATH); }
|
|
||||||
if (! file_exists(dirname(DBPATH))) { mkdir(dirname(DBPATH), 0777, true); }
|
|
||||||
|
|
||||||
$dbh = new PDO("sqlite:" . DBPATH);
|
|
||||||
|
|
||||||
$r = $dbh->exec(
|
|
||||||
"CREATE TABLE IF NOT EXISTS paste (
|
|
||||||
id TEXT PRIMARY KEY,
|
|
||||||
paste TEXT,
|
|
||||||
time INTEGER,
|
|
||||||
etime INTEGER
|
|
||||||
)"
|
|
||||||
);
|
|
||||||
|
|
||||||
if($r === false) {
|
|
||||||
$e = $r->errorInfo();
|
|
||||||
showindex($e[2]);
|
|
||||||
}
|
|
||||||
|
|
||||||
$dbh = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
function query_db($q) {
|
|
||||||
if (! file_exists(DBPATH)) {
|
|
||||||
init_db();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$dbh = new PDO("sqlite:" . DBPATH);
|
$dbh = new PDO("sqlite:" . DBPATH);
|
||||||
$sth = $dbh->query("SELECT paste FROM paste WHERE id='$q'");
|
$sth = $dbh->query("SELECT paste FROM paste WHERE id='$q'");
|
||||||
|
|
||||||
if ($sth === false) {
|
if ($sth === false) {
|
||||||
$e = $r->errorInfo();
|
$e = $r->errorInfo();
|
||||||
showindex($e[2]);
|
self::showindex($e[2]);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -275,8 +282,7 @@ function query_db($q) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function store_data($paste) {
|
public function store_data ($paste) {
|
||||||
if (! file_exists(DBPATH)) { init_db(); }
|
|
||||||
$dbh = new PDO("sqlite:" . DBPATH);
|
$dbh = new PDO("sqlite:" . DBPATH);
|
||||||
$q = 0;
|
$q = 0;
|
||||||
|
|
||||||
@@ -285,7 +291,8 @@ function store_data($paste) {
|
|||||||
$q = false;
|
$q = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$id = gen_id();
|
|
||||||
|
$id = self::gen_id();
|
||||||
$q++;
|
$q++;
|
||||||
} while (! $dbh->query("SELECT id FROM paste WHERE id='$id'"));
|
} while (! $dbh->query("SELECT id FROM paste WHERE id='$id'"));
|
||||||
|
|
||||||
@@ -349,13 +356,14 @@ function store_data($paste) {
|
|||||||
|
|
||||||
if ($sth === false) {
|
if ($sth === false) {
|
||||||
$e = $sth->errorInfo();
|
$e = $sth->errorInfo();
|
||||||
showindex($e[2]);
|
self::showindex($e[2]);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
$dbh = null;
|
$dbh = null;
|
||||||
return($id);
|
return($id);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -363,6 +371,7 @@ function store_data($paste) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
$text = '';
|
$text = '';
|
||||||
|
$p = new paste;
|
||||||
|
|
||||||
if (($_SERVER['REQUEST_METHOD'] === 'GET') or ($_SERVER['REQUEST_METHOD'] === 'HEAD')) {
|
if (($_SERVER['REQUEST_METHOD'] === 'GET') or ($_SERVER['REQUEST_METHOD'] === 'HEAD')) {
|
||||||
# substr returns empty string (boolean false) on error
|
# substr returns empty string (boolean false) on error
|
||||||
@@ -370,10 +379,10 @@ if (($_SERVER['REQUEST_METHOD'] === 'GET') or ($_SERVER['REQUEST_METHOD'] === 'H
|
|||||||
|
|
||||||
if (APP_TYPE == 'paste') {
|
if (APP_TYPE == 'paste') {
|
||||||
if ($str == 'e') {
|
if ($str == 'e') {
|
||||||
eclient();
|
$p->eclient();
|
||||||
exit;
|
exit;
|
||||||
} elseif ($str == 'd') {
|
} elseif ($str == 'd') {
|
||||||
dclient();
|
$p->dclient();
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -385,7 +394,7 @@ if (($_SERVER['REQUEST_METHOD'] === 'GET') or ($_SERVER['REQUEST_METHOD'] === 'H
|
|||||||
|
|
||||||
if ((mb_strlen($str, 'UTF-8') >= KEY_MIN) and ((mb_strlen($str, 'UTF-8') <= KEY_MAX))) {
|
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) {
|
if (preg_match('/^[a-z|A-Z]+$/', $str) == 1) {
|
||||||
$response = query_db($str);
|
$response = $p->query_db($str);
|
||||||
|
|
||||||
if ($response === false) {
|
if ($response === false) {
|
||||||
$text = 'No such paste.';
|
$text = 'No such paste.';
|
||||||
@@ -432,18 +441,18 @@ if (($_SERVER['REQUEST_METHOD'] === 'GET') or ($_SERVER['REQUEST_METHOD'] === 'H
|
|||||||
(preg_match('/^opera\:/', $_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('/^about\:/', $_POST['exs']) == 1) or # i'm doubt if this really working, but anyway
|
||||||
(preg_match('/^skype\:/', $_POST['exs']) == 1)) {
|
(preg_match('/^skype\:/', $_POST['exs']) == 1)) {
|
||||||
$text = APP_ADDRESS . store_data(base64_encode($_POST['exs']));
|
$text = APP_ADDRESS . $p->store_data(base64_encode($_POST['exs']));
|
||||||
} else {
|
} else {
|
||||||
$text = 'Unable to short your link.';
|
$text = 'Unable to short your link.';
|
||||||
}
|
}
|
||||||
} elseif (APP_TYPE == 'paste') {
|
} elseif (APP_TYPE == 'paste') {
|
||||||
$text = APP_ADDRESS . store_data(base64_encode($_POST['exs']));
|
$text = APP_ADDRESS . $p->store_data(base64_encode($_POST['exs']));
|
||||||
}
|
}
|
||||||
} elseif ((APP_TYPE == 'paste') and (isset($_POST['api_option']))) { # some pastebin API compatibility stuff
|
} elseif ((APP_TYPE == 'paste') and (isset($_POST['api_option']))) { # some pastebin API compatibility stuff
|
||||||
if ($_POST['api_option'] == 'paste') {
|
if ($_POST['api_option'] == 'paste') {
|
||||||
if ((isset($_POST['api_paste_code'])) and ($_POST['api_paste_code'] != '')) {
|
if ((isset($_POST['api_paste_code'])) and ($_POST['api_paste_code'] != '')) {
|
||||||
header('Content-Type: text/plain; charset=utf-8');
|
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');
|
print mb_convert_encoding(APP_ADDRESS . $p->store_data(base64_encode($_POST['api_paste_code'])), 'UTF-8', 'auto');
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
} elseif ($_POST['api_option'] == 'show_paste') {
|
} elseif ($_POST['api_option'] == 'show_paste') {
|
||||||
@@ -452,7 +461,7 @@ if (($_SERVER['REQUEST_METHOD'] === 'GET') or ($_SERVER['REQUEST_METHOD'] === 'H
|
|||||||
|
|
||||||
if ((mb_strlen($str, 'UTF-8') >= KEY_MIN) and ((mb_strlen($str, 'UTF-8') <= KEY_MAX))) {
|
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) {
|
if (preg_match('/^[a-z|A-Z]+$/', $str) == 1) {
|
||||||
$response = query_db($str);
|
$response = $p->query_db($str);
|
||||||
|
|
||||||
if ($response === false) {
|
if ($response === false) {
|
||||||
header('Content-Type: text/plain; charset=utf-8');
|
header('Content-Type: text/plain; charset=utf-8');
|
||||||
@@ -470,7 +479,7 @@ if (($_SERVER['REQUEST_METHOD'] === 'GET') or ($_SERVER['REQUEST_METHOD'] === 'H
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
showindex($text);
|
$p->showindex($text);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* END OF MAIN
|
* END OF MAIN
|
||||||
|
|||||||
Reference in New Issue
Block a user