public function testResponseIsSentToLogger() { $evt = $this->_createResponseEvent("354 Go ahead\r\n"); $logger = $this->_createLogger(); $this->_checking(Expectations::create()->one($logger)->add(pattern('~354 Go ahead\\r\\n~'))); $plugin = $this->_createPlugin($logger); $plugin->responseReceived($evt); }
public function testDomainNameIsPlacedInHelo() { //Overridden to include ESMTP /* -- RFC 2821, 4.1.4. The SMTP client MUST, if possible, ensure that the domain parameter to the EHLO command is a valid principal host name (not a CNAME or MX name) for its host. If this is not possible (e.g., when the client's address is dynamically assigned and the client does not have an obvious name), an address literal SHOULD be substituted for the domain name and supplemental information provided that will assist in identifying the client. */ $buf = $this->_getBuffer(); $smtp = $this->_getTransport($buf); $s = $this->_sequence('SMTP-convo'); $this->_checking(Expectations::create()->one($buf)->initialize()->inSequence($s)->one($buf)->readLine(0)->inSequence($s)->returns("220 some.server.tld bleh\r\n")->one($buf)->write(pattern('~^EHLO .+?\\r\\n$~D'))->inSequence($s)->returns(1)->one($buf)->readLine(1)->inSequence($s)->returns('501 WTF' . "\r\n")->one($buf)->write("HELO mydomain.com\r\n")->inSequence($s)->returns(2)->one($buf)->readLine(2)->inSequence($s)->returns('250 ServerName' . "\r\n")); $this->_finishBuffer($buf); $smtp->setLocalDomain('mydomain.com'); $smtp->start(); }
public function testChainOfCommandAlgorithmWhenNotifyingExtensions() { $buf = $this->_getBuffer(); $smtp = $this->_getTransport($buf); $ext1 = $this->_mock('Swift_Transport_EsmtpHandler'); $ext2 = $this->_mock('Swift_Transport_EsmtpHandler'); $ext3 = $this->_mock('Swift_Transport_EsmtpHandler'); $s = $this->_sequence('Initiation-sequence'); $this->_checking(Expectations::create()->one($buf)->readLine(0)->inSequence($s)->returns("220 server.com foo\r\n")->one($buf)->write(pattern('~^EHLO .*?\\r\\n$~D'))->inSequence($s)->returns(1)->one($buf)->readLine(1)->inSequence($s)->returns("250-ServerName.tld\r\n")->one($buf)->readLine(1)->inSequence($s)->returns("250-AUTH PLAIN LOGIN\r\n")->one($buf)->readLine(1)->inSequence($s)->returns("250 SIZE=123456\r\n")->never($buf)->write("FOO\r\n")->allowing($ext1)->getHandledKeyword()->returns('AUTH')->one($ext1)->onCommand($smtp, "FOO\r\n", array(250, 251), optional())->calls(array($this, 'cbStopCommand'))->allowing($ext2)->getHandledKeyword()->returns('SIZE')->never($ext2)->onCommand(any(), any(), any(), optional())->allowing($ext3)->getHandledKeyword()->returns('STARTTLS')->never($ext3)->onCommand(any(), any(), any(), optional())->ignoring($ext1)->ignoring($ext2)->ignoring($ext3)); $this->_finishBuffer($buf); $smtp->setExtensionHandlers(array($ext1, $ext2, $ext3)); $smtp->start(); $smtp->executeCommand("FOO\r\n", array(250, 251)); }
public function testIdIsAutoGenerated() { $headers = $this->_createHeaderSet(array(), false); $this->_checking(Expectations::create()->one($headers)->addIdHeader('Message-ID', pattern('/^.*?@.*?$/D'))->ignoring($headers)); $message = $this->_createMessage($headers, $this->_createEncoder(), $this->_createCache()); }
[site][user]" id="<?php echo $formname; ?> _site_user" placeholder="*****@*****.**" required/><br /> <label for="<?php echo $formname; ?> _site_password" data-icon="x"></label> <input type="password" name="<?php echo $formname; ?> [site][password]" id="<?php echo $formname; ?> _site_password" placeholder="Password" pattern="<?php echo pattern('password'); ?> " required/><br /> <label for="<?php echo $formname; ?> _site_repeat" data-icon="*"></label> <input type="password" name="<?php echo $formname; ?> [site][repeat]" id="<?php echo $formname; ?> _site_repeat" placeholder="Repeat password" data-must-match="<?php echo $formname; ?>
} else { if (array_key_exists('install', $_POST) and is_array($_POST['install']) and array_keys_exist('root', 'head', 'site', $_POST['install'])) { $created_con = false; $root = (object) $_POST['install']['root']; $root->database = 'information_schema'; $head = (object) $_POST['install']['head']; $head->viewport = 'width=device-width, height=device-height'; $head->charset = 'UTF-8'; $site = (object) $_POST['install']['site']; if (array_key_exists('connect', $_POST['install']) and is_array($_POST['install']['connect']) and array_keys_exist('user', 'password', 'repeat', $_POST['install']['connect'])) { $con = (object) $_POST['install']['connect']; $con->database = $con->user; } else { $con = null; } if (isset($site->user) and is_email($site->user) and isset($root->user) and preg_match('/^\\w+$/', $root->user) and isset($site->password) and preg_match('/' . pattern('password') . '/', $site->password) and isset($site->repeat) and $site->repeat === $site->password and isset($head->title) and preg_match('/^[\\w- ]{5,}$/', $head->title) and isset($head->keywords) and preg_match('/^[\\w, -]+$/', $head->keywords) and isset($head->description) and preg_match('/^[\\w-,\\.\\?\\! ]{1,160}$/', $head->description) and isset($head->robots) and preg_match('/^(no)?follow, (no)?index$/i', $head->robots) and (isset($head->author_g_plus) and is_url($head->author_g_plus)) and isset($head->author) and preg_match('/^[\\w- ]{5,}$/', $head->author) and (is_null($head->rss) or empty($head->rss) or is_url($head->rss)) and (is_null($head->publisher) or empty($head->publisher) or is_url($head->publisher)) and (is_null($head->google_analytics_code) or empty($head->google_analytics_code) or preg_match('/^[A-z]{2}-[A-z\\d]{8}-\\d$/', $head->google_analytics_code)) and (is_null($head->author) or empty($head->author) or preg_match('/^[\\w- ]{5,}$/', $head->author)) and (is_null($con) or preg_match('/' . pattern('password') . '/', $con->password) and $con->password === $con->repeat and !file_exists(BASE . '/config/connect.ini'))) { $pdo = new \shgysk8zer0\Core\PDO($root); if ($pdo->connected) { if (is_object($con)) { $config_dir = BASE . DIRECTORY_SEPARATOR . 'config'; if (is_writable($config_dir)) { file_put_contents($config_dir . DIRECTORY_SEPARATOR . 'connect.json', json_encode(['user' => $con->user, 'password' => $con->password, 'database' => $con->user], JSON_PRETTY_PRINT)); } else { $resp->notify('Could not save database connection settings to file', 'Make sure that config/ is writable'); exit($resp); } } $con_json = \shgysk8zer0\Core\resources\Parser::parseFile('connect.json'); $database = "`{$pdo->escape($con_json->database)}`"; $pdo->query("CREATE DATABASE IF NOT EXISTS {$database}"); $created = $pdo->prepare("GRANT ALL ON {$database}.*\n\t\t\t\t\t\t\tTO :user@'localhost'\n\t\t\t\t\t\t\tIDENTIFIED BY :password;")->bind(['user' => $con_json->user, 'password' => $con_json->password])->execute();
/** * checks whether value is matched by given regular expression * * @param string $regex regular expression to apply * @return bool */ public function isMatchedBy(string $regex) : bool { return pattern($regex)->matches($this->value); }
<?php function pattern($num) { $num = intval($num); if ($num < 0 || $num > 150) { echo 'input data error!'; exit; } $result_row = ''; $mod = fmod($num, 10); for ($row = 0; $row < $num; $row++) { $mark = $mod - $row; for ($count = $mod; $count > $mark; $count--) { $result_row .= fmod($count + 10 * $row, 10); } $col_temp = fmod($mark + 10 * $row, 10); $result_row .= str_repeat($col_temp, $num - $row); echo $result_row; echo '<br>'; $result_row = ''; } } pattern(27);
<?php $dialog = $doc->appendChild($doc->createElement('dialog')); $dialog->{'@id'} = 'loginDialog'; $form = $dialog->appendChild($doc->createElement('form')); $form->{'@name'} = 'login'; $form->{'@action'} = URL; $form->{'@method'} = 'POST'; $fieldset = $form->appendChild($doc->createElement('fieldset')); $fieldset->{'@form'} = 'login'; $fieldset->legend('Login')->label(['@for' => 'user', '@data-icon' => '@'])->input(['@type' => 'email', '@name' => 'user', '@id' => 'user', '@placeholder' => '*****@*****.**', '@required' => null])->br(null)->label(['@for' => 'password', '@data-icon' => 'x'])->input(['@type' => 'password', '@name' => 'password', '@id' => 'password', '@pattern' => pattern('password'), '@placeholder' => 'What\'s the password', '@required' => null])->button(['@type' => 'submit', '@title' => 'Login', '@data-icon' => 'X'])->button(['@type' => 'reset', '@title' => 'Reset Form', '@data-icon' => 'V'])->button(['@type' => 'button', '@title' => 'Close Dialog', '@data-close' => '#loginDialog']); echo $dialog;
protected function _finishBuffer($buf) { $this->_checking(Expectations::create()->ignoring($buf)->readLine(0)->returns('220 server.com foo' . "\r\n")->ignoring($buf)->write(pattern('~^(EH|HE)LO .*?\\r\\n$~D'))->returns($x = uniqid())->ignoring($buf)->readLine($x)->returns('250 ServerName' . "\r\n")->ignoring($buf)->write(pattern('~^MAIL FROM: <.*?>\\r\\n$~D'))->returns($x = uniqid())->ignoring($buf)->readLine($x)->returns('250 OK' . "\r\n")->ignoring($buf)->write(pattern('~^RCPT TO: <.*?>\\r\\n$~D'))->returns($x = uniqid())->ignoring($buf)->readLine($x)->returns('250 OK' . "\r\n")->ignoring($buf)->write("DATA\r\n")->returns($x = uniqid())->ignoring($buf)->readLine($x)->returns('354 OK' . "\r\n")->ignoring($buf)->write("\r\n.\r\n")->returns($x = uniqid())->ignoring($buf)->readLine($x)->returns('250 OK' . "\r\n")->ignoring($buf)->write("RSET\r\n")->returns($x = uniqid())->ignoring($buf)->readLine($x)->returns("250 OK\r\n")->ignoring($buf)->returns(false)); }