Thursday, May 24, 2012

IPCop :: block facebook hhpd - altenative

from http://gateway.hacker.my/2011/02/blocking-https-facebook-using-ipcop/
As we know, Squid’s transparent proxy cannot filter https traffic, but we can block it using iptables. Here are some tricks how to block https traffic from Facebook using IPcop version 1.9.x.

The easiest way to block Facebook’s https traffic is by blocking its IP range. You don’t have to find the specific IP for Facebook to block it. As we know, Facebook has a lot of public IP addresses.

– SNIP

1. From the IPcop gui-menu, go to Firewall –> Addresses

2. Put Name, Address format (make sure you choose IP here), Address and Netmask.

3. Here is the tricky part. For the Address and Netmask, put these IP addresses.
 
69.63.176.0/255.255.240.0
66.220.144.0/255.255.240.0
204.15.20.0/255.255.240.0

4. From the whois information, you can see at least this range belongs to Facebook.com
 
bsd@genetics:~$ whois 204.15.20.0
#
# Query terms are ambiguous.  The query is assumed to be:
#     "n 204.15.20.0"
#
# Use "?" to get help.
#
 
#
# The following results may also be obtained via:
# http://whois.arin.net/rest/nets;q=204.15.20.0?showDetails=true&showARIN=false
#
 
NetRange:       204.15.20.0 - 204.15.23.255
CIDR:           204.15.20.0/22
OriginAS:       AS32934
NetName:        TFBNET1
NetHandle:      NET-204-15-20-0-1
Parent:         NET-204-0-0-0-0
NetType:        Direct Assignment
NameServer:     NS5.FACEBOOK.COM
NameServer:     NS4.FACEBOOK.COM
NameServer:     NS3.FACEBOOK.COM
Comment:        Contact abuse@facebook.com with issues.
RegDate:        2005-08-08
Updated:        2010-07-08
Ref:            http://whois.arin.net/rest/net/NET-204-15-20-0-1
 
OrgName:        Facebook, Inc.
OrgId:          THEFA-3
Address:        1601 S. California Ave
City:           Palo Alto
StateProv:      CA
PostalCode:     94304
Country:        US
RegDate:        2004-08-11
Updated:        2010-04-09
Ref:            http://whois.arin.net/rest/org/THEFA-3
 
OrgTechHandle: OPERA82-ARIN
OrgTechName:   Operations
OrgTechPhone:  +1-650-543-4800
OrgTechEmail:  domain@facebook.com
OrgTechRef:    http://whois.arin.net/rest/poc/OPERA82-ARIN
 
RTechHandle: OPERA82-ARIN
RTechName:   Operations
RTechPhone:  +1-650-543-4800
RTechEmail:  domain@facebook.com
RTechRef:    http://whois.arin.net/rest/poc/OPERA82-ARIN
 
RAbuseHandle: OPERA82-ARIN
RAbuseName:   Operations
RAbusePhone:  +1-650-543-4800
RAbuseEmail:  domain@facebook.com
RAbuseRef:    http://whois.arin.net/rest/poc/OPERA82-ARIN
 
RNOCHandle: OPERA82-ARIN
RNOCName:   Operations
RNOCPhone:  +1-650-543-4800
RNOCEmail:  domain@facebook.com
RNOCRef:    http://whois.arin.net/rest/poc/OPERA82-ARIN
 
#
# ARIN WHOIS data and services are subject to the Terms of Use
# available at: https://www.arin.net/whois_tou.html
#
 
bsd@genetics:~$

5. Then proceed to Firewall –> Address Groups, create new Address Group Name (e.g Facebook), then select Custom Addresses inside that group.

6. Next, proceed to Firewall Rules –> Outgoing Traffic, then configure your firewall as below :
 
Default networks = Green Networks
Destination --> Address Groups -->Facebook
Tick Use Service --> Default Services --> https (443)
Additional --> Tick Rule enabled, Rule Action -->Drop, Remark -->Facebook https blocked
Click Save

7. Make sure these rules stay above any other rules.

8.  After this, point your browser at https://www.facebook.com. If you have understood and done things right, you should be unable to open https Facebook and get a timeout message.

MS Visual Studio

MS Visual Studio
Version history

Prior to Visual Studio Version 4.0 there were Visual Basic 3, Visual C++, Visual FoxPro and Visual SourceSafe as separate products.
Product name  Codename  Internal
version  Supported .NET
Framework versions  Release date
Visual Studio  N/A  4.0  N/A  1995-04
Visual Studio 97  Boston  5.0  N/A  1997-02
Visual Studio 6.0  Aspen  6.0  N/A  1998-06
Visual Studio .NET (2002)  Rainier  7.0  1.0  2002-02-13
Visual Studio .NET 2003  Everett  7.1  1.1  2003-04-24
Visual Studio 2005  Whidbey  8.0  2.0  2005-11-07
Visual Studio 2008  Orcas  9.0  2.0, 3.0, 3.5  2007-11-19
Visual Studio 2010  Dev10/Rosario  10.0  2.0, 3.0, 3.5, 4.0  2010-04-12

from : http://en.wikipedia.org/wiki/Microsoft_Visual_Studio

Monday, May 21, 2012

Tuesday, May 15, 2012

Ubuntu


Choose to be a pirate or choose to liberate!




upgrade ubuntu
do-release-upgrade --proposed
do-release-upgrade -d
update-manager -d
lsb_release -a

altenative
sed -i 's/oneiric/precise/g' /etc/apt/sources.list
apt-get update
apt-get dist-upgrade
apt-get upgrade


Monday, May 14, 2012

PHP

Display file size (Byte, MB,...)
 0.9){
        $filesize = $filesize / $decr;
        $step++;
    }
    return round($filesize,2).' '.$prefix[$step];
    } else {

    return 'NaN';
    }
  
}
?>
ftp

Upload image to database
////
/*

$result[name]
"; } ?> //// //// "; ?> */
Download image
            $filename = 'dummy.zip';
            $filename = realpath($filename);

            $file_extension = strtolower(substr(strrchr($filename,"."),1));

            switch ($file_extension) {
                case "pdf": $ctype="application/pdf"; break;
                case "exe": $ctype="application/octet-stream"; break;
                case "zip": $ctype="application/zip"; break;
                case "doc": $ctype="application/msword"; break;
                case "xls": $ctype="application/vnd.ms-excel"; break;
                case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
                case "gif": $ctype="image/gif"; break;
                case "png": $ctype="image/png"; break;
                case "jpe": case "jpeg":
                case "jpg": $ctype="image/jpg"; break;
                default: $ctype="application/force-download";
            }

            if (!file_exists($filename)) {
                die("NO FILE HERE");
            }

            header("Pragma: public");
            header("Expires: 0");
            header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
            header("Cache-Control: private",false);
            header("Content-Type: $ctype");
            header("Content-Disposition: attachment; filename=\"".basename($filename)."\";");
            header("Content-Transfer-Encoding: binary");
            header("Content-Length: ".@filesize($filename));
            set_time_limit(0);
            @readfile("$filename") or die("File not found.");
Upload image w/ YUI pgrogress bar
















 

Linux - environment

set date format to specific format :
vi /etc/environment
add the below setting
TIME_STYLE='+%Y-%m-%d %H:%M'
save & test :
drwxr-xr-x  2 fadabi fadabi  4096 2012-05-09 15:21 Music

Sunday, May 13, 2012

Linux common command

tar :
tar xvzf file-1.0.tar.gz - for uncompress a gzip tar file (.tgz or .tar.gz)
tar xvjf file-1.0.tar.bz2 - for uncompress a bzip2 tar file (.tbz or .tar.bz2)
tar xvf file-1.0.tar - for uncompressed tar file (.tar)

linux user:
groupadd developers
useradd -G developers vivek
passwd vivek
id vivek
useradd -G admins,ftp,www,developers jerry
useradd -g developers tony
usermod -a -G ftp tony
usermod -g www tony
usermod -s /sbin/nologin vivek
userdel vivek


'du' - Finding the size of a directory

$ du
Typing the above at the prompt gives you a list of directories that exist in the current directory along with their sizes. The last line of the output gives you the total size of the current directory including its subdirectories. The size given includes the sizes of the files and the directories that exist in the current directory as well as all of its subdirectories. Note that by default the sizes given are in kilobytes.


$ du /home/david
The above command would give you the directory size of the directory /home/david


$ du -h
This command gives you a better output than the default one. The option '-h' stands for human readable format. So the sizes of the files / directories are this time suffixed with a 'k' if its kilobytes and 'M' if its Megabytes and 'G' if its Gigabytes.


$ du -ah
This command would display in its output, not only the directories but also all the files that are present in the current directory. Note that 'du' always counts all files and directories while giving the final size in the last line. But the '-a' displays the filenames along with the directory names in the output. '-h' is once again human readable format.


$ du -c
This gives you a grand total as the last line of the output. So if your directory occupies 30MB the last 2 lines of the output would be

30M .
30M total

The first line would be the default last line of the 'du' output indicating the total size of the directory and another line displaying the same size, followed by the string 'total'. This is helpful in case you this command along with the grep command to only display the final total size of a directory as shown below.


$ du -ch | grep total
This would have only one line in its output that displays the total size of the current directory including all the subdirectories.

Note : In case you are not familiar with pipes (which makes the above command possible) refer to Article No. 24 . Also grep is one of the most important commands in Unix. Refer to Article No. 25 to know more about grep.


$ du -s
This displays a summary of the directory size. It is the simplest way to know the total size of the current directory.


$ du -S
This would display the size of the current directory excluding the size of the subdirectories that exist within that directory. So it basically shows you the total size of all the files that exist in the current directory.


$ du --exculde=mp3
The above command would display the size of the current directory along with all its subdirectories, but it would exclude all the files having the given pattern present in their filenames. Thus in the above case if there happens to be any mp3 files within the current directory or any of its subdirectories, their size would not be included while calculating the total directory size.

-

'df' - finding the disk free space / disk usage

$ df
Typing the above, outputs a table consisting of 6 columns. All the columns are very easy to understand. Remember that the 'Size', 'Used' and 'Avail' columns use kilobytes as the unit. The 'Use%' column shows the usage as a percentage which is also very useful.


$ df -h
Displays the same output as the previous command but the '-h' indicates human readable format. Hence instead of kilobytes as the unit the output would have 'M' for Megabytes and 'G' for Gigabytes.

Most of the users don't use the other parameters that can be passed to 'df'. So I shall not be discussing them.

I shall in turn show you an example that I use on my machine. I have actually stored this as a script named 'usage' since I use it often.

Example :

I have my Linux installed on /dev/hda1 and I have mounted my Windows partitions as well (by default every time Linux boots). So 'df' by default shows me the disk usage of my Linux as well as Windows partitions. And I am only interested in the disk usage of the Linux partitions. This is what I use :

$ df -h | grep /dev/hda1 | cut -c 41-43

This command displays the following on my machine

45%

Thursday, May 10, 2012

Dos Batch

DOS Batch file to delete folders by date range
@Echo Off
Setlocal EnableDelayedExpansion
:: User Variables
:: Set this to the number of days you want to keep
Set _DaysKept=7
:: Set this to the folder that contains the folders to check and delete
Set _Path=C:\Test1
:: Get todays date
Call :GetDate
Set _yy=%_fDate:~,4%
Set _mm=%_fDate:~4,2%
Set _dd=%_fDate:~6,2%
:: Convert todays date to Julian
Call :JDate %_yy% %_mm% %_dd%
Set _JToday=%_JDate%
:: Set delete date
Set /a _DelDate=_JToday-%_DaysKept%-1
:: Get time format, _iTime will be 0 if 12 hourt clock, 1 if 24 hour clock
:: Delims= is a TAB followed by a space in the next line
:: If you copy this code, you must edit this line
For /F "TOKENS=2* DELIMS=     " %%A In ('REG QUERY "HKCU\Control Panel\International" /v iTime') Do Set _iTime=%%B
If Exist "%temp%\tf}1{" Del "%temp%\tf}1{"
PushD %_Path%
Set _s=s
If %_DaysKept%==1 set _s=
Echo Please wait, searching for folders more than %_DaysKept% day%_s% old
If %_iTime%==0 (Set _Tok=1,4*) Else (Set _Tok=1,3*)
For /F "tokens=%_Tok% skip=4" %%I In ('dir "%_Path%\1*" /AD /OD /TW ^|Findstr /E "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]"') Do (
Set _Name=%%K
  If "!_Name:~10!"=="" If %%J==^ (
    Call :GetDate %%I
    Call :JDate !_fDate:~,4! !_fDate:~4,2! !_fDate:~6,2!
    If !_JDate! LEQ %_DelDate% (
      If Exist "%temp%\tf}1{" (
        Echo %%I:%%~fK >>"%temp%\tf}1{"
        ) Else (
        Echo.>"%temp%\tf}1{"
        Echo Do you wish to delete the following folders?>>"%temp%\tf}1{"
        Echo Date       Name>>"%temp%\tf}1{"
        Echo %%I:%%~fK >>"%temp%\tf}1{"
      )) Else (
      Goto :_allFound
      )))
PopD
:_allFound
If Not Exist "%temp%\tf}1{" Echo No Folders Found to delete&Goto _Done
Type "%temp%\tf}1{" | More
Set _rdflag= /q
:_Prompt1
Set /P _resp=Delete All, None, or Prompt for each (A/N/P)?
If /I "%_resp:~0,1%"=="N" Goto _Done
If /I "%_resp:~0,1%"=="A" Goto _Removeold
If /I NOT "%_resp:~0,1%"=="P" (Echo (A/N/P only please)&Goto _Prompt1
Set _rdflag=
:_Removeold
For /F "tokens=1* skip=3 Delims=:" %%I In ('type "%temp%\tf}1{"') Do (
 If "%_rdflag%"=="" Echo Deleting
 rd /s%_rdflag% "%%J")
:_Done
If Exist "%temp%\tf}1{" Del "%temp%\tf}1{"
Goto:EOF
::===================================::
::                                         ::
::   -   S u b r o u t i n e s   -   ::
::                                         ::
::===================================::
:JDate
:: Convert date to Julian
:: Arguments : YYYY MM DD
:: Returns   : Julian date in variable _JDate
:: Usage
::Call :JDate %__GYear% %_GMonth% %_GDay%
:: First strip leading zeroes; a logical error in this
:: routine was corrected with help from Alexander Shapiro
::Code taken from datediff.bat written by Rob van der Woude
::http://www.robvanderwoude.com
Set _JMM=%2
Set _JDD=%3
IF 1%_JMM% LSS 110 Set _JMM=%_JMM:~1%
IF 1%_JDD% LSS 110 Set _JDD=%_JDD:~1%
::
:: Algorithm based on Fliegel-Van Flandern
:: algorithm from the Astronomical Almanac,
:: provided by Doctor Fenton on the Math Forum
:: (http://mathforum.org/library/drmath/view/51907.html),
:: and converted to batch code by Ron Bakowski.
Set /A _JMonth1 = ( %_JMM% - 14 ) / 12
Set /A _JYear1  = %1 + 4800
Set /A _JDate  = 1461 * ( %_JYear1% + %_JMonth1% ) / 4 + 367 * ( %_JMM% - 2 -12 * %_JMonth1% ) / 12 - ( 3 * ( ( %_JYear1% + %_JMonth1% + 100 ) /

100 ) ) / 4 + %_JDD% - 32075
For %%A In (_JMonth1 _JYear1) Do Set %%A=
Goto:EOF
:GetDate
:: This subroutine will always display the same results,
:: for the date independent of "International" settings.
:: This batch file uses REG.EXE from the NT Resource Kit
:: (already installed with WinXP and Vista)
:: to read the "International" settings from the registry.
:: Date is returned as yyyymmdd in variable _fdate
:: Modified from SortDate Written by Rob van der Woude
:: http://www.robvanderwoude.com
::
If NOT [%1]==[] Set Date=%1
If "%date%A" LSS "A" (Set _NumTok=1-3) Else (Set _NumTok=2-4)
:: Delims= is a TAB followed by a space in the next two lines
:: If you copy this code, you must edit these two lines
For /F "SKIP=3 TOKENS=2* DELIMS=     " %%A In ('REG QUERY "HKCU\Control Panel\International" /v iDate') Do Set _iDate=%%B
For /F "SKIP=3 TOKENS=2* DELIMS=     " %%A In ('REG QUERY "HKCU\Control Panel\International" /v sDate') Do Set _sDate=%%B
IF %_iDate%==0 For /F "TOKENS=%_NumTok% DELIMS=%_sDate% " %%B In ("%date%") Do Set _fdate=%%D%%B%%C
IF %_iDate%==1 For /F "TOKENS=%_NumTok% DELIMS=%_sDate% " %%B In ("%date%") Do Set _fdate=%%D%%C%%B
IF %_iDate%==2 For /F "TOKENS=%_NumTok% DELIMS=%_sDate% " %%B In ("%date%") Do Set _fdate=%%B%%C%%D
Goto:EOF
FTP Batch
FTP -v -i -s:ftpscript.txt

open example.com
username
password
!:--- FTP commands below here ---
lcd c:\MyLocalDirectory
cd  public_html/MyRemoteDirectory
binary
mput "*.*"
disconnect
bye

Monday, May 7, 2012

Apache 2

Common apache related command
-restart 
/etc/init.d/apache2 restart
 
-reinstall 
apt-get --reinstall install apache2.2-common 

-reinstall configuration files
apt-get -o DPkg::Options::="--force-confmiss" --reinstall install apache2.2-common
 
-fully remove apache
apt-get purge apache2.2-common
apt-get remove --purge apache2 apache2-utils
 
-install apache
apt-get install apache2
   
 
Virtual Host 

vi /etc/apache2/sites-available/adabi
 

        ServerAdmin webmaster@localhost
        ServerName adabi

        DocumentRoot /var/www/adabi
        
                Options FollowSymLinks
                AllowOverride None
        
        
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        

        ErrorLog ${APACHE_LOG_DIR}/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog ${APACHE_LOG_DIR}/access.log combined

    Alias /doc/ "/usr/share/doc/"
    
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    
 
 
 
edit /etc/apache2/conf.d/fqdn
ServerName localhost 
 
edit 
/etc/hosts 
 
127.0.0.1       localhost.localdomain   localhost
127.0.0.1       localhost.localdomain   asf
127.0.0.1       localhost.localdomain   adabi
127.0.0.1       localhost.localdomain   open
 
 
activate virtual host :

a2dissite default 
a2ensite adabi
/etc/init.d/apache2 restart
 

Run, Stop, Test, And Restart Apache

 
/usr/sbin/apache2ctl start 
/usr/sbin/apache2ctl stop
/usr/sbin/apache2ctl restart
service apache2 restart 
/usr/sbin/apache2ctl configtest          ::test configuration 

Thursday, May 3, 2012

bash scripting

daily samba backup using crontab
#!/bin/bash
# backup sun01 server : /home/samba_folder 
echo `date` 'backup.sh: START' > /tmp/cron.log
cd /
DATESTAMP=`date +%F`
LIST="/tmp/backuplist_$$.txt"
SOURCE_PATH="/home/samba_folder"
DESTINATION_PATH="/media/backup"
OLDBACKUP_PATH="/home/oldbackup"

#mount -n -t cifs -o rw,username=,password= $DESTINATION_PATH

sleep 5
cat /dev/null > /tmp/bcksun01.out
find /tmp/*.ods  -cmin +200 -type f -exec rm -f '{}' \; 2>>/dev/null
find /tmp/*.csv  -cmin +200 -type f -exec rm -f '{}' \; 2>>/dev/null

#find /home/backup/*.gz -mtime +60 -type f -exec rm -f '{}' \;

set $(date +%d)
if test "$1" = "03" ; then
#   rm -f $OLDBACKUP/sun01.admin.full.tar.gz 2>>/dev/null
#   tar cvfz "$OLDBACKUP/sun01.admin.full.tar.gz" $SOURCE_PATH/admin  2>>/tmp/cron.log >>/tmp/backup.log
   rm -f $OLDBACKUP/sun01.samba_folder.full.tar.gz 2>>/dev/null
   tar cvfz "$OLDBACKUP/sun01.samba_folder.full.tar.gz" $SOURCE_PATH  2>>/tmp/cron.log >>/tmp/backup.log
else
   rm -f $OLDBACKUP/sun01.samba_folder.$1.tar.gz 2>>/dev/null
   find $SOURCE_PATH -depth -type f \( -mtime -2 \) -print > $LIST
   tar cvfzT "$OLDBACKUP/sun01.samba_folder.$1.tar.gz" $LIST 2>>/tmp/cron.log >/tmp/backup.log
   rm -f "$LIST"
fi
  
sleep 1
#umount $DESTINATION_PATH/tn_sql
history -c
echo `date` 'backup.sh: Completed' >> /tmp/cron.log
other backup sample
# use backticks " ` ` " to execute shell command

 # TARIKH=`date +"%Y%m%d_%s"`

mount -t smbfs //131.107.2.20/volume_1/  /home/vol1 -o username=adabi,password=akula
mount -t smbfs //131.107.2.20/volume_2/  /home/vol2 -o username=adabi,password=akula
TARIKH=`date +"%Y-%m-%d"`
TARIKH2=`date +"%Y%m%d"`
TARIKH3=`date +"%Y%m"`
DAY0=`date +"%d"`
WDAY0=`date +"%u"`
YDATE=`date -d '1 day ago' +'%Y%m%d'`
UPDSCRIPT=update$TARIKH.sh
PATCHSCRIPT=patch$TARIKH.sh
SENARAI=/tmp/bcklist.txt
SENARAIF=/tmp/fbcklist.txt

BCK_TNLINUX3=/home/vol1/tnlinux3
echo ${BCK_TNLINUX3}'/tnlinux3.full.tar.gz' > ${SENARAIF}
echo ${BCK_TNLINUX3}'/tnlinux3.artwork.full.tar.gz' >> ${SENARAIF}
echo ${BCK_TNLINUX3}'/tnlinux3.samba.administrator.full.tar.gz' >> ${SENARAIF}
echo ${BCK_TNLINUX3}'/tnlinux3.samba.customer1.full.tar.gz' >> ${SENARAIF}



yesterday date:

date -d '1 day ago' +'%Y-%m-%d'

or

date -d @`echo $((\`date +%s\` – 86400))` +”%Y-%m-%d”
MYSQL :: SQL LEFT JOIN Syntax
SELECT column_name(s)
FROM table_name1
LEFT JOIN table_name2
ON table_name1.column_name=table_name2.column_name