Posts Tagged ‘solution’
Saturday, April 7th, 2012
I've recently wanted to use PHP's embedded system(""); – external command execute function in order to use ls + wc to calculate the number of files stored in a directory. I know many would argue, this is not a good practice and from a performance view point it is absolutely bad idea. However as I was lazy to code ti in PHP, I used the below line of code to do the task:
<?
echo "Hello, ";
$line_count = system("ls -1 /dir/|wc -l");
echo "File count in /dir is $line_count \n";
?>
This example worked fine for me to calculate the number of files in my /dir, but unfortunately the execution output was also visialized in the browser. It seems this is some kind of default behaviour in both libphp and php cli. I didn't liked the behaviour so I checked online for a solution to prevent the system(); from printing its output.
What I found as a recommendations on many pages is instead of system(); to prevent command execution output one should use exec();.
Therefore I used instead of my above code:
<?
echo "Hello, ";
$line_count = exec("ls -1 /dir/|wc -l");
echo "File count in /dir is $line_count \n";
?>
By the way insetad of using exec();, it is also possible to just use ` (backtick) – in same way like in bash scripting's “.
Hence the above code can be also written for short like this:
<?
echo "Hello, ";
$line_count = `ls -1 /dir/|wc -l`;
echo "File count in /dir is $line_count \n";
?>
If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!
Tags: Auto, backtick, bad idea, behaviour, browser, code lt, command, command execution, count, default behaviour, dir, Draft, exec, execution, file, fine, function, idea, kind, libphp, line, online, order, performance, performance view, quot, solution, task, way
Posted in Programming, Web and CMS | 2 Comments »
Monday, March 26th, 2012

I had to install two PHPBB based internet forums, some long time ago. Since long time passed and I haven't checked what's happening with them I just noticed. They start filling up spam threads. The phpbb installations are done using the standard shipped deb packages in Debian Linux Lenny.
After checking online, I found one smart solution to . The idea is very simple most spam bots are written in a way that they don't have a properly set timezone. Therefore the quickest way to get rid of spam bots which try to auto register and put spam content inside the a forum category or post is to add a simple if condition in php to check the browser set timezone:
The file to add the php if condition is ucp_register.phpThe phpbb package install places default phpbb path on Debian is /usr/share/phpbb3/ and hence the file I had to modify is located in:
/usr/share/phpbb3/www/includes/ucp/ucp_register.php
To make the TZ check one needs to modify ../www/includes/ucp/ucp_register.php and look for php array definition:
$data = array(
'username' => utf8_normalize_nfc(request_var('username', '', true)),
'new_password' => request_var('new_password', '', true),
'password_confirm' => request_var('password_confirm', '', true),
'email' => strtolower(request_var('email', '')),
'email_confirm' => strtolower(request_var('email_confirm', '')),
'confirm_code' => request_var('confirm_code', ''),
'lang' => basename(request_var('lang', $user->lang_name)),
'tz' => request_var('tz', (float) $timezone),
);
Right after this chunk of code add the if condition code which is like so:
if ($data['tz'] == '-12.00')
{
die('Die, bot! Die.');
}
From now onwards, any attempt for new user registration with an incorrect timezone of -12.00 will be immediately stopped while the forum spammer bot will be offered an empty page
Another good practice is to disable Birthday Listing from phpbb Admin Control panel (ACP). Go to menus:
ACP -> General -> Board Settings -> Enable Birthday listing: (No)

I like disabling birthday listing, as when it is enabled and you have some spammer registrations, which even though didn't succeeded to contaminate your forum content has specified a birthday and therefore there profiles gets popping up each different day on the main page of the forum.
This will not eradicate all spammer bots, but at least will significantly decrease spammer bot registrations.
Tags: array definition, Auto, checking, chunk, code 39, deb, deb packages, Debian, debian gnu, debian linux, Draft, email, forum, forum category, GNU, Internet, internet forum, internet forums, Linux, long time, online, PHPBB, smart solution, solution, spam, spam bots, threads, time
Posted in System Administration, Web and CMS | No Comments »
Thursday, January 5th, 2012
While configuring JWchat domain, I've come across around an error:
pcfg_openfile: unable to check htaccess file, ensure it is readable
The exact error I got in /var/log/apache2/error.log looked like so:
[crit] [client xxx.xxx.xxx.xxx] (13)Permission denied: /var/lib/ejabberd/.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable, referer: http://jabber.mydomain.com/
The error message suggested /var/lib/ejabberd/.htaccess – is missing or not readable, however after checking i've seen .htaccess existed as well as was readable:
debian:~# ls -al /var/lib/ejabberd/.htaccess
-rw-r--r-- 1 www-data www-data 114 2012-01-05 07:44 /var/lib/ejabberd/.htaccess
At first glimpse it seems like the message is misleading and not true, however when I switched to www-data user (the user with which Apache runs on Debian), I've figured out the error meaning of unreadability is exactly correct:
www-data@debian:$ ls -al /var/lib/ejabberd/.htaccess
ls: cannot access /var/lib/ejabberd/.htaccess: Permission denied
This permission denied was quite strange, especially when considering the .htaccess is readable for all users:
debian:~# ls -al /var/lib/ejabberd/.htaccess
-rw-r--r-- 1 www-data www-data 114 2012-01-05 07:44 /var/lib/ejabberd/.htaccess
After a thorough look on what might go wrong, thanksfully I've figured it out. The all issues were caused by wrong permissions of /var/lib/ejabberd/.htaccess .You can see below the executable flag for all users (including apache's www-data) is missing :
debian:/var/lib# ls -ld /var/lib/ejabberd/drw-r--r-- 3 ejabberd ejabberd 4096 2012-01-05 07:45 /var/lib/ejabberd/
Solving the error, hence is as easy as adding +x flag to /var/lib/ejabberd :
debian:/var/lib# chmod +x /var/lib/ejabberd
Another way to fix the error is to chmod to 755 to the directory which holds .htaccess:
From now onwards pcfg_openfile: unable to check htaccess file, ensure it is readable err is no more
Tags: access, apache, Auto, Cannot, cause and solution, client, domain, Draft, drw, ejabberd, ERROR, error message, exact error, first glimpse, glimpse, htaccessAfter, jwchat, ld, lib, log, look, message, pcfg, Permission, readableThe, solution, unreadability, var, way, www data, xxx
Posted in Linux, System Administration, Various, Web and CMS | No Comments »
Friday, October 28th, 2011
One of the qmail servers I manage today has started returning strange errors in Squirrel webmail and via POP3/IMAP connections with Thunderbird.
What was rather strange is if the email doesn't contain a link to a webpage or and attachment, e.g. mail consists of just plain text the mail was sent properly, if not however it failed to sent with an error message of:
Requested action aborted: error in processing Server replied: 451 qq temporary problem (#4.3.0)
After looking up in the logs and some quick search in Google, I come across some online threads reporting that the whole issues are caused by malfunction of the qmail-scanner.pl (script checking mail for viruses).
After a close examination on what is happening I found out /usr/sbin/clamd was not running at all?!
Then I remembered a bit earlier I applied some updates on the server with apt-get update && apt-get upgrade , some of the packages which were updated were exactly clamav-daemon and clamav-freshclam .
Hence, the reason for the error:
451 qq temporary problem (#4.3.0)
was pretty obvious qmail-scanner.pl which is using the clamd daemon to check incoming and outgoing mail for viruses failed to respond, so any mail which contained any content which needed to go through clamd for a check and returned back to qmail-scanner.pl did not make it and therefore qmail returned the weird error message.
Apparently for some reason apparently the earlier update of clamav-daemon failed to properly restart, the init script /etc/init.d/clamav-daemon .
Following fix was very simple all I had to do is launch clamav-daemon again:
linux:~# /etc/inid.d/clamav-daemon restart
Afterwards the error is gone and all mails worked just fine
Tags: action, amp, cause and solution, checking, Clamav, clamd, daemon, email, examination, fine, fix, g mail, google, imap connections, init script, link, logs, mail, online, outgoing mail, pl script, processing, Qmail, qq, reason, Requested, scanner, Search, servers, solution, Squirrel, strange errors, Thunderbird, today, update, usr, Viruses, weird error message
Posted in Linux, Qmail, System Administration | No Comments »
Friday, September 23rd, 2011

In my recent question of looking for best ways to optimize my wordpress blog, as well as other wordpress based websites, I'm managing I've come across a great plugin called W3 Total Cache or W3TC as it's widely known among wordpress geeks.
The full caching wordpress solution in face of W3TC is already actively deployed among many major wordpress powered websites, to name a few:
stevesouders.com, mattcutts.com, mashable.com
I gave a try W3 Total Cache and was amazed about the rich caching functionality it provides. Having the W3TC plugin installed adds a whole menu on the left wordpress admin panel reading Performance , clicking on it shows a menu with thorough choices on numerous things which deal with the running of wordpress on the server.
Here is a screenshot on the menus W3 Total Cache provides:

The plugin has support for html caching, sql caching, CDN, CSS and Javascript compress & minify etc.
To test the plugin adequately I disabled HyperCache and Db Cache . My observations is that with W3TC wordpress renders php and the overall user experience and download times in wordpress are better. Therefore I'll probably use only W3 Total Cache as a cacher for wordpress installs.
Besides that I had some issues on some wordpress based websites with the Db Cache SQL caching.
On these websites after enabling Db Cache, suddenly page edditing of the created existing pages started returning empty pages. This could be due to the fact that these wordpress based websites was customly tailered and many code was wiped out, however it could also be a Db Cache bug. So to conclude W3TC is the perfect solution for wordpress caching
Tags: amp, blog, cacher, CDN, choices, com, comI, download, experience, face, geeks, Javascript, left, mashable, menus, minify, page, panel, perfect solution, performance, php, plugin, question, reading, reading performance, running, screenshot, solution, use, user experience, Wordpress
Posted in SEO, Various, Web and CMS, Wordpress | 4 Comments »
Wednesday, July 13th, 2011
One server with a broken Raid array was having troubles with it’s software raid.
I tried to scan the raid array via a rescue cd like so:
server:~# mdadm --assemble --scan /dev/md1
just to be suprised by the message:
mdadm: /dev/md1 assembled from 2 drives – not enough to start the array.
In /proc/mdstat respectively the raid was showing inactive, e.g.:
server:~# cat /proc/mdstat
Personalities : [raid10] [raid1]
md1 : inactive sda2[0] sdc2[2] sdb2[1]
12024384 blocks
Respectively trying to activate the software Linux raid array with:
server:~# mdadm -A -s
Couldn’t be completed because of the same annoying error:
/dev/md1 assembled from 2 drives – not enough to start the array.
Thanksfully finally thanks to some Russian, who posted having same issues reported to be able to active his software RAID with mdadm’s –force option.
Thus enabling the problematic RAID 5 array was possible with:
server:~# mdadm -A -s --force
This solution of course is temporary and will have to further check what’s wrong with the array, however at least now I can chroot to the server’s / directory.
Tags: annoying error, cat, check, course, dev, drive, ERROR, force option, Linux, md1, mdstat, option, Personalities, proc, Raid, raid 5 array, raid array, rescue, rescue cd, sCould, sda, sdb, sdc, software, software linux, software raid, solution, Thanksfully, way
Posted in Linux, System Administration | No Comments »
Saturday, July 9th, 2011
I’m currently writting a script which is supposed to be adding new crontab jobs and do a bunch of other mambo jambo.
By so far I’ve been aware of only one way to add a cronjob non-interactively like so:
linux:~# echo '*/5 * * * * /root/myscript.sh' | crontab -
Though using the | crontab - would work it has one major pitfall, I did completely forgot | crontab - OVERWRITES CURRENT CRONTAB! with the crontab passed by with the echo command.
One must be extremely careful if he decides to use the above example as you might loose your crontab definitions permanently!
Thanksfully it seems there is another way to add crontabs non interactively via a script, as I couldn’t find any good blog which explained something different from the classical example with pipe to crontab -, I dropped by in the good old irc.freenode.net to consult the bash gurus there
So I entered irc and asked the question how can I add a crontab via bash shell script without overwritting my old existing crontab definitions less than a minute later one guy with a nickname geirha was kind enough to explain me how to get around the annoying overwridding.
The solution to the ovewrite was expected, first you use crontab to dump current crontab lines to a file and then you append the new cron job as a new record in the file and finally you ask the crontab program to read and insert the crontab definitions from the newly created files.
So here is the exact code one could run inside a script to include new crontab jobs, next to the already present ones:
linux:~# crontab -l > file; echo '*/5 * * * * /root/myscript.sh >/dev/null 2>&1' >> file; crontab file
The above definition as you could read would make the new record of */5 * * * * /root/myscript.sh >/dev/null be added next to the existing crontab scheduled jobs.
Now I’ll continue with my scripting, in the mean time I hope this will be of use to someone out there
Tags: bash scripts, bash shell script, blog, classical example, cron, cron job, cron jobs, crontab, definitions, dev, echo, echo 5, echo command, exact code, file, fileThe, gurus, irc, jambo, kind, line, Linux, mambo jambo, mean time, minute, nbsp nbsp nbsp nbsp nbsp, nickname, ovewrite, pipe, pitfall, root, scripting, Shell, solution, someone, Thanksfully, time, use, way
Posted in Linux, System Administration | 7 Comments »
Tuesday, May 31st, 2011
This content editor is really awesome compared to the default editor TinyMCE. If you want to have an options rich content editor for Joomla, then this is the one for you
download JCE Content Editor here
After installing the JCE Joomla content editor in order to enable it as a default editor you need to go to the following location:
Site -> Global Configuration -> Default WYSIWYG Editor
There place on Editor TinyMCE and change it with Editor – JCE
Now go to edit some article, and you will see the difference in the editor
7. Add gallery Joomla capabilities with sigplus (Image Gallery Plus) and Very Simple Image Gallery
sigplus Image Gallery Plus is a straightforward way to add image or photo galleries to a Joomla article with a simple syntax. It takes a matter of minutes to set up a gallery but those who are looking for a powerful gallery solution will not be disappointed either: sigplus is suitable for both beginner and advanced users.
Tags: beginner, capabilities, Configuration, content, content editor, default editor, download, EditorThere, gallery, Global, global configuration, Image, image gallery, JCE, location, location site, matter, matter of minutes, nbsp, order, photo, photo galleries, place, Plus, site, solution, syntax, TinyMCE, way, WYSIWYG
Posted in Joomla, Various, Web and CMS | No Comments »
Wednesday, April 27th, 2011
I just completed a fresh Ubuntu 10.10 Maverick-Merkaat install.
Following the installation I used a small script to install a bunch of packages I used on the same notebook before the Ubuntu re-installation.
Now after the number of packages are installed on the newly installed Ubuntu, everytime I login with any GNOME user account I get mail notification settings window to automatically start-up
Closing on every gnome login session the mail settings is not a pleasent experience, therefore I took a bit of seconds to find out what launches the New Mail pop-up window
Here is how the annoying window looks like everytime I login on my ubuntu:

Some of the text on the above screenshot is in Bulgarian as the default configured locale for this Ubuntu install is set to Bulgarian but I hope this doesn’t matter as other people who have the same popup can still recognize the window.
Now to find out the process which spawned the mail notification popup I issued:
root@ubuntu:~# ps ax |grep -i mail 2651 pts/1 Sl+ 0:01 mail-notification --sm-disable
Further on I checked what is the original location of mail notification command :
root@ubuntu:~# which mail-notification
/usr/bin/mail-notification
To be absolutely sure mail-notification does spawn the mail settings window I used pkill -9 mail-notification
As the window suddenly died now I was absolutely sure that mail-notification is spawning the unwanted pop-up window which appeared right after me logging in.
I used dpkg -S to check which package does the mail-notification program belong to as I thought that the solution to get rid of this annoying popup will come to removing the whole package, here is what I did:
root@ubuntu:~# dpkg -S /usr/bin/mail-notification
mail-notification: /usr/bin/mail-notification
root@ubuntu:~#
Now knowing the package I simply wiped it off:
root@ubuntu:~# apt-get remove --yes mail-notification
...
root@ubuntu:~# dpkg --purge mail-notification
...
After that I guarantee you you won’t see the irritating new mail settings pop-up window again.
Farewell mail-notification annoyance, hope to never see you again!!!
Tags: annoyance, annoying popup, annoying window, command, dpkg, experience, Farewell, Gnome, gnome user, grep, installation, locale, location, login, mail notification program, mail pop, mail settings, maverick, new mail, notebook, notification, notification settings, ome, package, pkill, pleasent experience, pop up window, popup, purge, root, screenshot, settings window, solution, Ubuntu, usr, usr bin
Posted in Linux, Linux and FreeBSD Desktop | No Comments »
Wednesday, April 20th, 2011
After some upgrades of Ubuntu from 9.10 to Ubuntu 10.04.2, I faced problems during apt-get upgrade && apt-get dist-upgrade
I had to fix it up with apt-get upgrade -f , however the "fix" which was targetting a fix up to the apt-get dist-upgrade removed about 260 packages, among which were the grub boot loader , xorg-server and even gnome
As in order to fix the package mishap the apt-get update -f was my only possible solution I went by and confirmed that I would like to wipe out all the packages.
Logically afterwards it was required that I install my missing xorg-server and gnome in order to make the Ubuntu desktop work again.
Here is how:
ubuntu:~# apt-get update && apt-get xorg-server ubuntu-desktop
The ubuntu-desktop is a meta package which installs the GNOME environment.
Tags: amp, boot, Desktop, desktop work, environment, fix, Gnome, gnome environment, grub, grub boot loader, loader, Logically, LTS, Lucid, meta, meta package, mishap, order, package, possible solution, server, solution, Ubuntu, update, upgrade, work
Posted in Gnome, Linux and FreeBSD Desktop | 2 Comments »