filters.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796
  1. <?php
  2. /**
  3. * Message and Spam Filter Plugin - Filtering Functions
  4. *
  5. * This plugin filters your inbox into different folders based upon given
  6. * criteria. It is most useful for people who are subscibed to mailing lists
  7. * to help organize their messages. The argument stands that filtering is
  8. * not the place of the client, which is why this has been made a plugin for
  9. * SquirrelMail. You may be better off using products such as Sieve or
  10. * Procmail to do your filtering so it happens even when SquirrelMail isn't
  11. * running.
  12. *
  13. * If you need help with this, or see improvements that can be made, please
  14. * email me directly at the address above. I definately welcome suggestions
  15. * and comments. This plugin, as is the case with all SquirrelMail plugins,
  16. * is not directly supported by the developers. Please come to me off the
  17. * mailing list if you have trouble with it.
  18. *
  19. * Also view plugins/README.plugins for more information.
  20. *
  21. * @version $Id$
  22. * @copyright (c) 1999-2005 The SquirrelMail Project Team
  23. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  24. * @package plugins
  25. * @subpackage filters
  26. */
  27. /**
  28. * FIXME: Undocumented function
  29. * @access private
  30. */
  31. function filters_SaveCache () {
  32. global $data_dir, $SpamFilters_DNScache;
  33. if (file_exists($data_dir . '/dnscache')) {
  34. $fp = fopen($data_dir . '/dnscache', 'r');
  35. } else {
  36. $fp = false;
  37. }
  38. if ($fp) {
  39. flock($fp,LOCK_EX);
  40. } else {
  41. $fp = fopen($data_dir . '/dnscache', 'w+');
  42. fclose($fp);
  43. $fp = fopen($data_dir . '/dnscache', 'r');
  44. flock($fp,LOCK_EX);
  45. }
  46. $fp1=fopen($data_dir . '/dnscache', 'w+');
  47. foreach ($SpamFilters_DNScache as $Key=> $Value) {
  48. $tstr = $Key . ',' . $Value['L'] . ',' . $Value['T'] . "\n";
  49. fputs ($fp1, $tstr);
  50. }
  51. fclose($fp1);
  52. flock($fp,LOCK_UN);
  53. fclose($fp);
  54. }
  55. /**
  56. * FIXME: Undocumented function
  57. * @access private
  58. */
  59. function filters_LoadCache () {
  60. global $data_dir, $SpamFilters_DNScache;
  61. if (file_exists($data_dir . '/dnscache')) {
  62. $SpamFilters_DNScache = array();
  63. if ($fp = fopen ($data_dir . '/dnscache', 'r')) {
  64. flock($fp,LOCK_SH);
  65. while ($data=fgetcsv($fp,1024)) {
  66. if ($data[2] > time()) {
  67. $SpamFilters_DNScache[$data[0]]['L'] = $data[1];
  68. $SpamFilters_DNScache[$data[0]]['T'] = $data[2];
  69. }
  70. }
  71. flock($fp,LOCK_UN);
  72. }
  73. }
  74. }
  75. /**
  76. * FIXME: Undocumented function
  77. * @access private
  78. */
  79. function filters_bulkquery($filters, $IPs) {
  80. global $attachment_dir, $username,
  81. $SpamFilters_DNScache, $SpamFilters_BulkQuery,
  82. $SpamFilters_CacheTTL;
  83. if (count($IPs) > 0) {
  84. $rbls = array();
  85. foreach ($filters as $key => $value) {
  86. if ($filters[$key]['enabled']) {
  87. if ($filters[$key]['dns']) {
  88. $rbls[$filters[$key]['dns']] = true;
  89. }
  90. }
  91. }
  92. $bqfil = $attachment_dir . $username . '-bq.in';
  93. $fp = fopen($bqfil, 'w');
  94. fputs ($fp, $SpamFilters_CacheTTL . "\n");
  95. foreach ($rbls as $key => $value) {
  96. fputs ($fp, '.' . $key . "\n");
  97. }
  98. fputs ($fp, "----------\n");
  99. foreach ($IPs as $key => $value) {
  100. fputs ($fp, $key . "\n");
  101. }
  102. fclose ($fp);
  103. $bqout = array();
  104. exec ($SpamFilters_BulkQuery . ' < ' . $bqfil, $bqout);
  105. foreach ($bqout as $value) {
  106. $Chunks = explode(',', $value);
  107. $SpamFilters_DNScache[$Chunks[0]]['L'] = $Chunks[1];
  108. $SpamFilters_DNScache[$Chunks[0]]['T'] = $Chunks[2] + time();
  109. }
  110. unlink($bqfil);
  111. }
  112. }
  113. /**
  114. * FIXME: Undocumented function
  115. * @access private
  116. */
  117. function start_filters() {
  118. global $imapServerAddress, $imapPort, $imap_stream, $imapConnection,
  119. $UseSeparateImapConnection, $AllowSpamFilters;
  120. sqgetGlobalVar('username', $username, SQ_SESSION);
  121. sqgetGlobalVar('key', $key, SQ_COOKIE);
  122. // Detect if we have already connected to IMAP or not.
  123. // Also check if we are forced to use a separate IMAP connection
  124. if ((!isset($imap_stream) && !isset($imapConnection)) ||
  125. $UseSeparateImapConnection ) {
  126. $stream = sqimap_login($username, $key, $imapServerAddress,
  127. $imapPort, 10);
  128. $previously_connected = false;
  129. } else if (isset($imapConnection)) {
  130. $stream = $imapConnection;
  131. $previously_connected = true;
  132. } else {
  133. $previously_connected = true;
  134. $stream = $imap_stream;
  135. }
  136. $aStatus = sqimap_status_messages ($stream, 'INBOX', array('MESSAGES'));
  137. if ($aStatus['MESSAGES']) {
  138. sqimap_mailbox_select($stream, 'INBOX');
  139. // Filter spam from inbox before we sort them into folders
  140. if ($AllowSpamFilters) {
  141. spam_filters($stream);
  142. }
  143. // Sort into folders
  144. user_filters($stream);
  145. }
  146. if (!$previously_connected) {
  147. sqimap_logout($stream);
  148. }
  149. }
  150. /**
  151. * FIXME: Undocumented function
  152. * @access private
  153. */
  154. function user_filters($imap_stream) {
  155. global $data_dir, $username;
  156. $filters = load_filters();
  157. if (! $filters) return;
  158. $filters_user_scan = getPref($data_dir, $username, 'filters_user_scan');
  159. $expunge = false;
  160. // For every rule
  161. for ($i=0, $num = count($filters); $i < $num; $i++) {
  162. // If it is the "combo" rule
  163. if ($filters[$i]['where'] == 'To or Cc') {
  164. /*
  165. * If it's "TO OR CC", we have to do two searches, one for TO
  166. * and the other for CC.
  167. */
  168. $expunge = filter_search_and_delete($imap_stream, 'TO',
  169. $filters[$i]['what'], $filters[$i]['folder'], $filters_user_scan, $expunge);
  170. $expunge = filter_search_and_delete($imap_stream, 'CC',
  171. $filters[$i]['what'], $filters[$i]['folder'], $filters_user_scan, $expunge);
  172. } else {
  173. /*
  174. * If it's a normal TO, CC, SUBJECT, or FROM, then handle it
  175. * normally.
  176. */
  177. $expunge = filter_search_and_delete($imap_stream, $filters[$i]['where'],
  178. $filters[$i]['what'], $filters[$i]['folder'], $filters_user_scan, $expunge);
  179. }
  180. }
  181. // Clean out the mailbox whether or not auto_expunge is on
  182. // That way it looks like it was redirected properly
  183. if ($expunge) {
  184. sqimap_mailbox_expunge($imap_stream, 'INBOX');
  185. }
  186. }
  187. /**
  188. * FIXME: Undocumented function
  189. * @access private
  190. */
  191. function filter_search_and_delete($imap_stream, $where, $what, $where_to, $user_scan,
  192. $should_expunge) {
  193. global $languages, $squirrelmail_language, $allow_charset_search, $imap_server_type;
  194. if ($user_scan == 'new') {
  195. $category = 'UNSEEN';
  196. } else {
  197. $category = 'ALL';
  198. }
  199. if ($allow_charset_search &&
  200. isset($languages[$squirrelmail_language]['CHARSET']) &&
  201. $languages[$squirrelmail_language]['CHARSET']) {
  202. $search_str = 'SEARCH CHARSET '
  203. . strtoupper($languages[$squirrelmail_language]['CHARSET'])
  204. . ' ' . $category;
  205. } else {
  206. $search_str = 'SEARCH CHARSET US-ASCII ' . $category;
  207. }
  208. if ($where == 'Header') {
  209. $what = explode(':', $what);
  210. $where = trim($where . ' ' . $what[0]);
  211. $what = addslashes(trim($what[1]));
  212. }
  213. // see comments in squirrelmail sqimap_search function
  214. if ($imap_server_type == 'macosx' || $imap_server_type == 'hmailserver') {
  215. $search_str .= ' ' . $where . ' ' . $what;
  216. } else {
  217. $search_str .= ' ' . $where . ' {' . strlen($what) . "}\r\n"
  218. . $what . "\r\n";
  219. }
  220. /* read data back from IMAP */
  221. $read = sqimap_run_command($imap_stream, $search_str, true, $response, $message, TRUE);
  222. if (isset($read[0])) {
  223. $ids = array();
  224. for ($i=0,$iCnt=count($read);$i<$iCnt;++$i) {
  225. if (preg_match("/^\* SEARCH (.+)$/", $read[$i], $regs)) {
  226. $ids = preg_split("/ /", trim($regs[1]));
  227. break;
  228. }
  229. }
  230. if ($response == 'OK' && count($ids)) {
  231. if (sqimap_mailbox_exists($imap_stream, $where_to)) {
  232. $should_expunge = true;
  233. sqimap_msgs_list_move ($imap_stream, $ids, $where_to);
  234. }
  235. }
  236. }
  237. return $should_expunge;
  238. }
  239. /**
  240. * FIXME: Undocumented function
  241. * @access private
  242. */
  243. function spam_filters($imap_stream) {
  244. global $data_dir, $username;
  245. global $SpamFilters_YourHop;
  246. global $SpamFilters_DNScache;
  247. global $SpamFilters_SharedCache;
  248. global $SpamFilters_BulkQuery;
  249. global $SpamFilters_CacheTTL;
  250. $filters_spam_scan = getPref($data_dir, $username, 'filters_spam_scan');
  251. $filters_spam_folder = getPref($data_dir, $username, 'filters_spam_folder');
  252. $filters = load_spam_filters();
  253. if ($SpamFilters_SharedCache) {
  254. filters_LoadCache();
  255. }
  256. $run = false;
  257. foreach ($filters as $Key => $Value) {
  258. if ($Value['enabled']) {
  259. $run = true;
  260. break;
  261. }
  262. }
  263. // short-circuit
  264. if (!$run) {
  265. return;
  266. }
  267. // Ask for a big list of all "Received" headers in the inbox with
  268. // flags for each message. Kinda big.
  269. if ($filters_spam_scan == 'new') {
  270. $search_array = array();
  271. $read = sqimap_run_command($imap_stream, 'SEARCH UNSEEN', true, $response, $message, TRUE);
  272. if (isset($read[0])) {
  273. for ($i=0,$iCnt=count($read);$i<$iCnt;++$i) {
  274. if (preg_match("/^\* SEARCH (.+)$/", $read[$i], $regs)) {
  275. $search_array = preg_split("/ /", trim($regs[1]));
  276. break;
  277. }
  278. }
  279. }
  280. }
  281. if ($filters_spam_scan == 'new' && count($search_array)) {
  282. $headers = sqimap_get_small_header_list ($imap_stream, $search_array, array('Received'),array());
  283. } else if ($filters_spam_scan != 'new') {
  284. $headers = sqimap_get_small_header_list ($imap_stream, null , array('Received'),array());
  285. } else {
  286. return;
  287. }
  288. if (!count($headers)) {
  289. return;
  290. }
  291. $bulkquery = (strlen($SpamFilters_BulkQuery) > 0 ? true : false);
  292. $IPs = array();
  293. $aSpamIds = array();
  294. foreach ($headers as $id => $aValue) {
  295. if (isset($aValue['UID'])) {
  296. $MsgNum = $aValue['UID'];
  297. } else {
  298. $MsgNum = $id;
  299. }
  300. // Look through all of the Received headers for IP addresses
  301. if (isset($aValue['RECEIVED'])) {
  302. foreach ($aValue['RECEIVED'] as $received) {
  303. // Check to see if this line is the right "Received from" line
  304. // to check
  305. // $aValue['Received'] is an array with all the received lines.
  306. // We should check them from bottom to top and only check the first 2.
  307. // Currently we check only the header where $SpamFilters_YourHop in occures
  308. if (is_int(strpos($received, $SpamFilters_YourHop))) {
  309. if (preg_match('/([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/',$received,$aMatch)) {
  310. $isspam = false;
  311. if (filters_spam_check_site($aMatch[1],$aMatch[2],$aMatch[3],$aMatch[4],$filters)) {
  312. $aSpamIds[] = $MsgNum;
  313. $isspam = true;
  314. }
  315. if ($bulkquery) {
  316. array_shift($aMatch);
  317. $IP = explode('.',$aMatch);
  318. foreach ($filters as $key => $value) {
  319. if ($filters[$key]['enabled'] && $filters[$key]['dns']) {
  320. if (strlen($SpamFilters_DNScache[$IP.'.'.$filters[$key]['dns']]) == 0) {
  321. $IPs[$IP] = true;
  322. break;
  323. }
  324. }
  325. }
  326. }
  327. // If we've checked one IP and YourHop is
  328. // just a space
  329. if ($SpamFilters_YourHop == ' ' || $isspam) {
  330. break; // don't check any more
  331. }
  332. }
  333. }
  334. }
  335. }
  336. }
  337. // Lookie! It's spam! Yum!
  338. if (count($aSpamIds) && sqimap_mailbox_exists($imap_stream, $filters_spam_folder)) {
  339. sqimap_msgs_list_move ($imap_stream, $aSpamIds, $filters_spam_folder);
  340. sqimap_mailbox_expunge($imap_stream, 'INBOX');
  341. }
  342. if ($bulkquery && count($IPs)) {
  343. filters_bulkquery($filters, $IPs);
  344. }
  345. if ($SpamFilters_SharedCache) {
  346. filters_SaveCache();
  347. } else {
  348. sqsession_register($SpamFilters_DNScache, 'SpamFilters_DNScache');
  349. }
  350. }
  351. /**
  352. * FIXME: Undocumented function
  353. * Does the loop through each enabled filter for the specified IP address.
  354. * IP format: $a.$b.$c.$d
  355. * @access private
  356. */
  357. function filters_spam_check_site($a, $b, $c, $d, &$filters) {
  358. global $SpamFilters_DNScache, $SpamFilters_CacheTTL;
  359. foreach ($filters as $key => $value) {
  360. if ($filters[$key]['enabled']) {
  361. if ($filters[$key]['dns']) {
  362. $filter_revip = $d . '.' . $c . '.' . $b . '.' . $a . '.' .
  363. $filters[$key]['dns'];
  364. if(!isset($SpamFilters_DNScache[$filter_revip]['L']))
  365. $SpamFilters_DNScache[$filter_revip]['L'] = '';
  366. if(!isset($SpamFilters_DNScache[$filter_revip]['T']))
  367. $SpamFilters_DNScache[$filter_revip]['T'] = '';
  368. if (strlen($SpamFilters_DNScache[$filter_revip]['L']) == 0) {
  369. $SpamFilters_DNScache[$filter_revip]['L'] =
  370. gethostbyname($filter_revip);
  371. $SpamFilters_DNScache[$filter_revip]['T'] =
  372. time() + $SpamFilters_CacheTTL;
  373. }
  374. if ($SpamFilters_DNScache[$filter_revip]['L'] ==
  375. $filters[$key]['result']) {
  376. return 1;
  377. }
  378. }
  379. }
  380. }
  381. return 0;
  382. }
  383. /**
  384. * FIXME: Undocumented function
  385. * @access private
  386. */
  387. function load_filters() {
  388. global $data_dir, $username;
  389. $filters = array();
  390. for ($i=0; $fltr = getPref($data_dir, $username, 'filter' . $i); $i++) {
  391. $ary = explode(',', $fltr);
  392. $filters[$i]['where'] = $ary[0];
  393. $filters[$i]['what'] = $ary[1];
  394. $filters[$i]['folder'] = $ary[2];
  395. }
  396. return $filters;
  397. }
  398. /**
  399. * FIXME: Undocumented function
  400. * @access private
  401. */
  402. function load_spam_filters() {
  403. global $data_dir, $username, $SpamFilters_ShowCommercial;
  404. if ($SpamFilters_ShowCommercial) {
  405. $filters['MAPS RBL']['prefname'] = 'filters_spam_maps_rbl';
  406. $filters['MAPS RBL']['name'] = 'MAPS Realtime Blackhole List';
  407. $filters['MAPS RBL']['link'] = 'http://www.mail-abuse.org/rbl/';
  408. $filters['MAPS RBL']['dns'] = 'blackholes.mail-abuse.org';
  409. $filters['MAPS RBL']['result'] = '127.0.0.2';
  410. $filters['MAPS RBL']['comment'] =
  411. _("COMMERCIAL - This list contains servers that are verified spam senders. It is a pretty reliable list to scan spam from.");
  412. $filters['MAPS RSS']['prefname'] = 'filters_spam_maps_rss';
  413. $filters['MAPS RSS']['name'] = 'MAPS Relay Spam Stopper';
  414. $filters['MAPS RSS']['link'] = 'http://www.mail-abuse.org/rss/';
  415. $filters['MAPS RSS']['dns'] = 'relays.mail-abuse.org';
  416. $filters['MAPS RSS']['result'] = '127.0.0.2';
  417. $filters['MAPS RSS']['comment'] =
  418. _("COMMERCIAL - Servers that are configured (or misconfigured) to allow spam to be relayed through their system will be banned with this. Another good one to use.");
  419. $filters['MAPS DUL']['prefname'] = 'filters_spam_maps_dul';
  420. $filters['MAPS DUL']['name'] = 'MAPS Dial-Up List';
  421. $filters['MAPS DUL']['link'] = 'http://www.mail-abuse.org/dul/';
  422. $filters['MAPS DUL']['dns'] = 'dialups.mail-abuse.org';
  423. $filters['MAPS DUL']['result'] = '127.0.0.3';
  424. $filters['MAPS DUL']['comment'] =
  425. _("COMMERCIAL - Dial-up users are often filtered out since they should use their ISP's mail servers to send mail. Spammers typically get a dial-up account and send spam directly from there.");
  426. $filters['MAPS RBLplus-RBL']['prefname'] = 'filters_spam_maps_rblplus_rbl';
  427. $filters['MAPS RBLplus-RBL']['name'] = 'MAPS RBL+ RBL List';
  428. $filters['MAPS RBLplus-RBL']['link'] = 'http://www.mail-abuse.org/';
  429. $filters['MAPS RBLplus-RBL']['dns'] = 'rbl-plus.mail-abuse.org';
  430. $filters['MAPS RBLplus-RBL']['result'] = '127.0.0.2';
  431. $filters['MAPS RBLplus-RBL']['comment'] =
  432. _("COMMERCIAL - RBL+ Blackhole entries.");
  433. $filters['MAPS RBLplus-RSS']['prefname'] = 'filters_spam_maps_rblplus_rss';
  434. $filters['MAPS RBLplus-RSS']['name'] = 'MAPS RBL+ List RSS entries';
  435. $filters['MAPS RBLplus-RSS']['link'] = 'http://www.mail-abuse.org/';
  436. $filters['MAPS RBLplus-RSS']['dns'] = 'rbl-plus.mail-abuse.org';
  437. $filters['MAPS RBLplus-RSS']['result'] = '127.0.0.2';
  438. $filters['MAPS RBLplus-RSS']['comment'] =
  439. _("COMMERCIAL - RBL+ OpenRelay entries.");
  440. $filters['MAPS RBLplus-DUL']['prefname'] = 'filters_spam_maps_rblplus_dul';
  441. $filters['MAPS RBLplus-DUL']['name'] = 'MAPS RBL+ List DUL entries';
  442. $filters['MAPS RBLplus-DUL']['link'] = 'http://www.mail-abuse.org/';
  443. $filters['MAPS RBLplus-DUL']['dns'] = 'rbl-plus.mail-abuse.org';
  444. $filters['MAPS RBLplus-DUL']['result'] = '127.0.0.3';
  445. $filters['MAPS RBLplus-DUL']['comment'] =
  446. _("COMMERCIAL - RBL+ Dial-up entries.");
  447. }
  448. $filters['ORDB']['prefname'] = 'filters_spam_ordb';
  449. $filters['ORDB']['name'] = 'Open Relay Database List';
  450. $filters['ORDB']['link'] = 'http://www.ordb.org/';
  451. $filters['ORDB']['dns'] = 'relays.ordb.org';
  452. $filters['ORDB']['result'] = '127.0.0.2';
  453. $filters['ORDB']['comment'] =
  454. _("FREE - ORDB was born when ORBS went off the air. It seems to have fewer false positives than ORBS did though.");
  455. $filters['FiveTen Direct']['prefname'] = 'filters_spam_fiveten_src';
  456. $filters['FiveTen Direct']['name'] = 'Five-Ten-sg.com Direct SPAM Sources';
  457. $filters['FiveTen Direct']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
  458. $filters['FiveTen Direct']['dns'] = 'blackholes.five-ten-sg.com';
  459. $filters['FiveTen Direct']['result'] = '127.0.0.2';
  460. $filters['FiveTen Direct']['comment'] =
  461. _("FREE - Five-Ten-sg.com - Direct SPAM sources.");
  462. $filters['FiveTen DUL']['prefname'] = 'filters_spam_fiveten_dul';
  463. $filters['FiveTen DUL']['name'] = 'Five-Ten-sg.com DUL Lists';
  464. $filters['FiveTen DUL']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
  465. $filters['FiveTen DUL']['dns'] = 'blackholes.five-ten-sg.com';
  466. $filters['FiveTen DUL']['result'] = '127.0.0.3';
  467. $filters['FiveTen DUL']['comment'] =
  468. _("FREE - Five-Ten-sg.com - Dial-up lists - includes some DSL IPs.");
  469. $filters['FiveTen Unc. OptIn']['prefname'] = 'filters_spam_fiveten_oi';
  470. $filters['FiveTen Unc. OptIn']['name'] = 'Five-Ten-sg.com Unconfirmed OptIn Lists';
  471. $filters['FiveTen Unc. OptIn']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
  472. $filters['FiveTen Unc. OptIn']['dns'] = 'blackholes.five-ten-sg.com';
  473. $filters['FiveTen Unc. OptIn']['result'] = '127.0.0.4';
  474. $filters['FiveTen Unc. OptIn']['comment'] =
  475. _("FREE - Five-Ten-sg.com - Bulk mailers that do not use confirmed opt-in.");
  476. $filters['FiveTen Others']['prefname'] = 'filters_spam_fiveten_oth';
  477. $filters['FiveTen Others']['name'] = 'Five-Ten-sg.com Other Misc. Servers';
  478. $filters['FiveTen Others']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
  479. $filters['FiveTen Others']['dns'] = 'blackholes.five-ten-sg.com';
  480. $filters['FiveTen Others']['result'] = '127.0.0.5';
  481. $filters['FiveTen Others']['comment'] =
  482. _("FREE - Five-Ten-sg.com - Other misc. servers.");
  483. $filters['FiveTen Single Stage']['prefname'] = 'filters_spam_fiveten_ss';
  484. $filters['FiveTen Single Stage']['name'] = 'Five-Ten-sg.com Single Stage Servers';
  485. $filters['FiveTen Single Stage']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
  486. $filters['FiveTen Single Stage']['dns'] = 'blackholes.five-ten-sg.com';
  487. $filters['FiveTen Single Stage']['result'] = '127.0.0.6';
  488. $filters['FiveTen Single Stage']['comment'] =
  489. _("FREE - Five-Ten-sg.com - Single Stage servers.");
  490. $filters['FiveTen SPAM Support']['prefname'] = 'filters_spam_fiveten_supp';
  491. $filters['FiveTen SPAM Support']['name'] = 'Five-Ten-sg.com SPAM Support Servers';
  492. $filters['FiveTen SPAM Support']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
  493. $filters['FiveTen SPAM Support']['dns'] = 'blackholes.five-ten-sg.com';
  494. $filters['FiveTen SPAM Support']['result'] = '127.0.0.7';
  495. $filters['FiveTen SPAM Support']['comment'] =
  496. _("FREE - Five-Ten-sg.com - SPAM Support servers.");
  497. $filters['FiveTen Web forms']['prefname'] = 'filters_spam_fiveten_wf';
  498. $filters['FiveTen Web forms']['name'] = 'Five-Ten-sg.com Web Form IPs';
  499. $filters['FiveTen Web forms']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
  500. $filters['FiveTen Web forms']['dns'] = 'blackholes.five-ten-sg.com';
  501. $filters['FiveTen Web forms']['result'] = '127.0.0.8';
  502. $filters['FiveTen Web forms']['comment'] =
  503. _("FREE - Five-Ten-sg.com - Web Form IPs.");
  504. $filters['Dorkslayers']['prefname'] = 'filters_spam_dorks';
  505. $filters['Dorkslayers']['name'] = 'Dorkslayers Lists';
  506. $filters['Dorkslayers']['link'] = 'http://www.dorkslayers.com';
  507. $filters['Dorkslayers']['dns'] = 'orbs.dorkslayers.com';
  508. $filters['Dorkslayers']['result'] = '127.0.0.2';
  509. $filters['Dorkslayers']['comment'] =
  510. _("FREE - Dorkslayers appears to include only really bad open relays outside the US to avoid being sued. Interestingly enough, their website recommends you NOT use their service.");
  511. $filters['SPAMhaus']['prefname'] = 'filters_spam_spamhaus';
  512. $filters['SPAMhaus']['name'] = 'SPAMhaus Lists';
  513. $filters['SPAMhaus']['link'] = 'http://www.spamhaus.org';
  514. $filters['SPAMhaus']['dns'] = 'sbl.spamhaus.org';
  515. $filters['SPAMhaus']['result'] = '127.0.0.6';
  516. $filters['SPAMhaus']['comment'] =
  517. _("FREE - SPAMhaus - A list of well-known SPAM sources.");
  518. $filters['SPAMcop']['prefname'] = 'filters_spam_spamcop';
  519. $filters['SPAMcop']['name'] = 'SPAM Cop Lists';
  520. $filters['SPAMcop']['link'] = 'http://spamcop.net/bl.shtml';
  521. $filters['SPAMcop']['dns'] = 'bl.spamcop.net';
  522. $filters['SPAMcop']['result'] = '127.0.0.2';
  523. $filters['SPAMcop']['comment'] =
  524. _("FREE, for now - SpamCop - An interesting solution that lists servers that have a very high spam to legit email ratio (85 percent or more).");
  525. $filters['dev.null.dk']['prefname'] = 'filters_spam_devnull';
  526. $filters['dev.null.dk']['name'] = 'dev.null.dk Lists';
  527. $filters['dev.null.dk']['link'] = 'http://dev.null.dk/';
  528. $filters['dev.null.dk']['dns'] = 'dev.null.dk';
  529. $filters['dev.null.dk']['result'] = '127.0.0.2';
  530. $filters['dev.null.dk']['comment'] =
  531. _("FREE - dev.null.dk - I don't have any detailed info on this list.");
  532. $filters['visi.com']['prefname'] = 'filters_spam_visi';
  533. $filters['visi.com']['name'] = 'visi.com Relay Stop List';
  534. $filters['visi.com']['link'] = 'http://relays.visi.com';
  535. $filters['visi.com']['dns'] = 'relays.visi.com';
  536. $filters['visi.com']['result'] = '127.0.0.2';
  537. $filters['visi.com']['comment'] =
  538. _("FREE - visi.com - Relay Stop List. Very conservative OpenRelay List.");
  539. $filters['ahbl.org Open Relays']['prefname'] = 'filters_spam_2mb_or';
  540. $filters['ahbl.org Open Relays']['name'] = 'ahbl.org Open Relays List';
  541. $filters['ahbl.org Open Relays']['link'] = 'http://www.ahbl.org/';
  542. $filters['ahbl.org Open Relays']['dns'] = 'dnsbl.ahbl.org';
  543. $filters['ahbl.org Open Relays']['result'] = '127.0.0.2';
  544. $filters['ahbl.org Open Relays']['comment'] =
  545. _("FREE - ahbl.org Open Relays - Another list of Open Relays.");
  546. $filters['ahbl.org SPAM Source']['prefname'] = 'filters_spam_2mb_ss';
  547. $filters['ahbl.org SPAM Source']['name'] = 'ahbl.org SPAM Source List';
  548. $filters['ahbl.org SPAM Source']['link'] = 'http://www.ahbl.org/';
  549. $filters['ahbl.org SPAM Source']['dns'] = 'dnsbl.ahbl.org';
  550. $filters['ahbl.org SPAM Source']['result'] = '127.0.0.4';
  551. $filters['ahbl.org SPAM Source']['comment'] =
  552. _("FREE - ahbl.org SPAM Source - List of Direct SPAM Sources.");
  553. $filters['ahbl.org SPAM ISPs']['prefname'] = 'filters_spam_2mb_isp';
  554. $filters['ahbl.org SPAM ISPs']['name'] = 'ahbl.org SPAM-friendly ISP List';
  555. $filters['ahbl.org SPAM ISPs']['link'] = 'http://www.ahbl.org/';
  556. $filters['ahbl.org SPAM ISPs']['dns'] = 'dnsbl.ahbl.org';
  557. $filters['ahbl.org SPAM ISPs']['result'] = '127.0.0.7';
  558. $filters['ahbl.org SPAM ISPs']['comment'] =
  559. _("FREE - ahbl.org SPAM ISPs - List of SPAM-friendly ISPs.");
  560. $filters['Leadmon DUL']['prefname'] = 'filters_spam_lm_dul';
  561. $filters['Leadmon DUL']['name'] = 'Leadmon.net DUL List';
  562. $filters['Leadmon DUL']['link'] = 'http://www.leadmon.net/spamguard/';
  563. $filters['Leadmon DUL']['dns'] = 'spamguard.leadmon.net';
  564. $filters['Leadmon DUL']['result'] = '127.0.0.2';
  565. $filters['Leadmon DUL']['comment'] =
  566. _("FREE - Leadmon DUL - Another list of Dial-up or otherwise dynamically assigned IPs.");
  567. $filters['Leadmon SPAM Source']['prefname'] = 'filters_spam_lm_ss';
  568. $filters['Leadmon SPAM Source']['name'] = 'Leadmon.net SPAM Source List';
  569. $filters['Leadmon SPAM Source']['link'] = 'http://www.leadmon.net/spamguard/';
  570. $filters['Leadmon SPAM Source']['dns'] = 'spamguard.leadmon.net';
  571. $filters['Leadmon SPAM Source']['result'] = '127.0.0.3';
  572. $filters['Leadmon SPAM Source']['comment'] =
  573. _("FREE - Leadmon SPAM Source - List of IPs Leadmon.net has received SPAM directly from.");
  574. $filters['Leadmon Bulk Mailers']['prefname'] = 'filters_spam_lm_bm';
  575. $filters['Leadmon Bulk Mailers']['name'] = 'Leadmon.net Bulk Mailers List';
  576. $filters['Leadmon Bulk Mailers']['link'] = 'http://www.leadmon.net/spamguard/';
  577. $filters['Leadmon Bulk Mailers']['dns'] = 'spamguard.leadmon.net';
  578. $filters['Leadmon Bulk Mailers']['result'] = '127.0.0.4';
  579. $filters['Leadmon Bulk Mailers']['comment'] =
  580. _("FREE - Leadmon Bulk Mailers - Bulk mailers that do not require confirmed opt-in or that have allowed known spammers to become clients and abuse their services.");
  581. $filters['Leadmon Open Relays']['prefname'] = 'filters_spam_lm_or';
  582. $filters['Leadmon Open Relays']['name'] = 'Leadmon.net Open Relays List';
  583. $filters['Leadmon Open Relays']['link'] = 'http://www.leadmon.net/spamguard/';
  584. $filters['Leadmon Open Relays']['dns'] = 'spamguard.leadmon.net';
  585. $filters['Leadmon Open Relays']['result'] = '127.0.0.5';
  586. $filters['Leadmon Open Relays']['comment'] =
  587. _("FREE - Leadmon Open Relays - Single Stage Open Relays that are not listed on other active RBLs.");
  588. $filters['Leadmon Multi-stage']['prefname'] = 'filters_spam_lm_ms';
  589. $filters['Leadmon Multi-stage']['name'] = 'Leadmon.net Multi-Stage Relay List';
  590. $filters['Leadmon Multi-stage']['link'] = 'http://www.leadmon.net/spamguard/';
  591. $filters['Leadmon Multi-stage']['dns'] = 'spamguard.leadmon.net';
  592. $filters['Leadmon Multi-stage']['result'] = '127.0.0.6';
  593. $filters['Leadmon Multi-stage']['comment'] =
  594. _("FREE - Leadmon Multi-stage - Multi-Stage Open Relays that are not listed on other active RBLs and that have sent SPAM to Leadmon.net.");
  595. $filters['Leadmon SpamBlock']['prefname'] = 'filters_spam_lm_sb';
  596. $filters['Leadmon SpamBlock']['name'] = 'Leadmon.net SpamBlock Sites List';
  597. $filters['Leadmon SpamBlock']['link'] = 'http://www.leadmon.net/spamguard/';
  598. $filters['Leadmon SpamBlock']['dns'] = 'spamguard.leadmon.net';
  599. $filters['Leadmon SpamBlock']['result'] = '127.0.0.7';
  600. $filters['Leadmon SpamBlock']['comment'] =
  601. _("FREE - Leadmon SpamBlock - Sites on this listing have sent Leadmon.net direct SPAM from IPs in netblocks where the entire block has no DNS mappings. It's a list of BLOCKS of IPs being used by people who have SPAMmed Leadmon.net.");
  602. $filters['NJABL Open Relays']['prefname'] = 'filters_spam_njabl_or';
  603. $filters['NJABL Open Relays']['name'] = 'NJABL Open Relay/Direct Spam Source List';
  604. $filters['NJABL Open Relays']['link'] = 'http://www.njabl.org/';
  605. $filters['NJABL Open Relays']['dns'] = 'dnsbl.njabl.org';
  606. $filters['NJABL Open Relays']['result'] = '127.0.0.2';
  607. $filters['NJABL Open Relays']['comment'] =
  608. _("FREE, for now - Not Just Another Blacklist - Both Open Relays and Direct SPAM Sources.");
  609. $filters['NJABL DUL']['prefname'] = 'filters_spam_njabl_dul';
  610. $filters['NJABL DUL']['name'] = 'NJABL Dial-ups List';
  611. $filters['NJABL DUL']['link'] = 'http://www.njabl.org/';
  612. $filters['NJABL DUL']['dns'] = 'dnsbl.njabl.org';
  613. $filters['NJABL DUL']['result'] = '127.0.0.3';
  614. $filters['NJABL DUL']['comment'] =
  615. _("FREE, for now - Not Just Another Blacklist - Dial-up IPs.");
  616. $filters['Conf DSBL.ORG Relay']['prefname'] = 'filters_spam_dsbl_conf_ss';
  617. $filters['Conf DSBL.ORG Relay']['name'] = 'DSBL.org Confirmed Relay List';
  618. $filters['Conf DSBL.ORG Relay']['link'] = 'http://www.dsbl.org/';
  619. $filters['Conf DSBL.ORG Relay']['dns'] = 'list.dsbl.org';
  620. $filters['Conf DSBL.ORG Relay']['result'] = '127.0.0.2';
  621. $filters['Conf DSBL.ORG Relay']['comment'] =
  622. _("FREE - Distributed Sender Boycott List - Confirmed Relays");
  623. $filters['Conf DSBL.ORG Multi-Stage']['prefname'] = 'filters_spam_dsbl_conf_ms';
  624. $filters['Conf DSBL.ORG Multi-Stage']['name'] = 'DSBL.org Confirmed Multi-Stage Relay List';
  625. $filters['Conf DSBL.ORG Multi-Stage']['link'] = 'http://www.dsbl.org/';
  626. $filters['Conf DSBL.ORG Multi-Stage']['dns'] = 'multihop.dsbl.org';
  627. $filters['Conf DSBL.ORG Multi-Stage']['result'] = '127.0.0.2';
  628. $filters['Conf DSBL.ORG Multi-Stage']['comment'] =
  629. _("FREE - Distributed Sender Boycott List - Confirmed Multi-stage Relays");
  630. $filters['UN-Conf DSBL.ORG']['prefname'] = 'filters_spam_dsbl_unc';
  631. $filters['UN-Conf DSBL.ORG']['name'] = 'DSBL.org UN-Confirmed Relay List';
  632. $filters['UN-Conf DSBL.ORG']['link'] = 'http://www.dsbl.org/';
  633. $filters['UN-Conf DSBL.ORG']['dns'] = 'unconfirmed.dsbl.org';
  634. $filters['UN-Conf DSBL.ORG']['result'] = '127.0.0.2';
  635. $filters['UN-Conf DSBL.ORG']['comment'] =
  636. _("FREE - Distributed Sender Boycott List - UN-Confirmed Relays");
  637. foreach ($filters as $Key => $Value) {
  638. $filters[$Key]['enabled'] = getPref($data_dir, $username,
  639. $filters[$Key]['prefname']);
  640. }
  641. return $filters;
  642. }
  643. /**
  644. * FIXME: Undocumented function
  645. * @access private
  646. */
  647. function remove_filter ($id) {
  648. global $data_dir, $username;
  649. while ($nextFilter = getPref($data_dir, $username, 'filter' .
  650. ($id + 1))) {
  651. setPref($data_dir, $username, 'filter' . $id, $nextFilter);
  652. $id ++;
  653. }
  654. removePref($data_dir, $username, 'filter' . $id);
  655. }
  656. /**
  657. * FIXME: Undocumented function
  658. * @access private
  659. */
  660. function filter_swap($id1, $id2) {
  661. global $data_dir, $username;
  662. $FirstFilter = getPref($data_dir, $username, 'filter' . $id1);
  663. $SecondFilter = getPref($data_dir, $username, 'filter' . $id2);
  664. if ($FirstFilter && $SecondFilter) {
  665. setPref($data_dir, $username, 'filter' . $id2, $FirstFilter);
  666. setPref($data_dir, $username, 'filter' . $id1, $SecondFilter);
  667. }
  668. }
  669. /**
  670. * This update the filter rules when renaming or deleting folders
  671. * @param array $args
  672. * @access private
  673. */
  674. function update_for_folder ($args) {
  675. $old_folder = $args[0];
  676. $new_folder = $args[2];
  677. $action = $args[1];
  678. global $data_dir, $username;
  679. $filters = array();
  680. $filters = load_filters();
  681. $filter_count = count($filters);
  682. $p = 0;
  683. for ($i=0;$i<$filter_count;$i++) {
  684. if (!empty($filters)) {
  685. if ($old_folder == $filters[$i]['folder']) {
  686. if ($action == 'rename') {
  687. $filters[$i]['folder'] = $new_folder;
  688. setPref($data_dir, $username, 'filter'.$i,
  689. $filters[$i]['where'].','.$filters[$i]['what'].','.$new_folder);
  690. }
  691. elseif ($action == 'delete') {
  692. remove_filter($p);
  693. $p = $p-1;
  694. }
  695. }
  696. $p++;
  697. }
  698. }
  699. }
  700. /**
  701. * Display formated error message
  702. * @param string $string text message
  703. * @return string html formated text message
  704. * @access private
  705. */
  706. function do_error($string) {
  707. global $color;
  708. echo "<p align=\"center\"><font color=\"$color[2]\">";
  709. echo $string;
  710. echo "</font></p>\n";
  711. }
  712. ?>