Support exceptions in the maintenance mode

Allow for excluding certain IP addresses from the maintenance mode. This
allows administrators to view the web page while the site is still under
maintenance for the rest of the world.

Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
This commit is contained in:
Lukas Fleischer 2015-06-11 14:41:06 +02:00
parent a45b5073ca
commit 078f7256e3
3 changed files with 10 additions and 4 deletions

View file

@ -29,6 +29,7 @@ pkgbuild_uri = https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=%s
log_uri = https://aur.archlinux.org/cgit/aur.git/log/?h=%s
snapshot_uri = https://aur.archlinux.org/cgit/aur.git/snapshot/%s.tar.gz
enable-maintenance = 1
maintenance-exceptions = 127.0.0.1
[auth]
valid-keytypes = ssh-rsa ssh-dss ecdsa-sha2-nistp256 ecdsa-sha2-nistp384 ecdsa-sha2-nistp521 ssh-ed25519

View file

@ -22,6 +22,7 @@ git_shell_cmd = config.get('serve', 'git-shell-cmd')
ssh_cmdline = config.get('serve', 'ssh-cmdline')
enable_maintenance = config.getboolean('options', 'enable-maintenance')
maintenance_exc = config.get('options', 'maintenance-exceptions').split()
def pkgbase_exists(pkgbase):
db = mysql.connector.connect(host=aur_db_host, user=aur_db_user,
@ -113,6 +114,8 @@ cmdargv = shlex.split(cmd)
action = cmdargv[0]
if enable_maintenance:
remote_addr = os.environ["SSH_CLIENT"].split(" ")[0]
if not remote_addr in maintenance_exc:
die("The AUR is down due to maintenance. We will be back soon.")
if action == 'git-upload-pack' or action == 'git-receive-pack':

View file

@ -8,10 +8,12 @@ $path = $_SERVER['PATH_INFO'];
$tokens = explode('/', $path);
if (config_get_bool('options', 'enable-maintenance') && (empty($tokens[1]) || ($tokens[1] != "css" && $tokens[1] != "images"))) {
if (!in_array($_SERVER['REMOTE_ADDR'], explode(" ", config_get('options', 'maintenance-exceptions')))) {
header("HTTP/1.0 503 Service Unavailable");
include "./503.php";
return;
}
}
if (!empty($tokens[1]) && '/' . $tokens[1] == get_pkg_route()) {
if (!empty($tokens[2])) {