Wednesday 29 February 2012

Strict Validations in ActiveModel/Rails v3.2 has added the concept of strict validations


Rails v3.2 has added the concept of strict validations. These validations are ideally suited for data constraints which should always be enforced, but aren't affected by user input. For example, setting the user association to the current_user in the controller.
There are two ways of specifying a validation as strict. Firstly, you can set the :strictoption to true. Secondly, you can use the new validates! method.
An ActiveModel::StrictValidationFailed exception is raised if your record fails validation.
class Content
  validates_presence_of :user, strict: true

  # The following is equivalent: 
  # validates! :user, presence: true
end

content = Content.new
content.user = nil
content.valid? 
# => ActiveModel::StrictValidationFailed: can't be blank

5 Must Know Features of the Ruby Language


Ruby Language Feature Number One: Variables

When you're planning a party, do you create a numbered "To-Do" list? Does it make sense to pick up the food from the caterer before you've booked a the rec hall? Once you've booked that rec hall, though, how do you remember the address to give to the caterer? In its simplified form, a computer program can be thought of as a structured "To-Do" list. Each thing on the list needs to be completed to accomplish a final task, but also needs to done in a certain order.
If your computer program is your party list, than variables are the sticky notes you use to keep track of all the data you've collected. Without your sticky notes, you'd be at a loss as to how to move forward with planning. Without using variables, your Ruby program isn't able to keep track of its data either.

Ruby Language Feature Number Two: Arrays

Programs often have to manage collections of variables. Take for example, a program that manages your party information. You're bound to have party guests, each of whom must be stored in a variable and a list of which can be stored together in an array variable. That way you can access each guest via the array.

Ruby Language Feature Number Three: Hashes

Now imagine your party is a potluck event and each guest is required to bring a dish or other item. You'll still need a list of guests, which can be managed as an array, but you'll also need a way to keep track of what types of food are being brought. Additionally, you'll probably want to know who is bringing what. Using a hash to store key/value pairs allows you to store that information. Say Susan is bringing chocolate cake to your party. The "key" will be "Susan" and the variable stored and accessed by the key (the value) will be "chocolate cake."

Ruby Language Feature Number Four: Loops

Computer programs often have to perform actions more than just once. For example, if your program prints all new information added to your pot luck list, it will need to print more than just a single time. This can be accomplished using a construct known as a loop.

Ruby Language Feature Number Five: Blocks

Blocks aren't anything new, especially to functional programmers. In the Ruby language, the use of these nameless methods is widespread and the block is one of the language's key features. They're often used to abstract the more tedious and repetitive loops into a more user-friendly forms.

Using the Times Loop in Ruby on Rails


One of the most fundamental parts of programming is learning how to use loops, i.e. recursion or iteration, to your advantage. Once you understand the concept you will reach a level that is what I believe to be the main place that math or computer-phobes stumble, the concept of loops. This loop device is used in every programming language out there, there is just difference in syntax. It is very simple, but powerful.
Using the ‘Times’ Loop
The times loop is one of my favorite ways to loop things in Ruby, when using a language that doesn’t have something like it you really miss it. It makes it very simple and efficient to perform a quick iteration without need for setting up any counter variables or anything of that nature. Here is an example of the convenience offered by the times loop.
Instead of doing this –
puts "Hello World"
puts "Hello World"
puts "Hello World"
puts "Hello World"
puts "Hello World"
You can just do this –
5.times do
 puts "Hello World"
end


They will produce exactly the same result. Yes, it’s a simple example but it’s the concept that is important here. Remember DRY when programming, as in Dont Repeat Yourself! Using loops like the timesloop so that you aren’t copy and pasting all over the place when you are just repeating yourself.
Likewise if the # of times you want to iterate isn’t predetermined then you can use a variable in it’s place likeso—

puts "How many times should I say Hello World?"
x = gets.to_i

x.times do
 puts "Hello World"
end


Here we are just asking the console for an integer, and then we take what is entered and name it variable x. Then we just replace the previously hardcoded number with our variable and we are good to go — this will run however many times you want it to without needing to make any changes to your code. Hurray the Ruby times Loop!

25 Gem Commands for RubyGems with rails


The gem command is one of the most used Ruby-related commands, but most users don't take the time to learn anything past gem install and gem search. Learning the gem command well is an essential Ruby skill.
The gem command-line utility is split into a number of commands. Among these are the familiarinstall and search, but other useful commands exist such as spec and sources. However, you should start with the help command.
The gem command has integrated help. By running the command gem help, you can get a basic help screen. To get a list of commands available, run the gem help commands command. To get further help about a specific command, here, for example, the purge command, run the gem help purge command. Another useful help screen is the examples screen, accessible by the gem help examples command.
Most commands work on a gem repository, either local (the gems you have installed), or remote. Though, by default, it's the local repository. To specify the repository you intend , add either --remote or --local to the end of the command. For example, to search the remote repository for gems with the word "twitter" in them, you would run gem search twitter --remote. Specify both remote and local repositories by using the --both switch.
When running any gem command, the name can be shortened as long as it doesn't become ambiguous. To run a gem dependency command, you can simply run a gem dep command.
Below is a list of the commands and an explanation of their function.
  • build - Given the source code for a gem and a .gemspec file, this will build a .gem file suitable for uploading to a gem repository or installing on another computer with the gem command. A .gemspec file holds information about a gem including name, author, version and dependencies.
  • cert - Manages certificates for cryptographically signed gems. If you're worried that a malicious user is going to compromise the gems you install, you can cryptographically sign them to prevent this. Keys may be added or deleted from your list of acceptable keys, as well as a few other crypto key related functions.
  • check - Performs a number of actions, including running any unit tests, checking the checksum of installed gems and looking for unmanaged files in the gem repository. The type of check you wish to run must be added to the end of the gem command.
  • cleanup - Removes old versions of installed gems from your local repository. If you frequently upgrade gems, you can have old versions hanging around that you don't need anymore.
  • contents - Shows the contents of an installed gem. This is a list of files the gem installed and where they are on the filesystem.
  • dependency - Shows all the gems the listed gem depends upon, as well as the versions of the gem it depends upon. For example, running gem dep twitter tells me the twitter gem relies on hpricot, activesupport, httparty and echoe. This is useful when packaging your applications for deployment.
  • environment - Displays various information about the RubyGems environment, including the version installed, where it's installed, where the gem repository is, etc.
  • fetch - Fetches a gem and saves the .gem file in the current directory. This is useful for transferring gems to be deployed on other servers, without them needing to download the gem themselves.
  • generate_index - Generates an index for a gem server. This is only useful if you're running a gem repository.
  • install - Downloads a gem from the specified repository (--local or --remote) and install it. Also, downloads any dependencies and installs them as well. To install a specific version of a gem, use the --version switch.
  • list - Displays a list of gems in the repository. Note that doing this with --remote will generate quite a large list. Save this list to a file for fast searching.
  • lock - Generates a Ruby script that requires the exact version of all dependencies of a certain gem. This ensures that the gem versions tested during development will be installed, not future or past versions which may have bugs the developers cannot account for.
  • mirror - Mirrors an entire gem repository. Note that trying to mirror the RubyGems repository is a huge task. Do not do so unless you need to run a local mirror for other clients.
  • outdated - Displays a list of installed gems that have newer versions on the remote repository.
  • pristine - Returns gems to their original state. This means unpacking all gems from the local cache, overwriting any changes made to the gems in the local gem repository. This can be used to repair a broken gem.
  • rdoc - Generates rdoc documentation for an installed gem. This rdoc documentation can then be viewed with a web browser.
  • search - Searches the names of all gems and returns a list of gems whose name contains a string. For example, to search for all gems containing the word twitter in the name, run gem search twitter.
  • server - Starts a web server that will act as a gem repository and serves RDoc documentation for all installed gems. This is most useful for the documentation feature.
  • sources - Manages the list of sources for remote repositories. By default, only http://gems.rubyforge.org is in the list, but more can be added or removed.
  • specification - Displays the gemspec of a gem. This will tell you all the information about a gem, including author, dependencies, etc.
  • stale - Displays a list of installed gems, as well as the access times (the last time the gem was included). This can help you weed out gems you no longer user to uninstall them.
  • uninstall - Uninstalles a gem. If there are any installed gems that depend on this gem, you will be prompted whether you want to uninstall this gem. If you do, any gems that depended on this gem will be broken until it is reinstalled.
  • unpack - Unpacks an install gem into the current directory. This can be used to "freeze" gems to your project directory.
  • update - Checks if there are new versions of the specified gem in the remote repository. If there are, download and install the newest version.
  • which - Finds the exact location of the .rb file to include. This can be useful for getting a path for requiring a gem without requiring the rubygems library.

What is Bundler in ruby on rails?


This article was written for Bundler version 1.0. If you are using a later version of Bundler, the commands and code here may or may not work. If in doubt refer to the Bundler home page.
Bundler is a program for managing gem dependencies in your Ruby projects. With Bundler you can specify which gems your program needs, what versions they should be at, it can help you install them, load them at runtime and distribute them with your software. Basically, it takes all of the guesswork out of installing the gems needed to run your Ruby projects.
Before Bundler, you'd often see a section in the README for any particular project stating the gems you'll need to install. They might have even been kind enough to include a command line for you to copy and paste to install these gems. This worked just fine. Kind of. Sometimes. The problem here (besides it being very clunky and ad hoc) is that new versions of gems can introduce new features, break old features or just behave differently and make your Ruby program fail to run. By using Bundler to specify not only which gems you use but the versions of those gems, you can have very fine and automated control over which gems your program will use.
In addition to this amount of control, Bundler provides a simple way to install these gems. No more copying and pasting lists of gems, or even using the gem command manually. All of this is replaced by a simple command: bundle install. This is simple enough that system administrators and webmasters that have no idea about Ruby can run it, it all just works.
Another useful feature is the ability to store your gems in a vendor directory in your source tree. This allows you to distribute your Ruby program along with its dependencies so it doens't have to reach out to the Rubygems repository, it already has its gems right there.
In addition to the gems and gem versions you give to Bundler, Bundler will also keep track of the versions of all the dependencies of those gems. So it will not only track the gems you know about, but also the gems those gems rely on, whether you know about them or not.

Who Should Use Bundler?

The short answer to this question is "everyone." Bundler is so useful to practically everyone, it has become an absolute fixture in the Ruby ecosystem. Here are a few examples of the types of people who would find Bundler useful.
  • Individual developers. It might not sound like it's that important, but individual developers need to keep control of which gems their programs are using. There's nothing worse than having a program work fine on your development machine and fail elsewhere due to a differing gem version. Even if you're a single developer, and even if you only ever run your programs on your development machine, you should probably be using Bundler.
  • Groups of developers. Not every programmer on a team has the same versions of gems installed. Keeping all the developers on the same page is what Bundler was built for. It's hard to imagine doing development in a group without Bundler.
  • A web developer. If you're a web developer that needs to pass Rails, Sinatra or other Ruby web applications to web designers, system administrators, clients, etc then again, Bundler would be very useful. Even if the other members of the team are not programmers, they will still need to lock gem versions to the same versions you're using.
  • Everyone else. Every Ruby programmer should be using Bundler. I know I've personally encountered bugs where new versions of a gem have introduced some subtle bug and the whole program just crashes, or simply refuses to work. It is rare, gem authors usually do their best to keep regressions from happening, but it does happen. If you aren't using Bundler, you should be! I know that sounds like a sales pitch, but really, you should be.

Installing Bundler

Before you can dig in, you have to install Bundler itself. This should be the only gem you need to install yourself should all your programs' dependencies be managed by Bundler. And there are no surprises here, just gem install bundler. You'll now have the bundler gem installed and thebundle command line tool available.


$ gem install bundler

If you need to be root to install gems, you should run this from a root console or with sudo. Similarly, if the bundle command needs to install gems it should be run as root. If you fail to do this, it will ask you for your root password.

Thursday 23 February 2012

Five best download managers for Linux


The typical download manager at a minimum provides means to recover from errors without losing the work already completed, and can optionally split the file to be downloaded (or uploaded) into 2 or more segments, which are then moved in parallel, potentially making the process faster within the limits of the available bandwidth. So what is the perfect download manager i should use in Linux ?


Bellow I  listed  5 download managers for Gnome

Gwget (frontend to wget) :
-Gwget it’s a download manager for the Gnome Desktop. The main features are:
-Resume: By default, gwget tries to continue any download.
-Notification: Gwget tries to use the Gnome notification area support, if available. You can close the main window and gwget runs in the background.
-Recursivity: Gwget detects when you put a html, php, asp or a web page dir in the url to download, and ask you to only download certain files (multimedia, only the index, and so on).
-Drag & Drop: You can d&d a url to the main gwget window or the notification area icon to add a new download.Firefox
- Extension: Fireget
Latest version :18 Jun 2009. Gwget 1.0.2 Download: [ tgz ] [ bz2 ]
install in ubuntu :
sud apt-get install gwget
Fedora :
yum install gwget

MultiGet is an easy-to-use GUI file downloader for Linux also support windows and Mac operating systems, It supports HTTP/FTP protocols which covers the requirements of most users. It supports multi-task with multi-thread on multi-server. It supports resuming downloads if the Web server supports it, and if you like, you can reconfig the thread number without stopping the current task. It’s also support SOCKS 4,4a,5 proxy, ftp proxy, http proxy.
You can download it from this link http://sourceforge.net/projects/multiget/files/
To install it in Ubuntu :
sudo apt-get install MultiGet
Fedora :
yum install MultiGet
Mandriva :
urpmi MultiGet

FlashGot (Firefox addon):

FlashGot, the best Firefox download manager integration, you can download all the links, movies and audio clips of a page at the maximum speed with a single click, using the most popular, lightweight and reliable external download managers.



 Downloader For X
Downloader For X (or simply D4X) is a download manager/accelerator for Unix-like systems. It is open source software released under the Artistic licence. It can pause and restart downloads at any time, and utilises both the HTTP and FTP protocols. It can limit download speeds to free bandwidth for other uses.
wxDownload :

wxDownload Fast (also known as wxDFast) is an open source download manager. It is multi-platform and builds on Windows(2k,XP), Linux and Mac OS X(binary still not available). Besides that, it is a multi-threaded download manager. This means that it can split a file into several pieces and download the pieces simultaneously.
Features
  • Faster downloads (with Segmented/Multi-threaded/Accelerated transfers)
  • Download resuming (Pause and restart where you stopped)
  • Download scheduling
  • Organizes files you have already downloaded
  • View server messages (HTTP, FTP, file://). No HTTPS support.
  • Available in multiple languages and easily translated. Now available in Portuguese [Brazil], Spanish, English, German, Russian, Hungarian, Armenian, Indonesian and Dutch
  • Connection to HTTP/FTP servers which require a password
  • Calculates the MD5/SHA1 checksum of downloaded files so they can be easily verified
  • Metalink support
  • Firefox integration through FlashGot
  • Can be used as a portable download manager (Windows only)
  • Can be used over proxy servers(HTTP proxy support)
 

Install BackupPC server in Centos|Rhel|Fedora


BackupPC is an entirely disk-based backup and recovery system. It offers a number of advantages, some of which are available only with BackupPC,
Backuppc Support any client OS and has a Web interface to allows user control of and access to backups

How BackupPC Works
The BackupPC model has one user per client. This fits the usage pattern of the type of environment it was specifically designed for: backing up several users’ PCs (hence the name). This should typically be the user who owns the data on the machine. In the case of a large file server, it should be an administrator. BackupPC emails the owner if it cannot back up the client after a configurable time, and the owner can control restores using the web interface. The following list describes how BackupPC works.
Now we will show you how install Backup pc on Centos/Rhel/Fedora, the current installation is done on a machine with CentOS 5.2 installed, but it work also for fedora and RHEL.
Open your terminal, and under root type :
 yum install perl-Compress-Zlib perl-Archive-Zip perl-File-RsyncP perl-XML-RSS httpd
rpm  -Uvh   http://dev.centos.org/centos/5/testing/i386/RPMS/backuppc-3.1.0-1.el5.centos.i386.rpm
1- Add user backuppc to your machine, User backuppc will be created upon installation. Change apache user to backuppc.
 vi /etc/httpd/conf/httpd.conf

Change ‘User apache‘ to ‘User backuppc
Save
2- Edit file /etc/httpd/conf.d/backuppc.conf
 # vi /etc/httpd/conf.d/backuppc.conf   

change ‘Allow from 127.0.0.1‘ to ‘Allow from all
Save
3- Create password for cgi-bin admin user
# htpasswd -c /var/lib/backuppc/passwd/htpasswd admin
4- Edit backuppc config file
# vi /etc/BackupPC/config.pl 
Find and change accordingly
$Conf{ServerHost} = 'localhost';
$Conf{SplitPath} = '/usr/bin/split';
$Conf{CatPath} = '/bin/cat';
$Conf{GzipPath} = '/bin/gzip';
$Conf{Bzip2Path} = '/usr/bin/bzip2';
$Conf{BackupPCUser} = 'backuppc';
$Conf{TopDir} = '/var/lib/backuppc';
$Conf{ConfDir} = '/etc/BackupPC';
$Conf{LogDir} = '/var/log/BackupPC';
$Conf{InstallDir} = '/usr';
$Conf{CgiDir} = '/usr/share/backuppc/cgi-bin';
$Conf{ServerInitdPath} = '/etc/init.d/backuppc';
$Conf{ServerInitdStartCmd} = '$sshPath -q -x -l root $serverHost$serverInitdPath start';
$Conf{SshPath} = '/usr/bin/ssh';
$Conf{NmbLookupPath} = '/usr/bin/nmblookup';
$Conf{PingPath} = '/bin/ping';
$Conf{CgiAdminUsers} = 'admin';
Save
5- Grant passwordless sudo for user backuppc to run /bin/gtar and /bin/tar
# visudo

Add these entries :
Defaults !lecture # to disable lecture
backuppc ALL=NOPASSWD:/bin/gtar,/bin/tar # enable user backuppc to run /bin/tar and /bin/gtar without authentication.
Comment this entry
#Defaults requiretty
Save and exit
Restart apache and backuppc service
# /etc/init.d/http restart
# /etc/init.d/backuppc restart

Open your browser and point it to ‘http://backuppc_server_ip/backuppc‘ and you should see the backuppc web interface


After this, you have to do almost all the configuration through the web interface. To test, you can run localhost backup first. You have to create the host, fill up all the setting and you are ready to go. Record the host and ip in /etc/hosts.
II Client setup
1 – Create new user
# useradd backupuser
# passwd backupuser
2- Grant passwordless sudo for user backupuser
# visudo
Add these entries
Defaults !lecture # to disable lecture
backupuser ALL=NOPASSWD:/bin/gtar,/bin/tar # enable user backuppc to run /bin/tar and /bin/gtar without authentication.
Comment this entry
#Defaults requiretty
Save
3- From the server using backuppc user, create ssh public key
# su -s /bin/bash backuppc
$ mkdir .ssh
$ chown backuppc.backuppc .ssh
$ chmod 700 .ssh
$ ssh-keygen -t rsa
$ ssh-copy-id -i .ssh/id_rsa.pub backupuser@client
4 – To make sure that the 3rd step is a success, try to ssh to backupuser@client using backuppc user from the server. If no password is asked, then you are ready.
# su -s /bin/bash backuppc
$ ssh backupuser@client
You can start entering the client to the list of host and start backing up :)
If something didnt work , please post it in the forum

Setup a transparent proxy with Squid in three easy steps


i) System: HP dual Xeon CPU system with 8 GB RAM (good for squid).
ii) Eth0: IP:192.168.1.1
iii) Eth1: IP: 192.168.2.1 (192.168.2.0/24 network (around 150 windows XP systems))
iv) OS: Red Hat Enterprise Linux 4.0 (Following instruction should work with Debian and all other Linux distros)


Eth0 connected to internet and eth1 connected to local lan i.e. system act as router.

Server Configuration

  • Step #1 : Squid configuration so that it will act as a transparent proxy
  • Step #2 : Iptables configuration
    • a) Configure system as router
    • b) Forward all http requests to 3128 (DNAT)
  • Step #3: Run scripts and start squid service
First, Squid server installed (use up2date squid) and configured by adding following directives to file:
# vi /etc/squid/squid.conf
Modify or add following squid directives:
httpd_accel_host virtual
httpd_accel_port 80
httpd_accel_with_proxy on
httpd_accel_uses_host_header on
acl lan src 192.168.1.1 192.168.2.0/24
http_access allow localhost
http_access allow lan
Where,
  • httpd_accel_host virtual: Squid as an httpd accelerator
  • httpd_accel_port 80: 80 is port you want to act as a proxy
  • httpd_accel_with_proxy on: Squid act as both a local httpd accelerator and as a proxy.
  • httpd_accel_uses_host_header on: Header is turned on which is the hostname from the URL.
  • acl lan src 192.168.1.1 192.168.2.0/24: Access control list, only allow LAN computers to use squid
  • http_access allow localhost: Squid access to LAN and localhost ACL only
  • http_access allow lan: — same as above –
Here is the complete listing of squid.conf for your reference (grep will remove all comments and sed will remove all empty lines, thanks to David Klein for quick hint ):
# grep -v “^#” /etc/squid/squid.conf | sed -e ‘/^$/d’
OR, try out sed (thanks to kotnik for small sed trick)
# cat /etc/squid/squid.conf | sed ‘/ *#/d; /^ *$/d’
Output:
hierarchy_stoplist cgi-bin ?
acl QUERY urlpath_regex cgi-bin ?
no_cache deny QUERY
hosts_file /etc/hosts
refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern . 0 20% 4320
acl all src 0.0.0.0/0.0.0.0
acl manager proto cache_object
acl localhost src 127.0.0.1/255.255.255.255
acl to_localhost dst 127.0.0.0/8
acl purge method PURGE
acl CONNECT method CONNECT
cache_mem 1024 MB
http_access allow manager localhost
http_access deny manager
http_access allow purge localhost
http_access deny purge
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
acl lan src 192.168.1.1 192.168.2.0/24
http_access allow localhost
http_access allow lan
http_access deny all
http_reply_access allow all
icp_access allow all
visible_hostname myclient.hostname.com
httpd_accel_host virtual
httpd_accel_port 80
httpd_accel_with_proxy on
httpd_accel_uses_host_header on
coredump_dir /var/spool/squid

Iptables configuration

Next, I had added following rules to forward all http requests (coming to port 80) to the Squid server port 3128 :
iptables -t nat -A PREROUTING -i eth1 -p tcp –dport 80 -j DNAT –to 192.168.1.1:3128
iptables -t nat -A PREROUTING -i eth0 -p tcp –dport 80 -j REDIRECT –to-port 3128
Here is complete shell script. Script first configure Linux system as router and forwards all http request to port 3128

#!/bin/sh
# squid server IP
SQUID_SERVER=“192.168.1.1″
# Interface connected to Internet
INTERNET=“eth0″
# Interface connected to LAN
LAN_IN=“eth1″
# Squid port
SQUID_PORT=“3128″
# DO NOT MODIFY BELOW
# Clean old firewall
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
# Load IPTABLES modules for NAT and IP conntrack support
modprobe ip_conntrack
modprobe ip_conntrack_ftp
# For win xp ftp client
#modprobe ip_nat_ftp
echo 1 > /proc/sys/net/ipv4/ip_forward
# Setting default filter policy
iptables -P INPUT DROP
iptables -P OUTPUT ACCEPT
# Unlimited access to loop back
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT
# Allow UDP, DNS and Passive FTP
iptables -A INPUT -i $INTERNET -m state --state ESTABLISHED,RELATED -j ACCEPT
# set this system as a router for Rest of LAN
iptables --table nat --append POSTROUTING --out-interface $INTERNET -j MASQUERADE
iptables --append FORWARD --in-interface $LAN_IN -j ACCEPT
# unlimited access to LAN
iptables -A INPUT -i $LAN_IN -j ACCEPT
iptables -A OUTPUT -o $LAN_IN -j ACCEPT
# DNAT port 80 request comming from LAN systems to squid 3128 ($SQUID_PORT) aka transparent proxy
iptables -t nat -A PREROUTING -i $LAN_IN -p tcp --dport 80 -j DNAT --to $SQUID_SERVER:$SQUID_PORT
# if it is same system
iptables -t nat -A PREROUTING -i $INTERNET -p tcp --dport 80 -j REDIRECT --to-port $SQUID_PORT
# DROP everything and Log it
iptables -A INPUT -j LOG
iptables -A INPUT -j DROP
Save shell script. Execute script so that system will act as a router and forward the ports:
# chmod +x /etc/fw.proxy
# /etc/fw.proxy
# service iptables save
# chkconfig iptables on
Start or Restart the squid:
# /etc/init.d/squid restart
# chkconfig squid on

Desktop / Client computer configuration

Point all desktop clients to your eth1 IP address (192.168.2.1) as Router/Gateway (use DHCP to distribute this information). You do not have to setup up individual browsers to work with proxies.

How do I test my squid proxy is working correctly?

See access log file /var/log/squid/access.log:
# tail -f /var/log/squid/access.log
Above command will monitor all incoming request and log them to /var/log/squid/access_log file. Now if somebody accessing a website through browser, squid will log information.

Problems and solutions

(a) Windows XP FTP Client

All Desktop client FTP session request ended with an error:
Illegal PORT command.
I had loaded the ip_nat_ftp kernel module. Just type the following command press Enter and voila!
# modprobe ip_nat_ftp
Please note that modprobe command is already added to a shell script (above).

(b) Port 443 redirection

I had block out all connection request from our router settings except for our proxy (192.168.1.1) server. So all ports including 443 (https/ssl) request denied. You cannot redirect port 443, from debian mailing list, “Long answer: SSL is specifically designed to prevent “man in the middle” attacks, and setting up squid in such a way would be the same as such a “man in the middle” attack. You might be able to successfully achive this, but not without breaking the encryption and certification that is the point behind SSL“.
Therefore, I had quickly reopen port 443 (router firewall) for all my LAN computers and problem was solved.

(c) Squid Proxy authentication in a transparent mode

You cannot use Squid authentication with a transparently intercepting pro


source = cybercity

Howto install Java Runtime Environment in fedora and Linpus


To install  Java Runtime Environment in fedora or Linpus, please folow the instructions below.


First : Go to the link below and download the rpm package of java.

http://www.java.com/en/download/linux_manual.jsp?locale=en&host=www.java.com:80
then
open the terminal
su –
choose where you want to install the java , for me i choosed /usr/java
cd /usr/
create a new folder for java
mkdir java
go back to the directory where you downloaded java ,then copy the downloaded file to this directory(/usr/java) ,in my case :
cd /home/unixmen/Download

[root@zinovsky-fedora Download]# cp jre-6u11-linux-i586-rpm.bin /usr/java

then
[root@zinovsky-fedora Download]# cd /usr/java/
make the file executable :
[root@zinovsky-fedora java]# chmod a+x jre-6u11-linux-i586-rpm.bin
run installation :
[root@zinovsky-fedora java]# ./jre-6u11-linux-i586-rpm.bin
output:
[root@zinovsky-fedora java]# ./jre-6u11-linux-i586-rpm.bin
Sun Microsystems, Inc.  Binary Code License Agreement
for the JAVA SE RUNTIME ENVIRONMENT (JRE) VERSION 6 and
JAVAFX RUNTIME VERSION 1
SUN MICROSYSTEMS, INC.  (“SUN”) IS WILLING TO LICENSE THE
SOFTWARE IDENTIFIED BELOW TO YOU ONLY UPON THE CONDITION
THAT YOU ACCEPT ALL OF THE TERMS CONTAINED IN THIS BINARY
CODE LICENSE AGREEMENT AND SUPPLEMENTAL LICENSE TERMS
(COLLECTIVELY “AGREEMENT”).  PLEASE READ THE AGREEMENT
CAREFULLY.  BY DOWNLOADING OR INSTALLING THIS SOFTWARE, YOU
ACCEPT THE TERMS OF THE AGREEMENT.  INDICATE ACCEPTANCE BY
SELECTING THE “ACCEPT” BUTTON AT THE BOTTOM OF THE
AGREEMENT.  IF YOU ARE NOT WILLING TO BE BOUND BY ALL THE
TERMS, SELECT THE “DECLINE” BUTTON AT THE BOTTOM OF THE
AGREEMENT AND THE DOWNLOAD OR INSTALL PROCESS WILL NOT
CONTINUE.
1.  DEFINITIONS.  “Software” means the identified above in
binary form, any other machine readable materials
(including, but not limited to, libraries, source files,
header files, and data files), any updates or error
corrections provided by Sun, and any user manuals,
programming guides and other documentation provided to you
by Sun under this Agreement.  “General Purpose Desktop
…………….
…………..
………………….
………………
………………
Please enter “yes” or “no”.
Do you agree to the above license terms? [yes or no]
yes
Unpacking…
Checksumming…
Extracting…
UnZipSFX 5.50 of 17 February 2002, by Info-ZIP (Zip-Bugs@lists.wku.edu).
inflating: jre-6u11-linux-i586.rpm
Preparing…                ########################################### [100%]
1:jre                    ########################################### [100%]
Unpacking JAR files…
rt.jar…
jsse.jar…
charsets.jar…
localedata.jar…
plugin.jar…
javaws.jar…
deploy.jar…
Done.

Then you have to run this command :

[root@zinovsky-fedora java]# rpm -iv  jre-6u11-linux-i586.rpm
then verify if java subfolder is in /usr/java
And is done :)
For more about configurating java on your firefox please visit :
http://www.java.com/en/download/help/5000010500.xml#100