Archive for March, 2009
How to change SSHD port
by z3n on Mar.30, 2009, under Linux Happyness
Problem:
how to change sshd port in order to avoid script kiddies attacks and lower your cpu usage (brute force password attacks)
Solution:
vi /etc/ssh/sshd_config
change Port XX value
service sshd restart
Now you should test ssh with the new port, i don’t need to say that you shouldn’t disconnect the first session in case something goes wrong.
If the ssh don’t work for you on the new port you probably got selinux rule for the ssh enabled, to check try this:
semanage port -l | grep ssh
if you have the selinux rule enabled for ssh, this command will return this:
ssh_port_t tcp 22
now we should add a new rule (since it’s impossible to remove the default one) for the ssh, allow it to listen on a different port of your choice:
semanage port -a -t ssh_port_t -p tcp ####
where #### is the port you configurated for sshd (doh!)
then now all you have to do is restart sshd and done!
Server Ping Script v1.2
by z3n on Mar.27, 2009, under Coding
Problem:
How know if a server is up and if each of it’s needed services (httpd, mysql, ftp etc) are working?
Solution:
A php script that check the ports you want and report it back to you by email when the server is down and when it gets backup.
This is a new version of my old ping script, it’s been tunned and now allows you to warn multiple emails when something goes wrong. It also fixes the issue with port flood (when there’s too little servers to check)
Please note that you are supposed to run this on a stable server with a good connection, otherwise it will generate useless status. If you insist in running it on your home connection, give a tune up on the variables by raising the timeout values.
Batch Getting Movie File Information (PHP + MySQL + FFMpeg)
by z3n on Mar.27, 2009, under Coding
Problem:
Sorting movies is a really boring process, specially when you can’t get their sizes (height x width) and length automatically.
Solution:
A php script that gets movies sizes, length, filesize, name, adds it to a mysql table for futher processing.
* You will need FFmpeg on your %PATH%
* Check source to know how to make a compatible table
Usage: mi.php <folder> [recursive 0|1]
(recursive folders is enabled by default)
PHP to extract and delete compressed files (rar/zip)
by z3n on Mar.11, 2009, under Coding
Problem:
After downloading massive stuff on the internet you need to do the boring process of extracting then deleting the compressed files from multiple folders etc etc
Solution:
A php script that extract all rar/zip files into all subfolders from the root folder you specify.
How to use:
on prompt:
php x.php /path/to/folder
if you are on windows it’s recommended that you put x.php on a folder before the ones you want to process, or at least into the same drive letter.
Note: Must have php_zip and php_rar libraries enabled on your php.ini
Note2: Apparetly there’s a bug on the php_rar library, even if i close the handler or even unset the object, the last file of a rar archive keeps being used, meaning that script can’t delete it, so you need to do it manually (you will need to wait the script finish uncompressing of all the subfolders before deleting).
Fix Japanese File Name on Linux
by z3n on Mar.06, 2009, under Linux Happyness
Problem:
Japanese filenames are screwed up on linux, when you try to copy them to windows their encoding is different. Or when you write them on linux and want to use on a windows machine or even by http or ftp they are all wrong.
Solution:
Apart from all the encoding mess, apparently linux encodes filenames as UTF-16 which is different from windows’ UTF-8 default, i say apparently because all the programs i used to test the charset on the linux stated that it was UTF-8 actually, which contradicts all the sites about linux’s default charset being UTF-16 … but this is just lame, basically what you need to do is convert the file names to Shift_JIS which is the most compatible format for windows, i wrote a php script to fix a folder or even the whole tree if you want. the source:
http://www.overflow.biz/blog/~scripts/convert2shift_jis.phps
by default this script will only rename the files it’s into, but you can easly tune it up to rename everything.
Fedora + VNC Server + Wine + Perfect Dark p2p
by z3n on Mar.05, 2009, under Linux Happyness
Problem:
Run perfect dark on a remote fedora/linux server
Solution:
You need to install a vncserver and wine (to emulate windows),
yum install wine-tools wine-capi wine-core wiwine-nas wine-twain wine-nas wine-cms wine-jack wine-ldap wine vnc-server vnc
then you configure the user(s) who will use the vnc server here:
vi /etc/sysconfig/vncservers
VNCSERVERS=”2:your_happy_user_name”
VNCSERVERARGS[2]=”-geometry 800×600 -nohttpd”
(note that the number 2 matches, if you need to add more users just change the array, note that when you connect you will need to change the display to match this number as well)
after that you need to configure the vncserver password on your user (do this logged as the user you will use on vnc) — the command is vncpasswd
alright now you’re ready to start the vnc server, you can either put it to start automatically or do it manually, i like it manually so know when it’s up:
service vncserver start
now on your client machine you open the vncviewer and connect to your server, remember that number 2 on the config file? it’s the display number, so you gonna connect to : example.com:2
there you go, now you just need to place perfect dark on your “drive_c” folder , which is at ~/.wine/drive_c/ then start it, by
cd ~/.wine/drive_c/Perfect_Dark/;wine ./perfect \dark.exe
don’t forget to configure your folders and the firewall. to view the japanese fonts you need to edit the visual.txt (if you don’t have it at mutagen folder, go on perfect dark options and click on generate mutagen) on visual.txt you will need to change:
“default font” = “MS Pゴシック”
“eye font” = “MS Pゴシック”
MS Pゴシック is the best font for perfect dark, it don’t get blurry or too small, however if you don’t have it you can use MS PGothic, which gets blurry but it’s readable.
if “MS Pゴシック” don’t work for you use “MS PGothic” instead, don’t forget that you need to upload the file msgothic.ttc (from your windows fonts) to ~/.wine/drive_c/windows/fonts/
this visual.txt is also in utf-16, so get yourself a good editor.
that’s it, also a last note, if you open perfect dark and it says “connected but port not open” even if you know you’re not behind a firewall, do this:
go settings and change the ports to a different number and press ok
magic! it’s working!!!
hahahah