2023-01-18 12:34:55 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
// global settings
|
|
|
|
$datafile = '../data/data.json';
|
2023-04-24 09:30:46 +02:00
|
|
|
$icsfile = 'ics url';
|
|
|
|
|
2023-01-18 12:34:55 +01:00
|
|
|
$password = '';
|
|
|
|
|
|
|
|
// check authent
|
|
|
|
if ($password && (!isset($_POST['password']) || $_POST['password'] != $password))
|
|
|
|
{
|
|
|
|
echo '{"error": "authent"}';
|
|
|
|
}
|
|
|
|
else if (isset($_POST['action']))
|
|
|
|
{
|
|
|
|
$action = $_POST['action'];
|
|
|
|
switch ($action)
|
|
|
|
{
|
|
|
|
case 'fetch':
|
|
|
|
if (file_exists($datafile))
|
|
|
|
{
|
|
|
|
echo file_get_contents($datafile);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
echo '[]';
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'push':
|
|
|
|
$result = file_put_contents($datafile, $_POST['data']);
|
|
|
|
if ($result === false)
|
|
|
|
{
|
|
|
|
echo '{"error": "could not save ' . $datafile . '"}';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
echo '{}';
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2023-04-24 09:30:46 +02:00
|
|
|
case 'cal':
|
|
|
|
$result = array();
|
|
|
|
$result["ics"] = file_get_contents($icsfile);
|
|
|
|
echo json_encode($result);
|
|
|
|
break;
|
|
|
|
|
2023-01-18 12:34:55 +01:00
|
|
|
default:
|
|
|
|
echo '{"error": "unknown action ' . $action . '"}';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
echo '{"error": "missing action parameter"}';
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|