added pastebinit support and fixed small errors

This commit is contained in:
Chris
2018-12-22 21:38:48 +01:00
parent 63a28b8b4b
commit 3345eb399c
6 changed files with 73 additions and 4 deletions

39
api/pastebin.php Normal file
View File

@@ -0,0 +1,39 @@
<?php
// basic path definitions
define('DS', DIRECTORY_SEPARATOR);
define('ROOT', dirname(__FILE__).'/..');
//loading default settings if exist
if(!file_exists(ROOT.DS.'inc'.DS.'config.inc.php'))
exit('Rename /inc/example.config.inc.php to /inc/config.inc.php first!');
include_once(ROOT.DS.'inc'.DS.'config.inc.php');
//loading core and controllers
include_once(ROOT . DS . 'inc' . DS. 'core.php');
require_once(ROOT . DS . 'controllers' . DS. 'text'. DS . 'text.controller.php');
// check write permissions first
if(!isFolderWritable(ROOT.DS.'data'))
exit(json_encode(array('status'=>'err','reason'=>'Data directory not writable')));
else if(!isFolderWritable(ROOT.DS.'tmp'))
exit(json_encode(array('status'=>'err','reason'=>'Temp directory not writable')));
// check for POSTed text
if($_REQUEST['api_paste_code'])
{
$hash = getNewHash('txt',$length=10);
$tmpfile = ROOT.DS.'tmp'.DS.$hash;
file_put_contents($tmpfile,$_REQUEST['api_paste_code']);
//check if this exact paste already exists
$sha1 = sha1_file($tmpfile);
$sha_hash = sha1Exists($sha1);
if($sha_hash)
exit(URL.$sha_hash);
$answer = (new TextController())->handleUpload($tmpfile,$hash);
if($answer['hash'])
addSha1($answer['hash'],$sha1);
echo URL.$hash;
}