index.php 5.24 KB
Newer Older
1
<?php
2
set_include_path(get_include_path() . PATH_SEPARATOR . '../lib');
pjmattal's avatar
pjmattal committed
3

4
5
include_once("aur.inc.php");
include_once("pkgfuncs.inc.php");
Lukas Fleischer's avatar
Lukas Fleischer committed
6

7
$path = $_SERVER['PATH_INFO'];
8
$tokens = explode('/', $path);
Lukas Fleischer's avatar
Lukas Fleischer committed
9

Lukas Fleischer's avatar
Lukas Fleischer committed
10
if (config_get_bool('options', 'enable-maintenance') && (empty($tokens[1]) || ($tokens[1] != "css" && $tokens[1] != "images"))) {
11
12
13
14
15
	if (!in_array($_SERVER['REMOTE_ADDR'], explode(" ", config_get('options', 'maintenance-exceptions')))) {
		header("HTTP/1.0 503 Service Unavailable");
		include "./503.php";
		return;
	}
Lukas Fleischer's avatar
Lukas Fleischer committed
16
17
}

18
19
if (!empty($tokens[1]) && '/' . $tokens[1] == get_pkg_route()) {
	if (!empty($tokens[2])) {
20
21
22
23
		/* TODO: Create a proper data structure to pass variables from
		 * the routing framework to the individual pages instead of
		 * initializing arbitrary variables here. */
		$pkgname = $tokens[2];
24
		$pkgid = pkg_from_name($pkgname);
25

26
27
28
29
30
		if (!$pkgid) {
			header("HTTP/1.0 404 Not Found");
			include "./404.php";
			return;
		}
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
	}

	include get_route('/' . $tokens[1]);
} elseif (!empty($tokens[1]) && '/' . $tokens[1] == get_pkgbase_route()) {
	if (!empty($tokens[2])) {
		/* TODO: Create a proper data structure to pass variables from
		 * the routing framework to the individual pages instead of
		 * initializing arbitrary variables here. */
		$pkgbase_name = $tokens[2];
		$base_id = pkgbase_from_name($pkgbase_name);

		if (!$base_id) {
			header("HTTP/1.0 404 Not Found");
			include "./404.php";
			return;
		}
47
48

		if (!empty($tokens[3])) {
49
50
51
			/* TODO: Remove support for legacy URIs and move these
			 * actions to separate modules. */
			switch ($tokens[3]) {
52
53
54
55
			case "adopt":
				$_POST['do_Adopt'] = __('Adopt');
				break;
			case "disown":
56
57
				include('pkgdisown.php');
				return;
58
59
60
61
62
63
64
65
66
67
68
69
70
			case "vote":
				$_POST['do_Vote'] = __('Vote');
				break;
			case "unvote":
				$_POST['do_UnVote'] = __('UnVote');
				break;
			case "notify":
				$_POST['do_Notify'] = __('Notify');
				break;
			case "unnotify":
				$_POST['do_UnNotify'] = __('UnNotify');
				break;
			case "flag":
71
72
				include('pkgflag.php');
				return;
73
74
75
			case "unflag":
				$_POST['do_UnFlag'] = __('UnFlag');
				break;
Mark Weiman's avatar
Mark Weiman committed
76
77
78
			case "flag-comment":
				include('pkgflagcomment.php');
				return;
79
80
81
			case "delete":
				include('pkgdel.php');
				return;
82
83
84
			case "merge":
				include('pkgmerge.php');
				return;
85
			case "voters":
86
				$_GET['N'] = $tokens[2];
87
88
				include('voters.php');
				return;
89
90
91
			case "request":
				include('pkgreq.php');
				return;
92
93
94
			case "comaintainers":
				include('comaintainers.php');
				return;
Marcel Korpel's avatar
Marcel Korpel committed
95
96
97
			case "edit-comment":
				include('commentedit.php');
				return;
98
99
100
101
			default:
				header("HTTP/1.0 404 Not Found");
				include "./404.php";
				return;
102
103
			}

104
			$_POST['IDs'] = array(pkgbase_from_name($tokens[2]) => '1');
105
106
107
		}
	}

108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
	include get_route('/' . $tokens[1]);
} elseif (!empty($tokens[1]) && '/' . $tokens[1] == get_pkgreq_route()) {
	if (!empty($tokens[2])) {
		/* TODO: Create a proper data structure to pass variables from
		 * the routing framework to the individual pages instead of
		 * initializing arbitrary variables here. */
		if (!empty($tokens[3]) && $tokens[3] == 'close') {
			$pkgreq_id = $tokens[2];
		} else {
			$pkgreq_id = null;
		}

		if (!$pkgreq_id) {
			header("HTTP/1.0 404 Not Found");
			include "./404.php";
			return;
		}
	}

127
	include get_route('/' . $tokens[1]);
128
129
130
} elseif (!empty($tokens[1]) && '/' . $tokens[1] == get_user_route()) {
	if (!empty($tokens[2])) {
		$_REQUEST['ID'] = uid_from_username($tokens[2]);
131

132
133
134
135
136
137
138
		if (!$_REQUEST['ID']) {
			header("HTTP/1.0 404 Not Found");
			include "./404.php";
			return;
		}

		if (!empty($tokens[3])) {
139
140
			if ($tokens[3] == 'edit') {
				$_REQUEST['Action'] = "DisplayAccount";
141
142
			} elseif ($tokens[3] == 'update') {
				$_REQUEST['Action'] = "UpdateAccount";
143
144
			} elseif ($tokens[3] == 'delete') {
				$_REQUEST['Action'] = "DeleteAccount";
145
			} else {
146
147
148
				header("HTTP/1.0 404 Not Found");
				include "./404.php";
				return;
149
			}
150
151
		} else {
			$_REQUEST['Action'] = "AccountInfo";
152
		}
153
	}
154
155
	include get_route('/' . $tokens[1]);
} elseif (get_route($path) !== NULL) {
Lukas Fleischer's avatar
Lukas Fleischer committed
156
157
158
159
	include get_route($path);
} else {
	switch ($path) {
	case "/css/archweb.css":
160
	case "/css/aurweb.css":
161
	case "/css/cgit.css":
Lukas Fleischer's avatar
Lukas Fleischer committed
162
163
	case "/css/archnavbar/archnavbar.css":
		header("Content-Type: text/css");
164
		readfile("./$path");
Lukas Fleischer's avatar
Lukas Fleischer committed
165
		break;
166
167
168
169
	case "/images/ajax-loader.gif":
		header("Content-Type: image/gif");
		readfile("./$path");
		break;
Lukas Fleischer's avatar
Lukas Fleischer committed
170
	case "/css/archnavbar/archlogo.gif":
171
		header("Content-Type: image/png");
172
		readfile("./$path");
Lukas Fleischer's avatar
Lukas Fleischer committed
173
174
		break;
	case "/css/archnavbar/archlogo.png":
Lukas Fleischer's avatar
Lukas Fleischer committed
175
	case "/css/archnavbar/aurlogo.png":
Lukas Fleischer's avatar
Lukas Fleischer committed
176
177
178
179
	case "/images/favicon.ico":
	case "/images/titlelogo.png":
	case "/images/x.png":
		header("Content-Type: image/png");
180
		readfile("./$path");
Lukas Fleischer's avatar
Lukas Fleischer committed
181
		break;
182
	case "/images/x.min.svg":
183
	case "/images/action-undo.min.svg":
Marcel Korpel's avatar
Marcel Korpel committed
184
	case "/images/pencil.min.svg":
185
186
	case "/images/pin.min.svg":
	case "/images/unpin.min.svg":
Lukas Fleischer's avatar
Lukas Fleischer committed
187
	case "/images/rss.svg":
Lukas Fleischer's avatar
Lukas Fleischer committed
188
	case "/images/new.svg":
189
190
191
		header("Content-Type: image/svg+xml");
		readfile("./$path");
		break;
192
	case "/js/bootstrap-typeahead.min.js":
Marcel Korpel's avatar
Marcel Korpel committed
193
		header("Content-Type: application/javascript");
194
		readfile("./$path");
Marcel Korpel's avatar
Marcel Korpel committed
195
		break;
196
197
198
199
200
201
	case "/packages.gz":
	case "/pkgbase.gz":
		header("Content-Type: text/plain");
		header("Content-Encoding: gzip");
		readfile("./$path");
		break;
202
203
204
205
	default:
		header("HTTP/1.0 404 Not Found");
		include "./404.php";
		break;
Lukas Fleischer's avatar
Lukas Fleischer committed
206
207
	}
}