Automatically apply PSR-2 coding style

Applying PSR-2 coding style manually is really no fun and wasting time. A short visit in Github and there’s a tool which detects and fixes the coding style. The tool is called php-cs-fixer.

I’ll show you how to get the tool and use it to easily reformat all PHP file in project.

Continue reading Automatically apply PSR-2 coding style

Connection refused after installing DSM 6.0 Beta

After installing the newly released DSM 6.0 beta for Synology NAS, I was unable to reach the DSM again. My Chrome browser showed “Connection refused”. Not really a good start for beta testing new software. connection-refused

Luckily SSH is still up. Since DSM running on nginx, it’s straightforward to look for some error log in the nginx error log.

1
$ cat /var/log/nginx/error.log

shows following log records

1
2015/10/14 21:08:31 [emerg] 9040#9040: PEM_read_bio_X509_AUX("/usr/syno/etc/ssl/ssl.chain.crt/server.crt") failed (SSL: error:0906D066:PEM routines:PEM_read_bio:bad end line)

in the file /usr/syno/etc/ssl/ssl.chain.crt/server.crt I found a weird certificate formatting

1
2
3
4
5
6
...
ImqVevbi0ntIdiu3OBL0NuuHNw7N1kKkXTBIZnswp3mxOVSqDrEchULLW8fyawVX
lBOEu1QErxKSjwvlkQ==
-----END CERTIFICATE----------BEGIN CERTIFICATE-----
MIIF2TCCA8GgAwIBAgIHFxU9nqs/vzANBgkqhkiG9w0BAQsFADB9MQswCQYDVQQG
...

There’s a missing newline between the chained certificate. Put a new line between the certificate and restart nginx.

1
2
3
4
5
6
7
...
ImqVevbi0ntIdiu3OBL0NuuHNw7N1kKkXTBIZnswp3mxOVSqDrEchULLW8fyawVX
lBOEu1QErxKSjwvlkQ==
-----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
MIIF2TCCA8GgAwIBAgIHFxU9nqs/vzANBgkqhkiG9w0BAQsFADB9MQswCQYDVQQG
...

and restart nginx

1
$ synoservicecfg --restart nginx

Tadaaaa… DSM is available again.

Fail downloading file on Android

How hard is it, to write a PHP script to allow user to download a file? really easy, one would say. Just send the appropriate HTTP header and echo the file content.

1
2
3
4
5
< ?php
  header('Content-type: application/force-download');
  header('Content-Disposition: attachment; filename="test.txt"');
  echo(file_get_content('/path/to/file'));
?>

Basically that’s all I need to force download per PHP. But somehow Android stock browser (Chrome) only downloads and creates a 0 kB file. Other browser (tested with Firefox on Android) saves the file correctly.

What does happen here?

Continue reading Fail downloading file on Android

SEO – add trailing slash to URL

The problem

For those who use Google Webmaster Tool, they might find Google “duplicated content” warning. This is caused by slightly different URL, which is found by search engine.
Like:

http://domain.tld/google

and

http://domain.tld/google/

are interpreted as 2 different pages by search engine. So how do we resolve this?

Continue reading SEO – add trailing slash to URL

Munin on Raspberry Pi with dynamic IP

the easiest tool to monitoring a server is munin. It’s easy to install and has lots of plugins. Installing munin on a server, which is to be monitored, is not really a smart move. Seeing a raspberry pi laying on a closet and do nothing, gives me the idea to use it to monitor my vServer. The problem is how to configure munin-node to communicate with munin, which is behind a dynamic IP. But one step after the other 🙂

First move is to grab a SD-Card and flash Raspbian from Raspberry Pi website. This is an easy task.

Next task is to assign a static IP address. Continue reading Munin on Raspberry Pi with dynamic IP

Extbase and RealURL

another day, another problem. Extbase is becoming main framework for TYPO3 extension, because it’s really easy to create a frontend plugin to show (listing or detail view) of a records. Since it’s MVC framework, Extbase create a complex URL for each record.


http://domain.tld/pageName/?tx_extension_plugin[action]=show&tx_extension_plugin[controller]=controllerName&tx_extension_pluginName[param]=9

how to short this?

Continue reading Extbase and RealURL

Standalone view in extbase

Usually a view in extbase is always called from a controller.  but what if, an action in your controller is called as an eID and only parts of the template needs to be rendered? Partial is an option, but I have a code snippet, which uses the

1
TYPO3\\CMS\\Fluid\\View\\StandaloneView

class.

Continue reading Standalone view in extbase