-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathresaovh.php
executable file
·81 lines (65 loc) · 2.33 KB
/
resaovh.php
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
<?php
$feeder = getFeeder();
$getAvailability = file_get_contents("https://ws.ovh.com/dedicated/r2/ws.dispatcher/getAvailability");
// echo $getAvailability;
$availability = json_decode($getAvailability);
$servAvailability = $availability->answer->availability;
foreach ($servAvailability as $key => $value) {
//echo $value->reference;
foreach ($feeder as $feed) {
if ($value->reference == $feed[0]) {
$avaible = false;
foreach ($value->zones as $zone) {
// echo $zone->availability;
if ($zone->availability != "unavailable") {
// sendmail($zone, $feed[0], $feed[1]);
$avaible = true;
}
}
if ($avaible === true) {
sendmail($feed[0], $feed[1]);
//echo 'mailsend';
}
}
}
}
// var_dump($availability);
function sendmail($servRef, $mailFeeder) {
$to = "$mailFeeder";
$subject = 'Serveur Disponible';
$message = "Le serveur ($servRef) est disponible.
Pour le réserver aller à ce lien : https://eu.soyoustart.com/fr/commande/soYouStart.xml?reference=$servRef
Vous avez raté la disponibilité réactiver la demande : http://ovh-availability.loicvaille.ovh/";
$headers = 'From: [email protected]' . "\r\n" .
'Reply-To: [email protected]' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$log = mail($to, $subject, $message, $headers);
if ($log === true ) {
deleteFeeder($mailFeeder, $servRef);
incressFind();
}
}
function getFeeder() {
$feederjson = file_get_contents('/var/www/ovh-availability/feeder.json');
return json_decode($feederjson);
}
function deleteFeeder($mail, $servRef) {
$feederjson = file_get_contents('/var/www/ovh-availability/feeder.json');
$feeder = json_decode($feederjson);
$newfeeder = array();
foreach ($feeder as $user) {
if ($mail != $user[1] || $servRef != $user[0]) {
$newfeeder[] = $user;
}
}
$encoded_feeder = json_encode($newfeeder);
file_put_contents('/var/www/ovh-availability/feeder.json',$encoded_feeder.PHP_EOL);
}
function incressFind() {
$file = fopen('/var/www/ovh-availability/nbfind.txt', 'r+');
$nbfind = fgets($file); // On lit la première ligne (nombre de pages vues)
$nbfind = $nbfind + 1;
fseek($file, 0); // On remet le curseur au début du fichier
fputs($file, $nbfind); // On écrit le nouveau nombre de pages vues
fclose($file);
}