6ed23e074ca8c0424502c62d86dd178649127fd0
[cacert.git] / cacert / includes / mysql.php.sample
1 <? /*
2 LibreSSL - CAcert web application
3 Copyright (C) 2004-2008 CAcert Inc.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; version 2 of the License.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 mysql_connect("localhost", "username", "password");
20 mysql_select_db("database");
21
22 $_SESSION['_config']['normalhostname'] = "www.cacert.org";
23 $_SESSION['_config']['securehostname'] = "secure.cacert.org";
24 $_SESSION['_config']['tverify'] = "tverify.cacert.org";
25
26 function sendmail($to, $subject, $message, $from, $replyto = "", $toname = "", $fromname = "", $errorsto = "returns@cacert.org", $extra="")
27 {
28 $lines = explode('\n', $message);
29 $message = "";
30 foreach($lines as $line)
31 {
32 $line = trim($line);
33 if($line == ".")
34 $message .= " .\n";
35 else
36 $message .= $line."\n";
37 }
38
39 if($fromname == "")
40 $fromname = $from;
41
42 $bits = explode(",", $from);
43 $from = addslashes($bits['0']);
44 $fromname = addslashes($fromname);
45
46 $smtp = fsockopen("localhost", 25);
47 if(!$smtp)
48 {
49 echo("Could not connect to mailserver at localhost:25\n");
50 return;
51 }
52 $InputBuffer = fgets($smtp, 1024);
53 fputs($smtp, "HELO hlin.cacert.org\r\n");
54 $InputBuffer = fgets($smtp, 1024);
55 fputs($smtp, "MAIL FROM: <returns@cacert.org>\r\n");
56 $InputBuffer = fgets($smtp, 1024);
57 $bits = explode(",", $to);
58 foreach($bits as $user)
59 fputs($smtp, "RCPT TO: <".trim($user).">\r\n");
60 $InputBuffer = fgets($smtp, 1024);
61 fputs($smtp, "DATA\r\n");
62 $InputBuffer = fgets($smtp, 1024);
63 fputs($smtp, "X-Mailer: CAcert.org Website\r\n");
64 fputs($smtp, "X-OriginatingIP: ".$_SERVER["REMOTE_ADDR"]."\r\n");
65 fputs($smtp, "Sender: $errorsto\r\n");
66 fputs($smtp, "Errors-To: $errorsto\r\n");
67 if($replyto != "")
68 fputs($smtp, "Reply-To: $replyto\r\n");
69 else
70 fputs($smtp, "Reply-To: $from\r\n");
71 fputs($smtp, "From: $from\r\n");
72 fputs($smtp, "To: $to\r\n");
73 if(preg_match("/[^a-zA-Z0-9 .-\[\]!_@]/",$subject))
74 {
75 fputs($smtp, "Subject: =?utf-8?B?".base64_encode(recode("html..utf-8", $subject))."?=\r\n");
76 }
77 else
78 {
79 fputs($smtp, "Subject: $subject\r\n");
80 }
81 fputs($smtp, "Mime-Version: 1.0\r\n");
82 if($extra == "")
83 {
84 fputs($smtp, "Content-Type: text/plain; charset=\"utf-8\"\r\n");
85 fputs($smtp, "Content-Transfer-Encoding: 8bit\r\n");
86 } else {
87 fputs($smtp, "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n");
88 fputs($smtp, "Content-Transfer-Encoding: quoted-printable\r\n");
89 fputs($smtp, "Content-Disposition: inline\r\n");
90 }
91 // fputs($smtp, "Content-Transfer-Encoding: BASE64\r\n");
92 fputs($smtp, "\r\n");
93 // fputs($smtp, chunk_split(base64_encode(recode("html..utf-8", $message)))."\r\n.\r\n");
94 fputs($smtp, recode("html..utf-8", $message)."\r\n.\r\n");
95 fputs($smtp, "QUIT\n");
96 $InputBuffer = fgets($smtp, 1024);
97 fclose($smtp);
98 }
99
100 function make_hash()
101 {
102 if(function_exists("dio_open"))
103 {
104 $rnd = dio_open("/dev/urandom",O_RDONLY);
105 $hash = md5(dio_read($rnd,64));
106 dio_close($rnd);
107 } else {
108 $rnd = fopen("/dev/urandom", "r");
109 $hash = md5(fgets($rnd, 64));
110 fclose($rnd);
111 }
112 return($hash);
113 }
114
115 function clean_csr($CSR)
116 {
117 return(preg_replace("/[^A-Za-z0-9\n\r\-\:\=\+\/ ]/","",$CSR));
118 }
119 ?>