From 6617d03a1748f7049e26a7ee8159eaa1ccfd5d55 Mon Sep 17 00:00:00 2001 From: Pijus Kamandulis Date: Wed, 13 Sep 2023 22:36:33 +0300 Subject: [PATCH] Reorganize file structure --- MyPastes.php | 60 -------- NewPaste.php | 12 -- NewPastePanel.php | 119 -------------- NewestPastes.php | 18 --- README.md | 10 +- UserPage.php | 52 ------- ViewPaste.php | 56 ------- cronjob.php | 19 --- delete.php | 42 ----- docker-compose.yml | 4 +- edit.php | 35 ----- index.php | 145 ------------------ login.php | 120 --------------- nginx_cfg.conf | 2 +- signup.php | 29 ---- src/cronjob.php | 19 +++ src/delete.php | 42 +++++ {config => src/includes}/config.php | 5 +- {includes => src/includes}/highlight.php | 99 ++++++------ {includes => src/includes}/user.php | 117 +++++++------- src/index.php | 46 ++++++ post.php => src/post.php | 3 +- .../public/css}/SyntaxHighlighter/shCore.css | 0 .../css}/SyntaxHighlighter/shCoreDefault.css | 0 .../css}/SyntaxHighlighter/shThemeDefault.css | 0 {css => src/public/css}/bootstrap-theme.css | 0 .../public/css}/bootstrap-theme.css.map | 0 .../public/css}/bootstrap-theme.min.css | 0 .../public/css}/bootstrap-theme.min.css.map | 0 {css => src/public/css}/bootstrap.css | 0 {css => src/public/css}/bootstrap.css.map | 0 {css => src/public/css}/bootstrap.min.css | 0 {css => src/public/css}/bootstrap.min.css.map | 0 {css => src/public/css}/chosen.css | 0 {css => src/public/css}/jquery.dynatable.css | 0 .../fonts}/glyphicons-halflings-regular.eot | Bin .../fonts}/glyphicons-halflings-regular.svg | 0 .../fonts}/glyphicons-halflings-regular.ttf | Bin .../fonts}/glyphicons-halflings-regular.woff | Bin .../fonts}/glyphicons-halflings-regular.woff2 | Bin .../js}/SyntaxHighlighter/shAutoloader.js | 0 .../js}/SyntaxHighlighter/shBrushAS3.js | 0 .../SyntaxHighlighter/shBrushAppleScript.js | 0 .../js}/SyntaxHighlighter/shBrushBash.js | 0 .../js}/SyntaxHighlighter/shBrushCSharp.js | 0 .../SyntaxHighlighter/shBrushColdFusion.js | 0 .../js}/SyntaxHighlighter/shBrushCpp.js | 0 .../js}/SyntaxHighlighter/shBrushCss.js | 0 .../js}/SyntaxHighlighter/shBrushDelphi.js | 0 .../js}/SyntaxHighlighter/shBrushDiff.js | 0 .../js}/SyntaxHighlighter/shBrushErlang.js | 0 .../js}/SyntaxHighlighter/shBrushGroovy.js | 0 .../js}/SyntaxHighlighter/shBrushJScript.js | 0 .../js}/SyntaxHighlighter/shBrushJava.js | 0 .../js}/SyntaxHighlighter/shBrushJavaFX.js | 0 .../js}/SyntaxHighlighter/shBrushPerl.js | 0 .../js}/SyntaxHighlighter/shBrushPhp.js | 0 .../js}/SyntaxHighlighter/shBrushPlain.js | 0 .../SyntaxHighlighter/shBrushPowerShell.js | 0 .../js}/SyntaxHighlighter/shBrushPython.js | 0 .../js}/SyntaxHighlighter/shBrushRuby.js | 0 .../js}/SyntaxHighlighter/shBrushSass.js | 0 .../js}/SyntaxHighlighter/shBrushScala.js | 0 .../js}/SyntaxHighlighter/shBrushSql.js | 0 .../public/js}/SyntaxHighlighter/shBrushVb.js | 0 .../js}/SyntaxHighlighter/shBrushXml.js | 0 .../public/js}/SyntaxHighlighter/shCore.js | 0 .../public/js}/SyntaxHighlighter/shLegacy.js | 0 {js => src/public/js}/bootstrap.js | 0 {js => src/public/js}/bootstrap.min.js | 0 {js => src/public/js}/chosen.jquery.js | 0 {js => src/public/js}/chosen.proto.js | 0 {js => src/public/js}/jquery.dynatable.js | 0 {js => src/public/js}/npm.js | 0 .../public/js}/vendor/jquery-1.7.2.min.js | 0 src/views/_layout.php | 44 ++++++ src/views/_navbar.php | 79 ++++++++++ src/views/_new-paste.php | 119 ++++++++++++++ src/views/_recent-pastes.php | 18 +++ src/views/edit.php | 35 +++++ src/views/login.php | 119 ++++++++++++++ src/views/my-pastes.php | 60 ++++++++ src/views/new-paste.php | 12 ++ src/views/signup.php | 29 ++++ src/views/user.php | 52 +++++++ src/views/view-paste.php | 55 +++++++ 86 files changed, 847 insertions(+), 829 deletions(-) delete mode 100644 MyPastes.php delete mode 100644 NewPaste.php delete mode 100644 NewPastePanel.php delete mode 100644 NewestPastes.php delete mode 100644 UserPage.php delete mode 100644 ViewPaste.php delete mode 100644 cronjob.php delete mode 100644 delete.php delete mode 100644 edit.php delete mode 100644 index.php delete mode 100644 login.php delete mode 100644 signup.php create mode 100644 src/cronjob.php create mode 100644 src/delete.php rename {config => src/includes}/config.php (73%) rename {includes => src/includes}/highlight.php (83%) rename {includes => src/includes}/user.php (68%) create mode 100644 src/index.php rename post.php => src/post.php (96%) rename {css => src/public/css}/SyntaxHighlighter/shCore.css (100%) rename {css => src/public/css}/SyntaxHighlighter/shCoreDefault.css (100%) rename {css => src/public/css}/SyntaxHighlighter/shThemeDefault.css (100%) rename {css => src/public/css}/bootstrap-theme.css (100%) rename {css => src/public/css}/bootstrap-theme.css.map (100%) rename {css => src/public/css}/bootstrap-theme.min.css (100%) rename {css => src/public/css}/bootstrap-theme.min.css.map (100%) rename {css => src/public/css}/bootstrap.css (100%) rename {css => src/public/css}/bootstrap.css.map (100%) rename {css => src/public/css}/bootstrap.min.css (100%) rename {css => src/public/css}/bootstrap.min.css.map (100%) rename {css => src/public/css}/chosen.css (100%) rename {css => src/public/css}/jquery.dynatable.css (100%) rename {fonts => src/public/fonts}/glyphicons-halflings-regular.eot (100%) rename {fonts => src/public/fonts}/glyphicons-halflings-regular.svg (100%) rename {fonts => src/public/fonts}/glyphicons-halflings-regular.ttf (100%) rename {fonts => src/public/fonts}/glyphicons-halflings-regular.woff (100%) rename {fonts => src/public/fonts}/glyphicons-halflings-regular.woff2 (100%) rename {js => src/public/js}/SyntaxHighlighter/shAutoloader.js (100%) rename {js => src/public/js}/SyntaxHighlighter/shBrushAS3.js (100%) rename {js => src/public/js}/SyntaxHighlighter/shBrushAppleScript.js (100%) rename {js => src/public/js}/SyntaxHighlighter/shBrushBash.js (100%) rename {js => src/public/js}/SyntaxHighlighter/shBrushCSharp.js (100%) rename {js => src/public/js}/SyntaxHighlighter/shBrushColdFusion.js (100%) rename {js => src/public/js}/SyntaxHighlighter/shBrushCpp.js (100%) rename {js => src/public/js}/SyntaxHighlighter/shBrushCss.js (100%) rename {js => src/public/js}/SyntaxHighlighter/shBrushDelphi.js (100%) rename {js => src/public/js}/SyntaxHighlighter/shBrushDiff.js (100%) rename {js => src/public/js}/SyntaxHighlighter/shBrushErlang.js (100%) rename {js => src/public/js}/SyntaxHighlighter/shBrushGroovy.js (100%) rename {js => src/public/js}/SyntaxHighlighter/shBrushJScript.js (100%) rename {js => src/public/js}/SyntaxHighlighter/shBrushJava.js (100%) rename {js => src/public/js}/SyntaxHighlighter/shBrushJavaFX.js (100%) rename {js => src/public/js}/SyntaxHighlighter/shBrushPerl.js (100%) rename {js => src/public/js}/SyntaxHighlighter/shBrushPhp.js (100%) rename {js => src/public/js}/SyntaxHighlighter/shBrushPlain.js (100%) rename {js => src/public/js}/SyntaxHighlighter/shBrushPowerShell.js (100%) rename {js => src/public/js}/SyntaxHighlighter/shBrushPython.js (100%) rename {js => src/public/js}/SyntaxHighlighter/shBrushRuby.js (100%) rename {js => src/public/js}/SyntaxHighlighter/shBrushSass.js (100%) rename {js => src/public/js}/SyntaxHighlighter/shBrushScala.js (100%) rename {js => src/public/js}/SyntaxHighlighter/shBrushSql.js (100%) rename {js => src/public/js}/SyntaxHighlighter/shBrushVb.js (100%) rename {js => src/public/js}/SyntaxHighlighter/shBrushXml.js (100%) rename {js => src/public/js}/SyntaxHighlighter/shCore.js (100%) rename {js => src/public/js}/SyntaxHighlighter/shLegacy.js (100%) rename {js => src/public/js}/bootstrap.js (100%) rename {js => src/public/js}/bootstrap.min.js (100%) rename {js => src/public/js}/chosen.jquery.js (100%) rename {js => src/public/js}/chosen.proto.js (100%) rename {js => src/public/js}/jquery.dynatable.js (100%) rename {js => src/public/js}/npm.js (100%) rename {js => src/public/js}/vendor/jquery-1.7.2.min.js (100%) create mode 100644 src/views/_layout.php create mode 100644 src/views/_navbar.php create mode 100644 src/views/_new-paste.php create mode 100644 src/views/_recent-pastes.php create mode 100644 src/views/edit.php create mode 100644 src/views/login.php create mode 100644 src/views/my-pastes.php create mode 100644 src/views/new-paste.php create mode 100644 src/views/signup.php create mode 100644 src/views/user.php create mode 100644 src/views/view-paste.php diff --git a/MyPastes.php b/MyPastes.php deleted file mode 100644 index 46a6107..0000000 --- a/MyPastes.php +++ /dev/null @@ -1,60 +0,0 @@ -
-
-
-You must be loged in to see your pastes!'); - $conn = null; - echo '
'; - die(); -} -$stmt = $conn->prepare('SELECT * FROM pastes WHERE owner=:own'); -$own = GetUsersIDBySession($_COOKIE["pp_sid"],$_COOKIE["pp_skey"]); -$stmt->bindParam(':own', $own); -$stmt->execute(); -if($stmt->rowCount()>0){ - echo ""; - printf(' - - - - '); - printf(''); - while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { - $title = $row['title']; - //Paste title - printf(''); - //Creation date - printf(''); - //Expire date - if($row["expire"]==0) printf(''); - else{ - $expire = ($row["expire"]-time())/3600; - if($expire>24){ - printf(''); - } else if($expire>=1) - printf(''); - else printf(''); - } - //Paste url - printf(''); - //Actions - printf(''); - } - printf(''); -} else { - printf('

You havent made any pastes yet!

'); -} -$conn = null; -?> - - - \ No newline at end of file diff --git a/NewPaste.php b/NewPaste.php deleted file mode 100644 index c0fb74b..0000000 --- a/NewPaste.php +++ /dev/null @@ -1,12 +0,0 @@ -
-
-
-
- -
-
- -
-
-
-
diff --git a/NewPastePanel.php b/NewPastePanel.php deleted file mode 100644 index df79ce5..0000000 --- a/NewPastePanel.php +++ /dev/null @@ -1,119 +0,0 @@ -
-
-'); - }else printf('
'); -?> -
- - '); - } else printf(''); - ?> -
-
- - '.$row['text'].''; - } else printf(''); - ?> -
- "); - printf(""); - } else printf(""); - ?> -
-
-
- -
- -
- - -
-
- -
- - -
- -
- - -
- -
- - -
- -
-
-
- -
-
diff --git a/NewestPastes.php b/NewestPastes.php deleted file mode 100644 index 2e69c35..0000000 --- a/NewestPastes.php +++ /dev/null @@ -1,18 +0,0 @@ -
-
-

Newest pastes:

-
- query('SELECT * FROM pastes WHERE exposure=0 ORDER BY id DESC LIMIT 5'); - while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { - $title = htmlspecialchars($row['title'], ENT_QUOTES, 'UTF-8'); - if(strlen($title)>25)$title = substr($title,0,25)."..."; - echo "".$title.""; - } - $conn = null; - ?> -
-
-
\ No newline at end of file diff --git a/README.md b/README.md index 40cf024..328d223 100644 --- a/README.md +++ b/README.md @@ -6,18 +6,18 @@ It's in active development so stay tuned for updates. Also if you have any ideas you can contact me on twitter, I'm @pik4mi If you have any issues, file them here https://github.com/pikami/palm-paste/issues -#Note -Original development environment is Apache 2.4 + PHP5.6 + MySQL. -Should work with Nginx and any PDO-compatible database. +# Note +Original development environment is Nginx + PHP5.6 + MySQL. +Should work with Apache. -#Install +# Install For the purposes of this guide, we won't cover setting up Apache, PHP, MySQL, or Nginx. So we'll just assume you already have them all running well. 1. Download palm-paste from https://github.com/pikami/palm-paste/tags 2. Create a user and database for palm-paste 3. Take the 'palm-paste.sql' and import it to your database. -4. Edit configuration settings in config/config.php +4. Edit configuration settings in includes/config.php 5. (For apache users) Change the "RewriteBase" setting in ".htaccess" file to the root of your palm-paste installation 5. (For nginx users) add the block from nginx_cfg.txt to your nginx server config, replace all occurrences of "paste" with the root of your palm-paste installation 6. Done! diff --git a/UserPage.php b/UserPage.php deleted file mode 100644 index 60b7629..0000000 --- a/UserPage.php +++ /dev/null @@ -1,52 +0,0 @@ -
-
-
-'.$owner["user"].'\'s profile'); - //== Print pastes ==// - $query = "SELECT * FROM pastes WHERE owner=:own AND exposure=0"; - if(GetUsersIDBySession($_COOKIE["pp_sid"],$_COOKIE["pp_skey"]) == $ownerID)$query = "SELECT * FROM pastes WHERE owner=:own"; - $stmt = $conn->prepare($query); - $stmt->bindParam(':own', $ownerID); - $stmt->execute(); - - if($stmt->rowCount()>0){ - echo "
TitleAddedExpiresIDActions
'.htmlspecialchars($row["title"], ENT_QUOTES, 'UTF-8').''.date('Y-m-d',$row["created"]).'Never'.round($expire/24).' days from now'.round($expire).' hours from now'.round($expire*60).' minutes from now'.htmlspecialchars($row["uid"], ENT_QUOTES, 'UTF-8').''); - //delete paste - printf(''); - //edit paste - printf(''); - printf('
"; - printf(' - - - '); - printf(''); - while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { - $title = $row['title']; - printf(''); - printf(''); - if($row["expire"]==0) printf(''); - else{ - $expire = ($row["expire"]-time())/3600; - if($expire>24){ - printf(''); - } else if($expire>=1) - printf(''); - else printf(''); - } - printf(''); - } - printf(''); - } else { - printf('

This user has no public pastes!

'); - } -} else printf('

User does not exist!

'); -$conn = null; -?> - - - \ No newline at end of file diff --git a/ViewPaste.php b/ViewPaste.php deleted file mode 100644 index 330a548..0000000 --- a/ViewPaste.php +++ /dev/null @@ -1,56 +0,0 @@ -
-
-
-query('SELECT * FROM pastes WHERE uid="'.$uid.'"'); - if($result = $stmt->fetch(PDO::FETCH_ASSOC)){ - $conn = null; - if($result["expire"]!=0 && $result["expire"]This paste just expired"; - include_once "cronjob.php"; - RemoveExpiredPastes(); - die(); - } - if($result["exposure"]==2 && $result["owner"]!=0 && isset($_COOKIE["pp_sid"]) && isset($_COOKIE["pp_skey"]) && $result["owner"]!=GetUsersIDBySession($_COOKIE["pp_sid"],$_COOKIE["pp_skey"])){ - echo "

This paste is private

"; - die(); - } - echo "

".htmlspecialchars($result["title"], ENT_QUOTES, 'UTF-8')."

"; - // - $owner = GetUserByID($result["owner"]); - echo "
"; - if($owner[1] == -1) - echo "Posted by: Guest"; - else echo "Posted by: ".htmlspecialchars($owner[1]).""; - echo ", at ".date('Y-m-d',$result["created"]).", it will expire "; - if($result["expire"]==0) printf('Never'); - else{ - $expire = ($result["expire"]-time())/3600; - if($expire>24){ - printf(round($expire/24).' days from now'); - } else if($expire>=1) - printf(round($expire).' hours from now'); - else printf(round($expire*60).' minutes from now'); - } - echo "
"; - // - echo "
";
-		echo htmlspecialchars($result["text"], ENT_QUOTES, 'UTF-8')."
"; - echo ""; - echo ""; - } - else echo "Paste does not exist"; - $conn = null; -} else echo "Error: id not set"; -?> - -
-
-
\ No newline at end of file diff --git a/cronjob.php b/cronjob.php deleted file mode 100644 index ac71237..0000000 --- a/cronjob.php +++ /dev/null @@ -1,19 +0,0 @@ -prepare("DELETE from `pastes` where `expire`<:time and `expire`>0"); - $stmt->bindValue(':time', $time); - $stmt->execute(); - $conn = null; //close connection to database - echo 'OK! 200'; -} -if (isset($_GET["key"])){ - if($_GET["key"]==$CRON_ExpireKey){ //Delete expired pastes - RemoveExpiredPastes(); - } -} -//Cron job example: */5 * * * * curl --silent http://127.0.0.1/paste/cronjob.php?key=fgd45fb5fb15gb > /dev/null -//More about cron jobs: http://www.shellhacks.com/en/Adding-Cron-Jobs-in-Linux-Crontab-Usage-and-Examples -?> \ No newline at end of file diff --git a/delete.php b/delete.php deleted file mode 100644 index 8881d08..0000000 --- a/delete.php +++ /dev/null @@ -1,42 +0,0 @@ -
-
-
-prepare('SELECT * FROM pastes WHERE uid=:uid'); - $stmt->bindParam(':uid', $paste); - $stmt->execute(); - if($stmt->rowCount()>0){ - while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { - if($row['owner'] === $uid){ - $stmt2 = $conn->prepare("DELETE FROM pastes WHERE id=:id"); - $stmt2->bindParam(':id', $row['id']); - $stmt2->execute(); - $conn = null; - echo '

Paste '.$row["uid"].' has been deleted!

'; - echo ''; - die(); - } else { - $conn = null; - echo '

You are not the owner of the paste '.$row["uid"].'

'; - echo ''; - die(); - } - } - } else { - $conn = null; - echo '

The paste '.$row["uid"].' does not exist

'; - echo ''; - die(); - } - $conn = null; - } -?> -
-
-
\ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index ffeea5c..3068c73 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,7 +6,7 @@ services: ports: - '8080:80' volumes: - - ./:/var/www/html + - ./src:/var/www/html - ./nginx_cfg.conf:/etc/nginx/conf.d/default.conf links: - php-fpm @@ -17,7 +17,7 @@ services: environment: SQL_HOST: db volumes: - - ./:/var/www/html + - ./src:/var/www/html db: image: mysql:5.6 diff --git a/edit.php b/edit.php deleted file mode 100644 index e943a5b..0000000 --- a/edit.php +++ /dev/null @@ -1,35 +0,0 @@ -
-
-
-prepare('SELECT * FROM pastes WHERE uid=:uid'); - $stmt->bindParam(':uid', $paste); - $stmt->execute(); - if($stmt->rowCount()>0){ - while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { - if($row['owner'] === $uid){ - include "NewPastePanel.php"; - } else { - $conn = null; - echo '

You are not the owner of the paste '.$row["uid"].'

'; - echo ''; - die(); - } - } - } else { - $conn = null; - echo '

The paste '.$row["uid"].' does not exist

'; - echo ''; - } - $conn = null; - } -?> -
-
-
\ No newline at end of file diff --git a/index.php b/index.php deleted file mode 100644 index 51a1626..0000000 --- a/index.php +++ /dev/null @@ -1,145 +0,0 @@ - - - - - Palm-Paste Index - - '; - $dir = ""; - if (isset($_GET["user"]) || isset($_GET["page"]) && $_GET["page"]=="edit")$dir="../"; - - echo ''; - echo ''; - - echo ''; - echo ''; - echo ''; - - echo ''; - echo ''; - echo ''; - - echo ""; - - // - include_once "includes/highlight.php"; - ?> - - - - - - - -

Please wait...

'; - echo ''; - die(); - } else if($_GET["page"] == "signup"){ - include_once "signup.php"; - } else if($_GET["page"] == "edit"){ - include_once "edit.php"; - } else { - $uid = $_GET["page"]; - include_once "ViewPaste.php"; - } -} else if (isset($_GET["user"])){ - include_once "UserPage.php"; -} else { - include_once "NewPaste.php"; -} -?> - - diff --git a/login.php b/login.php deleted file mode 100644 index 815d582..0000000 --- a/login.php +++ /dev/null @@ -1,120 +0,0 @@ -

Please wait...

'; - echo ''; -} else if(isset($_POST["type"])) { - if($_POST["type"]=="login" && isset($_POST["user"]) && isset($_POST["pwd"])){ - //Get options - $user = $_POST["user"]; - $pwd = $_POST["pwd"]; - $remember = 0; - if(isset($_POST["remember"]) && $_POST["remember"]=="on") - $remember = 1; - //Try to login - include_once "config/config.php"; - $conn = GetConnectionToDB(); - $stmt = $conn->prepare('SELECT * FROM users WHERE user=?'); - $stmt->execute(array($user)); - if($result = $stmt->fetch(PDO::FETCH_ASSOC)){ - if (password_verify($pwd, $result["password"])){ - $skey = generate_skey(); - $stmt = $conn->prepare("INSERT INTO sessions (skey, uid) - VALUES (:skey, :uid)"); - $stmt->bindParam(':skey', $skey); - $stmt->bindParam(':uid', $result["id"]); - $stmt->execute(); - $sid = $conn->lastInsertId(); - $conn = null; - if($remember == 1){ - setcookie("pp_sid", $sid, time()+63072000); //Dies in 2 years - setcookie("pp_skey", $skey, time()+63072000); //Dies in 2 years - } else { - setcookie("pp_sid", $sid); //Dies when browser closes - setcookie("pp_skey", $skey); //Dies when browser closes - } - echo '

Please wait...

'; - echo ''; - die(); - } - else echo "No!"; //TODO: Wrong password - } else echo "Fail!"; //TODO: No user or SQL fail. - $conn = null; - } - if($_POST["type"]=="register" && isset($_POST["user"]) && isset($_POST["pwd"])){ - //Get options - $user = $_POST["user"]; - $pwd = $_POST["pwd"]; - $hash = password_hash($pwd ,CRYPT_BLOWFISH); - //Does this user exist - include_once "config/config.php"; - $conn = GetConnectionToDB(); - $stmt = $conn->prepare('SELECT * FROM users WHERE user=?'); - $stmt->execute(array($user)); - if($result = $stmt->fetch(PDO::FETCH_ASSOC)){ - echo "

User allready exists!

"; - $conn = null; - die(); - } - //Did the person enter a password - if($pwd==""){ - echo "

You need a password to singup!

"; - $conn = null; - die(); - } - //Register the user - $stmt = $conn->prepare("INSERT INTO users (user,password) - VALUES (:user, :pwd)"); - $stmt->bindParam(':user', $user); - $stmt->bindParam(':pwd', $hash); - if($stmt->execute()){ - echo '

Please wait...

'; - echo ''; - } else { - echo "Fail!"; - } - $conn = null; - } -} else { - echo ' -
-
-
Login
-
- '; - echo ' -
-
- - -
-
- - -
-
- -
- - - - '; - echo ' -
-
-
- '; -} -?> \ No newline at end of file diff --git a/nginx_cfg.conf b/nginx_cfg.conf index bf404d1..c44f8c4 100644 --- a/nginx_cfg.conf +++ b/nginx_cfg.conf @@ -16,7 +16,7 @@ server { } location / { - if ( $uri !~ ^/(index\.php|css|js|robots\.txt|favicon\.ico|$) ) { + if ( $uri !~ ^/(fonts|public|index\.php|css|js|robots\.txt|favicon\.ico|$) ) { rewrite ^/u/(.*)$ /index.php?user=$1? last; rewrite ^/delete/(.*)$ /delete.php?id=$1? last; rewrite ^/([^/]+)/(.*)$ /index.php?page=$1&id=$2? last; diff --git a/signup.php b/signup.php deleted file mode 100644 index 29d5006..0000000 --- a/signup.php +++ /dev/null @@ -1,29 +0,0 @@ -
-
-
Register
-
- -
-
- -
- -
-
-
- -
- -
-
-
-
- - -
-
- - -
-
-
\ No newline at end of file diff --git a/src/cronjob.php b/src/cronjob.php new file mode 100644 index 0000000..2de2765 --- /dev/null +++ b/src/cronjob.php @@ -0,0 +1,19 @@ +prepare("DELETE from `pastes` where `expire`<:time and `expire`>0"); + $stmt->bindValue(':time', $time); + $stmt->execute(); + $conn = null; //close connection to database + echo 'OK! 200'; +} +if (isset($_GET["key"])) { + if ($_GET["key"] == $CRON_ExpireKey) { //Delete expired pastes + RemoveExpiredPastes(); + } +} +//Cron job example: */5 * * * * curl --silent http://127.0.0.1/paste/cronjob.php?key=fgd45fb5fb15gb > /dev/null +//More about cron jobs: http://www.shellhacks.com/en/Adding-Cron-Jobs-in-Linux-Crontab-Usage-and-Examples diff --git a/src/delete.php b/src/delete.php new file mode 100644 index 0000000..53d84b5 --- /dev/null +++ b/src/delete.php @@ -0,0 +1,42 @@ +
+
+
+ prepare('SELECT * FROM pastes WHERE uid=:uid'); + $stmt->bindParam(':uid', $paste); + $stmt->execute(); + if ($stmt->rowCount() > 0) { + while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { + if ($row['owner'] === $uid) { + $stmt2 = $conn->prepare("DELETE FROM pastes WHERE id=:id"); + $stmt2->bindParam(':id', $row['id']); + $stmt2->execute(); + $conn = null; + echo '

Paste ' . $row["uid"] . ' has been deleted!

'; + echo ''; + die(); + } else { + $conn = null; + echo '

You are not the owner of the paste ' . $row["uid"] . '

'; + echo ''; + die(); + } + } + } else { + $conn = null; + echo '

The paste ' . $row["uid"] . ' does not exist

'; + echo ''; + die(); + } + $conn = null; + } + ?> +
+
+
\ No newline at end of file diff --git a/config/config.php b/src/includes/config.php similarity index 73% rename from config/config.php rename to src/includes/config.php index a9410bd..6a0b873 100644 --- a/config/config.php +++ b/src/includes/config.php @@ -1,14 +1,13 @@ diff --git a/includes/highlight.php b/src/includes/highlight.php similarity index 83% rename from includes/highlight.php rename to src/includes/highlight.php index 6760a7d..3e5839f 100644 --- a/includes/highlight.php +++ b/src/includes/highlight.php @@ -1,50 +1,49 @@ -'; - // - include_once "config/config.php"; - $conn = GetConnectionToDB(); - $stmt = $conn->query('SELECT highlight FROM pastes WHERE uid="'.$uid.'"'); - if($result = $stmt->fetch(PDO::FETCH_ASSOC)){ - $conn = null; - $_HL = $result["highlight"]; - if($_HL == "")$_HL = "plain"; - echo ''; - } - $conn = null; - // - echo ' - '; - } - } -?> \ No newline at end of file +'; + // + include_once "includes/config.php"; + $conn = GetConnectionToDB(); + $stmt = $conn->query('SELECT highlight FROM pastes WHERE uid="'.$uid.'"'); + if($result = $stmt->fetch(PDO::FETCH_ASSOC)){ + $conn = null; + $_HL = $result["highlight"]; + if($_HL == "")$_HL = "plain"; + echo ''; + } + $conn = null; + // + echo ' + '; + } + } diff --git a/includes/user.php b/src/includes/user.php similarity index 68% rename from includes/user.php rename to src/includes/user.php index 9f5ba50..122406a 100644 --- a/includes/user.php +++ b/src/includes/user.php @@ -1,59 +1,58 @@ -prepare("SELECT uid FROM sessions WHERE id=:sid AND skey=:skey"); - $stmt->bindParam(':skey', $skey); - $stmt->bindParam(':sid', $sid); - $stmt->execute(); - if($result = $stmt->fetch()){ - $conn = null; - return $result[0]; - } else { - $conn = null; - return -1; - } -} -function LogOutUserBySession($sid,$skey){ - include_once "config/config.php"; - $conn = GetConnectionToDB(); - $stmt = $conn->prepare("DELETE FROM sessions WHERE id=:sid AND skey=:skey"); - $stmt->bindParam(':skey', $skey); - $stmt->bindParam(':sid', $sid); - $stmt->execute(); - $conn = null; -} -function UnsetBrowserCookies(){ - //These cookies expired an hour ago! What are you doind browser? :D - setcookie("pp_sid", '', time() - 3600); - setcookie("pp_skey", '', time() - 3600); -} -function GetUserByID($id){ - include_once "config/config.php"; - $conn = GetConnectionToDB(); - $stmt = $conn->prepare("SELECT * FROM users WHERE id=:id"); - $stmt->bindParam(':id', $id); - $stmt->execute(); - if($result = $stmt->fetch()){ - $conn = null; - return $result; - } else { - $conn = null; - return array(-1,-1,-1,-1); - } -} -function GetUserIDByName($name){ - include_once "config/config.php"; - $conn = GetConnectionToDB(); - $stmt = $conn->prepare("SELECT * FROM users WHERE user=:name"); - $stmt->bindParam(':name', $name); - $stmt->execute(); - if($result = $stmt->fetch()){ - $conn = null; - return $result[0]; - } else { - $conn = null; - return -1; - } -} -?> \ No newline at end of file +prepare("SELECT uid FROM sessions WHERE id=:sid AND skey=:skey"); + $stmt->bindParam(':skey', $skey); + $stmt->bindParam(':sid', $sid); + $stmt->execute(); + if ($result = $stmt->fetch()) { + $conn = null; + return $result[0]; + } else { + $conn = null; + return -1; + } +} +function LogOutUserBySession($sid, $skey) { + include_once "includes/config.php"; + $conn = GetConnectionToDB(); + $stmt = $conn->prepare("DELETE FROM sessions WHERE id=:sid AND skey=:skey"); + $stmt->bindParam(':skey', $skey); + $stmt->bindParam(':sid', $sid); + $stmt->execute(); + $conn = null; +} +function UnsetBrowserCookies() { + //These cookies expired an hour ago! What are you doind browser? :D + setcookie("pp_sid", '', time() - 3600); + setcookie("pp_skey", '', time() - 3600); +} +function GetUserByID($id) { + include_once "includes/config.php"; + $conn = GetConnectionToDB(); + $stmt = $conn->prepare("SELECT * FROM users WHERE id=:id"); + $stmt->bindParam(':id', $id); + $stmt->execute(); + if ($result = $stmt->fetch()) { + $conn = null; + return $result; + } else { + $conn = null; + return array(-1, -1, -1, -1); + } +} +function GetUserIDByName($name) { + include_once "includes/config.php"; + $conn = GetConnectionToDB(); + $stmt = $conn->prepare("SELECT * FROM users WHERE user=:name"); + $stmt->bindParam(':name', $name); + $stmt->execute(); + if ($result = $stmt->fetch()) { + $conn = null; + return $result[0]; + } else { + $conn = null; + return -1; + } +} diff --git a/src/index.php b/src/index.php new file mode 100644 index 0000000..883261d --- /dev/null +++ b/src/index.php @@ -0,0 +1,46 @@ + +include_once "includes/highlight.php"; + +if (isset($_GET["page"])) { + switch ($_GET["page"]) { + case "create": + require "views/new-paste.php"; + break; + case "mypastes": + require "views/my-pastes.php"; + break; + case "login": + require "views/login.php"; + break; + case "logout": + echo '

Please wait...

'; + echo ''; + die(); + case "signup": + require "views/signup.php"; + break; + case "edit": + require "views/edit.php"; + break; + default: + $uid = $_GET["page"]; + require "views/view-paste.php"; + break; + } +} else if (isset($_GET["user"])) { + include_once "views/user.php"; +} else { + include_once "views/new-paste.php"; +} + +$content = ob_get_clean(); + +require 'views/_layout.php'; diff --git a/post.php b/src/post.php similarity index 96% rename from post.php rename to src/post.php index 42ca001..a47f52c 100644 --- a/post.php +++ b/src/post.php @@ -1,5 +1,5 @@ \ No newline at end of file diff --git a/css/SyntaxHighlighter/shCore.css b/src/public/css/SyntaxHighlighter/shCore.css similarity index 100% rename from css/SyntaxHighlighter/shCore.css rename to src/public/css/SyntaxHighlighter/shCore.css diff --git a/css/SyntaxHighlighter/shCoreDefault.css b/src/public/css/SyntaxHighlighter/shCoreDefault.css similarity index 100% rename from css/SyntaxHighlighter/shCoreDefault.css rename to src/public/css/SyntaxHighlighter/shCoreDefault.css diff --git a/css/SyntaxHighlighter/shThemeDefault.css b/src/public/css/SyntaxHighlighter/shThemeDefault.css similarity index 100% rename from css/SyntaxHighlighter/shThemeDefault.css rename to src/public/css/SyntaxHighlighter/shThemeDefault.css diff --git a/css/bootstrap-theme.css b/src/public/css/bootstrap-theme.css similarity index 100% rename from css/bootstrap-theme.css rename to src/public/css/bootstrap-theme.css diff --git a/css/bootstrap-theme.css.map b/src/public/css/bootstrap-theme.css.map similarity index 100% rename from css/bootstrap-theme.css.map rename to src/public/css/bootstrap-theme.css.map diff --git a/css/bootstrap-theme.min.css b/src/public/css/bootstrap-theme.min.css similarity index 100% rename from css/bootstrap-theme.min.css rename to src/public/css/bootstrap-theme.min.css diff --git a/css/bootstrap-theme.min.css.map b/src/public/css/bootstrap-theme.min.css.map similarity index 100% rename from css/bootstrap-theme.min.css.map rename to src/public/css/bootstrap-theme.min.css.map diff --git a/css/bootstrap.css b/src/public/css/bootstrap.css similarity index 100% rename from css/bootstrap.css rename to src/public/css/bootstrap.css diff --git a/css/bootstrap.css.map b/src/public/css/bootstrap.css.map similarity index 100% rename from css/bootstrap.css.map rename to src/public/css/bootstrap.css.map diff --git a/css/bootstrap.min.css b/src/public/css/bootstrap.min.css similarity index 100% rename from css/bootstrap.min.css rename to src/public/css/bootstrap.min.css diff --git a/css/bootstrap.min.css.map b/src/public/css/bootstrap.min.css.map similarity index 100% rename from css/bootstrap.min.css.map rename to src/public/css/bootstrap.min.css.map diff --git a/css/chosen.css b/src/public/css/chosen.css similarity index 100% rename from css/chosen.css rename to src/public/css/chosen.css diff --git a/css/jquery.dynatable.css b/src/public/css/jquery.dynatable.css similarity index 100% rename from css/jquery.dynatable.css rename to src/public/css/jquery.dynatable.css diff --git a/fonts/glyphicons-halflings-regular.eot b/src/public/fonts/glyphicons-halflings-regular.eot similarity index 100% rename from fonts/glyphicons-halflings-regular.eot rename to src/public/fonts/glyphicons-halflings-regular.eot diff --git a/fonts/glyphicons-halflings-regular.svg b/src/public/fonts/glyphicons-halflings-regular.svg similarity index 100% rename from fonts/glyphicons-halflings-regular.svg rename to src/public/fonts/glyphicons-halflings-regular.svg diff --git a/fonts/glyphicons-halflings-regular.ttf b/src/public/fonts/glyphicons-halflings-regular.ttf similarity index 100% rename from fonts/glyphicons-halflings-regular.ttf rename to src/public/fonts/glyphicons-halflings-regular.ttf diff --git a/fonts/glyphicons-halflings-regular.woff b/src/public/fonts/glyphicons-halflings-regular.woff similarity index 100% rename from fonts/glyphicons-halflings-regular.woff rename to src/public/fonts/glyphicons-halflings-regular.woff diff --git a/fonts/glyphicons-halflings-regular.woff2 b/src/public/fonts/glyphicons-halflings-regular.woff2 similarity index 100% rename from fonts/glyphicons-halflings-regular.woff2 rename to src/public/fonts/glyphicons-halflings-regular.woff2 diff --git a/js/SyntaxHighlighter/shAutoloader.js b/src/public/js/SyntaxHighlighter/shAutoloader.js similarity index 100% rename from js/SyntaxHighlighter/shAutoloader.js rename to src/public/js/SyntaxHighlighter/shAutoloader.js diff --git a/js/SyntaxHighlighter/shBrushAS3.js b/src/public/js/SyntaxHighlighter/shBrushAS3.js similarity index 100% rename from js/SyntaxHighlighter/shBrushAS3.js rename to src/public/js/SyntaxHighlighter/shBrushAS3.js diff --git a/js/SyntaxHighlighter/shBrushAppleScript.js b/src/public/js/SyntaxHighlighter/shBrushAppleScript.js similarity index 100% rename from js/SyntaxHighlighter/shBrushAppleScript.js rename to src/public/js/SyntaxHighlighter/shBrushAppleScript.js diff --git a/js/SyntaxHighlighter/shBrushBash.js b/src/public/js/SyntaxHighlighter/shBrushBash.js similarity index 100% rename from js/SyntaxHighlighter/shBrushBash.js rename to src/public/js/SyntaxHighlighter/shBrushBash.js diff --git a/js/SyntaxHighlighter/shBrushCSharp.js b/src/public/js/SyntaxHighlighter/shBrushCSharp.js similarity index 100% rename from js/SyntaxHighlighter/shBrushCSharp.js rename to src/public/js/SyntaxHighlighter/shBrushCSharp.js diff --git a/js/SyntaxHighlighter/shBrushColdFusion.js b/src/public/js/SyntaxHighlighter/shBrushColdFusion.js similarity index 100% rename from js/SyntaxHighlighter/shBrushColdFusion.js rename to src/public/js/SyntaxHighlighter/shBrushColdFusion.js diff --git a/js/SyntaxHighlighter/shBrushCpp.js b/src/public/js/SyntaxHighlighter/shBrushCpp.js similarity index 100% rename from js/SyntaxHighlighter/shBrushCpp.js rename to src/public/js/SyntaxHighlighter/shBrushCpp.js diff --git a/js/SyntaxHighlighter/shBrushCss.js b/src/public/js/SyntaxHighlighter/shBrushCss.js similarity index 100% rename from js/SyntaxHighlighter/shBrushCss.js rename to src/public/js/SyntaxHighlighter/shBrushCss.js diff --git a/js/SyntaxHighlighter/shBrushDelphi.js b/src/public/js/SyntaxHighlighter/shBrushDelphi.js similarity index 100% rename from js/SyntaxHighlighter/shBrushDelphi.js rename to src/public/js/SyntaxHighlighter/shBrushDelphi.js diff --git a/js/SyntaxHighlighter/shBrushDiff.js b/src/public/js/SyntaxHighlighter/shBrushDiff.js similarity index 100% rename from js/SyntaxHighlighter/shBrushDiff.js rename to src/public/js/SyntaxHighlighter/shBrushDiff.js diff --git a/js/SyntaxHighlighter/shBrushErlang.js b/src/public/js/SyntaxHighlighter/shBrushErlang.js similarity index 100% rename from js/SyntaxHighlighter/shBrushErlang.js rename to src/public/js/SyntaxHighlighter/shBrushErlang.js diff --git a/js/SyntaxHighlighter/shBrushGroovy.js b/src/public/js/SyntaxHighlighter/shBrushGroovy.js similarity index 100% rename from js/SyntaxHighlighter/shBrushGroovy.js rename to src/public/js/SyntaxHighlighter/shBrushGroovy.js diff --git a/js/SyntaxHighlighter/shBrushJScript.js b/src/public/js/SyntaxHighlighter/shBrushJScript.js similarity index 100% rename from js/SyntaxHighlighter/shBrushJScript.js rename to src/public/js/SyntaxHighlighter/shBrushJScript.js diff --git a/js/SyntaxHighlighter/shBrushJava.js b/src/public/js/SyntaxHighlighter/shBrushJava.js similarity index 100% rename from js/SyntaxHighlighter/shBrushJava.js rename to src/public/js/SyntaxHighlighter/shBrushJava.js diff --git a/js/SyntaxHighlighter/shBrushJavaFX.js b/src/public/js/SyntaxHighlighter/shBrushJavaFX.js similarity index 100% rename from js/SyntaxHighlighter/shBrushJavaFX.js rename to src/public/js/SyntaxHighlighter/shBrushJavaFX.js diff --git a/js/SyntaxHighlighter/shBrushPerl.js b/src/public/js/SyntaxHighlighter/shBrushPerl.js similarity index 100% rename from js/SyntaxHighlighter/shBrushPerl.js rename to src/public/js/SyntaxHighlighter/shBrushPerl.js diff --git a/js/SyntaxHighlighter/shBrushPhp.js b/src/public/js/SyntaxHighlighter/shBrushPhp.js similarity index 100% rename from js/SyntaxHighlighter/shBrushPhp.js rename to src/public/js/SyntaxHighlighter/shBrushPhp.js diff --git a/js/SyntaxHighlighter/shBrushPlain.js b/src/public/js/SyntaxHighlighter/shBrushPlain.js similarity index 100% rename from js/SyntaxHighlighter/shBrushPlain.js rename to src/public/js/SyntaxHighlighter/shBrushPlain.js diff --git a/js/SyntaxHighlighter/shBrushPowerShell.js b/src/public/js/SyntaxHighlighter/shBrushPowerShell.js similarity index 100% rename from js/SyntaxHighlighter/shBrushPowerShell.js rename to src/public/js/SyntaxHighlighter/shBrushPowerShell.js diff --git a/js/SyntaxHighlighter/shBrushPython.js b/src/public/js/SyntaxHighlighter/shBrushPython.js similarity index 100% rename from js/SyntaxHighlighter/shBrushPython.js rename to src/public/js/SyntaxHighlighter/shBrushPython.js diff --git a/js/SyntaxHighlighter/shBrushRuby.js b/src/public/js/SyntaxHighlighter/shBrushRuby.js similarity index 100% rename from js/SyntaxHighlighter/shBrushRuby.js rename to src/public/js/SyntaxHighlighter/shBrushRuby.js diff --git a/js/SyntaxHighlighter/shBrushSass.js b/src/public/js/SyntaxHighlighter/shBrushSass.js similarity index 100% rename from js/SyntaxHighlighter/shBrushSass.js rename to src/public/js/SyntaxHighlighter/shBrushSass.js diff --git a/js/SyntaxHighlighter/shBrushScala.js b/src/public/js/SyntaxHighlighter/shBrushScala.js similarity index 100% rename from js/SyntaxHighlighter/shBrushScala.js rename to src/public/js/SyntaxHighlighter/shBrushScala.js diff --git a/js/SyntaxHighlighter/shBrushSql.js b/src/public/js/SyntaxHighlighter/shBrushSql.js similarity index 100% rename from js/SyntaxHighlighter/shBrushSql.js rename to src/public/js/SyntaxHighlighter/shBrushSql.js diff --git a/js/SyntaxHighlighter/shBrushVb.js b/src/public/js/SyntaxHighlighter/shBrushVb.js similarity index 100% rename from js/SyntaxHighlighter/shBrushVb.js rename to src/public/js/SyntaxHighlighter/shBrushVb.js diff --git a/js/SyntaxHighlighter/shBrushXml.js b/src/public/js/SyntaxHighlighter/shBrushXml.js similarity index 100% rename from js/SyntaxHighlighter/shBrushXml.js rename to src/public/js/SyntaxHighlighter/shBrushXml.js diff --git a/js/SyntaxHighlighter/shCore.js b/src/public/js/SyntaxHighlighter/shCore.js similarity index 100% rename from js/SyntaxHighlighter/shCore.js rename to src/public/js/SyntaxHighlighter/shCore.js diff --git a/js/SyntaxHighlighter/shLegacy.js b/src/public/js/SyntaxHighlighter/shLegacy.js similarity index 100% rename from js/SyntaxHighlighter/shLegacy.js rename to src/public/js/SyntaxHighlighter/shLegacy.js diff --git a/js/bootstrap.js b/src/public/js/bootstrap.js similarity index 100% rename from js/bootstrap.js rename to src/public/js/bootstrap.js diff --git a/js/bootstrap.min.js b/src/public/js/bootstrap.min.js similarity index 100% rename from js/bootstrap.min.js rename to src/public/js/bootstrap.min.js diff --git a/js/chosen.jquery.js b/src/public/js/chosen.jquery.js similarity index 100% rename from js/chosen.jquery.js rename to src/public/js/chosen.jquery.js diff --git a/js/chosen.proto.js b/src/public/js/chosen.proto.js similarity index 100% rename from js/chosen.proto.js rename to src/public/js/chosen.proto.js diff --git a/js/jquery.dynatable.js b/src/public/js/jquery.dynatable.js similarity index 100% rename from js/jquery.dynatable.js rename to src/public/js/jquery.dynatable.js diff --git a/js/npm.js b/src/public/js/npm.js similarity index 100% rename from js/npm.js rename to src/public/js/npm.js diff --git a/js/vendor/jquery-1.7.2.min.js b/src/public/js/vendor/jquery-1.7.2.min.js similarity index 100% rename from js/vendor/jquery-1.7.2.min.js rename to src/public/js/vendor/jquery-1.7.2.min.js diff --git a/src/views/_layout.php b/src/views/_layout.php new file mode 100644 index 0000000..3eda230 --- /dev/null +++ b/src/views/_layout.php @@ -0,0 +1,44 @@ +no content

'; +} +?> + + + + + + Palm-Paste Index + + '; + $dir = ""; + if (isset($_GET["user"]) || isset($_GET["page"]) && $_GET["page"] == "edit") $dir = "../"; + + echo ''; + echo ''; + + echo ''; + echo ''; + echo ''; + + echo ''; + echo ''; + echo ''; + + echo ""; + + ?> + + + + + + + + + + \ No newline at end of file diff --git a/src/views/_navbar.php b/src/views/_navbar.php new file mode 100644 index 0000000..abe0e94 --- /dev/null +++ b/src/views/_navbar.php @@ -0,0 +1,79 @@ + + + + \ No newline at end of file diff --git a/src/views/_new-paste.php b/src/views/_new-paste.php new file mode 100644 index 0000000..6af129a --- /dev/null +++ b/src/views/_new-paste.php @@ -0,0 +1,119 @@ +
+
+ '); + } else printf('
'); + ?> +
+ + '); + } else printf(''); + ?> +
+
+ + ' . $row['text'] . ''; + } else printf(''); + ?> +
+ "); + printf(""); + } else printf(""); + ?> +
+
+
+ +
+ +
+ + +
+
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+
+
+ +
+
\ No newline at end of file diff --git a/src/views/_recent-pastes.php b/src/views/_recent-pastes.php new file mode 100644 index 0000000..acf737d --- /dev/null +++ b/src/views/_recent-pastes.php @@ -0,0 +1,18 @@ +
+
+

Newest pastes:

+
+ query('SELECT * FROM pastes WHERE exposure=0 ORDER BY id DESC LIMIT 5'); + while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { + $title = htmlspecialchars($row['title'], ENT_QUOTES, 'UTF-8'); + if (strlen($title) > 25) $title = substr($title, 0, 25) . "..."; + echo "" . $title . ""; + } + $conn = null; + ?> +
+
+
\ No newline at end of file diff --git a/src/views/edit.php b/src/views/edit.php new file mode 100644 index 0000000..38b06e7 --- /dev/null +++ b/src/views/edit.php @@ -0,0 +1,35 @@ +
+
+
+ prepare('SELECT * FROM pastes WHERE uid=:uid'); + $stmt->bindParam(':uid', $paste); + $stmt->execute(); + if ($stmt->rowCount() > 0) { + while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { + if ($row['owner'] === $uid) { + include "views/_new-paste.php"; + } else { + $conn = null; + echo '

You are not the owner of the paste ' . $row["uid"] . '

'; + echo ''; + die(); + } + } + } else { + $conn = null; + echo '

The paste ' . $row["uid"] . ' does not exist

'; + echo ''; + } + $conn = null; + } + ?> +
+
+
\ No newline at end of file diff --git a/src/views/login.php b/src/views/login.php new file mode 100644 index 0000000..291a849 --- /dev/null +++ b/src/views/login.php @@ -0,0 +1,119 @@ +

Please wait...

'; + echo ''; +} else if (isset($_POST["type"])) { + if ($_POST["type"] == "login" && isset($_POST["user"]) && isset($_POST["pwd"])) { + //Get options + $user = $_POST["user"]; + $pwd = $_POST["pwd"]; + $remember = 0; + if (isset($_POST["remember"]) && $_POST["remember"] == "on") + $remember = 1; + //Try to login + include_once "includes/config.php"; + $conn = GetConnectionToDB(); + $stmt = $conn->prepare('SELECT * FROM users WHERE user=?'); + $stmt->execute(array($user)); + if ($result = $stmt->fetch(PDO::FETCH_ASSOC)) { + if (password_verify($pwd, $result["password"])) { + $skey = generate_skey(); + $stmt = $conn->prepare("INSERT INTO sessions (skey, uid) + VALUES (:skey, :uid)"); + $stmt->bindParam(':skey', $skey); + $stmt->bindParam(':uid', $result["id"]); + $stmt->execute(); + $sid = $conn->lastInsertId(); + $conn = null; + if ($remember == 1) { + setcookie("pp_sid", $sid, time() + 63072000); //Dies in 2 years + setcookie("pp_skey", $skey, time() + 63072000); //Dies in 2 years + } else { + setcookie("pp_sid", $sid); //Dies when browser closes + setcookie("pp_skey", $skey); //Dies when browser closes + } + echo '

Please wait...

'; + echo ''; + die(); + } else echo "No!"; //TODO: Wrong password + } else echo "Fail!"; //TODO: No user or SQL fail. + $conn = null; + } + if ($_POST["type"] == "register" && isset($_POST["user"]) && isset($_POST["pwd"])) { + //Get options + $user = $_POST["user"]; + $pwd = $_POST["pwd"]; + $hash = password_hash($pwd, CRYPT_BLOWFISH); + //Does this user exist + include_once "includes/config.php"; + $conn = GetConnectionToDB(); + $stmt = $conn->prepare('SELECT * FROM users WHERE user=?'); + $stmt->execute(array($user)); + if ($result = $stmt->fetch(PDO::FETCH_ASSOC)) { + echo "

User allready exists!

"; + $conn = null; + die(); + } + //Did the person enter a password + if ($pwd == "") { + echo "

You need a password to singup!

"; + $conn = null; + die(); + } + //Register the user + $stmt = $conn->prepare("INSERT INTO users (user,password) + VALUES (:user, :pwd)"); + $stmt->bindParam(':user', $user); + $stmt->bindParam(':pwd', $hash); + if ($stmt->execute()) { + echo '

Please wait...

'; + echo ''; + } else { + echo "Fail!"; + } + $conn = null; + } +} else { + echo ' +
+
+
Login
+
+ '; + echo ' +
+
+ + +
+
+ + +
+
+ +
+ + + + '; + echo ' +
+
+
+ '; +} diff --git a/src/views/my-pastes.php b/src/views/my-pastes.php new file mode 100644 index 0000000..139d1c7 --- /dev/null +++ b/src/views/my-pastes.php @@ -0,0 +1,60 @@ +
+
+
+ You must be loged in to see your pastes!'); + $conn = null; + echo '
'; + die(); + } + $stmt = $conn->prepare('SELECT * FROM pastes WHERE owner=:own'); + $own = GetUsersIDBySession($_COOKIE["pp_sid"], $_COOKIE["pp_skey"]); + $stmt->bindParam(':own', $own); + $stmt->execute(); + if ($stmt->rowCount() > 0) { + echo "
TitleAddedExpiresID
'.htmlspecialchars($row["title"], ENT_QUOTES, 'UTF-8').''.date('Y-m-d',$row["created"]).'Never'.round($expire/24).' days from now'.round($expire).' hours from now'.round($expire*60).' minutes from now'.htmlspecialchars($row["uid"], ENT_QUOTES, 'UTF-8').'
"; + printf(' + + + + '); + printf(''); + while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { + $title = $row['title']; + //Paste title + printf(''); + //Creation date + printf(''); + //Expire date + if ($row["expire"] == 0) printf(''); + else { + $expire = ($row["expire"] - time()) / 3600; + if ($expire > 24) { + printf(''); + } else if ($expire >= 1) + printf(''); + else printf(''); + } + //Paste url + printf(''); + //Actions + printf(''); + } + printf(''); + } else { + printf('

You havent made any pastes yet!

'); + } + $conn = null; + ?> + + + \ No newline at end of file diff --git a/src/views/new-paste.php b/src/views/new-paste.php new file mode 100644 index 0000000..efb4336 --- /dev/null +++ b/src/views/new-paste.php @@ -0,0 +1,12 @@ +
+
+
+
+ +
+
+ +
+
+
+
\ No newline at end of file diff --git a/src/views/signup.php b/src/views/signup.php new file mode 100644 index 0000000..51a2a21 --- /dev/null +++ b/src/views/signup.php @@ -0,0 +1,29 @@ +
+
+
Register
+
+ +
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+ + +
+
+ + +
+
+
\ No newline at end of file diff --git a/src/views/user.php b/src/views/user.php new file mode 100644 index 0000000..e40c3bc --- /dev/null +++ b/src/views/user.php @@ -0,0 +1,52 @@ +
+
+
+ ' . $owner["user"] . '\'s profile'); + //== Print pastes ==// + $query = "SELECT * FROM pastes WHERE owner=:own AND exposure=0"; + if (GetUsersIDBySession($_COOKIE["pp_sid"], $_COOKIE["pp_skey"]) == $ownerID) $query = "SELECT * FROM pastes WHERE owner=:own"; + $stmt = $conn->prepare($query); + $stmt->bindParam(':own', $ownerID); + $stmt->execute(); + + if ($stmt->rowCount() > 0) { + echo "
TitleAddedExpiresIDActions
' . htmlspecialchars($row["title"], ENT_QUOTES, 'UTF-8') . '' . date('Y-m-d', $row["created"]) . 'Never' . round($expire / 24) . ' days from now' . round($expire) . ' hours from now' . round($expire * 60) . ' minutes from now' . htmlspecialchars($row["uid"], ENT_QUOTES, 'UTF-8') . ''); + //delete paste + printf(''); + //edit paste + printf(''); + printf('
"; + printf(' + + + '); + printf(''); + while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { + $title = $row['title']; + printf(''); + printf(''); + if ($row["expire"] == 0) printf(''); + else { + $expire = ($row["expire"] - time()) / 3600; + if ($expire > 24) { + printf(''); + } else if ($expire >= 1) + printf(''); + else printf(''); + } + printf(''); + } + printf(''); + } else { + printf('

This user has no public pastes!

'); + } + } else printf('

User does not exist!

'); + $conn = null; + ?> + + + \ No newline at end of file diff --git a/src/views/view-paste.php b/src/views/view-paste.php new file mode 100644 index 0000000..05cf495 --- /dev/null +++ b/src/views/view-paste.php @@ -0,0 +1,55 @@ +
+
+
+ query('SELECT * FROM pastes WHERE uid="' . $uid . '"'); + if ($result = $stmt->fetch(PDO::FETCH_ASSOC)) { + $conn = null; + if ($result["expire"] != 0 && $result["expire"] < time()) { + //This paste is expired but not removed + echo "

This paste just expired

"; + include_once "cronjob.php"; + RemoveExpiredPastes(); + die(); + } + if ($result["exposure"] == 2 && $result["owner"] != 0 && isset($_COOKIE["pp_sid"]) && isset($_COOKIE["pp_skey"]) && $result["owner"] != GetUsersIDBySession($_COOKIE["pp_sid"], $_COOKIE["pp_skey"])) { + echo "

This paste is private

"; + die(); + } + echo "

" . htmlspecialchars($result["title"], ENT_QUOTES, 'UTF-8') . "

"; + // + $owner = GetUserByID($result["owner"]); + echo "
"; + if ($owner[1] == -1) + echo "Posted by: Guest"; + else echo "Posted by: " . htmlspecialchars($owner[1]) . ""; + echo ", at " . date('Y-m-d', $result["created"]) . ", it will expire "; + if ($result["expire"] == 0) printf('Never'); + else { + $expire = ($result["expire"] - time()) / 3600; + if ($expire > 24) { + printf(round($expire / 24) . ' days from now'); + } else if ($expire >= 1) + printf(round($expire) . ' hours from now'); + else printf(round($expire * 60) . ' minutes from now'); + } + echo "
"; + // + echo "
";
+          echo htmlspecialchars($result["text"], ENT_QUOTES, 'UTF-8') . "
"; + echo ""; + echo ""; + } else echo "Paste does not exist"; + $conn = null; + } else echo "Error: id not set"; + ?> + +
+
+
\ No newline at end of file
TitleAddedExpiresID
' . htmlspecialchars($row["title"], ENT_QUOTES, 'UTF-8') . '' . date('Y-m-d', $row["created"]) . 'Never' . round($expire / 24) . ' days from now' . round($expire) . ' hours from now' . round($expire * 60) . ' minutes from now' . htmlspecialchars($row["uid"], ENT_QUOTES, 'UTF-8') . '