Categoria: english

17 novembre 2017 / / english

Requirement: use a local custom string for a core Yii2 message.

Since of course I didn’t want to  touch files into @vendor (which wouldn’t survive an upgrade, and are out of git control) I worked it out by customizing the i18n core component of Yii2.

Open up config/web.php (if you created the app from the basic template) and add the following into the components section:

13 novembre 2017 / / english

Today I had to convert a PDF into a web embeddable image. In the past we used to run Ghostscript via exec()/system() calls, but that’s annoying because you have to deal with temporary files, if you don’t intend to keep them for archive. So I wanted to try a more decent way: convert the PDF using PHP’s Imagick libraries and display the image inline, using data-uri. This is the code I came up with:

try {
    // [0] means pick just the first page of the PDF
    $img = new \Imagick(Yii::getAlias("@app/documenti/pdf/{$this->telaio}-{$this->id}.pdf[0]"));
} catch (\ImagickException $e) {
    Yii::trace($e->getMessage(), __METHOD__);
    // If there's an error, most likely missing file, display a transparent PNG
    // If you want smaller image you can use GIF, but I had to display it in a mPDF document and it didn't like it 
return 'data:image/png;base64,'.base64_encode($img->getimageblob());

Unfortunately the exception I got was not about a missing file (which of course could have been properly checked), but:

ImagickException FailedToExecuteCommand ‘gs’

Ok, given that you have GhostScript installed (maybe via Homebrew), and gs command is in your path, let’s see why it’s not working.

17 ottobre 2017 / / english

Checking a Zimbra Network Edition server I found out backups were not running for some time. Nobody noticed because reports email were not delivered.

When running

zmbackup -f -a all

I got this error message:

Error occurred: system failure: unable to retrieve latest session-account, account name-id maps

Talking in IRC Tonster suggested that the main Zimbra backup file, accounts.xml, could have been corrupted.

13 ottobre 2017 / / english

When I purchased the new Macbook Pro last year, one big issue was the lack of widely used interface ports. In order not to purchase many dongles (and spend too much on the Apple Store) I had a look on the usual sites and found a nice one from Cable Matters (no, sadly I have no sponsorship from them) which had them all: ethernet, USB-A, VGA and HDMI. Fantastic!

Coming from Linux, where 99% of the drivers are already provided in the kernel, the first odd thing I had to do is install the drivers for these ports! Even if I manage Windows computers daily, I wasn’t used anymore on my laptop!

Luckily drivers are not hard to find:

  • USB-A port uses ASM1153 chipset (55aa:174c), but works out of the box
  • Ethernet uses AX88179 from Asix (1790:0b95)

When I first installed the drivers I was using Sierra, and no problems arise. Now that I reinstalled with High Sierra the ethernet driver wasn’t working. Why? User-Approved Kernel Extension Loading.

12 ottobre 2017 / / english

Since I’m oldskool (and since Time Machine stopped working nearly one month after I started using my new Mac), I was compelled to do a manual backup of my system before reinstalling it.

Yes, I reinstalled a MacOS system in less than one year. I remember doing this just when I was reinstalling Ubuntu from scratch after the release of a new version. Not really what I was expecting from a Mac.

Anyway… What I did was just an rsync of my whole home to an external disk, but then I had to recover the most I could. Reinstalling is fun, but reconfiguring everything not as much!

11 settembre 2017 / / english

Yesterday I released a new version (thus introducing the concept of versions) of the certbot-zimbra script.

One of the most notably change is the removal of the patches/ subdirectory, which I personally hated. Now patches are embedded inside the script. Less crap around to manage!

Also the patching method was changed: instead of having a single patch file (or variable, with the new method) for every Zimbra version now I do version comparison. So now there’s an if (version < 8.6) apply patch 1, otherwise if lower than X.Y apply patch 2 and so on. Simpler and less problematic for users.

8 settembre 2017 / / english
5 settembre 2017 / / english

wordpress-bruteforceNot the best solution out there, but a piece that could help.

I’ve an hosting VPS with LEMP stack and ISPConfig, on which I have some WordPress sites. WordPress sites are known to be very popular among spammers and crackers, not because of the core itself but because its thousands of plugins are often not updated and so easily crackable, or beause they know their chickens and WP admins might use weak passwords which can be bruteforced.

So I often find a lot of POSTs against wp-login.php in my webserver log. How to block them?

29 agosto 2017 / / english
1 agosto 2017 / / english

Quick and easy self note: when using Kartik plugins for Yii2, and including them in a Pjax container, some may need to be reinitialized.

Without getting crazy, Kartik already thought about this by providing a common property to all his widgets: pjaxContainerId. As the documentation states:

container ID if applicable inside which the widget will be rendered. If this is set, the widget will automatically reinitialize on pjax render completion.

So if you set that value to the ID of the pjax container, when the content is loaded the widget will be initialized correctly.