index.php 4.75 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
11
12
13
14
15
if (config_get_bool('options', 'enable-maintenance') && (empty($tokens[1]) || ($tokens[1] != "css" && $tokens[1] != "images"))) {
	header("HTTP/1.0 503 Service Unavailable");
	include "./503.php";
	return;
}

16
17
if (!empty($tokens[1]) && '/' . $tokens[1] == get_pkg_route()) {
	if (!empty($tokens[2])) {
18
19
20
21
		/* 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];
22
		$pkgid = pkg_from_name($pkgname);
23

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

	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;
		}
45
46

		if (!empty($tokens[3])) {
47
48
49
			/* TODO: Remove support for legacy URIs and move these
			 * actions to separate modules. */
			switch ($tokens[3]) {
50
51
52
53
			case "adopt":
				$_POST['do_Adopt'] = __('Adopt');
				break;
			case "disown":
54
55
				include('pkgdisown.php');
				return;
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
			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":
				$_POST['do_Flag'] = __('Flag');
				break;
			case "unflag":
				$_POST['do_UnFlag'] = __('UnFlag');
				break;
74
75
76
			case "delete":
				include('pkgdel.php');
				return;
77
78
79
			case "merge":
				include('pkgmerge.php');
				return;
80
			case "voters":
81
				$_GET['N'] = $tokens[2];
82
83
				include('voters.php');
				return;
84
85
86
			case "request":
				include('pkgreq.php');
				return;
87
88
89
			case "comaintainers":
				include('comaintainers.php');
				return;
90
91
92
93
			default:
				header("HTTP/1.0 404 Not Found");
				include "./404.php";
				return;
94
95
			}

96
			$_POST['IDs'] = array(pkgbase_from_name($tokens[2]) => '1');
97
98
99
		}
	}

100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
	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;
		}
	}

119
	include get_route('/' . $tokens[1]);
120
121
122
} elseif (!empty($tokens[1]) && '/' . $tokens[1] == get_user_route()) {
	if (!empty($tokens[2])) {
		$_REQUEST['ID'] = uid_from_username($tokens[2]);
123

124
125
126
127
128
129
130
		if (!$_REQUEST['ID']) {
			header("HTTP/1.0 404 Not Found");
			include "./404.php";
			return;
		}

		if (!empty($tokens[3])) {
131
132
			if ($tokens[3] == 'edit') {
				$_REQUEST['Action'] = "DisplayAccount";
133
134
			} elseif ($tokens[3] == 'update') {
				$_REQUEST['Action'] = "UpdateAccount";
135
136
			} elseif ($tokens[3] == 'delete') {
				$_REQUEST['Action'] = "DeleteAccount";
137
			} else {
138
139
140
				header("HTTP/1.0 404 Not Found");
				include "./404.php";
				return;
141
			}
142
143
		} else {
			$_REQUEST['Action'] = "AccountInfo";
144
		}
145
	}
146
147
	include get_route('/' . $tokens[1]);
} elseif (get_route($path) !== NULL) {
Lukas Fleischer's avatar
Lukas Fleischer committed
148
149
150
151
	include get_route($path);
} else {
	switch ($path) {
	case "/css/archweb.css":
152
	case "/css/aurweb.css":
153
	case "/css/cgit.css":
Lukas Fleischer's avatar
Lukas Fleischer committed
154
155
	case "/css/archnavbar/archnavbar.css":
		header("Content-Type: text/css");
156
		readfile("./$path");
Lukas Fleischer's avatar
Lukas Fleischer committed
157
158
		break;
	case "/css/archnavbar/archlogo.gif":
159
160
	case "/images/new.png":
		header("Content-Type: image/png");
161
		readfile("./$path");
Lukas Fleischer's avatar
Lukas Fleischer committed
162
163
		break;
	case "/css/archnavbar/archlogo.png":
Lukas Fleischer's avatar
Lukas Fleischer committed
164
	case "/css/archnavbar/aurlogo.png":
Lukas Fleischer's avatar
Lukas Fleischer committed
165
166
167
168
169
170
171
	case "/images/AUR-logo-80.png":
	case "/images/AUR-logo.png":
	case "/images/favicon.ico":
	case "/images/feed-icon-14x14.png":
	case "/images/titlelogo.png":
	case "/images/x.png":
		header("Content-Type: image/png");
172
		readfile("./$path");
Lukas Fleischer's avatar
Lukas Fleischer committed
173
		break;
174
	case "/js/bootstrap-typeahead.min.js":
Marcel Korpel's avatar
Marcel Korpel committed
175
		header("Content-Type: application/javascript");
176
		readfile("./$path");
Marcel Korpel's avatar
Marcel Korpel committed
177
		break;
178
179
180
181
182
183
	case "/packages.gz":
	case "/pkgbase.gz":
		header("Content-Type: text/plain");
		header("Content-Encoding: gzip");
		readfile("./$path");
		break;
184
185
186
187
	default:
		header("HTTP/1.0 404 Not Found");
		include "./404.php";
		break;
Lukas Fleischer's avatar
Lukas Fleischer committed
188
189
	}
}