notes/handler.php

42 lines
711 B
PHP
Raw Normal View History

2023-01-18 12:34:55 +01:00
<?php
2023-06-19 09:58:21 +02:00
require 'settings.php';
2023-01-18 12:34:55 +01:00
// check authent
if ($password && (!isset($_POST['password']) || $_POST['password'] != $password))
{
2024-02-15 16:02:56 +01:00
echo 'error: authent';
2023-01-18 12:34:55 +01:00
}
else if (isset($_POST['action']))
{
$action = $_POST['action'];
2024-02-15 16:02:56 +01:00
$path = $datadir . $_POST['name'];
2023-01-18 12:34:55 +01:00
switch ($action)
{
case 'fetch':
2024-02-15 16:02:56 +01:00
if (file_exists($path))
2023-01-18 12:34:55 +01:00
{
2024-02-15 16:02:56 +01:00
echo file_get_contents($path);
2023-01-18 12:34:55 +01:00
}
break;
case 'push':
2024-02-15 16:02:56 +01:00
$result = file_put_contents($path, $_POST['data']);
2023-01-18 12:34:55 +01:00
if ($result === false)
{
2024-02-15 16:02:56 +01:00
echo 'error: could not save ' . $_POST['name'];
2023-09-11 09:57:00 +02:00
}
2023-01-18 12:34:55 +01:00
break;
default:
2024-02-15 16:02:56 +01:00
echo 'error: unknown action ' . $action;
2023-01-18 12:34:55 +01:00
break;
}
}
else
{
2024-02-15 16:02:56 +01:00
echo 'error: missing action parameter';
2023-01-18 12:34:55 +01:00
}
?>