Tuesday, October 8, 2013

How to log Script Filename of Emails Sent by PHP Mail() Function to Detect Spam

Today I faced a server that seemed to was abused by some spammers.
I spent 6 hours to find a solution about how to Log mails and mail sender scripts in php...
Finally found that the PHP > 5.3 has the feature itself!!

Just enable "mail.log" in your php configuration and It will log each mail and the script which sends it...

It's also recommended to enable "mail.add_x_header", It'll make it easier to address spam complaints sent  from your servers...

Thursday, August 29, 2013

FSI error with Ansys Fluent or CFX

If you're getting one of the following errors while performing a FSI ( Fluid structure interaction ) simulation using ansys
Fluent coupling error :
 +====================================================================+
 |                      System Coupling Exception                     |
 +====================================================================+
 | Origin            : Transient Structural (Solution)                |
 | Error Code        : 2                                              |
 | Error Description :                                                |
 |    One or more elements have become highly distorted.  Excessive   |
 |   distortion of elements is usually a symptom indicating the need  |
 |   for corrective action elsewhere.  Try ramping the load up        |
 |   instead of step applying the load (KBC,1).                       |
 +====================================================================+

CFX coupling error :
 +--------------------------------------------------------------------+
 | ERROR #001100279 has occurred in subroutine ErrAction.             |
 | Message:                                                           |
 | CFX encountered the error: Read.  Fatal error occurred when reque- |
 | sting Total Mesh Displacement for FSI.                             |
 |                                                                    |
 |                                                                    |
 |                                                                    |
 |                                                                    |
 +--------------------------------------------------------------------+

This may occur if your solid is largely deforming at the very first step under your fluid pressure.
Remember that fluent has an operation pressure, cfx has a reference pressure too. All pressures you define are relative to this reference pressure. So it may cause a pressure increase in your model and cause a huge displacement resulting the above error.
Another reason might be if you're defining velocity inlet in wrong pressure. For example consider a pipe with X axis. Now if you wrongly define the velocity inlet toward Y or Z instead of X axis, the reduction in velocity at wall locations will cause a high pressure increase and same story.

Mos

Thursday, August 22, 2013

Fluent FSI Error : Unassigned interface zone detected for interface 6.

If you're trying to perform a FSI simulation using Ansys Fluent & Mechanical and getting the following error when you click on "Check Mesh" :

WARNING: Unassigned interface zone detected for interface 6.

WARNING: Mesh check failed.

To get more detailed information about the mesh check failure
increase the mesh check verbosity via the TUI command
/mesh/check-verbosity.

The reason of the above error is that type of BC which is set for your FSI interface is set to "Interface" while it should be "Wall" with an applied dynamic mesh on it...

Monday, August 19, 2013

Adina systems : ***INPUT ERROR: No node found in BCD X

This is my first Mechanical Engineering Post !

I was working with Adina systems FEM software performing a FSI simulation (Fluid Structure Interaction).
I received ' ***INPUT ERROR: No node found in BCD 1' when tried to generate the DATA file.

After some R&D I found that this error occurs when you've defined the FSI Boundary on wrong body ( e.g. Solid body instead of Fluid one )

Wednesday, July 31, 2013

Installing flv and mp4 module on cpanel apache 2

Well, If you're going to use flv or mp4 videos on your websites hosted on cpanel server, you will probably need this :

put the following codes into /scripts/after_apache_make_install :
cd /usr/local/src
wget http://people.apache.org/~pquerna/modules/mod_flvx.c
/usr/local/apache/bin/apxs -i -c mod_flvx.c

wget http://h264.code-shop.com/download/apache_mod_h264_streaming-2.2.7.tar.gz
tar -zxvf apache_mod_h264_streaming-2.2.7.tar.gz
cd /mod_h264_streaming-2.2.7
./configure --with-apxs='/usr/local/apache/bin/apxs'
make
make install
/usr/local/cpanel/bin/apache_conf_distiller --update


put the following codes into /usr/local/apache/conf/includes/pre_virtualhost_global.conf :
LoadModule h264_streaming_module modules/mod_h264_streaming.so
<IfModule mod_h264_streaming.c>
AddHandler h264-streaming.extensions .mp4
</IfModule>

LoadModule flvx_module modules/mod_flvx.so
<IfModule mod_flvx.c>
AddHandler flv-stream .flv
</IfModule>

Now, compile apache2 with EasyApache and it's on !!

Tuesday, June 11, 2013

PHP-SHELL script to whitelist IP on CSF

I needed a fast way to whitelist my IP on a linux server to be able to login to secure administration page...

I set it up by using a php file + shell file + cronjob

Now I easily open a public website address "mydomain.com/whatis.php" and it automatically whitelist my IP.

"whatis.php" PHP file code :
<?php
echo file_put_contents("/tmp/iplog",$_SERVER["REMOTE_ADDR"]);
?>


"/script/ip" Shell file code :
#!/bin/bash
i=1
while [ $i -le 10 ]
do
        status=`cat /tmp/iplog`
        if [ "$status" != "0" ]; then
                echo $status >> /etc/csf/csf.allow
                echo $status >> /etc/csf/csf.ignore
#                echo "allow from $status" >> /home/DOMAIN/public_html/admin/.htaccess
                echo "0" > /tmp/iplog
                `/etc/csf/csf.pl -r > /tmp/csf.log`
        fi
        sleep 5
        (( i++ ))
done

"/script/ip" Cronjob :
* * * * * /script/ip

Note : I tried to run `csf -r` to reset CSF firewall in shell script but it didn't work ! I don't know why. I found here that we should use `/etc/csf/csf.pl -r` instead. Thanks to that guy !!

Tuesday, June 4, 2013

Running mini_sendmail with php-fpm chroot on Centos 6 , debian 6, ...

Chrooting a website is a good security improvement on a server with multiple websites hosted.
When you set the chroot  of php-fpm you'll not be able to send mails, I fixed this using mini_sendmail. Here's the procedure:

Download and extract your OS template on chroot directory from openvz.  (Don't forget to set the file owners correctly)
Enter chroot directory and run :
chmod 0666 dev/{tty,null,zero}
echo "8.8.8.8" > etc/resolv.conf

Now compile mini_sendmail:
cd /usr/src
wget http://acme.com/software/mini_sendmail/mini_sendmail-1.3.6.tar.gz
tar -zxf mini_sendmail-1.3.6.tar.gz
cd mini_sendmail-1.3.6


If you start compiling mini_sendmail now, you'll receive the following error and mini_sendmail will not work properly :
mini_sendmail.c:(.text+0x5df): warning: Using 'getpwuid' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking

To fix that edit mini_sendmail.c and in Line #148 replace :
username = getlogin();
with
username = "USERNAME";
where USERNAME is your php-fpm user .
Now compile it :
make

and copy it to usr/sbin/sendmail
/home/USERNAME/usr/sbin/sendmail
chmod 755 /home/USERNAME/usr/sbin/sendmail
chown USERNAME:USERNAME /home/USERNAME/usr/sbin/sendmail

Notes :
- I also tested mini_sendmail on chrooted ssh user, if you don't replace username with getlogin() according to above instructions, mini_sendmail will fail to work with the following error :
mini_sendmail: can't determine username

- The following error can be ignored safely :
mini_sendmail.c:(.text+0xa47): warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking

- When I compiled mini_sendmail on debian 6 x64, It didn't work with the following error :
unexpected reloc type in static binarySegmentation fault
I tried to compile it on another OS ( centos 6, debian 6 i686 ) and copy the binary to the server, it worked...

Tuesday, April 16, 2013

building latest version of ffmpeg with x264 on Centos 6

A good tutorial has been posted here.
Here are some fixes on the above tutorial :

- You should remove ffmpeg and its libraries before you proceed to manual compilation of the program:
yum remove libvpx libogg libvorbis libtheora libx264 x264 ffmpeg
It's really important.My compilation was failed with the following error
libx264.c:552: undefined reference to `x264_encoder_open_130' 
And the reason was that I had not removed x264-libs and x264-devel packages.

-You'll receive the following error while compiling faac 1.28 library :
mpeg4ip.h:126: error: new declaration ‘char* strcasestr(const char*, const char*)’
And the fix is to remove line 126 from the file ./common/mp4v2/mpeg4ip.h :
char *strcasestr(const char *haystack, const char *needle);
 
- Compile x264 with the following parameters :
cd x264
./configure --enable-static --enable-shared


- You'll need to install libvpx to compile ffmpeg :
git clone http://git.chromium.org/webm/libvpx.git
cd libvpx
./configure
make && make install
ldconfig



That's all.

Mos

Wednesday, March 6, 2013

Install latest Wine [1.5] version on Debian

I don't know why debian loves wine v1.01 ?? an obsolete version of wine. They don't upgrade to the next stable versions. The winehq.org doesn't provide .deb packages for squeeze too.
So here's the way, I've just installed  the latest version of wine on my squeeze ! Just remember that compiling wine from source takes ~ 1h of time...

apt-get build-dep wine
cd /usr/src
wget http://downloads.sourceforge.net/project/wine/Source/wine-1.5.25.tar.bz2
tar -jxf wine-1.5.25.tar.bz2
chown -R nobody:nogroup wine-1.5.25
cd wine-1.5.25
sudo -u nobody ./configure
sudo -u nobody make
make install 

~Mos

How to disable Debian 12 sleep on production servers

 Debian 12 has power saver enabled by default which causes your server to go to sleep if there is no mouse / keyboard interaction. To resolv...