* because an RNG in user space memory is undesirable. * * For background, see http://sockpuppet.org/blog/2014/02/25/safely-generate-random-numbers/ */ $bytes = ''; // If we are on Linux or any OS that mimics the Linux /dev/urandom device, e.g. FreeBSD or OS X, // then read from /dev/urandom. if (file_exists('/dev/urandom')) { $handle = fopen('/dev/urandom', 'r'); if ($handle !== false) { $bytes .= fread($handle, $length); fclose($handle); } } if (StringHelper::byteLength($bytes) >= $length) { return StringHelper::byteSubstr($bytes, 0, $length);
*/ $bytes = ''; // If we are on Linux or any OS that mimics the Linux /dev/urandom device, e.g. FreeBSD or OS X, // then read from /dev/urandom. if (file_exists('/dev/urandom')) { $handle = fopen('/dev/urandom', 'r'); if ($handle !== false) { $bytes .= fread($handle, $length); fclose($handle); } }
* @return string the generated random key * @throws InvalidConfigException if OpenSSL extension is needed but not installed. * @throws Exception on failure. */ public function generateRandomString($length = 32) { $bytes = $this->generateRandomKey($length); // '=' character(s) returned by base64_encode() are always discarded because // they are guaranteed to be after position $length in the base64_encode() output. return strtr(substr(base64_encode($bytes), 0, $length), '+/', '_-'); } /**
/** * Generates an unmasked random token used to perform CSRF validation. * @return string the random token for CSRF validation. */ protected function generateCsrfToken() { $token = Yii::$app->getSecurity()->generateRandomString(); if ($this->enableCsrfCookie) { $cookie = $this->createCsrfCookie($token); Yii::$app->getResponse()->getCookies()->add($cookie); } else { Yii::$app->getSession()->set($this->csrfParam, $token); }
* @return string the token used to perform CSRF validation. */ public function getCsrfToken($regenerate = false) { if ($this->_csrfToken === null || $regenerate) { if ($regenerate || ($token = $this->loadCsrfToken()) === null) { $token = $this->generateCsrfToken(); } // the mask doesn't need to be very random $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-.'; $mask = substr(str_shuffle(str_repeat($chars, 5)), 0, self::CSRF_MASK_LENGTH); // The + sign may be decoded as blank space later, which will fail the validation $this->_csrfToken = str_replace('+', '.', base64_encode($mask . $this->xorTokens($token, $mask)));
if (strcasecmp($method, 'get') && strcasecmp($method, 'post')) { // simulate PUT, DELETE, etc. via POST $hiddenInputs[] = static::hiddenInput($request->methodParam, $method); $method = 'post'; } if ($request->enableCsrfValidation && !strcasecmp($method, 'post')) { $hiddenInputs[] = static::hiddenInput($request->csrfParam, $request->getCsrfToken()); } } if (!strcasecmp($method, 'get') && ($pos = strpos($action, '?')) !== false) { // query parameters in the action are ignored for GET method // we use hidden fields to add them back
*/ public function init() { if (!isset($this->options['id'])) { $this->options['id'] = $this->getId(); } echo Html::beginForm($this->action, $this->method, $this->options); } /** * Runs the widget. * This registers the necessary javascript code and renders the form close tag. * @throws InvalidCallException if `beginField()` and `endField()` calls are not matching
*/ public function __construct($config = []) { if (!empty($config)) { Yii::configure($this, $config); } $this->init(); } /** * Initializes the object. * This method is invoked at the end of the constructor after the object is initialized with the * given configuration.
return $reflection->newInstanceArgs($dependencies); } if (!empty($dependencies) && $reflection->implementsInterface('yii\base\Configurable')) { // set $config as the last parameter (existing one will be overwritten) $dependencies[count($dependencies) - 1] = $config; return $reflection->newInstanceArgs($dependencies); } else { $object = $reflection->newInstanceArgs($dependencies); foreach ($config as $name => $value) { $object->$name = $value; } return $object;
public function get($class, $params = [], $config = []) { if (isset($this->_singletons[$class])) { // singleton return $this->_singletons[$class]; } elseif (!isset($this->_definitions[$class])) { return $this->build($class, $params, $config); } $definition = $this->_definitions[$class]; if (is_callable($definition, true)) { $params = $this->resolveDependencies($this->mergeParams($class, $params));
{ if (is_string($type)) { return static::$container->get($type, $params); } elseif (is_array($type) && isset($type['class'])) { $class = $type['class']; unset($type['class']); return static::$container->get($class, $params, $type); } elseif (is_callable($type, true)) { return call_user_func($type, $params); } elseif (is_array($type)) { throw new InvalidConfigException('Object configuration must be an array containing a "class" element.'); } else { throw new InvalidConfigException("Unsupported configuration type: " . gettype($type));
* @return static the newly created widget instance */ public static function begin($config = []) { $config['class'] = get_called_class(); /* @var $widget Widget */ $widget = Yii::createObject($config); static::$stack[] = $widget; return $widget; } /**
</ul> </nav> <!-- Modal Login --> <div id="modal-login" style="display: none"> <?php $client = new app\models\form\LoginForm(); ?> <?php $form = ActiveForm::begin(['id' => 'login-form', 'action' => url('login')]); ?> <?= $form->field($client, 'username', ['inputOptions' => ['class' => 'email form-control', 'placeholder' => 'E-mail']])->label(false); ?> <?= $form->field($client, 'password', ['inputOptions' => ['class' => 'pass form-control', 'placeholder' => 'Senha']])->passwordInput()->label(false); ?> <button type="submit">Entrar</button> <a href="javascript:;" onclick="$('#modal-lost-password').show();">esqueceu a senha?</a> <a class="btn-fechar-login">Fechar</a> <?php ActiveForm::end(); ?>
*/ public function renderPhpFile($_file_, $_params_ = []) { ob_start(); ob_implicit_flush(false); extract($_params_, EXTR_OVERWRITE); require($_file_); return ob_get_clean(); } /** * Renders dynamic content returned by the given PHP statements.
$this->renderers[$ext] = Yii::createObject($this->renderers[$ext]); } /* @var $renderer ViewRenderer */ $renderer = $this->renderers[$ext]; $output = $renderer->render($this, $viewFile, $params); } else { $output = $this->renderPhpFile($viewFile, $params); } $this->afterRender($viewFile, $params, $output); } array_pop($this->_viewFiles); $this->context = $oldContext;
* @since 2.0.1 */ public function renderContent($content) { $layoutFile = $this->findLayoutFile($this->getView()); if ($layoutFile !== false) { return $this->getView()->renderFile($layoutFile, ['content' => $content], $this); } else { return $content; } } /**
* @return string the rendering result. * @throws InvalidParamException if the view file or the layout file does not exist. */ public function render($view, $params = []) { $content = $this->getView()->render($view, $params, $this); return $this->renderContent($content); } /** * Renders a static string by applying a layout. * @param string $content the static string being rendered * @return string the rendering result of the layout with the given static string as the `$content` variable.
class CursosController extends Controller { public function actionIndex() { $materiais = \app\models\Material::find()->released()->orderBy('title ASC')->all(); return $this->render('index', ['materiais' => $materiais]); } public function actionPresencial() { $cursos = CoursePresential::find()->released()->orderBy('sort ASC')->all();
$args = $this->controller->bindActionParams($this, $params); Yii::trace('Running action: ' . get_class($this->controller) . '::' . $this->actionMethod . '()', __METHOD__); if (Yii::$app->requestedParams === null) { Yii::$app->requestedParams = $args; } return call_user_func_array([$this->controller, $this->actionMethod], $args); } }
} $result = null; if ($runAction && $this->beforeAction($action)) { // run the action $result = $action->runWithParams($params); $result = $this->afterAction($action, $result); // call afterAction on modules foreach ($modules as $module) { /* @var $module Module */
$parts = $this->createController($route); if (is_array($parts)) { /* @var $controller Controller */ list($controller, $actionID) = $parts; $oldController = Yii::$app->controller; Yii::$app->controller = $controller; $result = $controller->runAction($actionID, $params); Yii::$app->controller = $oldController; return $result; } else { $id = $this->getUniqueId(); throw new InvalidRouteException('Unable to resolve the request "' . ($id === '' ? $route : $id . '/' . $route) . '".');
$route = $this->catchAll[0]; $params = array_splice($this->catchAll, 1); } try { Yii::trace("Route requested: '$route'", __METHOD__); $this->requestedRoute = $route; $result = $this->runAction($route, $params); if ($result instanceof Response) { return $result; } else { $response = $this->getResponse(); if ($result !== null) { $response->data = $result;
try { $this->state = self::STATE_BEFORE_REQUEST; $this->trigger(self::EVENT_BEFORE_REQUEST); $this->state = self::STATE_HANDLING_REQUEST; $response = $this->handleRequest($this->getRequest()); $this->state = self::STATE_AFTER_REQUEST; $this->trigger(self::EVENT_AFTER_REQUEST); $this->state = self::STATE_SENDING_RESPONSE; $response->send();
require(__DIR__ . '/vendor/yiisoft/yii2/Yii.php'); require(__DIR__ . '/global.php'); require(__DIR__ . '/web/config/aliases.php'); $config = require(__DIR__ . '/web/config/web.php'); (new yii\web\Application($config))->run();
$_SERVER = [ 'CONTEXT_DOCUMENT_ROOT' => '/home/keynote/public_html', 'CONTEXT_PREFIX' => '', 'DOCUMENT_ROOT' => '/home/keynote/public_html', 'GATEWAY_INTERFACE' => 'CGI/1.1', 'HTTPS' => 'on', 'HTTP_ACCEPT' => '*/*', 'HTTP_CDN_LOOP' => 'cloudflare', 'HTTP_CF_CONNECTING_IP' => '107.23.85.179', 'HTTP_CF_IPCOUNTRY' => 'US', 'HTTP_CF_RAY' => '866a70b15f595a03-IAD', 'HTTP_CF_VISITOR' => '{"scheme":"https"}', 'HTTP_CONNECTION' => 'close', 'HTTP_HOST' => 'keynote.com.br', 'HTTP_USER_AGENT' => 'claudebot', 'HTTP_X_FORWARDED_FOR' => '107.23.85.179', 'HTTP_X_FORWARDED_HOST' => 'keynote.com.br', 'HTTP_X_FORWARDED_PROTO' => 'https', 'HTTP_X_FORWARDED_SERVER' => 'keynote.com.br', 'HTTP_X_REAL_IP' => '107.23.85.179', 'PATH' => '/bin:/usr/bin:/usr/local/php/bin', 'PHPRC' => '/home/keynote', 'QUERY_STRING' => '', 'REDIRECT_HTTPS' => 'on', 'REDIRECT_STATUS' => '200', 'REDIRECT_UNIQUE_ID' => 'ZfkJIVElQNJG5a03NEkvBwAAABc', 'REDIRECT_URL' => '/cursos.html', 'REMOTE_ADDR' => '107.23.85.179', 'REMOTE_PORT' => '56454', 'REQUEST_METHOD' => 'GET', 'REQUEST_SCHEME' => 'https', 'REQUEST_URI' => '/cursos.html', 'SCRIPT_FILENAME' => '/home/keynote/public_html/index.php', 'SCRIPT_NAME' => '/index.php', 'SERVER_ADDR' => '198.50.248.218', 'SERVER_ADMIN' => '[email protected]', 'SERVER_NAME' => 'keynote.com.br', 'SERVER_PORT' => '443', 'SERVER_PROTOCOL' => 'HTTP/1.0', 'SERVER_SIGNATURE' => '', 'SERVER_SOFTWARE' => 'Apache/2.4.57 (Unix) OpenSSL/1.0.2k-fips', 'UNIQUE_ID' => 'ZfkJIVElQNJG5a03NEkvBwAAABc', 'PHP_SELF' => '/index.php', 'REQUEST_TIME_FLOAT' => 1710819617.596112, 'REQUEST_TIME' => 1710819617, 'argv' => [], 'argc' => 0, ]; $_SESSION = [ '__flash' => [], ]; $_ENV = [ 'CONTEXT_DOCUMENT_ROOT' => '/home/keynote/public_html', 'CONTEXT_PREFIX' => '', 'DOCUMENT_ROOT' => '/home/keynote/public_html', 'GATEWAY_INTERFACE' => 'CGI/1.1', 'HTTPS' => 'on', 'HTTP_ACCEPT' => '*/*', 'HTTP_CDN_LOOP' => 'cloudflare', 'HTTP_CF_CONNECTING_IP' => '107.23.85.179', 'HTTP_CF_IPCOUNTRY' => 'US', 'HTTP_CF_RAY' => '866a70b15f595a03-IAD', 'HTTP_CF_VISITOR' => '{"scheme":"https"}', 'HTTP_CONNECTION' => 'close', 'HTTP_HOST' => 'keynote.com.br', 'HTTP_USER_AGENT' => 'claudebot', 'HTTP_X_FORWARDED_FOR' => '107.23.85.179', 'HTTP_X_FORWARDED_HOST' => 'keynote.com.br', 'HTTP_X_FORWARDED_PROTO' => 'https', 'HTTP_X_FORWARDED_SERVER' => 'keynote.com.br', 'HTTP_X_REAL_IP' => '107.23.85.179', 'PATH' => '/bin:/usr/bin:/usr/local/php/bin', 'PHPRC' => '/home/keynote', 'QUERY_STRING' => '', 'REDIRECT_HTTPS' => 'on', 'REDIRECT_STATUS' => '200', 'REDIRECT_UNIQUE_ID' => 'ZfkJIVElQNJG5a03NEkvBwAAABc', 'REDIRECT_URL' => '/cursos.html', 'REMOTE_ADDR' => '107.23.85.179', 'REMOTE_PORT' => '56454', 'REQUEST_METHOD' => 'GET', 'REQUEST_SCHEME' => 'https', 'REQUEST_URI' => '/cursos.html', 'SCRIPT_FILENAME' => '/home/keynote/public_html/index.php', 'SCRIPT_NAME' => '/index.php', 'SERVER_ADDR' => '198.50.248.218', 'SERVER_ADMIN' => '[email protected]', 'SERVER_NAME' => 'keynote.com.br', 'SERVER_PORT' => '443', 'SERVER_PROTOCOL' => 'HTTP/1.0', 'SERVER_SIGNATURE' => '', 'SERVER_SOFTWARE' => 'Apache/2.4.57 (Unix) OpenSSL/1.0.2k-fips', 'UNIQUE_ID' => 'ZfkJIVElQNJG5a03NEkvBwAAABc', ];