Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit 6ed08d2cb310ced631ea9f098e4a68a31f264180 @bjoerge bjoerge committed Jun 16, 2012
Showing with 123 additions and 0 deletions.
  1. 0 .cred
  2. +17 −0 .gitignore
  3. +4 −0 Gemfile
  4. +22 −0 LICENSE
  5. +13 −0 README.md
  6. +2 −0 Rakefile
  7. +46 −0 bin/nordicruby-wifi
  8. +19 −0 nordicruby-wifi.gemspec
0 .cred
No changes.
@@ -0,0 +1,17 @@
+*.gem
+*.rbc
+.bundle
+.config
+.yardoc
+Gemfile.lock
+InstalledFiles
+_yardoc
+coverage
+doc/
+lib/bundler/man
+pkg
+rdoc
+spec/reports
+test/tmp
+test/version_tmp
+tmp
@@ -0,0 +1,4 @@
+source 'https://rubygems.org'
+
+# Specify your gem's dependencies in nordicruby-login.gemspec
+gemspec
22 LICENSE
@@ -0,0 +1,22 @@
+Copyright (c) 2012 Bjørge Næss
+
+MIT License
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,13 @@
+# Nordicruby::Wifi
+
+## Installation
+
+ rake install
+
+## Usage
+
+### Login
+ nordicruby login
+
+### Logout
+ nordicruby logout
@@ -0,0 +1,2 @@
+#!/usr/bin/env rake
+require "bundler/gem_tasks"
@@ -0,0 +1,46 @@
+#!/usr/bin/env ruby
+
+require "curb"
+require "thor"
+require "yaml"
+
+class NordicRubyWifi < Thor
+ desc "login", "Logs you in to the wifi"
+ def login
+ while true
+ username, password = cached_credentials do
+ [ask("Username:"), ask("Password:")]
+ end
+ say "Attempting login with #{username} / #{"*"*password.length}"
+ req = Curl::Easy.http_post("https://login.homerun.telia.com/sd/login", "username=#{username}&operator=&password=#{password}")
+
+ if req.body_str =~ /errorMessage/
+ puts "Wrong user name/password"
+ clear_cache
+ elsif req.body_str =~ /expired/
+ puts "Looks like your username/password expired"
+ clear_cache
+ else
+ say "Hooray, you are now logged in!"
+ break
+ end
+ end
+ end
+
+ desc "logout", "Logs you out"
+ def logout
+ req = Curl::Easy.http_post("https://login.homerun.telia.com/sd/logout")
+ say "Logged out!"
+ end
+
+ private
+ def clear_cache
+ File.delete(".cred")
+ end
+ def cached_credentials(&blk)
+ File.open(".cred", 'w') { |f| YAML::dump(blk.call, f) } unless File.exists?(".cred")
+ YAML::load_file(".cred")
+ end
+end
+
+NordicRubyWifi.start
@@ -0,0 +1,19 @@
+# -*- encoding: utf-8 -*-
+
+Gem::Specification.new do |gem|
+ gem.authors = ["Bjørge Næss"]
+ gem.email = ["bjoerge@bengler.no"]
+ gem.description = "Nordic Ruby wifi login - simplified"
+ gem.summary = "Nordic Ruby wifi login - simplified"
+ gem.homepage = ""
+
+ gem.files = `git ls-files`.split($\)
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
+ gem.name = "nordicruby-wifi"
+ gem.version = "0.0.1.final"
+
+ gem.add_dependency "rake"
+ gem.add_dependency "thor"
+ gem.add_dependency "curb"
+end

0 comments on commit 6ed08d2

Please sign in to comment.