<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-2074177390835984643</id><updated>2011-07-28T16:13:58.197-03:00</updated><category term='notepad'/><title type='text'>leobsd</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://leobsd.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2074177390835984643/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://leobsd.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Leo</name><uri>http://www.blogger.com/profile/14181600774390961702</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://4.bp.blogspot.com/_9X5XZTyDLBA/Sbsn6wJfRxI/AAAAAAAAAN8/T79RqmQK0ss/S220/lab1-medium.jpeg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>11</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-2074177390835984643.post-1914158866145193525</id><published>2009-07-04T15:03:00.005-03:00</published><updated>2009-07-04T17:05:49.545-03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='notepad'/><title type='text'>Hello Goodbye</title><content type='html'>&lt;blockquote class="quote"&gt;&lt;p&gt;You say yes, I say no&lt;br /&gt;You say stop and I say go go go, oh no&lt;br /&gt;You say goodbye and I say hello&lt;br /&gt;Hello hello&lt;br /&gt;I don't know why you say goodbye, I say hello&lt;/p&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;Goodbye Google Pages, hello Google Blogger. A few months ago, Google decided to shut down Google Pages and move its users to Google Sites. But the annoying thing is that Pages and Sites were not designed for the same type of user... not even close! Pages allows you to insert customized html, javascript and css; Sites allows you to insert... hm... custom text! Thank God, they didn't blocked custom text (yet)! :-D&lt;br /&gt;&lt;br /&gt;I was not willing to pay for a webhost, neither willing to create my own artwork. That's too expensive and too boring for me. Then I decided to move to Google Blogger! Why? because it's perfect for all types of users. For the beginners, a 5-step wizard make them able to setup the blogger and start writing. For the curious guys, there are lots of pre-defined widgets that they can insert on their pages and a pretty easy-to-use interface for changing the blog appearance. And what about the geeks that love to create custom layouts, artwork, javascripts and explore a little deeper the user interaction/experience on their websites? They can really do whatever they want, by editing the whole blog html code, importing external scripts, styles, images... it's perfect!&lt;br /&gt;&lt;br /&gt;Just for your reference, I spent just 60 minutes to: 1) create a new blog in Google Blogger; 2) pick a free layout template on the web; 3) import it on Blogger (you just need to click on a button, select the template's XML file and apply); 4) copy the contents from my old webpages to the blog; 5) clean-up the blog appearance (remove the Blogger's default widgets); 6) redirect the old URL to the new one.&lt;br /&gt;&lt;br /&gt;You might be thinking "Oh, but you can't create serious websites in Blogger... those infinite scrolls are annoying!". Alright, just take a look at these websites: &lt;a href="http://www.bloggertemplatesfree.com/download-gamezine-blogger-template/"&gt;1&lt;/a&gt;, &lt;a href="http://www.bloggertemplatesfree.com/download-magazeen-blogger-template/"&gt;2&lt;/a&gt;, &lt;a href="http://btemplates.com/2008/11/15/wista/"&gt;3&lt;/a&gt;, &lt;a href="http://btemplates.com/2009/07/02/solution/"&gt;4&lt;/a&gt;, &lt;a href="http://www.bloggertemplatesfree.com/download-internet-blogger-template/"&gt;5&lt;/a&gt;, &lt;a href="http://www.bloggertemplatesfree.com/download-made-in-spain-blogger-template/"&gt;6&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Hela, heba helloa...&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2074177390835984643-1914158866145193525?l=leobsd.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2074177390835984643/posts/default/1914158866145193525'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2074177390835984643/posts/default/1914158866145193525'/><link rel='alternate' type='text/html' href='http://leobsd.blogspot.com/2009/07/hello-goodbye.html' title='Hello Goodbye'/><author><name>Leo</name><uri>http://www.blogger.com/profile/14181600774390961702</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://4.bp.blogspot.com/_9X5XZTyDLBA/Sbsn6wJfRxI/AAAAAAAAAN8/T79RqmQK0ss/S220/lab1-medium.jpeg'/></author></entry><entry><id>tag:blogger.com,1999:blog-2074177390835984643.post-8766146326244744843</id><published>2009-04-27T23:31:00.009-03:00</published><updated>2009-07-04T13:28:50.858-03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='notepad'/><title type='text'>Speedtouch/Thomson 510v6 on the router mode</title><content type='html'>1) First off, connect the modem and your computer by using using the ethernet port. Now, set up the computer's ethernet interface with an IP address from the 192.168.1.0/24 class:&lt;br /&gt;&lt;br /&gt;&lt;div class="shell"&gt;&lt;br /&gt;&lt;pre&gt;root@localhost:/home/leo# ifconfig eth0 192.168.1.100 netmask 255.255.255.0&lt;br /&gt;root@localhost:/home/leo# ifconfig eth0&lt;br /&gt;eth0      Link encap:Ethernet  HWaddr 00:15:56:0b:3b:46&lt;br /&gt;   inet addr:192.168.1.100  Bcast:192.168.1.255  Mask:255.255.255.0&lt;br /&gt;   UP BROADCAST MULTICAST  MTU:1500  Metric:1&lt;br /&gt;   RX packets:0 errors:0 dropped:0 overruns:0 frame:0&lt;br /&gt;   TX packets:0 errors:0 dropped:0 overruns:0 carrier:0&lt;br /&gt;   collisions:0 txqueuelen:1000&lt;br /&gt;   RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;2) Reset the router from the default configuration: look for the reset button on the router's rear side. Press the button for at least 4 seconds (you might have to use a pen to do that). Keep pressing the button until the green leds turn off, and then release the button. Wait a minute while the router to reboots.&lt;br /&gt;&lt;br /&gt;3) Open a web browser and point it to http://192.168.1.254. If you're asked for the administrator password, insert "Administrator" as the username and press Enter&lt;enter&gt;, leaving the password field blank.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Note:&lt;/span&gt; If you have a pop-up blocker configured, remember to allow access for all pop-ups from modem's IP address.&lt;br /&gt;&lt;br /&gt;4) On the "Pick a task" menu, click &lt;span style="font-weight: bold;"&gt;set up&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;5) On the welcome screen, click &lt;span style="font-weight: bold;"&gt;next&lt;/span&gt;. On the service selection screen, click over the "routed PPP" option and click &lt;span style="font-weight: bold;"&gt;next&lt;/span&gt;. On the "Routed Internet Connection" screen, select the proper VPI/VCI and connection type (8.35/PPPoE works perfectly for my service provider) and click &lt;span style="font-weight: bold;"&gt;next&lt;/span&gt;. On the "Internet Account Service" screen, enter the username and password that you got from your service provider (e.g: john_doe@aol.com) and click &lt;span style="font-weight: bold;"&gt;next&lt;/span&gt;. On the "access control" screen, you have the chance to change the default username/password used to access the router's configuration interface, or leave it with the default "Administrator" account. Click &lt;span style="font-weight: bold;"&gt;next&lt;/span&gt; once again, check the information on the summary screen and click &lt;span style="font-weight: bold;"&gt;start&lt;/span&gt;. Now, wait a few seconds for the router to perform the configuration and press "finish" to reboot the router. Now, wait a minute while the router reboots.&lt;br /&gt;&lt;br /&gt;At this point, the client machines on your network are able to resolve DNS names but not to browse the Internet. To fix this, you will need to enable the network address translation (NAT) on the router. To do that, you have to run some few commands on the router's admin shell.&lt;br /&gt;&lt;br /&gt;6) Open a new shell session and telnet the router's IP. The username/password are the same that you've just set on the previous step:&lt;br /&gt;&lt;br /&gt;&lt;div class="shell"&gt;&lt;br /&gt;&lt;pre&gt;root@localhost:/home/leo# telnet 192.168.1.254&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;7) type the following commands to enable the NAT on the router:&lt;br /&gt;&lt;br /&gt;&lt;div class="shell"&gt;&lt;br /&gt;&lt;pre&gt;nat&lt;br /&gt;ifconfig intf=Internet translation=enabled&lt;br /&gt;tmpladd intf=Internet outside_addr=0.0.0.1&lt;br /&gt;saveall&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;8) Close the telnet session by typing &lt;span style="font-weight: bold;"&gt;exit&lt;/span&gt; and wait a few seconds while the router reloads its configuration. Now, wait a few seconds and test the Internet connection again.&lt;/enter&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2074177390835984643-8766146326244744843?l=leobsd.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2074177390835984643/posts/default/8766146326244744843'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2074177390835984643/posts/default/8766146326244744843'/><link rel='alternate' type='text/html' href='http://leobsd.blogspot.com/2009/04/setting-up-speedtouchthomsom-510-as-dsl.html' title='Speedtouch/Thomson 510v6 on the router mode'/><author><name>Leo</name><uri>http://www.blogger.com/profile/14181600774390961702</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://4.bp.blogspot.com/_9X5XZTyDLBA/Sbsn6wJfRxI/AAAAAAAAAN8/T79RqmQK0ss/S220/lab1-medium.jpeg'/></author></entry><entry><id>tag:blogger.com,1999:blog-2074177390835984643.post-6210988147828231467</id><published>2009-04-02T12:59:00.004-03:00</published><updated>2009-07-04T13:28:50.859-03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='notepad'/><title type='text'>SSH tunels</title><content type='html'>A few years ago, during my MSc research, I was looking for a way to access the IEEE Xplore from home. IEEE Xplore provides corporate/educational accounts, and they authenticate these accounts based on the requester's IP address. So, if you're inside a university/company which has one of these accounts, you're automatically authenticated based on your machine's IP address.&lt;br /&gt;&lt;br /&gt;But what if I'm at home and need to get a copy of that important white paper? Well, at that time, I just had one solution for this: connect to some SSH server on the university, open a text-mode web browser and look for the file at the IEEE Xplore website.&lt;br /&gt;&lt;br /&gt;And the change has came when I found this tip &lt;a href="http://www.gudlyf.com/2004/01/22/ieee-xplore-from-home"&gt;http://www.gudlyf.com/2004/01/22/ieee-xplore-from-home&lt;/a&gt;, teaching how to create SSH tunnels and redirect ports from a local machine to a remote SSH server.&lt;br /&gt;&lt;br /&gt;I found that this is also a pretty useful solution to secure the access to some web-based tools. A few days ago, I installed webmin to ease the management of my home webserver. For security reasons, I just allowed one single IP to access the webmin interface, 127.0.0.1 (the loopback interface in localhost). When I'm remote and I want to access the webmin UI, I just need to execute:&lt;br /&gt;&lt;br /&gt;&lt;div class="shell"&gt;&lt;pre&gt;user@OtherPC$ ssh -N -L &lt;span style="color: rgb(0, 153, 0);"&gt;10000&lt;/span&gt;:&lt;span style="color: rgb(255, 102, 0);"&gt;127.0.0.1:10000&lt;/span&gt; &lt;span style="color: rgb(0, 0, 153);"&gt;leo@MyWebServer.net&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;This creates a tunneled connection between OtherPC and MyWebServer, using my credentials as if I was simply SSHing &lt;span style="color: rgb(0, 0, 153);"&gt;leo@MyWebServer.net&lt;/span&gt;. It then redirects all the requests for the local port &lt;span style="color: rgb(0, 153, 0);"&gt;10000&lt;/span&gt; (at the OtherPC) through this SSH tunnel, and when they reach the tunnel's end, forward these requests to the &lt;span style="color: rgb(255, 102, 0);"&gt;127.0.0.1:10000&lt;/span&gt; address. In a nutshell, this allows me to type http://127.0.0.1:10000 on the OtherPC's Firefox and to access webmin (in MyWebServer's 10000 port) as I was sitting right in front of the MyWebServer's console.&lt;br /&gt;&lt;br /&gt;This is just one of the possible scenarios for SSH tunnels (a very simple scenario), but this is definetively a useful thing for when you just need to access some few resources in your private network but you don't want to set up a VPN server.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2074177390835984643-6210988147828231467?l=leobsd.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2074177390835984643/posts/default/6210988147828231467'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2074177390835984643/posts/default/6210988147828231467'/><link rel='alternate' type='text/html' href='http://leobsd.blogspot.com/2009/04/ssh-tunels.html' title='SSH tunels'/><author><name>Leo</name><uri>http://www.blogger.com/profile/14181600774390961702</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://4.bp.blogspot.com/_9X5XZTyDLBA/Sbsn6wJfRxI/AAAAAAAAAN8/T79RqmQK0ss/S220/lab1-medium.jpeg'/></author></entry><entry><id>tag:blogger.com,1999:blog-2074177390835984643.post-5200359246548724909</id><published>2009-03-27T10:22:00.013-03:00</published><updated>2009-07-04T13:28:50.859-03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='notepad'/><title type='text'>OpenVPN, step-by-step</title><content type='html'>&lt;span style="font-size:78%;"&gt;Special thanks to Cristiano Furtado dos Santos (http://jasonnfedora.eti.br) and Guilherme Rezende (http://www.vivaolinux.com.br/artigo/VPN-em-Linux-com-OpenVPN/)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;I've finally set up a VPN to access my home's network from anywhere (and check whether my torrents have finished downloading or not). These are the exact steps I followed. I've also included some notes on how to fix common issues regarding the TUN device creation and how to debug your OpenVPN installation.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold;"&gt;1) Server configuration&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Cleaning up the environment:&lt;br /&gt;&lt;br /&gt;&lt;div class="shell"&gt;&lt;pre&gt;root@VPNserver # cd /usr/share/doc/openvpn/examples/easy-rsa/2.0&lt;br /&gt;root@VPNserver # . ./vars&lt;br /&gt;NOTE: If you run ./clean-all, I will be doing a rm -rf on /usr/share/doc/openvpn/examples/easy-rsa/2.0/keys&lt;br /&gt;root@VPNserver #&lt;br /&gt;root@VPNserver # ./clean-all&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Building the server keys:&lt;br /&gt;&lt;br /&gt;&lt;div class="shell"&gt;&lt;pre&gt;&lt;br /&gt;root@VPNserver # ./build-ca&lt;br /&gt;Generating a 1024 bit RSA private key&lt;br /&gt;..++++++&lt;br /&gt;....................................++++++&lt;br /&gt;writing new private key to 'ca.key'&lt;br /&gt;-----&lt;br /&gt;You are about to be asked to enter information that will be incorporated&lt;br /&gt;into your certificate request.&lt;br /&gt;What you are about to enter is what is called a Distinguished Name or a DN.&lt;br /&gt;There are quite a few fields but you can leave some blank&lt;br /&gt;For some fields there will be a default value,&lt;br /&gt;If you enter '.', the field will be left blank.&lt;br /&gt;-----&lt;br /&gt;Country Name (2 letter code) [US]:BR&lt;br /&gt;string is too long, it needs to be less than  2 bytes long&lt;br /&gt;Country Name (2 letter code) [US]:BR&lt;br /&gt;State or Province Name (full name) [CA]:Sao Paulo&lt;br /&gt;Locality Name (eg, city) [SanFrancisco]:Campinas&lt;br /&gt;Organization Name (eg, company) [Fort-Funston]: mycompany.com&lt;br /&gt;Organizational Unit Name (eg, section) []:NT&lt;br /&gt;Common Name (eg, your name or your server's hostname) [Fort-Funston CA]: VPNserver&lt;br /&gt;Email Address [me@myhost.mydomain]:admin@mycompany.com&lt;br /&gt;root@VPNserver #&lt;br /&gt;root@VPNserver # ./build-key-server server&lt;br /&gt;Generating a 1024 bit RSA private key&lt;br /&gt;...............++++++&lt;br /&gt;.....................++++++&lt;br /&gt;writing new private key to 'server.key'&lt;br /&gt;-----&lt;br /&gt;You are about to be asked to enter information that will be incorporated&lt;br /&gt;into your certificate request.&lt;br /&gt;What you are about to enter is what is called a Distinguished Name or a DN.&lt;br /&gt;There are quite a few fields but you can leave some blank&lt;br /&gt;For some fields there will be a default value,&lt;br /&gt;If you enter '.', the field will be left blank.&lt;br /&gt;-----&lt;br /&gt;Country Name (2 letter code) [US]:BR&lt;br /&gt;State or Province Name (full name) [CA]:Sao Paulo&lt;br /&gt;Locality Name (eg, city) [SanFrancisco]: Campinas&lt;br /&gt;Organization Name (eg, company) [Fort-Funston]:mycompany.com&lt;br /&gt;Organizational Unit Name (eg, section) []:NTI&lt;br /&gt;Common Name (eg, your name or your server's hostname) [server]: VPNserver&lt;br /&gt;Email Address [me@myhost.mydomain]:admin@mycompany.com&lt;br /&gt;&lt;br /&gt;Please enter the following 'extra' attributes&lt;br /&gt;to be sent with your certificate request&lt;br /&gt;A challenge password []:&lt;br /&gt;An optional company name []:&lt;br /&gt;Using configuration from /usr/share/doc/openvpn/examples/easy-rsa/2.0/openssl.cnf&lt;br /&gt;Check that the request matches the signature&lt;br /&gt;Signature ok&lt;br /&gt;The Subject's Distinguished Name is as follows&lt;br /&gt;countryName           :PRINTABLE:'BR'&lt;br /&gt;stateOrProvinceName   :PRINTABLE:'Sao Paulo'&lt;br /&gt;localityName          :PRINTABLE:'Campinas'&lt;br /&gt;organizationName      :PRINTABLE:'mycompany.com'&lt;br /&gt;organizationalUnitName:PRINTABLE:'NTI'&lt;br /&gt;commonName            :PRINTABLE:'VPNserver'&lt;br /&gt;emailAddress          :IA5STRING:'admin@mycompany.com'&lt;br /&gt;Certificate is to be certified until Mar 25 11:43:43 2019 GMT (3650 days)&lt;br /&gt;Sign the certificate? [y/n]:y&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;1 out of 1 certificate requests certified, commit? [y/n]y&lt;br /&gt;Write out database with 1 new entries&lt;br /&gt;Data Base Updated&lt;br /&gt;&lt;br /&gt;root@VPNserver #&lt;br /&gt;root@VPNserver #&lt;br /&gt;root@VPNserver # ./build-dh&lt;br /&gt;Generating DH parameters, 1024 bit long safe prime, generator 2&lt;br /&gt;This is going to take a long time&lt;br /&gt;...............+..................................+..........................................................+................................+..............................................+.................................................+.....................+........+............................................+..............................................................+........................................+................+...........................+...+..........+..............................+.....................................................+..........+.......+...............+..........................+...........................................................................+...............................+..............+....................................................................................................+............................+.........+...........++*++*++*&lt;br /&gt;&lt;br /&gt;root@VPNserver # cd keys&lt;br /&gt;root@VPNserver # rm *csr&lt;br /&gt;root@VPNserver # cp 0* ca.* dh1024.pem index.txt* serial* server.* /etc/openvpn/&lt;br /&gt;root@VPNserver #&lt;br /&gt;root@VPNserver # echo "&lt;br /&gt;local 200.201.202.203   # My VPN server's IP&lt;br /&gt;port 1194               # Local Port&lt;br /&gt;proto udp&lt;br /&gt;dev tun&lt;br /&gt;ca ca.crt&lt;br /&gt;cert server.crt&lt;br /&gt;key server.key          # This file should be kept secret&lt;br /&gt;dh dh1024.pem&lt;br /&gt;server 10.10.10.0 255.255.255.0&lt;br /&gt;ifconfig-pool-persist ipp.txt&lt;br /&gt;push "route 192.168.1.0 255.255.255.0"&lt;br /&gt;client-to-client&lt;br /&gt;keepalive 10 120&lt;br /&gt;comp-lzo&lt;br /&gt;user nobody&lt;br /&gt;group nogroup&lt;br /&gt;persist-key&lt;br /&gt;persist-tun&lt;br /&gt;#status /var/log/openvpn-status.log&lt;br /&gt;#log         /var/log/openvpn.log&lt;br /&gt;#log-append  /var/log/openvpn.log&lt;br /&gt;#verb 3&lt;br /&gt;" &gt; /etc/openvpn/server.conf&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold;"&gt;2) Adding users&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;2.1) Building the user keys&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="shell"&gt;&lt;pre&gt;&lt;br /&gt;root@VPNserver # ./build-key leo&lt;br /&gt;Generating a 1024 bit RSA private key&lt;br /&gt;...............................................................++++++&lt;br /&gt;.++++++&lt;br /&gt;writing new private key to 'leo.key'&lt;br /&gt;-----&lt;br /&gt;You are about to be asked to enter information that will be incorporated&lt;br /&gt;into your certificate request.&lt;br /&gt;What you are about to enter is what is called a Distinguished Name or a DN.&lt;br /&gt;There are quite a few fields but you can leave some blank&lt;br /&gt;For some fields there will be a default value,&lt;br /&gt;If you enter '.', the field will be left blank.&lt;br /&gt;-----&lt;br /&gt;Country Name (2 letter code) [US]:BR&lt;br /&gt;State or Province Name (full name) [CA]:Sao Paulo&lt;br /&gt;Locality Name (eg, city) [SanFrancisco]:Campinas&lt;br /&gt;Organization Name (eg, company) [Fort-Funston]:mycompany.com&lt;br /&gt;Organizational Unit Name (eg, section) []:NTI&lt;br /&gt;Common Name (eg, your name or your server's hostname) [leo]:&lt;br /&gt;Email Address [me@myhost.mydomain]:leo@mycompany.com&lt;br /&gt;&lt;br /&gt;Please enter the following 'extra' attributes&lt;br /&gt;to be sent with your certificate request&lt;br /&gt;A challenge password []:&lt;br /&gt;An optional company name []:&lt;br /&gt;Using configuration from /usr/share/doc/openvpn/examples/easy-rsa/2.0/openssl.cnf&lt;br /&gt;Check that the request matches the signature&lt;br /&gt;Signature ok&lt;br /&gt;The Subject's Distinguished Name is as follows&lt;br /&gt;countryName           :PRINTABLE:'BR'&lt;br /&gt;stateOrProvinceName   :PRINTABLE:'Sao Paulo'&lt;br /&gt;localityName          :PRINTABLE:'Campinas'&lt;br /&gt;organizationName      :PRINTABLE:'mycompany.com'&lt;br /&gt;organizationalUnitName:PRINTABLE:'NTI'&lt;br /&gt;commonName            :PRINTABLE:'leo'&lt;br /&gt;emailAddress          :IA5STRING:'leo@mycompany.com'&lt;br /&gt;Certificate is to be certified until Mar 25 11:45:50 2019 GMT (3650 days)&lt;br /&gt;Sign the certificate? [y/n]:y&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;1 out of 1 certificate requests certified, commit? [y/n]y&lt;br /&gt;Write out database with 1 new entries&lt;br /&gt;Data Base Updated&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;2.2) Preparing the files that will be used on the client machines&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="shell"&gt;&lt;pre&gt;&lt;br /&gt;root@VPNserver # mkdir /root/vpnconfig&lt;br /&gt;root@VPNserver # # Creating a generic config file for the client machines&lt;br /&gt;root@VPNserver #&lt;br /&gt;root@VPNserver # echo "&lt;br /&gt;client&lt;br /&gt;dev tun&lt;br /&gt;proto udp&lt;br /&gt;remote 200.201.202.203 1194&lt;br /&gt;resolv-retry infinite&lt;br /&gt;nobind&lt;br /&gt;persist-key&lt;br /&gt;persist-tun&lt;br /&gt;ca ca.crt&lt;br /&gt;cert leo.crt&lt;br /&gt;key leo.key&lt;br /&gt;comp-lzo&lt;br /&gt;verb 3&lt;br /&gt;" &gt; /root/vpnconfig/vpn.conf&lt;br /&gt;&lt;br /&gt;root@VPNserver # cd /usr/share/doc/openvpn/examples/easy-rsa/2.0/keys&lt;br /&gt;root@VPNserver # cp leo.{crt,key} ca.crt /root/vpnconfig;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;One additional step for users that might want do connect to the VPN server using OpenVPN for Windows:&lt;br /&gt;&lt;div class="shell"&gt;&lt;pre&gt;&lt;br /&gt;root@VPNserver # unix2dos /root/vpnconfig/vpn.conf&lt;br /&gt;root@VPNserver # mv /root/vpnconfig/vpn.conf /root/vpnconfig/vpn.ovpn&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Now, we create a pack with the files configured for this particular user:&lt;br /&gt;&lt;div class="shell"&gt;&lt;pre&gt;&lt;br /&gt;root@VPNserver # cd /root/vpnconfig&lt;br /&gt;root@VPNserver # tar cf leo.tar *&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Now, figure out what's the best (and safe) way to send this to the user. For linux vpn clients, the files show /etc/openvpn. For windows clients, unpack the tarball on the C:\Program Files\OpenVPN\config directory&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;3) Starting the VPN&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:100%;"&gt;3.1) on the server's side&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="shell"&gt;&lt;pre&gt;root@VPNserver # /etc/init.d/openvpn start&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;or&lt;br /&gt;&lt;br /&gt;&lt;div class="shell"&gt;&lt;pre&gt;root@VPNserver # openvpn --config /etc/openvpn/server.conf --daemon&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="shell"&gt;&lt;pre&gt;root@VPNserver # # If the following line shows something, we're fine&lt;br /&gt;root@VPNserver # ifconfig tun0&lt;br /&gt;tun0      Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00&lt;br /&gt;     inet addr:10.10.10.1  P-t-P:10.10.10.2  Mask:255.255.255.255&lt;br /&gt;     UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1500  Metric:1&lt;br /&gt;     RX packets:0 errors:0 dropped:0 overruns:0 frame:0&lt;br /&gt;     TX packets:0 errors:0 dropped:0 overruns:0 carrier:0&lt;br /&gt;     collisions:0 txqueuelen:100&lt;br /&gt;     RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Enabling the packet forwarding on the server's side:&lt;br /&gt;&lt;div class="shell"&gt;&lt;pre&gt;root@VPNserver # echo 1 &gt; /proc/sys/net/ipv4/ip_forward&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Add a route for the client's private network (10.0.0.10 is the IP of the interface tun0 in VPNclient)&lt;br /&gt;&lt;div class="shell"&gt;&lt;pre&gt;root@VPNserver # route add -net 192.168.2.0/24 gw 10.0.0.10&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;3.2) on the client's side&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="shell"&gt;&lt;pre&gt;root@VPNclient # /etc/init.d/openvpn start&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;or&lt;br /&gt;&lt;br /&gt;&lt;div class="shell"&gt;&lt;pre&gt;root@VPNclient # openvpn --config /etc/openvpn/vpn.conf --daemon&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;If the following line shows something, we're fine.&lt;br /&gt;&lt;br /&gt;&lt;div class="shell"&gt;&lt;pre&gt;root@VPNclient # ifconfig tun0&lt;br /&gt;tun0      Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00&lt;br /&gt;     inet addr:10.10.10.10  P-t-P:10.10.10.9  Mask:255.255.255.255&lt;br /&gt;     UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1500  Metric:1&lt;br /&gt;     RX packets:8 errors:0 dropped:0 overruns:0 frame:0&lt;br /&gt;     TX packets:8 errors:0 dropped:0 overruns:0 carrier:0&lt;br /&gt;     collisions:0 txqueuelen:100&lt;br /&gt;     RX bytes:672 (672.0 B)  TX bytes:672 (672.0 B)&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Enabling the packet forwarding on the client side:&lt;br /&gt;&lt;div class="shell"&gt;&lt;pre&gt;root@VPNclient # echo 1 &gt; /proc/sys/net/ipv4/ip_forward&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Add a route for the client's private network (10.0.0.1 is the IP of the interface tun0 in VPNserver)&lt;br /&gt;&lt;br /&gt;&lt;div class="shell"&gt;&lt;pre&gt;root@VPNclient # route add -net 192.168.1.0/24 gw 10.0.0.1&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-size:130%;" &gt;4) Testing&lt;/span&gt;&lt;br /&gt;Pinging a machine on the server's private network&lt;br /&gt;&lt;div class="shell"&gt;&lt;pre&gt;root@VPNclient # ping 192.168.1.199&lt;br /&gt;PING 192.168.1.199 (192.168.1.199) 56(84) bytes of data.&lt;br /&gt;64 bytes from 192.168.1.199: icmp_seq=1 ttl=127 time=62.4 ms&lt;br /&gt;64 bytes from 192.168.1.199: icmp_seq=2 ttl=127 time=58.7 ms&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Pinging a machine on the client's private network&lt;br /&gt;&lt;br /&gt;&lt;div class="shell"&gt;&lt;pre&gt;root@VPNserver # ping 192.168.2.10&lt;br /&gt;PING 192.168.2.10 (192.168.2.10) 56(84) bytes of data.&lt;br /&gt;64 bytes from 192.168.2.10: icmp_seq=1 ttl=127 time=61.9 ms&lt;br /&gt;64 bytes from 192.168.2.10: icmp_seq=2 ttl=127 time=58.9 ms&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;5) Troubleshooting:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;5.1) Firewall-related issues.&lt;/span&gt; Make sure that the needed ports are properly opened (Thanks to Cristiano Furtado dos Santos (http://jasonnfedora.eti.br))&lt;br /&gt;&lt;div class="shell"&gt;&lt;pre&gt;root@VPNserver # iptables -A INPUT -s 10.10.10.0/16 -j ACCEPT&lt;br /&gt;root@VPNserver #&lt;br /&gt;root@VPNserver # iptables -A INPUT -p udp --dport 1194 -j ACCEPT&lt;br /&gt;root@VPNserver # iptables -A OUTPUT -p udp --sport 1194 -j ACCEPT&lt;br /&gt;root@VPNserver #&lt;br /&gt;root@VPNserver # iptables -A INPUT -i tun+ -j ACCEPT&lt;br /&gt;root@VPNserver # iptables -A OUTPUT -o tun+ -j ACCEPT&lt;br /&gt;root@VPNserver # iptables -A FORWARD -i tun+ -j ACCEPT&lt;br /&gt;root@VPNserver # iptables -A INPUT -i tap+ -j ACCEPT&lt;br /&gt;root@VPNserver # iptables -A OUTPUT -o tap+ -j ACCEPT&lt;br /&gt;root@VPNserver # iptables -A FORWARD -i tap+ -j ACCEPT&lt;br /&gt;root@VPNserver # iptables -A INPUT -i ppp+ -j ACCEPT&lt;br /&gt;root@VPNserver # iptables -A OUTPUT -o ppp+ -j ACCEPT&lt;br /&gt;root@VPNserver # iptables -A FORWARD -i ppp+ -j ACCEPT&lt;br /&gt;root@VPNserver # iptables -A INPUT -p gre -j ACCEPT&lt;br /&gt;root@VPNserver #&lt;br /&gt;root@VPNserver # iptables -t nat -A PREROUTING -p tcp -m tcp --dport 139 -m state --state NEW -j ACCEPT&lt;br /&gt;root@VPNserver # iptables -t nat -A PREROUTING -p tcp -m tcp --dport 445 -m state --state NEW -j ACCEPT&lt;br /&gt;root@VPNserver #&lt;br /&gt;root@VPNserver # iptables -t nat -A PREROUTING -p tcp -m tcp --dport 137 -m state --state NEW -j ACCEPT&lt;br /&gt;root@VPNserver # iptables -t nat -A PREROUTING -p tcp -m tcp --dport 138 -m state --state NEW -j ACCEPT&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;5.2) OpenVPN debugging messages:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;You can always run openVPN in the foreground and let it flood your stdout with debug messages:&lt;br /&gt;&lt;br /&gt;&lt;div class="shell"&gt;&lt;pre&gt;root@VPNserver # openvpn --config /etc/openvpn/server.conf&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;or you can optionally uncomment the following lines from your server.conf&lt;br /&gt;&lt;br /&gt;&lt;div class="shell"&gt;&lt;pre&gt;#status /var/log/openvpn-status.log&lt;br /&gt;#log         /var/log/openvpn.log&lt;br /&gt;#log-append  /var/log/openvpn.log&lt;br /&gt;#verb 3&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;5.3) The TUN/TAP error:&lt;/span&gt;&lt;br /&gt;&lt;div class="shell"&gt;&lt;pre&gt;&lt;br /&gt;Note: Cannot open TUN/TAP dev /dev/net/tun: No such file or directory (errno=2)&lt;br /&gt;Note: Attempting fallback to kernel 2.2 TUN/TAP interface&lt;br /&gt;&lt;br /&gt;Tried opening /dev/tun0 (failed): No such file or directory (errno=2)&lt;br /&gt;Tried opening /dev/tun1 (failed): No such file or directory (errno=2)&lt;br /&gt;...&lt;br /&gt;Tried opening /dev/tun255 (failed): No such file or directory (errno=2)&lt;br /&gt;Cannot allocate TUN/TAP dev dynamically&lt;br /&gt;Exiting&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Solution:&lt;br /&gt;&lt;div class="shell"&gt;&lt;pre&gt;root@VPNserver # mkdir /dev/net; mknod /dev/net/tun c 10 200&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;5.4) The TLS_ERROR:&lt;/span&gt;&lt;br /&gt;&lt;div class="shell"&gt;&lt;pre&gt;&lt;br /&gt;Thu Apr  2 12:27:07 2009 TLS: Initial packet from 200.202.220.53:1194, sid=1422627c d18b4e4f&lt;br /&gt;Thu Apr  2 12:27:07 2009 VERIFY ERROR: depth=0, error=unable to get local issuer certificate: /C=BR/ST=Sao_Paulo/L=Campinas/O=My_company/OU=NTI/CN=VPNserver/emailAddress=leo@mycompany.com&lt;br /&gt;Thu Apr  2 12:27:07 2009 TLS_ERROR: BIO read tls_read_plaintext error: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed&lt;br /&gt;Thu Apr  2 12:27:07 2009 TLS Error: TLS object -&gt; incoming plaintext read error&lt;br /&gt;Thu Apr  2 12:27:07 2009 TLS Error: TLS handshake failed&lt;br /&gt;Thu Apr  2 12:27:07 2009 TCP/UDP: Closing socket&lt;br /&gt;Thu Apr  2 12:27:07 2009 SIGUSR1[soft,tls-error] received, process restarting&lt;br /&gt;Thu Apr  2 12:27:07 2009 Restart pause, 2 second(s)&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Solution:&lt;br /&gt;1) check whether you have copied the needed files (ca.crt, user.key, user.crt, vpn.conf) to the client machine (look into the config file for the correct filenames and check whether they are in the same directory as the config file)&lt;br /&gt;2) try to restart the openvpn daemon is running on both sides&lt;br /&gt;3) If it still fails, take a look at the logs and google it :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2074177390835984643-5200359246548724909?l=leobsd.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2074177390835984643/posts/default/5200359246548724909'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2074177390835984643/posts/default/5200359246548724909'/><link rel='alternate' type='text/html' href='http://leobsd.blogspot.com/2009/03/openvpn-quick-n-dirty-guide.html' title='OpenVPN, step-by-step'/><author><name>Leo</name><uri>http://www.blogger.com/profile/14181600774390961702</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://4.bp.blogspot.com/_9X5XZTyDLBA/Sbsn6wJfRxI/AAAAAAAAAN8/T79RqmQK0ss/S220/lab1-medium.jpeg'/></author></entry><entry><id>tag:blogger.com,1999:blog-2074177390835984643.post-8749388682933204815</id><published>2009-03-23T23:43:00.005-03:00</published><updated>2009-07-04T13:28:50.859-03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='notepad'/><title type='text'>Concatenate PS/PDF files</title><content type='html'>It's Sunday morning. You've just download the 25th chapter of that book you love, which is available as 25 different PDFs. You save them all in a folder and you're finally ready to start reading it from the very beginning! Here you go!&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Problem #&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;1:&lt;/span&gt; You decided to print the book. But wait, there are 25 files! Ok, forget about it... start reading on the computer.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Problem #&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;2:&lt;/span&gt; You want to send that book for your mom. She would love that! Hey, but how to attach 25 files to an e-mail? And you think "Well, why don't I buy her the new Paul McCartney DVD?"&lt;br /&gt;&lt;br /&gt;Dealing with dozens of PDF files may be confusing and take an extra effort to keep them organized. Sometimes, the best thing to do is to simply concatenate them all in a single PDF. This is pretty simple to do in Linux, using the GhostScript program (yeah... and you were thinking that GS was solely intended to create PostScript documents, huh? ;-) ). The following example concatenates all the PDFs matching myfiles*pdf and another file called another_file.pdf, saving them all as a single document called all_files.pdf:&lt;br /&gt;&lt;br /&gt;&lt;div class="shell"&gt;gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=all_files.pdf myfiles*pdf another_file.pdf&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;To do the same for a bunch of PostScript files, do the following:&lt;br /&gt;&lt;br /&gt;&lt;div class="shell"&gt;gs -dBATCH -dNOPAUSE -q -sDEVICE=pswrite -sOutputFile=all_files.ps myfiles*ps another_file.ps&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;That's it ;-)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2074177390835984643-8749388682933204815?l=leobsd.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2074177390835984643/posts/default/8749388682933204815'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2074177390835984643/posts/default/8749388682933204815'/><link rel='alternate' type='text/html' href='http://leobsd.blogspot.com/2009/03/concatenate-pdf-files-in-linux.html' title='Concatenate PS/PDF files'/><author><name>Leo</name><uri>http://www.blogger.com/profile/14181600774390961702</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://4.bp.blogspot.com/_9X5XZTyDLBA/Sbsn6wJfRxI/AAAAAAAAAN8/T79RqmQK0ss/S220/lab1-medium.jpeg'/></author></entry><entry><id>tag:blogger.com,1999:blog-2074177390835984643.post-1000446529895301733</id><published>2009-03-22T19:01:00.005-03:00</published><updated>2009-07-04T13:28:50.859-03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='notepad'/><title type='text'>Error checking in Python using regular expressions</title><content type='html'>Everyone makes mistakes, so is not fair to say that "users are stupid" as an excuse when your application crashes due to user error. If you're a developer and your interface is so poorly designed that no one understands it and no error checking/handling is made, please don't blame the users &lt;span style="font-size:85%;"&gt;(*)&lt;/span&gt;. They probably just want to run that damn piece of software to execute some boring/complex task, and they don't want it to crash because they'll have to restart it over again ;-)&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Regular expressions&lt;/b&gt; are very useful for checking errors in input text fields. Here you can find an example of how to validate an IP address or MAC address typed by the user. This is a pretty simple example, but you can use it as a base for whatever checking you need:&lt;br /&gt;&lt;br /&gt;&lt;div class="shell"&gt;&lt;pre&gt;&lt;br /&gt;&gt;&gt;&gt; pattern={\&lt;br /&gt;... 'ip': re.compile(r"^(?:(?:25[0-5]\&lt;br /&gt;... |2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25\&lt;br /&gt;... [0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"),\&lt;br /&gt;... 'mac': re.compile(r"^[0-9a-fA-F]{2}\:\&lt;br /&gt;... [0-9a-fA-F]{2}\:[0-9a-fA-F]{2}\:[0-9a-fA-F]\&lt;br /&gt;... {2}\:[0-9a-fA-F]{2}\:[0-9a-fA-F]{2}$")}&lt;br /&gt;&gt;&gt;&gt;&lt;br /&gt;&gt;&gt;&gt; # Is it a valid IP address?&lt;br /&gt;... def valid_ip(address):&lt;br /&gt;...     if pattern['ip'].match(address) == None:&lt;br /&gt;...         return False&lt;br /&gt;...     return True&lt;br /&gt;...&lt;br /&gt;&gt;&gt;&gt; valid_ip("192.168.0.1")&lt;br /&gt;True&lt;br /&gt;&gt;&gt;&gt; valid_ip("192.168.0.457")&lt;br /&gt;False&lt;br /&gt;&gt;&gt;&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;span style="font-size:85%;"&gt;(*) If you truly believe that every user wants to mess with you... man, go to a shrink. I'm not kidding.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2074177390835984643-1000446529895301733?l=leobsd.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2074177390835984643/posts/default/1000446529895301733'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2074177390835984643/posts/default/1000446529895301733'/><link rel='alternate' type='text/html' href='http://leobsd.blogspot.com/2009/03/error-checking-in-python-using-regular.html' title='Error checking in Python using regular expressions'/><author><name>Leo</name><uri>http://www.blogger.com/profile/14181600774390961702</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://4.bp.blogspot.com/_9X5XZTyDLBA/Sbsn6wJfRxI/AAAAAAAAAN8/T79RqmQK0ss/S220/lab1-medium.jpeg'/></author></entry><entry><id>tag:blogger.com,1999:blog-2074177390835984643.post-4741789871486033161</id><published>2009-03-17T23:45:00.007-03:00</published><updated>2009-07-04T13:28:50.859-03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='notepad'/><title type='text'>Linux Swap in a file</title><content type='html'>Three years ago I was installing Debian in my laptop and was thinking "do I really need a swap partition?". I believe that most of you,  once in a while, have spent some minutes staring at the partitioner screen, thinking on that.&lt;br /&gt;&lt;br /&gt;At that time, the 1GB RAM of my laptop was more than I ever needed and I had many reasons to believe that nobody would never use more than 1GB RAM on a laptop... and now I can say I was completely wrong :-) I decided to not install the Linux swap... keeping one of my disk partitions reserved for the Linux Swap seemed to be worthless.&lt;br /&gt;&lt;br /&gt;Well, it's been 3 years since I installed Debian here in my laptop... and now my 1GB RAM is fully used most of time. You may be wondering "why?", "What have changed in three years?". Ok, give a try to gnome+screenlets+gdesklets+compiz and you will certainly know what I'm talking about ;-)&lt;br /&gt;&lt;br /&gt;The problem was that I didn't have any swap spaces installed and I didn't want to touch my disk's partitions neither wanted to reinstall the whole system... I just wanted a quick and simple solution for the swap problem. And then I found &lt;span style="font-weight: bold;"&gt;mkswap&lt;/span&gt;. It allows you create a swap space in a single file, which can be stored wherever you want in your filesystem. Here is an example situation. On the example below, I'm creating a 1GB swap, and will store it on the root filesystem in my Linux partition:&lt;br /&gt;&lt;br /&gt;&lt;div class="shell"&gt;&lt;pre&gt;root@localhost# dd if=/dev/zero of=/swapfile bs=1024 count=1024000&lt;br /&gt;root@localhost# mkswap /swapfile&lt;br /&gt;root@localhost# swapon /swapfile&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;And that's enough. I'm pretty sure that nobody would never use more than 2GB of RAM on a laptop. I guess. Well, maybe 1.5GB, but no more than 2GB. Or maybe not. Well, anyway, I guess I'm gonna buy an additional 1GB memory module... just in case... :-)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2074177390835984643-4741789871486033161?l=leobsd.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2074177390835984643/posts/default/4741789871486033161'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2074177390835984643/posts/default/4741789871486033161'/><link rel='alternate' type='text/html' href='http://leobsd.blogspot.com/2009/03/linux-swap-in-file.html' title='Linux Swap in a file'/><author><name>Leo</name><uri>http://www.blogger.com/profile/14181600774390961702</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://4.bp.blogspot.com/_9X5XZTyDLBA/Sbsn6wJfRxI/AAAAAAAAAN8/T79RqmQK0ss/S220/lab1-medium.jpeg'/></author></entry><entry><id>tag:blogger.com,1999:blog-2074177390835984643.post-8883795677442840027</id><published>2009-03-16T22:10:00.006-03:00</published><updated>2009-07-04T13:28:50.859-03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='notepad'/><title type='text'>Processing command line parameters</title><content type='html'>Sometimes, dealing with command line parameters is pretty useful for configuration scripts. After some minutes banging my head against the wall, I found the solution for that. Here are example scripts for Python and Shell script:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;In python&lt;/span&gt;&lt;br /&gt;&lt;div class="shell"&gt;&lt;pre&gt;user@localhost:~$ cat command_line.py&lt;br /&gt;import getopt&lt;br /&gt;import sys&lt;br /&gt;&lt;br /&gt;def start(argv):&lt;br /&gt;opts, args = getopt.getopt( argv[ 1: ], "n:a", ("name=", "age=" ))&lt;br /&gt;print "Arguments: ", opts&lt;br /&gt;for opt,arg in opts:&lt;br /&gt;if opt in ( "-n", "--name" ):&lt;br /&gt;print "The user typed his name: %s" %arg&lt;br /&gt;elif opt in ( "-a", "--age" ):&lt;br /&gt;print "The user typed his age: %s" %arg&lt;br /&gt;&lt;br /&gt;start(sys.argv)&lt;br /&gt;user@localhost:~$&lt;br /&gt;user@localhost:~$&lt;br /&gt;user@localhost:~$ python command_line.py --name="Leo" --age=26&lt;br /&gt;Arguments:  [('--name', 'Leo'), ('--age', '27')]&lt;br /&gt;The user typed his name: Leo&lt;br /&gt;The user typed his age: 27&lt;br /&gt;user@localhost:~$&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;In Shell script&lt;/span&gt;&lt;br /&gt;&lt;div class="shell"&gt;&lt;pre&gt;user@localhost:~$ cat command_line.sh&lt;br /&gt;#!/bin/bash&lt;br /&gt;&lt;br /&gt;NAME=""&lt;br /&gt;AGE=""&lt;br /&gt;&lt;br /&gt;if [ $# -gt 0 ]; then&lt;br /&gt;while [ $# -gt 0 ];do&lt;br /&gt;if [ "$1" == "--name" ];then&lt;br /&gt;  if [ -n "$2" ]; then&lt;br /&gt;      NAME=$2&lt;br /&gt;  fi&lt;br /&gt;  shift&lt;br /&gt;  shift&lt;br /&gt;elif [ "$1" == "--age" ]; then&lt;br /&gt;  if [ -n "$2" ]; then&lt;br /&gt;      AGE=$2&lt;br /&gt;  fi&lt;br /&gt;  shift&lt;br /&gt;  shift&lt;br /&gt;else&lt;br /&gt;  echo "Unknown option: $1"&lt;br /&gt;  shift&lt;br /&gt;fi&lt;br /&gt;done&lt;br /&gt;fi&lt;br /&gt;&lt;br /&gt;echo -e "NAME: $NAME\nAGE: $AGE"&lt;br /&gt;&lt;br /&gt;user@localhost:~$&lt;br /&gt;user@localhost:~$&lt;br /&gt;user@localhost:~$ bash command_line.sh --name leo --age 27 --wrong&lt;br /&gt;Unknown option: --wrong&lt;br /&gt;NAME: leo&lt;br /&gt;AGE: 27&lt;br /&gt;user@localhost:~$&lt;br /&gt;user@localhost:~$ bash command_line.sh --name leo --age&lt;br /&gt;NAME: leo&lt;br /&gt;AGE:&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2074177390835984643-8883795677442840027?l=leobsd.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2074177390835984643/posts/default/8883795677442840027'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2074177390835984643/posts/default/8883795677442840027'/><link rel='alternate' type='text/html' href='http://leobsd.blogspot.com/2009/03/processing-command-line-parameters.html' title='Processing command line parameters'/><author><name>Leo</name><uri>http://www.blogger.com/profile/14181600774390961702</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://4.bp.blogspot.com/_9X5XZTyDLBA/Sbsn6wJfRxI/AAAAAAAAAN8/T79RqmQK0ss/S220/lab1-medium.jpeg'/></author></entry><entry><id>tag:blogger.com,1999:blog-2074177390835984643.post-4103312940910909119</id><published>2009-03-15T18:01:00.005-03:00</published><updated>2009-07-04T13:28:50.860-03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='notepad'/><title type='text'>OpenSSH - stdin: is not a tty</title><content type='html'>I'm using Debian testing (squeeze/sid) and the SSH/SCP stopped working after my last distro-upgrade.&lt;br /&gt;&lt;br /&gt;After executing the SSH client, the server was returning the error below:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Error:&lt;/b&gt;&lt;br /&gt;&lt;div class="shell"&gt;ssh -v root@SSHserver&lt;br /&gt;stdin: is not a tty&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Solution 1: you have physical access to the machine&lt;/b&gt;&lt;br /&gt;On the machine's console, log in as root and execute the following commands:&lt;br /&gt;&lt;br /&gt;&lt;div class="shell"&gt;root@SSHserver# mkdir /dev/pts&lt;br /&gt;root@SSHserver# mount -t devpts /dev/pts /dev/pts&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Solution 2: you only have remote access to the machine&lt;/b&gt;&lt;br /&gt;ssh to the target server again, but now remember to append a "/bin/sh" as the last argument. The "/bin/sh" on the command line basically tells the ssh client to ignore the normal logon process (which is not working) and to simply execute the "/bin/sh" right after the SSH authentication. This will give you a restricted shell on the target server instead of logging you on, but don't worry, you won't need anything else to fix the problem.&lt;br /&gt;&lt;br /&gt;In order to execute the recovering procedures, you'll need root privileges, so remember to inform &lt;b&gt;root&lt;/b&gt; as the user for the SSH authentication. After the authentication, the server will not return any sign of successful authentication. You will only be presented with a blinking cursor. To check whether you were successfully logged or not, you can simply type an 'ls' and check if you're actually seeing the remote server contents. After that, you can go ahead and execute the 'mkdir' and the 'mount' as shown in the box above.&lt;br /&gt;&lt;br /&gt;&lt;div class="shell"&gt;user@remoteMachine$ ssh root@SSHserver /bin/sh&lt;br /&gt;mkdir /dev/pts&lt;br /&gt;mount -t devpts /dev/pts /dev/pts&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Try again&lt;/b&gt;&lt;br /&gt;ssh to the the target server again and you'll be presented the Linux shell again :-D.&lt;br /&gt;&lt;br /&gt;You might also add the following line to the /etc/fstab to make devpts be automatically mounted on the next time you reboot the machine:&lt;br /&gt;&lt;br /&gt;&lt;div class="shell"&gt;none /dev/pts devpts defaults 0 0&lt;/div&gt;&lt;br /&gt;Well, that's all. If you have any question or similar solution, please leave a comment.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2074177390835984643-4103312940910909119?l=leobsd.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2074177390835984643/posts/default/4103312940910909119'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2074177390835984643/posts/default/4103312940910909119'/><link rel='alternate' type='text/html' href='http://leobsd.blogspot.com/2009/03/openssh-stdin-is-not-tty.html' title='OpenSSH - stdin: is not a tty'/><author><name>Leo</name><uri>http://www.blogger.com/profile/14181600774390961702</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://4.bp.blogspot.com/_9X5XZTyDLBA/Sbsn6wJfRxI/AAAAAAAAAN8/T79RqmQK0ss/S220/lab1-medium.jpeg'/></author></entry><entry><id>tag:blogger.com,1999:blog-2074177390835984643.post-3489597700679148581</id><published>2009-03-14T04:17:00.003-03:00</published><updated>2009-07-04T13:28:50.860-03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='notepad'/><title type='text'>Case/switch statements in Python</title><content type='html'>&lt;pre&gt;Python does not have a case/switch statement, but you can easily work this around in two steps:&lt;br /&gt;&lt;br /&gt;&gt;&gt;&gt; def exit_ok():&lt;br /&gt;...     print "OK"&lt;br /&gt;...&lt;br /&gt;&gt;&gt;&gt; def exit_error():&lt;br /&gt;...     print "ERROR"&lt;br /&gt;...&lt;br /&gt;&gt;&gt;&gt; def exit_dontpanic():&lt;br /&gt;...     print "AAAH! PANIC! RUN!"&lt;br /&gt;...&lt;br /&gt;... # 1) Create a dictionary with references to the&lt;br /&gt;... #    handler functions or whatever you was going&lt;br /&gt;... #    to call in your case/switch&lt;br /&gt;...&lt;br /&gt;&gt;&gt;&gt; functions = { 0: exit_ok,\&lt;br /&gt;...               1: exit_error,\&lt;br /&gt;...               2: exit_dontpanic }&lt;br /&gt;&gt;&gt;&gt;&lt;br /&gt;&gt;&gt;&gt; myrandomvar = 0&lt;br /&gt;&gt;&gt;&gt;&lt;br /&gt;&gt;&gt;&gt; # 2) Call the function&lt;br /&gt;... functions[myrandomvar]()&lt;br /&gt;OK&lt;br /&gt;&gt;&gt;&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;another good example is the conditional attribution. So if you have, for instance, to set the value of a variable according to a conditional statement, you can combine both steps (checking and attribution) in one single step:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&gt;&gt;&gt; cur=""&lt;br /&gt;&gt;&gt;&gt; var1="something"&lt;br /&gt;&gt;&gt;&gt; var2=False&lt;br /&gt;&gt;&gt;&gt;&lt;br /&gt;&gt;&gt;&gt; # This is how any code monkey makes a&lt;br /&gt;... # conditional attribution. People who &lt;br /&gt;... # like COCOMO would probably love that&lt;br /&gt;... if (var1 == "something") and (not var2):&lt;br /&gt;...     cur = "OK"&lt;br /&gt;... else:&lt;br /&gt;...     cur = "PANIC! RUN!"&lt;br /&gt;...&lt;br /&gt;&gt;&gt;&gt; # But if one does that, he would probably&lt;br /&gt;... # get a bad year-end evaluation...&lt;br /&gt;... status = { True: "OK", False: "AAAH! PANIC! RUN!" }&lt;br /&gt;&gt;&gt;&gt; cur = status[(var1 == "something") and (not var2)]&lt;br /&gt;&gt;&gt;&gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2074177390835984643-3489597700679148581?l=leobsd.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2074177390835984643/posts/default/3489597700679148581'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2074177390835984643/posts/default/3489597700679148581'/><link rel='alternate' type='text/html' href='http://leobsd.blogspot.com/2009/03/caseswitch-statements-in-python.html' title='Case/switch statements in Python'/><author><name>Leo</name><uri>http://www.blogger.com/profile/14181600774390961702</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://4.bp.blogspot.com/_9X5XZTyDLBA/Sbsn6wJfRxI/AAAAAAAAAN8/T79RqmQK0ss/S220/lab1-medium.jpeg'/></author></entry><entry><id>tag:blogger.com,1999:blog-2074177390835984643.post-3721119015348337326</id><published>2009-03-14T02:22:00.006-03:00</published><updated>2009-07-04T13:28:50.860-03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='notepad'/><title type='text'>...write it down!</title><content type='html'>"If you can't remember for long, just write it down". This kind of changed the way I deal with humans.&lt;br /&gt;&lt;br /&gt;Limited memory, limited processing power, limited autonomy (it requires a 30-minute recharging period for each hour awake!) and sometimes unpredictable behavior... but they still be a powerful and complex "machine".&lt;br /&gt;&lt;br /&gt;So why not look forward to improve the machine's performance, by taking some notes, by using on those modern calculate machines (some call them computers), by letting millions of brilliant&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://upload.wikimedia.org/wikipedia/commons/4/40/Child_and_Computer_08473.jpg"&gt;&lt;img style="margin: 0pt 0pt 10px 10px; float: right; cursor: pointer; width: 267px; height: 200px;" src="http://4.bp.blogspot.com/_9X5XZTyDLBA/SbtQHIWKMGI/AAAAAAAAAOg/Hpqebh1D4OA/s320/Child_and_Computer_08473_p.jpg" alt="" id="BLOGGER_PHOTO_ID_5312928268843364450" border="0" /&gt;&lt;/a&gt; minds around the World know your thoughts and help you on finding a better way use it? And what if everyone helped each other on doing that, sharing thoughts, on a continuous and collaborative process, making the overall humanity's knowledge grow?&lt;br /&gt;&lt;br /&gt;The complex and limited machine has turned a huge distributed system, and there's no way to stop it. Don't even try. You'd better look around, share, help, teach, learn... and if you can't tell the whole world what you've learned, just &lt;span style="font-style: italic;"&gt;blog it down&lt;/span&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2074177390835984643-3721119015348337326?l=leobsd.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2074177390835984643/posts/default/3721119015348337326'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2074177390835984643/posts/default/3721119015348337326'/><link rel='alternate' type='text/html' href='http://leobsd.blogspot.com/2009/03/write-it-down.html' title='...write it down!'/><author><name>Leo</name><uri>http://www.blogger.com/profile/14181600774390961702</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://4.bp.blogspot.com/_9X5XZTyDLBA/Sbsn6wJfRxI/AAAAAAAAAN8/T79RqmQK0ss/S220/lab1-medium.jpeg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_9X5XZTyDLBA/SbtQHIWKMGI/AAAAAAAAAOg/Hpqebh1D4OA/s72-c/Child_and_Computer_08473_p.jpg' height='72' width='72'/></entry></feed>
