From 76343fb91511b9f53e58b6c01b258bfe00ddb4c6 Mon Sep 17 00:00:00 2001
From: Lukas Fleischer
Date: Fri, 24 Oct 2014 08:31:47 +0200
Subject: Use an INI-style configuration file
Replace web/lib/config.inc.php with an INI-style configuration file.
This allows us to get rid of several globals and makes it easier to use
the same configuration file in external scripts.
Signed-off-by: Lukas Fleischer
---
conf/config.proto | 29 +++++++++++++++
scripts/aurblup/aurblup-wrapper | 12 ++++---
scripts/cleanup | 11 +++---
upgrading/3.5.0.txt | 4 +++
web/html/login.php | 9 ++---
web/html/pkgsubmit.php | 8 ++---
web/lib/DB.class.php | 17 +++++++--
web/lib/acctfuncs.inc.php | 66 ++++++++++++++++------------------
web/lib/aur.inc.php | 26 +++++++++-----
web/lib/aurjson.class.php | 13 ++++---
web/lib/config.inc.php.proto | 72 -------------------------------------
web/lib/confparser.inc.php | 20 +++++++++++
web/lib/credentials.inc.php | 1 -
web/lib/pkgbasefuncs.inc.php | 17 ++-------
web/lib/pkgfuncs.inc.php | 7 +---
web/lib/pkgreqfuncs.inc.php | 41 +++++++++------------
web/lib/routing.inc.php | 18 +++++-----
web/lib/translator.inc.php | 8 ++---
web/template/actions_form.php | 2 +-
web/template/header.php | 2 +-
web/template/pkg_details.php | 13 +++----
web/template/pkgbase_details.php | 13 +++----
web/template/pkgreq_results.php | 5 +--
web/template/tu_last_votes_list.php | 2 +-
24 files changed, 200 insertions(+), 216 deletions(-)
create mode 100644 conf/config.proto
delete mode 100644 web/lib/config.inc.php.proto
create mode 100644 web/lib/confparser.inc.php
diff --git a/conf/config.proto b/conf/config.proto
new file mode 100644
index 0000000..280c1e8
--- /dev/null
+++ b/conf/config.proto
@@ -0,0 +1,29 @@
+[database]
+dsn_prefix = mysql
+host = localhost
+socket = /var/run/mysqld/mysqld.sock
+name = AUR
+user = aur
+password = aur
+
+[paths]
+storage = /srv/aur/unsupported/
+
+[options]
+username_min_len = 3
+username_max_len = 16
+passwd_min_len = 4
+default_lang = en
+sql_debug = 0
+max_sessions_per_user = 8
+login_timeout = 7200
+persistent_cookie_timeout = 2592000
+max_filesize_uncompressed = 8388608
+disable_http_login = 1
+aur_location = http://localhost
+package_url = /packages/
+use_virtual_urls = 1
+max_rpc_results = 5000
+aur_request_ml = aur-requests@archlinux.org
+request_idle_time = 1209600
+auto_orphan_age = 15552000
diff --git a/scripts/aurblup/aurblup-wrapper b/scripts/aurblup/aurblup-wrapper
index b056030..c7b20af 100755
--- a/scripts/aurblup/aurblup-wrapper
+++ b/scripts/aurblup/aurblup-wrapper
@@ -8,10 +8,14 @@ if (empty($dir)) {
}
set_include_path(get_include_path() . PATH_SEPARATOR . "$dir/lib");
-include("config.inc.php");
+include("confparser.inc.php");
+
+$user = config_get('database', 'user');
+$password = config_get('database', 'password');
+$name = config_get('database', 'name');
exec($dir . "/../scripts/aurblup/aurblup " .
"-S /var/run/mysqld/mysqld.sock " .
- "-u " . escapeshellarg(AUR_db_user) . " " .
- "-p " . escapeshellarg(AUR_db_pass) . " " .
- "-D " . escapeshellarg(AUR_db_name));
+ "-u " . escapeshellarg($user) . " " .
+ "-p " . escapeshellarg($password) . " " .
+ "-D " . escapeshellarg($name));
diff --git a/scripts/cleanup b/scripts/cleanup
index 1fe63a2..0ccbe7d 100755
--- a/scripts/cleanup
+++ b/scripts/cleanup
@@ -16,24 +16,25 @@ if (empty($dir)) {
}
set_include_path(get_include_path() . PATH_SEPARATOR . "$dir/lib");
-include("config.inc.php");
+include("confparser.inc.php");
include("aur.inc.php");
include("pkgfuncs.inc.php");
$count = 0;
-$buckets = scandir(INCOMING_DIR);
+$incoming_dir = config_get('paths', 'storage');
+$buckets = scandir($incoming_dir);
foreach ($buckets as $bucket) {
- $bucketpath = INCOMING_DIR . $bucket;
+ $bucketpath = $incoming_dir . $bucket;
if ($bucket == '.' || $bucket == '..' || !is_dir($bucketpath)) {
continue;
}
- $files = scandir(INCOMING_DIR . $bucket);
+ $files = scandir($incoming_dir . $bucket);
foreach ($files as $pkgname) {
if ($pkgname == '.' || $pkgname == '..') {
continue;
}
- $fullpath = INCOMING_DIR . $bucket . "/" . $pkgname;
+ $fullpath = $incoming_dir . $bucket . "/" . $pkgname;
if (!pkg_from_name($pkgname) && is_dir($fullpath)) {
echo 'Removing ' . $fullpath . "\n";
rm_tree($fullpath);
diff --git a/upgrading/3.5.0.txt b/upgrading/3.5.0.txt
index 1990c47..e8af4af 100644
--- a/upgrading/3.5.0.txt
+++ b/upgrading/3.5.0.txt
@@ -17,3 +17,7 @@ ALTER TABLE PackageVotes ADD COLUMN VoteTS BIGINT NULL DEFAULT NULL;
----
INSERT INTO PackageCategories (Category) VALUES ('wayland');
----
+
+4. The configuration file format has been changed. Make sure you convert
+web/lib/config.inc.php to the new format (see conf/config.proto for an example
+configuration) and put the resulting file in conf/config.
diff --git a/web/html/login.php b/web/html/login.php
index e458fec..dba3af5 100644
--- a/web/html/login.php
+++ b/web/html/login.php
@@ -5,7 +5,8 @@ include_once("aur.inc.php");
set_lang();
check_sid();
-if (!$DISABLE_HTTP_LOGIN || (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'])) {
+$disable_http_login = config_get_bool('options', 'disable_http_login');
+if (!$disable_http_login || (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'])) {
$login = try_login();
$login_error = $login['error'];
}
@@ -19,7 +20,7 @@ html_header('AUR ' . __("Login"));
= __("Logged-in as: %s", '' . username_from_sid($_COOKIE["AURSID"]) . ''); ?>
[= __("Logout"); ?>]
-
+