Advertisement
Guest User

remote_imapd.pl

a guest
Dec 19th, 2014
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 2.90 KB | None | 0 0
  1. #!/usr/bin/perl -w
  2. use strict;  
  3. use warnings;  
  4. use FindBin;              
  5. use lib $FindBin::Bin;  
  6. use Lib;
  7. use const ':constants';
  8.  
  9. open(STDERR, '+>>', CHILD_LOG_FILE, );
  10. open(STDOUT, '+>>', CHILD_LOG_FILE, );
  11. my ($dbname,$dbuser,$dbpass, $dbhost, $dbport) = (DB_NAME, DB_LOGIN, DB_PASSWORD, DB_HOST, DB_PORT);
  12. my $dbh = DBI->connect("dbi:Pg:dbname=$dbname;host=$dbhost;port=$dbport", $dbuser, $dbpass,
  13.             { RaiseError => 0,
  14.             AutoCommit => 1,
  15.             PrintError => 0})
  16.     or &debug(4, $$, "Cannot connect to main DB at line ".__LINE__." in file ".__FILE__."\n");
  17. my ($db_ag_name,$db_ag_user,$db_ag_pass, $db_ag_host, $db_ag_port) = (DB_AGENT_NAME, DB_AGENT_LOGIN, DB_AGENT_PASSWORD, DB_AGENT_HOST, DB_AGENT_PORT);
  18. my $dbh_ag = DBI->connect("dbi:Pg:dbname=$db_ag_name;host=$db_ag_host;port=$db_ag_port", $db_ag_user, $db_ag_pass,
  19.             { RaiseError => 0,
  20.             AutoCommit => 1,
  21.             PrintError => 0,})
  22.     or &debug(4, $$, "Cannot connect to agents DB at line ".__LINE__." in file ".__FILE__."\n");
  23.  
  24. my $p_pid=$ARGV[0];
  25. my $interval = REMOTE_OUT_DELAY;
  26. my $send_mail_error_count = REMOTE_SEND_MAIL_ERROR_COUNT;
  27. my $status = DB_USERS_REMOTE_STATUS_PROCESSING;
  28. my (@array, @is_ok, @params, $user_id, $user_remote_id, $is_delete, $error_count, $is_first, $server, $port, $login, $password, $is_ssl, $no_error, $error_text, $pid, $date, $date_up, $exists, $q, $sth, $rv);
  29.  
  30. $| = 1;
  31. while (1) {
  32.     $pid = $$;
  33.     $date = &now;
  34.     $date_up = &now_up($interval);
  35.     $exists = kill 0, $p_pid or &debug(4, $pid, "Cannot check parent process $!\n") and exit;
  36.     &debug(4, $pid, "Parent is not running, i die\n") and exit if !$exists;
  37. ## select
  38.     if ($rv ne "0E0") {
  39.         while(@array = $sth->fetchrow_array()) {
  40.             $user_remote_id = $array[0];
  41.             $user_id = $array[1];
  42.             $error_count = $array[9];
  43.             $is_delete = $array[20];
  44.             $is_first = $array[22];
  45.             $server = $array[2];
  46.             $port = $array[3] ? $array[3] : 143;
  47.             $login = $array[4];
  48.             $password = decode_base64($array[5]);
  49.             $is_ssl = $array[12];
  50.         }
  51.         &debug(1, $pid, "=================== START DEBUGING ===================\n");
  52.         @is_ok = &get_remote_email($dbh, $dbh_ag, $user_id, $user_remote_id, $is_first, $is_delete, $server, $port, $login, $password, $is_ssl, $pid);
  53.         $no_error = $is_ok[0];
  54.         $error_text = $is_ok[1];
  55.         @params;
  56.         $params[1] = $error_text;
  57.         $params[2] = DB_USERS_REMOTE_STATUS_NEW;
  58.         $params[3] = REMOTE_MAX_ERROR_COUNT;
  59.         if ($no_error) {
  60.             ## update1
  61.         } else {
  62. #           &debug(3, $pid, $error_text);
  63.             $error_count = 1 + $error_count;
  64.             if ($error_count >= $params[3]) {
  65.                 ## update2
  66.             } else {
  67.                 ## update3
  68.             }
  69.         }
  70.     &debug(1, $pid, "=================== END DEBUGING =====================\n");
  71.     }
  72.     (@array, @is_ok, @params, $user_id, $user_remote_id, $is_delete, $error_count, $is_first, $server, $port, $login, $password, $is_ssl, $no_error, $error_text, $pid, $date, $date_up, $exists, $q, $sth, $rv) = undef;
  73.     usleep(DAEMON_CHILD_DELAY);
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement