notes/handler.php

42 lines
711 B
PHP

<?php
require 'settings.php';
// check authent
if ($password && (!isset($_POST['password']) || $_POST['password'] != $password))
{
echo 'error: authent';
}
else if (isset($_POST['action']))
{
$action = $_POST['action'];
$path = $datadir . $_POST['name'];
switch ($action)
{
case 'fetch':
if (file_exists($path))
{
echo file_get_contents($path);
}
break;
case 'push':
$result = file_put_contents($path, $_POST['data']);
if ($result === false)
{
echo 'error: could not save ' . $_POST['name'];
}
break;
default:
echo 'error: unknown action ' . $action;
break;
}
}
else
{
echo 'error: missing action parameter';
}
?>