trešdiena, 2011. gada 20. aprīlis

Applescript to check .LV short domain name availability

set the_list to {"q", "w", "e", "r", "t", "y", "u", "i", "o", "p", "a", "s", "d", "f", "g", "h", "j", "k", "l", "z", "x", "c", "v", "b", "n", "m", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}
tell application "Safari"
activate
set URL of document 1 to "https://www.nic.lv/client/check_domain"
delay 10
end tell


repeat with one_let in the_list
repeat with two_let in the_list
tell application "Safari"
do JavaScript "document.getElementById('domain').value = '" & one_let & two_let & "';" in document 1
do JavaScript "$('checkcontent').childElements()[0].submit();" in document 1

delay 5
repeat until ((do JavaScript "document.readyState" in document 1) is "complete")
delay 2
end repeat
end tell

end repeat
end repeat

otrdiena, 2009. gada 10. marts

Sharing internet between 250m. WDS

Some time ago I was trying to make WDS connection between two places for sharing one internet bill. That wasn't too hard to make, but I have learnt several things from building this.

This was great experience for me, because I had several problems and I always postponed creation of this connection. First I bought 2 cantannas from ebay (http://www.cantenna.com/).
Then I tried to make connection between WRT54GL and dir-300. None of original firmwares provide WDS connection support, so I had to install DD-WRT on both of these routers. But after a while I understood that dir-300 is really bad router - it was hanging all the time. So after a while I bought one more WRT54GL (this is really great router) and installed DD-WRT on that.

I had next problem - signal between two points was only 7%. At the first I didn't get, where is problem, but then I opened my PVC window and I had 30% signal! :)

So, great - everything worked just fine, but I had next problem :)
If my grandma plugs out my router from electricity and then I call her and say: "Hei, grandma, what are you doing, plug it back in." 
And here next problem comes up. It can't restore WDS connection, if it has been interapted. The only possibility to restore WDS connection is to turnoff-turnon both routers. This really isn't nice.
I investigated this a little and found WDS/Connection watchdog in DD-WRT control panel. So I happily activated this, but this doesn't work as it should. Yes - it restarts the router, but connection isn't restored. The only possibility to restore connection was changing wireless password (I guess that it restarts wireless part).
I didn't get deeply into DD-WRT commands on restarting wireless, so I created crontabs on both side servers. I call ruby program every 15 minutes and check if connection is available. In case of grandma, I change password on both routers. This also increase security, because I created 100 different passwords.





1. Architecture

2. Configuration details
2.1. Linksys WRT300N
This router is configured as gateway to internet and DHCP server is activated on this.
IP address is set to 192.168.1.1.
There are only some open ports to server, like 80 & 25.

2.2. Linksys WRT54GL DD-WRT first router
Remember to connect network cable to LAN port (not WAN port).
IP address is set to 192.168.1.2.
Subnet is set to 255.255.255.0.
Gateway is not changed from 0.0.0.0
WAN is disabled.
DHCP server is disabled.

Wireless name is set to: wirelessconnection
Channel: 7
Wireless mode: AP
Wireless security: WPA
WPA Algorithm: AES
Wireless password: wireless

Advanced settings.
Authentication type: Shared key
Frame Burst: Enabled
TX Antenna: Right (my cantenna was connected to right router antenna)
RX Antenna: Right (my cantenna was connected to right router antenna)
TX Power: 250
Afterburner: Enabled

WDS
Choose LAN and enter other router MAC address.

2.3. Linksys WRT54GL DD-WRT second router
Remember to connect network cable to LAN port (not WAN port).
IP address is set to 192.168.1.3.
Subnet is set to 255.255.255.0.
Gateway is not changed from 0.0.0.0
WAN is disabled.
DHCP server is disabled.

Wireless name is set to: wirelessconnection
Channel: 7
Wireless mode: AP
Wireless security: WPA
WPA Algorithm: AES
Wireless password: wireless

Advanced settings.
Authentication type: Shared key
Frame Burst: Enabled
TX Antenna: Right (my cantenna was connected to right router antenna)
RX Antenna: Right (my cantenna was connected to right router antenna)
TX Power: 250
Afterburner: Enabled

WDS
Choose LAN and enter first router MAC address.

2.4. Linksys WRT54GL
DHCP server is disabled.
IP address is set to 192.168.1.4.
Wireless is configured to have password.

3. Some problems I had creating this

3.1. PVC windows really decrease signal strength.
Put cantenna outside.
3.2. Cantenna comes with SMA end, but router WRT54GL have TNC end, so I had to buy connector from ebay.
RP-SMA female to RP-TNC male connector for WIFI antenna


3.3. Routers doesn't restore WDS connection if it is lost.
Ruby code that change password on both routers (restore connection):
require 'rubygems'
require 'net/http'
begin    
thread = Thread.new { `ping -c 1 -t 3 192.168.1.3` }    
puts "Waiting on the thread..."    
value = thread.value

if value.match(/1 received/).nil?    
puts "not connected"    
pwd = [ 'f9Up5asdasdUCE7a',
'WAxdsfdfdsfA2EMtAMet',
'bukasdsadsadabreswushe6',
[..97 more passwords..] ]
time = Time.now    
rez = ((time.year*(time.hour + 1)*time.month^2 + time.month*time.day*(time.hour + 1) + time.yday/(time.hour + 1) + (time.wday * 100 + (time.hour + 1)))/3)%100    
rez2 = (time.yday*4/3)%100    
password = pwd[rez]    
password2 = pwd[rez2]    

if time.min <>
password = "#{password}#{password2[2]}"    
elsif time.min <>
password = "#{password}#{password2[3]}"    
elsif time.min <>
password = "#{password}#{password2[4]}"    
elsif time.min <>
password = "#{password}#{password2[5]}"    
end    

res = Net::HTTP.post_form(URI.parse('http://root:admin@192.168.1.2/apply.cgi'),                                               {   'submit_button'=>'WL_WPATable',
                               'action'=>'ApplyTake',
       'change_action'=>'gozila_cgi',
                               'submit_type' => 'save',
                               'security_varname' => '',
                               'security_mode_last' => '',
                               'wl_wep_last' => '', 
                               'filter_mac_value' => '',
                               'wl0_security_mode' => 'psk',
                               'wl0_crypto' => 'aes',
                               'wl0_wpa_psk' => password,
                               'wl0_wl_unmask' => '0',
                               'wl0_wpa_gtk_rekey' => '3600' })
end
rescue
puts "ERROR"
end

3.4. Running WDS restoring code from both sides using crontab
Crontab on both servers (sudo crontab -e):
5,20,35,50 * * * * ruby /home/user/need/router.rb
5 7 * * * sudo ntpdate time.euro.apple.com



svētdiena, 2008. gada 17. februāris

Problem with auto_complete_for and protect_from_forgery

I was having problem with rails plugin auto_complete.
The problem is that when you use protect_from_forgery then auto_complete gives error.

Rails version: Rails 2.0.2

This I have in controller:
auto_complete_for :userEquipment, :name

This I have in view:
text_field_with_auto_complete :userEquipment, :name

But I was having such error:
ActionController::InvalidAuthenticityToken (ActionController::InvalidAuthenticityToken):

The answer is here in file auto_complete_macros_helper.rb

You need to change this line:
auto_complete_field("#{object}_#{method}", { :url => { :action => "auto_complete_for_#{object}_#{method}" } }.update(completion_options))
To this line:
auto_complete_field("#{object}_#{method}", { :url => { :action => "auto_complete_for_#{object}_#{method}", :authenticity_token => "#{form_authenticity_token}" } }.update(completion_options))

And now it's working!

But I'm new in Rails, so maybe there is nicer way. :)

sestdiena, 2008. gada 16. februāris

What is this blog about?

I'm now learning to make web application in rails and in learning process I'm having many small things that are not clearly described in internet. So, here I will share with these things.