mirror of https://github.com/pikami/palm-paste.git
Changes to paste expiry
This commit is contained in:
parent
4ec25c960e
commit
b59f2f0596
10
MyPastes.php
10
MyPastes.php
|
@ -17,12 +17,22 @@ if($stmt->rowCount()>0){
|
|||
echo "<table id=\"tablepastes\" class=\"table table-striped\" style=\"width:100%\">";
|
||||
printf('<thead><th data-dynatable-column="name" style="text-align: left;">Title</th>
|
||||
<th style="text-align: left;">Added</th>
|
||||
<th style="text-align: left;">Expires</th>
|
||||
<th style="text-align: left;">ID</th></thead>');
|
||||
printf('<tbody>');
|
||||
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
$title = $row['title'];
|
||||
printf('<tr><td style="text-align: left;">'.htmlspecialchars($row["title"], ENT_QUOTES, 'UTF-8').'</td>');
|
||||
printf('<td style="text-align: left;">'.date('Y-m-d',$row["created"]).'</td>');
|
||||
if($row["expire"]==0) printf('<td style="text-align: left;">Never</td>');
|
||||
else{
|
||||
$expire = ($row["expire"]-time())/3600;
|
||||
if($expire>24){
|
||||
printf('<td style="text-align: left;">'.round($expire/24).' days from now</td>');
|
||||
} else if($expire>=1)
|
||||
printf('<td style="text-align: left;">'.round($expire).' hours from now</td>');
|
||||
else printf('<td style="text-align: left;">'.round($expire*60).' minutes from now</td>');
|
||||
}
|
||||
printf('<td style="text-align: right;"><a href="'.htmlspecialchars($row["uid"], ENT_QUOTES, 'UTF-8').'">'.htmlspecialchars($row["uid"], ENT_QUOTES, 'UTF-8').'</a></td></tr>');
|
||||
}
|
||||
printf('</tbody></talbe>');
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
<option value="600">10 Minutes</option>
|
||||
<option value="3600">1 Hour</option>
|
||||
<option value="86400">1 Day</option>
|
||||
<option value="2592000">1 Month</option>
|
||||
</select>
|
||||
</div>
|
||||
<!-- Syntax Highlight -->
|
||||
|
|
|
@ -8,6 +8,12 @@ if(isset($uid)){
|
|||
$stmt = $conn->query('SELECT * FROM pastes WHERE uid="'.$uid.'"');
|
||||
if($result = $stmt->fetch(PDO::FETCH_ASSOC)){
|
||||
$conn = null;
|
||||
if($result["expire"]<time()){
|
||||
//This paste is expired but not removed
|
||||
include "cronjob.php";
|
||||
RemoveExpiredPastes();
|
||||
die();
|
||||
}
|
||||
if($result["exposure"]==2 && isset($_COOKIE["pp_sid"]) && isset($_COOKIE["pp_skey"]) && $result["owner"]!=GetUsersIDBySession($_COOKIE["pp_sid"],$_COOKIE["pp_skey"])){
|
||||
echo "<h1>This paste is private</h1>";
|
||||
die();
|
||||
|
@ -19,7 +25,17 @@ if(isset($uid)){
|
|||
if($owner[1] == -1)
|
||||
echo "Posted by: <b>Guest</b>";
|
||||
else echo "Posted by: <b>".htmlspecialchars($owner[1])."</b>";
|
||||
echo ", at ".date('Y-m-d',$result["created"])."</h5>";
|
||||
echo ", at ".date('Y-m-d',$result["created"]).", it will expire <b>";
|
||||
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 "</b></h5>";
|
||||
//
|
||||
echo "<pre class=\"brush: ".$_HL."\">";
|
||||
echo htmlspecialchars($result["text"], ENT_QUOTES, 'UTF-8')."</pre><pb>";
|
||||
|
|
|
@ -4,6 +4,8 @@ $SQL_Host = "localhost";
|
|||
$SQL_Database = "palm-paste";
|
||||
$SQL_User = "paste";
|
||||
$SQL_Password = "ckQgRJRhib74XMgVpzmn38uj1MrCcNnK7L9bc7zu";
|
||||
//========CRON_JOBS=========//
|
||||
$CRON_ExpireKey = "b1g51bf6g";
|
||||
//========CONNECTION========//
|
||||
$conn = new PDO('mysql:host='.$SQL_Host.';dbname='.$SQL_Database.';charset=utf8mb4', $SQL_User, $SQL_Password);
|
||||
?>
|
||||
|
|
11
cronjob.php
11
cronjob.php
|
@ -1,15 +1,18 @@
|
|||
<?php
|
||||
if (isset($_GET["key"])){
|
||||
if($_GET["key"]=="b1g51bf6g"){ //Kill sessions
|
||||
include "config/config.php";
|
||||
include_once "config/config.php";
|
||||
function RemoveExpiredPastes(){
|
||||
$time = time();
|
||||
$stmt = $conn->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=b1g51bf6g > /dev/null
|
||||
//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
|
||||
?>
|
Loading…
Reference in New Issue