Пример #1
0
 public static function getInstance()
 {
     if (null == self::$instance) {
         self::$instance = new CerberusSimulator();
     }
     return self::$instance;
 }
Пример #2
0
 function generateTicketsAction()
 {
     require_once dirname(__FILE__) . '/api/API.class.php';
     $tpl = DevblocksPlatform::getTemplateService();
     $tpl_path = dirname(__FILE__) . '/templates/';
     $tpl->assign('path', $tpl_path);
     @($address = DevblocksPlatform::importGPC($_POST['address'], 'string'));
     @($dataset = DevblocksPlatform::importGPC($_POST['dataset'], 'string'));
     @($how_many = DevblocksPlatform::importGPC($_POST['how_many'], 'integer', 0));
     if (empty($address)) {
         $tpl->assign('error', sprintf("Oops! '%s' is not a valid e-mail address.", htmlspecialchars($address)));
         $tpl->display('file:' . $tpl_path . 'config_tab/output.tpl');
         return;
     }
     // [JAS]: [TODO] This should probably move to an extension point later
     switch ($dataset) {
         default:
         case "retail":
             $dataset = new RetailDataset();
             break;
         case "hosting":
             $dataset = new HostingDataset();
             break;
         case "edu":
             $dataset = new EduDataset();
             break;
         case "gov":
             $dataset = new GovDataset();
             break;
         case "npo":
             $dataset = new NPODataset();
             break;
         case "spam":
             $dataset = new SpamDataset();
             break;
     }
     $simulator = CerberusSimulator::getInstance();
     $emails = $simulator->generateEmails($dataset, $how_many);
     foreach ($emails as $template) {
         if (preg_match("/\"(.*?)\" \\<(.*?)\\>/", $template['sender'], $matches)) {
             $personal = $matches[1];
             $from = $matches[1];
         }
         // [TODO] error checking
         $message = new CerberusParserMessage();
         $message->headers['from'] = $template['sender'];
         $message->headers['to'] = $address;
         $message->headers['subject'] = $template['subject'];
         $message->headers['message-id'] = CerberusApplication::generateMessageId();
         $message->body = sprintf("%s\r\n" . "\r\n" . "--\r\n%s\r\n", $template['body'], $personal);
         CerberusParser::parseMessage($message, array('no_autoreply' => true));
     }
     $tpl->assign('output', sprintf("Success!  %d simulated tickets were generated for %s", $how_many, htmlspecialchars($address)));
     $tpl->display('file:' . $tpl_path . 'config_tab/output.tpl');
 }