<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>P0L0&#039;s Blog</title>
	<atom:link href="http://p0l0.binware.org/index.php/feed/" rel="self" type="application/rss+xml" />
	<link>http://p0l0.binware.org</link>
	<description>Opensource Projects and IT experiences</description>
	<lastBuildDate>Mon, 12 Mar 2012 08:01:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Zend Framework 2: Authentication + Acl using EventManager</title>
		<link>http://p0l0.binware.org/index.php/2012/02/18/zend-framework-2-authentication-acl-using-eventmanager/</link>
		<comments>http://p0l0.binware.org/index.php/2012/02/18/zend-framework-2-authentication-acl-using-eventmanager/#comments</comments>
		<pubDate>Sat, 18 Feb 2012 12:44:14 +0000</pubDate>
		<dc:creator>P0L0</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Zend EventManager]]></category>
		<category><![CDATA[zend framework]]></category>
		<category><![CDATA[Zend_Acl]]></category>
		<category><![CDATA[Zend_Authentication]]></category>
		<category><![CDATA[ZF2]]></category>

		<guid isPermaLink="false">http://p0l0.binware.org/?p=1844</guid>
		<description><![CDATA[This is a first try to implement Zend Authentication with Zend Acl under ZF2. I used the EventManager to catch the MVC preDispatch Event so that I can evaluate if the user has or not permission for the requested page. First I created an extra config for ACL (could be also in module.config.php, but I [...]]]></description>
			<content:encoded><![CDATA[<p>This is a first try to implement Zend Authentication with Zend Acl under ZF2. I used the EventManager to catch the MVC preDispatch Event so that I can evaluate if the user has or not permission for the requested page.</p>
<p><div style="margin-left: -20px; margin-top: 20px; margin-bottom: 20px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-5682258244719056";
/* Inline Post */
google_ad_slot = "6946080416";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><br />
<span id="more-1844"></span></p>
<p>First I created an extra config for ACL (could be also in <em>module.config.php</em>, but I prefer to have it in a separated file)</p>
<ul>
<li><strong>config/acl.config.php</strong></li>
</ul>
<pre class="brush: php; title: ; notranslate">
&lt;?php
return array(
    'acl' =&gt; array(
        'roles' =&gt; array(
            'guest'   =&gt; null,
            'member'  =&gt; 'guest'
        ),
        'resources' =&gt; array(
            'allow' =&gt; array(
                'user' =&gt; array(
                    'login' =&gt; 'guest',
                    'all'   =&gt; 'member'
                )
            )
        )
    )
);
</pre>
<p>Next step is to create the Acl Class where we manage the roles and resources which we have defined in the config</p>
<ul>
<li><strong>src/User/Acl/Acl.php</strong></li>
</ul>
<pre class="brush: php; title: ; notranslate">
&lt;?php
/**
 * File for Acl Class
 *
 * @category  User
 * @package   User_Acl
 * @author    Marco Neumann &lt;webcoder_at_binware_dot_org&gt;
 * @copyright Copyright (c) 2011, Marco Neumann
 * @license   http://binware.org/license/index/type:new-bsd New BSD License
 */

/**
 * @namespace
 */
namespace User\Acl;

/**
 * @uses Zend\Acl\Acl
 * @uses Zend\Acl\Role\GenericRole
 * @uses Zend\Acl\Resource\GenericResource
 */
use Zend\Acl\Acl as ZendAcl,
    Zend\Acl\Role\GenericRole as Role,
    Zend\Acl\Resource\GenericResource as Resource;

/**
 * Class to handle Acl
 *
 * This class is for loading ACL defined in a config
 *
 * @category User
 * @package  User_Acl
 * @copyright Copyright (c) 2011, Marco Neumann
 * @license   http://binware.org/license/index/type:new-bsd New BSD License
 */
class Acl extends ZendAcl {
    /**
     * Default Role
     */
    const DEFAULT_ROLE = 'guest';

    /**
     * Constructor
     *
     * @param array $config
     * @return void
     * @throws \Exception
     */
    public function __construct($config)
    {
        if (!isset($config['acl']['roles']) || !isset($config['acl']['resources'])) {
            throw new \Exception('Invalid ACL Config found');
        }

        $roles = $config['acl']['roles'];
        if (!isset($roles[self::DEFAULT_ROLE])) {
            $roles[self::DEFAULT_ROLE] = '';
        }

        $this-&gt;_addRoles($roles)
             -&gt;_addResources($config['acl']['resources']);
    }

    /**
     * Adds Roles to ACL
     *
     * @param array $roles
     * @return User\Acl
     */
    protected function _addRoles($roles)
    {
        foreach ($roles as $name =&gt; $parent) {
            if (!$this-&gt;hasRole($name)) {
                if (empty($parent)) {
                    $parent = array();
                } else {
                    $parent = explode(',', $parent);
                }

                $this-&gt;addRole(new Role($name), $parent);
            }
        }

        return $this;
    }

    /**
     * Adds Resources to ACL
     *
     * @param $resources
     * @return User\Acl
     * @throws \Exception
     */
    protected function _addResources($resources)
    {
        foreach ($resources as $permission =&gt; $controllers) {
            foreach ($controllers as $controller =&gt; $actions) {
                if ($controller == 'all') {
                    $controller = null;
                } else {
                    if (!$this-&gt;hasResource($controller)) {
                        $this-&gt;addResource(new Resource($controller));
                    }
                }

                foreach ($actions as $action =&gt; $role) {
                    if ($action == 'all') {
                        $action = null;
                    }

                    if ($permission == 'allow') {
                        $this-&gt;allow($role, $controller, $action);
                    } elseif ($permission == 'deny') {
                        $this-&gt;deny($role, $controller, $action);
                    } else {
                        throw new \Exception('No valid permission defined: ' . $permission);
                    }
                }
            }
        }

        return $this;
    }
}
</pre>
<p>I decided to use a Controller Plugin (zf1 ActionHelpers) for the Authentication interaction</p>
<ul>
<li><strong>src/User/Controller/Plugin/UserAuthentication.php</strong></li>
</ul>
<pre class="brush: php; title: ; notranslate">
&lt;?php
/**
 * File for UserAuthentication Class
 *
 * @category   User
 * @package    User_Controller
 * @subpackage User_Controller_Plugin
 * @author     Marco Neumann &lt;webcoder_at_binware_dot_org&gt;
 * @copyright  Copyright (c) 2011, Marco Neumann
 * @license    http://binware.org/license/index/type:new-bsd New BSD License
 */

/**
 * @namespace
 */
namespace User\Controller\Plugin;

/**
 * @uses Zend\Mvc\Controller\Plugin\AbstractPlugin
 * @uses Zend\Authentication\AuthenticationService
 * @uses Zend\Authentication\Adapter\DbTable
 */
use Zend\Mvc\Controller\Plugin\AbstractPlugin,
    Zend\Authentication\AuthenticationService,
    Zend\Authentication\Adapter\DbTable as AuthAdapter;

/**
 * Class for User Authentication
 *
 * Handles Auth Adapter and Auth Service to check Identity
 *
 * @category   User
 * @package    User_Controller
 * @subpackage User_Controller_Plugin
 * @copyright  Copyright (c) 2011, Marco Neumann
 * @license    http://binware.org/license/index/type:new-bsd New BSD License
 */
class UserAuthentication extends AbstractPlugin
{
    /**
     * @var AuthAdapter
     */
    protected $_authAdapter = null;

    /**
     * @var AuthenticationService
     */
    protected $_authService = null;

    /**
     * Check if Identity is present
     *
     * @return bool
     */
    public function hasIdentity()
    {
        return $this-&gt;getAuthService()-&gt;hasIdentity();
    }

    /**
     * Return current Identity
     *
     * @return mixed|null
     */
    public function getIdentity()
    {
        return $this-&gt;getAuthService()-&gt;getIdentity();
    }

    /**
     * Sets Auth Adapter
     *
     * @param \Zend\Authentication\Adapter\DbTable $authAdapter
     * @return UserAuthentication
     */
    public function setAuthAdapter(AuthAdapter $authAdapter)
    {
        $this-&gt;_authAdapter = $authAdapter;

        return $this;
    }

    /**
     * Returns Auth Adapter
     *
     * @return \Zend\Authentication\Adapter\DbTable
     */
    public function getAuthAdapter()
    {
        if ($this-&gt;_authAdapter === null) {
            $this-&gt;setAuthAdapter(new AuthAdapter());
        }

        return $this-&gt;_authAdapter;
    }

    /**
     * Sets Auth Service
     *
     * @param \Zend\Authentication\AuthenticationService $authService
     * @return UserAuthentication
     */
    public function setAuthService(AuthenticationService $authService)
    {
        $this-&gt;_authService = $authService;

        return $this;
    }

    /**
     * Gets Auth Service
     *
     * @return \Zend\Authentication\AuthenticationService
     */
    public function getAuthService()
    {
        if ($this-&gt;_authService === null) {
            $this-&gt;setAuthService(new AuthenticationService());
        }

        return $this-&gt;_authService;
    }

}
</pre>
<p>Now we can create the Event Handler were we will implement the AuthenticationPlugin (at this point, I think that using a Controller Plugin is not the right way to do it, but for now I will leave it so until I have a better solution&#8230;) and the Acl</p>
<ul>
<li><strong>src/Event/Authentication.php</strong></li>
</ul>
<pre class="brush: php; title: ; notranslate">
&lt;?php
/**
 * File for Event Class
 *
 * @category  User
 * @package   User_Event
 * @author    Marco Neumann &lt;webcoder_at_binware_dot_org&gt;
 * @copyright Copyright (c) 2011, Marco Neumann
 * @license   http://binware.org/license/index/type:new-bsd New BSD License
 */

/**
 * @namespace
 */
namespace User\Event;

/**
 * @uses Zend\Mvc\MvcEvent
 * @uses User\Controller\Plugin\UserAuthentication
 * @uses User\Acl\Acl
 */
use Zend\Mvc\MvcEvent as MvcEvent,
    User\Controller\Plugin\UserAuthentication as AuthPlugin,
    User\Acl\Acl as AclClass;

/**
 * Authentication Event Handler Class
 *
 * This Event Handles Authentication
 *
 * @category  User
 * @package   User_Event
 * @copyright Copyright (c) 2011, Marco Neumann
 * @license   http://binware.org/license/index/type:new-bsd New BSD License
 */
class Authentication
{
    /**
     * @var AuthPlugin
     */
    protected $_userAuth = null;

    /**
     * @var AclClass
     */
    protected $_aclClass = null;

    /**
     * preDispatch Event Handler
     *
     * @param \Zend\Mvc\MvcEvent $event
     * @throws \Exception
     */
    public function preDispatch(MvcEvent $event)
    {
        //@todo - Should we really use here and Controller Plugin?
        $userAuth = $this-&gt;getUserAuthenticationPlugin();
        $acl = $this-&gt;getAclClass();
        $role = AclClass::DEFAULT_ROLE;

        if ($userAuth-&gt;hasIdentity()) {
            $user = $userAuth-&gt;getIdentity();
            $role = 'member'; //@todo - Get role from user!
        }

        $routeMatch = $event-&gt;getRouteMatch();
        $controller = $routeMatch-&gt;getParam('controller');
        $action     = $routeMatch-&gt;getParam('action');

        if (!$acl-&gt;hasResource($controller)) {
            throw new \Exception('Resource ' . $controller . ' not defined');
        }

        if (!$acl-&gt;isAllowed($role, $controller, $action)) {
            $url = $event-&gt;getRouter()-&gt;assemble(array(), array('name' =&gt; 'login'));
            $response = $event-&gt;getResponse();
            $response-&gt;headers()-&gt;addHeaderLine('Location', $url);
            $response-&gt;setStatusCode(302);
            $response-&gt;sendHeaders();
            exit;
        }
    }

    /**
     * Sets Authentication Plugin
     *
     * @param \User\Controller\Plugin\UserAuthentication $userAuthenticationPlugin
     * @return Authentication
     */
    public function setUserAuthenticationPlugin(AuthPlugin $userAuthenticationPlugin)
    {
        $this-&gt;_userAuth = $userAuthenticationPlugin;

        return $this;
    }

    /**
     * Gets Authentication Plugin
     *
     * @return \User\Controller\Plugin\UserAuthentication
     */
    public function getUserAuthenticationPlugin()
    {
        if ($this-&gt;_userAuth === null) {
            $this-&gt;_userAuth = new AuthPlugin();
        }

        return $this-&gt;_userAuth;
    }

    /**
     * Sets ACL Class
     *
     * @param \User\Acl\Acl $aclClass
     * @return Authentication
     */
    public function setAclClass(AclClass $aclClass)
    {
        $this-&gt;_aclClass = $aclClass;

        return $this;
    }

    /**
     * Gets ACL Class
     *
     * @return \User\Acl\Acl
     */
    public function getAclClass()
    {
        if ($this-&gt;_aclClass === null) {
            $this-&gt;_aclClass = new AclClass(array());
        }

        return $this-&gt;_aclClass;
    }
}
</pre>
<p>Now we need to attach the Event Handler to the EventManager, this will be done in the Module Class (haven&#8217;t found a better way to do it). I also had to attach an own function and from there trigger the User\Event\Authentication function (not very elegant ;( )</p>
<ul>
<li><strong>Module.php</strong></li>
</ul>
<pre class="brush: php; title: ; notranslate">
&lt;?php
/**
 * File for Module Class
 *
 * @category  User
 * @package   User
 * @author    Marco Neumann &lt;webcoder_at_binware_dot_org&gt;
 * @copyright Copyright (c) 2011, Marco Neumann
 * @license   http://binware.org/license/index/type:new-bsd New BSD License
 */

/**
 * @namespace
 */
namespace User;

/**
 * @uses Zend\Module\Consumer\AutoloaderProvider
 * @uses Zend\EventManager\StaticEventManager
 */
use Zend\Module\Consumer\AutoloaderProvider,
    Zend\EventManager\StaticEventManager;

/**
 * Module Class
 *
 * Handles Module Initialization
 *
 * @category  User
 * @package   User
 * @copyright Copyright (c) 2011, Marco Neumann
 * @license   http://binware.org/license/index/type:new-bsd New BSD License
 */
class Module implements AutoloaderProvider
{
    /**
     * Init function
     *
     * @return void
     */
    public function init()
    {
        // Attach Event to EventManager
        $events = StaticEventManager::getInstance();
        $events-&gt;attach('Zend\Mvc\Controller\ActionController', 'dispatch', array($this, 'mvcPreDispatch'), 100); //@todo - Go directly to User\Event\Authentication
    }

    /**
     * Get Autoloader Configuration
     *
     * @return array
     */
    public function getAutoloaderConfig()
    {
        return array(
            'Zend\Loader\ClassMapAutoloader' =&gt; array(
                __DIR__ . '/autoload_classmap.php'
            ),
            'Zend\Loader\StandardAutoloader' =&gt; array(
                'namespaces' =&gt; array(
                    __NAMESPACE__ =&gt; __DIR__ . '/src/' . __NAMESPACE__
                )
            )
        );
    }

    /**
     * Get Module Configuration
     *
     * @return array
     */
    public function getConfig()
    {
        return include __DIR__ . '/config/module.config.php';
    }

    /**
     * MVC preDispatch Event
     *
     * @param $event
     * @return mixed
     */
    public function mvcPreDispatch($event) {
        $di = $event-&gt;getTarget()-&gt;getLocator();
        $auth = $di-&gt;get('User\Event\Authentication');

        return $auth-&gt;preDispatch($event);
    }
}
</pre>
<p>Here is the config where we attach all needed classes and load <em>acl.config.php</em></p>
<ul>
<li><strong>config/module.config.php</strong></li>
</ul>
<pre class="brush: php; title: ; notranslate">
&lt;?php
return array(
    'di' =&gt; array(
        'instance' =&gt; array(
            'alias' =&gt; array(
                'user' =&gt; 'User\Controller\UserController'
            ),
            'user' =&gt; array(
                'parameters' =&gt; array(
                    'broker' =&gt; 'Zend\Mvc\Controller\PluginBroker'
                )
            ),
            'User\Event\Authentication' =&gt; array(
                'parameters' =&gt; array(
                    'userAuthenticationPlugin' =&gt; 'User\Controller\Plugin\UserAuthentication',
                    'aclClass'                 =&gt; 'User\Acl\Acl'
                )
            ),
            'User\Acl\Acl' =&gt; array(
                'parameters' =&gt; array(
                    'config' =&gt; include __DIR__ . '/acl.config.php'
                )
            ),
            'User\Controller\Plugin\UserAuthentication' =&gt; array(
                'parameters' =&gt; array(
                    'authAdapter' =&gt; 'Zend\Authentication\Adapter\DbTable'
                )
            ),
            'Zend\Authentication\Adapter\DbTable' =&gt; array(
                'parameters' =&gt; array(
                    'zendDb' =&gt; 'Zend\Db\Adapter\Mysqli',
                    'tableName' =&gt; 'users',
                    'identityColumn' =&gt; 'email',
                    'credentialColumn' =&gt; 'password',
                    'credentialTreatment' =&gt; 'SHA1(CONCAT(?, &quot;secretKey&quot;))'
                )
            ),
            'Zend\Db\Adapter\Mysqli' =&gt; array(
                'parameters' =&gt; array(
                    'config' =&gt; array(
                        'host' =&gt; 'localhost',
                        'username' =&gt; 'username',
                        'password' =&gt; 'password',
                        'dbname' =&gt; 'dbname',
                        'charset' =&gt; 'utf-8'
                    )
                )
            ),
            'Zend\Mvc\Controller\PluginLoader' =&gt; array(
                'parameters' =&gt; array(
                    'map' =&gt; array(
                        'userAuthentication' =&gt; 'User\Controller\Plugin\UserAuthentication'
                    )
                )
            ),
            'Zend\View\PhpRenderer' =&gt; array(
                'parameters' =&gt; array(
                    'options' =&gt; array(
                        'script_paths' =&gt; array(
                            'user' =&gt; __DIR__ . '/../views'
                        )
                    )
                )
            )
        )
    ),
    'routes' =&gt; array(
        'login' =&gt; array(
            'type' =&gt; 'Zend\Mvc\Router\Http\Literal',
            'options' =&gt; array(
                'route'    =&gt; '/login',
                'defaults' =&gt; array(
                    'controller' =&gt; 'user',
                    'action'     =&gt; 'login',
                )
            )
        )
    )
);
</pre>
<p>Well, we are now done, we only need to create the Login Form and the Controller</p>
<ul>
<li><strong>src/Form/Login.php</strong></li>
</ul>
<pre class="brush: php; title: ; notranslate">
&lt;?php
/**
 * File for Login Form Class
 *
 * @category  User
 * @package   User_Form
 * @author    Marco Neumann &lt;webcoder_at_binware_dot_org&gt;
 * @copyright Copyright (c) 2011, Marco Neumann
 * @license   http://binware.org/license/index/type:new-bsd New BSD License
 */

/**
 * @namespace
 */
namespace User\Form;

/**
 * @uses Zend\Form\Form
 */
use Zend\Form\Form;

/**
 * Login Form Class
 *
 * Login Form
 *
 * @category  User
 * @package   User_Form
 * @copyright Copyright (c) 2011, Marco Neumann
 * @license   http://binware.org/license/index/type:new-bsd New BSD License
 */
class Login extends Form
{
    /**
     * Initialize Form
     */
    public function init()
    {
        $this-&gt;setMethod('post')
             -&gt;loadDefaultDecorators()
             -&gt;addDecorator('FormErrors');

        $this-&gt;addElement(
            'text',
            'username',
            array(
                 'filters' =&gt; array(
                     array('StringTrim')
                 ),
                 'validators' =&gt; array(
                     'EmailAddress'
                 ),
                 'required' =&gt; true,
                 'label'    =&gt; 'Email'
            )
        );

        $this-&gt;addElement(
            'password',
            'password',
            array(
                 'filters' =&gt; array(
                     array('StringTrim')
                 ),
                 'validators' =&gt; array(
                     array(
                         'StringLength',
                         true,
                         array(
                             6,
                             999
                         )
                     )
                 ),
                 'required' =&gt; true,
                 'label'    =&gt; 'Password'
            )
        );

        $this-&gt;addElement(
            'hash',
            'csrf',
            array(
                 'ignore' =&gt; true,
                 'decorators' =&gt; array('ViewHelper')
            )
        );

        $this-&gt;addElement(
            'submit',
            'login',
            array(
                 'ignore' =&gt; true,
                 'label' =&gt; 'Login'
            )
        );

    }
}
</pre>
<ul>
<li><strong>src/User/Controller/UserController.php</strong></li>
</ul>
<pre class="brush: php; title: ; notranslate">
&lt;?php
/**
 * File for User Controller Class
 *
 * @category  User
 * @package   User_Controller
 * @author    Marco Neumann &lt;webcoder_at_binware_dot_org&gt;
 * @copyright Copyright (c) 2011, Marco Neumann
 * @license   http://binware.org/license/index/type:new-bsd New BSD License
 */

/**
 * @namespace
 */
namespace User\Controller;

/**
 * @uses Zend\Mvc\Controller\ActionController
 * @uses User\Form\Login
 */
use Zend\Mvc\Controller\ActionController,
    User\Form\Login as LoginForm;

/**
 * User Controller Class
 *
 * User Controller
 *
 * @category  User
 * @package   User_Controller
 * @copyright Copyright (c) 2011, Marco Neumann
 * @license   http://binware.org/license/index/type:new-bsd New BSD License
 */
class UserController extends ActionController
{
    /**
     * Index Action
     */
    public function indexAction()
    {
        //@todo - Implement indexAction
    }

    /**
     * Login Action
     *
     * @return array
     */
    public function loginAction()
    {
        $form = new LoginForm();
        $request = $this-&gt;getRequest();

        if ($request-&gt;isPost() &amp;&amp; $form-&gt;isValid($request-&gt;post()-&gt;toArray())) {
            $uAuth = $this-&gt;getLocator()-&gt;get('User\Controller\Plugin\UserAuthentication'); //@todo - We must use PluginLoader $this-&gt;userAuthentication()!!
            $authAdapter = $uAuth-&gt;getAuthAdapter();

            $authAdapter-&gt;setIdentity($form-&gt;getValue('username'));
            $authAdapter-&gt;setCredential($form-&gt;getValue('password'));

            \Zend\Debug::dump($uAuth-&gt;getAuthService()-&gt;authenticate($authAdapter));
        }

        return array('loginForm' =&gt; $form);
    }

    /**
     * Logout Action
     */
    public function logoutAction()
    {
        $this-&gt;getLocator()-&gt;get('User\Controller\Plugin\UserAuthentication')-&gt;clearIdentity(); //@todo - We must use PluginLoader $this-&gt;userAuthentication()!!
    }
}
</pre>
<p><div style="margin-left: -20px; margin-top: 20px; margin-bottom: 20px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-5682258244719056";
/* Inline Post */
google_ad_slot = "6946080416";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div></p>
<p>I know this is not perfect, but this implementation works. For an initial implementation I think it&#8217;s ok.</p>
]]></content:encoded>
			<wfw:commentRss>http://p0l0.binware.org/index.php/2012/02/18/zend-framework-2-authentication-acl-using-eventmanager/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Git Over HTTP (git-http-backend)</title>
		<link>http://p0l0.binware.org/index.php/2011/08/26/git-over-http-git-http-backend/</link>
		<comments>http://p0l0.binware.org/index.php/2011/08/26/git-over-http-git-http-backend/#comments</comments>
		<pubDate>Fri, 26 Aug 2011 19:03:37 +0000</pubDate>
		<dc:creator>P0L0</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[GNU/Linux]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[dvcs]]></category>
		<category><![CDATA[git]]></category>

		<guid isPermaLink="false">http://p0l0.binware.org/?p=1036</guid>
		<description><![CDATA[I found really annoying that all Git guides I found talked about using Git over SSH, thats because I googled until I found that Git now comes with git-http-backend, which lets you to configure your webserver to serve git over HTTP/HTTPS. Here is a little guide how to setup git-http-backend using apache. First of all [...]]]></description>
			<content:encoded><![CDATA[<p>I found really annoying that all Git guides I found talked about using Git over SSH, thats because I googled until I found that Git now comes with <a href="http://www.kernel.org/pub/software/scm/git/docs/git-http-backend.html" title="git-http-backend(1)" target="_blank">git-http-backend</a>, which lets you to configure your webserver to serve git over HTTP/HTTPS.</p>
<p><div style="margin-left: -20px; margin-top: 20px; margin-bottom: 20px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-5682258244719056";
/* Inline Post */
google_ad_slot = "6946080416";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><br />
<span id="more-1036"></span><br />
Here is a little guide how to setup git-http-backend using apache. First of all we need to install git on our server:</p>
<pre class="brush: bash; title: ; notranslate">
apt-get install git-core
</pre>
<p>Once git is installed we will found git-http-backend under <em>/usr/lib/git-core/git-http-backend</em>. Next step is to setup the Apache configuration:</p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;">&lt;<span style="color: #000000; font-weight:bold;">IfModule</span> mod_ssl.c&gt;
&lt;<span style="color: #000000; font-weight:bold;">VirtualHost</span> *:<span style="color: #ff0000;">443</span>&gt;
    <span style="color: #00007f;">SSLEngine</span> <span style="color: #0000ff;">on</span>
&nbsp;
    <span style="color: #00007f;">SSLCertificateFile</span> /etc/ssl/server.crt
    <span style="color: #00007f;">SSLCertificateKeyFile</span> /etc/ssl/server.key
    <span style="color: #00007f;">SetEnvIf</span> User-Agent <span style="color: #7f007f;">&quot;.*MSIE.*&quot;</span> <span style="color: #0000ff;">nokeepalive</span> ssl-unclean-shutdown
&nbsp;
    <span style="color: #00007f;">ServerName</span> git.example.com
    <span style="color: #00007f;">ErrorLog</span> /var/log/apache2/git-error.log
    <span style="color: #00007f;">CustomLog</span> /var/log/apache2/git-access.log combined
&nbsp;
    <span style="color: #adadad; font-style: italic;"># GIT Config</span>
    <span style="color: #00007f;">SetEnv</span> GIT_PROJECT_ROOT /opt/git/repositories
    <span style="color: #00007f;">SetEnv</span> GIT_HTTP_EXPORT_ALL
&nbsp;
    <span style="color: #adadad; font-style: italic;"># Route Git-Http-Backend</span>
    <span style="color: #00007f;">ScriptAlias</span> / /usr/lib/git-core/git-http-backend/
&nbsp;
    <span style="color: #adadad; font-style: italic;"># Require Acces for all resources</span>
    &lt;<span style="color: #000000; font-weight:bold;">Location</span> /&gt;
        <span style="color: #00007f;">AuthType</span> Basic
        <span style="color: #00007f;">AuthName</span> <span style="color: #7f007f;">&quot;Private&quot;</span>
        <span style="color: #00007f;">Require</span> valid-<span style="color: #00007f;">user</span>
        <span style="color: #00007f;">AuthUserFile</span> /opt/git/<span style="color: #00007f;">user</span>.passwd
    &lt;/<span style="color: #000000; font-weight:bold;">Location</span>&gt;
&lt;/<span style="color: #000000; font-weight:bold;">VirtualHost</span>&gt;
&lt;/<span style="color: #000000; font-weight:bold;">IfModule</span>&gt;</pre></div></div>

<p>Now we only need to create our repositories under <em>/opt/git/repositories</em> (The repositories must be owned by the apache user to work):</p>
<pre class="brush: bash; title: ; notranslate">
cd /opt/git/repositories
git --bare init test.git
chown -R www-data:www-data /opt/git/repositories
</pre>
<p>And thats all, now we can checkout the repository using the url <em>https://git.example.com/test.git</em>:</p>
<pre class="brush: bash; title: ; notranslate">
git clone https://username@git.example.com/test.git
cd test
mkdir testdir
touch testdir/README
git add .
git commit -m 'test commit'
git push origin master
</pre>
<p><div style="margin-left: -20px; margin-top: 20px; margin-bottom: 20px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-5682258244719056";
/* Inline Post */
google_ad_slot = "6946080416";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div></p>
<p>This environment variable is useful for testing and debug the request to your repository:</p>
<pre class="brush: bash; title: ; notranslate">
# Activates verbosity for HTTP Requests
export GIT_CURL_VERBOSE=1
</pre>
<p>If you have a Self-Signed Certificate and you haven&#8217;t imported your Root CA to your computer (which is the better option), you will get an SSL error. To avoid this you can use following Environment variable (CAUTION: With this you will not detect Man-In-The-Middle Attacks!)</p>
<pre class="brush: bash; title: ; notranslate">
# Do not verify Certificate
export GIT_SSL_NO_VERIFY=true
</pre>
]]></content:encoded>
			<wfw:commentRss>http://p0l0.binware.org/index.php/2011/08/26/git-over-http-git-http-backend/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>SimpleXML vs XMLWriter vs DOM</title>
		<link>http://p0l0.binware.org/index.php/2011/07/04/simplexml-vs-xmlwriter-vs-dom/</link>
		<comments>http://p0l0.binware.org/index.php/2011/07/04/simplexml-vs-xmlwriter-vs-dom/#comments</comments>
		<pubDate>Mon, 04 Jul 2011 20:52:04 +0000</pubDate>
		<dc:creator>P0L0</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[dom]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[simplexml]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[xmlwriter]]></category>

		<guid isPermaLink="false">http://p0l0.binware.org/?p=1018</guid>
		<description><![CDATA[I have done a little Performance test for the 3 different methods available in PHP for XML generation. For this test I wrote a little script which generates the same XML File using the different methods. Test: 1000 Nodes with 100 Subnodes for each Node. (XML Filesize: 1.9MB) &#160; SimpleXML XMLWriter DOM Time 0.48202991485596 ms [...]]]></description>
			<content:encoded><![CDATA[<p>I have done a little Performance test for the 3 different methods available in PHP for XML generation. For this test I wrote a little script which generates the same XML File using the different methods.</p>
<p><span id="more-1018"></span><br />
<div style="margin-left: -20px; margin-top: 20px; margin-bottom: 20px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-5682258244719056";
/* Inline Post */
google_ad_slot = "6946080416";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div></p>
<pre class="brush: php; title: ; notranslate">
&lt;?php

function printMemory()
{
    echo &quot;Used &quot; . (memory_get_peak_usage() / 1024 / 1024) . &quot; MB\n&quot;;
}

function simpleXMLTest($nodes, $subnodes)
{
    $xml = new SimpleXMLElement(&quot;&lt;?xml version=\&quot;1.0\&quot; encoding=\&quot;utf-8\&quot; ?&gt;&lt;resultset/&gt;&quot;);
    for ($i=0; $i&lt;$nodes; $i++) {
        $node = $xml-&gt;addChild('feed' . $i);
        for ($j=0; $j&lt;$subnodes; $j++) {
            $subnode = $node-&gt;addChild('feed' . $j);
            $subnode-&gt;addAttribute('feed', $j);
        }
    }
    printMemory();
    file_put_contents('/tmp/_test.xml', $xml-&gt;asXML());
}

function XMLWriterTest($nodes, $subnodes)
{
    $xml = new XMLWriter();
    $xml-&gt;openMemory();
    $xml-&gt;startDocument('1.0', 'UTF-8');
    $xml-&gt;startElement('resultset');
    for ($i=0; $i&lt;$nodes; $i++) {
        $xml-&gt;startElement('test' . $i);
        for ($j=0; $j&lt;$subnodes; $j++) {
            $xml-&gt;startElement('test' . $j);
            $xml-&gt;writeAttribute('test', $j);
            $xml-&gt;endElement();
        }
        $xml-&gt;endElement();
    }
    $xml-&gt;endElement();
    printMemory();
    file_put_contents('/tmp/_test.xml', $xml-&gt;outputMemory(true));
}

function DOMTest($nodes, $subnodes)
{
    $dom = new DOMDocument('1.0', 'utf-8');
    $resultset = $dom-&gt;createElement('resultset');
    for ($i=0; $i&lt;$nodes; $i++) {
        $node = $dom-&gt;createElement('test' . $i);
        for ($j=0; $j&lt;$subnodes; $j++) {
            $subnode = $dom-&gt;createElement('test' . $j);
            $subnode-&gt;setAttribute('test', $j);
            $node-&gt;appendChild($subnode);
        }
        $resultset-&gt;appendChild($node);
    }
    $dom-&gt;appendChild($resultset);
    printMemory();
    file_put_contents('/tmp/_test.xml', $dom-&gt;saveXML());
}

$nodes = 1000;
$subnodes = 100;

$start = microtime(true);

//simpleXMLTest($nodes, $subnodes);
//XMLWriterTest($nodes, $subnodes);
//DOMTest($nodes, $subnodes);

$end = microtime(true) - $start;
echo &quot;Took &quot; . $end . &quot; ms\n&quot;;
</pre>
<ol>
<li>
<p>Test: <strong>1000</strong> Nodes with <strong>100</strong> Subnodes for each Node. (XML Filesize: <strong>1.9MB</strong>)</p>
<table>
<tr>
<th>&nbsp;</th>
<th>SimpleXML</th>
<th>XMLWriter</th>
<th>DOM</th>
</tr>
<tr>
<td>Time</td>
<td>0.48202991485596 ms</td>
<td>0.36775803565979 ms</td>
<td>0.72811722755432 ms</td>
</tr>
<tr>
<td>Memory</td>
<td>0.6109619140625 MB</td>
<td>0.61136627197266 MB</td>
<td>0.6141357421875 MB</td>
</tr>
</table>
<p>
<a href="http://p0l0.binware.org/wp-content/uploads/2011/07/XML-1000-100.png" rel="lightbox[1018]"><img src="http://p0l0.binware.org/wp-content/uploads/2011/07/XML-1000-100-300x203.png" alt="XML Comparison - Nodes 1000 - Subnodes 100" title="XML Comparison - Nodes 1000 - Subnodes 100" width="300" height="203" class="alignnone size-medium wp-image-1020" /></a>
</p>
</li>
<li>
<p>Test: <strong>1000</strong> Nodes with <strong>1000</strong> Subnodes for each Node. (XML Filesize: <strong>20MB</strong>)</p>
<table>
<tr>
<th>&nbsp;</th>
<th>SimpleXML</th>
<th>XMLWriter</th>
<th>DOM</th>
</tr>
<tr>
<td>Time</td>
<td>4.867399930954 ms</td>
<td>3.5637412071228 ms</td>
<td>7.1697089672089 ms</td>
</tr>
<tr>
<td>Memory</td>
<td>0.6109619140625 MB</td>
<td>0.61136627197266 MB</td>
<td>0.6141357421875 MB</td>
</tr>
</table>
<p>
<a href="http://p0l0.binware.org/wp-content/uploads/2011/07/XML-1000-1000.png" rel="lightbox[1018]"><img src="http://p0l0.binware.org/wp-content/uploads/2011/07/XML-1000-1000-300x203.png" alt="XML Comparison - Nodes 1000 - Subnodes 1000" title="XML Comparison - Nodes 1000 - Subnodes 1000" width="300" height="203" class="alignnone size-medium wp-image-1021" /></a>
</p>
</li>
<li>
<p>Test: <strong>10000</strong> Nodes with <strong>1000</strong> Subnodes for each Node. (XML Filesize: <strong>199MB</strong>)</p>
<table>
<tr>
<th>&nbsp;</th>
<th>SimpleXML</th>
<th>XMLWriter</th>
<th>DOM</th>
</tr>
<tr>
<td>Time</td>
<td>129.83511686325 ms</td>
<td>38.820327997208 ms</td>
<td>365.01518082619 ms</td>
</tr>
<tr>
<td>Memory</td>
<td>0.6109619140625 MB</td>
<td>0.61136627197266 MB</td>
<td>0.6141357421875 MB</td>
</tr>
</table>
<p>
<a href="http://p0l0.binware.org/wp-content/uploads/2011/07/XML-10000-1000.png" rel="lightbox[1018]"><img src="http://p0l0.binware.org/wp-content/uploads/2011/07/XML-10000-1000-300x203.png" alt="XML Comparison - Nodes 10000 - Subnodes 1000" title="XML Comparison - Nodes 10000 - Subnodes 1000" width="300" height="203" class="alignnone size-medium wp-image-1022" /></a>
</p>
</li>
</ol>
<ul>
<li>
<p>Memory Usage: There isn&#8217;t a big difference between the three methods in Memory Usage (~0.002 MB)</p>
<p>
<a href="http://p0l0.binware.org/wp-content/uploads/2011/07/XML-Memory-usage.png" rel="lightbox[1018]"><img src="http://p0l0.binware.org/wp-content/uploads/2011/07/XML-Memory-usage-300x203.png" alt="XML Comparison - Memory Usage" title="XML Comparison - Memory Usage" width="300" height="203" class="alignnone size-medium wp-image-1023" /></a>
</p>
</li>
</ul>
<p><div style="margin-left: -20px; margin-top: 20px; margin-bottom: 20px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-5682258244719056";
/* Inline Post */
google_ad_slot = "6946080416";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div></p>
<p>After this Tests, we can see that DOM is not an optimal method for XML generation. DOM with small files needs <strong>+0.40 seconds</strong> more then XMLWriter, and SimpleXML needs only <strong>+0.08 seconds</strong> more.</p>
<p>With bigger files, XMLWriter is much faster than the other two methods. So if you need to create big XML files, the best solution is <strong>XMLWriter</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://p0l0.binware.org/index.php/2011/07/04/simplexml-vs-xmlwriter-vs-dom/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Eclipse/ZendStudio custom username for Code Templates</title>
		<link>http://p0l0.binware.org/index.php/2011/06/13/eclipsezendstudio-custom-username-for-code-templates/</link>
		<comments>http://p0l0.binware.org/index.php/2011/06/13/eclipsezendstudio-custom-username-for-code-templates/#comments</comments>
		<pubDate>Sun, 12 Jun 2011 23:48:32 +0000</pubDate>
		<dc:creator>P0L0</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[IDE]]></category>
		<category><![CDATA[netbeans]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[zendstudio]]></category>

		<guid isPermaLink="false">http://p0l0.binware.org/?p=971</guid>
		<description><![CDATA[At work we started using Zendstudio, as the installation on our Linux Boxes is global, we can&#8217;t edit the ZendStudio.ini, and the only way to specify our custom username for Code Templates is using the commandline arguments. The easiest way is to create a shell script to start ZendStudio: Now ZendStudio will replace the variable [...]]]></description>
			<content:encoded><![CDATA[<p>At work we started using Zendstudio, as the installation on our Linux Boxes is global, we can&#8217;t edit the ZendStudio.ini, and the only way to specify our custom username for Code Templates is using the commandline arguments. The easiest way is to create a shell script to start ZendStudio:</p>
<p><span id="more-971"></span><br />
<div style="margin-left: -20px; margin-top: 20px; margin-bottom: 20px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-5682258244719056";
/* Inline Post */
google_ad_slot = "6946080416";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div></p>
<pre class="brush: bash; title: ; notranslate">
#!/bin/bash

###### CONFIG ######
ZENDPATH=&quot;/opt/ZendStudio/ZendStudio&quot;
USERNAME=&quot;Marco Neumann&quot;
USERMAIL=&quot;webcoder_at_binware_dot_org&quot;
####################

USERSTRING=&quot;$USERNAME&quot;
if [ ! -z $USERMAIL ]; then
    USERSTRING=&quot;$USERSTRING &lt;$USERMAIL&gt;&quot;
fi

$ZENDPATH -vmargs -Duser.name=&quot;$USERSTRING&quot;
</pre>
<p>Now ZendStudio will replace the variable <em><strong>${user}</strong></em> in your Code templates with <em>Marco Neumann &lt;webcoder_at_binware_dot_org&gt;</em></p>
<p>Here is an example for &#8220;Simple php file&#8221; in ZendStudio (You will find it in ZendStudio under Window/Preferences/PHP/Code Style):</p>
<ul>
<li><strong>Code Template</strong></li>
</ul>
<pre class="brush: php; title: ; notranslate">
&lt;?php
/**
 * File for the class ${file}
 *
 * @category   CATEGORY
 * @package    PACKAGE
 * @subpackage SUBPACKAGE
 * @copyright  Copyright (c) ${year} ${user}
 * @author     ${user}
 * @version    $$Id:$$
 */

/**
 * SHORT_DESCRIPTION
 *
 * LONG DESCRIPTION
 *
 * @category   CATEGORY
 * @package    PACKAGE
 * @subpackage SUBPACKAGE
 * @copyright  Copyright (c) ${year} ${user}
 */
${cursor}
</pre>
<ul>
<li><strong>Ouput</strong></li>
</ul>
<pre class="brush: php; title: ; notranslate">
&lt;?php
/**
 * File for the class test.php
 *
 * @category   CATEGORY
 * @package    PACKAGE
 * @subpackage SUBPACKAGE
 * @copyright  Copyright (c) 2011 Marco Neumann &lt;webcoder_at_binware_dot_org&gt;
 * @author     Marco Neumann &lt;webcoder_at_binware_dot_org&gt;
 * @version    $Id:$
 */

/**
 * SHORT_DESCRIPTION
 *
 * LONG DESCRIPTION
 *
 * @category   CATEGORY
 * @package    PACKAGE
 * @subpackage SUBPACKAGE
 * @copyright  Copyright (c) 2011 Marco Neumann &lt;webcoder_at_binware_dot_org&gt;
 */
</pre>
<p>This also works with Eclipse and I think it would also work with Netbeans, but haven&#8217;t tested it.</p>
<p><div style="margin-left: -20px; margin-top: 20px; margin-bottom: 20px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-5682258244719056";
/* Inline Post */
google_ad_slot = "6946080416";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div></p>
]]></content:encoded>
			<wfw:commentRss>http://p0l0.binware.org/index.php/2011/06/13/eclipsezendstudio-custom-username-for-code-templates/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google +1 for Sharedaddy</title>
		<link>http://p0l0.binware.org/index.php/2011/06/03/google-1-for-sharedaddy/</link>
		<comments>http://p0l0.binware.org/index.php/2011/06/03/google-1-for-sharedaddy/#comments</comments>
		<pubDate>Fri, 03 Jun 2011 08:26:30 +0000</pubDate>
		<dc:creator>P0L0</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[sharedaddy]]></category>
		<category><![CDATA[sharing]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://p0l0.binware.org/?p=930</guid>
		<description><![CDATA[Google published on 01 June the possibility to add Google +1 to your page, which is a great service to add to the existing sharing services. Im using Sharedaddy, and I will not install another extra plugin to support Google +1 and the Sharedaddy option to add a custom service is not prepared for dynamic [...]]]></description>
			<content:encoded><![CDATA[<p>Google published on 01 June the possibility to <a href="http://googlewebmastercentral.blogspot.com/2011/06/add-1-to-help-your-site-stand-out.html?utm_source=feedburner&#038;utm_medium=feed&#038;utm_campaign=Feed%3A+blogspot%2FamDG+%28Official+Google+Webmaster+Central+Blog%29" target="_blank">add Google +1 to your page</a>, which is a great service to add to the existing sharing services.</p>
<p>Im using <a href="http://wordpress.org/extend/plugins/sharedaddy/" target="_blank">Sharedaddy</a>, and I will not install another extra plugin to support Google +1 and the Sharedaddy option to add a custom service is not prepared for dynamic services like this one. That&#8217;s because I looked to integrate the service into Sharedaddy avoiding to change to much the plugin.</p>
<p><span id="more-930"></span></p>
<p><div style="margin-left: -20px; margin-top: 20px; margin-bottom: 20px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-5682258244719056";
/* Inline Post */
google_ad_slot = "6946080416";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div></p>
<p>Sharedaddy is Object Oriented, so its easy to create a new Sevice Class which extends <em>Sharing_Advanced_Source</em>. But to load your class, you need to change some files.</p>
<ul>
<li>
<p><em>sharing-sources.php</em></p>
<p>To make it dynamic, I created an extra file called <em>sharing-sources-custom.php</em> and load this file from the original Sharedaddy <em>sharing-sources.php</em>:</p>
<pre class="brush: php5; title: ; notranslate">
// Custom Sharing services
require_once('sharing-sources-custom.php');
</pre>
</li>
<li>
<p><em>sharing-services.php</em></p>
<p>This file has an array with the current services and the class name for this service, here we must change directly the function to add our new class.</p>
<pre class="brush: php5; first-line: 37; title: ; notranslate">
private function get_all_services() {
// Default services
$services = array(
...
'googleplusone' =&gt; 'Share_GooglePlusOne'
);
</pre>
</li>
</ul>
<p>This two changes are enought to get your new service working, if you want you can also add images and edit admin-sharing.css to have preview in your admin panel, but the Service will be working without this.</p>
<p>Here is the Code for the <em>Share_GooglePlusOne</em> class:</p>
<pre class="brush: php5; title: ; notranslate">
&lt;?php
/**
 * File for Custom Services
 *
 * @category WordPress
 * @package  Sharedaddy
 */

/**
 * Class for Google+1
 *
 * Implementeation of Google+1 Service for Sharedaddy
 *
 * @category WordPress
 * @package  Sharedaddy
 * @author Marco Neumann &lt;webcoder_at_binware_dot_org&gt;
 * @copyright Copyright (c) 2011, Marco Neumann
 * Licensed under the GNU GPLv3.
 *
 */
class Share_GooglePlusOne extends Sharing_Advanced_Source
{
    /**
     * Button Size
     *
     * @var String
     */
    private $_size = 'small';

    /**
     * Button Language
     *
     * @var String
     */
    private $_language = 'en-US';

    /**
     * Button with count?
     *
     * @var String
     */
    private $_count = 'true';

    // Configuration extracted from http://code.google.com/apis/+1button/#configuration
    /**
     * Available sizes
     *
     * @var Array
     */
    private $_optionsSize = array(
        'small'    =&gt; 'Small Size',
        'medium'   =&gt; 'Medium Size',
        'standard' =&gt; 'Standard Size',
        'tall'     =&gt; 'Tall Size'
    );

    /**
     * Available languages
     *
     * @var Array
     */
    private $_optionsLanguage = array(
        'ar'     =&gt; 'Arabic',
        'bg'     =&gt; 'Bulgarian',
        'ca'     =&gt; 'Catalan',
        'zh-CN'  =&gt; 'Chinese (Simplified)',
        'zh-TW'  =&gt; 'Chinese (Traditional)',
        'hr'     =&gt; 'Croatian',
        'cs'     =&gt; 'Czech',
        'da'     =&gt; 'Danish',
        'nl'     =&gt; 'Dutch',
        'en-GB'  =&gt; 'English (UK)',
        'en-US'  =&gt; 'English (US)',
        'et'     =&gt; 'Estonian',
        'fil'    =&gt; 'Filipino',
        'fi'     =&gt; 'Finnish',
        'fr'     =&gt; 'French',
        'de'     =&gt; 'German',
        'el'     =&gt; 'Greek',
        'iw'     =&gt; 'Hebrew',
        'hi'     =&gt; 'Hindi',
        'hu'     =&gt; 'Hungarian',
        'id'     =&gt; 'Indonesian',
        'it'     =&gt; 'Italian',
        'ja'     =&gt; 'Japanese',
        'ko'     =&gt; 'Korean',
        'lv'     =&gt; 'Latvian',
        'lt'     =&gt; 'Lithuanian',
        'ms'     =&gt; 'Malay',
        'no'     =&gt; 'Norwegian',
        'fa'     =&gt; 'Persian',
        'pl'     =&gt; 'Polish',
        'pt-BR'  =&gt; 'Portuguese (Brazil)',
        'pt-PT'  =&gt; 'Portuguese (Portugal)',
        'ro'     =&gt; 'Romanian',
        'ru'     =&gt; 'Russian',
        'sr'     =&gt; 'Serbian',
        'sk'     =&gt; 'Slovak',
        'sl'     =&gt; 'Slovenian',
        'es'     =&gt; 'Spanish',
        'es-419' =&gt; 'Spanish (Latin America)',
        'sv'     =&gt; 'Swedish',
        'th'     =&gt; 'Thai',
        'tr'     =&gt; 'Turkish',
        'uk'     =&gt; 'Ukrainian',
        'vi'     =&gt; 'Vietnamese'
    );

    /**
     * Constructor
     *
     * @param Integer $id
     * @param Array $settings
     */
    public function __construct($id, array $settings)
    {
        parent::__construct($id, $settings);

        if (isset($settings['size'])) {
            $this-&gt;_size = $settings['size'];
        }
        if (isset($settings['language'])) {
            $this-&gt;_language = $settings['language'];
        }
        if (isset($settings['count'])) {
            $this-&gt;_count = $settings['count'];
        }
    }

    /**
     * Get Service Name
     *
     * @return String
     */
    public function get_name()
    {
        return __('Google +1', 'sharedaddy');
    }

    /**
     * Displays preview
     *
     * @return Share_GooglePlusOne
     */
    public function display_preview()
    {
?&gt;
    &lt;div class=&quot;option option-smart-&lt;?php echo $this-&gt;_count; ?&gt;&quot;&gt;
        &lt;?php
            if ($this-&gt;button_style == 'text' || $this-&gt;button_style == 'icon-text') {
                echo $this-&gt;get_name();
            } else {
               echo '&amp;nbsp;';
            }
        ?&gt;
    &lt;/div&gt;
&lt;?php

        return $this;
    }    

    /**
     * Loads Service required footer code
     *
     * @return Share_GooglePlusOne
     */
    public function display_footer()
    {
        // Load JS for Google +1
        global $post;

        if (isset($post-&gt;ID) &amp;&amp; $post-&gt;ID &gt; 0) {
            $options = array(
                'lang' =&gt; $this-&gt;_language
            );

            echo '&lt;script type=&quot;text/javascript&quot;&gt;';
            if (!empty($options)) {
                echo 'window.___gcfg = ' . json_encode($options) .';';
            }
            echo '(function() {
                  var po = document.createElement(\'script\'); po.type = \'text/javascript\'; po.async = true;
                  po.src = \'https://apis.google.com/js/plusone.js\';
                  var s = document.getElementsByTagName(\'script\')[0]; s.parentNode.insertBefore(po, s);
                  })();';
            echo '&lt;/script&gt;';
        }

        return $this;
    }

    /**
     * Shows icon
     *
     * @return String
     */
    public function get_display($post)
    {
        return '&lt;g:plusone size=&quot;' . $this-&gt;_size . '&quot; count=&quot;' . $this-&gt;_count . '&quot; href=&quot;' . get_permalink() . '&quot;&gt;&lt;/g:plusone&gt;';
    }

    /**
     * Displays available Service options
     *
     * @return Share_GooglePlusOne
     */
    public function display_options()
    {
?&gt;
&lt;div class=&quot;input&quot;&gt;
    &lt;label&gt;
        &lt;select name=&quot;size&quot;&gt;
            &lt;?php foreach ($this-&gt;_optionsSize as $value=&gt;$name): ?&gt;
                &lt;option value=&quot;&lt;?php echo $value; ?&gt;&quot;&lt;?php if ($this-&gt;_size == $value): ?&gt; selected=&quot;selected&quot;&lt;?php endif; ?&gt;&gt;&lt;?php _e($name, 'sharedaddy'); ?&gt;
            &lt;?php endforeach; ?&gt;
        &lt;/select&gt;
    &lt;/label&gt;
    &lt;label&gt;
        &lt;select name=&quot;language&quot;&gt;
            &lt;?php foreach ($this-&gt;_optionsLanguage as $value=&gt;$name): ?&gt;
                &lt;option value=&quot;&lt;?php echo $value; ?&gt;&quot;&lt;?php if ($this-&gt;_language == $value): ?&gt; selected=&quot;selected&quot;&lt;?php endif; ?&gt;&gt;&lt;?php _e($name, 'sharedaddy'); ?&gt;
            &lt;?php endforeach; ?&gt;
        &lt;/select&gt;
    &lt;/label&gt;
    &lt;label&gt;
        &lt;input type=&quot;checkbox&quot;&lt;?php if ($this-&gt;_count == 'true') { echo ' checked=&quot;checked&quot;'; } ?&gt; name=&quot;count&quot; /&gt; Show Count
    &lt;/label&gt;
&lt;/div&gt;
&lt;?php

        return $this;
    }

    /**
     * Updates submitted options
     *
     * @return Share_GooglePlusOne
     */
    public function update_options(array $data)
    {
        if (isset($data['size']) &amp;&amp; isset($this-&gt;_optionsSize[$data['size']])) {
            $this-&gt;_size = $data['size'];
        }

        if (isset($data['language']) &amp;&amp; isset($this-&gt;_optionsLanguage[$data['language']])) {
            $this-&gt;_language = $data['language'];
        }

        $this-&gt;_count = ($data['count'])?'true':'false';

        return $this;
    }

    /**
     * Returns current options
     *
     * @var Array
     */
    public function get_options()
    {
        return array(
            'size'     =&gt; $this-&gt;_size,
            'language' =&gt; $this-&gt;_language,
            'count'    =&gt; $this-&gt;_count
        );
    }
}
</pre>
<p><div style="margin-left: -20px; margin-top: 20px; margin-bottom: 20px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-5682258244719056";
/* Inline Post */
google_ad_slot = "6946080416";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div></p>
<p>Here you can download this file were you will find a patch for the actual sharedaddy version and the images for the admin panel. You only need to apply patch on <em>wp-content/plugins/sharedaddy/</em> and copy the images to <em>wp-content/plugins/sharedaddy/images/</em></p>
<ul>
<li style="list-style-type: none; font-weight: bold;">Patches</li>
<li><a href="http://p0l0.binware.org/wp-content/uploads/2011/06/sharedaddy-googleplusone-1.0.tar.bz2">Sharedaddy with Google +1 &#8211; v.1.0</a></li>
<li><a href="http://p0l0.binware.org/wp-content/uploads/2011/06/sharedaddy-googleplusone-1.1.tar.bz2">Sharedaddy with Google +1 &#8211; v.1.1</a> (Added permalink to +1 button &#8211; Thanks to <a href="http://wordpress.org/support/profile/megazone" target="_blank">megazone</a>)</li>
<li><a href="http://p0l0.binware.org/wp-content/uploads/2011/06/sharedaddy-googleplusone-1.2.tar.bz2">Sharedaddy with Google +1 &#8211; v.1.2</a> (Asynchronous Javascript Loading)</li>
</ul>
<ul>
<li style="list-style-type: none; font-weight: bold;">Complete downloads</li>
<li><a href="http://p0l0.binware.org/wp-content/uploads/2011/06/sharedaddy-0.2.12-googleplusone-1.1.tar.bz2">Sharedaddy 0.2.12 with Google +1 &#8211; v.1.1</a>
<li><a href="http://p0l0.binware.org/wp-content/uploads/2011/06/sharedaddy-0.2.12-googleplusone-1.2.tar.bz2">Sharedaddy 0.2.12 with Google +1 &#8211; v.1.2</a>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://p0l0.binware.org/index.php/2011/06/03/google-1-for-sharedaddy/feed/</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>ChiliProject 1.4.0 + Ruby Enterprise + Passenger + Apache2</title>
		<link>http://p0l0.binware.org/index.php/2011/05/30/redmine-1-2-ruby-enterprise-passenger-apache2/</link>
		<comments>http://p0l0.binware.org/index.php/2011/05/30/redmine-1-2-ruby-enterprise-passenger-apache2/#comments</comments>
		<pubDate>Mon, 30 May 2011 18:29:43 +0000</pubDate>
		<dc:creator>P0L0</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[GNU/Linux]]></category>
		<category><![CDATA[IT Security]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[chiliproject]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[redmine]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[trac]]></category>

		<guid isPermaLink="false">http://p0l0.binware.org/?p=732</guid>
		<description><![CDATA[I was a happy Trac user, but after seeing Redmine, I realized that Trac has many missing features and that you must do a lot of things with plugins, Redmine has this features out-of-box. After working a bit with Redmine I discovered ChiliProject, which is a fork of Redmine, and its actually compatible with Redmine [...]]]></description>
			<content:encoded><![CDATA[<p>I was a happy <a href="http://trac.edgewall.org/" target="_blank">Trac</a> user, but after seeing <a href="http://www.redmine.org/" target="_blank">Redmine</a>, I realized that Trac has many missing features and that you must do a lot of things with plugins, Redmine has this features out-of-box. After working a bit with Redmine I discovered <a href="https://www.chiliproject.org/" target="_blank">ChiliProject</a>, which is a <a href="https://www.chiliproject.org/projects/chiliproject/wiki/Why_Fork" target="_blank">fork</a> of Redmine, and its actually compatible with Redmine <a href="http://www.redmine.org/projects/redmine/wiki/Theme_List" target="_blank">Themes</a> and <a href="http://www.redmine.org/plugins" target="_blank">Plugins</a>.</p>
<p>Here is a comparison of Redmine/ChiliProject and Trac features:<br />
<span id="more-732"></span></p>
<p><div style="margin-left: -20px; margin-top: 20px; margin-bottom: 20px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-5682258244719056";
/* Inline Post */
google_ad_slot = "6946080416";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div></p>
<table>
<tr>
<th>Feature</th>
<th>Redmine/ChiliProject</th>
<th>Trac</th>
</tr>
<tr>
<td>Multiple projects support</td>
<td style="color: green;">Yes</td>
<td style="color: orange;">No (with plugin, planned 0.14)</td>
</tr>
<tr>
<td>Flexible role based access control</td>
<td style="color: green;">Yes</td>
<td style="color: red;">No</td>
</tr>
<tr>
<td>Flexible issue tracking system</td>
<td style="color: green;">Yes</td>
<td style="color: orange;">Yes (no bulk ticket changes and ticket dependencies)</td>
</tr>
<tr>
<td>Gantt chart and calendar</td>
<td style="color: green;">Yes</td>
<td style="color: red;">No (<a href="http://trac-hacks.org/wiki/GanttCalendarPlugin" target="_blank" style="color: red;">GanttCalendarPlugin</a>)</td>
</tr>
<tr>
<td>Feeds &#038; email notifications</td>
<td style="color: green;">Yes</td>
<td style="color: red;">Yes</td>
</tr>
<tr>
<td>Per project wiki</td>
<td style="color: green;">Yes</td>
<td style="color: red;">Yes</td>
</tr>
<tr>
<td>Per project forums</td>
<td style="color: green;">Yes</td>
<td style="color: red;">No (<a href="http://trac-hacks.org/wiki/DiscussionPlugin" target="_blank" style="color: red;">DiscussionPlugin</a>)</td>
</tr>
<tr>
<td>Time tracking</td>
<td style="color: green;">Yes</td>
<td style="color: orange;">No (<a href="http://trac.edgewall.org/wiki/TimeTracking" target="_blank" style="color: orange;">Plugins or custom field</a>)</td>
</tr>
<tr>
<td>Custom fields for issues, time-entries, projects and users</td>
<td style="color: green;">Yes</td>
<td style="color: green;">Yes (<a href="http://trac.edgewall.org/wiki/TracTicketsCustomFields" target="_blank" style="color: green;">editing trac.ini</a>)</td>
</tr>
<tr>
<td>SCM integration</td>
<td style="color: green;">SVN, CVS, Git, Mercurial, Bazaar and Darcs</td>
<td style="color: orange;">SVN in core, others with Plugins</td>
</tr>
<tr>
<td>Issue creation via email</td>
<td style="color: green;">Yes</td>
<td style="color: orange;">No (<a href="http://trac-hacks.org/wiki/MailToTracPlugin" target="_blank" style="color: orange;">MailToTracPlugin</a>)</td>
</tr>
<tr>
<td>Multiple LDAP authentication support</td>
<td style="color: green;">Yes</td>
<td style="color: orange;">No (<a href="http://trac-hacks.org/wiki/LdapPlugin" target="_blank" style="color: orange;">LDAPPlugin</a>)</td>
</tr>
<tr>
<td>User self-registration support</td>
<td style="color: green;">Yes</td>
<td style="color: orange;">No (<a href="http://trac-hacks.org/wiki/AccountManagerPlugin" target="_blank" style="color: orange;">AccountManagerPlugin</a>)</td>
</tr>
<tr>
<td>Multilanguage support</td>
<td style="color: green;">Yes</td>
<td style="color: green;">Yes</td>
</tr>
<tr>
<td>Multiple databases support</td>
<td style="color: green;">MySQL, PostgreSQL, SQLite</td>
<td style="color: orange;">MySQL (unstable), PostgreSQL, SQLite</td>
</tr>
<tr>
<td>iPhone/Android Apps</td>
<td style="color: green;">Yes</td>
<td style="color: red;">No</td>
</tr>
</table>
<p>The first thing that made me not to test Redmine/ChiliProject immediately was that it is RoR and the complexity to make it run stable under apache, but after searching a bit, I found <a href="http://www.modrails.com/" target="_blank">Phusion Passenger</a> and <a href="http://www.rubyenterpriseedition.com/" target="_blank">Ruby Enterprise</a>, which is a very good solution to run RoR products stable under Apache, and you have the ability to run Ruby with custom user, usefull for shared environments.</p>
<h3>Installation</h3>
<ol>
<li>
<p>Ruby Enterprise</p>
<p>I downloaded and installer from source code, so that it&#8217;s compiled for my server and I can store it in a specific location. So, the first we have to do is download latest version from <a href="http://www.rubyenterpriseedition.com/download.html" target="_blank">Ruby Enterprise Download page</a></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>rubyenterpriseedition.googlecode.com<span style="color: #000000; font-weight: bold;">/</span>files<span style="color: #000000; font-weight: bold;">/</span>ruby-enterprise-1.8.7-<span style="color: #000000;">2011.03</span>.tar.gz
<span style="color: #c20cb9; font-weight: bold;">tar</span> zxvf ruby-enterprise-1.8.7-<span style="color: #000000;">2011.03</span>.tar.gz
<span style="color: #7a0874; font-weight: bold;">cd</span> ruby-enterprise-1.8.7-<span style="color: #000000;">2011.03</span>
.<span style="color: #000000; font-weight: bold;">/</span>installer</pre></div></div>

<p>Follow installer instructions, and install dependencies if needed (the installer tells us which packages we need for our Linux distro)</p>
</li>
<li>
<p>Phusion Passenger</p>
<p>Next thing to do, is install the Passanger module for apache, this can be done with the <em>passenger-install-apache2-module</em> script available at Ruby Enterprise installation</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>ruby-enterprise-1.8.7-<span style="color: #000000;">2011.03</span><span style="color: #000000; font-weight: bold;">/</span>bin
.<span style="color: #000000; font-weight: bold;">/</span>passenger-install-apache2-module</pre></div></div>

<p>This script also checks the dependencies and says what packages you need for your Linux distro</p>
</li>
<li>
<p>Apache</p>
<p>Now we need to configure apache, first we need to activate and configure the passenger module</p>
<p><strong>/etc/apache2/mods-enabled/passenger.load</strong></p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;"><span style="color: #00007f;">LoadModule</span> passenger_module /opt/ruby-enterprise-1.8.7-<span style="color: #ff0000;">2011.03</span>/lib/ruby/gems/<span style="color: #ff0000;">1.8</span>/gems/passenger-3.0.7/ext/apache2/mod_passenger.so</pre></div></div>

<p><strong>/etc/apache2/mods-enabled/passenger.conf</strong></p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;">&lt;<span style="color: #000000; font-weight:bold;">ifmodule</span> mod_passenger.c&gt;
  PassengerRoot /opt/ruby-enterprise-1.8.7-<span style="color: #ff0000;">2011.03</span>/lib/ruby/gems/<span style="color: #ff0000;">1.8</span>/gems/passenger-3.0.7
  PassengerRuby /opt/ruby-enterprise-1.8.7-<span style="color: #ff0000;">2011.03</span>/bin/ruby
&nbsp;
  PassengerFriendlyErrorPages <span style="color: #0000ff;">Off</span>
  PassengerUserSwitching <span style="color: #0000ff;">On</span>
  PassengerDefaultUser www-data
  PassengerDefaultGroup www-data
&lt;/<span style="color: #000000; font-weight:bold;">ifmodule</span>&gt;</pre></div></div>

<p>And the last thing is configure a vhost under which we will run this ChiliProject installation</p>
<p><strong>/etc/apache2/sites-enabled/chiliproject</strong></p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;"><span style="color: #00007f;">NameVirtualHost</span> *:<span style="color: #ff0000;">443</span>
&lt;<span style="color: #000000; font-weight:bold;">virtualhost</span> *:<span style="color: #ff0000;">443</span>&gt;
	<span style="color: #00007f;">SSLEngine</span> <span style="color: #0000ff;">on</span>
&nbsp;
	<span style="color: #00007f;">SSLCertificateFile</span>    /etc/apache2/ssl/server.crt
	<span style="color: #00007f;">SSLCertificateKeyFile</span> /etc/apache2/ssl/server.key
&nbsp;
	&lt;<span style="color: #000000; font-weight:bold;">ifmodule</span> mod_passenger.c&gt;
		PassengerUser chiliproject
		PassengerGroup chiliproject
	&lt;/<span style="color: #000000; font-weight:bold;">ifmodule</span>&gt;
&nbsp;
        <span style="color: #00007f;">ServerAdmin</span> webmaster@chiliproject.org
	<span style="color: #00007f;">ServerName</span> chiliproject.org
&nbsp;
	<span style="color: #00007f;">DocumentRoot</span> /home/chiliproject/public
	&lt;<span style="color: #000000; font-weight:bold;">directory</span> /&gt;
		<span style="color: #00007f;">Options</span> -MultiViews
		<span style="color: #00007f;">AllowOverride</span> <span style="color: #0000ff;">All</span>
	&lt; /Directory&gt;
&nbsp;
	<span style="color: #00007f;">ErrorLog</span> /var/log/apache2/chiliproject-error.log
&nbsp;
	<span style="color: #00007f;">CustomLog</span> /var/log/apache2/chiliproject-access.log combined
&lt;/<span style="color: #000000; font-weight:bold;">virtualhost</span>&gt;</pre></div></div>

</li>
<li>
<p>ChiliProject</p>
<p>First install needed gems</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>ruby-enterprise-1.8.7-<span style="color: #000000;">2011.03</span><span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>gem <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #660033;">-v</span>=0.4.2 i18n
<span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>ruby-enterprise-1.8.7-<span style="color: #000000;">2011.03</span><span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>gem <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #660033;">-v</span>=1.0.1 rack
<span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>ruby-enterprise-1.8.7-<span style="color: #000000;">2011.03</span><span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>gem <span style="color: #c20cb9; font-weight: bold;">install</span> mysql</pre></div></div>

<p>Download the last available ChiliProject version from <a href="https://www.chiliproject.org/projects/chiliproject/files" target="_blank">ChiliProject Files Page</a></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">wget</span> https:<span style="color: #000000; font-weight: bold;">//</span>www.chiliproject.org<span style="color: #000000; font-weight: bold;">/</span>attachments<span style="color: #000000; font-weight: bold;">/</span>download<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">99</span><span style="color: #000000; font-weight: bold;">/</span>chiliproject-1.4.0.tar.gz
<span style="color: #c20cb9; font-weight: bold;">tar</span> zxvf chiliproject-1.4.0.tar.gz
<span style="color: #c20cb9; font-weight: bold;">mv</span> chiliproject-1.4.0 <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>chiliproject</pre></div></div>

<p>Create the mysql database and user for ChiliProject</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">DATABASE</span> chiliproject <span style="color: #993333; font-weight: bold;">CHARACTER</span> <span style="color: #993333; font-weight: bold;">SET</span> utf8 <span style="color: #993333; font-weight: bold;">COLLATE</span> utf8_unicode_ci;
<span style="color: #993333; font-weight: bold;">GRANT</span> <span style="color: #993333; font-weight: bold;">ALL</span> privileges <span style="color: #993333; font-weight: bold;">ON</span> chiliproject<span style="color: #66cc66;">.*</span> <span style="color: #993333; font-weight: bold;">TO</span> <span style="color: #ff0000;">'chiliproject'</span>@<span style="color: #ff0000;">'localhost'</span> <span style="color: #993333; font-weight: bold;">IDENTIFIED</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #ff0000;">'my_password'</span>;</pre></div></div>

<p>Configure ChiliProject Database Connection</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">mv</span> config<span style="color: #000000; font-weight: bold;">/</span>database.yml.example config<span style="color: #000000; font-weight: bold;">/</span>database.yml</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="yml" style="font-family:monospace;">production:
  adapter: mysql
  database: chiliproject
  host: localhost
  username: chiliproject
  password: my_password</pre></div></div>

<p>Now initialize ChiliProject (session Store, DB Tables, DB Default Data</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>ruby-enterprise-1.8.7-<span style="color: #000000;">2011.03</span><span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>rake generate_session_store
<span style="color: #007800;">RAILS_ENV</span>=production <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>ruby-enterprise-1.8.7-<span style="color: #000000;">2011.03</span><span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>rake db:migrate
<span style="color: #007800;">RAILS_ENV</span>=production <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>ruby-enterprise-1.8.7-<span style="color: #000000;">2011.03</span><span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>rake redmine:load_default_data</pre></div></div>

<p>And the last thing we need to do before we can restart apache and begin to use the new installed ChiliProject, we need to create the <em>chiliproject</em> user</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">adduser <span style="color: #660033;">--home</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>chiliproject <span style="color: #660033;">--shell</span> <span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">false</span> <span style="color: #660033;">--no-create-home</span> chiliproject
<span style="color: #c20cb9; font-weight: bold;">chown</span> <span style="color: #660033;">-R</span> chiliproject:chiliproject <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>chiliproject</pre></div></div>

</li>
<div style="margin-left: -40px;">
<div style="margin-left: -20px; margin-top: 20px; margin-bottom: 20px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-5682258244719056";
/* Inline Post */
google_ad_slot = "6946080416";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
</div>
<li>
<p>(Optinal) Rmagick</p>
<p>If we would like to enable Gantt export to png image we need to install Rmagick (available as gem). First we need to install imagemagick ang graphicsmagick dev packages and then we can install the rmagick gem.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> libmagickcore-dev libgraphicsmagick1-dev libmagickwand-dev
<span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>ruby-enterprise-1.8.7-<span style="color: #000000;">2011.03</span><span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>gem <span style="color: #c20cb9; font-weight: bold;">install</span> rmagick</pre></div></div>

</li>
</ol>
<p>Now we only need to restart Apache and load ChiliProject in our Browser. The default user is <em><strong>admin/admin</strong></em></p>
]]></content:encoded>
			<wfw:commentRss>http://p0l0.binware.org/index.php/2011/05/30/redmine-1-2-ruby-enterprise-passenger-apache2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Memcached &#8211; Pages/Chunks and Rebalancing</title>
		<link>http://p0l0.binware.org/index.php/2011/05/21/memcached-pageschunks-and-rebalancing/</link>
		<comments>http://p0l0.binware.org/index.php/2011/05/21/memcached-pageschunks-and-rebalancing/#comments</comments>
		<pubDate>Sat, 21 May 2011 06:26:52 +0000</pubDate>
		<dc:creator>P0L0</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[caching]]></category>
		<category><![CDATA[memcached]]></category>

		<guid isPermaLink="false">http://p0l0.binware.org/?p=811</guid>
		<description><![CDATA[It&#8217;s important to know how Memcached organizes the available memory and how Objects are saved to understand &#8220;strange&#8221; effects. Memcached has Pages that have a size of 1Mb (in newer version you can configure them from 1Mb to 128Mb), these Pages are divided in Chunks. The size of the Chunks is created dynamically after start, [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s important to know how Memcached organizes the available memory and how Objects are saved to understand &#8220;strange&#8221; effects.</p>
<p>Memcached has Pages that have a size of 1Mb (in newer version you can configure them from 1Mb to 128Mb), these Pages are divided in Chunks. The size of the Chunks is created dynamically after start, depending on the size of the Objects you are saving. Memcached tries to save a Object in a Chunk were the basted space is minimal (An 49Kb Object will be saved in an 50Kb Chunk)</p>
<p><span id="more-811"></span></p>
<p><div style="margin-left: -20px; margin-top: 20px; margin-bottom: 20px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-5682258244719056";
/* Inline Post */
google_ad_slot = "6946080416";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div></p>
<p>These behavior is ok, but it&#8217;s a Problem when you change the size of your Objects, because Memcached doesn&#8217;t recalculate the Chunk Size, he will use the Chunk Size that is available and because of that the available Memory will not used optimally.</p>
<p>An Example:</p>
<ul>
<li>We start Memcached and save 5-50Kb Objects, so the Chunks will take an Size of 5-50Kb and for bigger Objects there would be only one or two Pages available.</li>
<li>We change our Objects and we want to save 500Kb Objects. Memcached only has for this Object size one or two Pages available, and therefore this big Objects will be soon Evicted, because we have Space for maximum 2x500Kb for each Page. That means if we have 2 Pages with 500Kb Chunks, we can save 4 500Kb Objects, but if we save a fifth element it will cause that the first Object we saved is Evicted.</li>
</ul>
<p>This behavior will cause that the small and big Objects will be saved correctly in Memcached, but when we try to get the entry from cache, it could happen we only have the small Objects in cache and the big Objects are not available.</p>
<p>Here an example with 300 seconds lifetime:</p>
<pre>
Item count:  2
Chunk Size (max item size): 448.2 KBytes
Chunks Per Page (items per 1MB): 2
Pages Allocated: 1
Total Chunks (capacity): 2
Used Chunks (capacity): 2
Free Chunks (free capacity): 0
Evicted: 1172130
Age: 1 minute

Items: item
1968214dc63043688cf883c794c118ecc29e6
19682_039f86925e86b5a3da4cff58c252dff4
</pre>
<p>After 1 minute the Objects are not available and we have two new Objects:</p>
<pre>
Item count:  2
Chunk Size (max item size): 448.2 KBytes
Chunks Per Page (items per 1MB): 2
Pages Allocated: 1
Total Chunks (capacity): 2
Used Chunks (capacity): 2
Free Chunks (free capacity): 0
Evicted: 1172133
Age: 0 minutes

Items: item
19682_63de2d8620816234fd044ca48c0578bd
19682_f86a0ea59a264a397233232a20a080f4
</pre>
<p>Unfortunately it seems that the actual version 1.4.5 doesn&#8217;t have rebalancing implemented, so if you change your cache Object size you must restart your Memcached instance (a flush will not help you).</p>
<p>Here two Screenshots were we can appreciate this behavior.</p>
<p>Only small Objects:</p>
<p><a href="http://p0l0.binware.org/wp-content/uploads/2011/05/memcache09-smallObjects-e1305958284558.png" rel="lightbox[811]"><img src="http://p0l0.binware.org/wp-content/uploads/2011/05/memcache09-smallObjects-e1305958284558-300x150.png" alt="" title="Memcached - Small Objects" width="300" height="150" class="alignnone size-medium wp-image-816" /></a></p>
<p>After restart with small and big Objects:</p>
<p><a href="http://p0l0.binware.org/wp-content/uploads/2011/05/memcache09-smallAndBigObjects-e1305958303522.png" rel="lightbox[811]"><img src="http://p0l0.binware.org/wp-content/uploads/2011/05/memcache09-smallAndBigObjects-e1305958303522-300x136.png" alt="" title="Memcached - Small and Big Objects" width="300" height="136" class="alignnone size-medium wp-image-815" /></a></p>
<p><div style="margin-left: -20px; margin-top: 20px; margin-bottom: 20px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-5682258244719056";
/* Inline Post */
google_ad_slot = "6946080416";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div></p>
<ul>
<li>Statistics Tool with pages/chunk Detail:</li>
<li style="margin-left: 10px;"><a href="http://artur.ejsmont.org/blog/content/first-version-of-memcache-stats-script-based-on-memcachephp" target="_blank">First version of memcache stats script based on memcache.php</a></li>
<li>Memcached Pages/Chunk information:</li>
<li style="margin-left: 10px;"><a href="http://drupal.org/node/971250#comment-3861050" target="_blank">Evictions and memory setup for memcache</a></li>
<li style="margin-left: 10px;"><a href="http://groups.google.com/group/memcached/browse_thread/thread/0ee24dcb981b434a#anchor_0014f6550120de9e" target="_blank">MemCached Evictions</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://p0l0.binware.org/index.php/2011/05/21/memcached-pageschunks-and-rebalancing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Spidermonkey &#8211; Execute javascript from console</title>
		<link>http://p0l0.binware.org/index.php/2010/05/24/spidermonkey-execute-javascript-from-console/</link>
		<comments>http://p0l0.binware.org/index.php/2010/05/24/spidermonkey-execute-javascript-from-console/#comments</comments>
		<pubDate>Mon, 24 May 2010 06:09:26 +0000</pubDate>
		<dc:creator>P0L0</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[GNU/Linux]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://p0l0.binware.org/?p=693</guid>
		<description><![CDATA[SpiderMonkey is the code-name for the Mozilla&#8217;s C implementation of JavaScript. This is useful to test part of our JavaScript from the console or in scripts. In Debian we have a package called spidermonkey-bin. apt-get install spidermonkey-bin After installing you will have a program called smjs. If you start the program without parameters you will [...]]]></description>
			<content:encoded><![CDATA[<p>SpiderMonkey is the code-name for the Mozilla&#8217;s C implementation of JavaScript. This is useful to test part of our JavaScript from the console or in scripts.</p>
<p>In Debian we have a package called <strong>spidermonkey-bin</strong>.</p>
<p><span id="more-693"></span></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> spidermonkey-bin</pre></div></div>

<p><div style="margin-left: -20px; margin-top: 20px; margin-bottom: 20px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-5682258244719056";
/* Inline Post */
google_ad_slot = "6946080416";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div></p>
<p>After installing you will have a program called <strong>smjs</strong>.</p>
<p>If you start the program without parameters you will get a <strong>Javascript shell</strong>, in which you can write and test javascript.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>smjs
js<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #7a0874; font-weight: bold;">test</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
print<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #ff0000;">'test'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>;
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
js<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #7a0874; font-weight: bold;">test</span>
<span style="color: #000000; font-weight: bold;">function</span> <span style="color: #7a0874; font-weight: bold;">test</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    print<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #ff0000;">&quot;test&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>;
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
js<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #7a0874; font-weight: bold;">test</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>;
<span style="color: #7a0874; font-weight: bold;">test</span>
js<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #7a0874; font-weight: bold;">test</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
print<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #ff0000;">'test'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>;
test2<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">123</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>;
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
js<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">function</span> test2<span style="color: #7a0874; font-weight: bold;">&#40;</span>param<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
print <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #ff0000;">'test2: '</span> + param<span style="color: #7a0874; font-weight: bold;">&#41;</span>;
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
js<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #7a0874; font-weight: bold;">test</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>;
<span style="color: #7a0874; font-weight: bold;">test</span>
test2: <span style="color: #000000;">123</span>
js<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<p>To exit the shell, just press &#8220;<strong>Ctrl+D</strong>&#8220;.</p>
<p>It&#8217;s important to note that in spidermonkey you doesn&#8217;t have the &#8220;<strong>document</strong>&#8221; Object. If you want to print out text, you cant use <strong>document.write</strong>, you should use <strong>print</strong>.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">document.<span style="color: #000066; font-weight: bold;">write</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'test'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// In browser</span>
<span style="color: #000066;">print</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'test'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//spidermonkey</span></pre></div></div>

<p>You can also make <strong>smjs</strong> to execute the content of a file.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>smjs test-local.js
Rand: <span style="color: #000000;">407</span>
Old: <span style="color: #000000;">600</span>
New: <span style="color: #000000;">800</span>
Result: old</pre></div></div>

<p><div style="margin-left: -20px; margin-top: 20px; margin-bottom: 20px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-5682258244719056";
/* Inline Post */
google_ad_slot = "6946080416";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div></p>
]]></content:encoded>
			<wfw:commentRss>http://p0l0.binware.org/index.php/2010/05/24/spidermonkey-execute-javascript-from-console/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing TRAC with mod_wsgi using virtualenv</title>
		<link>http://p0l0.binware.org/index.php/2010/05/10/installing-trac-with-mod_wsgi-using-virtualenv/</link>
		<comments>http://p0l0.binware.org/index.php/2010/05/10/installing-trac-with-mod_wsgi-using-virtualenv/#comments</comments>
		<pubDate>Mon, 10 May 2010 19:33:03 +0000</pubDate>
		<dc:creator>P0L0</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[GNU/Linux]]></category>
		<category><![CDATA[IT Security]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mod_wsgi]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[svn]]></category>
		<category><![CDATA[trac]]></category>
		<category><![CDATA[virtualenv]]></category>

		<guid isPermaLink="false">http://p0l0.binware.org/?p=664</guid>
		<description><![CDATA[This guide is for installing Trac as a user using virtualenv for a isolated Python environment so that the whole installation runs under a specific user. First of all we need to install needed packages apt-get install libapache2-mod-wsgi python-virtualenv python-setuptools Once we have installed the required packages proceed to create the Python environment mkdir /usr/local/trac [...]]]></description>
			<content:encoded><![CDATA[<p>This guide is for installing <a href="http://trac.edgewall.org/" target="_blank">Trac </a> as a user using <a href="http://pypi.python.org/pypi/virtualenv/1.4.8" target="_blank">virtualenv</a> for a isolated Python environment so that the whole installation runs under a specific user.</p>
<p>First of all we need to install needed packages</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> libapache2-mod-wsgi python-virtualenv python-setuptools</pre></div></div>

<p>Once we have installed the required packages proceed to create the Python environment</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>trac
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>trac
virtualenv python</pre></div></div>

<p>We now have the isolated Python environment locate under <strong>/usr/local/trac/python</strong>.</p>
<p>To make possible to use <strong>easy_install</strong> with repositories we need to upgrade easy_install. I use this to install Trac plugins directly from SVN.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>trac<span style="color: #000000; font-weight: bold;">/</span>python<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>easy_install <span style="color: #660033;">-U</span> trunk</pre></div></div>

<p>We now can install trac 0.12 using the 0.12b1 SVN Tag (<strong>http://svn.edgewall.com/repos/trac/tags/trac-0.12b1</strong> or <strong>Trac==0.12b1</strong>) or directly from SVN Trunk:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>trac<span style="color: #000000; font-weight: bold;">/</span>python<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>easy_install http:<span style="color: #000000; font-weight: bold;">//</span>svn.edgewall.org<span style="color: #000000; font-weight: bold;">/</span>repos<span style="color: #000000; font-weight: bold;">/</span>trac<span style="color: #000000; font-weight: bold;">/</span>trunk</pre></div></div>

<p>This will download and install the latest trunk version for Trac.</p>
<p>To have webaccess to the Trac projects, we need a <strong>.wsgi</strong> script, were we define where our local python environment is located:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;"># Not needed if mod_wsgi &gt;= 3.0</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>
<span style="color: #dc143c;">sys</span>.<span style="color: black;">stdout</span> = <span style="color: #dc143c;">sys</span>.<span style="color: black;">stderr</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Load Trac</span>
<span style="color: #ff7700;font-weight:bold;">import</span> trac.<span style="color: black;">web</span>.<span style="color: black;">main</span>
application = trac.<span style="color: black;">web</span>.<span style="color: black;">main</span>.<span style="color: black;">dispatch_request</span></pre></div></div>

<p>And finally we need to configure apache. If you want only one Trac project, you should define <strong>trac.env</strong> to the location of your trac, but if you want multiproject support, you must use <strong>trac.env_parent_dir</strong> (this is what I used)</p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;">&lt;<span style="color: #000000; font-weight:bold;">virtualhost</span> *:<span style="color: #ff0000;">80</span>&gt;
    <span style="color: #00007f;">ServerName</span> trac.dns.com
&nbsp;
    <span style="color: #00007f;">DocumentRoot</span> /usr/local/trac/htdocs
    <span style="color: #00007f;">ErrorLog</span> /var/log/apache2/trac-error.log
    <span style="color: #00007f;">CustomLog</span> /var/log/apache2/trac-access.log combined
&nbsp;
    <span style="color: #adadad; font-style: italic;"># Trac Auth</span>
    &lt;<span style="color: #000000; font-weight:bold;">location</span> /&gt;
        <span style="color: #00007f;">AuthType</span> Basic
        <span style="color: #00007f;">AuthName</span> <span style="color: #7f007f;">&quot;Trac&quot;</span>
        <span style="color: #00007f;">AuthUserFile</span> /usr/local/trac/.htpasswd
        <span style="color: #00007f;">Require</span> valid-<span style="color: #00007f;">user</span>
    &lt; /location&gt;
&nbsp;
    <span style="color: #adadad; font-style: italic;">#Trac</span>
    <span style="color: #adadad; font-style: italic;">#Define ProcessGroup with user and group under which it should run</span>
    WSGIDaemonProcess trac <span style="color: #00007f;">user</span>=trac <span style="color: #00007f;">group</span>=trac python-path=/usr/local/trac/python/lib/python2.5/site-packages python-eggs=/usr/local/trac/python/cache
    WSGIScriptAlias / /usr/local/trac/htdocs/trac.wsgi
&nbsp;
    &lt;<span style="color: #000000; font-weight:bold;">directory</span> /usr/local/trac/htdocs&gt;
        WSGIProcessGroup trac
        WSGIApplicationGroup %{GLOBAL}
        <span style="color: #00007f;">SetEnv</span> trac.env_parent_dir /usr/local/trac/projects
    &lt;/<span style="color: #000000; font-weight:bold;">directory</span>&gt;
&lt;/<span style="color: #000000; font-weight:bold;">virtualhost</span>&gt;</pre></div></div>

<p>We need to create the user and change the permissions for <strong>/usr/local/trac</strong> for that user <strong>trac</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">adduser <span style="color: #660033;">--home</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>trac <span style="color: #660033;">--shell</span> <span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">false</span> <span style="color: #660033;">--no-create-home</span> trac
<span style="color: #c20cb9; font-weight: bold;">chown</span> <span style="color: #660033;">-R</span> trac:trac <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>trac</pre></div></div>

<p>If you get an error <strong>&#8220;ImportError: No module named simplejson&#8221;</strong> just install it using easy_install</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>trac<span style="color: #000000; font-weight: bold;">/</span>python<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>easy_install simplejson</pre></div></div>

<p><div style="margin-left: -20px; margin-top: 20px; margin-bottom: 20px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-5682258244719056";
/* Inline Post */
google_ad_slot = "6946080416";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div></p>
]]></content:encoded>
			<wfw:commentRss>http://p0l0.binware.org/index.php/2010/05/10/installing-trac-with-mod_wsgi-using-virtualenv/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Netbeans Performance Switches</title>
		<link>http://p0l0.binware.org/index.php/2010/04/17/netbeans-performance-switches/</link>
		<comments>http://p0l0.binware.org/index.php/2010/04/17/netbeans-performance-switches/#comments</comments>
		<pubDate>Sat, 17 Apr 2010 07:30:23 +0000</pubDate>
		<dc:creator>P0L0</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[IDE]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[netbeans]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[svn]]></category>

		<guid isPermaLink="false">http://p0l0.binware.org/?p=655</guid>
		<description><![CDATA[I recently have began to use Netbeans because I&#8217;m sad that Eclipse is every time slower and it frozes every time when you are doing something to fast. Netbeans is not perfect, and there are some features that need to be polished (Ex.: SVN Support, Time Tracking like Mylyn), but the PHP/HTML/CSS/JS Support is excellent, [...]]]></description>
			<content:encoded><![CDATA[<p>I recently have began to use <a href="http://netbeans.org/features/php/index.html" target="_blank">Netbeans</a> because I&#8217;m sad that <a href="http://www.eclipse.org/pdt" target="_blank">Eclipse</a> is every time slower and it frozes every time when you are doing something to fast.</p>
<p>Netbeans is not perfect, and there are some features that need to be polished (Ex.: SVN Support, Time Tracking like Mylyn), but the PHP/HTML/CSS/JS Support is excellent, in my opinion better than the Eclipse PDF support.</p>
<p>These is my netbeans_default_options for Netbeans for MacOSX (under Windows you can leave out the &#8211;laf switch, it&#8217;s for changing the look and feel):<br />
<span id="more-655"></span></p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;"><span style="color: #000099;">netbeans_default_options</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #933;">&quot;-J-client -J-Xss2m -J-Xms32m -J-Xmx512m -J-XX:PermSize=32m -J-XX:MaxPermSize=200m -J-Xverify:none -J-XX:CompileThreshold=100 -XX:+CompressedOOPS -XX:+AggressiveOpts -XX:+TieredCompilation -XX:+DoEscapeAnalysis -XX:+UseConcMarkSweepGC -J-XX:+CMSClassUnloadingEnabled -J-XX:+CMSPermGenSweepingEnabled -J-Dapple.laf.useScreenMenuBar=true -J-Dsun.java2d.noddraw=true --laf javax.swing.plaf.metal.MetalLookAndFeel&quot;</span></pre></div></div>

<p>Some switches come from <a href="http://performance.netbeans.org/howto/jvmswitches/index.html" target="_blank">Netbeans Performance</a> site.</p>
<ul>
<li><strong>-J-Xss2m</strong> &#8211; Define Stack Size (Too small and you will get StackOverflow Exceptions)</li>
<li><strong>-J-Xms32m</strong> &#8211; This setting tells the Java virtual machine to set its initial heap size to 32 megabytes. By telling the JVM how much memory it should initially allocate for the heap, we save it growing the heap as NetBeans consumes more memory. This switch improves startup time</li>
<li><strong>-J-Xmx512m</strong> &#8211; This settings tells the Java virtual machine the maximum amount of memory it should use for the heap. Placing a hard upper limit on this number means that the Java process cannot consume more memory than physical RAM available. This limit can be raised on systems with more memory. Current default value is 128MB. Note: Do not set this value to near or greater than the amount of physical RAM in your system or it will cause severe swapping during runtime</li>
<li><strong>-J-XX:PermSize=32m -J-XX:MaxPermSize=200m</strong> &#8211; How much Heap can be added over the Xmx limit</li>
<li><strong>-J-Xverify:none</strong> &#8211; This switch turns off Java bytecode verification, making classloading faster, and eliminating the need for classes to be loaded during startup solely for the purposes of verification. This switch improves startup time, and there is no reason not to use it</li>
<li><strong>-J-XX:CompileThreshold=100</strong> &#8211; This switch will make startup time slower, by HotSpot to compile many more methods down to native code sooner than it otherwise would. The reported result is snappier performance once the IDE is running, since more of the UI code will be compiled rather than interpreted. This value represents the number of times a method must be called before it will be compiled</li>
<li><strong>-XX:+CompressedOOPS</strong> &#8211; Activate Compressed &#8220;Ordinary Object Pointer&#8221;</li>
<li><strong>-XX:+AggressiveOpts</strong> &#8211; Turns on point performance optimizations that are expected to be on by default in upcoming releases</li>
<li><strong>-XX:+TieredCompilation</strong> &#8211; Activate Tiered Compiler</li>
<li><strong>-XX:+DoEscapeAnalysis</strong> &#8211; Activate Escape Analysis</li>
<li><strong>-J-XX:+UseConcMarkSweepGC or -J-XX:+UseParNewGC</strong> Try these switches if you are having problems with intrusive garbage collection pauses. This switch causes the JVM to use different algorithms for major garbage collection events (also for minor collections, if run on a multiprocessor workstation), ones which do not &#8220;stop the world&#8221; for the entire garbage collection process. You should also add the line <strong>-J-XX:+CMSClassUnloadingEnabled</strong> and <strong>-J-XX:+CMSPermGenSweepingEnabled</strong> to your netbeans.conf file so that class unloading is enabled (it isn&#8217;t by default when using this collector)</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://p0l0.binware.org/index.php/2010/04/17/netbeans-performance-switches/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

