Advertisement
Guest User

Untitled

a guest
May 28th, 2013
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. # myapp.rb
  2. require 'sinatra'
  3. require 'rubygems'
  4. require 'popen4'
  5. require 'rack/cors'
  6. require `logger`
  7.  
  8. set :bind, '0.0.0.0'
  9.  
  10.  
  11.  
  12.  
  13. ###SET LOGGING ON/OFF
  14. log = Logger.new('/tmp/log.txt')
  15. log.level = Logger::Error
  16.  
  17.  
  18.  
  19.  
  20. ###Needed to respond correctly to headers
  21. before do
  22. headers['Access-Control-Allow-Origin'] = "*"
  23. headers['Access-Control-Allow-Credentials'] = "true"
  24. headers['Access-Control-Expose-Headers'] = "Content-Type, Cache-Control, Expires, Etag, Last-Modified"
  25. end
  26.  
  27. options // do
  28. headers['Access-Control-Allow-Methods'] = "HEAD, GET, POST, PATCH, PUT, DELETE"
  29. headers['Access-Control-Allow-Headers'] = "Content-Type, Authorization, Accept, If-None-Match, If-Modified-Since"
  30. end
  31.  
  32. set :protection, :except => [:remote_token, :frame_options], :origin_whitelist => 'http://192.168.1.73'
  33.  
  34. #########################################
  35.  
  36.  
  37. ###############Authentication###########i
  38.  
  39. #use Rack::Cors do
  40. # allow do
  41. # origins '*'
  42. # resource '*', :headers => :any, :methods => [:get, :post, :options]
  43. # end
  44. # end
  45.  
  46. #use Rack::Auth::Basic, "Restricted Area" do |username, password|
  47. # username == 'admin' and password == 'admin'
  48. #end
  49.  
  50. ########################################
  51.  
  52.  
  53.  
  54.  
  55.  
  56. ####SETUP Wired Connection####
  57. get '/netconf' do
  58. connection_type= params[:net_type]
  59. sid = params[:sid]
  60. net_sec = params[:net_sec]
  61. wireless_pass = params[:wireless_pass]
  62. ipaddress = params[:local_ip]
  63. subnet = params[:subnetmask]
  64. defaultgw = params[:defaultgw]
  65. dns = params[:dns]
  66.  
  67. fork do
  68. if (connection_type == "wired")
  69. `ifconfig eth0 #{ipaddress} netmask #{subnet} up`
  70. `/sbin/route add default gw #{defaultgw}`
  71. `echo nameserver #{dns} > /etc/resolv.conf`
  72. elsif (connection_type == "wifi")
  73. `id > /tmp/id`
  74. `wpa_passphrase #{sid} #{wireless_pass} > /etc/wpa_supplicant.conf`
  75. test_lines=File.readlines('/etc/wpa_supplicant.conf')
  76. test_lines[-1]="\tkey_mgmt=WPA-PSK\n\tproto=WPA\n \} \n"
  77. text_lines = test_lines.join("")
  78. File.write("/etc/wpa_supplicant.conf",text_lines)
  79. fork do
  80. `/sbin/wpa_supplicant -iwlan3 -c/etc/wpa_supplicant.conf -Dwext `
  81. end
  82. sleep(5)
  83. `ifconfig wlan3 #{ipaddress} netmask #{subnet} up`
  84. `/sbin/route add default gw #{defaultgw}`
  85. `echo nameserver #{dns} > /etc/resolv.conf`
  86. elsif (connection_type == "3g")
  87. `sh /root/hiper_scripts/netconf.sh 3g`
  88. end
  89. end
  90. " Network Configuration Mode: #{connection_type} ipaddress assigned to box: #{ipaddress}/#{subnet} "
  91. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement