11<?php
22require_once 'StdinMailParser.php ' ;
3- require_once 'ConfigLoader.php ' ;
43
54/**
65 * Sendmail Wrapper by Onlime GmbH webhosting services
@@ -16,48 +15,31 @@ class SendmailThrottle extends StdinMailParser
1615 const STATUS_BLOCKED = 3 ;
1716 const STATUS_EXCEPTION = 4 ;
1817
19- /**
20- * @var StdClass
21- */
22- protected $ _conf ;
23-
2418 /**
2519 * @var PDO
2620 */
27- protected $ _pdo ;
28-
29- /**
30- * Constructor
31- */
32- public function __construct ()
33- {
34- // load configuration
35- $ configLoader = new ConfigLoader ();
36- $ this ->_conf = $ configLoader ->getConfig ();
37-
38- parent ::__construct ();
39- }
21+ protected $ pdo ;
4022
4123 /**
4224 * Destructor
4325 * close the PDO database connection
4426 */
4527 public function __destruct ()
4628 {
47- $ this ->_pdo = null ;
29+ $ this ->pdo = null ;
4830 }
4931
5032 /**
5133 * Create PDO database connection
5234 *
5335 * @throws PDOException
5436 */
55- protected function _connect ()
37+ protected function connect ()
5638 {
57- $ this ->_pdo = new PDO (
58- $ this ->_conf ->db ->dsn ,
59- $ this ->_conf ->db ->user ,
60- $ this ->_conf ->db ->pass
39+ $ this ->pdo = new PDO (
40+ $ this ->conf ->db ->dsn ,
41+ $ this ->conf ->db ->user ,
42+ $ this ->conf ->db ->pass
6143 );
6244 }
6345
@@ -77,13 +59,13 @@ public function run($username, $rcptCount)
7759 {
7860 try {
7961 // connect to DB
80- $ this ->_connect ();
62+ $ this ->connect ();
8163
8264 // default status code: success
8365 $ status = self ::STATUS_OK ;
8466
8567 $ sql = 'SELECT * FROM throttle WHERE username = :username ' ;
86- $ stmt = $ this ->_pdo ->prepare ($ sql );
68+ $ stmt = $ this ->pdo ->prepare ($ sql );
8769 $ stmt ->bindParam (':username ' , $ username );
8870 $ stmt ->execute ();
8971 $ throttle = $ stmt ->fetchObject ();
@@ -114,7 +96,7 @@ public function run($username, $rcptCount)
11496 $ sql = 'UPDATE throttle SET updated_ts = NOW(), count_cur = :countCur, count_tot = :countTot,
11597 rcpt_cur = :rcptCur, rcpt_tot = :rcptTot, status = :status
11698 WHERE username = :username ' ;
117- $ stmt = $ this ->_pdo ->prepare ($ sql );
99+ $ stmt = $ this ->pdo ->prepare ($ sql );
118100 $ stmt ->bindParam (':countCur ' , $ countCur , PDO ::PARAM_INT );
119101 $ stmt ->bindParam (':countTot ' , $ countTot , PDO ::PARAM_INT );
120102 $ stmt ->bindParam (':rcptCur ' , $ rcptCur , PDO ::PARAM_INT );
@@ -129,30 +111,30 @@ public function run($username, $rcptCount)
129111 $ status = self ::STATUS_BLOCKED ;
130112 }
131113 } else {
132- $ countMax = $ this ->_conf ->throttle ->countMax ;
114+ $ countMax = $ this ->conf ->throttle ->countMax ;
133115 $ countCur = 1 ;
134116 $ countTot = 1 ;
135- $ rcptMax = $ this ->_conf ->throttle ->rcptMax ;
117+ $ rcptMax = $ this ->conf ->throttle ->rcptMax ;
136118 $ rcptCur = $ rcptCount ;
137119 $ rcptTot = $ rcptCount ;
138120
139121 $ sql = 'INSERT INTO throttle (updated_ts, username, count_max, rcpt_max, rcpt_cur, rcpt_tot)
140122 VALUES (NOW(), :username, :countMax, :rcptMax, :rcptCur, :rcptTot) ' ;
141- $ stmt = $ this ->_pdo ->prepare ($ sql );
123+ $ stmt = $ this ->pdo ->prepare ($ sql );
142124 $ stmt ->bindParam (':username ' , $ username );
143125 $ stmt ->bindParam (':countMax ' , $ countMax , PDO ::PARAM_INT );
144126 $ stmt ->bindParam (':rcptMax ' , $ rcptMax , PDO ::PARAM_INT );
145127 $ stmt ->bindParam (':rcptCur ' , $ rcptCur , PDO ::PARAM_INT );
146128 $ stmt ->bindParam (':rcptTot ' , $ rcptTot , PDO ::PARAM_INT );
147129 $ stmt ->execute ();
148- $ id = $ this ->_pdo ->lastInsertId ();
130+ $ id = $ this ->pdo ->lastInsertId ();
149131 }
150132
151133 // syslogging
152134 $ syslogMsg = sprintf ('%s: user=%s (%s:%s), rcpts=%s, status=%s, command=%s, ' .
153135 'count_max=%s, count_cur=%s, count_tot=%s, ' .
154136 'rcpt_max=%s, rcpt_cur=%s, rcpt_tot=%s ' ,
155- $ this ->_conf ->throttle ->syslogPrefix ,
137+ $ this ->conf ->throttle ->syslogPrefix ,
156138 $ username ,
157139 $ _SERVER ['SUDO_UID ' ],
158140 $ _SERVER ['SUDO_GID ' ],
@@ -177,19 +159,19 @@ public function run($username, $rcptCount)
177159 // Do not report on status code 2, as the admin only wants to get notified once!
178160 // Also, he is never interested in blocked accounts (status code 3).
179161 mail (
180- $ this ->_conf ->global ->adminTo ,
181- $ this ->_conf ->throttle ->adminSubject ,
162+ $ this ->conf ->global ->adminTo ,
163+ $ this ->conf ->throttle ->adminSubject ,
182164 $ syslogMsg ,
183- "From: " . $ this ->_conf ->global ->adminFrom
165+ "From: " . $ this ->conf ->global ->adminFrom
184166 );
185167 }
186168
187169 // write all meta information to db messages log
188- $ this ->_logMessage ($ id , $ username , $ rcptCount , $ status );
170+ $ this ->logMessage ($ id , $ username , $ rcptCount , $ status );
189171
190172 return $ status ;
191173 } catch (PDOException $ e ) {
192- syslog (LOG_WARNING , sprintf ('%s: PDOException: %s ' , $ this ->_conf ->throttle ->syslogPrefix , $ e ->getMessage ()));
174+ syslog (LOG_WARNING , sprintf ('%s: PDOException: %s ' , $ this ->conf ->throttle ->syslogPrefix , $ e ->getMessage ()));
193175 return self ::STATUS_EXCEPTION ;
194176 }
195177 }
@@ -203,7 +185,7 @@ public function run($username, $rcptCount)
203185 * @param int $rcptCount
204186 * @param int $status
205187 */
206- protected function _logMessage ($ throttleId , $ username , $ rcptCount , $ status )
188+ protected function logMessage ($ throttleId , $ username , $ rcptCount , $ status )
207189 {
208190 $ headerArr = $ this ->getParsedHeaderArr ();
209191 $ from = mb_decode_mimeheader ($ headerArr ['from ' ] ?? null );
@@ -216,7 +198,7 @@ protected function _logMessage($throttleId, $username, $rcptCount, $status)
216198 cc_addr, bcc_addr, subject, site, client, sender_host, script)
217199 VALUES (:throttleId, :username, :uid, :gid, :rcptCount, :status, :msgid, :fromAddr, :toAddr,
218200 :ccAddr, :bccAddr, :subject, :site, :client, SUBSTRING_INDEX(USER(), '@', -1), :script) " ;
219- $ stmt = $ this ->_pdo ->prepare ($ sql );
201+ $ stmt = $ this ->pdo ->prepare ($ sql );
220202 $ stmt ->bindParam (':throttleId ' , $ throttleId );
221203 $ stmt ->bindParam (':username ' , $ username );
222204 $ stmt ->bindParam (':uid ' , $ _SERVER ['SUDO_UID ' ]);
0 commit comments