-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathota.php
More file actions
76 lines (55 loc) · 1.7 KB
/
ota.php
File metadata and controls
76 lines (55 loc) · 1.7 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
#define('ARCHIVE_PATH','/srv');
#define('ARCHIVE_URL','https://download.lineage.org');
#define('PROP_TIMESTAMP_MARGIN',600);
define('ARCHIVE_PATH', getenv('ARCHIVE_PATH', true));
define('ARCHIVE_URL', getenv('ARCHIVE_URL', true));
define('PROP_TIMESTAMP_MARGIN', getenv('PROP_TIMESTAMP_MARGIN', true));
if(!isset($_SERVER['REQUEST_URI']))
die('Invalid request / Missing $_SERVER[\'REQUEST_URI\']');
$request_uri=preg_replace('#/+#','/',$_SERVER['REQUEST_URI']);
$parts=explode('/',$request_uri);
if(count($parts) != 6)
die('Invalid request');
$request=array(
'apiversion'=>$parts[2],
'device'=>$parts[3],
'romtype'=>$parts[4],
'incremental'=>$parts[5]
);
if($request['apiversion'] != 'v1')
die('Unsupported API version (!= v1)');
if(!is_dir(ARCHIVE_PATH . '/' . $request['device']))
die('Unknown device');
$incremental_time=0;
$prop_files=glob(ARCHIVE_PATH . '/' . $request['device'] . '/*.prop');
foreach($prop_files as $prop_file)
{
if (strpos(file_get_contents($prop_file), $request['incremental']) !== false)
{
$incremental_time=filemtime($prop_file)+PROP_TIMESTAMP_MARGIN;
break;
}
}
$files=glob(ARCHIVE_PATH . '/' . $request['device'] . '/*.zip');
$roms=array();
foreach($files as $file)
{
$filename=basename($file);
$version=explode('-',$filename)[1];
$rom=array(
'datetime'=>filemtime($file),
'filename'=>$filename,
'id'=>strval(filemtime($file)),
'romtype'=>$request['romtype'],
'size'=>filesize($file),
'url'=>ARCHIVE_URL . '/' . $request['device'] . '/' . $filename,
'version'=>$version
);
if ($rom['datetime'] > $incremental_time)
$roms[]=$rom;
}
$output['response']=$roms;
header('Content-Type: application/json');
echo json_encode($output, JSON_UNESCAPED_SLASHES);
?>