Example #1
0
session_name("_%%APP_NAME%%_session");
session_set_cookie_params($lifetime = 0, $path = "/");
/* activate encrypted cookie storage; requires the mcrypt php extension */
HalfMoon\Config::set_session_store("encrypted_cookie", array("encryption_key" => "%%COOKIE_ENCRYPTION_KEY%%"));
/* a timezone is required for DateTime functions */
date_default_timezone_set("UTC");
/* environment-specific settings */
if (HALFMOON_ENV == "development") {
    /* be open and verbose during development */
    /* show errors in the browser */
    ini_set("display_errors", 1);
    /* log all activerecord queries and values */
    HalfMoon\Config::set_activerecord_log_level("full");
    /* log all halfmoon activity */
    HalfMoon\Config::set_log_level("full");
} elseif (HALFMOON_ENV == "production") {
    /* be quiet in production */
    /* don't display actual php error messages to the user, just generic error
     * pages (see skel/500.html) */
    ini_set("display_errors", 0);
    /* do not log any activerecord queries */
    HalfMoon\Config::set_activerecord_log_level("none");
    /* only log halfmoon processing times with urls */
    HalfMoon\Config::set_log_level("short");
    /* perform file caching for controllers that request it, and store files in
     * this directory (must be writable by web server user running halfmoon */
    HalfMoon\Config::set_cache_store_path(HALFMOON_ROOT . "/public/cache");
    /* uncomment to send emails of error backtraces and debugging info */
    # HalfMoon\Config::set_exception_notification_recipient("*****@*****.**");
    # HalfMoon\Config::set_exception_notification_subject("[%%APP_NAME%%]");
}
Example #2
0
<?php

require __DIR__ . "/../lib/halfmoon.php";
HalfMoon\Config::set_session_store("encrypted_cookie", array("encryption_key" => str_repeat("0", 32)));
class EncryptedCookieTest extends PHPUnit_Framework_TestCase
{
    static $str = "australia's darrell lea soft eating liquorice";
    static $key = "3d737148b5d7c1a08e0e92d26f8d020b";
    static $cookie = "test";
    public function setupSS($key, $cookie)
    {
        $this->ss = new HalfMoon\EncryptedCookieSessionStore($key);
        $this->ss->open("", $cookie);
    }
    public function testCookieEncryptionAndDecryption()
    {
        for ($z = 0; $z < 5000; $z++) {
            $key = bin2hex(openssl_random_pseudo_bytes(16));
            $this->setupSS($key, "test_" . $z);
            $ki = rand(20, 40);
            for ($k = "", $x = 0; $x++ < $ki; $k .= bin2hex(chr(mt_rand(0, 255)))) {
            }
            $vi = rand(20, 500);
            for ($v = "", $x = 0; $x++ < $vi; $v .= bin2hex(chr(mt_rand(0, 255)))) {
            }
            $data = var_export(array($k, $v), true);
            $this->ss->write("", $data);
            $this->setupSS($key, "test_" . $z);
            $dec_data = $this->ss->read("");
            $this->assertEquals($data, $dec_data);
        }
Example #3
0
    require_once HALFMOON_ROOT . "/config/boot.php";
}
/* autoload controllers and helpers as needed */
function halfmoon_autoload($class_name)
{
    if (preg_match("/^([A-Za-z0-9_]+)(Controller|Helper)\$/", $class_name, $m)) {
        $file = HALFMOON_ROOT . "/";
        /* Controller -> controllers/ */
        $file .= strtolower($m[2]) . "s/";
        /* CamelCase -> camel_case_controller.php */
        $words = preg_split('/(?<=\\w)(?=[A-Z])/', $m[1]);
        $file .= strtolower(join("_", $words)) . "_" . strtolower($m[2]) . ".php";
        if (file_exists($file)) {
            require_once $file;
        }
    }
}
spl_autoload_register("halfmoon_autoload", false, false);
if (defined("PHP_ACTIVERECORD_ROOT")) {
    HalfMoon\Config::initialize_activerecord();
}
/* bring in any post-framework but pre-route code */
if (file_exists($f = HALFMOON_ROOT . "/config/application.php")) {
    require_once $f;
}
/* bring in the route table and route our request */
if (file_exists(HALFMOON_ROOT . "/config/routes.php")) {
    HalfMoon\Router::initialize(function ($router) {
        require_once HALFMOON_ROOT . "/config/routes.php";
    });
}