filters.php 37 KB

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