All mysql_-statments replaced by their corresponding mysqli_-statements
[cacert-devel.git] / scripts / scanforexponents.php
1 #!/usr/bin/php -q
2 <? /*
3 LibreSSL - CAcert web application
4 Copyright (C) 2004-2008 CAcert Inc.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; version 2 of the License.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19 include_once("../includes/mysql.php");
20
21 $fp = fopen("exp-report.txt", "w");
22
23 $d = dir("../crt/");
24 while (false !== ($entry = $d->read()))
25 {
26 if(substr($entry, 0, 3) == "gpg")
27 continue;
28 $file = "../crt/$entry";
29 if(!is_file($file))
30 continue;
31
32 $file_esc = escapeshellarg($file);
33 if(substr($file, -3) == "der")
34 $do = trim(`openssl x509 -inform der -in $file_esc -text -noout 2>&1 |grep 'Exponent'`);
35 else
36 $do = trim(`openssl x509 -in $file_esc -text -noout 2>&1 |grep 'Exponent'`);
37
38 if($do == "")
39 continue;
40
41 list($crud, $exp, $crud) = explode(" ", $do);
42 if($exp >= 65537)
43 continue;
44
45 list($a, $crud) = explode(".", $entry, 2);
46 list($type, $id) = explode("-", $a);
47
48 $id = intval($id);
49
50 if($type == "client")
51 {
52 $query = "select `memid`,`serial`,`CN`,`subject`,`keytype`,`emailcerts`.`codesign` as `codesign`,`crt_name`,
53 `emailcerts`.`created` as `created`,`emailcerts`.`revoked` as `revoked`,
54 `emailcerts`.`expire` as `expire`, `rootcert`, `md`, `fname`, `lname`, `language`
55 from `emailcerts`,`users` where `emailcerts`.`id`='$id' and `users`.`id`=`emailcerts`.`memid`";
56 $res = mysqli_query($_SESSION['mconn'], $query);
57 if(mysqli_num_rows($res) <= 0)
58 {
59 echo $query."\n";
60 echo "$file: $do\n";
61 continue;
62 }
63
64 $row = mysqli_fetch_assoc($res);
65 $email = $row['email'];
66 } else if($type == "orgclient") {
67 $query = "select `memid`,`serial`,`CN`,`subject`,`keytype`,`orgemailcerts`.`codesign` as `codesign`,`crt_name`,
68 `orgemailcerts`.`created` as `created`,`orgemailcerts`.`revoked` as `revoked`,
69 `orgemailcerts`.`expire` as `expire`, `rootcert`, `md`, `fname`, `lname`, `language`
70 from `orgemailcerts`,`org`,`users` where `orgemailcerts`.`id`='$id' and
71 `orgemailcerts`.`orgid`=`org`.`id` and `users`.`id`=`org`.`memid`";
72 $res = mysqli_query($_SESSION['mconn'], $query);
73 if(mysqli_num_rows($res) <= 0)
74 {
75 echo $query."\n";
76 echo "$file: $do\n";
77 continue;
78 }
79
80 $row = mysqli_fetch_assoc($res);
81 $email = $row['email'];
82 } else if($type == "server") {
83 $query = "select `memid`,`serial`,`CN`,`subject`,`crt_name`,
84 `domaincerts`.`created` as `created`,`domaincerts`.`revoked` as `revoked`,
85 `domaincerts`.`expire` as `expire`, `rootcert`, `md`, `fname`, `lname`, `language`
86 from `domaincerts`,`domains`,`users` where `domaincerts`.`id`='$id' and
87 `domains`.`id`=`domaincerts`.`domid` and `users`.`id`=`domains`.`memid`";
88 $res = mysqli_query($_SESSION['mconn'], $query);
89 if(mysqli_num_rows($res) <= 0)
90 {
91 echo $query."\n";
92 echo "$file: $do\n";
93 continue;
94 }
95
96 $row = mysqli_fetch_assoc($res);
97 $email = $row['email'];
98 } else if($type == "orgserver") {
99 $query = "select `memid`,`serial`,`CN`,`subject`,`crt_name`,
100 `orgdomaincerts`.`created` as `created`,`orgdomaincerts`.`revoked` as `revoked`,
101 `orgdomaincerts`.`expire` as `expire`, `rootcert`, `md`, `fname`, `lname`, `language`
102 from `orgdomaincerts`,`org`,`users` where `orgdomaincerts`.`id`='$id' and
103 `orgdomaincerts`.`orgid`=`org`.`id` and `users`.`id`=`org`.`memid`";
104 $res = mysqli_query($_SESSION['mconn'], $query);
105 if(mysqli_num_rows($res) <= 0)
106 {
107 echo $query."\n";
108 echo "$file: $do\n";
109 continue;
110 }
111
112 $row = mysqli_fetch_assoc($res);
113 $email = $row['email'];
114 } else {
115 echo "$file: $do\n";
116 continue;
117 }
118
119 $body = "New Report:\n\n$do\n";
120
121 foreach($row as $key => $val)
122 $body .= "$key: $val\n";
123
124 $body .= "\n\n".file_get_contents($file);
125 fputs($fp, $body."\n\n===============================================================\n\n");
126 echo "$file: $do\n";
127 }
128 ?>