Feb 02 2010

Plesk 9: Adding a subdomain pointing to custom folder (for example, inside webroot)

Category: UncategorizedFractalizeR @ 4:31 pm

Usually, I work with CPanel. But some time ago my friend asked me to move his website to a server with Plesk installed by default. Website required domain sub.domain.com to point to a folder inside main site webroot. I surprizingly found, that with Plesk 9 it is impossible (it was ok with old versions where Plesk allowed to choose subdomain destination folder). I had to find a way to overcome that.

Continue reading “Plesk 9: Adding a subdomain pointing to custom folder (for example, inside webroot)”


Jan 09 2010

[Linux] “network unreachable resolving XXXX” messages in system log

Category: Articles, Linux administrationFractalizeR @ 3:10 pm

Some time ago I noticed many messages in log file about named attempt to resolve strange addresses.

Continue reading “[Linux] “network unreachable resolving XXXX” messages in system log”

Tags: ,


Jan 06 2010

Free opensource Symfony-friendly IDE: NetBeans 6.8

Category: Articles, PHPFractalizeR @ 8:03 pm

My search for a good PHP IDE never stops ;) My choice was Zend Studio until recently. But Zend Studio is not free and it’s free analogue – PDT – lacks some features like refactoring (PDT is also mainly developed by Zend, so, I think, Zend will always keep it low to prevent competition with Zend Studio). Also, it is monstrous (More than 300Mb installer) and it definitely lacks good Symfony support.

Recently I came across NetBeans, which is now free and developed by Sun. Sun seem to abandon all own IDE projects in favour of NetBeans, so this is a somehow strong foundation.

Oh… 25Mb installer only for PHP version ;) And… it is easy to use. Very. I would like to guide you through the creation of new symfony project in NetBeans.

Continue reading “Free opensource Symfony-friendly IDE: NetBeans 6.8″

Tags: , ,


Jan 06 2010

[JavaScript] EditArea: Realtime Syntax Highlighting JavaScript Library

Category: Articles, JavaScriptFractalizeR @ 3:19 pm

Recently, improving my WordPress plugin WP-SynHighlight, I chose EditArea as a source code editor with realtime syntax highlighting. The syntax of language description files for highlighting of EditArea is pretty much the same as Geshi has. So, I wrote a small converter and executed it over all Geshi files for 1.0.x version.

I have posted a patch for EditArea with all generated files.

So, now you can have EditArea with almost all power of supporting more than 130 languages ;)

Tags: , ,


Jan 06 2010

[JavaScript] PHP PCRE_DOT_ALL option emulation in JavaScript

Category: Articles, JavaScriptFractalizeR @ 2:06 pm

Writting my WP-SynHighlight WordPress plugin, I came to a need of parsing multilined shortcode like this:

[ codesyntax option1="optionvalue1"...] <many lines here….> [ / codesyntax]

So, I extracted regular expression to parse shortcode from WordPress source code (if you are interested in it, see /wp-includes/shortcodes.php file). This regex was executed with /s option (PCRE_DOT_ALL) which makes dot (“.”) to match newlines also. There is no such option in JavaScript for some reason and I had to replace dot by such character class:

[\S\s]

Actually, any opposite metacharacters should work. [\W\w] for example.

Quite easy, isn’t it? :)

Tags: , ,


Jan 04 2010

[Linux, PHP] PHP script to backup all databases

Category: Articles, Linux administration, PHPFractalizeR @ 1:20 am

Hello.

I’d like to share my script, which I use on some production servers for quick database backup using mysql tools. People say, that I should use bash for that, but I prefer PHP :)

Script uses mysqldump for dumping databases and gzip for compressing backups. rm is run to ensure backups are not stored for too long.

Continue reading “[Linux, PHP] PHP script to backup all databases”

Tags: , , ,


Dec 27 2009

WARNING: mismatch_cnt is not 0 on /dev/md0

Category: Articles, Linux administrationFractalizeR @ 12:37 pm

I’ve gotten cron log from one of my servers today which says:

/etc/cron.weekly/99-raid-check:
 WARNING: mismatch_cnt is not 0 on /dev/md0

That worried me a little and I decided to investigate.

Continue reading “WARNING: mismatch_cnt is not 0 on /dev/md0″

Tags: , , , ,


Dec 20 2009

Script for securing server with IPTables

Category: Articles, Linux administrationFractalizeR @ 7:31 pm

Hello.

Here is a script, which I use on my production servers to secure them a bit. I hope it will be useful to you. Script logs all dropped packets so that you can easily find out tye clutch should there be any. Additional FTP server setup will be necessary. For ProFTPD add the following line to /etc/proftpd.conf:

PassivePorts 65400 65534

Continue reading “Script for securing server with IPTables”

Tags: , , ,


Sep 08 2009

Zend Studio 7 nightmares…

Category: PHP Software Flash-ins, Software flash-insFractalizeR @ 4:25 pm

Recently I’ve downloaded Zend Studio 7 Final to try new features they promised for PHP 5.3. OMG.It seems I caught early alpha, not final by accident…

  • CodeAssist doesn’t show completion variants for variables
  • PHPUnit always tries to generate test files near testing .php file (but it seems, it’s a general behavior which I don’t like)
  • PHPUnit cannot handle namespaced classes! This is the code it generated for one of my classes:
<?php
 
require_once 'System\Core\Autoload\StructuredAutoloader.php';
 
require_once 'PHPUnit\Framework\TestCase.php';
 
/**
 * Core\Autoload test case.
 */
class AutoloadTest extends PHPUnit_Framework_TestCase
{
 
 /**
 * @var Core\Autoload
 */
 private $Core
\Autoload;
 
 /**
 * Prepares the environment before running a test.
 */
 protected function setUp()
 {
 parent::setUp();
 
 // TODO Auto-generated AutoloadTest::setUp()
 
 $this->Core\Autoload = new Core\Autoload(/* parameters */);
 
 }
 
 /**
 * Cleans up the environment after running a test.
 */
 protected function tearDown()
 {
 // TODO Auto-generated AutoloadTest::tearDown()
 
 $this->Core\Autoload = null;
 
 parent::tearDown();
 }
 
 /**
 * Constructs the test case.
 */
 public function __construct()
 {
 // TODO Auto-generated constructor
 }
 
}

I am publishing it as-is. The whole code is broken as if Zend Studio doesn’t know about 5.3 namespacing at all! My god… And this is a final release… No, better I will go PDT… Why paying money for non-working things?

  • After saving a file it sometimes drops “An error has occurred. See error log for more details. Widget is disposed” message.
  • Analyzer hung on analyzing Smarty.php class file from 2.6.x.
<?php

require_once ‘System\Core\Autoload\StructuredAutoloader.php’;

require_once ‘PHPUnit\Framework\TestCase.php’;

/**
* Core\Autoload test case.
*/
class AutoloadTest extends PHPUnit_Framework_TestCase
{

/**
* @var Core\Autoload
*/
private $Core
\Autoload;

/**
* Prepares the environment before running a test.
*/
protected function setUp()
{
parent::setUp();

// TODO Auto-generated AutoloadTest::setUp()

$this->Core\Autoload = new Core\Autoload(/* parameters */);

}

/**
* Cleans up the environment after running a test.
*/
protected function tearDown()
{
// TODO Auto-generated AutoloadTest::tearDown()

$this->Core\Autoload = null;

parent::tearDown();
}

/**
* Constructs the test case.
*/
public function __construct()
{
// TODO Auto-generated constructor
}

}

Tags: , , ,


Jul 03 2009

PHP Array of ISO 639-1 language codes => names.

Category: Code snippets, PHPFractalizeR @ 4:43 pm

Hello. For purposes of writting scripts for converting data formats, I have constructed an array, that can be used to replace language codes by their names.

Continue reading “PHP Array of ISO 639-1 language codes => names.”

Tags: , , , ,


Jul 01 2009

[Linux, FreeBSD] Small Anti-DDOS Shell Script for FreeBSD

Category: Articles, Linux administrationFractalizeR @ 3:21 pm

Struggling with DDoS on my friend’s site, I wrote small Anti-DDoS script, that in original just lists all IPs, that have more than X active connections open to your server. It was originally written for FreeBSD.

#!/bin/sh
# Set here a minimum number of connections for action to be executed (150 by default).
FR_MIN_CONN=150
TMP_PREFIX='/tmp/frrr'
TMP_FILE=`mktemp $TMP_PREFIX.XXXXXXXX`
netstat -ntu -f inet| awk '{if(NR>2 && NF=6) print $5}' | cut -d. -f1-4 | grep '^[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}$' | sort | uniq -c | sort -nr > $TMP_FILE
while read line; do
 CURR_LINE_CONN=$(echo $line | cut -d" " -f1)
 CURR_LINE_IP=$(echo $line | cut -d" " -f2)
 if [ $CURR_LINE_CONN -lt $FR_MIN_CONN ]; then
 break
 fi
 
 # You can insert your own logic here (e.g. ban with your favourite firewall). Now it just prints the IP to console.
 echo $CURR_LINE_IP
done < $TMP_FILE
rm -f $TMP_PREFIX.*

I think this will work on general Linux also. You just need to change “cut -d.” to “cut -d:” in the listing and, probably, “/bin/sh” to “/bin/bash”.

Tags: , ,


Jul 01 2009

[Linux, FreeBSD] Using netstat and ipfw to manually detect and blacklist DOSers on FreeBSD

Category: Articles, Linux administrationFractalizeR @ 1:22 pm

This is just an addition to my this article with some corrections needed if you use FreeBSD.

netstat command should look like

netstat -ntu -f inet| awk '{print $5}' | cut -d. -f1-4 | sort | uniq -c | sort -nr|more

And firewall IP blocking command should be

ipfw add deny all from xxx.xxx.xxx.xxx to any in

Tags: , , ,


Jun 25 2009

[Linux] Automated RPMForge Repository Installation

Category: Articles, Linux administrationFractalizeR @ 12:28 pm

Actually, I am using CentOS on production servers. CentOS native repository is very small and contains very necessary packages. If you need something more, you should consider using RPMForge repository as I do ;) But to add this repository to CentOS you need to do several annoying actions. And this is annoyng when you do so on each new server you are asked to setup. So, I wrote small script to automate the job which I like to share with you now.

Continue reading “[Linux] Automated RPMForge Repository Installation”

Tags: , , , ,


Jun 01 2009

[Solution] Apache: No space left on device: Couldn’t create accept lock

Category: Articles, Linux administrationFractalizeR @ 3:31 pm

My friend asked me to check the server with this problem. I did and of course first I checked free space on disk using ‘df -h’, but free space was ok. Googling around I found the reason. Unclean shutdown of Apache left many semaphores opened. So, I cleaned them with

for i in `ipcs -s | awk '/nobody/ {print $2}'`; do (ipcrm -s $i); done

You should replace “nobody” in the command with the name of the user Apache is running on your system under. Also I increased semaphore limit in /etc/sysctl.conf by adding to the end of this file

kernel.msgmni = 1024
kernel.sem = 250 256000 32 1024

No system restart is needed to apply changes. Just issue 'sysctl -p‘ command. The solution was found here.

You may also want to switch to another SSLMutex implementation.

Tags:


Sep 19 2008

[Misc] A guide to effective forum administration v.0.9

Category: Articles, Miscellaneous, VBulletinFractalizeR @ 5:14 pm

Introduction
Being a forum administrator/moderator on several forums I would like to share my opinions on how a good forum should be organized and administrated.

Continue reading “[Misc] A guide to effective forum administration v.0.9″

Tags:


Aug 27 2008

[PHP] PHP Quine

Category: Articles, PHPFractalizeR @ 4:28 pm

Browing internet, I found the term of “quine” which is the program, that prints it’s exact source code. I was curious, if I am able to write such software. This is what I was able to compose:

<?php
$u='$';
$q="'";
$qq='"';
$s='<?php';
$e='?>';
$w='eval($p);';
$p='echo"$s\r\n{$u}u=$q$u$q;\r\n{$u}q=$qq$q$qq;\r\n{$u}qq=$q$qq$q;\r\n{$u}s=$q$s$q;\r\n{$u}e=$q$e$q;\r\n{$u}w=$q$w$q;\r\n{$u}p=$q$p$q;\r\n$w";';
eval($p);

It is a small and quite simple quine, however, I spent about several hours understanding how quines work and how to write them in PHP :)

Tags: ,


Aug 25 2008

[PHP, MySQL] Batch changing charset and collation on databases

Category: Articles, MySQL, PHPFractalizeR @ 11:51 pm

Recently I needed to quickly change charset on all tables and change each field’s chanset in each table in a specific database to latin1 and collation to latin1_swedish_ci. I googled a little and found this solution by shimon doodkin. I used it and it did work, but also it attempted to change charset at MySQL information_schema system database which is something I didn’t want to. It also proceessed all databases at MySQL server. Luckily, there was only two :) It was a test server, that’s why I was uncareful.

Ok. I wrote a bit more elegant solution I would like to share with you today. It is pretty self-explanatory and is based on ALTER TABLE CONVERT TO charset MySQL statement.

Continue reading “[PHP, MySQL] Batch changing charset and collation on databases”

Tags: , , , , ,


Aug 24 2008

[Linux] Installing latest Apache, PHP and MySQL from sources

Category: Articles, Linux administrationFractalizeR @ 12:48 am

As you probably know, latest software versions are rarely available to be installed as rpms. So, you need to compile them yourself. In this article I will briefly describe a process of installing, configuring and  upgrading latest Apache and PHP.

Please remember, that installing from sources can sometimes break working system. So, please use this guide carefully.

Continue reading “[Linux] Installing latest Apache, PHP and MySQL from sources”

Tags: , , , , ,


Aug 21 2008

[Linux] Installing YUM (Yellow dog Updater, Modified)

Category: Articles, Linux administrationFractalizeR @ 4:46 pm

YUM is an rpm package manager with very easy syntax. It is preferred especially for beginners to install packages using yum as this is very easy. Your Linux distro should already have yum by default, but if this is not so, let’s install it. BTW, you can find yum manual here.

You can check if your system has yum by entering

  • yum –help

Continue reading “[Linux] Installing YUM (Yellow dog Updater, Modified)”

Tags: ,


Aug 18 2008

[PHP] Writting Custom Class Autoloader Using SPL

Category: Articles, PHPFractalizeR @ 1:11 am

My approach to writting mid-to-huge applications is to put each class to separate file and autoload class files on demand to eliminate the use of include/require statements completely. Autoloading in some cases can even speed up your project (for example, my scripts rarely throw exceptions. Exception classes are loaded by demand and only in case exception happend, so I remove

<?php
require_once('DatabaseException.php');
require_once('UserBOException.php);

overhead from my project. However, writting a good universal autoloader class is not trivial, however, simple. In this article I would like to suggest my own lightweigh multifunctional autoloader class.

Continue reading “[PHP] Writting Custom Class Autoloader Using SPL”

Tags: , , ,


Next Page »