/**
  * Execute this task
  *
  * @param \TYPO3\Surf\Domain\Model\Node $node
  * @param \TYPO3\Surf\Domain\Model\Application $application
  * @param \TYPO3\Surf\Domain\Model\Deployment $deployment
  * @param array $options Supported options: "scriptBasePath" and "scriptIdentifier"
  * @return void
  * @throws \TYPO3\Surf\Exception\InvalidConfigurationException
  * @throws \TYPO3\Surf\Exception\TaskExecutionException
  */
 public function execute(Node $node, Application $application, Deployment $deployment, array $options = array())
 {
     $workspacePath = $deployment->getWorkspacePath($application);
     $scriptBasePath = isset($options['scriptBasePath']) ? $options['scriptBasePath'] : Files::concatenatePaths(array($workspacePath, 'Web'));
     if (!isset($options['scriptIdentifier'])) {
         // Generate random identifier
         $factory = new \RandomLib\Factory();
         $generator = $factory->getMediumStrengthGenerator();
         $scriptIdentifier = $generator->generateString(32, \RandomLib\Generator::CHAR_ALNUM);
         // Store the script identifier as an application option
         $application->setOption('TYPO3\\Surf\\Task\\Php\\WebOpcacheResetExecuteTask[scriptIdentifier]', $scriptIdentifier);
     } else {
         $scriptIdentifier = $options['scriptIdentifier'];
     }
     $localhost = new Node('localhost');
     $localhost->setHostname('localhost');
     $commands = array('cd ' . escapeshellarg($scriptBasePath), 'rm -f surf-opcache-reset-*');
     $this->shell->executeOrSimulate($commands, $localhost, $deployment);
     if (!$deployment->isDryRun()) {
         $scriptFilename = $scriptBasePath . '/surf-opcache-reset-' . $scriptIdentifier . '.php';
         $result = file_put_contents($scriptFilename, '<?php
             if (function_exists("opcache_reset")) {
                 opcache_reset();
             }
             @unlink(__FILE__);
             echo "success";
         ');
         if ($result === false) {
             throw new \TYPO3\Surf\Exception\TaskExecutionException('Could not write file "' . $scriptFilename . '"', 1421932414);
         }
     }
 }
Example #2
0
/**
 * Generates a random string
 *
 * @param int Size
 * @return string
 */
function noise($size = 32)
{
    $pool = 'abcefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
    $factory = new RandomLib\Factory();
    $generator = $factory->getMediumStrengthGenerator();
    return $generator->generateString($size, $pool);
}
Example #3
0
 public static function generate($usr_id)
 {
     $factory = new RandomLib\Factory();
     $generator = $factory->getMediumStrengthGenerator();
     $token = $generator->generateString(32, \RandomLib\Generator::CHAR_ALNUM);
     self::saveToken($usr_id, $token);
     return $token;
 }
Example #4
0
 /** Generate a CSRF token. */
 protected function _generateHash()
 {
     $factory = new \RandomLib\Factory();
     $generator = $factory->getMediumStrengthGenerator();
     $random1 = $generator->generateString(32);
     $random2 = $generator->generateString(32);
     $this->_hash = hash('sha256', $random1 . $this->getSalt() . $this->getName() . $random2);
     $this->setValue($this->_hash);
 }
Example #5
0
function generate_random_string($length, $alphabet = null)
{
    $factory = new RandomLib\Factory();
    $generator = $factory->getMediumStrengthGenerator();
    if (empty($alphabet)) {
        return $generator->generateString($length);
    } else {
        return $generator->generateString($length, $alphabet);
    }
}
 /**
  * Register the application services.
  *
  * @return void
  */
 public function register()
 {
     $this->mergeConfigFrom(__DIR__ . '/config/laravel-random.php', 'laravel-random');
     $this->app->singleton('random', function ($app) {
         $factory = new \RandomLib\Factory();
         $strength = $app['config']->get('laravel-random.strength');
         if ($strength === 'high') {
             return $factory->getHighStrengthGenerator();
         }
         if ($strength === 'medium') {
             return $factory->getMediumStrengthGenerator();
         }
         return $factory->getLowStrengthGenerator();
     });
 }
Example #7
0
<?php

session_start();
/*Préparation et connexion à la base de donnees*/
//include("config.php");
require_once "db.php";
include "vendor/autoload.php";
include "functions.php";
//create token
$factory = new RandomLib\Factory();
$generator = $factory->getMediumStrengthGenerator();
$token = $generator->generateString(80, '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-');
//date expiration du token
$expiry = date("Y-m-d H:i:s", strtotime("+ 1 day"));
if (!empty($_POST)) {
    $email = $_POST["email"];
    $sql = "SELECT email\n\t\t\t\tFROM users\n\t\t\t\tWHERE email = :email\n\t\t\t\tLIMIT 1";
    $sth = $dbh->prepare($sql);
    $sth->bindValue(":email", $email);
    $sth->execute();
    $forgottenPassword = $sth->fetch();
    //ptr($token);
    if ($_POST['email'] == $forgottenPassword['email']) {
        //send a mail
        //echo "Whaouh !";
        include "send_mail_forgotten_password.php";
        $sql = "UPDATE users\n\t\t\t\t\t\tSET token = '{$token}'\n\t\t\t\t\t\tWHERE email = '{$email}'";
        $sth = $dbh->prepare($sql);
        $sth->bindValue(":email", $email);
        $sth->execute();
    }
Example #8
0
});
$app->container->singleton('mail', function () use($app) {
    $mailer = new PHPMailer();
    $mailer->isSMTP();
    $mailer->Host = $app->config->get('mail.host');
    $mailer->SMTPAuth = $app->config->get('mail.smtp_auth');
    $mailer->SMTPSecure = $app->config->get('mail.smtp_secure');
    $mailer->Port = $app->config->get('mail.port');
    $mailer->Username = $app->config->get('mail.username');
    $mailer->Password = $app->config->get('mail.password');
    $mailer->isHTML($app->config->get('mail.html'));
    return $mailer;
});
$app->container->singleton('randomlib', function () {
    $factory = new RandomLib\Factory();
    return $factory->getMediumStrengthGenerator();
});
$app->container->singleton('hash', function () use($app) {
    return new Hash($app->config);
});
$app->container->singleton('slug', function () {
    return new Slugify();
});
$app->container->singleton('validation', function () use($app) {
    return new Validator(new User(), $app->hash, $app->auth);
});
$app->container->singleton('log', function () {
    $log = new Logger('log');
    $log->pushHandler(new StreamHandler(ROOT_PATH . '/app/logs/app.log', Logger::DEBUG));
    return $log;
});
Example #9
0
 /**
  * Generate the token value
  *
  * @return string Token hash
  */
 public function generateToken()
 {
     $factory = new \RandomLib\Factory();
     $generator = $factory->getMediumStrengthGenerator();
     return base64_encode($generator->generate(24));
 }
Example #10
0
 /**
  * Generate a random byte string of the requested size.
  *
  * Uses Medium Strength Generator
  *
  * @link https://github.com/ircmaxell/RandomLib#factory-getlowstrengthgenerator
  *
  * @param int $size
  * @return string
  */
 public static function generateRandom($size = 32)
 {
     $factory = new RandomLib\Factory();
     $generator = $factory->getMediumStrengthGenerator();
     return $generator->generate($size);
 }
Example #11
0
 /**
  * Generate a secure, random, 32-character nonce for use in the 'jti' claim
  *
  * @return string
  */
 private function generateNonce()
 {
     $factory = new \RandomLib\Factory();
     $generator = $factory->getMediumStrengthGenerator();
     $string = $generator->generateString(32, '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ');
     return $string;
 }
Example #12
0
 /**
  * Get a random string
  *
  * @param integer $length of the random string
  * @param boolean $high strength of the random source (since 9.2)
  *
  * @return random string
  **/
 static function getRandomString($length, $high = false)
 {
     $factory = new RandomLib\Factory();
     if ($high) {
         /* Notice "High" imply mcrypt extension, unwanted for now
            See https://github.com/ircmaxell/RandomLib/issues/57 */
         $generator = $factory->getMediumStrengthGenerator();
     } else {
         $generator = $factory->getLowStrengthGenerator();
     }
     return $generator->generateString($length, RandomLib\Generator::CHAR_LOWER + RandomLib\Generator::CHAR_DIGITS);
 }