contentdispenser/index.php

46 lines
1.1 KiB
PHP
Raw Normal View History

2023-06-09 16:00:29 +02:00
<?php
$idcko = $_GET['id'];
if (!empty($idcko)){
$ipcka = $_SERVER['REMOTE_ADDR'];
2023-06-09 21:54:01 +02:00
if(!file_exists("data/logs.json")){
file_put_contents("data/logs.json", "{}");
}
2023-06-09 21:45:45 +02:00
2023-06-09 16:00:29 +02:00
$stranky = json_decode(file_get_contents("data/pageindex.json"), true);
2023-06-09 21:45:45 +02:00
$contents = json_decode(file_get_contents("data/contents.json"), true);
$logs = json_decode(file_get_contents("data/logs.json"), true);
2023-06-09 21:53:18 +02:00
2023-06-09 16:00:29 +02:00
$alllog = "data/all.log";
if(array_key_exists($idcko, $stranky)){
$entry = $stranky[$idcko];
2023-06-09 21:45:45 +02:00
$content = $contents[$entry["contentid"]];
2023-06-09 16:00:29 +02:00
$nickname = $entry["nickname"];
2023-06-09 21:53:18 +02:00
$logmessage = "Success from $nickname($idcko), IP: $ipcka\n";
2023-06-09 21:45:45 +02:00
if (!array_key_exists($idcko, $logs)){
$logs[$idcko] = [];
}
$logs[$idcko][] = array("action"=>"Success", "datetime"=>date("H:i:s d.m.Y"), "link"=>$idcko, "nickname"=>$nickname, "ip"=>$ipcka);
2023-06-09 16:00:29 +02:00
2023-06-09 21:45:45 +02:00
file_put_contents("data/logs.json", json_encode($logs, JSON_PRETTY_PRINT));
2023-06-09 16:00:29 +02:00
file_put_contents($alllog, $logmessage, FILE_APPEND);
2023-06-09 21:45:45 +02:00
echo $content;
2023-06-09 16:00:29 +02:00
}
else{
die("Bad link");
}
}
else{
die("Bad link");
}
?>