filters.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797
  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-2004 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 $SpamFilters_YourHop, $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 $mailbox, $imapServerAddress, $imapPort, $imap,
  119. $imap_general, $filters, $imap_stream, $imapConnection,
  120. $UseSeparateImapConnection, $AllowSpamFilters;
  121. sqgetGlobalVar('username', $username, SQ_SESSION);
  122. sqgetGlobalVar('key', $key, SQ_COOKIE);
  123. // Detect if we have already connected to IMAP or not.
  124. // Also check if we are forced to use a separate IMAP connection
  125. if ((!isset($imap_stream) && !isset($imapConnection)) ||
  126. $UseSeparateImapConnection ) {
  127. $stream = sqimap_login($username, $key, $imapServerAddress,
  128. $imapPort, 10);
  129. $previously_connected = false;
  130. } else if (isset($imapConnection)) {
  131. $stream = $imapConnection;
  132. $previously_connected = true;
  133. } else {
  134. $previously_connected = true;
  135. $stream = $imap_stream;
  136. }
  137. $aStatus = sqimap_status_messages ($stream, 'INBOX', array('MESSAGES'));
  138. if ($aStatus['MESSAGES']) {
  139. sqimap_mailbox_select($stream, 'INBOX');
  140. // Filter spam from inbox before we sort them into folders
  141. if ($AllowSpamFilters) {
  142. spam_filters($stream);
  143. }
  144. // Sort into folders
  145. user_filters($stream);
  146. }
  147. if (!$previously_connected) {
  148. sqimap_logout($stream);
  149. }
  150. }
  151. /**
  152. * FIXME: Undocumented function
  153. * @access private
  154. */
  155. function user_filters($imap_stream) {
  156. global $data_dir, $username;
  157. $filters = load_filters();
  158. if (! $filters) return;
  159. $filters_user_scan = getPref($data_dir, $username, 'filters_user_scan');
  160. $expunge = false;
  161. // For every rule
  162. for ($i=0, $num = count($filters); $i < $num; $i++) {
  163. // If it is the "combo" rule
  164. if ($filters[$i]['where'] == 'To or Cc') {
  165. /*
  166. * If it's "TO OR CC", we have to do two searches, one for TO
  167. * and the other for CC.
  168. */
  169. $expunge = filter_search_and_delete($imap_stream, 'TO',
  170. $filters[$i]['what'], $filters[$i]['folder'], $filters_user_scan, $expunge);
  171. $expunge = filter_search_and_delete($imap_stream, 'CC',
  172. $filters[$i]['what'], $filters[$i]['folder'], $filters_user_scan, $expunge);
  173. } else {
  174. /*
  175. * If it's a normal TO, CC, SUBJECT, or FROM, then handle it
  176. * normally.
  177. */
  178. $expunge = filter_search_and_delete($imap_stream, $filters[$i]['where'],
  179. $filters[$i]['what'], $filters[$i]['folder'], $filters_user_scan, $expunge);
  180. }
  181. }
  182. // Clean out the mailbox whether or not auto_expunge is on
  183. // That way it looks like it was redirected properly
  184. if ($expunge) {
  185. sqimap_mailbox_expunge($imap_stream, 'INBOX');
  186. }
  187. }
  188. /**
  189. * FIXME: Undocumented function
  190. * @access private
  191. */
  192. function filter_search_and_delete($imap_stream, $where, $what, $where_to, $user_scan,
  193. $should_expunge) {
  194. global $languages, $squirrelmail_language, $allow_charset_search, $imap_server_type;
  195. if ($user_scan == 'new') {
  196. $category = 'UNSEEN';
  197. } else {
  198. $category = 'ALL';
  199. }
  200. if ($allow_charset_search &&
  201. isset($languages[$squirrelmail_language]['CHARSET']) &&
  202. $languages[$squirrelmail_language]['CHARSET']) {
  203. $search_str = 'SEARCH CHARSET '
  204. . strtoupper($languages[$squirrelmail_language]['CHARSET'])
  205. . ' ' . $category;
  206. } else {
  207. $search_str = 'SEARCH CHARSET US-ASCII ' . $category;
  208. }
  209. if ($where == 'Header') {
  210. $what = explode(':', $what);
  211. $where = trim($where . ' ' . $what[0]);
  212. $what = addslashes(trim($what[1]));
  213. }
  214. if ($imap_server_type == 'macosx') {
  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, $show_num=false,
  283. array('Received'),array());
  284. } else if ($filters_spam_scan != 'new') {
  285. $headers = sqimap_get_small_header_list ($imap_stream,false, '*', array('Received'),array());
  286. } else {
  287. return;
  288. }
  289. if (!count($headers)) {
  290. return;
  291. }
  292. $bulkquery = (strlen($SpamFilters_BulkQuery) > 0 ? true : false);
  293. $IPs = array();
  294. $aSpamIds = array();
  295. foreach ($headers as $id => $aValue) {
  296. if (isset($aValue['UID'])) {
  297. $MsgNum = $aValue['UID'];
  298. } else {
  299. $MsgNum = $id;
  300. }
  301. // Look through all of the Received headers for IP addresses
  302. if (isset($aValue['RECEIVED'])) {
  303. foreach ($aValue['RECEIVED'] as $received) {
  304. // Check to see if this line is the right "Received from" line
  305. // to check
  306. // $aValue['Received'] is an array with all the received lines.
  307. // We should check them from bottom to top and only check the first 2.
  308. // Currently we check only the header where $SpamFilters_YourHop in occures
  309. if (is_int(strpos($received, $SpamFilters_YourHop))) {
  310. if (preg_match('/([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/',$received,$aMatch)) {
  311. $isspam = false;
  312. if (filters_spam_check_site($aMatch[1],$aMatch[2],$aMatch[3],$aMatch[4],$filters)) {
  313. $aSpamIds[] = $MsgNum;
  314. $isspam = true;
  315. }
  316. if ($bulkquery) {
  317. array_shift($aMatch);
  318. $IP = explode('.',$aMatch);
  319. foreach ($filters as $key => $value) {
  320. if ($filters[$key]['enabled'] && $filters[$key]['dns']) {
  321. if (strlen($SpamFilters_DNScache[$IP.'.'.$filters[$key]['dns']]) == 0) {
  322. $IPs[$IP] = true;
  323. break;
  324. }
  325. }
  326. }
  327. }
  328. // If we've checked one IP and YourHop is
  329. // just a space
  330. if ($SpamFilters_YourHop == ' ' || $isspam) {
  331. break; // don't check any more
  332. }
  333. }
  334. }
  335. }
  336. }
  337. }
  338. // Lookie! It's spam! Yum!
  339. if (count($aSpamIds) && sqimap_mailbox_exists($imap_stream, $filters_spam_folder)) {
  340. sqimap_msgs_list_move ($imap_stream, $aSpamIds, $filters_spam_folder);
  341. sqimap_mailbox_expunge($imap_stream, 'INBOX');
  342. }
  343. if ($bulkquery && count($IPs)) {
  344. filters_bulkquery($filters, $IPs);
  345. }
  346. if ($SpamFilters_SharedCache) {
  347. filters_SaveCache();
  348. } else {
  349. sqsession_register($SpamFilters_DNScache, 'SpamFilters_DNScache');
  350. }
  351. }
  352. /**
  353. * FIXME: Undocumented function
  354. * Does the loop through each enabled filter for the specified IP address.
  355. * IP format: $a.$b.$c.$d
  356. * @access private
  357. */
  358. function filters_spam_check_site($a, $b, $c, $d, &$filters) {
  359. global $SpamFilters_DNScache, $SpamFilters_CacheTTL;
  360. foreach ($filters as $key => $value) {
  361. if ($filters[$key]['enabled']) {
  362. if ($filters[$key]['dns']) {
  363. $filter_revip = $d . '.' . $c . '.' . $b . '.' . $a . '.' .
  364. $filters[$key]['dns'];
  365. if(!isset($SpamFilters_DNScache[$filter_revip]['L']))
  366. $SpamFilters_DNScache[$filter_revip]['L'] = '';
  367. if(!isset($SpamFilters_DNScache[$filter_revip]['T']))
  368. $SpamFilters_DNScache[$filter_revip]['T'] = '';
  369. if (strlen($SpamFilters_DNScache[$filter_revip]['L']) == 0) {
  370. $SpamFilters_DNScache[$filter_revip]['L'] =
  371. gethostbyname($filter_revip);
  372. $SpamFilters_DNScache[$filter_revip]['T'] =
  373. time() + $SpamFilters_CacheTTL;
  374. }
  375. if ($SpamFilters_DNScache[$filter_revip]['L'] ==
  376. $filters[$key]['result']) {
  377. return 1;
  378. }
  379. }
  380. }
  381. }
  382. return 0;
  383. }
  384. /**
  385. * FIXME: Undocumented function
  386. * @access private
  387. */
  388. function load_filters() {
  389. global $data_dir, $username;
  390. $filters = array();
  391. for ($i=0; $fltr = getPref($data_dir, $username, 'filter' . $i); $i++) {
  392. $ary = explode(',', $fltr);
  393. $filters[$i]['where'] = $ary[0];
  394. $filters[$i]['what'] = $ary[1];
  395. $filters[$i]['folder'] = $ary[2];
  396. }
  397. return $filters;
  398. }
  399. /**
  400. * FIXME: Undocumented function
  401. * @access private
  402. */
  403. function load_spam_filters() {
  404. global $data_dir, $username, $SpamFilters_ShowCommercial;
  405. if ($SpamFilters_ShowCommercial) {
  406. $filters['MAPS RBL']['prefname'] = 'filters_spam_maps_rbl';
  407. $filters['MAPS RBL']['name'] = 'MAPS Realtime Blackhole List';
  408. $filters['MAPS RBL']['link'] = 'http://www.mail-abuse.org/rbl/';
  409. $filters['MAPS RBL']['dns'] = 'blackholes.mail-abuse.org';
  410. $filters['MAPS RBL']['result'] = '127.0.0.2';
  411. $filters['MAPS RBL']['comment'] =
  412. _("COMMERCIAL - This list contains servers that are verified spam senders. It is a pretty reliable list to scan spam from.");
  413. $filters['MAPS RSS']['prefname'] = 'filters_spam_maps_rss';
  414. $filters['MAPS RSS']['name'] = 'MAPS Relay Spam Stopper';
  415. $filters['MAPS RSS']['link'] = 'http://www.mail-abuse.org/rss/';
  416. $filters['MAPS RSS']['dns'] = 'relays.mail-abuse.org';
  417. $filters['MAPS RSS']['result'] = '127.0.0.2';
  418. $filters['MAPS RSS']['comment'] =
  419. _("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.");
  420. $filters['MAPS DUL']['prefname'] = 'filters_spam_maps_dul';
  421. $filters['MAPS DUL']['name'] = 'MAPS Dial-Up List';
  422. $filters['MAPS DUL']['link'] = 'http://www.mail-abuse.org/dul/';
  423. $filters['MAPS DUL']['dns'] = 'dialups.mail-abuse.org';
  424. $filters['MAPS DUL']['result'] = '127.0.0.3';
  425. $filters['MAPS DUL']['comment'] =
  426. _("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.");
  427. $filters['MAPS RBLplus-RBL']['prefname'] = 'filters_spam_maps_rblplus_rbl';
  428. $filters['MAPS RBLplus-RBL']['name'] = 'MAPS RBL+ RBL List';
  429. $filters['MAPS RBLplus-RBL']['link'] = 'http://www.mail-abuse.org/';
  430. $filters['MAPS RBLplus-RBL']['dns'] = 'rbl-plus.mail-abuse.org';
  431. $filters['MAPS RBLplus-RBL']['result'] = '127.0.0.2';
  432. $filters['MAPS RBLplus-RBL']['comment'] =
  433. _("COMMERCIAL - RBL+ Blackhole entries.");
  434. $filters['MAPS RBLplus-RSS']['prefname'] = 'filters_spam_maps_rblplus_rss';
  435. $filters['MAPS RBLplus-RSS']['name'] = 'MAPS RBL+ List RSS entries';
  436. $filters['MAPS RBLplus-RSS']['link'] = 'http://www.mail-abuse.org/';
  437. $filters['MAPS RBLplus-RSS']['dns'] = 'rbl-plus.mail-abuse.org';
  438. $filters['MAPS RBLplus-RSS']['result'] = '127.0.0.2';
  439. $filters['MAPS RBLplus-RSS']['comment'] =
  440. _("COMMERCIAL - RBL+ OpenRelay entries.");
  441. $filters['MAPS RBLplus-DUL']['prefname'] = 'filters_spam_maps_rblplus_dul';
  442. $filters['MAPS RBLplus-DUL']['name'] = 'MAPS RBL+ List DUL entries';
  443. $filters['MAPS RBLplus-DUL']['link'] = 'http://www.mail-abuse.org/';
  444. $filters['MAPS RBLplus-DUL']['dns'] = 'rbl-plus.mail-abuse.org';
  445. $filters['MAPS RBLplus-DUL']['result'] = '127.0.0.3';
  446. $filters['MAPS RBLplus-DUL']['comment'] =
  447. _("COMMERCIAL - RBL+ Dial-up entries.");
  448. }
  449. $filters['ORDB']['prefname'] = 'filters_spam_ordb';
  450. $filters['ORDB']['name'] = 'Open Relay Database List';
  451. $filters['ORDB']['link'] = 'http://www.ordb.org/';
  452. $filters['ORDB']['dns'] = 'relays.ordb.org';
  453. $filters['ORDB']['result'] = '127.0.0.2';
  454. $filters['ORDB']['comment'] =
  455. _("FREE - ORDB was born when ORBS went off the air. It seems to have fewer false positives than ORBS did though.");
  456. $filters['FiveTen Direct']['prefname'] = 'filters_spam_fiveten_src';
  457. $filters['FiveTen Direct']['name'] = 'Five-Ten-sg.com Direct SPAM Sources';
  458. $filters['FiveTen Direct']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
  459. $filters['FiveTen Direct']['dns'] = 'blackholes.five-ten-sg.com';
  460. $filters['FiveTen Direct']['result'] = '127.0.0.2';
  461. $filters['FiveTen Direct']['comment'] =
  462. _("FREE - Five-Ten-sg.com - Direct SPAM sources.");
  463. $filters['FiveTen DUL']['prefname'] = 'filters_spam_fiveten_dul';
  464. $filters['FiveTen DUL']['name'] = 'Five-Ten-sg.com DUL Lists';
  465. $filters['FiveTen DUL']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
  466. $filters['FiveTen DUL']['dns'] = 'blackholes.five-ten-sg.com';
  467. $filters['FiveTen DUL']['result'] = '127.0.0.3';
  468. $filters['FiveTen DUL']['comment'] =
  469. _("FREE - Five-Ten-sg.com - Dial-up lists - includes some DSL IPs.");
  470. $filters['FiveTen Unc. OptIn']['prefname'] = 'filters_spam_fiveten_oi';
  471. $filters['FiveTen Unc. OptIn']['name'] = 'Five-Ten-sg.com Unconfirmed OptIn Lists';
  472. $filters['FiveTen Unc. OptIn']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
  473. $filters['FiveTen Unc. OptIn']['dns'] = 'blackholes.five-ten-sg.com';
  474. $filters['FiveTen Unc. OptIn']['result'] = '127.0.0.4';
  475. $filters['FiveTen Unc. OptIn']['comment'] =
  476. _("FREE - Five-Ten-sg.com - Bulk mailers that do not use confirmed opt-in.");
  477. $filters['FiveTen Others']['prefname'] = 'filters_spam_fiveten_oth';
  478. $filters['FiveTen Others']['name'] = 'Five-Ten-sg.com Other Misc. Servers';
  479. $filters['FiveTen Others']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
  480. $filters['FiveTen Others']['dns'] = 'blackholes.five-ten-sg.com';
  481. $filters['FiveTen Others']['result'] = '127.0.0.5';
  482. $filters['FiveTen Others']['comment'] =
  483. _("FREE - Five-Ten-sg.com - Other misc. servers.");
  484. $filters['FiveTen Single Stage']['prefname'] = 'filters_spam_fiveten_ss';
  485. $filters['FiveTen Single Stage']['name'] = 'Five-Ten-sg.com Single Stage Servers';
  486. $filters['FiveTen Single Stage']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
  487. $filters['FiveTen Single Stage']['dns'] = 'blackholes.five-ten-sg.com';
  488. $filters['FiveTen Single Stage']['result'] = '127.0.0.6';
  489. $filters['FiveTen Single Stage']['comment'] =
  490. _("FREE - Five-Ten-sg.com - Single Stage servers.");
  491. $filters['FiveTen SPAM Support']['prefname'] = 'filters_spam_fiveten_supp';
  492. $filters['FiveTen SPAM Support']['name'] = 'Five-Ten-sg.com SPAM Support Servers';
  493. $filters['FiveTen SPAM Support']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
  494. $filters['FiveTen SPAM Support']['dns'] = 'blackholes.five-ten-sg.com';
  495. $filters['FiveTen SPAM Support']['result'] = '127.0.0.7';
  496. $filters['FiveTen SPAM Support']['comment'] =
  497. _("FREE - Five-Ten-sg.com - SPAM Support servers.");
  498. $filters['FiveTen Web forms']['prefname'] = 'filters_spam_fiveten_wf';
  499. $filters['FiveTen Web forms']['name'] = 'Five-Ten-sg.com Web Form IPs';
  500. $filters['FiveTen Web forms']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
  501. $filters['FiveTen Web forms']['dns'] = 'blackholes.five-ten-sg.com';
  502. $filters['FiveTen Web forms']['result'] = '127.0.0.8';
  503. $filters['FiveTen Web forms']['comment'] =
  504. _("FREE - Five-Ten-sg.com - Web Form IPs.");
  505. $filters['Dorkslayers']['prefname'] = 'filters_spam_dorks';
  506. $filters['Dorkslayers']['name'] = 'Dorkslayers Lists';
  507. $filters['Dorkslayers']['link'] = 'http://www.dorkslayers.com';
  508. $filters['Dorkslayers']['dns'] = 'orbs.dorkslayers.com';
  509. $filters['Dorkslayers']['result'] = '127.0.0.2';
  510. $filters['Dorkslayers']['comment'] =
  511. _("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.");
  512. $filters['SPAMhaus']['prefname'] = 'filters_spam_spamhaus';
  513. $filters['SPAMhaus']['name'] = 'SPAMhaus Lists';
  514. $filters['SPAMhaus']['link'] = 'http://www.spamhaus.org';
  515. $filters['SPAMhaus']['dns'] = 'sbl.spamhaus.org';
  516. $filters['SPAMhaus']['result'] = '127.0.0.6';
  517. $filters['SPAMhaus']['comment'] =
  518. _("FREE - SPAMhaus - A list of well-known SPAM sources.");
  519. $filters['SPAMcop']['prefname'] = 'filters_spam_spamcop';
  520. $filters['SPAMcop']['name'] = 'SPAM Cop Lists';
  521. $filters['SPAMcop']['link'] = 'http://spamcop.net/bl.shtml';
  522. $filters['SPAMcop']['dns'] = 'bl.spamcop.net';
  523. $filters['SPAMcop']['result'] = '127.0.0.2';
  524. $filters['SPAMcop']['comment'] =
  525. _("FREE, for now - SPAMCOP - An interesting solution that lists servers that have a very high spam to legit email ratio (85 percent or more).");
  526. $filters['dev.null.dk']['prefname'] = 'filters_spam_devnull';
  527. $filters['dev.null.dk']['name'] = 'dev.null.dk Lists';
  528. $filters['dev.null.dk']['link'] = 'http://dev.null.dk/';
  529. $filters['dev.null.dk']['dns'] = 'dev.null.dk';
  530. $filters['dev.null.dk']['result'] = '127.0.0.2';
  531. $filters['dev.null.dk']['comment'] =
  532. _("FREE - dev.null.dk - I don't have any detailed info on this list.");
  533. $filters['visi.com']['prefname'] = 'filters_spam_visi';
  534. $filters['visi.com']['name'] = 'visi.com Relay Stop List';
  535. $filters['visi.com']['link'] = 'http://relays.visi.com';
  536. $filters['visi.com']['dns'] = 'relays.visi.com';
  537. $filters['visi.com']['result'] = '127.0.0.2';
  538. $filters['visi.com']['comment'] =
  539. _("FREE - visi.com - Relay Stop List. Very conservative OpenRelay List.");
  540. $filters['ahbl.org Open Relays']['prefname'] = 'filters_spam_2mb_or';
  541. $filters['ahbl.org Open Relays']['name'] = 'ahbl.org Open Relays List';
  542. $filters['ahbl.org Open Relays']['link'] = 'http://www.ahbl.org/';
  543. $filters['ahbl.org Open Relays']['dns'] = 'dnsbl.ahbl.org';
  544. $filters['ahbl.org Open Relays']['result'] = '127.0.0.2';
  545. $filters['ahbl.org Open Relays']['comment'] =
  546. _("FREE - ahbl.org Open Relays - Another list of Open Relays.");
  547. $filters['ahbl.org SPAM Source']['prefname'] = 'filters_spam_2mb_ss';
  548. $filters['ahbl.org SPAM Source']['name'] = 'ahbl.org SPAM Source List';
  549. $filters['ahbl.org SPAM Source']['link'] = 'http://www.ahbl.org/';
  550. $filters['ahbl.org SPAM Source']['dns'] = 'dnsbl.ahbl.org';
  551. $filters['ahbl.org SPAM Source']['result'] = '127.0.0.4';
  552. $filters['ahbl.org SPAM Source']['comment'] =
  553. _("FREE - ahbl.org SPAM Source - List of Direct SPAM Sources.");
  554. $filters['ahbl.org SPAM ISPs']['prefname'] = 'filters_spam_2mb_isp';
  555. $filters['ahbl.org SPAM ISPs']['name'] = 'ahbl.org SPAM-friendly ISP List';
  556. $filters['ahbl.org SPAM ISPs']['link'] = 'http://www.ahbl.org/';
  557. $filters['ahbl.org SPAM ISPs']['dns'] = 'dnsbl.ahbl.org';
  558. $filters['ahbl.org SPAM ISPs']['result'] = '127.0.0.7';
  559. $filters['ahbl.org SPAM ISPs']['comment'] =
  560. _("FREE - ahbl.org SPAM ISPs - List of SPAM-friendly ISPs.");
  561. $filters['Leadmon DUL']['prefname'] = 'filters_spam_lm_dul';
  562. $filters['Leadmon DUL']['name'] = 'Leadmon.net DUL List';
  563. $filters['Leadmon DUL']['link'] = 'http://www.leadmon.net/spamguard/';
  564. $filters['Leadmon DUL']['dns'] = 'spamguard.leadmon.net';
  565. $filters['Leadmon DUL']['result'] = '127.0.0.2';
  566. $filters['Leadmon DUL']['comment'] =
  567. _("FREE - Leadmon DUL - Another list of Dial-up or otherwise dynamically assigned IPs.");
  568. $filters['Leadmon SPAM Source']['prefname'] = 'filters_spam_lm_ss';
  569. $filters['Leadmon SPAM Source']['name'] = 'Leadmon.net SPAM Source List';
  570. $filters['Leadmon SPAM Source']['link'] = 'http://www.leadmon.net/spamguard/';
  571. $filters['Leadmon SPAM Source']['dns'] = 'spamguard.leadmon.net';
  572. $filters['Leadmon SPAM Source']['result'] = '127.0.0.3';
  573. $filters['Leadmon SPAM Source']['comment'] =
  574. _("FREE - Leadmon SPAM Source - List of IPs Leadmon.net has received SPAM directly from.");
  575. $filters['Leadmon Bulk Mailers']['prefname'] = 'filters_spam_lm_bm';
  576. $filters['Leadmon Bulk Mailers']['name'] = 'Leadmon.net Bulk Mailers List';
  577. $filters['Leadmon Bulk Mailers']['link'] = 'http://www.leadmon.net/spamguard/';
  578. $filters['Leadmon Bulk Mailers']['dns'] = 'spamguard.leadmon.net';
  579. $filters['Leadmon Bulk Mailers']['result'] = '127.0.0.4';
  580. $filters['Leadmon Bulk Mailers']['comment'] =
  581. _("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.");
  582. $filters['Leadmon Open Relays']['prefname'] = 'filters_spam_lm_or';
  583. $filters['Leadmon Open Relays']['name'] = 'Leadmon.net Open Relays List';
  584. $filters['Leadmon Open Relays']['link'] = 'http://www.leadmon.net/spamguard/';
  585. $filters['Leadmon Open Relays']['dns'] = 'spamguard.leadmon.net';
  586. $filters['Leadmon Open Relays']['result'] = '127.0.0.5';
  587. $filters['Leadmon Open Relays']['comment'] =
  588. _("FREE - Leadmon Open Relays - Single Stage Open Relays that are not listed on other active RBLs.");
  589. $filters['Leadmon Multi-stage']['prefname'] = 'filters_spam_lm_ms';
  590. $filters['Leadmon Multi-stage']['name'] = 'Leadmon.net Multi-Stage Relay List';
  591. $filters['Leadmon Multi-stage']['link'] = 'http://www.leadmon.net/spamguard/';
  592. $filters['Leadmon Multi-stage']['dns'] = 'spamguard.leadmon.net';
  593. $filters['Leadmon Multi-stage']['result'] = '127.0.0.6';
  594. $filters['Leadmon Multi-stage']['comment'] =
  595. _("FREE - Leadmon Multi-stage - Multi-Stage Open Relays that are not listed on other active RBLs and that have sent SPAM to Leadmon.net.");
  596. $filters['Leadmon SpamBlock']['prefname'] = 'filters_spam_lm_sb';
  597. $filters['Leadmon SpamBlock']['name'] = 'Leadmon.net SpamBlock Sites List';
  598. $filters['Leadmon SpamBlock']['link'] = 'http://www.leadmon.net/spamguard/';
  599. $filters['Leadmon SpamBlock']['dns'] = 'spamguard.leadmon.net';
  600. $filters['Leadmon SpamBlock']['result'] = '127.0.0.7';
  601. $filters['Leadmon SpamBlock']['comment'] =
  602. _("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.");
  603. $filters['NJABL Open Relays']['prefname'] = 'filters_spam_njabl_or';
  604. $filters['NJABL Open Relays']['name'] = 'NJABL Open Relay/Direct Spam Source List';
  605. $filters['NJABL Open Relays']['link'] = 'http://www.njabl.org/';
  606. $filters['NJABL Open Relays']['dns'] = 'dnsbl.njabl.org';
  607. $filters['NJABL Open Relays']['result'] = '127.0.0.2';
  608. $filters['NJABL Open Relays']['comment'] =
  609. _("FREE, for now - Not Just Another Blacklist - Both Open Relays and Direct SPAM Sources.");
  610. $filters['NJABL DUL']['prefname'] = 'filters_spam_njabl_dul';
  611. $filters['NJABL DUL']['name'] = 'NJABL Dial-ups List';
  612. $filters['NJABL DUL']['link'] = 'http://www.njabl.org/';
  613. $filters['NJABL DUL']['dns'] = 'dnsbl.njabl.org';
  614. $filters['NJABL DUL']['result'] = '127.0.0.3';
  615. $filters['NJABL DUL']['comment'] =
  616. _("FREE, for now - Not Just Another Blacklist - Dial-up IPs.");
  617. $filters['Conf DSBL.ORG Relay']['prefname'] = 'filters_spam_dsbl_conf_ss';
  618. $filters['Conf DSBL.ORG Relay']['name'] = 'DSBL.org Confirmed Relay List';
  619. $filters['Conf DSBL.ORG Relay']['link'] = 'http://www.dsbl.org/';
  620. $filters['Conf DSBL.ORG Relay']['dns'] = 'list.dsbl.org';
  621. $filters['Conf DSBL.ORG Relay']['result'] = '127.0.0.2';
  622. $filters['Conf DSBL.ORG Relay']['comment'] =
  623. _("FREE - Distributed Sender Boycott List - Confirmed Relays");
  624. $filters['Conf DSBL.ORG Multi-Stage']['prefname'] = 'filters_spam_dsbl_conf_ms';
  625. $filters['Conf DSBL.ORG Multi-Stage']['name'] = 'DSBL.org Confirmed Multi-Stage Relay List';
  626. $filters['Conf DSBL.ORG Multi-Stage']['link'] = 'http://www.dsbl.org/';
  627. $filters['Conf DSBL.ORG Multi-Stage']['dns'] = 'multihop.dsbl.org';
  628. $filters['Conf DSBL.ORG Multi-Stage']['result'] = '127.0.0.2';
  629. $filters['Conf DSBL.ORG Multi-Stage']['comment'] =
  630. _("FREE - Distributed Sender Boycott List - Confirmed Multi-stage Relays");
  631. $filters['UN-Conf DSBL.ORG']['prefname'] = 'filters_spam_dsbl_unc';
  632. $filters['UN-Conf DSBL.ORG']['name'] = 'DSBL.org UN-Confirmed Relay List';
  633. $filters['UN-Conf DSBL.ORG']['link'] = 'http://www.dsbl.org/';
  634. $filters['UN-Conf DSBL.ORG']['dns'] = 'unconfirmed.dsbl.org';
  635. $filters['UN-Conf DSBL.ORG']['result'] = '127.0.0.2';
  636. $filters['UN-Conf DSBL.ORG']['comment'] =
  637. _("FREE - Distributed Sender Boycott List - UN-Confirmed Relays");
  638. foreach ($filters as $Key => $Value) {
  639. $filters[$Key]['enabled'] = getPref($data_dir, $username,
  640. $filters[$Key]['prefname']);
  641. }
  642. return $filters;
  643. }
  644. /**
  645. * FIXME: Undocumented function
  646. * @access private
  647. */
  648. function remove_filter ($id) {
  649. global $data_dir, $username;
  650. while ($nextFilter = getPref($data_dir, $username, 'filter' .
  651. ($id + 1))) {
  652. setPref($data_dir, $username, 'filter' . $id, $nextFilter);
  653. $id ++;
  654. }
  655. removePref($data_dir, $username, 'filter' . $id);
  656. }
  657. /**
  658. * FIXME: Undocumented function
  659. * @access private
  660. */
  661. function filter_swap($id1, $id2) {
  662. global $data_dir, $username;
  663. $FirstFilter = getPref($data_dir, $username, 'filter' . $id1);
  664. $SecondFilter = getPref($data_dir, $username, 'filter' . $id2);
  665. if ($FirstFilter && $SecondFilter) {
  666. setPref($data_dir, $username, 'filter' . $id2, $FirstFilter);
  667. setPref($data_dir, $username, 'filter' . $id1, $SecondFilter);
  668. }
  669. }
  670. /**
  671. * This update the filter rules when renaming or deleting folders
  672. * @param array $args
  673. * @access private
  674. */
  675. function update_for_folder ($args) {
  676. $old_folder = $args[0];
  677. $new_folder = $args[2];
  678. $action = $args[1];
  679. global $plugins, $data_dir, $username;
  680. $filters = array();
  681. $filters = load_filters();
  682. $filter_count = count($filters);
  683. $p = 0;
  684. for ($i=0;$i<$filter_count;$i++) {
  685. if (!empty($filters)) {
  686. if ($old_folder == $filters[$i]['folder']) {
  687. if ($action == 'rename') {
  688. $filters[$i]['folder'] = $new_folder;
  689. setPref($data_dir, $username, 'filter'.$i,
  690. $filters[$i]['where'].','.$filters[$i]['what'].','.$new_folder);
  691. }
  692. elseif ($action == 'delete') {
  693. remove_filter($p);
  694. $p = $p-1;
  695. }
  696. }
  697. $p++;
  698. }
  699. }
  700. }
  701. /**
  702. * Display formated error message
  703. * @param string $string text message
  704. * @return string html formated text message
  705. * @access private
  706. */
  707. function do_error($string) {
  708. global $color;
  709. echo "<p align=\"center\"><font color=\"$color[2]\">";
  710. echo $string;
  711. echo "</font></p>\n";
  712. }
  713. ?>