This repository was archived by the owner on Aug 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
55 lines (44 loc) · 1.63 KB
/
index.php
File metadata and controls
55 lines (44 loc) · 1.63 KB
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
<?php
require_once 'class/Config.php';
require_once 'class/Applications.php';
require_once 'class/Users.php';
// Initialisation des paraètres de configuration
require "config.php";
Config::initFromArray($_CONFIG);
// Initialisation de la connexion à la DataBase
require_once 'class/DB.php';
$DB = new DB(Config::get('sql_host'),Config::get('sql_user'),Config::get('sql_pass'),Config::get('sql_db'));
// Parse l'url
$path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$actions = explode('/', $path);
// On cherche index.php et on ne garde que ce qu'il y a après
$first = array_search("index.php", $actions) + 1;
$actions = array_slice($actions, $first);
if($actions[0] != "v1")
die("Version non supportée");
// Authentification de l'application
if(empty($_GET['key']) && empty($_POST['key'])) {
die("Pas de clé envoyée");
} else {
$key = $_GET['key'] ?? $_POST['key'];
if(!Applications::checkApp($key)) {
die("Clé invalide");
}
}
if(empty($actions[1]))
die("Pas d'action");
if($actions[1] == "find" || $actions[1] == "cotisations" || (!empty($actions[1]) && !empty($actions[2]) && $actions[2] == "cotisations"))
die("Action non implémentée");
if($actions[1] == "badge" && !empty($actions[2]))
$user = Users::getByBadge($actions[2]);
else if($actions[1] == "login") {
$user = Users::getByLoginKey($_POST['login'], $_POST['userKey']);
}
else if($actions[1] == "checkApp" && !empty($actions[2]))
$user = Applications::checkApp($_GET["key"]);
else if(!empty($actions[1]))
$user = Users::getByLogin($actions[1]);
if($user != null)
echo json_encode($user);
else
header("HTTP/1.0 404 Not Found");