This repository has been archived by the owner on Feb 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
134 lines (122 loc) · 2.29 KB
/
index.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
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
<?php
$dataset = 'ssd';
$date = get_date();
switch($dataset)
{
case "aff":
$model = 'aff';
break;
case "apt":
$model = 'apt';
break;
case "arb":
$model = 'arb';
break;
case "ats":
$model = 'ats';
break;
case "awos":
$model = 'awos';
break;
case "awy":
$model = 'awy';
break;
case "cdr":
$model = 'cdr';
break;
case "com":
$model = 'com';
break;
case "fix":
$model = 'fix';
break;
case "fss":
$model = 'fss';
break;
case "harfix":
$model = 'harfix';
break;
case "hpf":
$model = 'hpf';
break;
case "ils":
$model = 'ils';
break;
case "lid":
$model = 'lid';
break;
case "mtr":
$model = 'mtr';
break;
case "natfix":
$model = 'natfix';
break;
case "nav":
$model = 'nav';
break;
case "pfr":
$model = 'pfr';
break;
case "pja":
$model = 'pja';
break;
case "ssd":
$model = 'ssd';
break;
case "stardp":
$model = 'stardp';
break;
case "twr":
$model = 'twr';
break;
default:
echo "Invalid dataset";
exit;
break;
}
require_once('./functions/'.$model.'.php');
$header = '
; Generated with OpenFMS v1.0
; Created on '.date("Y-m-d").'
; Dataset '.strtoupper($model).'
; NFDC Rotation '.$date.'
';
process($date);
function get_date()
{
$page = file_get_contents('https://nfdc.faa.gov/xwiki/bin/view/NFDC/56+Day+NASR+Subscription');
$url = explode('<h2>Current</h2>',$page);
$url = explode('">',$url[1]);
$url = explode('<a href="/xwiki/bin/view/NFDC/56DaySub-',$url[0]);
$date = $url[1];
return $date;
}
function get_data($url,$internal_filename)
{
// download zip to tmp
$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL,$url);
curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);
// write file
$file_name = time();
file_put_contents('./tmp/'.$file_name.'.zip',$buffer);
// unzip
$zip = new ZipArchive;
$res = $zip->open('./tmp/'.$file_name.'.zip');
if ($res === TRUE) {
echo 'ok';
$zip->extractTo('./tmp/');
$zip->close();
} else {
echo 'failed, code:' . $res;
}
// load file into memory
$file_data = file_get_contents('./tmp/'.$internal_filename);
// delete zip and folder
unlink('./tmp/'.$file_name.'.zip');
unlink('./tmp/'.$internal_filename);
return $file_data;
}