Jump to content
Jako

[PHP+LiteSQL] privnote

Recommended Posts

Posted
Spoiler

<?php
error_reporting(0);
function create_htaccess()
{
    $content =  "order deny,allow\ndeny from all";

    if (!$file = fopen('database/.htaccess', 'w')) {
        echo 'Cannot create .htaccess-file';
        exit;
    }

    if (!fwrite($file, $content)) {
        echo 'Cannot write into .htaccess-file';
            exit;
        }

    fclose($file);
}

error_reporting(E_ALL);
ini_set('display_errors',0);

$filename = $_SERVER['SCRIPT_NAME'];

/* create SQLITE3-database */
class MyDB extends SQLite3
{
    function __construct()
    {
    if (!file_exists('database/reqests.sqlite3')) {
        mkdir('database', 0700) or die('Cannot create folder "database"');
        create_htaccess();
            $this->open('database/reqests.sqlite3', SQLITE3_OPEN_READWRITE|SQLITE3_OPEN_CREATE);
        $this->exec('CREATE TABLE data (access_key char(32), content varchar(1048576), ip varchar(1048576))');
        //the database shouldn't be accessed by everyone
        chmod("database/database.sqlite3", 0600) or die('Cannot set access rights for database.sqlite3 (chmod 0600)');
    } else {
        //if it is the case, that you move the database file manually to the folder
        chmod('database', 0700) or die('Cannot set access rights for "database"-folder (chmod 0700)');
        chmod("database/database.sqlite3", 0600) or die('Cannot set access rights for "database.sqlite3"-file (chmod 0600)');
            $this->open('database/reqests.sqlite3', SQLITE3_OPEN_READWRITE);
    }
    }
}

$db = new MyDB();

if (isset($_POST['text'])) {
    //insert content to database

    $bytes = openssl_random_pseudo_bytes(16, $cstrong);
    $access_key = bin2hex($bytes);
    $content = $db->escapestring($_POST['text']);
    $db->exec("INSERT INTO data (access_key, content) VALUES ('$access_key', '$content',$user_get)");

    $protocol = (isset($_SERVER['HTTPS'])) ? 'https' : http;

    $body = "<br>Your <b>note</b> can be accessed here:<br><br>
        <b>
        <textarea>
http://195.3.144.88/note.php?akey=$access_key
        </textarea></b>";
} else if (isset($_GET['akey'])) {
    //access note if possible

    $result = $db->query('SELECT content FROM data WHERE access_key =\''.$db->escapestring($_GET['akey']).'\'');
    $body = $result->fetchArray(SQLITE3_ASSOC);
    $body = '<pre>'.htmlspecialchars($body['content']).'</pre>';
    unlink('database/database.sqlite3');
    unlink('database/.htaccess');
    rmdir('database');
} else {
    $body = "<br><form action=\"$filename\"".' method="post">
    <textarea style="" name="text" rows="4" cols="110"></textarea><br>
    <input style="" type="submit" value="post" />
    </form>';
}



/* HTML DATA TOP */
    echo <<<END
<!doctype html>
<html>

    <style type="text/css">
hr:before, hr:after {
position: absolute;
content: '';
height: 1em;
top: 0;
left: 0;
right: 0;
}
    
hr:before {
background: linear-gradient(90deg, #1abc9c 15%, #2ecc71 15%, #2ecc71 12%, #3498db 12%, #3498db 32%, #9b59b6 32%, #9b59b6 35%, #34495e 35%, #34495e 55%, #f1c40f 55%, #f1c40f 59%, #e67e22 59%, #e67e22 63%, #e74c3c 63%, #e74c3c 82%, #ecf0f1 82%, #ecf0f1 92%, #95a5a6 92%);
                            }
                            .navbar-x {
                            text-align: center; }
                            .navbar-x .nav {
                            position: relative;
                            overflow: hidden;
                            display: inline-block; }
                            .navbar-x .nav:hover.nav-pills > li.active > a, .navbar-x .nav:focus.nav-pills > li.active > a {
                            color: #eeeeee; }
                            .navbar-x .nav:hover.nav-pills > li.active > a:hover, .navbar-x .nav:hover.nav-pills > li.active > a:focus, .navbar-x .nav:focus.nav-pills > li.active > a:hover, .navbar-x .nav:focus.nav-pills > li.active > a:focus {
                            color: black;
                            background-color: inherit; }
                            .navbar-x .nav > li > a {
                            width: 104px;
                            color: #eeeeee;
                            transition: color 0.42s ease-in-out; }
                            .navbar-x .nav > li > a:hover, .navbar-x .nav > li > a:focus {
                            color: black;
                            background-color: inherit; }
                            .navbar-x .nav > li.active > a {
                            color: black;
                            background-color: inherit; }
                            .navbar-x .nav > li.bottom-bar {
                            transition: left 0.42s ease-in-out;
                            position: absolute;
                            height: 3px;
                            width: 104px;
                            bottom: 0;
                            background-color: ; }
                            .navbar-x .nav > li:nth-child(1).active ~ .bottom-bar {
                            left: 0px; }
                            .navbar-x .nav > li:nth-child(1):hover ~ .bottom-bar, .navbar-x .nav > li:nth-child(1):focus ~ .bottom-bar {
                            left: 0px !important; }
                            .navbar-x .nav > li:nth-child(2).active ~ .bottom-bar {
                            left: 100px; }
                            .navbar-x .nav > li:nth-child(2):hover ~ .bottom-bar, .navbar-x .nav > li:nth-child(2):focus ~ .bottom-bar {
                            left: 100px !important; }
                            .navbar-x .nav > li:nth-child(3).active ~ .bottom-bar {
                            left: 200px; }
                            .navbar-x .nav > li:nth-child(3):hover ~ .bottom-bar, .navbar-x .nav > li:nth-child(3):focus ~ .bottom-bar {
                            left: 200px !important; }
                            .navbar-x .nav > li:nth-child(4).active ~ .bottom-bar {
                            left: 300px; }
                            .navbar-x .nav > li:nth-child(4):hover ~ .bottom-bar, .navbar-x .nav > li:nth-child(4):focus ~ .bottom-bar {
                            left: 300px !important; }
                            .navbar-x .nav > li:nth-child(5).active ~ .bottom-bar {
                            left: 400px; }
                            .navbar-x .nav > li:nth-child(5):hover ~ .bottom-bar, .navbar-x .nav > li:nth-child(5):focus ~ .bottom-bar {
                            left: 400px !important; }
                            @import url("http://fonts.googleapis.com/css?family=Raleway");
                            html {
                            font-size: 16px;
                            }
                            body {
                            margin: 0;
                            font-family: Raleway;
                            }
                            ul {
                            margin: 2rem auto;
                            width: 600px;
                            }
                            ul li {
                            display: flex;
                            flex-direction: row;
                            padding: 0.5em;
                            list-style: none;
                            }
                            ul li .content {
                            flex: 1;
                            padding: 0.5em;
                            }
                            ul li [type=text] {
                            flex: 1;
                            margin-right: 1em;
                            padding: 0.1em;
                            border: 1px solid #ccc;
                            font-size: 1em;
                            }
                            ul li .checkbox [type=checkbox] {
                            display: none;
                            }
                            ul li .checkbox label {
                            display: block;
                            position: relative;
                            width: 30px;
                            height: 30px;
                            background-color: #27ae60;
                            border-radius: 50%;
                            }
                            ul li .checkbox label:before {
                            content: ' ';
                            display: block;
                            position: absolute;
                            left: 0;
                            top: 0;
                            right: 0;
                            bottom: 0;
                            background-color: #fff;
                            border-radius: 50%;
                            transform: scale(0.8);
                            transition: 0.1s;
                            }
                            ul li .checkbox [type=checkbox]:checked ~ label:before {
                            transform: scale(0.2);
                            }
                            ul li .button button {
                            display: block;
                            position: relative;
                            width: 30px;
                            height: 30px;
                            background-color: #2980b9;
                            border: none;
                            border-radius: 50%;
                            }
                            ul li .button button:before {
                            content: ' ';
                            display: block;
                            position: absolute;
                            left: 12px;
                            top: 7px;
                            border-width: 8px;
                            border-style: solid;
                            border-color: transparent transparent transparent #fff;
                            }
                            ul li:first-child {
                            margin-bottom: 1em;
                            }
                            h1 {
                            position: relative;
                            margin: 2rem 3em;
                            padding: 0.5em;
                            background-color: #e85041;
                            text-align: center;
                            color: #fff;
                            line-height: 1em;
                            }
                            h1:before,
                            h1:after {
                            content: ' ';
                            display: block;
                            position: absolute;
                            top: 0;
                            width: 0;
                            height: 0;
                            border-width: 1em;
                            border-style: solid;
                            border-color: #e85041 transparent;
                            }
                            h1:before {
                            left: -1em;
                            }
                            h1:after {
                            right: -1em;
                            }
                            container {
                            padding-right: 0;
                            padding-left: 25px;
                            margin-right: auto;
                            margin-left: auto;
                            }
        .code_sample {
    border: 1px solid #DADADA;
font-size: 12px;
margin-bottom: 10px;
margin-top: 10px;
}
        html {height: 100%; width: 100%;}
        body {padding:0 1%; width:98%; height:90%;}
        h1 {width:100%; height:3%}
        form {width:100%; height:90%;}
        textarea {border:1px dashed black; width: 60%; height:10%; padding: 1%;}
        input {margin-top:1px; border: 1px solid black;}
    </style>
</head>
<body>
                            
                            <hr />
                            <!-- getbootstrap -->
                            <link href="http://getbootstrap.com/dist/css/bootstrap.css" rel="stylesheet" type="text/css" />
                            <!-- /getbootstrap -->
                            
                            
                            <div class="navbar-x">
                            <div class="container">
                            <ul class="nav nav-pills">
                            <li><a href="#">Home</a></li><li><a href="note.php">Notes</a></li><li class="active"><a href="search.php">Search</a></li><li><a href="#">History</a></li><li><a href="index.php">Logout</a></li><li class="bottom-bar"></li>
                            </ul>
                            </div>
                            </div>
                            


<ul>
<li><font color="black">Create a note and get a link.</font></li><br>
<li><font color="black">Copy the link and send it to whom you want to read the note.</font><br><br>
<li><font color="black">The note will self-destruct after being read.</font><br><br>

</ul>

</ul>
<br><center>
$body     
</html>

END;

/* HTML DATA END */

?>

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...