aboutsummaryrefslogtreecommitdiff
path: root/Neutron-trunk/api/admin/calendar_create.php
blob: eff468267dba8c56d5258b82a3c66cad88dd2326 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php require_once "../../resources/private/relative.php"; getRelativeDetails("api"); ?>
<?php

require_once $_SERVER['DOCUMENT_ROOT'] . "/api/lang/processor.php";

if (isset($_COOKIE['_NEUTRON_ADMIN_TOKEN']) && $_COOKIE['_NEUTRON_ADMIN_TOKEN'] != "." && $_COOKIE['_NEUTRON_ADMIN_TOKEN'] != ".." && $_COOKIE['_NEUTRON_ADMIN_TOKEN'] != "/") {
    if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/data/tokens/" . $_COOKIE['_NEUTRON_ADMIN_TOKEN'])) {

    } else {
        require $_SERVER['DOCUMENT_ROOT'] . "/api/electrode/quit.php";quit($lang['api']['token']);
        if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/data/webcontent/system.log")) {
            file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/data/webcontent/system.log", file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/data/webcontent/system.log") . date("d/m/Y H:i:s") . " - APIDENY/" . $_SERVER['REQUEST_METHOD'] . " - " . $_SERVER['REQUEST_URI'] . " - " . $_SERVER['HTTP_USER_AGENT'] . "\n\n");
        } else {
            file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/data/webcontent/system.log", date("d/m/Y H:i:s") . " - APIDENY/" . $_SERVER['REQUEST_METHOD'] . " - " . $_SERVER['REQUEST_URI'] . " - " . $_SERVER['HTTP_USER_AGENT'] . "\n\n");
        }
    }
} else {
    require $_SERVER['DOCUMENT_ROOT'] . "/api/electrode/quit.php";quit($lang['api']['token']);
    if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/data/webcontent/system.log")) {
        file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/data/webcontent/system.log", file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/data/webcontent/system.log") . date("d/m/Y H:i:s") . " - APIDENY/" . $_SERVER['REQUEST_METHOD'] . " - " . $_SERVER['REQUEST_URI'] . " - " . $_SERVER['HTTP_USER_AGENT'] . "\n\n");
    } else {
        file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/data/webcontent/system.log", date("d/m/Y H:i:s") . " - APIDENY/" . $_SERVER['REQUEST_METHOD'] . " - " . $_SERVER['REQUEST_URI'] . " - " . $_SERVER['HTTP_USER_AGENT'] . "\n\n");
    }
}

function isJson($string) {
    json_decode($string);
    return (json_last_error() == JSON_ERROR_NONE);
}

$jsonraw = file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/data/webcontent/caldb.json");
if (isJson($jsonraw)) {
    if (isset($_POST['name'])) {
        $name = $_POST['name'];
    } else {
        require $_SERVER['DOCUMENT_ROOT'] . "/api/electrode/quit.php";quit($lang["api"]["calnodesc"]);
    }
    if (isset($_POST['desc'])) {
        $desc = $_POST['desc'];
    } else {
        require $_SERVER['DOCUMENT_ROOT'] . "/api/electrode/quit.php";quit($lang["api"]["calnodesc"]);
    }
    if (isset($_POST['link'])) {
        $link = $_POST['link'];
    } else {
        require $_SERVER['DOCUMENT_ROOT'] . "/api/electrode/quit.php";quit($lang["api"]["calnolink"]);
    }
    if (isset($_POST['day'])) {
        $day = $_POST['day'];
    } else {
        require $_SERVER['DOCUMENT_ROOT'] . "/api/electrode/quit.php";quit($lang["api"]["calnoday"]);
    }
    if (isset($_POST['month'])) {
        $month = $_POST['month'];
    } else {
        require $_SERVER['DOCUMENT_ROOT'] . "/api/electrode/quit.php";quit($lang["api"]["calnomonth"]);
    }
    if (isset($_POST['year'])) {
        $year = $_POST['year'];
    } else {
        require $_SERVER['DOCUMENT_ROOT'] . "/api/electrode/quit.php";quit($lang["api"]["calnoyear"]);
    }
    $date = strtotime($year . "-" . $month . "-" . $day);
    if (($month == "4" || $month == "6" || $month == "9" || $month == "11") && ($day == "31")) {
        require $_SERVER['DOCUMENT_ROOT'] . "/api/electrode/quit.php";quit($lang["api"]["calinvalidday"]);
    }
    if (($month == "2") && ($day == "30" || $day == "31" || ((bool)date('L', strtotime("$year-01-01")) === false && $day == "29"))) {
        require $_SERVER['DOCUMENT_ROOT'] . "/api/electrode/quit.php";quit($lang["api"]["calinvalidday"]);
    }
    if ((int)date('Y', $date) < (int)date('Y')) {
        require $_SERVER['DOCUMENT_ROOT'] . "/api/electrode/quit.php";quit($lang["api"]["calpast"]);
    }
    if (((int)date('m', $date) < (int)date('m')) && ((int)date('Y', $date) == (int)date('Y'))) {
        require $_SERVER['DOCUMENT_ROOT'] . "/api/electrode/quit.php";quit($lang["api"]["calpast"]);
    }
    if (((int)date('d', $date) < (int)date('d')) && ((int)date('m', $date) == (int)date('m'))) {
        require $_SERVER['DOCUMENT_ROOT'] . "/api/electrode/quit.php";quit($lang["api"]["calpast"]);
    }
    $name = str_replace('>', '&gt;', $name);
    $name = str_replace('<', '&lt;', $name);
    if (strlen($name) > 75) {
        require $_SERVER['DOCUMENT_ROOT'] . "/api/electrode/quit.php";quit($lang["api"]["calnamelong"]);
    }
    if (trim($name) == "") {
        require $_SERVER['DOCUMENT_ROOT'] . "/api/electrode/quit.php";quit($lang["api"]["calnamenone"]);
    }
    $desc = str_replace('>', '&gt;', $desc);
    $desc = str_replace('<', '&lt;', $desc);
    if ($day == "1") {
        $daystr = $lang["api"]["calordinal"];
    } else {
        $daystr = $day;
    }
    if ($month == "01") {
        $monthstr = $lang["api"]["calminmonths"][0];
    }
    if ($month == "02") {
        $monthstr = $lang["api"]["calminmonths"][1];
    }
    if ($month == "03") {
        $monthstr = $lang["api"]["calminmonths"][2];
    }
    if ($month == "04") {
        $monthstr = $lang["api"]["calminmonths"][3];
    }
    if ($month == "05") {
        $monthstr = $lang["api"]["calminmonths"][4];
    }
    if ($month == "06") {
        $monthstr = $lang["api"]["calminmonths"][5];
    }
    if ($month == "07") {
        $monthstr = $lang["api"]["calminmonths"][6];
    }
    if ($month == "08") {
        $monthstr = $lang["api"]["calminmonths"][7];
    }
    if ($month == "09") {
        $monthstr = $lang["api"]["calminmonths"][8];
    }
    if ($month == "10") {
        $monthstr = $lang["api"]["calminmonths"][9];
    }
    if ($month == "11") {
        $monthstr = $lang["api"]["calminmonths"][10];
    }
    if ($month == "12") {
        $monthstr = $lang["api"]["calminmonths"][11];
    }
    $json = json_decode($jsonraw);
    foreach($json->events as $event) {
        if (isset($event->timestamp)) {
            if ($event->timestamp == $year . date('m', $date) . date('d', $date)) {
                require $_SERVER['DOCUMENT_ROOT'] . "/api/electrode/quit.php";quit($lang["api"]["calsameday"]);
            }
        }
    }
    $pos = count($json->events);
    $json->events[$pos] = new stdClass();
    $json->events[$pos]->timestamp = $year . date('m', $date) . date('d', $date);
    $json->events[$pos]->name = $name;
    $json->events[$pos]->description = $desc;
    if (substr($link, 0, 4) == "http") {
        $json->events[$pos]->link = $link;
    } else {
        $json->events[$pos]->link = "http://" . $link;
    }
    $json->events[$pos]->datestr = $daystr . " " . $monthstr . " " . $year;
    $newjsonraw = json_encode($json, JSON_PRETTY_PRINT);
    file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/data/webcontent/caldb.json", $newjsonraw);
    require $_SERVER['DOCUMENT_ROOT'] . "/api/admin/cache_content_reset.php";
    require $_SERVER['DOCUMENT_ROOT'] . "/api/electrode/quit.php";quit("ok");
} else {
    require $_SERVER['DOCUMENT_ROOT'] . "/api/electrode/quit.php";quit($lang["api"]["calerror"]);
}