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 @@
  • < = _ ("PR Materials" ) > ?> < ? = _ ( " CAcert Logos " ) ? > ?> -
  • +
  • < ? = _ ( " Credits " ) ? > ?>
  • diff --git a/includes/account.php b/includes/account.php index 6dacf2da..7f19b135 100644 --- a/includes/account.php +++ b/includes/account.php @@ -1,6 +1,6 @@ real_escape_string(trim(stripslashes($_REQUEST['newemail']))) == "") { showheader(_("My CAcert.org Account!")); printf(_("Not a valid email address. Can't continue.")); @@ -128,7 +128,7 @@ function buildSubjectFromSession() { exit; } $oldid=0; - $_REQUEST['email'] = trim(mysql_real_escape_string(stripslashes($_REQUEST['newemail']))); + $_REQUEST['email'] = $db_conn->real_escape_string(trim(stripslashes($_REQUEST['newemail']))); if(check_email_exists($_REQUEST['email'])==true) { showheader(_("My CAcert.org Account!")); @@ -152,11 +152,11 @@ function buildSubjectFromSession() { } $hash = make_hash(); $query = "insert into `email` set `email`='".$_REQUEST['email']."',`memid`='".intval($_SESSION['profile']['id'])."',`created`=NOW(),`hash`='$hash'"; - mysql_query($query); - $emailid = mysql_insert_id(); + $db_conn->query($query); + $emailid = $db_conn->insert_id; $body = _("Below is the link you need to open to verify your email address. Once your address is verified you will be able to start issuing certificates to your heart's content!")."\n\n"; - $body .= "http://".$_SESSION['_config']['normalhostname']."/verify.php?type=email&emailid=$emailid&hash=$hash\n\n"; + $body .= build_verify_url(["type" => "email", "mailid" => $emailid, "hash" => $hash]); $body .= _("Best regards")."\n"._("CAcert.org Support!"); sendmail($_REQUEST['email'], "[CAcert.org] "._("Email Probe"), $body, "support@cacert.org", "", "", "CAcert Support"); @@ -172,15 +172,15 @@ function buildSubjectFromSession() { $id = 2; $emailid = intval($_REQUEST['emailid']); $query = "select * from `email` where `id`='$emailid' and `memid`='".intval($_SESSION['profile']['id'])."' and `hash` = '' and `deleted`=0"; - $res = mysql_query($query); - if(mysql_num_rows($res) <= 0) + $res = $db_conn->query($query); + if($res->num_rows <= 0) { showheader(_("Error!")); echo _("You currently don't have access to the email address you selected, or you haven't verified it yet."); showfooter(); exit; } - $row = mysql_fetch_assoc($res); + $row = $res->fetch_assoc(); $body = sprintf(_("Hi %s,"),$_SESSION['profile']['fname'])."\n\n"; $body .= _("You are receiving this email because you or someone else ". "has changed the default email on your account.")."\n\n"; @@ -191,8 +191,8 @@ function buildSubjectFromSession() { "support@cacert.org", "", "", "CAcert Support"); $_SESSION['profile']['email'] = $row['email']; - $query = "update `users` set `email`='".mysql_real_escape_string($row['email'])."' where `id`='".intval($_SESSION['profile']['id'])."'"; - mysql_query($query); + $query = "update `users` set `email`='".$db_conn->real_escape_string($row['email'])."' where `id`='".intval($_SESSION['profile']['id'])."'"; + $db_conn->query($query); showheader(_("My CAcert.org Account!")); printf(_("Your default email address has been updated to '%s'."), sanitizeHTML($row['email'])); showfooter(); @@ -216,11 +216,11 @@ function buildSubjectFromSession() { } $id = intval($id); $query = "select * from `email` where `id`='$id' and `memid`='".intval($_SESSION['profile']['id'])."' and - `email`!='".mysql_real_escape_string($_SESSION['profile']['email'])."'"; - $res = mysql_query($query); - if(mysql_num_rows($res) > 0) + `email`!='".$db_conn->real_escape_string($_SESSION['profile']['email'])."'"; + $res = $db_conn->query($query); + if($res->num_rows > 0) { - $row = mysql_fetch_assoc($res); + $row = $res->fetch_assoc($res); echo $row['email']."
    \n"; account_email_delete($row['id']); $delcount++; @@ -258,7 +258,7 @@ function buildSubjectFromSession() { exit; } - $_SESSION['_config']['SSO'] = intval($_REQUEST['SSO']); + $_SESSION['_config']['SSO'] = array_key_exists('SSO', $_REQUEST) ? intval($_REQUEST['SSO']) : 0; $_SESSION['_config']['addid'] = $_REQUEST['addid']; if($_SESSION['profile']['points'] >= 50) @@ -326,10 +326,10 @@ function buildSubjectFromSession() { if(is_array($_SESSION['_config']['addid'])) foreach($_SESSION['_config']['addid'] as $id) { - $res = mysql_query("select * from `email` where `memid`='".intval($_SESSION['profile']['id'])."' and `id`='".intval($id)."'"); - if(mysql_num_rows($res) > 0) + $res = $db_conn->query("select * from `email` where `memid`='".intval($_SESSION['profile']['id'])."' and `id`='".intval($id)."'"); + if($res->num_rows > 0) { - $row = mysql_fetch_assoc($res); + $row = $res->fetch_assoc(); if(!$emails) $defaultemail = $row['email']; $emails .= "$count.emailAddress = ".$row['email']."\n"; @@ -345,7 +345,8 @@ function buildSubjectFromSession() { showfooter(); exit; } - $user = mysql_fetch_assoc(mysql_query("select * from `users` where `id`='".intval($_SESSION['profile']['id'])."'")); + $res = $db_conn->query("select * from `users` where `id`='".intval($_SESSION['profile']['id'])."'"); + $user = $res->fetch_assoc(); if($_SESSION['_config']['SSO'] == 1) $emails .= "$count.emailAddress = ".$user['uniqueID']."\n"; @@ -389,13 +390,13 @@ function buildSubjectFromSession() { `codesign`='".intval($_SESSION['_config']['codesign'])."', `disablelogin`='".($_SESSION['_config']['disablelogin']?1:0)."', `rootcert`='".intval($_SESSION['_config']['rootcert'])."', - `md`='".mysql_real_escape_string($_SESSION['_config']['hash_alg'])."', - `description`='".mysql_real_escape_string($_SESSION['_config']['description'])."'"; - mysql_query($query); - $emailid = mysql_insert_id(); + `md`='".$db_conn->real_escape_string($_SESSION['_config']['hash_alg'])."', + `description`='".$db_conn->real_escape_string($_SESSION['_config']['description'])."'"; + $db_conn->query($query); + $emailid = $db_conn->insert_id; if(is_array($addys)) foreach($addys as $addy) - mysql_query("insert into `emaillink` set `emailcertsid`='$emailid', `emailid`='$addy'"); + $db_conn->query("insert into `emaillink` set `emailcertsid`='$emailid', `emailid`='$addy'"); $CSRname=generatecertpath("csr","client",$emailid); $fp = fopen($CSRname, "w"); fputs($fp, $emails); @@ -411,7 +412,7 @@ function buildSubjectFromSession() { showfooter(); exit; } - mysql_query("update `emailcerts` set `csr_name`='$CSRname' where `id`='".intval($emailid)."'"); + $db_conn->query("update `emailcerts` set `csr_name`='$CSRname' where `id`='".intval($emailid)."'"); } else if($_REQUEST['keytype'] == "MS" || $_REQUEST['keytype'] == "VI") { if($csr == "") $csr = "-----BEGIN CERTIFICATE REQUEST-----\n".clean_csr($_REQUEST['CSR'])."\n-----END CERTIFICATE REQUEST-----\n"; @@ -434,7 +435,8 @@ function buildSubjectFromSession() { $defaultemail = ""; $csrsubject=""; - $user = mysql_fetch_assoc(mysql_query("select * from `users` where `id`='".intval($_SESSION['profile']['id'])."'")); + $res = $db_conn->query("select * from `users` where `id`='".intval($_SESSION['profile']['id'])."'"); + $user = $res->fetch_assoc(); if(strlen($user['mname']) == 1) $user['mname'] .= '.'; if($_SESSION['_config']['incname'] <= 0 || $_SESSION['_config']['incname'] > 4) @@ -450,10 +452,10 @@ function buildSubjectFromSession() { if(is_array($_SESSION['_config']['addid'])) foreach($_SESSION['_config']['addid'] as $id) { - $res = mysql_query("select * from `email` where `memid`='".intval($_SESSION['profile']['id'])."' and `id`='".intval($id)."'"); - if(mysql_num_rows($res) > 0) + $res = $db_conn->query("select * from `email` where `memid`='".intval($_SESSION['profile']['id'])."' and `id`='".intval($id)."'"); + if($res->num_rows > 0) { - $row = mysql_fetch_assoc($res); + $row = $res->fetch_assoc(); if($defaultemail == "") $defaultemail = $row['email']; $csrsubject .= "/emailAddress=".$row['email']; @@ -490,27 +492,27 @@ function buildSubjectFromSession() { `keytype`='".sanitizeHTML($_REQUEST['keytype'])."', `memid`='".intval($_SESSION['profile']['id'])."', `created`=FROM_UNIXTIME(UNIX_TIMESTAMP()), - `subject`='".mysql_real_escape_string($csrsubject)."', + `subject`='".$db_conn->real_escape_string($csrsubject)."', `codesign`='".intval($_SESSION['_config']['codesign'])."', `disablelogin`='".($_SESSION['_config']['disablelogin']?1:0)."', `rootcert`='".intval($_SESSION['_config']['rootcert'])."', - `md`='".mysql_real_escape_string($_SESSION['_config']['hash_alg'])."', - `description`='".mysql_real_escape_string($_SESSION['_config']['description'])."'"; - mysql_query($query); - $emailid = mysql_insert_id(); + `md`='".$db_conn->real_escape_string($_SESSION['_config']['hash_alg'])."', + `description`='".$db_conn->real_escape_string($_SESSION['_config']['description'])."'"; + $db_conn->query($query); + $emailid = $db_conn->insert_id; if(is_array($addys)) foreach($addys as $addy) - mysql_query("insert into `emaillink` set `emailcertsid`='$emailid', `emailid`='".mysql_real_escape_string($addy)."'"); + $db_conn->query("insert into `emaillink` set `emailcertsid`='$emailid', `emailid`='".$db_conn->real_escape_string($addy)."'"); $CSRname=generatecertpath("csr","client",$emailid); $fp = fopen($CSRname, "w"); fputs($fp, $csr); fclose($fp); - mysql_query("update `emailcerts` set `csr_name`='$CSRname' where `id`='$emailid'"); + $db_conn->query("update `emailcerts` set `csr_name`='$CSRname' where `id`='$emailid'"); } waitForResult("emailcerts", $emailid, 4); $query = "select * from `emailcerts` where `id`='$emailid' and `crt_name` != ''"; - $res = mysql_query($query); - if(mysql_num_rows($res) <= 0) + $res = $db_conn->query($query); + if($res->num_rows <= 0) { $id = 4; showheader(_("My CAcert.org Account!")); @@ -547,12 +549,12 @@ function buildSubjectFromSession() { } $newdom = trim(escapeshellarg($newdomain)); - $newdomain = mysql_real_escape_string(trim($newdomain)); + $newdomain = $db_conn->real_escape_string(trim($newdomain)); - $res1 = mysql_query("select * from `orgdomains` where `domain`='$newdomain'"); + $res1 = $db_conn->query("select * from `orgdomains` where `domain`='$newdomain'"); $query = "select * from `domains` where `domain`='$newdomain' and `deleted`=0"; - $res2 = mysql_query($query); - if(mysql_num_rows($res1) > 0 || mysql_num_rows($res2)) + $res2 = $db_conn->query($query); + if($res1->num_rows > 0 || $res2->num_rows) { $oldid=0; $id = 7; @@ -576,10 +578,13 @@ function buildSubjectFromSession() { if(is_array($adds)) foreach($adds as $line) { - $bits = explode(":", $line, 2); - $line = trim($bits[1]); - if(!in_array($line, $addy) && $line != "") - $addy[] = trim(mysql_real_escape_string(stripslashes($line))); + if (strpos($line, ":") > 0) { + $bits = explode(":", $line, 2); + $line = trim($bits[1]); + if (!in_array($line, $addy) && $line != "") { + $addy[] = $db_conn->real_escape_string(trim(stripslashes($line))); + } + } } } else { if(is_array($adds)) @@ -597,7 +602,7 @@ function buildSubjectFromSession() { $line = $bit; } if(!in_array($line, $addy) && $line != "") - $addy[] = trim(mysql_real_escape_string(stripslashes($line))); + $addy[] = trim($db_conn->real_escape_string(stripslashes($line))); } } @@ -606,7 +611,7 @@ function buildSubjectFromSession() { if(!in_array($sub, $addy)) $addy[] = $sub; $_SESSION['_config']['addy'] = $addy; - $_SESSION['_config']['domain'] = mysql_real_escape_string($newdomain); + $_SESSION['_config']['domain'] = $db_conn->real_escape_string($newdomain); } if($process != "" && $oldid == 8) @@ -615,7 +620,7 @@ function buildSubjectFromSession() { $oldid=0; $id = 8; - $authaddy = trim(mysql_real_escape_string(stripslashes($_REQUEST['authaddy']))); + $authaddy = trim($db_conn->real_escape_string(stripslashes($_REQUEST['authaddy']))); if($authaddy == "" || !is_array($_SESSION['_config']['addy'])) { @@ -633,9 +638,9 @@ function buildSubjectFromSession() { exit; } - $query = "select * from `domains` where `domain`='".mysql_real_escape_string($_SESSION['_config']['domain'])."' and `deleted`=0"; - $res = mysql_query($query); - if(mysql_num_rows($res) > 0) + $query = "select * from `domains` where `domain`='".$db_conn->real_escape_string($_SESSION['_config']['domain'])."' and `deleted`=0"; + $res = $db_conn->query($query); + if($res->num_rows > 0) { showheader(_("My CAcert.org Account!")); printf(_("The domain '%s' is already in a different account and is listed as valid. Can't continue."), sanitizeHTML($_SESSION['_config']['domain'])); @@ -659,13 +664,13 @@ function buildSubjectFromSession() { } $hash = make_hash(); - $query = "insert into `domains` set `domain`='".mysql_real_escape_string($_SESSION['_config']['domain'])."', + $query = "insert into `domains` set `domain`='".$db_conn->real_escape_string($_SESSION['_config']['domain'])."', `memid`='".intval($_SESSION['profile']['id'])."',`created`=NOW(),`hash`='$hash'"; - mysql_query($query); - $domainid = mysql_insert_id(); + $db_conn->query($query); + $domainid = $db_conn->insert_id; $body = sprintf(_("Below is the link you need to open to verify your domain '%s'. Once your address is verified you will be able to start issuing certificates to your heart's content!"),$_SESSION['_config']['domain'])."\n\n"; - $body .= "http://".$_SESSION['_config']['normalhostname']."/verify.php?type=domain&domainid=$domainid&hash=$hash\n\n"; + $body .= build_verify_url(["type" => domain, "domainid"=>$domainid,"hash"=>$hash]) . "\n\n"; $body .= _("Best regards")."\n"._("CAcert.org Support!"); sendmail($authaddy, "[CAcert.org] "._("Email Probe"), $body, "support@cacert.org", "", "", "CAcert Support"); @@ -689,10 +694,10 @@ function buildSubjectFromSession() { { $id = intval($id); $query = "select * from `domains` where `id`='$id' and `memid`='".intval($_SESSION['profile']['id'])."'"; - $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(); echo $row['domain']."
    \n"; account_domain_delete($row['id']); } @@ -810,20 +815,20 @@ function buildSubjectFromSession() { if(array_key_exists('0',$_SESSION['_config']['rowid']) && $_SESSION['_config']['rowid']['0'] > 0) { $query = "insert into `domaincerts` set - `CN`='".mysql_real_escape_string($_SESSION['_config']['rows']['0'])."', - `domid`='".mysql_real_escape_string($_SESSION['_config']['rowid']['0'])."', - `created`=NOW(),`subject`='".mysql_real_escape_string($subject)."', - `rootcert`='".mysql_real_escape_string($_SESSION['_config']['rootcert'])."', - `md`='".mysql_real_escape_string($_SESSION['_config']['hash_alg'])."', - `description`='".mysql_real_escape_string($_SESSION['_config']['description'])."'"; + `CN`='".$db_conn->real_escape_string($_SESSION['_config']['rows']['0'])."', + `domid`='".$db_conn->real_escape_string($_SESSION['_config']['rowid']['0'])."', + `created`=NOW(),`subject`='".$db_conn->real_escape_string($subject)."', + `rootcert`='".$db_conn->real_escape_string($_SESSION['_config']['rootcert'])."', + `md`='".$db_conn->real_escape_string($_SESSION['_config']['hash_alg'])."', + `description`='".$db_conn->real_escape_string($_SESSION['_config']['description'])."'"; } elseif(array_key_exists('0',$_SESSION['_config']['altid']) && $_SESSION['_config']['altid']['0'] > 0) { $query = "insert into `domaincerts` set - `CN`='".mysql_real_escape_string($_SESSION['_config']['altrows']['0'])."', - `domid`='".mysql_real_escape_string($_SESSION['_config']['altid']['0'])."', - `created`=NOW(),`subject`='".mysql_real_escape_string($subject)."', - `rootcert`='".mysql_real_escape_string($_SESSION['_config']['rootcert'])."', - `md`='".mysql_real_escape_string($_SESSION['_config']['hash_alg'])."', - `description`='".mysql_real_escape_string($_SESSION['_config']['description'])."'"; + `CN`='".$db_conn->real_escape_string($_SESSION['_config']['altrows']['0'])."', + `domid`='".$db_conn->real_escape_string($_SESSION['_config']['altid']['0'])."', + `created`=NOW(),`subject`='".$db_conn->real_escape_string($subject)."', + `rootcert`='".$db_conn->real_escape_string($_SESSION['_config']['rootcert'])."', + `md`='".$db_conn->real_escape_string($_SESSION['_config']['hash_alg'])."', + `description`='".$db_conn->real_escape_string($_SESSION['_config']['description'])."'"; } else { showheader(_("My CAcert.org Account!")); echo _("Domain not verified."); @@ -831,24 +836,24 @@ function buildSubjectFromSession() { exit; } - mysql_query($query); - $CSRid = mysql_insert_id(); + $db_conn->query($query); + $CSRid = $db_conn->insert_id; if(is_array($_SESSION['_config']['rowid'])) foreach($_SESSION['_config']['rowid'] as $dom) - mysql_query("insert into `domlink` set `certid`='$CSRid', `domid`='$dom'"); + $db_conn->query("insert into `domlink` set `certid`='$CSRid', `domid`='$dom'"); if(is_array($_SESSION['_config']['altid'])) foreach($_SESSION['_config']['altid'] as $dom) - mysql_query("insert into `domlink` set `certid`='$CSRid', `domid`='$dom'"); + $db_conn->query("insert into `domlink` set `certid`='$CSRid', `domid`='$dom'"); $CSRname=generatecertpath("csr","server",$CSRid); rename($_SESSION['_config']['tmpfname'], $CSRname); chmod($CSRname,0644); - mysql_query("update `domaincerts` set `CSR_name`='$CSRname' where `id`='$CSRid'"); + $db_conn->query("update `domaincerts` set `CSR_name`='$CSRname' where `id`='$CSRid'"); waitForResult("domaincerts", $CSRid, 11); $query = "select * from `domaincerts` where `id`='$CSRid' and `crt_name` != ''"; - $res = mysql_query($query); - if(mysql_num_rows($res) <= 0) + $res = $db_conn->query($query); + if($res->num_rows <= 0) { $id = 11; showheader(_("My CAcert.org Account!")); @@ -878,14 +883,14 @@ function buildSubjectFromSession() { where `domaincerts`.`id`='$id' and `domaincerts`.`domid`=`domains`.`id` and `domains`.`memid`='".intval($_SESSION['profile']['id'])."'"; - $res = mysql_query($query); - if(mysql_num_rows($res) <= 0) + $res = $db_conn->query($query); + if($res->num_rows <= 0) { printf(_("Invalid ID '%s' presented, can't do anything with it.")."
    \n", $id); continue; } - $row = mysql_fetch_assoc($res); + $row = $res->fetch_assoc(); if (($weakKey = checkWeakKeyX509(file_get_contents( $row['crt_name']))) !== "") @@ -894,20 +899,20 @@ function buildSubjectFromSession() { continue; } - mysql_query("update `domaincerts` set `renewed`='1' where `id`='$id'"); + $db_conn->query("update `domaincerts` set `renewed`='1' where `id`='$id'"); $query = "insert into `domaincerts` set `domid`='".intval($row['domid'])."', - `CN`='".mysql_real_escape_string($row['CN'])."', - `subject`='".mysql_real_escape_string($row['subject'])."',". + `CN`='".$db_conn->real_escape_string($row['CN'])."', + `subject`='".$db_conn->real_escape_string($row['subject'])."',". //`csr_name`='".$row['csr_name']."', // RACE CONDITION - "`created`='".mysql_real_escape_string($row['created'])."', + "`created`='".$db_conn->real_escape_string($row['created'])."', `modified`=NOW(), `rootcert`='".intval($row['rootcert'])."', `type`='".intval($row['type'])."', - `pkhash`='".mysql_real_escape_string($row['pkhash'])."', - `description`='".mysql_real_escape_string($row['description'])."'"; - mysql_query($query); - $newid = mysql_insert_id(); + `pkhash`='".$db_conn->real_escape_string($row['pkhash'])."', + `description`='".$db_conn->real_escape_string($row['description'])."'"; + $db_conn->query($query); + $newid = $db_conn->insert_id; $newfile=generatecertpath("csr","server",$newid); copy($row['csr_name'], $newfile); $newfile_esc = escapeshellarg($newfile); @@ -929,18 +934,18 @@ function buildSubjectFromSession() { } $subject = buildSubjectFromSession(); - $subject = mysql_real_escape_string($subject); - mysql_query("update `domaincerts` set `subject`='$subject',`csr_name`='$newfile' where `id`='$newid'"); + $subject = $db_conn->real_escape_string($subject); + $db_conn->query("update `domaincerts` set `subject`='$subject',`csr_name`='$newfile' where `id`='$newid'"); echo _("Renewing").": ".sanitizeHTML($_SESSION['_config']['0.CN'])."
    \n"; waitForResult("domaincerts", $newid,$oldid,0); $query = "select * from `domaincerts` where `id`='$newid' and `crt_name` != ''"; - $res = mysql_query($query); - if(mysql_num_rows($res) <= 0) + $res = $db_conn->query($query); + if($res->num_rows <= 0) { printf(_("Your certificate request has failed to be processed correctly, see %sthe WIKI page%s for reasons and solutions."), "", ""); } else { - $drow = mysql_fetch_assoc($res); + $drow = $res->fetch_assoc(); $crt_name = escapeshellarg($drow['crt_name']); $cert = shell_exec("/usr/bin/openssl x509 -in $crt_name"); echo "
    \n$cert\n
    \n"; @@ -971,19 +976,19 @@ function buildSubjectFromSession() { where `domaincerts`.`id`='$id' and `domaincerts`.`domid`=`domains`.`id` and `domains`.`memid`='".intval($_SESSION['profile']['id'])."'"; - $res = mysql_query($query); - if(mysql_num_rows($res) <= 0) + $res = $db_conn->query($query); + if($res->num_rows <= 0) { printf(_("Invalid ID '%s' presented, can't do anything with it.")."
    \n", $id); continue; } - $row = mysql_fetch_assoc($res); + $row = $res->fetch_assoc(); if($row['revoke'] > 0) { printf(_("It would seem '%s' has already been revoked. I'll skip this for now.")."
    \n", $row['CN']); continue; } - mysql_query("update `domaincerts` set `revoked`='1970-01-01 10:00:01' where `id`='$id'"); + $db_conn->query("update `domaincerts` set `revoked`='1970-01-01 10:00:01' where `id`='$id'"); printf(_("Certificate for '%s' with the serial no '%s' has been revoked.").'
    ', htmlspecialchars($row['CN']), htmlspecialchars($row['serial'])); } @@ -1006,19 +1011,19 @@ function buildSubjectFromSession() { where `domaincerts`.`id`='$id' and `domaincerts`.`domid`=`domains`.`id` and `domains`.`memid`='".intval($_SESSION['profile']['id'])."'"; - $res = mysql_query($query); - if(mysql_num_rows($res) <= 0) + $res = $db_conn->query($query); + if($res->num_rows <= 0) { printf(_("Invalid ID '%s' presented, can't do anything with it.")."
    \n", $id); continue; } - $row = mysql_fetch_assoc($res); + $row = $res->fetch_assoc(); if($row['expired'] > 0) { printf(_("Couldn't remove the request for `%s`, request had already been processed.")."
    \n", $row['CN']); continue; } - mysql_query("delete from `domaincerts` where `id`='$id'"); + $db_conn->query("delete from `domaincerts` where `id`='$id'"); @unlink($row['csr_name']); @unlink($row['crt_name']); printf(_("Removed a pending request for '%s'")."
    \n", $row['CN']); @@ -1036,8 +1041,8 @@ function buildSubjectFromSession() { if(substr($id,0,14)=="check_comment_") { $cid = intval(substr($id,14)); - $comment=trim(mysql_real_escape_string(stripslashes($_REQUEST['comment_'.$cid]))); - mysql_query("update `domaincerts` set `description`='$comment' where `id`='$cid'"); + $comment=trim($db_conn->real_escape_string(stripslashes($_REQUEST['comment_'.$cid]))); + $db_conn->query("update `domaincerts` set `description`='$comment' where `id`='$cid'"); } } echo(_("Certificate settings have been changed.")."
    \n"); @@ -1057,14 +1062,14 @@ function buildSubjectFromSession() { $id = intval($id); $query = "select *,UNIX_TIMESTAMP(`revoked`) as `revoke` from `emailcerts` where `id`='$id' and `memid`='".intval($_SESSION['profile']['id'])."'"; - $res = mysql_query($query); - if(mysql_num_rows($res) <= 0) + $res = $db_conn->query($query); + if($res->num_rows <= 0) { printf(_("Invalid ID '%s' presented, can't do anything with it.")."
    \n", $id); continue; } - $row = mysql_fetch_assoc($res); + $row = $res->fetch_assoc(); if (($weakKey = checkWeakKeyX509(file_get_contents( $row['crt_name']))) !== "") @@ -1073,34 +1078,34 @@ function buildSubjectFromSession() { continue; } - mysql_query("update `emailcerts` set `renewed`='1' where `id`='$id'"); + $db_conn->query("update `emailcerts` set `renewed`='1' where `id`='$id'"); $query = "insert into emailcerts set `memid`='".intval($row['memid'])."', - `CN`='".mysql_real_escape_string($row['CN'])."', - `subject`='".mysql_real_escape_string($row['subject'])."', - `keytype`='".mysql_real_escape_string($row['keytype'])."', - `csr_name`='".mysql_real_escape_string($row['csr_name'])."', - `created`='".mysql_real_escape_string($row['created'])."', + `CN`='".$db_conn->real_escape_string($row['CN'])."', + `subject`='".$db_conn->real_escape_string($row['subject'])."', + `keytype`='".$db_conn->real_escape_string($row['keytype'])."', + `csr_name`='".$db_conn->real_escape_string($row['csr_name'])."', + `created`='".$db_conn->real_escape_string($row['created'])."', `modified`=NOW(), `disablelogin`='".intval($row['disablelogin'])."', `codesign`='".intval($row['codesign'])."', `rootcert`='".intval($row['rootcert'])."', - `description`='".mysql_real_escape_string($row['description'])."'"; - mysql_query($query); - $newid = mysql_insert_id(); + `description`='".$db_conn->real_escape_string($row['description'])."'"; + $db_conn->query($query); + $newid = $db_conn->insert_id; $newfile=generatecertpath("csr","client",$newid); copy($row['csr_name'], $newfile); - mysql_query("update `emailcerts` set `csr_name`='$newfile' where `id`='$newid'"); - $res = mysql_query("select * from `emaillink` where `emailcertsid`='".$row['id']."'"); - while($r2 = mysql_fetch_assoc($res)) + $db_conn->query("update `emailcerts` set `csr_name`='$newfile' where `id`='$newid'"); + $res = $db_conn->query("select * from `emaillink` where `emailcertsid`='".$row['id']."'"); + while($r2 = $res->fetch_assoc()) { - mysql_query("insert into `emaillink` set `emailid`='".$r2['emailid']."', + $db_conn->query("insert into `emaillink` set `emailid`='".$r2['emailid']."', `emailcertsid`='$newid'"); } waitForResult("emailcerts", $newid,$oldid,0); $query = "select * from `emailcerts` where `id`='$newid' and `crt_name` != ''"; - $res = mysql_query($query); - if(mysql_num_rows($res) <= 0) + $res = $db_conn->query($query); + if($res->num_rows <= 0) { printf(_("Your certificate request has failed to be processed correctly, see %sthe WIKI page%s for reasons and solutions."), "", ""); } else { @@ -1131,19 +1136,19 @@ function buildSubjectFromSession() { $id = intval($id); $query = "select *,UNIX_TIMESTAMP(`revoked`) as `revoke` from `emailcerts` where `id`='$id' and `memid`='".intval($_SESSION['profile']['id'])."'"; - $res = mysql_query($query); - if(mysql_num_rows($res) <= 0) + $res = $db_conn->query($query); + if($res->num_rows <= 0) { printf(_("Invalid ID '%s' presented, can't do anything with it.")."
    \n", $id); continue; } - $row = mysql_fetch_assoc($res); + $row = $res->fetch_assoc(); if($row['revoke'] > 0) { printf(_("It would seem '%s' has already been revoked. I'll skip this for now.")."
    \n", $row['CN']); continue; } - mysql_query("update `emailcerts` set `revoked`='1970-01-01 10:00:01' where `id`='$id'"); + $db_conn->query("update `emailcerts` set `revoked`='1970-01-01 10:00:01' where `id`='$id'"); printf(_("Certificate for '%s' with the serial no '%s' has been revoked.").'
    ', htmlspecialchars($row['CN']), htmlspecialchars($row['serial'])); } @@ -1163,19 +1168,19 @@ function buildSubjectFromSession() { $id = intval($id); $query = "select *,UNIX_TIMESTAMP(`expire`) as `expired` from `emailcerts` where `id`='$id' and `memid`='".intval($_SESSION['profile']['id'])."'"; - $res = mysql_query($query); - if(mysql_num_rows($res) <= 0) + $res = $db_conn->query($query); + if($res->num_rows <= 0) { printf(_("Invalid ID '%s' presented, can't do anything with it.")."
    \n", $id); continue; } - $row = mysql_fetch_assoc($res); + $row = $res->fetch_assoc(); if($row['expired'] > 0) { printf(_("Couldn't remove the request for `%s`, request had already been processed.")."
    \n", $row['CN']); continue; } - mysql_query("delete from `emailcerts` where `id`='$id'"); + $db_conn->query("delete from `emailcerts` where `id`='$id'"); @unlink($row['csr_name']); @unlink($row['crt_name']); printf(_("Removed a pending request for '%s'")."
    \n", $row['CN']); @@ -1194,14 +1199,14 @@ function buildSubjectFromSession() { { $cid = intval(substr($id,5)); $dis=(array_key_exists('disablelogin_'.$cid,$_REQUEST) && $_REQUEST['disablelogin_'.$cid]=="1")?"0":"1"; - mysql_query("update `emailcerts` set `disablelogin`='$dis' where `id`='$cid' and `memid`='".intval($_SESSION['profile']['id'])."'"); + $db_conn->query("update `emailcerts` set `disablelogin`='$dis' where `id`='$cid' and `memid`='".intval($_SESSION['profile']['id'])."'"); } if(substr($id,0,14)=="check_comment_") { $cid = intval(substr($id,14)); if(!empty($_REQUEST['check_comment_'.$cid])) { - $comment=trim(mysql_real_escape_string(stripslashes($_REQUEST['comment_'.$cid]))); - mysql_query("update `emailcerts` set `description`='$comment' where `id`='$cid' and `memid`='".intval($_SESSION['profile']['id'])."'"); + $comment=trim($db_conn->real_escape_string(stripslashes($_REQUEST['comment_'.$cid]))); + $db_conn->query("update `emailcerts` set `description`='$comment' where `id`='$cid' and `memid`='".intval($_SESSION['profile']['id'])."'"); } } } @@ -1215,16 +1220,16 @@ function buildSubjectFromSession() { csrf_check("perschange"); $_SESSION['_config']['user'] = $_SESSION['profile']; - $_SESSION['_config']['user']['Q1'] = trim(mysql_real_escape_string(stripslashes(strip_tags($_REQUEST['Q1'])))); - $_SESSION['_config']['user']['Q2'] = trim(mysql_real_escape_string(stripslashes(strip_tags($_REQUEST['Q2'])))); - $_SESSION['_config']['user']['Q3'] = trim(mysql_real_escape_string(stripslashes(strip_tags($_REQUEST['Q3'])))); - $_SESSION['_config']['user']['Q4'] = trim(mysql_real_escape_string(stripslashes(strip_tags($_REQUEST['Q4'])))); - $_SESSION['_config']['user']['Q5'] = trim(mysql_real_escape_string(stripslashes(strip_tags($_REQUEST['Q5'])))); - $_SESSION['_config']['user']['A1'] = trim(mysql_real_escape_string(stripslashes(strip_tags($_REQUEST['A1'])))); - $_SESSION['_config']['user']['A2'] = trim(mysql_real_escape_string(stripslashes(strip_tags($_REQUEST['A2'])))); - $_SESSION['_config']['user']['A3'] = trim(mysql_real_escape_string(stripslashes(strip_tags($_REQUEST['A3'])))); - $_SESSION['_config']['user']['A4'] = trim(mysql_real_escape_string(stripslashes(strip_tags($_REQUEST['A4'])))); - $_SESSION['_config']['user']['A5'] = trim(mysql_real_escape_string(stripslashes(strip_tags($_REQUEST['A5'])))); + $_SESSION['_config']['user']['Q1'] = trim($db_conn->real_escape_string(stripslashes(strip_tags($_REQUEST['Q1'])))); + $_SESSION['_config']['user']['Q2'] = trim($db_conn->real_escape_string(stripslashes(strip_tags($_REQUEST['Q2'])))); + $_SESSION['_config']['user']['Q3'] = trim($db_conn->real_escape_string(stripslashes(strip_tags($_REQUEST['Q3'])))); + $_SESSION['_config']['user']['Q4'] = trim($db_conn->real_escape_string(stripslashes(strip_tags($_REQUEST['Q4'])))); + $_SESSION['_config']['user']['Q5'] = trim($db_conn->real_escape_string(stripslashes(strip_tags($_REQUEST['Q5'])))); + $_SESSION['_config']['user']['A1'] = trim($db_conn->real_escape_string(stripslashes(strip_tags($_REQUEST['A1'])))); + $_SESSION['_config']['user']['A2'] = trim($db_conn->real_escape_string(stripslashes(strip_tags($_REQUEST['A2'])))); + $_SESSION['_config']['user']['A3'] = trim($db_conn->real_escape_string(stripslashes(strip_tags($_REQUEST['A3'])))); + $_SESSION['_config']['user']['A4'] = trim($db_conn->real_escape_string(stripslashes(strip_tags($_REQUEST['A4'])))); + $_SESSION['_config']['user']['A5'] = trim($db_conn->real_escape_string(stripslashes(strip_tags($_REQUEST['A5'])))); if($_SESSION['_config']['user']['Q1'] == $_SESSION['_config']['user']['Q2'] || $_SESSION['_config']['user']['Q1'] == $_SESSION['_config']['user']['Q3'] || @@ -1276,16 +1281,16 @@ function buildSubjectFromSession() { if($oldid == 13 && $process != "") { $ddquery = "select sum(`points`) as `total` from `notary` where `to`='".intval($_SESSION['profile']['id'])."' and `deleted` = 0 group by `to`"; - $ddres = mysql_query($ddquery); - $ddrow = mysql_fetch_assoc($ddres); + $ddres = $db_conn->query($ddquery); + $ddrow = $ddres->fetch_assoc(); $_SESSION['profile']['points'] = $ddrow['total']; if($_SESSION['profile']['points'] == 0) { - $_SESSION['_config']['user']['fname'] = trim(mysql_real_escape_string(stripslashes(strip_tags($_REQUEST['fname'])))); - $_SESSION['_config']['user']['mname'] = trim(mysql_real_escape_string(stripslashes(strip_tags($_REQUEST['mname'])))); - $_SESSION['_config']['user']['lname'] = trim(mysql_real_escape_string(stripslashes(strip_tags($_REQUEST['lname'])))); - $_SESSION['_config']['user']['suffix'] = trim(mysql_real_escape_string(stripslashes(strip_tags($_REQUEST['suffix'])))); + $_SESSION['_config']['user']['fname'] = trim($db_conn->real_escape_string(stripslashes(strip_tags($_REQUEST['fname'])))); + $_SESSION['_config']['user']['mname'] = trim($db_conn->real_escape_string(stripslashes(strip_tags($_REQUEST['mname'])))); + $_SESSION['_config']['user']['lname'] = trim($db_conn->real_escape_string(stripslashes(strip_tags($_REQUEST['lname'])))); + $_SESSION['_config']['user']['suffix'] = trim($db_conn->real_escape_string(stripslashes(strip_tags($_REQUEST['suffix'])))); $_SESSION['_config']['user']['day'] = intval($_REQUEST['day']); $_SESSION['_config']['user']['month'] = intval($_REQUEST['month']); $_SESSION['_config']['user']['year'] = intval($_REQUEST['year']); @@ -1316,7 +1321,7 @@ function buildSubjectFromSession() { `suffix`='".$_SESSION['_config']['user']['suffix']."', `dob`='".$_SESSION['_config']['user']['year']."-".$_SESSION['_config']['user']['month']."-".$_SESSION['_config']['user']['day']."' where `id`='".intval($_SESSION['profile']['id'])."'"; - mysql_query($query); + $db_conn->query($query); } if ($showdetails!="") { $query = "update `users` set `Q1`='".$_SESSION['_config']['user']['Q1']."', @@ -1330,16 +1335,16 @@ function buildSubjectFromSession() { `A4`='".$_SESSION['_config']['user']['A4']."', `A5`='".$_SESSION['_config']['user']['A5']."' where `id`='".intval($_SESSION['profile']['id'])."'"; - mysql_query($query); + $db_conn->query($query); } $_SESSION['_config']['user']['set'] = 0; - $_SESSION['profile'] = mysql_fetch_assoc(mysql_query("select * from `users` where `id`='".intval($_SESSION['profile']['id'])."'")); + $_SESSION['profile'] = $db_conn->query("select * from `users` where `id`='".intval($_SESSION['profile']['id'])."'")->fetch_assoc(); $_SESSION['profile']['loggedin'] = 1; $ddquery = "select sum(`points`) as `total` from `notary` where `to`='".intval($_SESSION['profile']['id'])."' and `deleted` = 0 group by `to`"; - $ddres = mysql_query($ddquery); - $ddrow = mysql_fetch_assoc($ddres); + $ddres = $db_conn->query($ddquery); + $ddrow = $ddres->fetch_assoc(); $_SESSION['profile']['points'] = $ddrow['total']; @@ -1352,9 +1357,9 @@ function buildSubjectFromSession() { if($oldid == 14 && $process != "") { - $_SESSION['_config']['user']['oldpass'] = trim(mysql_real_escape_string(stripslashes($_REQUEST['oldpassword']))); - $_SESSION['_config']['user']['pword1'] = trim(mysql_real_escape_string(stripslashes($_REQUEST['pword1']))); - $_SESSION['_config']['user']['pword2'] = trim(mysql_real_escape_string(stripslashes($_REQUEST['pword2']))); + $_SESSION['_config']['user']['oldpass'] = trim($db_conn->real_escape_string(stripslashes($_REQUEST['oldpassword']))); + $_SESSION['_config']['user']['pword1'] = trim($db_conn->real_escape_string(stripslashes($_REQUEST['pword1']))); + $_SESSION['_config']['user']['pword2'] = trim($db_conn->real_escape_string(stripslashes($_REQUEST['pword2']))); $id = 14; csrf_check("pwchange"); @@ -1371,10 +1376,10 @@ function buildSubjectFromSession() { if($_SESSION['_config']['hostname'] != $_SESSION['_config']['securehostname']) { - $match = mysql_query("select * from `users` where `id`='".intval($_SESSION['profile']['id'])."' and + $match = $db_conn->query("select * from `users` where `id`='".intval($_SESSION['profile']['id'])."' and (`password`=old_password('".$_SESSION['_config']['user']['oldpass']."') or `password`=sha1('".$_SESSION['_config']['user']['oldpass']."'))"); - $rc = mysql_num_rows($match); + $rc = $match->num_rows; } else { $rc = 1; } @@ -1392,7 +1397,7 @@ function buildSubjectFromSession() { _("Failure: Pass Phrase not Changed"), '', "\n"; echo _("You failed to correctly enter your current Pass Phrase."); } else { - mysql_query("update `users` set `password`=sha1('".$_SESSION['_config']['user']['pword1']."') + $db_conn->query("update `users` set `password`=sha1('".$_SESSION['_config']['user']['pword1']."') where `id`='".intval($_SESSION['profile']['id'])."'"); echo '

    ', _("Pass Phrase Changed Successfully"), '

    ', "\n"; echo _("Your Pass Phrase has been updated and your primary email account has been notified of the change."); @@ -1417,7 +1422,7 @@ function buildSubjectFromSession() { foreach($_REQUEST['emails'] as $val) { - $val = mysql_real_escape_string(stripslashes(trim($val))); + $val = $db_conn->real_escape_string(stripslashes(trim($val))); $bits = explode("@", $val); $count = count($bits); if($count != 2) @@ -1434,7 +1439,7 @@ function buildSubjectFromSession() { if($val != "") $_SESSION['_config']['emails'][] = $val; } - $_SESSION['_config']['name'] = mysql_real_escape_string(stripslashes(trim($_REQUEST['name']))); + $_SESSION['_config']['name'] = $db_conn->real_escape_string(stripslashes(trim($_REQUEST['name']))); $_SESSION['_config']['OU'] = stripslashes(trim($_REQUEST['OU'])); $_SESSION['_config']['description']= trim(stripslashes($_REQUEST['description'])); @@ -1504,7 +1509,7 @@ function buildSubjectFromSession() { if($_SESSION['_config']['name'] != "") $emails .= "commonName = ".$_SESSION['_config']['name']."\n"; if($_SESSION['_config']['OU']) - $emails .= "organizationalUnitName = ".mysql_real_escape_string($_SESSION['_config']['OU'])."\n"; + $emails .= "organizationalUnitName = ".$db_conn->real_escape_string($_SESSION['_config']['OU'])."\n"; if($org['O']) $emails .= "organizationName = ".$org['O']."\n"; if($org['L']) @@ -1529,19 +1534,20 @@ function buildSubjectFromSession() { $query = "insert into `orgemailcerts` set `CN`='$defaultemail', - `ou`='".mysql_real_escape_string($_SESSION['_config']['OU'])."', + `ou`='".$db_conn->real_escape_string($_SESSION['_config']['OU'])."', `keytype`='NS', `orgid`='".intval($org['orgid'])."', `created`=FROM_UNIXTIME(UNIX_TIMESTAMP()), `codesign`='".intval($_SESSION['_config']['codesign'])."', `rootcert`='".intval($_SESSION['_config']['rootcert'])."', - `md`='".mysql_real_escape_string($_SESSION['_config']['hash_alg'])."', - `description`='".mysql_real_escape_string($_SESSION['_config']['description'])."'"; - mysql_query($query); - $emailid = mysql_insert_id(); + `md`='".$db_conn->real_escape_string($_SESSION['_config']['hash_alg'])."', + `description`='".$db_conn->real_escape_string($_SESSION['_config']['description'])."'"; + $db_conn->query($query); + $emailid = $db_conn->insert_id; - foreach($_SESSION['_config']['domids'] as $addy) - mysql_query("insert into `domemaillink` set `emailcertsid`='$emailid', `emailid`='$addy'"); + foreach($_SESSION['_config']['domids'] as $addy) { + $db_conn->query("insert into `orgemaillink` set `emailcertsid`='$emailid', `domid`='$addy'"); + } $CSRname=generatecertpath("csr","orgclient",$emailid); $fp = fopen($CSRname, "w"); @@ -1558,7 +1564,7 @@ function buildSubjectFromSession() { showfooter(); exit; } - mysql_query("update `orgemailcerts` set `csr_name`='$CSRname' where `id`='$emailid'"); + $db_conn->query("update `orgemailcerts` set `csr_name`='$CSRname' where `id`='$emailid'"); } else if($_REQUEST['keytype'] == "MS" || $_REQUEST['keytype']=="VI") { $csr = clean_csr($_REQUEST['CSR']); if(strpos($csr,"---BEGIN") === FALSE) @@ -1629,31 +1635,31 @@ function buildSubjectFromSession() { $query = "insert into `orgemailcerts` set `CN`='$defaultemail', - `ou`='".mysql_real_escape_string($_SESSION['_config']['OU'])."', + `ou`='".$db_conn->real_escape_string($_SESSION['_config']['OU'])."', `keytype`='" . sanitizeHTML($_REQUEST['keytype']) . "', `orgid`='".intval($org['orgid'])."', `created`=FROM_UNIXTIME(UNIX_TIMESTAMP()), - `subject`='".mysql_real_escape_string($csrsubject)."', + `subject`='".$db_conn->real_escape_string($csrsubject)."', `codesign`='".intval($_SESSION['_config']['codesign'])."', `rootcert`='".intval($_SESSION['_config']['rootcert'])."', - `md`='".mysql_real_escape_string($_SESSION['_config']['hash_alg'])."', - `description`='".mysql_real_escape_string($_SESSION['_config']['description'])."'"; - mysql_query($query); - $emailid = mysql_insert_id(); + `md`='".$db_conn->real_escape_string($_SESSION['_config']['hash_alg'])."', + `description`='".$db_conn->real_escape_string($_SESSION['_config']['description'])."'"; + $db_conn->query($query); + $emailid = $db_conn->insert_id; foreach($_SESSION['_config']['domids'] as $addy) - mysql_query("insert into `domemaillink` set `emailcertsid`='$emailid', `emailid`='$addy'"); + $db_conn->query("insert into `orgemaillink` set `emailcertsid`='$emailid', `domid`='$addy'"); $CSRname=generatecertpath("csr","orgclient",$emailid); $fp = fopen($CSRname, "w"); fputs($fp, $csr); fclose($fp); - mysql_query("update `orgemailcerts` set `csr_name`='$CSRname' where `id`='$emailid'"); + $db_conn->query("update `orgemailcerts` set `csr_name`='$CSRname' where `id`='$emailid'"); } waitForResult("orgemailcerts", $emailid,$oldid); $query = "select * from `orgemailcerts` where `id`='$emailid' and `crt_name` != ''"; - $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!")); printf(_("Your certificate request has failed to be processed correctly, see %sthe WIKI page%s for reasons and solutions."), "", ""); @@ -1681,14 +1687,14 @@ function buildSubjectFromSession() { $query = "select *,UNIX_TIMESTAMP(`revoked`) as `revoke` from `orgemailcerts`, `org` where `orgemailcerts`.`id`='$id' 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) { printf(_("Invalid ID '%s' presented, can't do anything with it.")."
    \n", $id); continue; } - $row = mysql_fetch_assoc($res); + $row = $res->fetch_assoc(); if (($weakKey = checkWeakKeyX509(file_get_contents( $row['crt_name']))) !== "") @@ -1697,7 +1703,7 @@ function buildSubjectFromSession() { continue; } - mysql_query("update `orgemailcerts` set `renewed`='1' where `id`='$id'"); + $db_conn->query("update `orgemailcerts` set `renewed`='1' where `id`='$id'"); if($row['revoke'] > 0) { printf(_("It would seem '%s' has already been revoked. I'll skip this for now.")."
    \n", $row['CN']); @@ -1705,25 +1711,25 @@ function buildSubjectFromSession() { } $query = "insert into `orgemailcerts` set `orgid`='".intval($row['orgid'])."', - `CN`='".mysql_real_escape_string($row['CN'])."', - `ou`='".mysql_real_escape_string($row['ou'])."', - `subject`='".mysql_real_escape_string($row['subject'])."', - `keytype`='".mysql_real_escape_string($row['keytype'])."', - `csr_name`='".mysql_real_escape_string($row['csr_name'])."', - `created`='".mysql_real_escape_string($row['created'])."', + `CN`='".$db_conn->real_escape_string($row['CN'])."', + `ou`='".$db_conn->real_escape_string($row['ou'])."', + `subject`='".$db_conn->real_escape_string($row['subject'])."', + `keytype`='".$db_conn->real_escape_string($row['keytype'])."', + `csr_name`='".$db_conn->real_escape_string($row['csr_name'])."', + `created`='".$db_conn->real_escape_string($row['created'])."', `modified`=NOW(), `codesign`='".intval($row['codesign'])."', `rootcert`='".intval($row['rootcert'])."', - `description`='".mysql_real_escape_string($row['description'])."'"; - mysql_query($query); - $newid = mysql_insert_id(); + `description`='".$db_conn->real_escape_string($row['description'])."'"; + $db_conn->query($query); + $newid = $db_conn->insert_id; $newfile=generatecertpath("csr","orgclient",$newid); copy($row['csr_name'], $newfile); - mysql_query("update `orgemailcerts` set `csr_name`='$newfile' where `id`='$newid'"); + $db_conn->query("update `orgemailcerts` set `csr_name`='$newfile' where `id`='$newid'"); waitForResult("orgemailcerts", $newid,$oldid,0); $query = "select * from `orgemailcerts` where `id`='$newid' and `crt_name` != ''"; - $res = mysql_query($query); - if(mysql_num_rows($res) > 0) + $res = $db_conn->query($query); + if($res->num_rows > 0) { printf(_("Certificate for '%s' has been renewed."), $row['CN']); echo "". @@ -1754,19 +1760,19 @@ function buildSubjectFromSession() { $query = "select *,UNIX_TIMESTAMP(`revoked`) as `revoke` from `orgemailcerts`, `org` where `orgemailcerts`.`id`='".intval($id)."' 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) { printf(_("Invalid ID '%s' presented, can't do anything with it.")."
    \n", $id); continue; } - $row = mysql_fetch_assoc($res); + $row = $res->fetch_assoc(); if($row['revoke'] > 0) { printf(_("It would seem '%s' has already been revoked. I'll skip this for now.")."
    \n", $row['CN']); continue; } - mysql_query("update `orgemailcerts` set `revoked`='1970-01-01 10:00:01' where `id`='$id'"); + $db_conn->query("update `orgemailcerts` set `revoked`='1970-01-01 10:00:01' where `id`='$id'"); printf(_("Certificate for '%s' with the serial no '%s' has been revoked.").'
    ', htmlspecialchars($row['CN']), htmlspecialchars($row['serial'])); } @@ -1787,19 +1793,19 @@ function buildSubjectFromSession() { $query = "select *,UNIX_TIMESTAMP(`expire`) as `expired` from `orgemailcerts`, `org` where `orgemailcerts`.`id`='".intval($id)."' 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) { printf(_("Invalid ID '%s' presented, can't do anything with it.")."
    \n", $id); continue; } - $row = mysql_fetch_assoc($res); + $row = $res->fetch_assoc(); if($row['expired'] > 0) { printf(_("Couldn't remove the request for `%s`, request had already been processed.")."
    \n", $row['CN']); continue; } - mysql_query("delete from `orgemailcerts` where `id`='$id'"); + $db_conn->query("delete from `orgemailcerts` where `id`='$id'"); @unlink($row['csr_name']); @unlink($row['crt_name']); printf(_("Removed a pending request for '%s'")."
    \n", $row['CN']); @@ -1817,8 +1823,8 @@ function buildSubjectFromSession() { if(substr($id,0,14)=="check_comment_") { $cid = intval(substr($id,14)); - $comment=trim(mysql_real_escape_string(stripslashes($_REQUEST['comment_'.$cid]))); - mysql_query("update `orgemailcerts` set `description`='$comment' where `id`='$cid'"); + $comment=trim($db_conn->real_escape_string(stripslashes($_REQUEST['comment_'.$cid]))); + $db_conn->query("update `orgemailcerts` set `description`='$comment' where `id`='$cid'"); } } echo(_("Certificate settings have been changed.")."
    \n"); @@ -1879,14 +1885,14 @@ function buildSubjectFromSession() { `org`.`memid`='".intval($_SESSION['profile']['id'])."' and `org`.`orgid`=`orginfo`.`id` and `org`.`orgid`=`orgdomains`.`orgid` and - `orgdomains`.`domain`='".mysql_real_escape_string($_SESSION['_config']['0.CN'])."'"; - $_SESSION['_config']['CNorg'] = mysql_fetch_assoc(mysql_query($query)); + `orgdomains`.`domain`='".$db_conn->real_escape_string($_SESSION['_config']['0.CN'])."'"; + $_SESSION['_config']['CNorg'] = $db_conn->query($query)->fetch_assoc(); $query = "select * from `orginfo`,`org`,`orgdomains` where `org`.`memid`='".intval($_SESSION['profile']['id'])."' and `org`.`orgid`=`orginfo`.`id` and `org`.`orgid`=`orgdomains`.`orgid` and - `orgdomains`.`domain`='".mysql_real_escape_string($_SESSION['_config']['0.subjectAltName'])."'"; - $_SESSION['_config']['SANorg'] = mysql_fetch_assoc(mysql_query($query)); + `orgdomains`.`domain`='".$db_conn->real_escape_string($_SESSION['_config']['0.subjectAltName'])."'"; + $_SESSION['_config']['SANorg'] = $db_conn->query($query)->fetch_assoc(); //echo "
    "; print_r($_SESSION['_config']); die;
     
     		if($_SESSION['_config']['0.CN'] == "" && $_SESSION['_config']['0.subjectAltName'] == "")
    @@ -1946,7 +1952,7 @@ function buildSubjectFromSession() {
     					`orginfo`.`id`=`org`.`orgid` and
     					`org`.`memid`='".intval($_SESSION['profile']['id'])."'";
     		}
    -		$org = mysql_fetch_assoc(mysql_query($query));
    +		$org = $db_conn->query($query)->fetch_assoc();
     		$csrsubject = "";
     
     		if($_SESSION['_config']['OU'])
    @@ -1972,42 +1978,42 @@ function buildSubjectFromSession() {
     		if($_SESSION['_config']['rowid']['0'] > 0)
     		{
     			$query = "insert into `orgdomaincerts` set
    -					`CN`='".mysql_real_escape_string($_SESSION['_config']['rows']['0'])."',
    +					`CN`='".$db_conn->real_escape_string($_SESSION['_config']['rows']['0'])."',
     					`orgid`='".intval($org['id'])."',
     					`created`=NOW(),
    -					`subject`='".mysql_real_escape_string($csrsubject)."',
    +					`subject`='".$db_conn->real_escape_string($csrsubject)."',
     					`rootcert`='".intval($_SESSION['_config']['rootcert'])."',
    -					`md`='".mysql_real_escape_string($_SESSION['_config']['hash_alg'])."',
    +					`md`='".$db_conn->real_escape_string($_SESSION['_config']['hash_alg'])."',
     					`type`='".$type."',
    -					`description`='".mysql_real_escape_string($_SESSION['_config']['description'])."'";
    +					`description`='".$db_conn->real_escape_string($_SESSION['_config']['description'])."'";
     		} else {
     			$query = "insert into `orgdomaincerts` set
    -					`CN`='".mysql_real_escape_string($_SESSION['_config']['altrows']['0'])."',
    +					`CN`='".$db_conn->real_escape_string($_SESSION['_config']['altrows']['0'])."',
     					`orgid`='".intval($org['id'])."',
     					`created`=NOW(),
    -					`subject`='".mysql_real_escape_string($csrsubject)."',
    +					`subject`='".$db_conn->real_escape_string($csrsubject)."',
     					`rootcert`='".intval($_SESSION['_config']['rootcert'])."',
    -					`md`='".mysql_real_escape_string($_SESSION['_config']['hash_alg'])."',
    +					`md`='".$db_conn->real_escape_string($_SESSION['_config']['hash_alg'])."',
     					`type`='".$type."',
    -					`description`='".mysql_real_escape_string($_SESSION['_config']['description'])."'";
    +					`description`='".$db_conn->real_escape_string($_SESSION['_config']['description'])."'";
     		}
    -		mysql_query($query);
    -		$CSRid = mysql_insert_id();
    +		$db_conn->query($query);
    +		$CSRid = $db_conn->insert_id;
     
     		$CSRname=generatecertpath("csr","orgserver",$CSRid);
     		rename($_SESSION['_config']['tmpfname'], $CSRname);
     		chmod($CSRname,0644);
    -		mysql_query("update `orgdomaincerts` set `CSR_name`='$CSRname' where `id`='$CSRid'");
    +		$db_conn->query("update `orgdomaincerts` set `CSR_name`='$CSRname' where `id`='$CSRid'");
     		if(is_array($_SESSION['_config']['rowid']))
     			foreach($_SESSION['_config']['rowid'] as $id)
    -				mysql_query("insert into `orgdomlink` set `orgdomid`='".intval($id)."', `orgcertid`='$CSRid'");
    +				$db_conn->query("insert into `orgdomlink` set `orgdomid`='".intval($id)."', `orgcertid`='$CSRid'");
     		if(is_array($_SESSION['_config']['altid']))
     			foreach($_SESSION['_config']['altid'] as $id)
    -				mysql_query("insert into `orgdomlink` set `orgdomid`='".intval($id)."', `orgcertid`='$CSRid'");
    +				$db_conn->query("insert into `orgdomlink` set `orgdomid`='".intval($id)."', `orgcertid`='$CSRid'");
     		waitForResult("orgdomaincerts", $CSRid,$oldid);
     		$query = "select * from `orgdomaincerts` where `id`='$CSRid' and `crt_name` != ''";
    -		$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!"));
     			printf(_("Your certificate request has failed to be processed correctly, see %sthe WIKI page%s for reasons and solutions.")." CSRid: $CSRid", "", "");
    @@ -2035,14 +2041,14 @@ function buildSubjectFromSession() {
     						where `orgdomaincerts`.`id`='$id' and
     						`orgdomaincerts`.`orgid`=`org`.`orgid` and
     						`org`.`memid`='".intval($_SESSION['profile']['id'])."'";
    -				$res = mysql_query($query);
    -				if(mysql_num_rows($res) <= 0)
    +				$res = $db_conn->query($query);
    +				if($res->num_rows <= 0)
     				{
     					printf(_("Invalid ID '%s' presented, can't do anything with it.")."
    \n", $id); continue; } - $row = mysql_fetch_assoc($res); + $row = $res->fetch_assoc(); if (($weakKey = checkWeakKeyX509(file_get_contents( $row['crt_name']))) !== "") @@ -2051,7 +2057,7 @@ function buildSubjectFromSession() { continue; } - mysql_query("update `orgdomaincerts` set `renewed`='1' where `id`='$id'"); + $db_conn->query("update `orgdomaincerts` set `renewed`='1' where `id`='$id'"); if($row['revoke'] > 0) { printf(_("It would seem '%s' has already been revoked. I'll skip this for now.")."
    \n", $row['CN']); @@ -2059,32 +2065,32 @@ function buildSubjectFromSession() { } $query = "insert into `orgdomaincerts` set `orgid`='".intval($row['orgid'])."', - `CN`='".mysql_real_escape_string($row['CN'])."', - `csr_name`='".mysql_real_escape_string($row['csr_name'])."', - `created`='".mysql_real_escape_string($row['created'])."', + `CN`='".$db_conn->real_escape_string($row['CN'])."', + `csr_name`='".$db_conn->real_escape_string($row['csr_name'])."', + `created`='".$db_conn->real_escape_string($row['created'])."', `modified`=NOW(), - `subject`='".mysql_real_escape_string($row['subject'])."', + `subject`='".$db_conn->real_escape_string($row['subject'])."', `type`='".intval($row['type'])."', `rootcert`='".intval($row['rootcert'])."', - `description`='".mysql_real_escape_string($row['description'])."'"; - mysql_query($query); - $newid = mysql_insert_id(); + `description`='".$db_conn->real_escape_string($row['description'])."'"; + $db_conn->query($query); + $newid = $db_conn->insert_id; //echo "NewID: $newid
    \n"; $newfile=generatecertpath("csr","orgserver",$newid); copy($row['csr_name'], $newfile); - mysql_query("update `orgdomaincerts` set `csr_name`='$newfile' where `id`='$newid'"); + $db_conn->query("update `orgdomaincerts` set `csr_name`='$newfile' where `id`='$newid'"); echo _("Renewing").": ".$row['CN']."
    \n"; - $res = mysql_query("select * from `orgdomlink` where `orgcertid`='".$row['id']."'"); - while($r2 = mysql_fetch_assoc($res)) - mysql_query("insert into `orgdomlink` set `orgdomid`='".intval($r2['orgdomid'])."', `orgcertid`='$newid'"); + $res = $db_conn->query("select * from `orgdomlink` where `orgcertid`='".$row['id']."'"); + while($r2 = $res->fetch_assoc()) + $db_conn->query("insert into `orgdomlink` set `orgdomid`='".intval($r2['orgdomid'])."', `orgcertid`='$newid'"); waitForResult("orgdomaincerts", $newid,$oldid,0); $query = "select * from `orgdomaincerts` where `id`='$newid' and `crt_name` != ''"; - $res = mysql_query($query); - if(mysql_num_rows($res) <= 0) + $res = $db_conn->query($query); + if($res->num_rows <= 0) { printf(_("Your certificate request has failed to be processed correctly, see %sthe WIKI page%s for reasons and solutions.")." newid: $newid", "", ""); } else { - $drow = mysql_fetch_assoc($res); + $drow = $res->fetch_assoc(); $crtname = escapeshellarg($drow['crt_name']); $cert = shell_exec("/usr/bin/openssl x509 -in $crtname"); echo "
    \n$cert\n
    \n"; @@ -2114,19 +2120,19 @@ function buildSubjectFromSession() { where `orgdomaincerts`.`id`='$id' and `orgdomaincerts`.`orgid`=`org`.`orgid` and `org`.`memid`='".intval($_SESSION['profile']['id'])."'"; - $res = mysql_query($query); - if(mysql_num_rows($res) <= 0) + $res = $db_conn->query($query); + if($res->num_rows <= 0) { printf(_("Invalid ID '%s' presented, can't do anything with it.")."
    \n", $id); continue; } - $row = mysql_fetch_assoc($res); + $row = $res->fetch_assoc(); if($row['revoke'] > 0) { printf(_("It would seem '%s' has already been revoked. I'll skip this for now.")."
    \n", $row['CN']); continue; } - mysql_query("update `orgdomaincerts` set `revoked`='1970-01-01 10:00:01' where `id`='$id'"); + $db_conn->query("update `orgdomaincerts` set `revoked`='1970-01-01 10:00:01' where `id`='$id'"); printf(_("Certificate for '%s' with the serial no '%s' has been revoked.").'
    ', htmlspecialchars($row['CN']), htmlspecialchars($row['serial'])); } @@ -2149,19 +2155,19 @@ function buildSubjectFromSession() { where `orgdomaincerts`.`id`='$id' and `orgdomaincerts`.`orgid`=`org`.`orgid` and `org`.`memid`='".intval($_SESSION['profile']['id'])."'"; - $res = mysql_query($query); - if(mysql_num_rows($res) <= 0) + $res = $db_conn->query($query); + if($res->num_rows <= 0) { printf(_("Invalid ID '%s' presented, can't do anything with it.")."
    \n", $id); continue; } - $row = mysql_fetch_assoc($res); + $row = $res->fetch_assoc(); if($row['expired'] > 0) { printf(_("Couldn't remove the request for `%s`, request had already been processed.")."
    \n", $row['CN']); continue; } - mysql_query("delete from `orgdomaincerts` where `id`='$id'"); + $db_conn->query("delete from `orgdomaincerts` where `id`='$id'"); @unlink($row['csr_name']); @unlink($row['crt_name']); printf(_("Removed a pending request for '%s'")."
    \n", $row['CN']); @@ -2179,8 +2185,8 @@ function buildSubjectFromSession() { if(substr($id,0,14)=="check_comment_") { $cid = intval(substr($id,14)); - $comment=trim(mysql_real_escape_string(stripslashes($_REQUEST['comment_'.$cid]))); - mysql_query("update `orgdomaincerts` set `description`='$comment' where `id`='$cid'"); + $comment=trim($db_conn->real_escape_string(stripslashes($_REQUEST['comment_'.$cid]))); + $db_conn->query("update `orgdomaincerts` set `description`='$comment' where `id`='$cid'"); } } echo(_("Certificate settings have been changed.")."
    \n"); @@ -2219,18 +2225,18 @@ function buildSubjectFromSession() { if($oldid == 24 && $process != "") { $id = intval($oldid); - $_SESSION['_config']['O'] = trim(mysql_real_escape_string(stripslashes($_REQUEST['O']))); - $_SESSION['_config']['contact'] = trim(mysql_real_escape_string(stripslashes($_REQUEST['contact']))); - $_SESSION['_config']['L'] = trim(mysql_real_escape_string(stripslashes($_REQUEST['L']))); - $_SESSION['_config']['ST'] = trim(mysql_real_escape_string(stripslashes($_REQUEST['ST']))); - $_SESSION['_config']['C'] = trim(mysql_real_escape_string(stripslashes($_REQUEST['C']))); - $_SESSION['_config']['comments'] = trim(mysql_real_escape_string(stripslashes($_REQUEST['comments']))); + $_SESSION['_config']['O'] = trim($db_conn->real_escape_string(stripslashes($_REQUEST['O']))); + $_SESSION['_config']['contact'] = trim($db_conn->real_escape_string(stripslashes($_REQUEST['contact']))); + $_SESSION['_config']['L'] = trim($db_conn->real_escape_string(stripslashes($_REQUEST['L']))); + $_SESSION['_config']['ST'] = trim($db_conn->real_escape_string(stripslashes($_REQUEST['ST']))); + $_SESSION['_config']['C'] = trim($db_conn->real_escape_string(stripslashes($_REQUEST['C']))); + $_SESSION['_config']['comments'] = trim($db_conn->real_escape_string(stripslashes($_REQUEST['comments']))); if($_SESSION['_config']['O'] == "" || $_SESSION['_config']['contact'] == "") { $_SESSION['_config']['errmsg'] = _("Organisation Name and Contact Email are required fields."); } else { - mysql_query("insert into `orginfo` set `O`='".$_SESSION['_config']['O']."', + $db_conn->query("insert into `orginfo` set `O`='".$_SESSION['_config']['O']."', `contact`='".$_SESSION['_config']['contact']."', `L`='".$_SESSION['_config']['L']."', `ST`='".$_SESSION['_config']['ST']."', @@ -2247,18 +2253,18 @@ function buildSubjectFromSession() { { csrf_check('orgdetchange'); $id = intval($oldid); - $_SESSION['_config']['O'] = trim(mysql_real_escape_string(stripslashes($_REQUEST['O']))); - $_SESSION['_config']['contact'] = trim(mysql_real_escape_string(stripslashes($_REQUEST['contact']))); - $_SESSION['_config']['L'] = trim(mysql_real_escape_string(stripslashes($_REQUEST['L']))); - $_SESSION['_config']['ST'] = trim(mysql_real_escape_string(stripslashes($_REQUEST['ST']))); - $_SESSION['_config']['C'] = trim(mysql_real_escape_string(stripslashes($_REQUEST['C']))); - $_SESSION['_config']['comments'] = trim(mysql_real_escape_string(stripslashes($_REQUEST['comments']))); + $_SESSION['_config']['O'] = trim($db_conn->real_escape_string(stripslashes($_REQUEST['O']))); + $_SESSION['_config']['contact'] = trim($db_conn->real_escape_string(stripslashes($_REQUEST['contact']))); + $_SESSION['_config']['L'] = trim($db_conn->real_escape_string(stripslashes($_REQUEST['L']))); + $_SESSION['_config']['ST'] = trim($db_conn->real_escape_string(stripslashes($_REQUEST['ST']))); + $_SESSION['_config']['C'] = trim($db_conn->real_escape_string(stripslashes($_REQUEST['C']))); + $_SESSION['_config']['comments'] = trim($db_conn->real_escape_string(stripslashes($_REQUEST['comments']))); if($_SESSION['_config']['O'] == "" || $_SESSION['_config']['contact'] == "") { $_SESSION['_config']['errmsg'] = _("Organisation Name and Contact Email are required fields."); } else { - mysql_query("update `orginfo` set `O`='".$_SESSION['_config']['O']."', + $db_conn->query("update `orginfo` set `O`='".$_SESSION['_config']['O']."', `contact`='".$_SESSION['_config']['contact']."', `L`='".$_SESSION['_config']['L']."', `ST`='".$_SESSION['_config']['ST']."', @@ -2274,9 +2280,9 @@ function buildSubjectFromSession() { if($oldid == 28 && $process != "" && array_key_exists("domainname",$_REQUEST)) { - $domain = $_SESSION['_config']['domain'] = trim(mysql_real_escape_string(stripslashes($_REQUEST['domainname']))); - $res1 = mysql_query("select * from `orgdomains` where `domain`='$domain'"); - if(mysql_num_rows($res1) > 0) + $domain = $_SESSION['_config']['domain'] = trim($db_conn->real_escape_string(stripslashes($_REQUEST['domainname']))); + $res1 = $db_conn->query("select * from `orgdomains` where `domain`='$domain'"); + if($res1->num_rows > 0) { $_SESSION['_config']['errmsg'] = sprintf(_("The domain '%s' is already in a different account and is listed as valid. Can't continue."), sanitizeHTML($domain)); $id = $oldid; @@ -2292,7 +2298,7 @@ function buildSubjectFromSession() { if($oldid == 28 && $process != "" && array_key_exists("orgid",$_SESSION["_config"])) { - mysql_query("insert into `orgdomains` set `orgid`='".intval($_SESSION['_config']['orgid'])."', `domain`='$domain'"); + $db_conn->query("insert into `orgdomains` set `orgid`='".intval($_SESSION['_config']['orgid'])."', `domain`='$domain'"); showheader(_("My CAcert.org Account!")); printf(_("'%s' has just been successfully added to the database."), sanitizeHTML($domain)); echo "

    "._("Click here")." "._("to continue."); @@ -2302,11 +2308,11 @@ function buildSubjectFromSession() { if($oldid == 29 && $process != "") { - $domain = mysql_real_escape_string(stripslashes(trim($_REQUEST['domainname']))); + $domain = $db_conn->real_escape_string(stripslashes(trim($_REQUEST['domainname']))); - $res1 = mysql_query("select * from `orgdomains` where `domain` like '$domain' and `id`!='".intval($domid)."'"); - $res2 = mysql_query("select * from `domains` where `domain` like '$domain' and `deleted`=0"); - if(mysql_num_rows($res1) > 0 || mysql_num_rows($res2) > 0) + $res1 = $db_conn->query("select * from `orgdomains` where `domain` like '$domain' and `id`!='".intval($domid)."'"); + $res2 = $db_conn->query("select * from `domains` where `domain` like '$domain' and `deleted`=0"); + if($res1->num_rows > 0 || $res2->num_rows > 0) { $_SESSION['_config']['errmsg'] = sprintf(_("The domain '%s' is already in a different account and is listed as valid. Can't continue."), sanitizeHTML($domain)); $id = $oldid; @@ -2320,23 +2326,23 @@ function buildSubjectFromSession() { `orgdomlink`.`orgdomid`=`orgdomains`.`id` and `orgdomaincerts`.`id`=`orgdomlink`.`orgcertid` and `orgdomains`.`id`='".intval($domid)."'"; - $res = mysql_query($query); - while($row = mysql_fetch_assoc($res)) - mysql_query("update `orgdomaincerts` set `revoked`='1970-01-01 10:00:01' where `id`='".$row['id']."'"); + $res = $db_conn->query($query); + while($row = $res->fetch_assoc()) + $db_conn->query("update `orgdomaincerts` set `revoked`='1970-01-01 10:00:01' where `id`='".$row['id']."'"); $query = "select `orgemailcerts`.`id` as `id` from `orgemailcerts`, `orgemaillink`, `orgdomains` where `orgemaillink`.`domid`=`orgdomains`.`id` and `orgemailcerts`.`id`=`orgemaillink`.`emailcertsid` and `orgdomains`.`id`='".intval($domid)."'"; - $res = mysql_query($query); - while($row = mysql_fetch_assoc($res)) - mysql_query("update `orgemailcerts` set `revoked`='1970-01-01 10:00:01' where `id`='".intval($row['id'])."'"); + $res = $db_conn->query($query); + while($row = $res->fetch_assoc()) + $db_conn->query("update `orgemailcerts` set `revoked`='1970-01-01 10:00:01' where `id`='".intval($row['id'])."'"); } if($oldid == 29 && $process != "") { - $row = mysql_fetch_assoc(mysql_query("select * from `orgdomains` where `id`='".intval($domid)."'")); - mysql_query("update `orgdomains` set `domain`='$domain' where `id`='".intval($domid)."'"); + $row = $db_conn->query("select * from `orgdomains` where `id`='".intval($domid)."'")->fetch_assoc(); + $db_conn->query("update `orgdomains` set `domain`='$domain' where `id`='".intval($domid)."'"); showheader(_("My CAcert.org Account!")); printf(_("'%s' has just been successfully updated in the database."), sanitizeHTML($domain)); echo "

    "._("Click here")." "._("to continue."); @@ -2346,9 +2352,10 @@ function buildSubjectFromSession() { if($oldid == 30 && $process != "") { - $row = mysql_fetch_assoc(mysql_query("select * from `orgdomains` where `id`='".intval($domid)."'")); + $res = $db_conn->query("select * from `orgdomains` where `id`='".intval($domid)."'"); + $row = $res->fetch_assoc(); $domain = $row['domain']; - mysql_query("delete from `orgdomains` where `id`='".intval($domid)."'"); + $db_conn->query("delete from `orgdomains` where `id`='".intval($domid)."'"); showheader(_("My CAcert.org Account!")); printf(_("'%s' has just been successfully deleted from the database."), sanitizeHTML($domain)); echo "

    "._("Click here")." "._("to continue."); @@ -2365,36 +2372,36 @@ function buildSubjectFromSession() { if($oldid == 31 && $process != "") { $query = "select * from `orgdomains` where `orgid`='".intval($_SESSION['_config']['orgid'])."'"; - $dres = mysql_query($query); - while($drow = mysql_fetch_assoc($dres)) + $dres = $db_conn->query($query); + while($drow = $dres->fetch_assoc()) { $query = "select `orgdomaincerts`.`id` as `id` from `orgdomlink`, `orgdomaincerts`, `orgdomains` where `orgdomlink`.`orgdomid`=`orgdomains`.`id` and `orgdomaincerts`.`id`=`orgdomlink`.`orgcertid` and `orgdomains`.`id`='".intval($drow['id'])."'"; - $res = mysql_query($query); - while($row = mysql_fetch_assoc($res)) + $res = $db_conn->query($query); + while($row = $res->fetch_assoc()) { - mysql_query("update `orgdomaincerts` set `revoked`='1970-01-01 10:00:01' where `id`='".intval($row['id'])."'"); - mysql_query("delete from `orgdomaincerts` where `orgid`='".intval($row['id'])."'"); - mysql_query("delete from `orgdomlink` where `domid`='".intval($row['id'])."'"); + $db_conn->query("update `orgdomaincerts` set `revoked`='1970-01-01 10:00:01' where `id`='".intval($row['id'])."'"); + $db_conn->query("delete from `orgdomaincerts` where `orgid`='".intval($row['id'])."'"); + $db_conn->query("delete from `orgdomlink` where `orgcertid`='".intval($row['id'])."'"); } $query = "select `orgemailcerts`.`id` as `id` from `orgemailcerts`, `orgemaillink`, `orgdomains` where `orgemaillink`.`domid`=`orgdomains`.`id` and `orgemailcerts`.`id`=`orgemaillink`.`emailcertsid` and `orgdomains`.`id`='".intval($drow['id'])."'"; - $res = mysql_query($query); - while($row = mysql_fetch_assoc($res)) + $res = $db_conn->query($query); + while($row = $res->fetch_assoc()) { - mysql_query("update `orgemailcerts` set `revoked`='1970-01-01 10:00:01' where `id`='".intval($row['id'])."'"); - mysql_query("delete from `orgemailcerts` where `id`='".intval($row['id'])."'"); - mysql_query("delete from `orgemaillink` where `domid`='".intval($row['id'])."'"); + $db_conn->query("update `orgemailcerts` set `revoked`='1970-01-01 10:00:01' where `id`='".intval($row['id'])."'"); + $db_conn->query("delete from `orgemailcerts` where `id`='".intval($row['id'])."'"); + $db_conn->query("delete from `orgemaillink` where `domid`='".intval($row['id'])."'"); } } - mysql_query("delete from `org` where `orgid`='".intval($_SESSION['_config']['orgid'])."'"); - mysql_query("delete from `orgdomains` where `orgid`='".intval($_SESSION['_config']['orgid'])."'"); - mysql_query("delete from `orginfo` where `id`='".intval($_SESSION['_config']['orgid'])."'"); + $db_conn->query("delete from `org` where `orgid`='".intval($_SESSION['_config']['orgid'])."'"); + $db_conn->query("delete from `orgdomains` where `orgid`='".intval($_SESSION['_config']['orgid'])."'"); + $db_conn->query("delete from `orginfo` where `id`='".intval($_SESSION['_config']['orgid'])."'"); } if($oldid == 31) @@ -2406,7 +2413,8 @@ function buildSubjectFromSession() { if($id == 32 || $oldid == 32 || $id == 33 || $oldid == 33 || $id == 34 || $oldid == 34) { $query = "select * from `org` where `memid`='".intval($_SESSION['profile']['id'])."' and `masteracc`='1'"; - $_macc = mysql_num_rows(mysql_query($query)); + $res = $db_conn->query($query); + $_macc = $res->num_rows; if($_SESSION['profile']['orgadmin'] != 1 && $_macc <= 0) { showheader(_("My CAcert.org Account!")); @@ -2419,7 +2427,7 @@ function buildSubjectFromSession() { if($id == 35 || $oldid == 35) { $query = "select 1 from `org` where `memid`='".intval($_SESSION['profile']['id'])."'"; - $is_orguser = mysql_num_rows(mysql_query($query)); + $is_orguser = $db_conn->query($query->num_rows); if($_SESSION['profile']['orgadmin'] != 1 && $is_orguser <= 0) { showheader(_("My CAcert.org Account!")); @@ -2433,8 +2441,8 @@ function buildSubjectFromSession() { { $orgid = intval($_SESSION['_config']['orgid']); $query = "select * from `org` where `orgid`='$orgid' and `memid`='".intval($_SESSION['profile']['id'])."' and `masteracc`='1'"; - $res = mysql_query($query); - if(mysql_num_rows($res) <= 0) + $res = $db_conn->query($query); + if($res->num_rows <= 0) { $id = 35; } @@ -2447,17 +2455,17 @@ function buildSubjectFromSession() { $masteracc = $_SESSION['_config']['masteracc'] = intval($_REQUEST['masteracc']); else $masteracc = $_SESSION['_config']['masteracc'] = 0; - $_REQUEST['email'] = $_SESSION['_config']['email'] = mysql_real_escape_string(stripslashes(trim($_REQUEST['email']))); + $_REQUEST['email'] = $_SESSION['_config']['email'] = $db_conn->real_escape_string(stripslashes(trim($_REQUEST['email']))); $_SESSION['_config']['OU'] = stripslashes(trim($_REQUEST['OU'])); - $comments = $_SESSION['_config']['comments'] = mysql_real_escape_string(stripslashes(trim($_REQUEST['comments']))); - $res = mysql_query("select * from `users` where `email`='".$_REQUEST['email']."' and `deleted`=0"); - if(mysql_num_rows($res) <= 0) + $comments = $_SESSION['_config']['comments'] = $db_conn->real_escape_string(stripslashes(trim($_REQUEST['comments']))); + $res = $db_conn->query("select * from `users` where `email`='".$_REQUEST['email']."' and `deleted`=0"); + if($res->num_rows <= 0) { $id = $oldid; $oldid=0; $_SESSION['_config']['errmsg'] = sprintf(_("Wasn't able to match '%s' against any user in the system"), sanitizeHTML($_REQUEST['email'])); } else { - $row = mysql_fetch_assoc($res); + $row = $res->fetch_assoc(); if ( !is_assurer(intval($row['id'])) ) { $id = $oldid; @@ -2465,12 +2473,12 @@ function buildSubjectFromSession() { $_SESSION['_config']['errmsg'] = _("The user is not an Assurer yet"); } else { - mysql_query( + $db_conn->query( "insert into `org` set `memid`='".intval($row['id'])."', `orgid`='".intval($_SESSION['_config']['orgid'])."', `masteracc`='$masteracc', - `OU`='".mysql_real_escape_string($_SESSION['_config']['OU'])."', + `OU`='".$db_conn->real_escape_string($_SESSION['_config']['OU'])."', `comments`='$comments'"); } } @@ -2479,8 +2487,8 @@ function buildSubjectFromSession() { if(($oldid == 34 || $id == 34) && $_SESSION['profile']['orgadmin'] != 1) { $orgid = intval($_SESSION['_config']['orgid']); - $res = mysql_query("select * from `org` where `orgid`='$orgid' and `memid`='".intval($_SESSION['profile']['id'])."' and `masteracc`='1'"); - if(mysql_num_rows($res) <= 0) + $res = $db_conn->query("select * from `org` where `orgid`='$orgid' and `memid`='".intval($_SESSION['profile']['id'])."' and `masteracc`='1'"); + if($res->num_rows <= 0) $id = 32; } @@ -2489,7 +2497,7 @@ function buildSubjectFromSession() { $orgid = intval($_SESSION['_config']['orgid']); $memid = intval($_REQUEST['memid']); $query = "delete from `org` where `orgid`='$orgid' and `memid`='$memid'"; - mysql_query($query); + $db_conn->query($query); } if($oldid == 34 || $oldid == 33) @@ -2501,7 +2509,8 @@ function buildSubjectFromSession() { if($id == 36) { - $row = mysql_fetch_assoc(mysql_query("select * from `alerts` where `memid`='".intval($_SESSION['profile']['id'])."'")); + $res = $db_conn->query("select * from `alerts` where `memid`='".intval($_SESSION['profile']['id'])."'"); + $row = $res->fetch_assoc(); $_REQUEST['general'] = $row['general']; $_REQUEST['country'] = $row['country']; $_REQUEST['regional'] = $row['regional']; @@ -2510,7 +2519,8 @@ function buildSubjectFromSession() { if($oldid == 36) { - $rc = mysql_num_rows(mysql_query("select * from `alerts` where `memid`='".intval($_SESSION['profile']['id'])."'")); + $result = $db_conn->query("select * from `alerts` where `memid`='" . intval($_SESSION['profile']['id']) . "'"); + $rc = $result->num_rows; if($rc > 0) { $query = "update `alerts` set `general`='".intval(array_key_exists('general',$_REQUEST)?$_REQUEST['general']:0)."', @@ -2525,7 +2535,7 @@ function buildSubjectFromSession() { `radius`='".intval(array_key_exists('radius',$_REQUEST)?$_REQUEST['radius']:0)."', `memid`='".intval($_SESSION['profile']['id'])."'"; } - mysql_query($query); + $db_conn->query($query); $id = $oldid; $oldid=0; } @@ -2533,12 +2543,12 @@ function buildSubjectFromSession() { if($oldid == 41 && $_REQUEST['action'] == 'default') { csrf_check("mainlang"); - $lang = mysql_real_escape_string($_REQUEST['lang']); + $lang = $db_conn->real_escape_string($_REQUEST['lang']); foreach(L10n::$translations as $key => $val) { if($key == $lang) { - mysql_query("update `users` set `language`='$lang' where `id`='".intval($_SESSION['profile']['id'])."'"); + $db_conn->query("update `users` set `language`='$lang' where `id`='".intval($_SESSION['profile']['id'])."'"); $_SESSION['profile']['language'] = $lang; showheader(_("My CAcert.org Account!")); echo _("Your language setting has been updated."); @@ -2556,9 +2566,9 @@ function buildSubjectFromSession() { if($oldid == 41 && $_REQUEST['action'] == 'addsec') { csrf_check("seclang"); - $addlang = mysql_real_escape_string($_REQUEST['addlang']); + $addlang = $db_conn->real_escape_string($_REQUEST['addlang']); // Does the language exist? - mysql_query("insert into `addlang` set `userid`='".intval($_SESSION['profile']['id'])."', `lang`='$addlang'"); + $db_conn->query("insert into `addlang` set `userid`='".intval($_SESSION['profile']['id'])."', `lang`='$addlang'"); showheader(_("My CAcert.org Account!")); echo _("Your language setting has been updated."); showfooter(); @@ -2568,8 +2578,8 @@ function buildSubjectFromSession() { if($oldid == 41 && $_REQUEST['action'] == 'dellang') { csrf_check("seclang"); - $remove = mysql_real_escape_string($_REQUEST['remove']); - mysql_query("delete from `addlang` where `userid`='".intval($_SESSION['profile']['id'])."' and `lang`='$remove'"); + $remove = $db_conn->real_escape_string($_REQUEST['remove']); + $db_conn->query("delete from `addlang` where `userid`='".intval($_SESSION['profile']['id'])."' and `lang`='$remove'"); showheader(_("My CAcert.org Account!")); echo _("Your language setting has been updated."); showfooter(); @@ -2604,7 +2614,7 @@ function buildSubjectFromSession() { $regid = intval(array_key_exists('regid',$_REQUEST)?$_REQUEST['regid']:0); $newreg = intval(array_key_exists('newreg',$_REQUEST)?$_REQUEST['newreg']:0); $locid = intval(array_key_exists('locid',$_REQUEST)?$_REQUEST['locid']:0); - $name = array_key_exists('name',$_REQUEST)?mysql_real_escape_string(strip_tags($_REQUEST['name'])):""; + $name = array_key_exists('name',$_REQUEST)?$db_conn->real_escape_string(strip_tags($_REQUEST['name'])):""; $long = array_key_exists('longitude',$_REQUEST)?ereg_replace("[^-0-9\.]","",$_REQUEST['longitude']):""; $lat = array_key_exists('latitude', $_REQUEST)?ereg_replace("[^-0-9\.]","",$_REQUEST['latitude']):""; $action = array_key_exists('action',$_REQUEST)?$_REQUEST['action']:""; @@ -2612,58 +2622,60 @@ function buildSubjectFromSession() { if($locid > 0 && $action == "edit") { $query = "update `locations` set `name`='$name', `lat`='$lat', `long`='$long' where `id`='$locid'"; - mysql_query($query); - $row = mysql_fetch_assoc(mysql_query("select * from `locations` where `id`='$locid'")); + $db_conn->query($query); + $res = $db_conn->query("select * from `locations` where `id`='$locid'"); + $row = $res->fetch_assoc(); $_REQUEST['regid'] = $row['regid']; unset($_REQUEST['ccid']); unset($_REQUEST['locid']); unset($_REQUEST['action']); } else if($regid > 0 && $action == "edit") { $query = "update `regions` set `name`='$name' where `id`='$regid'"; - mysql_query($query); - $row = mysql_fetch_assoc(mysql_query("select * from `regions` where `id`='$regid'")); + $db_conn->query($query); + $res = $db_conn->query("select * from `regions` where `id`='$regid'"); + $row = $res->fetch_assoc(); $_REQUEST['ccid'] = $row['ccid']; unset($_REQUEST['regid']); unset($_REQUEST['locid']); unset($_REQUEST['action']); } else if($regid > 0 && $action == "add") { - $row = mysql_fetch_assoc(mysql_query("select `ccid` from `regions` where `id`='$regid'")); + $row = $db_conn->query("select `ccid` from `regions` where `id`='$regid'")->fetch_assoc(); $ccid = $row['ccid']; $query = "insert into `locations` set `ccid`='$ccid', `regid`='$regid', `name`='$name', `lat`='$lat', `long`='$long'"; - mysql_query($query); + $db_conn->query($query); unset($_REQUEST['ccid']); unset($_REQUEST['locid']); unset($_REQUEST['action']); } else if($ccid > 0 && $action == "add" && $name != "") { $query = "insert into `regions` set `ccid`='$ccid', `name`='$name'"; - mysql_query($query); - $row = mysql_fetch_assoc(mysql_query("select * from `locations` where `id`='$locid'")); + $db_conn->query($query); + $row = $db_conn->query("select * from `locations` where `id`='$locid'")->fetch_assoc(); unset($_REQUEST['regid']); unset($_REQUEST['locid']); unset($_REQUEST['action']); } else if($locid > 0 && $action == "delete") { - $row = mysql_fetch_assoc(mysql_query("select * from `locations` where `id`='$locid'")); + $row = $db_conn->query("select * from `locations` where `id`='$locid'")->fetch_assoc(); $_REQUEST['regid'] = $row['regid']; - mysql_query("delete from `localias` where `locid`='$locid'"); - mysql_query("delete from `locations` where `id`='$locid'"); + $db_conn->query("delete from `localias` where `locid`='$locid'"); + $db_conn->query("delete from `locations` where `id`='$locid'"); unset($_REQUEST['ccid']); unset($_REQUEST['locid']); unset($_REQUEST['action']); } else if($locid > 0 && $action == "move") { - $row = mysql_fetch_assoc(mysql_query("select * from `locations` where `id`='$locid'")); + $row = $db_conn->query("select * from `locations` where `id`='$locid'")->fetch_assoc(); $oldregid = $row['regid']; - mysql_query("update `locations` set `regid`='$newreg' where `id`='$locid'"); - mysql_query("update `users` set `regid`='$newreg' where `regid`='$oldregid'"); - $row = mysql_fetch_assoc(mysql_query("select * from `locations` where `id`='$locid'")); + $db_conn->query("update `locations` set `regid`='$newreg' where `id`='$locid'"); + $db_conn->query("update `users` set `regid`='$newreg' where `regid`='$oldregid'"); + $row = $db_conn->query("select * from `locations` where `id`='$locid'")->fetch_assoc(); $_REQUEST['regid'] = $row['regid']; unset($_REQUEST['ccid']); unset($_REQUEST['locid']); unset($_REQUEST['action']); } else if($regid > 0 && $action == "delete") { - $row = mysql_fetch_assoc(mysql_query("select * from `regions` where `id`='$regid'")); + $row = $db_conn->query("select * from `regions` where `id`='$regid'")->fetch_assoc(); $_REQUEST['ccid'] = $row['ccid']; - mysql_query("delete from `locations` where `regid`='$regid'"); - mysql_query("delete from `regions` where `id`='$regid'"); + $db_conn->query("delete from `locations` where `regid`='$regid'"); + $db_conn->query("delete from `regions` where `id`='$regid'"); unset($_REQUEST['regid']); unset($_REQUEST['locid']); unset($_REQUEST['action']); @@ -2672,12 +2684,12 @@ function buildSubjectFromSession() { $_REQUEST['action'] = "aliases"; $_REQUEST['locid'] = $locid; $name = htmlentities($name); - $row = mysql_query("insert into `localias` set `locid`='$locid',`name`='$name'"); + $row = $db_conn->query("insert into `localias` set `locid`='$locid',`name`='$name'"); } else if($locid > 0 && $action == "delalias") { $id = 54; $_REQUEST['action'] = "aliases"; $_REQUEST['locid'] = $locid; - $row = mysql_query("delete from `localias` where `locid`='$locid' and `name`='$name'"); + $row = $db_conn->query("delete from `localias` where `locid`='$locid' and `name`='$name'"); } } @@ -2714,15 +2726,15 @@ function buildSubjectFromSession() { showfooter(); exit; } - $fname = mysql_real_escape_string($_REQUEST['fname']); - $mname = mysql_real_escape_string($_REQUEST['mname']); - $lname = mysql_real_escape_string($_REQUEST['lname']); - $suffix = mysql_real_escape_string($_REQUEST['suffix']); + $fname = $db_conn->real_escape_string($_REQUEST['fname']); + $mname = $db_conn->real_escape_string($_REQUEST['mname']); + $lname = $db_conn->real_escape_string($_REQUEST['lname']); + $suffix = $db_conn->real_escape_string($_REQUEST['suffix']); $day = intval($_REQUEST['day']); $month = intval($_REQUEST['month']); $year = intval($_REQUEST['year']); $query = "update `users` set `fname`='$fname',`mname`='$mname',`lname`='$lname',`suffix`='$suffix',`dob`='$year-$month-$day' where `id`='$userid'"; - mysql_query($query); + $db_conn->query($query); }elseif($oldid == 43 && $actionrequest == "updatedob" && $ticketvalidation == FALSE){ $id = 43; $oldid=0; @@ -2761,7 +2773,7 @@ function buildSubjectFromSession() { if($id == 44) { $_REQUEST['userid'] = intval($_REQUEST['userid']); - $row = mysql_fetch_assoc(mysql_query("select * from `users` where `id`='".intval($_REQUEST['userid'])."'")); + $row = $db_conn->query("select * from `users` where `id`='".intval($_REQUEST['userid'])."'")->fetch_assoc(); if($row['email'] == "") $id = 42; else @@ -2781,8 +2793,8 @@ function buildSubjectFromSession() { showfooter(); exit; } - mysql_query("update `users` set `password`=sha1('".mysql_real_escape_string(stripslashes($_REQUEST['newpass']))."') where `id`='".intval($_REQUEST['userid'])."'"); - $row = mysql_fetch_assoc(mysql_query("select * from `users` where `id`='".intval($_REQUEST['userid'])."'")); + $db_conn->query("update `users` set `password`=sha1('".$db_conn->real_escape_string(stripslashes($_REQUEST['newpass']))."') where `id`='".intval($_REQUEST['userid'])."'"); + $row = $db_conn->query("select * from `users` where `id`='".intval($_REQUEST['userid'])."'")->fetch_assoc(); printf(_("The password for %s has been updated successfully in the system."), sanitizeHTML($row['email'])); $my_translation = L10n::get_translation(); @@ -2872,24 +2884,24 @@ function buildSubjectFromSession() { `CN`='".$_SESSION['_config']['0.CN']."', `domid`='".$_SESSION['_config']['row']['id']."', `created`=NOW()"; - mysql_query($query); - $CSRid = mysql_insert_id(); + $db_conn->query($query); + $CSRid = $db_conn->insert_id; foreach($_SESSION['_config']['rowid'] as $dom) - mysql_query("insert into `domlink` set `certid`='$CSRid', `domid`='".intval($dom)."'"); + $db_conn->query("insert into `domlink` set `certid`='$CSRid', `domid`='".intval($dom)."'"); if(is_array($_SESSION['_config']['altid'])) foreach($_SESSION['_config']['altid'] as $dom) - mysql_query("insert into `domlink` set `certid`='$CSRid', `domid`='".intval($dom)."'"); + $db_conn->query("insert into `domlink` set `certid`='$CSRid', `domid`='".intval($dom)."'"); $CSRname=generatecertpath("csr","server",$CSRid); $fp = fopen($CSRname, "w"); fputs($fp, $_SESSION['_config']['CSR']); fclose($fp); - mysql_query("update `domaincerts` set `CSR_name`='$CSRname' where `id`='$CSRid'"); + $db_conn->query("update `domaincerts` set `CSR_name`='$CSRname' where `id`='$CSRid'"); waitForResult("domaincerts", $CSRid,$oldid); $query = "select * from `domaincerts` where `id`='$CSRid' and `crt_name` != ''"; - $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!")); printf(_("Your certificate request has failed to be processed correctly, see %sthe WIKI page%s for reasons and solutions."), "", ""); @@ -2913,9 +2925,9 @@ function buildSubjectFromSession() { exit; } $query = "select * from `users` where `id`='$memid'"; - $row = mysql_fetch_assoc(mysql_query($query)); + $row = $db_conn->query($query)->fetch_assoc(); $ver = !$row['tverify']; - mysql_query("update `users` set `tverify`='$ver' where `id`='$memid'"); + $db_conn->query("update `users` set `tverify`='$ver' where `id`='$memid'"); }elseif($id == 43 && array_key_exists('tverify',$_REQUEST) && $_REQUEST['tverify'] > 0 && $ticketvalidation==FALSE){ $_SESSION['ticketmsg']='No action taken. Ticket number is missing!'; } @@ -2932,9 +2944,9 @@ function buildSubjectFromSession() { exit; } $query = "select * from `users` where `id`='$memid'"; - $row = mysql_fetch_assoc(mysql_query($query)); + $row = $db_conn->query($query)->fetch_assoc(); $ver = !$row['assurer']; - mysql_query("update `users` set `assurer`='$ver' where `id`='$memid'"); + $db_conn->query("update `users` set `assurer`='$ver' where `id`='$memid'"); }elseif($id == 43 && array_key_exists('assurer',$_REQUEST) && $_REQUEST['assurer'] > 0 && $ticketvalidation == FALSE){ $_REQUEST['userid'] = intval($_REQUEST['assurer']); $_SESSION['ticketmsg']='No action (Change assurer status) taken. Ticket number is missing!'; @@ -2950,9 +2962,9 @@ function buildSubjectFromSession() { exit; } $query = "select * from `users` where `id`='$memid'"; - $row = mysql_fetch_assoc(mysql_query($query)); + $row = $db_conn->query($query)->fetch_assoc(); $ver = !$row['assurer_blocked']; - mysql_query("update `users` set `assurer_blocked`='$ver' where `id`='$memid'"); + $db_conn->query("update `users` set `assurer_blocked`='$ver' where `id`='$memid'"); }elseif($id == 43 && array_key_exists('assurer_blocked',$_REQUEST) && $_REQUEST['assurer_blocked'] > 0 && $ticketvalidation == FALSE){ $_REQUEST['userid'] = intval($_REQUEST['assurer_blocked']); $_SESSION['ticketmsg']='No action taken. Ticket number is missing!'; @@ -2969,9 +2981,9 @@ function buildSubjectFromSession() { exit; } $query = "select * from `users` where `id`='$memid'"; - $row = mysql_fetch_assoc(mysql_query($query)); + $row = $db_conn->query($query)->fetch_assoc(); $ver = !$row['locked']; - mysql_query("update `users` set `locked`='$ver' where `id`='$memid'"); + $db_conn->query("update `users` set `locked`='$ver' where `id`='$memid'"); }elseif($id == 43 && array_key_exists('locked',$_REQUEST) && $_REQUEST['locked'] > 0 && $ticketvalidation == FALSE){ $_REQUEST['userid'] = intval($_REQUEST['locked']); $_SESSION['ticketmsg']='No action taken. Ticket number is missing!'; @@ -2988,9 +3000,9 @@ function buildSubjectFromSession() { exit; } $query = "select * from `users` where `id`='$memid'"; - $row = mysql_fetch_assoc(mysql_query($query)); + $row = $db_conn->query($query)->fetch_assoc(); $ver = !$row['codesign']; - mysql_query("update `users` set `codesign`='$ver' where `id`='$memid'"); + $db_conn->query("update `users` set `codesign`='$ver' where `id`='$memid'"); }elseif($id == 43 && array_key_exists('codesign',$_REQUEST) && $_REQUEST['codesign'] > 0 && $ticketvalidation == FALSE){ $_REQUEST['userid'] = intval($_REQUEST['codesign']); $_SESSION['ticketmsg']='No action taken. Ticket number is missing!'; @@ -3007,9 +3019,9 @@ function buildSubjectFromSession() { exit; } $query = "select * from `users` where `id`='$memid'"; - $row = mysql_fetch_assoc(mysql_query($query)); + $row = $db_conn->query($query)->fetch_assoc(); $ver = !$row['orgadmin']; - mysql_query("update `users` set `orgadmin`='$ver' where `id`='$memid'"); + $db_conn->query("update `users` set `orgadmin`='$ver' where `id`='$memid'"); }elseif($id == 43 && array_key_exists('orgadmin',$_REQUEST) && $_REQUEST['orgadmin'] > 0 && $ticketvalidation == FALSE){ $_REQUEST['userid'] = intval($_REQUEST['orgadmin']); $_SESSION['ticketmsg']='No action taken. Ticket number is missing!'; @@ -3026,9 +3038,9 @@ function buildSubjectFromSession() { exit; } $query = "select * from `users` where `id`='$memid'"; - $row = mysql_fetch_assoc(mysql_query($query)); + $row = $db_conn->query($query)->fetch_assoc(); $ver = !$row['ttpadmin']; - mysql_query("update `users` set `ttpadmin`='$ver' where `id`='$memid'"); + $db_conn->query("update `users` set `ttpadmin`='$ver' where `id`='$memid'"); }elseif($id == 43 && array_key_exists('ttpadmin',$_REQUEST) && $_REQUEST['ttpadmin'] > 0 && $ticketvalidation == FALSE){ $_REQUEST['userid'] = intval($_REQUEST['ttpadmin']); $_SESSION['ticketmsg']='No action taken. Ticket number is missing!'; @@ -3044,11 +3056,11 @@ function buildSubjectFromSession() { exit; } $query = "select * from `users` where `id`='$memid'"; - $row = mysql_fetch_assoc(mysql_query($query)); + $row = $db_conn->query($query)->fetch_assoc(); $ver = $row['adadmin'] + 1; if($ver > 2) $ver = 0; - mysql_query("update `users` set `adadmin`='$ver' where `id`='$memid'"); + $db_conn->query("update `users` set `adadmin`='$ver' where `id`='$memid'"); }elseif($id == 43 && array_key_exists('adadmin',$_REQUEST) && $_REQUEST['adadmin'] > 0 && $ticketvalidation == FALSE){ $_REQUEST['userid'] = intval($_REQUEST['adadmin']); $_SESSION['ticketmsg']='No action taken. Ticket number is missing!'; @@ -3064,9 +3076,9 @@ function buildSubjectFromSession() { exit; } $query = "select * from `users` where `id`='$memid'"; - $row = mysql_fetch_assoc(mysql_query($query)); + $row = $db_conn->query($query)->fetch_assoc(); $ver = !$row['locadmin']; - mysql_query("update `users` set `locadmin`='$ver' where `id`='$memid'"); + $db_conn->query("update `users` set `locadmin`='$ver' where `id`='$memid'"); }elseif($id == 43 && array_key_exists('locadmin',$_REQUEST) && $_REQUEST['locadmin'] > 0 && $ticketvalidation == FALSE){ $_REQUEST['userid'] = intval($_REQUEST['locadmin']); $_SESSION['ticketmsg']='No action taken. Ticket number is missing!'; @@ -3083,9 +3095,9 @@ function buildSubjectFromSession() { exit; } $query = "select * from `users` where `id`='$memid'"; - $row = mysql_fetch_assoc(mysql_query($query)); + $row = $db_conn->query($query)->fetch_assoc(); $ver = !$row['admin']; - mysql_query("update `users` set `admin`='$ver' where `id`='$memid'"); + $db_conn->query("update `users` set `admin`='$ver' where `id`='$memid'"); }elseif($id == 43 && array_key_exists('admin',$_REQUEST) && $_REQUEST['admin'] > 0 && $ticketvalidation == FALSE){ $_REQUEST['userid'] = intval($_REQUEST['admin']); $_SESSION['ticketmsg']='No action taken. Ticket number is missing!'; @@ -3101,9 +3113,9 @@ function buildSubjectFromSession() { exit; } $query = "select * from `alerts` where `memid`='$memid'"; - $row = mysql_fetch_assoc(mysql_query($query)); + $row = $db_conn->query($query)->fetch_assoc(); $ver = !$row['general']; - mysql_query("update `alerts` set `general`='$ver' where `memid`='$memid'"); + $db_conn->query("update `alerts` set `general`='$ver' where `memid`='$memid'"); }elseif($id == 43 && array_key_exists('general',$_REQUEST) && $_REQUEST['general'] > 0 && $ticketvalidation == FALSE){ $_REQUEST['userid'] = intval($_REQUEST['general']); $_SESSION['ticketmsg']='No action taken. Ticket number is missing!'; @@ -3119,9 +3131,9 @@ function buildSubjectFromSession() { exit; } $query = "select * from `alerts` where `memid`='$memid'"; - $row = mysql_fetch_assoc(mysql_query($query)); + $row = $db_conn->query($query)->fetch_assoc(); $ver = !$row['country']; - mysql_query("update `alerts` set `country`='$ver' where `memid`='$memid'"); + $db_conn->query("update `alerts` set `country`='$ver' where `memid`='$memid'"); }elseif($id == 43 && array_key_exists('country',$_REQUEST) && $_REQUEST['country'] > 0 && $ticketvalidation == FALSE){ $_REQUEST['userid'] = intval($_REQUEST['country']); $_SESSION['ticketmsg']='No action taken. Ticket number is missing!'; @@ -3137,9 +3149,9 @@ function buildSubjectFromSession() { exit; } $query = "select * from `alerts` where `memid`='$memid'"; - $row = mysql_fetch_assoc(mysql_query($query)); + $row = $db_conn->query($query)->fetch_assoc(); $ver = !$row['regional']; - mysql_query("update `alerts` set `regional`='$ver' where `memid`='$memid'"); + $db_conn->query("update `alerts` set `regional`='$ver' where `memid`='$memid'"); }elseif($id == 43 && array_key_exists('regional',$_REQUEST) && $_REQUEST['regional'] > 0 && $ticketvalidation == FALSE){ $_REQUEST['userid'] = intval($_REQUEST['regional']); $_SESSION['ticketmsg']='No action taken. Ticket number is missing!'; @@ -3155,9 +3167,9 @@ function buildSubjectFromSession() { exit; } $query = "select * from `alerts` where `memid`='$memid'"; - $row = mysql_fetch_assoc(mysql_query($query)); + $row = $db_conn->query($query)->fetch_assoc(); $ver = !$row['radius']; - mysql_query("update `alerts` set `radius`='$ver' where `memid`='$memid'"); + $db_conn->query("update `alerts` set `radius`='$ver' where `memid`='$memid'"); }elseif($id == 43 && array_key_exists('radius',$_REQUEST) && $_REQUEST['radius'] > 0 && $ticketvalidation == false){ $_REQUEST['userid'] = intval($_REQUEST['radius']); $_SESSION['ticketmsg']='No action taken. Ticket number is missing!'; @@ -3169,7 +3181,7 @@ function buildSubjectFromSession() { $_REQUEST['userid'] = intval($_REQUEST['userid']); } - $row = mysql_fetch_assoc(mysql_query("select * from `users` where `id`='".intval($_REQUEST['userid'])."'")); + $row = $db_conn->query("select * from `users` where `id`='".intval($_REQUEST['userid'])."'")->fetch_assoc(); if($row['email'] == "") { $id = 42; } else { @@ -3216,7 +3228,7 @@ function buildSubjectFromSession() { showfooter(); exit; } - if (check_is_orgadmin(intval($_REQUEST['userid']),1)) { + if (check_is_orgadmin(intval($_REQUEST['userid']))) { showheader(_("My CAcert.org Account!")); printf(_("The user is listed as Organisation Administrator. Can't continue.")); printf('
    ' . _('Back to previous page.') .''); diff --git a/includes/account_stuff.php b/includes/account_stuff.php index 0fda2f1a..524be4d2 100644 --- a/includes/account_stuff.php +++ b/includes/account_stuff.php @@ -1,6 +1,6 @@ ">

    - +
    - 0 || $_SESSION['profile']['orgadmin'] == 1) { ?> +query("select * from `org` where `memid`='".intval($_SESSION['profile']['id'])."'") + ->num_rows > 0 || $_SESSION['profile']['orgadmin'] == 1) { ?> - 0 || $_SESSION['profile']['orgadmin'] == 1) { ?> +query("select * from `org` where `memid`='".intval($_SESSION['profile']['id'])."'")->num_rows > 0 || $_SESSION['profile']['orgadmin'] == 1) { ?>