Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /***************************************************************************/
- /* Author: Nyle E. Davis Create Date: 12/10/05 */
- /* E-Mail: davisoftaec@gmail.com Revision: 1.0 */
- /* File: tbird_rules.php Path: localhost/Project/Tools/ */
- /* Purpose: This file process all the existing TBird filter files, put */
- /* all the rules into a MySQL DB, checking for duplicates, then */
- /* pulls the rules from MySQL and rewrites all TBird rule files */
- /* with the complete rule set. Future capabilities will allow */
- /* full control of the rule set. Blog forthcoming on the */
- /* future rule set capabilities. */
- /***************************************************************************/
- // Define Processing Constants
- define ('DB_HST', 'localhost'); // DB Host
- define ('DB_PRT', 3306); // DB Port
- define ('DB_UID', 'myuser'); // DB User
- define ('DB_PWD', 'mypass'); // DB Password
- define ('DB_USE', 'TBirdRules'); // DB Default DB
- define ('CR_DIR', getcwd().'/'); // Current Directory
- $var_ray = array('DB_HST','DB_PRT','DB_UID','DB_PWD','DB_USE','CR_DIR');
- $tr = new TBird_Rules();
- Class TBird_Rules {
- function __Construct() {
- /*********************************************************************/
- /* Purpose: Start the object and istantiate the initial var */
- /* settings. */
- /*********************************************************************/
- include (EM_DIR.'em_dio.php'); // Call Enterprise Modules DB IO proc.
- $emdb = new em_dio();
- $dbc = $em_dio->db_connect;
- $ffile = self::find_rules;
- if (!$ffile===false) {
- $fil_ray = self::read_rules;
- //return $fil_ray;
- } // end if !$ffile
- $rs = self::proc_rules();
- } // end fuction __Construct
- function __Destruct() {
- /*********************************************************************/
- /* Purpose: Close the object and destory all the vars. */
- /*********************************************************************/
- foreach ($this->var_ray as $key) {
- unset($key);
- } // end foreach $this->var_ray
- } // end fuction __Destruct
- function find_rules() {
- /*********************************************************************/
- /* Purpose: Run the "locate -i MsgFilterRules.dat" cmd and put the */
- /* results into a readable text file. */
- /* Note: If you are on Windows or a version of Linux that does */
- /* support this command then read up on what command you */
- /* need to replace "locate" to find all the rule files on */
- /* your system. */
- /*********************************************************************/
- echo exec("sudo -i");
- $if (!is_dir('/data')) { echo exec("sudo mkdir /data"); }
- $if (!is_dir('/data/TBird')) { echo exec("sudo mkdir /data/TBird"); }
- echo exec("locate -i MsgFilterRules.dat > /data/TBird/tbird_rfiles.txt");
- return '/data/TBird/tbird_rfiles.txt';
- } // end fuction find_rules
- function read_rules($rfile) {
- /*********************************************************************/
- /* Purpose: Read the list of rules files and put the list into an */
- /* array. */
- /*********************************************************************/
- if (!file_exists($rfile)) {
- echo "File => $rfile <= not found!";
- return false;
- }
- line = array();
- $pfile = @fopen($rfile, "r") or die ("Could not open the file => $rfile");
- while (!feof($pfile)) {
- $line[] = fgets($pfile);
- } // end while !feof
- fclose($pfile);
- return $line;
- } // end fuction read_rules
- function proc_rules($lst_ray) {
- /*********************************************************************/
- /* Purpose: This method parses the lines from the rules files and */
- /* sets them into an array that can be used to create SQL */
- /* inserts and duplication queries, so the rules can be */
- /* recreated from the DB and equally written into all the */
- /* account files. The DB contains markers for each */
- /* profile to allow selection of rules to each profile. */
- /*********************************************************************/
- $i = 0;
- $out_ray = array();
- $tst_ray = array(0=>'name=',1=>'enabled=',2=>'type=',3=>'action=',
- 4=>'actionValue=',5=>'condition=');
- foreach ($lst_ray as $key => $val) {
- if (file_exists($val)) {
- $fh = @fopen($val, "r");
- while (!feof($fh)) {
- $line = fgets($fh);
- $i++;
- foreach ($tst_ray as $k => $v) {
- if (strpos($line,$v)) {
- $sp = strpos($line,$v)+1;
- $out_str = substr($line,$sp);
- switch ($v) {
- case 'name=':
- $out_ray[$i] = array(0,"`rul_nam`='$out_str'");
- break;
- case 'enabled=':
- $out_ray[$i] = array(1,"`rul_enb`='$out_str'");
- break;
- case 'type=':
- $out_ray[$i] = array(2,"`rul_typ`='$out_str'");
- break;
- case 'action=':
- $out_ray[$i] = array(3,"`rul_act`='$out_str'");
- break;
- case 'actionValue=':
- $out_ray[$i] = array(4,"`rul_val`='$out_str'");
- break;
- case 'condition=':
- $out_ray[$i] = array(5,"`rul_cnd='$out_str'");
- break;
- } // end switch $v
- } else {
- $out_ray[$i] = $line;
- continue;
- } // end if strpos
- } // end foreach $tst_ray
- } // end while !feof
- fclose($pfile);
- }
- return $out_ray;
- } // end foreach $this->lst_ray
- } // end fuction proc_rules
- function db_check_dup() {
- /*********************************************************************/
- /* Purpose: Start the object and istantiate the initial var */
- /* settings. */
- /*********************************************************************/
- } // end fuction db_check_dup
- function db_insert() {
- /*********************************************************************/
- /* Purpose: Start the object and istantiate the initial var */
- /* settings. */
- /*********************************************************************/
- } // end fuction db_insert
- function db_fetch() {
- /*********************************************************************/
- /* Purpose: Start the object and istantiate the initial var */
- /* settings. */
- /*********************************************************************/
- } // end fuction db_fetch
- function write_rules() {
- /*********************************************************************/
- /* Purpose: Start the object and istantiate the initial var */
- /* settings. */
- /*********************************************************************/
- } // end fuction write_rules
- } // end class TBird_Rules
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement