Advertisement
TBotNik

tb_rules.php

Nov 7th, 2012
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.31 KB | None | 0 0
  1. <?php
  2. /***************************************************************************/
  3. /* Author: Nyle E. Davis Create Date: 12/10/05 */
  4. /* E-Mail: davisoftaec@gmail.com Revision: 1.0 */
  5. /* File: tbird_rules.php Path: localhost/Project/Tools/ */
  6. /* Purpose: This file process all the existing TBird filter files, put */
  7. /* all the rules into a MySQL DB, checking for duplicates, then */
  8. /* pulls the rules from MySQL and rewrites all TBird rule files */
  9. /* with the complete rule set. Future capabilities will allow */
  10. /* full control of the rule set. Blog forthcoming on the */
  11. /* future rule set capabilities. */
  12. /***************************************************************************/
  13. // Define Processing Constants
  14. define ('DB_HST', 'localhost'); // DB Host
  15. define ('DB_PRT', 3306); // DB Port
  16. define ('DB_UID', 'myuser'); // DB User
  17. define ('DB_PWD', 'mypass'); // DB Password
  18. define ('DB_USE', 'TBirdRules'); // DB Default DB
  19. define ('CR_DIR', getcwd().'/'); // Current Directory
  20. $var_ray = array('DB_HST','DB_PRT','DB_UID','DB_PWD','DB_USE','CR_DIR');
  21.  
  22. $tr = new TBird_Rules();
  23.  
  24. Class TBird_Rules {
  25.  
  26. function __Construct() {
  27. /*********************************************************************/
  28. /* Purpose: Start the object and istantiate the initial var */
  29. /* settings. */
  30. /*********************************************************************/
  31. include (EM_DIR.'em_dio.php'); // Call Enterprise Modules DB IO proc.
  32. $emdb = new em_dio();
  33. $dbc = $em_dio->db_connect;
  34. $ffile = self::find_rules;
  35. if (!$ffile===false) {
  36. $fil_ray = self::read_rules;
  37. //return $fil_ray;
  38. } // end if !$ffile
  39. $rs = self::proc_rules();
  40. } // end fuction __Construct
  41.  
  42. function __Destruct() {
  43. /*********************************************************************/
  44. /* Purpose: Close the object and destory all the vars. */
  45. /*********************************************************************/
  46. foreach ($this->var_ray as $key) {
  47. unset($key);
  48. } // end foreach $this->var_ray
  49. } // end fuction __Destruct
  50.  
  51. function find_rules() {
  52. /*********************************************************************/
  53. /* Purpose: Run the "locate -i MsgFilterRules.dat" cmd and put the */
  54. /* results into a readable text file. */
  55. /* Note: If you are on Windows or a version of Linux that does */
  56. /* support this command then read up on what command you */
  57. /* need to replace "locate" to find all the rule files on */
  58. /* your system. */
  59. /*********************************************************************/
  60. echo exec("sudo -i");
  61. $if (!is_dir('/data')) { echo exec("sudo mkdir /data"); }
  62. $if (!is_dir('/data/TBird')) { echo exec("sudo mkdir /data/TBird"); }
  63. echo exec("locate -i MsgFilterRules.dat > /data/TBird/tbird_rfiles.txt");
  64. return '/data/TBird/tbird_rfiles.txt';
  65. } // end fuction find_rules
  66.  
  67. function read_rules($rfile) {
  68. /*********************************************************************/
  69. /* Purpose: Read the list of rules files and put the list into an */
  70. /* array. */
  71. /*********************************************************************/
  72. if (!file_exists($rfile)) {
  73. echo "File => $rfile <= not found!";
  74. return false;
  75. }
  76. line = array();
  77. $pfile = @fopen($rfile, "r") or die ("Could not open the file => $rfile");
  78. while (!feof($pfile)) {
  79. $line[] = fgets($pfile);
  80. } // end while !feof
  81. fclose($pfile);
  82. return $line;
  83. } // end fuction read_rules
  84.  
  85. function proc_rules($lst_ray) {
  86. /*********************************************************************/
  87. /* Purpose: This method parses the lines from the rules files and */
  88. /* sets them into an array that can be used to create SQL */
  89. /* inserts and duplication queries, so the rules can be */
  90. /* recreated from the DB and equally written into all the */
  91. /* account files. The DB contains markers for each */
  92. /* profile to allow selection of rules to each profile. */
  93. /*********************************************************************/
  94. $i = 0;
  95. $out_ray = array();
  96. $tst_ray = array(0=>'name=',1=>'enabled=',2=>'type=',3=>'action=',
  97. 4=>'actionValue=',5=>'condition=');
  98. foreach ($lst_ray as $key => $val) {
  99. if (file_exists($val)) {
  100. $fh = @fopen($val, "r");
  101. while (!feof($fh)) {
  102. $line = fgets($fh);
  103. $i++;
  104. foreach ($tst_ray as $k => $v) {
  105. if (strpos($line,$v)) {
  106. $sp = strpos($line,$v)+1;
  107. $out_str = substr($line,$sp);
  108. switch ($v) {
  109. case 'name=':
  110. $out_ray[$i] = array(0,"`rul_nam`='$out_str'");
  111. break;
  112. case 'enabled=':
  113. $out_ray[$i] = array(1,"`rul_enb`='$out_str'");
  114. break;
  115. case 'type=':
  116. $out_ray[$i] = array(2,"`rul_typ`='$out_str'");
  117. break;
  118. case 'action=':
  119. $out_ray[$i] = array(3,"`rul_act`='$out_str'");
  120. break;
  121. case 'actionValue=':
  122. $out_ray[$i] = array(4,"`rul_val`='$out_str'");
  123. break;
  124. case 'condition=':
  125. $out_ray[$i] = array(5,"`rul_cnd='$out_str'");
  126. break;
  127. } // end switch $v
  128. } else {
  129. $out_ray[$i] = $line;
  130. continue;
  131. } // end if strpos
  132. } // end foreach $tst_ray
  133. } // end while !feof
  134. fclose($pfile);
  135. }
  136. return $out_ray;
  137. } // end foreach $this->lst_ray
  138. } // end fuction proc_rules
  139.  
  140. function db_check_dup() {
  141. /*********************************************************************/
  142. /* Purpose: Start the object and istantiate the initial var */
  143. /* settings. */
  144. /*********************************************************************/
  145.  
  146. } // end fuction db_check_dup
  147.  
  148. function db_insert() {
  149. /*********************************************************************/
  150. /* Purpose: Start the object and istantiate the initial var */
  151. /* settings. */
  152. /*********************************************************************/
  153.  
  154. } // end fuction db_insert
  155.  
  156. function db_fetch() {
  157. /*********************************************************************/
  158. /* Purpose: Start the object and istantiate the initial var */
  159. /* settings. */
  160. /*********************************************************************/
  161.  
  162. } // end fuction db_fetch
  163.  
  164. function write_rules() {
  165. /*********************************************************************/
  166. /* Purpose: Start the object and istantiate the initial var */
  167. /* settings. */
  168. /*********************************************************************/
  169.  
  170. } // end fuction write_rules
  171.  
  172. } // end class TBird_Rules
  173. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement