Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # myapp.rb
- require 'sinatra'
- require 'rubygems'
- require 'popen4'
- require 'rack/cors'
- require `logger`
- set :bind, '0.0.0.0'
- ###SET LOGGING ON/OFF
- log = Logger.new('/tmp/log.txt')
- log.level = Logger::Error
- ###Needed to respond correctly to headers
- before do
- headers['Access-Control-Allow-Origin'] = "*"
- headers['Access-Control-Allow-Credentials'] = "true"
- headers['Access-Control-Expose-Headers'] = "Content-Type, Cache-Control, Expires, Etag, Last-Modified"
- end
- options // do
- headers['Access-Control-Allow-Methods'] = "HEAD, GET, POST, PATCH, PUT, DELETE"
- headers['Access-Control-Allow-Headers'] = "Content-Type, Authorization, Accept, If-None-Match, If-Modified-Since"
- end
- set :protection, :except => [:remote_token, :frame_options], :origin_whitelist => 'http://192.168.1.73'
- #########################################
- ###############Authentication###########i
- #use Rack::Cors do
- # allow do
- # origins '*'
- # resource '*', :headers => :any, :methods => [:get, :post, :options]
- # end
- # end
- #use Rack::Auth::Basic, "Restricted Area" do |username, password|
- # username == 'admin' and password == 'admin'
- #end
- ########################################
- ####SETUP Wired Connection####
- get '/netconf' do
- connection_type= params[:net_type]
- sid = params[:sid]
- net_sec = params[:net_sec]
- wireless_pass = params[:wireless_pass]
- ipaddress = params[:local_ip]
- subnet = params[:subnetmask]
- defaultgw = params[:defaultgw]
- dns = params[:dns]
- fork do
- if (connection_type == "wired")
- `ifconfig eth0 #{ipaddress} netmask #{subnet} up`
- `/sbin/route add default gw #{defaultgw}`
- `echo nameserver #{dns} > /etc/resolv.conf`
- elsif (connection_type == "wifi")
- `id > /tmp/id`
- `wpa_passphrase #{sid} #{wireless_pass} > /etc/wpa_supplicant.conf`
- test_lines=File.readlines('/etc/wpa_supplicant.conf')
- test_lines[-1]="\tkey_mgmt=WPA-PSK\n\tproto=WPA\n \} \n"
- text_lines = test_lines.join("")
- File.write("/etc/wpa_supplicant.conf",text_lines)
- fork do
- `/sbin/wpa_supplicant -iwlan3 -c/etc/wpa_supplicant.conf -Dwext `
- end
- sleep(5)
- `ifconfig wlan3 #{ipaddress} netmask #{subnet} up`
- `/sbin/route add default gw #{defaultgw}`
- `echo nameserver #{dns} > /etc/resolv.conf`
- elsif (connection_type == "3g")
- `sh /root/hiper_scripts/netconf.sh 3g`
- end
- end
- " Network Configuration Mode: #{connection_type} ipaddress assigned to box: #{ipaddress}/#{subnet} "
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement