forked from sorenpeter/phpub2twtxt
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.php
99 lines (97 loc) · 2.85 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
// Config
$txt_file = '../twtxt.txt'; // Picoblog file route
$pass = ""; // Put your password's hash here
if(isset($_POST["sub"])){
if(password_verify($_POST["pass"], $pass)){
$new_post = filter_input(INPUT_POST, 'new_post');
function id(){
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$randstring = ''; $i=0;
while ($i <= 6){
$randstring .= $characters[rand(0, strlen($characters))];
$i++;
}
return $randstring;
}
$id=id();
if($new_post){
$contents = file_get_contents($txt_file);
$contents .= "\n" . date("Y-m-d\TH:i:s\Z") . "\t(#" . $id . ")\t" ;
$contents .= "$new_post";
file_put_contents($txt_file, $contents);
header("Refresh:0; url=?");
exit;
}else{
echo "Opps something went wrong...\n\nCheck the error_log on the server";
exit;
}
}else{header("location: ?retry");}
}else{ ?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>pdpush</title>
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<style type="text/css">
body{
margin:1em;
background-color:#333;
color:#FFE;
font-family:-apple-system, "Segoe UI", Roboto, Helvetica, sans-serif;
font-size:1em;
font-weight:400;
line-height:1.6;
max-width:800px;
margin:0 auto;
}
a{color:#9F9;text-decoration:none;}
a:hover{color:#9F9;text-decoration:underline;}
form{align-content:center;}
form input,#retry{
font-size:1.2em;
border-radius:2px;
padding:10px;
}
form input[type=text],form input[type=password]{
flex-grow:1;
background:#222;
color:#ffe;
border:solid 1px #9F9;
margin-right:5px;
}
form input[type=password]{font-size:90%;}
form input[type=submit]{
margin-left:5px;
background:#9F9;
color:#222;
border:none;
}
#posting{display:flex;}
#retry{margin:0 0 20px 0;border:solid 1px #f45;}
iframe{
border:none;
margin-top:1em;
background-color:#ffe;
width:100%;
}
footer{font-size:0.9em;text-align:right;}
</style>
</head>
<body>
<h1>pdpush</h1>
<p>An interface for publishing microblogposts to your selfhosted twtxt/picoblog</p>
<?php if(isset($_GET["retry"])){echo '<div id="retry">Your author key isn\'t valid, please try again</div>';} ?>
<form method="POST" class="column">
<div id="posting">
<input type="text" name="new_post" autofocus placeholder="Write you twtxt post here">
<input type="submit" value="Post" name="sub">
</div>
<input type="password" name="pass" autofocus placeholder="Author key">
</form>
<iframe src="<?= $txt_file ?>" height="450"></iframe>
<footer><a href="https://github.com/luqaska/pdpush">source code</a></footer>
</body>
</html>
<?php } ?>