diff --git a/.gitignore b/.gitignore
index 4559ec0c..408081e9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,3 +5,5 @@
# Ignore file with the account data
/password.dat
+
+/pages/index/feed.rss
diff --git a/README b/README
deleted file mode 100644
index 7f2ca78c..00000000
--- a/README
+++ /dev/null
@@ -1,17 +0,0 @@
-LibreSSL Documentation
-
-(c) 2005-2008 by CAcert Inc.
-License: GNU-GPLv2
-
-System Requirements:
-Linux/POSIX
-PHP
-GetText
-UFPDF - PDF generation library from http://acko.net/node/56
-OpenSSL - X.509 toolkit from http://www.openssl.org/
-openssl-vulnkey including blacklists for all common key sizes
-GnuPG - OpenPGP toolkit from http://www.gnupg.org/
-whois - whois client from http://www.linux.it/~md/software/
-XEnroll - Enrollment Active-X control for IE5/6 from Microsoft (search for xenroll.cab)
-CommModule - CAcert Communication Module
-
diff --git a/README.md b/README.md
new file mode 100644
index 00000000..240e8837
--- /dev/null
+++ b/README.md
@@ -0,0 +1,89 @@
+# LibreSSL Documentation
+
+(c) 2005-2020 by CAcert Inc. License: GNU-GPLv2
+
+## System Requirements
+
+* Linux/POSIX PHP and Webserver (i.e. Apache httpd)
+* MySQL compatible database system
+
+
+* GetText UFPDF - PDF generation library from http://acko.net/node/56
+* OpenSSL - X.509 toolkit from http://www.openssl.org/
+* openssl-vulnkey including blacklists for all common key sizes
+* GnuPG - OpenPGP toolkit from http://www.gnupg.org/
+* whois - whois client from http://www.linux.it/~md/software/
+* XEnroll - Enrollment Active-X control for IE5/6 from Microsoft (search for xenroll.cab)
+* CommModule - CAcert Communication Module
+
+## Setup
+
+### Create a database and database user
+
+Create a new database with charset `latin1` and default collation
+`latin1_swedish_ci`. These settings are used for historical reasons.
+
+Create a user that has permissions on the database and has the global
+[`FILE`](https://mariadb.com/kb/en/grant/#file) permission that is required to export files using
+the `SELECT INTO OUTFILE` clause.
+
+The SQL commands can be executed in a shell via the regular mysql or mariadb command:
+
+```shell
+sudo mysql mysql <<<-EOF
+-- SQL commands
+EOF
+```
+
+```sql
+CREATE DATABASE cacert CHARSET latin1 COLLATE latin1_swedish_ci;
+CREATE USER cacertmigration@localhost IDENTIFIED BY 'hardtoguesslongpassword';
+GRANT ALL PRIVILEGES ON cacert.* TO cacertmigration@localhost;
+GRANT FILE ON *.* TO cacertmigration@localhost;
+```
+
+It is a good idea to create a different user for the application that has only the necessary privileges:
+
+```sql
+CREATE USER cacertapplication@localhost IDENTIFIED BY 'anotherhardpassword';
+GRANT CREATE TEMPORARY TABLES ON cacert.* TO cacertapplication@localhost;
+GRANT SELECT, INSERT, UPDATE, DELETE ON cacert.* TO cacertapplication@localhost;
+```
+
+### Apply schema migrations
+
+```shell
+sh scripts/db_migrations/version0.sh -h localhost -u cacertmigration -phardtoguesslongpassword cacert
+sh scripts/db_migrations/version1.sh -h localhost -u cacertmigration -phardtoguesslongpassword cacert
+sh scripts/db_migrations/version2.sh -h localhost -u cacertmigration -phardtoguesslongpassword cacert
+sh scripts/db_migrations/version3.sh -h localhost -u cacertmigration -phardtoguesslongpassword cacert
+sh scripts/db_migrations/version4.sh -h localhost -u cacertmigration -phardtoguesslongpassword cacert
+sh scripts/db_migrations/version5.sh -h localhost -u cacertmigration -phardtoguesslongpassword cacert
+sh scripts/db_migrations/version6.sh -h localhost -u cacertmigration -phardtoguesslongpassword cacert
+```
+
+### Configuration
+
+The application is configured via a set of environment variables. The variables can be defined via
+[`SetEnv` directives](https://httpd.apache.org/docs/current/mod/mod_env.html#setenv). The following environment
+variables are used:
+
+Variable | Description | Default value
+---- | ---- | ----
+`DEPLOYMENT_NAME` | name of the specific instance | `"CAcert.org Website"`
+`CRT_DIRECTORY`* | directory where certificates are stored | none
+`CSR_DIRECTORY`* | directory where CSRs are stored | none
+`MYSQL_WEBDB_DATABASE`* | database name | none
+`MYSQL_WEBDB_HOSTNAME`* | database hostname | none
+`MYSQL_WEBDB_PASSWORD`* | database password | none
+`MYSQL_WEBDB_USER`* | database user name | none
+`RETURN_ADDRESS`* | return address (Errors-To header) for outgoing mails | none
+`SMTP_HOST`* | mail server to use for outgoing mails | none
+`SMTP_PORT` | port of the mail server | `25`
+`INSECURE_PORT` | port to use for http | none (defaults to 80)
+`SECURE_PORT` | port to use for https | none (default to 443)
+`DEFAULT_HOSTNAME`* | hostname for the default URL | none
+`SECURE_HOSTNAME`* | hostname for client certificate authentication | none
+`TVERIFY_HOSTNAME`* | hostname for tverify | none
+
+Environment variables marked with an asterisk (*) need to be defined explicitly.
\ No newline at end of file
diff --git a/TODO.md b/TODO.md
new file mode 100644
index 00000000..d086bbd7
--- /dev/null
+++ b/TODO.md
@@ -0,0 +1,30 @@
+# Development to do list
+
+## Modernization for PHP > 5 and newer OS
+
+* change from deprecated mysql to mysqli ✅
+* switch to supported PDF library ([tcpdf](https://tcpdf.org/))
+
+## Maintainability
+
+* rename numbered files to something more readable
+* implement release automation
+* implement automated tests
+
+## Best practice implementation
+
+* switch everything to UTF-8 (better i18n, support for international names, support for modern PDF library, ...)
+* use redirect after POST for all form actions
+* implement CSRF protection
+
+## Code quality
+
+* do not store request scoped objects in session
+* unify formatting
+* add copyright headers in all files
+* remove dead code / commented sections
+
+## Documentation
+
+* add documentation for all request flows
+* add documentation for the signer protocol
\ No newline at end of file
diff --git a/changelog.md b/changelog.md
new file mode 100644
index 00000000..873307ed
--- /dev/null
+++ b/changelog.md
@@ -0,0 +1,6 @@
+# Change log
+
+## _unreleased_
+
+* switch from deprecated mysql_* APIs to [mysqli](https://www.php.net/manual/de/book.mysqli.php)
+* add documentation for setup (in [README.md](README.md)) and [development to do list](TODO.md)
\ No newline at end of file
diff --git a/includes/.cvsignore b/includes/.cvsignore
deleted file mode 100644
index 3317ea5d..00000000
--- a/includes/.cvsignore
+++ /dev/null
@@ -1,2 +0,0 @@
-mysql.php
-hash_password.php
diff --git a/includes/.gitignore b/includes/.gitignore
deleted file mode 100644
index 9ac21562..00000000
--- a/includes/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-mysql.php
diff --git a/includes/about_menu.php b/includes/about_menu.php
index f34a2749..90d8aa10 100644
--- a/includes/about_menu.php
+++ b/includes/about_menu.php
@@ -8,7 +8,7 @@
diff --git a/includes/lib/account.php b/includes/lib/account.php
index dd8afd3b..036d96c1 100644
--- a/includes/lib/account.php
+++ b/includes/lib/account.php
@@ -1,7 +1,7 @@
= 100';
- $query = mysql_query($sql);
+ $query = $db_conn->query($sql);
if (!$query) {
return false;
}
@@ -91,7 +92,7 @@ function fix_assurer_flag($userID = NULL)
) < 100
)';
- $query = mysql_query($sql);
+ $query = $db_conn->query($sql);
if (!$query) {
return false;
}
diff --git a/includes/lib/general.php b/includes/lib/general.php
index 127c6b76..9ab4645f 100644
--- a/includes/lib/general.php
+++ b/includes/lib/general.php
@@ -1,6 +1,6 @@
/*
LibreSSL - CAcert web application
- Copyright (C) 2004-2011 CAcert Inc.
+ Copyright (C) 2004-2020 CAcert Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -31,16 +31,17 @@
*/
function get_user_id_from_cert($serial, $issuer_cn)
{
+ global $db_conn;
$query = "select `memid` from `emailcerts` where
- `serial`='".mysql_escape_string($serial)."' and
+ `serial`='".$db_conn->real_escape_string($serial)."' and
`rootcert`= (select `id` from `root_certs` where
- `Cert_Text`='".mysql_escape_string($issuer_cn)."') and
+ `Cert_Text`='".$db_conn->real_escape_string($issuer_cn)."') and
`revoked`=0 and disablelogin=0 and
UNIX_TIMESTAMP(`expire`) - UNIX_TIMESTAMP() > 0";
- $res = mysql_query($query);
- if(mysql_num_rows($res) > 0)
+ $res = $db_conn->query($query);
+ if($res->num_rows > 0)
{
- $row = mysql_fetch_assoc($res);
+ $row = $res->fetch_assoc();
return intval($row['memid']);
}
@@ -138,22 +139,24 @@ function runCommand($command, $input = "", &$output = null, &$errors = true) {
// Bit 3 is set if the user is not allowed to be an Assurer (assurer_blocked > 0)
function get_assurer_status($userID)
{
+ global $db_conn;
$Result = 0;
- $query = mysql_query('SELECT * FROM `cats_passed` AS `tp`, `cats_variant` AS `cv` '.
+ $query = $db_conn->query('SELECT * FROM `cats_passed` AS `tp`, `cats_variant` AS `cv` '.
' WHERE `tp`.`variant_id` = `cv`.`id` AND `cv`.`type_id` = 1 AND `tp`.`user_id` = \''.(int)intval($userID).'\'');
- if(mysql_num_rows($query) < 1)
+ if($query->num_rows < 1)
{
$Result |= 5;
}
- $query = mysql_query('SELECT SUM(`points`) AS `points` FROM `notary` AS `n` WHERE `n`.`to` = \''.(int)intval($userID).'\' AND `n`.`expire` < now() and `deleted` = 0');
- $row = mysql_fetch_assoc($query);
+ $query = $db_conn->query('SELECT SUM(`points`) AS `points` FROM `notary` AS `n` WHERE `n`.`to` = \''.(int)intval
+ ($userID).'\' AND `n`.`expire` < now() and `deleted` = 0');
+ $row = $query->fetch_assoc();
if ($row['points'] < 100) {
$Result |= 3;
}
- $query = mysql_query('SELECT `assurer_blocked` FROM `users` WHERE `id` = \''.(int)intval($userID).'\'');
- $row = mysql_fetch_assoc($query);
+ $query = $db_conn->query('SELECT `assurer_blocked` FROM `users` WHERE `id` = \''.(int)intval($userID).'\'');
+ $row = $query->fetch_assoc();
if ($row['assurer_blocked'] > 0) {
$Result |= 9;
}
diff --git a/includes/lib/l10n.php b/includes/lib/l10n.php
index 4859946d..ae371228 100644
--- a/includes/lib/l10n.php
+++ b/includes/lib/l10n.php
@@ -1,6 +1,6 @@
$qvalue)
{
// ignore any non-conforming values (that's why we don't need to
- // mysql_real_escape() or escapeshellarg(), but take care of
+ // $db_conn->real_escape_string() or escapeshellarg(), but take care of
// the '*')
// spec: ( ( 1*8ALPHA *( "-" 1*8ALPHA ) ) | "*" )
if ( preg_match('/^(?:([a-zA-Z]{1,8})(?:-[a-zA-Z]{1,8})*|\*)$/',
@@ -357,12 +357,13 @@ public static function init_gettext($domain = 'messages') {
}
public static function set_recipient_language($accountid) {
+ global $db_conn;
//returns the language of a recipient to make sure that the language is correct
//use together with
$query = "select `language` from `users` where `id`='".intval($accountid)."'";
- $res = mysql_query($query);
- if (mysql_num_rows($res)>=0) {
- $row = mysql_fetch_assoc($res);
+ $res = $db_conn->query($query);
+ if ($res->num_rows>=0) {
+ $row = $res->fetch_assoc();
if (NULL==$row['language'] || $row['language']=='') {
self::set_translation('en');
} else {
diff --git a/includes/loggedin.php b/includes/loggedin.php
index c14f8c2f..b537b6fa 100644
--- a/includes/loggedin.php
+++ b/includes/loggedin.php
@@ -1,6 +1,6 @@
/*
LibreSSL - CAcert web application
- Copyright (C) 2004-2008 CAcert Inc.
+ Copyright (C) 2004-2020 CAcert Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -44,7 +44,7 @@
//session_unregister($key);
}
- $_SESSION['profile'] = mysql_fetch_assoc(mysql_query("select * from `users` where `id`='".intval($uid)."'"));
+ $_SESSION['profile'] = $db_conn->query("select * from `users` where `id`='".intval($uid)."'")->fetch_assoc();
if($_SESSION['profile']['locked'] == 0)
$_SESSION['profile']['loggedin'] = 1;
else
@@ -70,8 +70,8 @@
//session_unregister($key);
}
- $_SESSION['profile'] = mysql_fetch_assoc(mysql_query(
- "select * from `users` where `id`='".intval($user_id)."'"));
+ $_SESSION['profile'] = $db_conn->query(
+ "select * from `users` where `id`='".intval($user_id)."'")->fetch_assoc();
if($_SESSION['profile']['locked'] == 0)
$_SESSION['profile']['loggedin'] = 1;
else
@@ -103,15 +103,15 @@
if($_SERVER['HTTP_HOST'] == $_SESSION['_config']['securehostname'] && $_SESSION['profile']['id'] > 0 && $_SESSION['profile']['loggedin'] > 0)
{
$query = "select sum(`points`) as `total` from `notary` where `to`='".intval($_SESSION['profile']['id'])."' and `deleted` = 0 group by `to`";
- $res = mysql_query($query);
- $row = mysql_fetch_assoc($res);
+ $res = $db_conn->query($query);
+ $row = $res->fetch_assoc();
$_SESSION['profile']['points'] = $row['total'];
if($_SESSION['profile']['language'] == "")
{
$query = "update `users` set `language`='".L10n::get_translation()."'
where `id`='".intval($_SESSION['profile']['id'])."'";
- mysql_query($query);
+ $db_conn->query($query);
} else {
L10n::set_translation($_SESSION['profile']['language']);
L10n::init_gettext();
diff --git a/includes/mysql.php b/includes/mysql.php
new file mode 100644
index 00000000..4e2ed8c5
--- /dev/null
+++ b/includes/mysql.php
@@ -0,0 +1,168 @@
+ sprintf("http://%s", $insecure_host), "normal" => sprintf("https://%s", $default_host),
+ "secure" => sprintf("https://%s", $secure_host), "tverify" => sprintf("https://%s", $tverify_host)];
+
+// TODO: replace with $base_urls
+$_SESSION['_config']['normalhostname'] = $default_host;
+$_SESSION['_config']['securehostname'] = $secure_host;
+$_SESSION['_config']['tverify'] = $tverify_host;
+
+function sendmail($to, $subject, $message, $from, $replyto = "", $toname = "", $fromname = "", $errorsto = "",
+ $use_utf8 = true) {
+ if (!$errorsto) {
+ $errorsto = getenv("RETURN_ADDRESS");
+ }
+ $lines = explode("\n", $message);
+ $message = "";
+ foreach ($lines as $line) {
+ $line = trim($line);
+ if ($line == ".") {
+ $message .= " .\n";
+ } else {
+ $message .= $line . "\n";
+ }
+ }
+
+ if ($fromname == "") {
+ $fromname = $from;
+ }
+
+ $bits = explode(",", $from);
+ $from = addslashes($bits['0']);
+ $fromname = addslashes($fromname);
+
+ $deployment_name = getenv("DEPLOYMENT_NAME");
+ if (!$deployment_name) {
+ $deployment_name = "CAcert.org Website";
+ }
+
+ $smtp_host = getenv("SMTP_HOST");
+ $smtp_port = getenv("SMTP_PORT");
+ if (!$smtp_port) {
+ $smtp_port = 25;
+ } else {
+ $smtp_port = intval($smtp_port);
+ }
+
+ $smtp = fsockopen($smtp_host, $smtp_port);
+ if (!$smtp) {
+ printf("Could not connect to mail server at %s:%d\n", $smtp_host, $smtp_port);
+ return;
+ }
+ $InputBuffer = fgets($smtp, 1024);
+ fputs($smtp, "EHLO test.cacert.localhost\r\n");
+ $InputBuffer = fgets($smtp, 1024);
+ fputs($smtp, "MAIL FROM:\r\n");
+ $InputBuffer = fgets($smtp, 1024);
+ $bits = explode(",", $to);
+ foreach ($bits as $user) {
+ fputs($smtp, "RCPT TO:<" . trim($user) . ">\r\n");
+ }
+ $InputBuffer = fgets($smtp, 1024);
+ fputs($smtp, "DATA\r\n");
+ $InputBuffer = fgets($smtp, 1024);
+ fputs($smtp, sprintf("X-Mailer: %s\r\n", $deployment_name));
+ if (array_key_exists("REMOTE_ADDR", $_SERVER)) {
+ fputs($smtp, "X-OriginatingIP: " . $_SERVER["REMOTE_ADDR"] . "\r\n");
+ }
+ fputs($smtp, "Sender: $errorsto\r\n");
+ fputs($smtp, "Errors-To: $errorsto\r\n");
+ if ($replyto != "") {
+ fputs($smtp, "Reply-To: $replyto\r\n");
+ } else {
+ fputs($smtp, "Reply-To: $from\r\n");
+ }
+ fputs($smtp, "From: $fromname <$from>\r\n");
+ fputs($smtp, "To: $toname <$to>\r\n");
+ if (preg_match("/[^a-zA-Z0-9 .k\-\[\]!_@]/", $subject)) {
+ fputs($smtp, "Subject: =?utf-8?B?" . base64_encode(recode_string("html..utf-8", $subject)) . "?=\r\n");
+ } else {
+ fputs($smtp, "Subject: $subject\r\n");
+ }
+ fputs($smtp, "MIME-Version: 1.0\r\n");
+ if ($use_utf8) {
+ fputs($smtp, "Content-Type: text/plain; charset=\"utf-8\"\r\n");
+ } else {
+ fputs($smtp, "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n");
+ }
+ fputs($smtp, "Content-Transfer-Encoding: quoted-printable\r\n");
+ fputs($smtp, "Content-Disposition: inline\r\n");
+
+ // fputs($smtp, "Content-Transfer-Encoding: BASE64\r\n");
+ fputs($smtp, "\r\n");
+ // fputs($smtp, chunk_split(base64_encode(recode("html..utf-8", $message)))."\r\n.\r\n");
+ $encoded_lines = explode("\n", str_replace("\r", "", $message));
+ array_walk($encoded_lines, function (&$a) {
+ $a = quoted_printable_encode(recode_string("html..utf-8", $a));
+ });
+ $encoded_message = implode("\n", $encoded_lines);
+
+ $encoded_message = str_replace("\r.", "\r=2E", $encoded_message);
+ $encoded_message = str_replace("\n.", "\n=2E", $encoded_message);
+ fputs($smtp, $encoded_message);
+ fputs($smtp, "\r\n.\r\n");
+ fputs($smtp, "QUIT\n");
+ $InputBuffer = fgets($smtp, 1024);
+ fclose($smtp);
+}
+
+function build_verify_url($params) {
+ global $base_urls;
+ $url_params = [];
+ foreach ($params as $key => $value) {
+ $url_params[] = sprintf("%s=%s", $key, urlencode($value));
+ }
+ return sprintf("%s/verify.php?%s", $base_urls["normal"], implode("&", $url_params));
+}
+
+function build_resource_url($path) {
+ return sprintf("%s://%s%s", $_SERVER["REQUEST_SCHEME"], $_SERVER["HTTP_HOST"], $path);
+}
\ No newline at end of file
diff --git a/includes/mysql.php.sample b/includes/mysql.php.sample
deleted file mode 100644
index 77be95f9..00000000
--- a/includes/mysql.php.sample
+++ /dev/null
@@ -1,116 +0,0 @@
- /*
- LibreSSL - CAcert web application
- Copyright (C) 2004-2008 CAcert Inc.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; version 2 of the License.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-*/
-
- $_SESSION['mconn'] = mysql_connect("127.0.0.1", "username", "password");
- if ($_SESSION['mconn'] != FALSE)
- {
- mysql_select_db("database");
- $_SESSION['mconn'] = TRUE;
- }
- $_SESSION['_config']['normalhostname'] = "www.cacert.org";
- $_SESSION['_config']['securehostname'] = "secure.cacert.org";
- $_SESSION['_config']['tverify'] = "tverify.cacert.org";
-
- function sendmail($to, $subject, $message, $from, $replyto = "", $toname = "", $fromname = "", $errorsto = "returns@cacert.org", $use_utf8 = true)
- {
- $lines = explode("\n", $message);
- $message = "";
- foreach($lines as $line)
- {
- $line = trim($line);
- if($line == ".")
- $message .= " .\n";
- else
- $message .= $line."\n";
- }
-
- if($fromname == "")
- $fromname = $from;
-
- $bits = explode(",", $from);
- $from = addslashes($bits['0']);
- $fromname = addslashes($fromname);
-
- $smtp = fsockopen("localhost", 25);
- if(!$smtp)
- {
- echo("Could not connect to mailserver at localhost:25\n");
- return;
- }
- $InputBuffer = fgets($smtp, 1024);
- fputs($smtp, "HELO www.cacert.org\r\n");
- $InputBuffer = fgets($smtp, 1024);
- fputs($smtp, "MAIL FROM:\r\n");
- $InputBuffer = fgets($smtp, 1024);
- $bits = explode(",", $to);
- foreach($bits as $user)
- fputs($smtp, "RCPT TO:<".trim($user).">\r\n");
- $InputBuffer = fgets($smtp, 1024);
- fputs($smtp, "DATA\r\n");
- $InputBuffer = fgets($smtp, 1024);
- fputs($smtp, "X-Mailer: CAcert.org Website\r\n");
- if (array_key_exists("REMOTE_ADDR", $_SERVER))
- fputs($smtp, "X-OriginatingIP: ".$_SERVER["REMOTE_ADDR"]."\r\n");
- fputs($smtp, "Sender: $errorsto\r\n");
- fputs($smtp, "Errors-To: $errorsto\r\n");
- if($replyto != "")
- fputs($smtp, "Reply-To: $replyto\r\n");
- else
- fputs($smtp, "Reply-To: $from\r\n");
- fputs($smtp, "From: $from\r\n");
- fputs($smtp, "To: $to\r\n");
- if(preg_match("/[^a-zA-Z0-9 .-\[\]!_@]/",$subject))
- {
- fputs($smtp, "Subject: =?utf-8?B?".base64_encode(recode("html..utf-8", $subject))."?=\r\n");
- }
- else
- {
- fputs($smtp, "Subject: $subject\r\n");
- }
- fputs($smtp, "Mime-Version: 1.0\r\n");
- if($use_utf8)
- {
- fputs($smtp, "Content-Type: text/plain; charset=\"utf-8\"\r\n");
- }
- else
- {
- fputs($smtp, "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n");
- }
- fputs($smtp, "Content-Transfer-Encoding: quoted-printable\r\n");
- fputs($smtp, "Content-Disposition: inline\r\n");
-
-// fputs($smtp, "Content-Transfer-Encoding: BASE64\r\n");
- fputs($smtp, "\r\n");
-// fputs($smtp, chunk_split(base64_encode(recode("html..utf-8", $message)))."\r\n.\r\n");
- $encoded_lines = explode( "\n", str_replace("\r", "", $message) );
- array_walk( $encoded_lines,
- function (&$a) {
- $a = quoted_printable_encode(recode("html..utf-8", $a));
- });
- $encoded_message = implode("\n", $encoded_lines);
-
- $encoded_message = str_replace("\r.", "\r=2E", $encoded_message);
- $encoded_message = str_replace("\n.", "\n=2E", $encoded_message);
- fputs($smtp, $encoded_message);
- fputs($smtp, "\r\n.\r\n");
- fputs($smtp, "QUIT\n");
- $InputBuffer = fgets($smtp, 1024);
- fclose($smtp);
- }
-
-?>
diff --git a/includes/notary.inc.php b/includes/notary.inc.php
index 3b8e736d..7101843b 100644
--- a/includes/notary.inc.php
+++ b/includes/notary.inc.php
@@ -1,6 +1,6 @@
/*
LibreSSL - CAcert web application
- Copyright (C) 2004-2011 CAcert Inc.
+ Copyright (C) 2004-2020 CAcert Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -21,18 +21,18 @@
function query_init ($query)
{
- return mysql_query($query);
+ global $db_conn;
+ return $db_conn->query($query);
}
function query_getnextrow ($res)
{
- $row1 = mysql_fetch_assoc($res);
- return $row1;
+ return $res->fetch_assoc();
}
function query_get_number_of_rows ($resultset)
{
- return intval(mysql_num_rows($resultset));
+ return intval($resultset->num_rows);
}
function get_number_of_assurances ($userid)
@@ -125,7 +125,7 @@ function get_received_assurances_summary ($userid)
function get_user ($userid)
{
$res = query_init ("select * from `users` where `id`='".intval($userid)."'");
- return mysql_fetch_assoc($res);
+ return $res->fetch_assoc();
}
function get_cats_state ($userid)
@@ -133,7 +133,7 @@ function get_cats_state ($userid)
$res = query_init ("select * from `cats_passed` inner join `cats_variant` on `cats_passed`.`variant_id` = `cats_variant`.`id` and `cats_variant`.`type_id` = 1
WHERE `cats_passed`.`user_id` = '".intval($userid)."'");
- return mysql_num_rows($res);
+ return $res->num_rows;
}
@@ -587,7 +587,7 @@ function output_given_assurances_content(
$sum_points = 0;
$sumexperience = 0;
$res = get_given_assurances(intval($userid), $log);
- while($row = mysql_fetch_assoc($res))
+ while($row = $res->fetch_assoc())
{
$assuree = get_user(intval($row['to']));
calc_experience($row, $sum_points, $sum_experience);
@@ -617,7 +617,7 @@ function output_received_assurances_content(
$sum_points = 0;
$sumexperience = 0;
$res = get_received_assurances(intval($userid), $log);
- while($row = mysql_fetch_assoc($res))
+ while($row = $res->fetch_assoc())
{
$fromuser = get_user(intval($row['from']));
calc_assurances($row, $sum_points, $sum_experience);
@@ -661,7 +661,7 @@ function output_summary_content($userid,$display_output)
}
$res = get_received_assurances_summary($userid);
- while($row = mysql_fetch_assoc($res))
+ while($row = $res->fetch_assoc())
{
$points = calc_awarded($row);
@@ -674,7 +674,7 @@ function output_summary_content($userid,$display_output)
}
$res = get_given_assurances_summary($userid);
- while($row = mysql_fetch_assoc($res))
+ while($row = $res->fetch_assoc())
{
switch ($row['method'])
{
@@ -855,13 +855,13 @@ function output_end_of_page()
* @param mixed $comment
* @param integer $active
* @param integer $secmemid
- * @return
*/
function write_user_agreement($memid, $document, $method, $comment, $active=1, $secmemid=0){
+ global $db_conn;
// write a new record to the table user_agreement
$query="insert into `user_agreements` set `memid`=".intval($memid).", `secmemid`=".intval($secmemid).
- ",`document`='".mysql_real_escape_string($document)."',`date`=NOW(), `active`=".intval($active).",`method`='".mysql_real_escape_string($method)."',`comment`='".mysql_real_escape_string($comment)."'" ;
- $res = mysql_query($query);
+ ",`document`='".$db_conn->real_escape_string($document)."',`date`=NOW(), `active`=".intval($active).",`method`='".$db_conn->real_escape_string($method)."',`comment`='".$db_conn->real_escape_string($comment)."'" ;
+ $db_conn->query($query);
}
/**
@@ -869,13 +869,13 @@ function write_user_agreement($memid, $document, $method, $comment, $active=1, $
* returns 1 if the user has an entry for the given type in user_agreement, 0 if no entry is recorded
* @param mixed $memid
* @param string $type
- * @return
*/
function get_user_agreement_status($memid, $type="CCA"){
+ global $db_conn;
$query="SELECT u.`document` FROM `user_agreements` u
- WHERE u.`document` = '" . mysql_real_escape_string($type) . "' AND u.`memid`=" . intval($memid) ;
- $res = mysql_query($query);
- if(mysql_num_rows($res) <=0){
+ WHERE u.`document` = '" . $db_conn->real_escape_string($type) . "' AND u.`memid`=" . intval($memid) ;
+ $res = $db_conn->query($query);
+ if($res->num_rows <=0){
return 0;
}else{
return 1;
@@ -895,9 +895,10 @@ function get_user_agreement_status($memid, $type="CCA"){
* 'document', 'date', 'method', 'comment', 'active'
*/
function get_first_user_agreement($memid, $type=null, $active=null){
+ global $db_conn;
$filter = '';
if (!is_null($type)) {
- $filter .= " AND u.`document` = '".mysql_real_escape_string($type)."'";
+ $filter .= " AND u.`document` = '".$db_conn->real_escape_string($type)."'";
}
if (!is_null($active)) {
@@ -908,9 +909,9 @@ function get_first_user_agreement($memid, $type=null, $active=null){
WHERE u.`memid`=".intval($memid)."
$filter
ORDER BY u.`date` LIMIT 1";
- $res = mysql_query($query);
- if(mysql_num_rows($res) >0){
- $rec = mysql_fetch_assoc($res);
+ $res = $db_conn->query($query);
+ if($res->num_rows >0){
+ $rec = $res->fetch_assoc();
}else{
$rec=array();
}
@@ -930,9 +931,10 @@ function get_first_user_agreement($memid, $type=null, $active=null){
* 'document', 'date', 'method', 'comment', 'active'
*/
function get_last_user_agreement($memid, $type=null, $active=null){
+ global $db_conn;
$filter = '';
if (!is_null($type)) {
- $filter .= " AND u.`document` = '".mysql_real_escape_string($type)."'";
+ $filter .= " AND u.`document` = '".$db_conn->real_escape_string($type)."'";
}
if (!is_null($active)) {
@@ -943,9 +945,9 @@ function get_last_user_agreement($memid, $type=null, $active=null){
WHERE u.`memid`=".intval($memid)."
$filter
ORDER BY u.`date` DESC LIMIT 1";
- $res = mysql_query($query);
- if(mysql_num_rows($res) >0){
- $rec = mysql_fetch_assoc($res);
+ $res = $db_conn->query($query);
+ if($res->num_rows >0){
+ $rec = $res->fetch_assoc();
}else{
$rec=array();
}
@@ -964,9 +966,10 @@ function get_last_user_agreement($memid, $type=null, $active=null){
* @return resource - a mysql result set containing all agreements
*/
function get_user_agreements($memid, $type=null, $active=null){
+ global $db_conn;
$filter = '';
if (!is_null($type)) {
- $filter .= " AND u.`document` = '".mysql_real_escape_string($type)."'";
+ $filter .= " AND u.`document` = '".$db_conn->real_escape_string($type)."'";
}
if (!is_null($active)) {
@@ -977,7 +980,7 @@ function get_user_agreements($memid, $type=null, $active=null){
WHERE u.`memid`=".intval($memid)."
$filter
ORDER BY u.`date`";
- return mysql_query($query);
+ return $db_conn->query($query);
}
/**
@@ -985,15 +988,15 @@ function get_user_agreements($memid, $type=null, $active=null){
* deletes all entries for a given type from user_agreement of a given user, if type is not given all
* @param mixed $memid
* @param string $type
- * @return
*/
function delete_user_agreement($memid, $type=false){
+ global $db_conn;
if ($type === false) {
$filter = '';
} else {
- $filter = " and `document` = '" . mysql_real_escape_string($type) . "'";
+ $filter = " and `document` = '" . $db_conn->real_escape_string($type) . "'";
}
- mysql_query("delete from `user_agreements` where `memid`=" . intval($memid) . $filter );
+ $db_conn->query("delete from `user_agreements` where `memid`=" . intval($memid) . $filter );
}
// functions for 6.php (assure somebody)
@@ -1087,6 +1090,7 @@ function AssureFoot($oldid,$confirm)
}
function account_email_delete($mailid){
+ global $db_conn;
//deletes an email entry from an acount
//revolkes all certifcates for that email address
//called from www/account.php if($process != "" && $oldid == 2)
@@ -1095,10 +1099,11 @@ function account_email_delete($mailid){
$mailid = intval($mailid);
revoke_all_client_cert($mailid);
$query = "update `email` set `deleted`=NOW() where `id`='$mailid'";
- mysql_query($query);
+ $db_conn->query($query);
}
function account_domain_delete($domainid){
+ global $db_conn;
//deletes an domain entry from an acount
//revolkes all certifcates for that domain address
//called from www/account.php if($process != "" && $oldid == 9)
@@ -1106,18 +1111,19 @@ function account_domain_delete($domainid){
//called from account_delete
$domainid = intval($domainid);
revoke_all_server_cert($domainid);
- mysql_query(
+ $db_conn->query(
"update `domains`
set `deleted`=NOW()
where `id` = '$domainid'");
}
function account_delete($id, $arbno, $adminid){
+ global $db_conn;
//deletes an account following the deleted account routnie V3
// called from www/account.php if($oldid == 50 && $process != "")
//change password
$id = intval($id);
- $arbno = mysql_real_escape_string($arbno);
+ $arbno = $db_conn->real_escape_string($arbno);
$adminid = intval($adminid);
$pool = 'abcdefghijklmnopqrstuvwxyz';
$pool .= '0123456789!()§';
@@ -1128,33 +1134,33 @@ function account_delete($id, $arbno, $adminid){
{
$password .= substr($pool,(rand()%(strlen ($pool))), 1);
}
- mysql_query("update `users` set `password`=sha1('".$password."') where `id`='".$id."'");
+ $db_conn->query("update `users` set `password`=sha1('".$password."') where `id`='".$id."'");
//create new mail for arbitration number
$query = "insert into `email` set `email`='".$arbno."@cacert.org',`memid`='".$id."',`created`=NOW(),`modified`=NOW(), `attempts`=-1";
- mysql_query($query);
- $emailid = mysql_insert_id();
+ $db_conn->query($query);
+ $emailid = $db_conn->insert_id;
//set new mail as default
$query = "update `users` set `email`='".$arbno."@cacert.org' where `id`='".$id."'";
- mysql_query($query);
+ $db_conn->query($query);
//delete all other email address
$query = "select `id` from `email` where `memid`='".$id."' and `id`!='".$emailid."'" ;
- $res=mysql_query($query);
- while($row = mysql_fetch_assoc($res)){
+ $res=$db_conn->query($query);
+ while($row = $res->fetch_assoc()){
account_email_delete($row['id']);
}
//delete all domains
$query = "select `id` from `domains` where `memid`='".$id."'";
- $res=mysql_query($query);
- while($row = mysql_fetch_assoc($res)){
+ $res=$db_conn->query($query);
+ while($row = $res->fetch_assoc()){
account_domain_delete($row['id']);
}
//clear alert settings
- mysql_query(
+ $db_conn->query(
"update `alerts` set
`general`='0',
`country`='0',
@@ -1164,17 +1170,17 @@ function account_delete($id, $arbno, $adminid){
//set default location
$query = "update `users` set `locid`='2256755', `regid`='243', `ccid`='12' where `id`='".$id."'";
- mysql_query($query);
+ $db_conn->query($query);
//clear listings
$query = "update `users` set `listme`=' ',`contactinfo`=' ' where `id`='".$id."'";
- mysql_query($query);
+ $db_conn->query($query);
//set lanuage to default
//set default language
- mysql_query("update `users` set `language`='en_AU' where `id`='".$id."'");
+ $db_conn->query("update `users` set `language`='en_AU' where `id`='".$id."'");
//delete secondary langugaes
- mysql_query("delete from `addlang` where `userid`='".$id."'");
+ $db_conn->query("delete from `addlang` where `userid`='".$id."'");
//change secret questions
for($i=1;$i<=5;$i++){
@@ -1186,7 +1192,7 @@ function account_delete($id, $arbno, $adminid){
$a .= substr($pool,(rand()%(strlen ($pool))), 1);
}
$query = "update `users` set `Q$i`='$q', `A$i`='$a' where `id`='".$id."'";
- mysql_query($query);
+ $db_conn->query($query);
}
//change personal information to arbitration number and DOB=1900-01-01
@@ -1196,10 +1202,10 @@ function account_delete($id, $arbno, $adminid){
`suffix`='".$arbno."',
`dob`='1900-01-01'
where `id`='".$id."'";
- mysql_query($query);
+ $db_conn->query($query);
//clear all admin and board flags
- mysql_query(
+ $db_conn->query(
"update `users` set
`assurer`='0',
`assurer_blocked`='0',
@@ -1214,20 +1220,22 @@ function account_delete($id, $arbno, $adminid){
where `id`='$id'");
//block account
- mysql_query("update `users` set `locked`='1' where `id`='$id'"); //, `deleted`=Now()
+ $db_conn->query("update `users` set `locked`='1' where `id`='$id'"); //, `deleted`=Now()
}
function check_email_exists($email){
+ global $db_conn;
// called from includes/account.php if($process != "" && $oldid == 1)
// called from includes/account.php if($oldid == 50 && $process != "")
- $email = mysql_real_escape_string($email);
+ $email = $db_conn->real_escape_string($email);
$query = "select 1 from `email` where `email`='$email' and `deleted`=0";
- $res = mysql_query($query);
- return mysql_num_rows($res) > 0;
+ $res = $db_conn->query($query);
+ return $res->num_rows > 0;
}
function check_gpg_cert_running($uid,$cca=0){
+ global $db_conn;
//if $cca =0 if just expired, =1 if CCA retention +3 month should be obeyed
// called from includes/account.php if($oldid == 50 && $process != "")
$uid = intval($uid);
@@ -1236,11 +1244,12 @@ function check_gpg_cert_running($uid,$cca=0){
}else{
$query = "select 1 from `gpg` where `memid`='$uid' and `expire`>(NOW()-90*86400)";
}
- $res = mysql_query($query);
- return mysql_num_rows($res) > 0;
+ $res = $db_conn->query($query);
+ return $res->num_rows() > 0;
}
function check_client_cert_running($uid,$cca=0){
+ global $db_conn;
//if $cca =0 if just expired, =1 if CCA retention +3 month should be obeyed
// called from includes/account.php if($oldid == 50 && $process != "")
$uid = intval($uid);
@@ -1251,15 +1260,16 @@ function check_client_cert_running($uid,$cca=0){
$query1 = "select 1 from `emailcerts` where `memid`='$uid' and `expire`>(NOW()-90*86400) and `revoked`<`created`";
$query2 = "select 1 from `emailcerts` where `memid`='$uid' and `revoked`>(NOW()-90*86400)";
}
- $res = mysql_query($query1);
- $r1 = mysql_num_rows($res)>0;
- $res = mysql_query($query2);
- $r2 = mysql_num_rows($res)>0;
+ $res = $db_conn->query($query1);
+ $r1 = $res->num_rows>0;
+ $res = $db_conn->query($query2);
+ $r2 = $res->num_rows>0;
return !!($r1 || $r2);
}
function check_server_cert_running($uid,$cca=0){
- //if $cca =0 if just expired, =1 if CCA retention +3 month should be obeyed
+ global $db_conn;
+ //if $cca =0 if just expired, =1 if CCA retention +3 month should be obeyed
// called from includes/account.php if($oldid == 50 && $process != "")
$uid = intval($uid);
if (0==$cca) {
@@ -1287,37 +1297,40 @@ function check_server_cert_running($uid,$cca=0){
where `domains`.`memid` = '$uid'
and `revoked`>(NOW()-90*86400)";
}
- $res = mysql_query($query1);
- $r1 = mysql_num_rows($res)>0;
- $res = mysql_query($query2);
- $r2 = mysql_num_rows($res)>0;
+ $res = $db_conn->query($query1);
+ $r1 = $res->num_rows>0;
+ $res = $db_conn->query($query2);
+ $r2 = $res->num_rows>0;
return !!($r1 || $r2);
}
function check_is_orgadmin($uid){
- // called from includes/account.php if($oldid == 50 && $process != "")
+ global $db_conn;
+ // called from includes/account.php if($oldid == 50 && $process != "")
$uid = intval($uid);
$query = "select 1 from `org` where `memid`='$uid' and `deleted`=0";
- $res = mysql_query($query);
- return mysql_num_rows($res) > 0;
+ $res = $db_conn->query($query);
+ return $res->num_rows > 0;
}
// revokation of certificates
function revoke_all_client_cert($mailid){
+ global $db_conn;
//revokes all client certificates for an email address
$mailid = intval($mailid);
$query = "select `emailcerts`.`id`
from `emaillink`,`emailcerts` where
`emaillink`.`emailid`='$mailid' and `emaillink`.`emailcertsid`=`emailcerts`.`id` and `emailcerts`.`revoked`=0
group by `emailcerts`.`id`";
- $dres = mysql_query($query);
- while($drow = mysql_fetch_assoc($dres)){
- mysql_query("update `emailcerts` set `revoked`='1970-01-01 10:00:01', `disablelogin`=1 where `id`='".$drow['id']."'");
+ $dres = $db_conn->query($query);
+ while($drow = $dres->fetch_assoc()){
+ $db_conn->query("update `emailcerts` set `revoked`='1970-01-01 10:00:01', `disablelogin`=1 where `id`='".$drow['id']."'");
}
}
- function revoke_all_server_cert($domainid){
+ function revoke_all_server_cert($domainid) {
+ global $db_conn;
//revokes all server certs for an domain
$domainid = intval($domainid);
$query =
@@ -1329,10 +1342,10 @@ function revoke_all_server_cert($domainid){
from `domaincerts`, `domlink`
where `domaincerts`.`id` = `domlink`.`certid`
and `domlink`.`domid` = '$domainid'";
- $dres = mysql_query($query);
- while($drow = mysql_fetch_assoc($dres))
+ $dres = $db_conn->query($query);
+ while($drow = $dres->fetch_assoc())
{
- mysql_query(
+ $db_conn->query(
"update `domaincerts`
set `revoked`='1970-01-01 10:00:01'
where `id` = '".$drow['id']."'
@@ -1341,19 +1354,20 @@ function revoke_all_server_cert($domainid){
}
function revoke_all_private_cert($uid){
+ global $db_conn;
//revokes all certificates linked to a personal accounts
//gpg revokation needs to be added to a later point
$uid=intval($uid);
$query = "select `id` from `email` where `memid`='".$uid."'";
- $res=mysql_query($query);
- while($row = mysql_fetch_assoc($res)){
+ $res=$db_conn->query($query);
+ while($row = $res->fetch_assoc()){
revoke_all_client_cert($row['id']);
}
$query = "select `id` from `domains` where `memid`='".$uid."'";
- $res=mysql_query($query);
- while($row = mysql_fetch_assoc($res)){
+ $res=$db_conn->query($query);
+ while($row = $res->fetch_assoc()){
revoke_all_server_cert($row['id']);
}
}
@@ -1412,14 +1426,15 @@ function check_date_difference($date, $diff=1){
* @return bool - true := success, false := error
*/
function write_se_log($uid, $adminid, $type, $info){
+ global $db_conn;
//records all support engineer actions changing a user account
$uid = intval($uid);
$adminid = intval($adminid);
- $type = mysql_real_escape_string($type);
- $info = mysql_real_escape_string($info);
+ $type = $db_conn->real_escape_string($type);
+ $info = $db_conn->real_escape_string($info);
$query="insert into `adminlog` (`when`, `uid`, `adminid`,`type`,`information`) values
(Now(), $uid, $adminid, '$type', '$info')";
- return mysql_query($query);
+ return $db_conn->query($query);
}
/**
@@ -1447,13 +1462,14 @@ function valid_ticket_number($ticketno){
* @return resource - a mysql result set
*/
function get_user_data($userid, $deleted=0){
+ global $db_conn;
$userid = intval($userid);
$filter='';
if (0==$deleted) {
$filter .=' and `users`.`deleted`=0';
}
$query = "select * from `users` where `users`.`id`='$userid' ".$filter;
- return mysql_query($query);
+ return $db_conn->query($query);
}
/**
@@ -1462,7 +1478,8 @@ function get_user_data($userid, $deleted=0){
* @return array - associative array
*/
function get_alerts($userid){
- return mysql_fetch_assoc(mysql_query("select * from `alerts` where `memid`='".intval($userid)."'"));
+ global $db_conn;
+ return $db_conn->query("select * from `alerts` where `memid`='".intval($userid)."'")->fetch_assoc();
}
/**
@@ -1473,6 +1490,7 @@ function get_alerts($userid){
* @return resource - a mysql result set
*/
function get_email_addresses($userid, $exclude, $deleted=0){
+ global $db_conn;
//should be entered in account/2.php
$userid = intval($userid);
$filter='';
@@ -1480,10 +1498,10 @@ function get_email_addresses($userid, $exclude, $deleted=0){
$filter .= ' and `deleted`=0';
}
if ($exclude) {
- $filter .= " and `email`!='".mysql_real_escape_string($exclude)."'";
+ $filter .= " and `email`!='".$db_conn->real_escape_string($exclude)."'";
}
$query = "select * from `email` where `memid`='".$userid."' and `hash`='' ".$filter." order by `created`";
- return mysql_query($query);
+ return $db_conn->query($query);
}
/**
@@ -1493,6 +1511,7 @@ function get_email_addresses($userid, $exclude, $deleted=0){
* @return resource - a mysql result set
*/
function get_domains($userid, $deleted=0){
+ global $db_conn;
//should be entered in account/9.php
$userid = intval($userid);
$filter='';
@@ -1500,7 +1519,7 @@ function get_domains($userid, $deleted=0){
$filter .= ' and `deleted`=0';
}
$query = "select * from `domains` where `memid`='".$userid."' and `hash`=''".$filter." order by `created`";
- return mysql_query($query);
+ return $db_conn->query($query);
}
/**
@@ -1509,13 +1528,14 @@ function get_domains($userid, $deleted=0){
* @return resource - a mysql result set
*/
function get_training_results($userid){
+ global $db_conn;
//should be entered in account/55.php
$userid = intval($userid);
$query = "SELECT `CP`.`pass_date`, `CT`.`type_text`, `CV`.`test_text` ".
" FROM `cats_passed` AS CP, `cats_variant` AS CV, `cats_type` AS CT ".
" WHERE `CP`.`variant_id`=`CV`.`id` AND `CV`.`type_id`=`CT`.`id` AND `CP`.`user_id` ='".$userid."'".
" ORDER BY `CP`.`pass_date`";
- return mysql_query($query);
+ return $db_conn->query($query);
}
/**
@@ -1524,12 +1544,13 @@ function get_training_results($userid){
* @return resource - a mysql result set
*/
function get_se_log($userid){
+ global $db_conn;
$userid = intval($userid);
$query = "SELECT `adminlog`.`when`, `adminlog`.`type`, `adminlog`.`information`, `users`.`fname`, `users`.`lname`
FROM `adminlog`, `users`
WHERE `adminlog`.`adminid` = `users`.`id` and `adminlog`.`uid`=".$userid."
ORDER BY `adminlog`.`when`";
- return mysql_query($query);
+ return $db_conn->query($query);
}
/**
@@ -1539,6 +1560,7 @@ function get_se_log($userid){
* @return resource - a mysql result set
*/
function get_client_certs($userid, $viewall=0){
+ global $db_conn;
//add to account/5.php
$userid = intval($userid);
$query = "select UNIX_TIMESTAMP(`emailcerts`.`created`) as `created`,
@@ -1560,7 +1582,7 @@ function get_client_certs($userid, $viewall=0){
$query .= " HAVING `timeleft` > 0";
}
$query .= " ORDER BY `emailcerts`.`modified` desc";
- return mysql_query($query);
+ return $db_conn->query($query);
}
/**
@@ -1570,6 +1592,7 @@ function get_client_certs($userid, $viewall=0){
* @return resource - a mysql result set
*/
function get_server_certs($userid, $viewall=0){
+ global $db_conn;
//add to account/12.php
$userid = intval($userid);
$query = "select UNIX_TIMESTAMP(`domaincerts`.`created`) as `created`,
@@ -1590,7 +1613,7 @@ function get_server_certs($userid, $viewall=0){
$query .= " HAVING `timeleft` > 0";
}
$query .= " ORDER BY `domaincerts`.`modified` desc";
- return mysql_query($query);
+ return $db_conn->query($query);
}
/**
@@ -1600,6 +1623,7 @@ function get_server_certs($userid, $viewall=0){
* @return resource - a mysql result set
*/
function get_gpg_certs($userid, $viewall=0){
+ global $db_conn;
//add to gpg/2.php
$userid = intval($userid);
$query = $query = "select UNIX_TIMESTAMP(`issued`) as `issued`,
@@ -1611,7 +1635,7 @@ function get_gpg_certs($userid, $viewall=0){
$query .= " HAVING `timeleft` > 0";
}
$query .= " ORDER BY `issued` desc";
- return mysql_query($query);
+ return $db_conn->query($query);
}
diff --git a/locale/Makefile b/locale/Makefile
index b8317199..97fda2dd 100644
--- a/locale/Makefile
+++ b/locale/Makefile
@@ -8,7 +8,7 @@
################################################################################
DOWNLOAD_SERVER := translations.cacert.org
-PO_URL_TEMPLATE := http://$(DOWNLOAD_SERVER)/export/cacert/%/messages.po
+PO_URL_TEMPLATE := https://$(DOWNLOAD_SERVER)/export/cacert/%/messages.po
# Only use languages that have 10% or more of translated strings
AUTO_LANGS := \
@@ -111,7 +111,7 @@ $(LANGS:%=$(MO_FILE_TEMPLATE)): $(MO_FILE_TEMPLATE): $(PO_FILE_TEMPLATE)
.PHONY: $(LANGS:%=$(PO_FILE_TEMPLATE))
$(LANGS:%=$(PO_FILE_TEMPLATE)):
mkdir -p $(@D)
- wget --output-document - '$(@:$(PO_FILE_TEMPLATE)=$(PO_URL_TEMPLATE))' | \
+ curl --silent --fail '$(@:$(PO_FILE_TEMPLATE)=$(PO_URL_TEMPLATE))' | \
php -f escape_special_chars.php \
> $@
diff --git a/pages/account/12.php b/pages/account/12.php
index f4428aa0..10b3610e 100644
--- a/pages/account/12.php
+++ b/pages/account/12.php
@@ -1,6 +1,6 @@
/*
LibreSSL - CAcert web application
- Copyright (C) 2004-2008 CAcert Inc.
+ Copyright (C) 2004-2020 CAcert Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -49,15 +49,15 @@
}
$query .= "ORDER BY `modified` desc";
//echo $query." \n";
- $res = mysql_query($query);
- if(mysql_num_rows($res) <= 0)
+ $res = $db_conn->query($query);
+ if($res->num_rows <= 0)
{
?>
=_("No certificates are currently listed.")?>
} else {
- while($row = mysql_fetch_assoc($res))
+ while($row = $res->fetch_assoc())
{
if($row['timeleft'] > 0)
$verified = _("Valid");
diff --git a/pages/account/13.php b/pages/account/13.php
index ea28c0ec..dae1d7ba 100644
--- a/pages/account/13.php
+++ b/pages/account/13.php
@@ -1,6 +1,6 @@
/*
LibreSSL - CAcert web application
- Copyright (C) 2004-2008 CAcert Inc.
+ Copyright (C) 2004-2020 CAcert Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -17,8 +17,8 @@
*/ ?>
$query = "select * from `users` where `id`='".intval($_SESSION['profile']['id'])."' and `users`.`deleted`=0";
- $res = mysql_query($query);
- $user = mysql_fetch_assoc($res);
+ $res = $db_conn->query($query);
+ $user = $res->fetch_assoc();
$year = intval(substr($user['dob'], 0, 4));
$month = intval(substr($user['dob'], 5, 2));
diff --git a/pages/account/14.php b/pages/account/14.php
index 29aeb210..7909d7dd 100644
--- a/pages/account/14.php
+++ b/pages/account/14.php
@@ -1,6 +1,6 @@
/*
LibreSSL - CAcert web application
- Copyright (C) 2004-2008 CAcert Inc.
+ Copyright (C) 2004-2020 CAcert Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -16,7 +16,7 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ ?>
- if (intval($_REQUEST['force']) === 1)
+ if (array_key_exists("force", $_REQUEST) && intval($_REQUEST['force']) === 1)
{
?>
diff --git a/pages/account/15.php b/pages/account/15.php
index 405cb449..8d7b6971 100644
--- a/pages/account/15.php
+++ b/pages/account/15.php
@@ -1,6 +1,6 @@
/*
LibreSSL - CAcert web application
- Copyright (C) 2004-2008 CAcert Inc.
+ Copyright (C) 2004-2020 CAcert Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -21,14 +21,14 @@
$query = "select * from `domaincerts`,`domains` where `domaincerts`.`id`='$certid' and
`domains`.`memid`='".intval($_SESSION['profile']['id'])."' and
`domains`.`id`=`domaincerts`.`domid`";
- $res = mysql_query($query);
- if(mysql_num_rows($res) <= 0)
+ $res = $db_conn->query($query);
+ if($res->num_rows <= 0)
{
echo _("No such certificate attached to your account.");
showfooter();
exit;
}
- $row = mysql_fetch_assoc($res);
+ $row = $res->fetch_assoc();
$crtname=escapeshellarg($row['crt_name']);
$cert = shell_exec("/usr/bin/openssl x509 -in $crtname");
?>
diff --git a/pages/account/18.php b/pages/account/18.php
index ca0a3c85..983d3d36 100644
--- a/pages/account/18.php
+++ b/pages/account/18.php
@@ -1,6 +1,6 @@
/*
LibreSSL - CAcert web application
- Copyright (C) 2004-2008 CAcert Inc.
+ Copyright (C) 2004-2020 CAcert Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -37,9 +37,9 @@
from `org`, `orginfo`
where `org`.`memid`='".intval($_SESSION['profile']['id'])."' and `orginfo`.`id` = `org`.`orgid`
ORDER BY `orginfo`.`O` ";
- $reso = mysql_query($query);
- if(mysql_num_rows($reso) >= 1){
- while($row = mysql_fetch_assoc($reso)){
+ $reso = $db_conn->query($query);
+ if($reso->num_rows >= 1){
+ while($row = $reso->fetch_assoc()){
printf('',$row['id'], $row['id'] == $orgfilterid ? " selected" : "" , $row['O']);
}
}?>
@@ -106,8 +106,8 @@
$query .= "ORDER BY `orginfo`.`O`, `oemail`.`CN`, `modified` desc";
break;
}
- $res = mysql_query($query);
- if(mysql_num_rows($res) <= 0)
+ $res = $db_conn->query($query);
+ if($res->num_rows <= 0)
{
?>
@@ -116,7 +116,7 @@
} else {
$orgname='';
- while($row = mysql_fetch_assoc($res))
+ while($row = $res->fetch_assoc())
{
if ($row['O']<>$orgname) {
$orgname=$row['O'];?>
diff --git a/pages/account/19.php b/pages/account/19.php
index d7259f31..8190a882 100644
--- a/pages/account/19.php
+++ b/pages/account/19.php
@@ -1,6 +1,6 @@
/*
LibreSSL - CAcert web application
- Copyright (C) 2004-2008 CAcert Inc.
+ Copyright (C) 2004-2020 CAcert Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -21,15 +21,15 @@
$query = "select * from `orgemailcerts`,`org` where `orgemailcerts`.`id`='".intval($certid)."' and
`org`.`memid`='".intval($_SESSION['profile']['id'])."' and
`org`.`orgid`=`orgemailcerts`.`orgid`";
- $res = mysql_query($query);
- if(mysql_num_rows($res) <= 0)
+ $res = $db_conn->query($query);
+ if($res->num_rows <= 0)
{
showheader(_("My CAcert.org Account!"));
echo _("No such certificate attached to your account.");
showfooter();
exit;
}
- $row = mysql_fetch_assoc($res);
+ $row = $res->fetch_assoc();
$crtname=escapeshellarg($row['crt_name']);
$cert = shell_exec("/usr/bin/openssl x509 -in $crtname");
diff --git a/pages/account/2.php b/pages/account/2.php
index 36421f9b..79f015da 100644
--- a/pages/account/2.php
+++ b/pages/account/2.php
@@ -1,6 +1,6 @@
/*
LibreSSL - CAcert web application
- Copyright (C) 2004-2008 CAcert Inc.
+ Copyright (C) 2004-2020 CAcert Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -28,8 +28,8 @@
$query = "select * from `email` where `memid`='".intval($_SESSION['profile']['id'])."' and `deleted`=0";
- $res = mysql_query($query);
- while($row = mysql_fetch_assoc($res))
+ $res = $db_conn->query($query);
+ while($row = $res->fetch_assoc())
{
if($row['hash'] == "")
$verified = _("Verified");
diff --git a/pages/account/22.php b/pages/account/22.php
index 7b7db2d7..600cc562 100644
--- a/pages/account/22.php
+++ b/pages/account/22.php
@@ -1,6 +1,6 @@
/*
LibreSSL - CAcert web application
- Copyright (C) 2004-2008 CAcert Inc.
+ Copyright (C) 2004-2020 CAcert Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -37,9 +37,9 @@
from `org`, `orginfo`
where `org`.`memid`='".intval($_SESSION['profile']['id'])."' and `orginfo`.`id` = `org`.`orgid`
ORDER BY `orginfo`.`O` ";
- $reso = mysql_query($query);
- if(mysql_num_rows($reso) >= 1){
- while($row = mysql_fetch_assoc($reso)){
+ $reso = $db_conn->query($query);
+ if($reso->num_rows >= 1){
+ while($row = $reso->fetch_assoc()){
printf('',$row['id'], $row['id'] == $orgfilterid ? " selected" : "" , $row['O']);
}
}?>
@@ -109,8 +109,8 @@
//echo $query." \n";
- $res = mysql_query($query);
- if(mysql_num_rows($res) <= 0)
+ $res = $db_conn->query($query);
+ if($res->num_rows <= 0)
{
?>
@@ -118,7 +118,7 @@
} else {
$orgname='';
- while($row = mysql_fetch_assoc($res))
+ while($row = $res->fetch_assoc())
{
if ($row['O']<>$orgname) {
$orgname=$row['O'];?>
diff --git a/pages/account/23.php b/pages/account/23.php
index 4255b470..ab965c6e 100644
--- a/pages/account/23.php
+++ b/pages/account/23.php
@@ -1,6 +1,6 @@
/*
LibreSSL - CAcert web application
- Copyright (C) 2004-2008 CAcert Inc.
+ Copyright (C) 2004-2020 CAcert Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -21,14 +21,14 @@
$query = "select * from `orgdomaincerts`,`org` where `orgdomaincerts`.`id`='$certid' and
`org`.`memid`='".intval($_SESSION['profile']['id'])."' and
`org`.`orgid`=`orgdomaincerts`.`orgid`";
- $res = mysql_query($query);
- if(mysql_num_rows($res) <= 0)
+ $res = $db_conn->query($query);
+ if($res->num_rows <= 0)
{
echo _("No such certificate attached to your account.");
showfooter();
exit;
}
- $row = mysql_fetch_assoc($res);
+ $row = $res->fetch_assoc();
$crtname=escapeshellarg($row['crt_name']);
$cert = shell_exec("/usr/bin/openssl x509 -in $crtname");
?>
diff --git a/pages/account/25.php b/pages/account/25.php
index a70f6080..a11b2100 100644
--- a/pages/account/25.php
+++ b/pages/account/25.php
@@ -1,6 +1,6 @@
/*
LibreSSL - CAcert web application
- Copyright (C) 2004-2008 CAcert Inc.
+ Copyright (C) 2004-2020 CAcert Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -54,13 +54,13 @@
// Safe because $order_by only contains fixed strings
$query = sprintf("select * from `orginfo` ORDER BY %s", $order_by);
- $res = mysql_query($query);
- while($row = mysql_fetch_assoc($res))
+ $res = $db_conn->query($query);
+ while($row = $res->fetch_assoc())
{
- $r2 = mysql_query("select * from `org` where `orgid`='".intval($row['id'])."'");
- $admincount = mysql_num_rows($r2);
- $r2 = mysql_query("select * from `orgdomains` where `orgid`='".intval($row['id'])."'");
- $domcount = mysql_num_rows($r2);
+ $r2 = $db_conn->query("select * from `org` where `orgid`='".intval($row['id'])."'");
+ $admincount = $r2->num_rows;
+ $r2 = $db_conn->query("select * from `orgdomains` where `orgid`='".intval($row['id'])."'");
+ $domcount = $r2->num_rows;
?>
diff --git a/pages/account/26.php b/pages/account/26.php
index f8b195d3..ab040697 100644
--- a/pages/account/26.php
+++ b/pages/account/26.php
@@ -1,6 +1,6 @@
/*
LibreSSL - CAcert web application
- Copyright (C) 2004-2008 CAcert Inc.
+ Copyright (C) 2004-2020 CAcert Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -17,7 +17,7 @@
*/ ?>
$query = "select * from `orginfo` where `id`='".intval($_REQUEST['orgid'])."'";
- $row = mysql_fetch_assoc(mysql_query($query));
+ $row = $db_conn->query($query)->fetch_assoc();
?>
diff --git a/pages/account/27.php b/pages/account/27.php
index a1086d40..bd340e12 100644
--- a/pages/account/27.php
+++ b/pages/account/27.php
@@ -1,6 +1,6 @@
/*
LibreSSL - CAcert web application
- Copyright (C) 2004-2008 CAcert Inc.
+ Copyright (C) 2004-2020 CAcert Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -16,7 +16,7 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ ?>
- $row = mysql_fetch_assoc(mysql_query("select * from `orginfo` where `id`='".intval($_REQUEST['orgid'])."'"));
+ $row = $db_conn->query("select * from `orginfo` where `id`='".intval($_REQUEST['orgid'])."'")->fetch_assoc();
?>