147 lines
3.5 KiB
PHP
147 lines
3.5 KiB
PHP
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>
|
|
<?php
|
|
if (isset($_GET['openaction']))
|
|
{
|
|
echo $_GET['userdata'];
|
|
}
|
|
?>
|
|
</title>
|
|
<meta name="theme-color" content="white" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
|
|
<meta charset="UTF-8">
|
|
<style type="text/css">
|
|
body {
|
|
font-family: helvetica;
|
|
}
|
|
textarea {
|
|
width: 100%;
|
|
border: none;
|
|
outline: none;
|
|
font-family: inherit;
|
|
font-size: inherit;
|
|
}
|
|
.title {
|
|
width: 100%;
|
|
border: none;
|
|
outline: none;
|
|
font-family: inherit;
|
|
font-size: inherit;
|
|
font-weight: bold;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<?php
|
|
require 'settings.php';
|
|
|
|
if ($password && (!isset($_SERVER['PHP_AUTH_PW']) || $_SERVER['PHP_AUTH_PW'] != $password)) {
|
|
header('WWW-Authenticate: Basic realm="bbn"');
|
|
header('HTTP/1.0 401 Unauthorized');
|
|
echo '<p>Access denied.</p>';
|
|
exit;
|
|
}
|
|
|
|
echo '<div><a accesskey="h" href="' . $root . '">home</a></div><br>';
|
|
|
|
$action = '';
|
|
if (isset($_POST['action'])) $action = $_POST['action'];
|
|
else if (isset($_GET['action'])) $action = $_GET['action'];
|
|
|
|
$param = '';
|
|
if (isset($_GET['param'])) $param = $_GET['param'];
|
|
|
|
if ($action == 'save')
|
|
{
|
|
$title = $_POST['title'];
|
|
$content = $_POST['content'];
|
|
file_put_contents($dir . '/' . $title, $content);
|
|
$action = 'open';
|
|
$param = $title;
|
|
}
|
|
else if ($action == 'delete')
|
|
{
|
|
$title = $_POST['title'];
|
|
rename($dir . '/' . $title, $dir . '/' . $title . '.del');
|
|
}
|
|
|
|
if ($action == 'open')
|
|
{
|
|
$title = $param;
|
|
|
|
$content = '';
|
|
if (!file_exists($dir . '/' . $title))
|
|
{
|
|
file_put_contents($dir . '/' . $title, $content);
|
|
}
|
|
else
|
|
{
|
|
$content = file_get_contents($dir . '/' . $title);
|
|
}
|
|
|
|
$nblines = max(20, substr_count($content, "\r\n") + 1) * 2;
|
|
|
|
echo '<form action="index.php" method="POST">
|
|
<div>
|
|
<select name="action">
|
|
<option value="save">save</option>
|
|
<option value="delete">delete</option>
|
|
</select>
|
|
<input type="submit" name="go" value="go" accesskey="g">
|
|
</div>
|
|
<br>
|
|
<div><input class="title" name="title" value="' . $title . '"></div><br>
|
|
<div>
|
|
<textarea rows="' . $nblines. '" autofocus name="content" spellcheck="false">' . $content . '</textarea>
|
|
</div>
|
|
</form>';
|
|
}
|
|
else
|
|
{
|
|
$defaulttitle = date("Y-m-d H.i.s", time());
|
|
if ($param)
|
|
{
|
|
$defaulttitle = $param;
|
|
}
|
|
echo '<form action="index.php" method="GET">
|
|
<input name="param" value="' . $defaulttitle . '">
|
|
<select name="action">
|
|
<option value="open">open</option>
|
|
<option value="filter">filter</option>
|
|
<option value="search">search</option>
|
|
</select>
|
|
<input accesskey="g" type="submit" value="go">
|
|
</form>';
|
|
echo '<br>';
|
|
|
|
$files = glob($dir . '/*');
|
|
usort($files, function($a, $b)
|
|
{
|
|
return filemtime($b) - filemtime($a);
|
|
});
|
|
|
|
foreach($files as $path)
|
|
{
|
|
$name = basename($path);
|
|
if (!str_ends_with($name, '.del')
|
|
&& ($action != 'filter' || str_contains($name, $param)))
|
|
{
|
|
if ($action == 'search')
|
|
{
|
|
$content = file_get_contents($path);
|
|
if (!str_contains($content, $param))
|
|
{
|
|
continue;
|
|
}
|
|
}
|
|
echo '<div><a href=index.php?action=open¶m=' . urlencode($name) . '>' . $name .'</a></div>';
|
|
}
|
|
}
|
|
echo '<br>';
|
|
}
|
|
?>
|
|
</body>
|
|
</html>
|