protected function execute($arguments = array(), $options = array()) { // initialize the database connection $databaseManager = new sfDatabaseManager($this->configuration); $connection = $databaseManager->getDatabase($options['connection'] ? $options['connection'] : null)->getConnection(); $to = $arguments['to'] ? $arguments['to'] : ''; $message2 = $arguments['message'] ? $arguments['message'] : ''; // TODO : get login, localparts names $subject = "Welcome to JU email System"; $headers = 'From: Jimma University ICTDO <*****@*****.**>'; $message = <<<EOF Hello #FIRSTNAME# #FATHERSNAME#, We would like to inform you about the following. Your login name for the User Adminitration System is: #LOGIN# Please go to http://mail.ju.edu.et/uas/ to use it. The password to log in is the same as for the email system. Login in into the email system is still done with your email address. Thank you for your cooperation. We hope you will enjoy the UAS. Expect us to expand its functionality in the future. The ICT Development office EOF; $users = array(); if ($to != '') { $a = explode("@", $to); $users[] = UserPeer::getUserFromEmailLocalPart($a[0]); } else { $users = UserPeer::getEmailAccounts(); } if ($message2 != '') { $handle = fopen($message2, 'r'); $Data = fread($handle, filesize($message2)); fclose($handle); //echo $Data; } else { echo "You must provide file that has text"; } foreach ($users as $user) { $login = $user->getLogin(); $search = array("#LOGIN#", "#FIRSTNAME#", "#FATHERSNAME#", "#EMAILADDRESS#"); $replace = array($user->getLogin(), $user->getName(), $user->getFathersName(), $user->getEmailAddress()); echo str_replace($search, $replace, $Data); /*if(!mail($user->getEmailAddress(), $subject, str_replace($search, $replace, $Data), $headers)) { echo "message failed"; }*/ } //echo $message2; }
protected function execute($arguments = array(), $options = array()) { // initialize the database connection $databaseManager = new sfDatabaseManager($this->configuration); $connection = $databaseManager->getDatabase($options['connection'] ? $options['connection'] : null)->getConnection(); $to = $arguments['to'] ? $arguments['to'] : ''; // TODO : get login, localparts names $subject = "Notification"; $headers = 'From: ICT <*****@*****.**>'; $message = <<<EOF Hello #FIRSTNAME# #FATHERSNAME#, We would like to inform you about the following. Your login name for the User Adminitration System is: #LOGIN# Please go to http://mail.ju.edu.et/uas/ to use it. The password to log in is the same as for the email system. Login in into the email system is still done with your email address. Thank you for your cooperation. We hope you will enjoy the UAS. Expect us to expand its functionality in the future. The ICT Development office EOF; $users = array(); if ($to != '') { $users[] = UserPeer::getUserFromLogin($to); } else { $users = UserPeer::getEmailAccounts(); } foreach ($users as $user) { $login = $user->getLogin(); $search = array("#LOGIN#", "#FIRSTNAME#", "#FATHERSNAME#", "#EMAILADDRESS#"); $replace = array($user->getLogin(), $user->getName(), $user->getFathersName(), $user->getEmailAddress()); if (!mail($user->getEmailAddress(), $subject, str_replace($search, $replace, $message), $headers)) { echo "message failed"; } } }
protected function execute($arguments = array(), $options = array()) { // initialize the database connection $databaseManager = new sfDatabaseManager($this->configuration); $connection = $databaseManager->getDatabase($options['connection'] ? $options['connection'] : null)->getConnection(); // add your code here $dir_for_deleted_accounts = $arguments['dirdeleted'] ? $arguments['dirdeleted'] : '/home/vmail_deleted'; $dir = $arguments['dir'] ? $arguments['dir'] : '/home/vmail'; $db_email_addresses = array(); $domains_on_system = array(); $system_email_addresses = array(); foreach (UserPeer::getEmailAccounts() as $user) { $db_email_addresses[] = $user->getEmailAddress(); } if ($handle_domain = opendir($dir)) { while (false !== ($domain_dir = readdir($handle_domain))) { if ($domain_dir != "." && $domain_dir != "..") { if (is_dir($dir . "/" . $domain_dir)) { $domains_on_system[$domain_dir] = 1; if ($handle_local_part = opendir($dir . "/" . $domain_dir)) { while (false !== ($local_part_dir = readdir($handle_local_part))) { if ($local_part_dir != "." && $local_part_dir != "..") { //is $local_part_dir is directory if (is_dir($dir . "/" . $domain_dir . "/" . $local_part_dir)) { // put email accounts on array $system_email_addresses[] = "{$local_part_dir}@{$domain_dir}"; //echo "$subfile@$file\n"; } else { echo $dir . "/" . $domain_dir . "/" . $local_part_dir; die("Not a directory"); } } } } } else { die($dir . $domain_dir . " not directory"); } } } closedir($handle_domain); } else { die($dir . "does not exist"); } if (sizeof($domains_on_system) == 0) { die("Please create the domain names under {$dir}\n"); } // Create domain name directory where we store deleted accounts foreach (array_keys($domains_on_system) as $domain_on_system) { if (!is_dir($dir_for_deleted_accounts . "/" . $domain_on_system)) { exec("mkdir " . $dir_for_deleted_accounts . "/" . $domain_on_system); } } // Compute accounts to be deleted. if (sizeof($system_email_addresses) == 0) { $deleted_accounts = array(); } else { $deleted_accounts = array_diff($system_email_addresses, $db_email_addresses); } foreach ($deleted_accounts as $deleted_account) { // Get the local part and domain name from the email address $a = explode("@", $deleted_account); $local_part = $a[0]; $domain = $a[1]; $path = $domain . "/" . $local_part; exec("mv {$dir}/{$path} {$dir_for_deleted_accounts}/{$path}"); echo "mv {$dir}/{$path} {$dir_for_deleted_accounts}/{$path}\n"; } //Accounts to have home directory created. $create_accounts = array_diff($db_email_addresses, $system_email_addresses); foreach ($create_accounts as $create_account) { // Get the local part and domain name from the email address $a = explode("@", $create_account); $local_part = $a[0]; $domain = $a[1]; $path = $domain . "/" . $local_part; exec("mkdir -p {$dir}/{$path}"); $output = shell_exec("symfony uas:sendLoginNames messages/welcomeMessage {$local_part}@{$domain}\n"); //echo("symfony uas:sendLoginNames messages/LoginNames ${local_part}@${domain}\n"); echo "<pre>{$output}</pre>"; chown("{$dir}/{$path}", "vmail"); chgrp("{$dir}/{$path}", "vmail"); echo "mkdir -p {$dir}/{$path}\n"; } }