Getting Yii2 debug to show on user role instead of IP

I recently had to get Yii2 debug to show based on whether I was an admin user or not due to not connecting to the site using static IPs.

Having the debug in production run for the admin user is really useful for fixing those problems which are not easily, or possibly, replicated down to development.

So I overrode the Module class for debug but found some problems with view paths. I ended up with:


<?php

namespace common\components;

use Yii;
use yii\debug\Module as DebugModule;
use common\models\User;

class Module extends DebugModule
{
	private $_basePath;
	
	protected function checkAccess()
	{
		$user = Yii::$app->getUser();

		if(
			$user->identity && 
			$user->can('admin')
		){
			return true;
		}
		return parent::checkAccess();
	}
	
	/**
	 * Returns the root directory of the module.
	 * It defaults to the directory containing the module class file.
	 * @return string the root directory of the module.
	 */
	public function getBasePath()
	{
		if ($this->_basePath === null) {
			$class = new \ReflectionClass(new yii\debug\Module('debug'));
			$this->_basePath = dirname($class->getFileName());
		}
	
		return $this->_basePath;
	}
}

The question of internet freedoms

I would say this film is required watching for all internet denizens: https://www.youtube.com/watch?v=vXr-2hwTk58

It tells of a person who gave everything for the cause of internet freedom, even their own life.

Somethings have made me question free speech and freedom of information on the internet, for example: what is the difference between free speech and self advetisement? Is there an invisible line that should be drawn even on blog comments (such as this very site) between what is considered free speech and what could be counted as very elaborate spam to promote a certain product invisibly?

I have so far avoided censoring any blog comments on here, even ones that contain links to the commentors site or products within them, mainly because I feel so strongly about freedom in every single way that I feel bad about editing that comment, even if to just remove that link.

In an internet where people say they are for free speech (wordpress.com) but then use the very same motto and morale as Aaron to make free speech work for their own ends it is sometimes hard to decide if Aaron really did make a difference in the long term.

Take, as I mentioned, wordpress.com. They boast free speech as being paramount to everythng they believe in, that it is required of every blogger on this site (they even produce transparency reports: http://en.blog.wordpress.com/2014/04/17/transparency-report/) and they try their hardest to confront every take down request and stop it. Yet they cannot seem to apply that rule to themselves, in the form of comment moderation on their news blog posts (it is kind of like a wordpress.com newsletter).

I have made many comments on wordpress.com news blog posts over my time here but only one has ever not been censored. I made a comment recently on Rwanda and how evidence shows that it is not only under a increasing, authoritarian, dictatorship (whose leader has been numerously accused by his closest allies of causing the action that resulted in the murder of many hundreds of thousands of people) but that ethnic grievances have never been solved, and how the problems are just laying under the surface for a resurgance of voilence.

The comment was in line with the post which talked about using UX design in Rwanda to try and put across and message that massacres are wrong and that they should not be tolerated. I praised the author for his gumption to try and do something but reminded people of the facts that are beginning to once more make themselves aware.

This comment was consequently consored and deleted along with many other less confrontational comments, even ones as simple as “the website you linked has UX problems because…” on a more recent post of what they considered to be good looking websites; ironically they allowed comments through which agreed with their stance.

This explains the problem quite clearly, many people on the internet are using Aarons legacy as a means to pass themselves off as pro-freedom, pro-sharing, when in reality they are not. In reality they use and abuse Aarons and other legacy to suite their needs, and turn back to the old ways when it no longer suites them.

Freedom is not about it suiting you, it is about you respecting and understanding other peoples wantings and needs. When someone comments on your blog post, don’t remove what you don’t like, it is their needs that they feel as though they have to say that. Yes, I understand there are limits, swearing, abusive language, and the rest. However, when someone genuinely makes a worthwhile comment on our site/blog you should try everything in your power to accomodate for their need of freedom, including free speech.

We have created an amazing thing called the internet, people have even died to give us the freedoms we currently enjoy on the internet; you could even count those that died in the World Wars as being part of that, afterall is not the internet based upon our own principles of freedom? However, there are those who will use this legacy to their benefit to twist the internet into their own little playground and attempt to tame it. It is bad enough that our internet is run by a bunch of technologically senile people who cannot call us “experts”, let’s not prove that we are no better by resorting to freedom by convience.

Next time someone tries to comment on your blog remember the likes of activitists like Aaron who tried to give you the right to make that content in the first place to be commented on.

Try to keep our freedoms.

Why I refuse to earn money from Facebook games

I was recently approached, through various channels, to co-found a Facebook game.

Essentially the primise of it is to make something like Tetrus or Diamonds and add micro-transactions for bonuses and what not to make the users life on the game easier.

I will get right to the point and state that I turned down the offer.

Sure it is a quick buck, use about 5 hours making the game, £300 of Facebook advertising/marketing and “bingo”, you have something that could earn you double your normal wage in the space of a year. An easy and sustainable income if I may be honest. Once every few years you release a new game and solely you can hold down a wage. No need to work for Zenga or one of those other big companies, just you can earn the money.

So with the last paragraph in mind it seems like a no brainer to make a Facebook game and earn some easy money, and many do, just look at how many games there are; with an added audience of 1 billion users how can you go wrong? There will always be a suckers addiction and/or misery to feed off.

Wait, what? Addiction and/or misery? Did I really learn to program to do this? And this follows onto my reasoning for refusing to make this game.

Sure I could make this game, sure I could earn a lot of money, but can I really?

Like many others, I learnt to program in my spare time because I wanted to, not to make money. I was in the final year of my university Honors degree in Computing and I had to come up with a final project idea so I chose to make a YouTube replica from PHP. I had never touched PHP before that time nor any web development frankly, aside form a small Java project in my first year to make a simple HTML website running on Tomcat.

To cut to the point: despite doing all that work and still being one of the few in the class who actually completed a project I got a shitty grade; 41.4% in fact which almost failed me (39% would have been a fail) and caused me to lose the 2:1 mark I was heading for.

But that didn’t stop me and I went onto a job which involved that exact work and I can feel pride in my work.

How, after everything I went through to get this expertise and knowledge, could I feel pride in something that feeds on misery? I think I probably speak for quite a few programmers when I say that this isn’t what we learnt to program for.

That’s why I feel sorry for people who work for Zenga, they have to work knowing that they have to take pride in something that brings addiction and misery to many millions of Facebook users, stealing their money in the process; their programs are effectively a plague upon the internet. Maybe that is why I keep hearing such low morale at the company in question, aside from management issues.

Every worth while programmer knows that they need to feel pride for what they have accomplished, sure there will be those who learn to program to “get ahead” in the market or to earn money. But the real programmers, those who make the internet what it is today love to program and they need to feel pride in their work and what they do and know that it is benefiting others, not sucking their money using their misfortunes as an excuse.

I could not feel pride in making a Facebook game that makes a quick buck, though I must admit myself that the thought of doing such a thing is tempting, but for the minute I will resist. I will not convert over to the dark side and become effectively Lord Vader. I still have some moralities left in me.

As such I regretfully but honestly decline to make a Facebook game.

Definition of Yii2 Aliases

Following on from this good article by @KartikV: Yii 2.0: Yii 2 list of path aliases available with default basic and advanced app – I recently needed to use this list to understand what goes into each alias so that I could dupe it for compression in the console. Unfortunately I found no reference for understanding this and the descriptions in that article are not very useful so here is my attempt.

There are a few assumptions made here:

- I have a url of “http://localhost.com/yii” as my base URL
– My app root is at “/srv/www/webapp” in my OS (Linux)

So here is my list:

- @app = /srv/www/webapp/frontend
– @vendor = /srv/www/webapp/frontend/config/../../vendor
– @runtime = /srv/www/webapp/frontend/runtime
– @web = /yii (from “http://localhost.com/yii“)
– @webroot = /srv/www/webapp/frontend/web
– @common = /srv/www/webapp/common
– @frontend = /srv/www/webapp/frontend
– @backend = /srv/www/webapp/backend
– @console = /srv/www/webapp/console

Nginx truncating Any Web Page with or without PHP

I had a problem recently (or rather just now) whereby one of my Nginx installs was truncating PHP pages.

I soon figured out it was because Nginx was actually showing me the in-memory buffer output and cutting off file buffer. You see Nginx will first try and load your entire page into memory, when failing this it will pump the output to a file.

The problem is if Nginx cannot write to that file for some reason it will only give you the first in-memory output of a page.

The way to find out if this is happening to you and how to solve it is detailed here: http://derekneely.com/2009/06/nginx-failed-13-permission-denied-while-reading-upstream/ but I will summarise it here to prevent link rot.

Your error.log should have a line of:

2014/07/08 08:19:25 [crit] 30100#0: *308814 open() "/var/lib/nginx/fastcgi/0/11/0000005110" failed (13: Permiss ion denied) while reading upstream, client: xx.xxx.xxx.xxx, server: localhost, request: "GET /xxxx/xxxx-xxxx  HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "xxxx.com", referrer: "http://xxxx.com/xxx/xxx"

And put simply double check the permissions of your folders/files in: /var/lib/nginx/fastcgi there is a very good chance they are not of the right permissions.

Making npm work on a Cifs/Windows Share

I spent the last 5 hours trying to work out why I couldn’t use npm install for bootstrap in a cifs partition.

Turns out some has had this problem and posted a fix: http://askubuntu.com/questions/269727/npm-errors-when-installing-packages-on-windows-share

npm install --no-bin-links

This is since on a cifs partition npm will actually bail out with chmod when trying to set symlinks for the modules that it cannot due to you using a Windows share.