From abccbcd1b8a562022b2a5517348d0b193a1c5f70 Mon Sep 17 00:00:00 2001 From: feder Date: Wed, 8 Feb 2017 18:00:33 +0300 Subject: [PATCH] Add project --- .htaccess | 7 ++ LICENSE | 30 +++++ README.md | 5 + anthrstlsht.css | 152 +++++++++++++++++++++++ index.php | 313 ++++++++++++++++++++++++++++++++++++++++++++++++ storage.sql | 50 ++++++++ 6 files changed, 557 insertions(+) create mode 100644 .htaccess create mode 100644 LICENSE create mode 100644 README.md create mode 100644 anthrstlsht.css create mode 100644 index.php create mode 100644 storage.sql diff --git a/.htaccess b/.htaccess new file mode 100644 index 0000000..5e925b2 --- /dev/null +++ b/.htaccess @@ -0,0 +1,7 @@ + +RewriteEngine on +RewriteCond %{REQUEST_FILENAME} !-f +RewriteCond %{REQUEST_FILENAME} !-l +RewriteCond %{REQUEST_FILENAME} !-d +RewriteRule ^(.*)$ index.php?$1 [L,QSA] + \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..5bb77c7 --- /dev/null +++ b/LICENSE @@ -0,0 +1,30 @@ +pastedfile + +pastedfile is released under the DWTW license. + +This program is free software; you can redistribute it and/or modify it under the terms of the Do What Thou Wilt License. + +DO WHAT THAU WILT +TO PUBLIC LICENSE + +Version 2.5 + +Everyone is permitted to copy and distribute verbatim or modified copies of this license document, and changing it is allowed as long as the name is changed. + +TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + +0. Do what thou wilt shall be the whole of the Law. + +Anyone is allowed to copy and distribute the copies of this license agreement in whole or in part, as well as modify it without any other limitations. + +DWTW – a license with a single requirement: DO WHAT THOU WILT + +The license provides more freedom than any other one (such as GPL or BSD) and does not require saving the license text on copying. + +DWTW – an accomplished and eligible license for free text (including the software, documentation and artwork). + +The license does not contain "no warranty" clause. DWTW can be used in countries that do not legally acknowledge the transition to public domain. + +Summary: + +An author-creator gives his or her source code to the world for free, without becoming distracted by worldly thinking regarding how and why the others will use it. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..b5f053f --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# pastedfile + +pastedfile v.0.0.5-prealpha + +released under the DWTWL license diff --git a/anthrstlsht.css b/anthrstlsht.css new file mode 100644 index 0000000..66ae12e --- /dev/null +++ b/anthrstlsht.css @@ -0,0 +1,152 @@ +/** + * anthrstlsht.css (another style sheet) v0.8 + * https://github.com/zlaxy/anthrstlsht + * DWTWL 2.5 license: https://soundragon.su/license/license.html + * fonts connection: http://font.ubuntu.com/web/ , for example: + * + */ + +html { + font-family: sans-serif; +} + +body { + margin: 0; + font-family: Ubuntu, sans-serif; + color: #222; +} + +.container { + width: 95%; + margin: auto; +} + +h1, h2, h3, h4 { + margin-top: 0; + margin-bottom: 0; + font-weight: 500; +} + +h1 { + font-size: 3.6rem; +} + +h2 { + font-size: 3.2rem; +} + +h3 { + font-size: 2.6rem; +} + +h4 { + font-size: 2.0rem; +} + +hr { + border-width: 0; + border-top: 1px solid #bbb; +} + +p { + margin-top: 0; + margin-bottom: 0; +} + +img { + border: 0; +} + +.button, +button, +html input[type="button"], +input[type="reset"], +input[type="submit"] { + padding: 0 20px; + color: #555; + text-align: center; + font-family: Ubuntu, sans-serif; + font-weight: 800; + line-height: 28px; + background-color: transparent; + border-radius: 6px; + border: 1px solid #bbb; + cursor: pointer; +} + +.button:hover, +button:hover, +input[type="button"]:hover, +input[type="reset"]:hover, +input[type="submit"]:hover, +.button:focus, +button:focus, +input[type="button"]:focus, +input[type="reset"]:focus, +input[type="submit"]:focus { + color: #333; + border-color: #999; + outline: 0; +} + +button[disabled], +html input[disabled] { + cursor: default; +} + +input[type="email"], +input[type="number"], +input[type="search"], +input[type="text"], +input[type="tel"], +input[type="url"], +input[type="password"], +textarea, +select { + height: 28px; + padding: 3px 5px; + border: 1px solid #bbb; + border-radius: 6px; + box-shadow: none; +} + +input[type="email"]:focus, +input[type="number"]:focus, +input[type="search"]:focus, +input[type="text"]:focus, +input[type="tel"]:focus, +input[type="url"]:focus, +input[type="password"]:focus, +textarea:focus, +select:focus { + border: 1px solid #888; + outline: 0; +} + +code { + font-family: monospace, monospace; + padding: .2rem .2rem; + font-size: 80%; + background: #eee; + white-space: pre; + border: 1px solid #ccc; + border-radius: 6px; +} + +ul { + list-style: circle; +} + +ol, ul, li { + margin-top: 0; + margin-bottom: 0; +} + +button, +.button, +input, +textarea, +select, +fieldset { + margin-bottom: .1rem; +} diff --git a/index.php b/index.php new file mode 100644 index 0000000..6aad216 --- /dev/null +++ b/index.php @@ -0,0 +1,313 @@ +",$Titles[Head],"\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "
\n"; + } + +function HTMLfooter() + { + echo "
\n"; + echo ""; + } + +function HTML404() + { + global $Titles; + HTMLheader(); + echo "

",$Titles[404],"

\n"; + HTMLfooter(); + } + +if (ParsedURI()[0]=="index") + { + HTMLheader(); + echo "

",$Titles[Head],"


\n"; + echo " $Titles[IndexRegister]",MainURL(),"register
\n"; + echo " $Titles[IndexGet]",MainURL(),"get/pastedfileID
\n"; + echo " $Titles[IndexEdit]",MainURL(),"edit/pastedfileID
\n"; + echo " $Titles[IndexPut]
\n"; + echo "
",$Titles[SampleCurlPart1],MainURL(),$Titles[SampleCurlPart2],"
\n"; + echo " ",$Titles[MaximumFIleSize],$SettingMaxFileSizeBytes," ",$Titles[Bytes],"
\n"; + echo " ",$Titles[DefaultMIME],$DefaultMIMEtype,"
\n"; + echo " ",$Titles[StoragePeriod],$SettingExpireDays," ",$Titles[Days],"
\n"; + HTMLfooter(); + } + +else if (ParsedURI()[0]=="get") + { + if (!ParsedURI()[1]) HTML404(); + else + { + $URIid=ParsedURI()[1]; + $dbconnection=mysqli_connect($mySQL[host],$mySQL[user],$mySQL[password],$mySQL[dbname]); + mysqli_query($dbconnection,"SET CHARACTER SET 'utf8'"); + $paste=mysqli_fetch_object(mysqli_query($dbconnection,"SELECT * FROM `$mySQL[table]` WHERE BINARY `id`='$URIid';")); + if ($paste->data) + { + $viewheader="Content-type: ".$paste->mime; + header($viewheader); + echo $paste->data; + } + else HTML404(); + } + } + +else if (ParsedURI()[0]=="put") + { + $URIid=ParsedURI()[1]; + $dbconnection=mysqli_connect($mySQL[host],$mySQL[user],$mySQL[password],$mySQL[dbname]); + mysqli_query($dbconnection,"SET CHARACTER SET 'utf8'"); + $paste=mysqli_fetch_object(mysqli_query($dbconnection,"SELECT * FROM `".$mySQL[table]."` WHERE `id` = '$URIid';")); + $URIparam=explode('=',ParsedURI()[param][1]); + if ($URIid===$paste->id) + if (($URIparam[0]=="password")&&($URIparam[1]===$paste->password)) + { + header("Content-type: text/plain"); + if ($_FILES['filedata']['size']<1) echo $Titles[ErrorDataTrans],"\n"; + if ($_FILES['filedata']['size']>$SettingMaxFileSizeBytes) echo $Titles[ErrorDataTrans],". ",$Titles[MaximumSize],$SettingMaxFileSizeBytes,$Titles[Bytes],"\n"; + if ($_FILES['filedata']['error']>0) echo $Titles[ErrorDataErrNo],$_FILES['filedata']['error'],")\n"; + else + { + if ($SettingMaxFileSizeBytes>$_FILES['filedata']['size']&&$_FILES['filedata']['size']>0) + { + echo $Titles[SuccFileSize],$_FILES['filedata']['size'],$Titles[SuccFileBytes],"\n"; + $filedata=addslashes(fread(fopen($_FILES['filedata']['tmp_name'],"rb"),filesize($_FILES['filedata']['tmp_name']))); + mysqli_query($dbconnection,"UPDATE `$mySQL[table]` SET `data` = '$filedata' WHERE `$mySQL[table]`.`id` = '$URIid';"); + mysqli_query($dbconnection,"UPDATE `$mySQL[table]` SET `modified` = NOW( ) WHERE `$mySQL[table]`.`id` = '$URIid';"); + } + } + } + else HTML404(); + else HTML404(); + } + +else if (ParsedURI()[0]=="register") + { + session_start(); + HTMLheader(); + if($_POST['submit']) + { + $_SESSION['formpasteid']=$_POST['pasteid']; + $UncorrectPasteIDorPassword=0; + if(!$_POST['pasteid']) echo "",$Titles[ReqPasteID],"
\n
\n"; + if((!$_POST['password'])||(!$_POST['password2'])) echo "",$Titles[ReqPassword],"
\n
\n"; + else if($_POST['password']!=$_POST['password2']) echo "",$Titles[WrongPassword],"
\n
\n"; + if(($_POST['pasteid'])&&(!ereg("^[a-zA-Z0-9_\.-]+$",$_POST['pasteid']))) $UncorrectPasteIDorPassword=1; + if(($_POST['password'])&&(!ereg("^[a-zA-Z0-9_\.-]+$",$_POST['password']))) $UncorrectPasteIDorPassword=1; + if(!$_POST['captcha']) echo "",$Titles[ReqCaptcha],"
\n
\n"; + if (($_POST['captcha'])&&!($_POST["captcha"]==$_SESSION["captcha"])) echo "",$Titles[WrongCaptcha],"
\n
\n"; + if ($UncorrectPasteIDorPassword==1) echo "",$Titles[WrongSymbols],"
\n
\n"; + else + { + if ((($_POST['captcha'])&&($_POST["captcha"]==$_SESSION["captcha"]))&&(($_POST['pasteid'])&&($_POST['password']))&&($_POST['password']===$_POST['password2'])) + { + $dbconnection=mysqli_connect($mySQL[host],$mySQL[user],$mySQL[password],$mySQL[dbname]); + mysqli_query($dbconnection,"SET CHARACTER SET 'utf8'"); + mysqli_query($dbconnection,"INSERT INTO `".$mySQL[table]."` (`id`,`password`,`data`,`modified`,`expire`,`mime`) VALUES ('".$_POST['pasteid']."','".$_POST['password']."',NULL,CURRENT_TIMESTAMP ,'".date("Y-m-d h:i:s", $_SESSION['expiretimestamp'])."','".$DefaultMIMEtype."');"); + if (mysqli_errno($dbconnection)==1062) echo "",$Titles[WrongPasteID],"
\n
\n"; + else if (mysqli_errno($dbconnection)==0) + { + $CorrectPasteID="true"; + echo $Titles[addDone],"
\n"; + $_SESSION['formpasteid']=""; + if ($SettingMaxFileSizeBytes>$_FILES['filedata']['size']&&$_FILES['filedata']['size']>0) + { + $filedata=addslashes(fread(fopen($_FILES['filedata']['tmp_name'],"rb"),filesize($_FILES['filedata']['tmp_name']))); + mysqli_query($dbconnection,"UPDATE `$mySQL[table]` SET `data` = '$filedata' WHERE `$mySQL[table]`.`id` = '".$_POST['pasteid']."';"); + } + } + else echo "",$Titles[ErrorAdd],mysqli_error($dbconnection),"
\n
\n"; + } + } + } + if (!($_POST['submit'])||!($CorrectPasteID)) + { + $captchanumber1=rand(1, 50); + $captchanumber2=rand(1, 49); + $_SESSION['captcha']=$captchanumber1+$captchanumber2; + $_SESSION['expiretimestamp']=(time()+$SettingExpireDays*24*60*60); + echo "

",$Titles[registerNew],"

\n"; + echo "
\n"; + echo " ",$Titles[PasteID],":
\n"; + echo " ",$Titles[Password],":
\n"; + echo " ",$Titles[Password],": (",$Titles[Check],")
\n"; + echo " ",$Titles[CheckSymbols],"
\n"; + echo " ",$Titles[UploadFile],": (",$Titles[NotNecessary],")
\n"; + echo " ",$Titles[MaximumSize],$SettingMaxFileSizeBytes,$Titles[Bytes],"
\n"; + echo " ",$Titles[Expire],": ",date("Y m d", $_SESSION['expiretimestamp']),"
\n"; + echo " ",$Titles[MIMEtype],": ",$DefaultMIMEtype," (",$Titles[CanBeChanged],")
\n"; + echo " ",$Titles[Captcha],": $captchanumber1 ",$Titles[Plus]," $captchanumber2 = ?
\n"; + echo " \n"; + echo "
\n"; + } + HTMLfooter(); + } + +else if (ParsedURI()[0]=="edit") + { + if (ParsedURI()[1]) + { + $URIid=ParsedURI()[1]; + $dbconnection=mysqli_connect($mySQL[host],$mySQL[user],$mySQL[password],$mySQL[dbname]); + mysqli_query($dbconnection,"SET CHARACTER SET 'utf8'"); + $paste=mysqli_fetch_object(mysqli_query($dbconnection,"SELECT * FROM `".$mySQL[table]."` WHERE `id` = '$URIid';")); + if ($URIid===$paste->id) + { + session_start(); + HTMLheader(); + if($_POST['submit']) + { + if ($_POST['password']===$paste->password) $_SESSION['editstatus']=$paste->id; + else echo "",$Titles[WrongPassword],"
\n
\n"; + } + if($_POST['exit']) $_SESSION['editstatus']=""; + if($_POST['submit2']) + { + $editerror=""; + if ($SettingMaxFileSizeBytes>$_FILES['filedata']['size']&&$_FILES['filedata']['size']>0) + { + $filedata=addslashes(fread(fopen($_FILES['filedata']['tmp_name'],"rb"),filesize($_FILES['filedata']['tmp_name']))); + mysqli_query($dbconnection,"UPDATE `$mySQL[table]` SET `data` = '$filedata' WHERE `$mySQL[table]`.`id` = '".$paste->id."';"); + mysqli_query($dbconnection,"UPDATE `$mySQL[table]` SET `modified` = NOW( ) WHERE `$mySQL[table]`.`id` = '".$paste->id."';"); + } + if ($_POST['mime']!=$paste->mime) + { + if(!ereg("^[a-zA-Z0-9\./+-]+$",$_POST['mime'])) $editerror=$editerror."".$Titles[WrongSymbolsMIME]."

\n"; + else mysqli_query($dbconnection,"UPDATE `$mySQL[table]` SET `mime` = '".$_POST['mime']."' WHERE `$mySQL[table]`.`id` = '".$paste->id."';"); + } + if($_POST['password']||$_POST['password2']) + { + if($_POST['password']===$_POST['password2']) + { + if(!ereg("^[a-zA-Z0-9_\.-]+$",$_POST['password'])) $editerror=$editerror."".$Titles[WrongSymbols]."

\n"; + else + { + mysqli_query($dbconnection,"UPDATE `$mySQL[table]` SET `password` = '".$_POST['password']."' WHERE `$mySQL[table]`.`id` = '".$paste->id."';"); + $editerror=$editerror."".$Titles[PasswordUpdated]."

\n"; + } + } + else $editerror=$editerror."".$Titles[WrongPassword]."

\n"; + } + $paste=mysqli_fetch_object(mysqli_query($dbconnection,"SELECT * FROM `".$mySQL[table]."` WHERE `id` = '$URIid';")); + } + if($_SESSION['editstatus']==$URIid) + { + echo "
\n"; + echo "

",$Titles[PasteID],": ",$paste->id,"


\n"; + echo " ",$editerror; + echo " ",$Titles[Data],": "; + if (strlen($paste->data)>0) echo "id,"\">",strlen($paste->data),$Titles[Bytes],"
\n"; + else echo "0",$Titles[Bytes],"
\n"; + echo " ",$Titles[Modified],": ",$paste->modified,"
\n"; + echo " ",$Titles[Expire],": ",$paste->expire,"
\n"; + echo " ",$Titles[UploadFile],":
\n"; + echo " ",$Titles[MIMEtype],": mime,"\" maxlength=255>
\n"; + echo " ",$Titles[NewPassword],":
\n"; + echo " ",$Titles[NewPassword],": (",$Titles[Check],")
\n"; + echo "

\n"; + echo " \n"; + echo "
\n"; + } + else + { + echo "
\n"; + echo " ",$Titles[Password],":
\n"; + echo " \n"; + echo "
\n"; + } + HTMLheader(); + } + else HTML404(); + } else HTML404(); + } + +else HTML404(); + +?> diff --git a/storage.sql b/storage.sql new file mode 100644 index 0000000..6b76513 --- /dev/null +++ b/storage.sql @@ -0,0 +1,50 @@ +-- phpMyAdmin SQL Dump +-- version 4.5.4.1deb2ubuntu2 +-- http://www.phpmyadmin.net +-- +-- Host: localhost +-- Generation Time: Feb 08, 2017 at 05:53 PM +-- Server version: 5.7.17-0ubuntu0.16.04.1 +-- PHP Version: 7.0.13-0ubuntu0.16.04.1 + +SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; +SET time_zone = "+00:00"; + + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8mb4 */; + +-- +-- Database: `pastedfile` +-- + +-- -------------------------------------------------------- + +-- +-- Table structure for table `storage` +-- + +CREATE TABLE `storage` ( + `id` char(255) COLLATE utf8_bin NOT NULL, + `password` char(255) COLLATE utf8_bin NOT NULL, + `data` mediumblob, + `modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `expire` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', + `mime` char(255) COLLATE utf8_bin NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; + +-- +-- Indexes for dumped tables +-- + +-- +-- Indexes for table `storage` +-- +ALTER TABLE `storage` + ADD PRIMARY KEY (`id`); + +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;