This repository was archived by the owner on Jan 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcron.php
88 lines (68 loc) · 3.07 KB
/
cron.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
82
83
84
85
86
87
88
<?php
require_once('config.php');
require_once('functions.php');
if(!$aGlobalConfig['cron']['enableWebAccess'])
die("The website administrator has disabled cron triggers through the URL.");
cronPrint('WebTSS cron running..');
$webTSSRoot = realpath(dirname(__FILE__));
$mysqli = new mysqli($aGlobalConfig['database']['host'], $aGlobalConfig['database']['username'], $aGlobalConfig['database']['password'], $aGlobalConfig['database']['database'],$aGlobalConfig['database']['port']);
$tssPermissions = substr(sprintf('%o', fileperms($webTSSRoot.'/tss')), -4);
$binary = $aGlobalConfig["tssbinary"];
if(!is_dir($webTSSRoot.'/tss'))
die('Please create the directory "'.$webTSSRoot.'/tss'.'"..');
if(!is_writable($webTSSRoot.'/tss'))
die('Can\'t write to "'.$webTSSRoot.'/tss"..');
if(!is_readable($webTSSRoot.'/tss'))
die('Can\'t read "'.$webTSSRoot.'/tss"..');
if(!is_dir($webTSSRoot.'/bins'))
die('Please create the directory "'.$webTSSRoot.'/bins"..');
if(!is_readable($webTSSRoot.'/bins'))
die('Can\'t read "'.$webTSSRoot.'/bins"..');
if(!is_executable($webTSSRoot."/bins/$binary"))
die('TSSChecker is not executable. Please fix this with chmod +x '.$webTSSRoot."/bins/$binary");
if (mysqli_connect_errno())
die('Can\'t connect to the database..');
if ($stmt = $mysqli->prepare("SELECT ecid, platform FROM devices")) {
/* execute statement */
$stmt->execute();
/* bind result variables */
$stmt->bind_result($ecid, $platform);
/* fetch values */
while ($stmt->fetch()) {
cronPrint("Working on $ecid ($platform)..");
$command = $webTSSRoot.'/bins/tsschecker -e '.hexdec($ecid).' -d '.basename($platform).' -s -l --save-path '.$webTSSRoot.'/tss/'.hexdec($ecid);
if(!is_dir($webTSSRoot.'/tss/'.hexdec($ecid))) {
cronPrint("Creating \"".$webTSSRoot.'/tss/'.hexdec($ecid)."\"..");
mkdir($webTSSRoot.'/tss/'.hexdec($ecid));
}
if(!is_readable($webTSSRoot.'/tss/'.hexdec($ecid)) || !is_writable($webTSSRoot.'/tss/'.hexdec($ecid))) {
cronPrint('Can\'t read and/or write to "'.$webTSSRoot.'/tss/'.hexdec($ecid).'"..');
} else {
// Big thanks to 1Conan!
$signedVersionsURL = "https://api.ipsw.me/v2.1/firmwares.json/condensed";
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL,$signedVersionsURL);
$result = curl_exec($ch);
curl_close($ch);
$data = json_decode($result, true);
$firmwares = $data['devices'][$platform]['firmwares'];
$countFirmwares = count($firmwares);
for($i = 0; $i < $countFirmwares; $i++) {
$current = $firmwares[$i];
if($current['signed'] == true) {
$command = $webTSSRoot."/bins/$binary -e ".hexdec($ecid).' -d '.basename($platform).' -s --buildid '.$current['buildid'].' --save-path '.$webTSSRoot.'/tss/'.hexdec($ecid);
cronPrint("Running \"".$command."\"..");
@shell_exec($command);
}
}
}
}
/* close statement */
$stmt->close();
}
/* close connection */
$mysqli->close();
cronPrint('Cron finished.');
?>