From 7611229521ba78b9f012fb218e14e20b4e5669fa Mon Sep 17 00:00:00 2001 From: sdi Date: Sat, 3 Nov 2018 18:27:03 +0200 Subject: [PATCH 1/3] fix eduroam accounting and auth --- app/admin/wifi_sessions.rb | 8 ++++---- app/controllers/api/eduroam/accounting_controller.rb | 5 +++++ app/lib/eduroam_authorize.rb | 5 +++-- config/locales/en.yml | 6 ++++++ 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/app/admin/wifi_sessions.rb b/app/admin/wifi_sessions.rb index 405a2e3..afca9e8 100644 --- a/app/admin/wifi_sessions.rb +++ b/app/admin/wifi_sessions.rb @@ -24,6 +24,8 @@ index do id_column + column :created_at + column :updated_at column 'Session ID', :session_id, sortable: :session_id column :username, :login_link, sortable: :username column :connect_info @@ -38,13 +40,13 @@ column :packets_tx column 'Called Station ID', :called_station_id, sortable: :called_station_id column 'Calling Station ID', :calling_station_id, sortable: :calling_station_id - column :created_at - column :updated_at end show do attributes_table do row :id + row :created_at + row :updated_at row 'Session ID' do resource.session_id end @@ -67,8 +69,6 @@ row 'Calling Station ID' do resource.calling_station_id end - row :created_at - row :updated_at end end end diff --git a/app/controllers/api/eduroam/accounting_controller.rb b/app/controllers/api/eduroam/accounting_controller.rb index 6cfc38c..fb8932b 100644 --- a/app/controllers/api/eduroam/accounting_controller.rb +++ b/app/controllers/api/eduroam/accounting_controller.rb @@ -1,6 +1,11 @@ module Api module Eduroam class AccountingController < ApiController + + #fix for Can't verify CSRF token authenticity. + skip_before_action :verify_authenticity_token + + def create record = WifiSessionForm.new(permitted_params) if record.save diff --git a/app/lib/eduroam_authorize.rb b/app/lib/eduroam_authorize.rb index f1b09f4..d7ece2c 100644 --- a/app/lib/eduroam_authorize.rb +++ b/app/lib/eduroam_authorize.rb @@ -26,8 +26,9 @@ def authorize! def authorization_data_for(record) { - 'User-Name': record.login, - 'Cleartext-Password': record.password +# 'User-Name': record.login, + 'control:Cleartext-Password': record.password, + 'Acct-Interim-Interval': 60 } end diff --git a/config/locales/en.yml b/config/locales/en.yml index decc5a8..fc58a31 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -31,3 +31,9 @@ en: hello: "Hello world" + date: + formats: + long: "%Y-%m-%d" + time: + formats: + long: "%Y-%m-%d %H:%M:%S" From 5e5d611833c4371aaf2ca2ba733ef49f7c40cf4b Mon Sep 17 00:00:00 2001 From: sdi Date: Sat, 3 Nov 2018 22:35:26 +0200 Subject: [PATCH 2/3] Email --- Gemfile | 4 +- Gemfile.lock | 9 +--- app/admin/service_configuration/domains.rb | 35 +++++++++++++++ .../service_configuration/email_redirects.rb | 43 +++++++++++++++++++ .../{ => service_configuration}/services.rb | 2 + app/models/domain.rb | 14 ++++++ app/models/email/redirect.rb | 16 +++++++ db/migrate/20181103182805_add_email.rb | 30 +++++++++++++ 8 files changed, 143 insertions(+), 10 deletions(-) create mode 100644 app/admin/service_configuration/domains.rb create mode 100644 app/admin/service_configuration/email_redirects.rb rename app/admin/{ => service_configuration}/services.rb (78%) create mode 100644 app/models/domain.rb create mode 100644 app/models/email/redirect.rb create mode 100644 db/migrate/20181103182805_add_email.rb diff --git a/Gemfile b/Gemfile index fc35731..17e22d1 100644 --- a/Gemfile +++ b/Gemfile @@ -62,6 +62,6 @@ group :development do gem 'web-console', '>= 3.3.0' # Spring speeds up development by keeping your application running in the background. # Read more: https://github.com/rails/spring - gem 'spring' - gem 'spring-watcher-listen', '~> 2.0.0' +# gem 'spring' +# gem 'spring-watcher-listen', '~> 2.0.0' end diff --git a/Gemfile.lock b/Gemfile.lock index c74144d..ca59a43 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -267,11 +267,6 @@ GEM sprockets (>= 2.8, < 4.0) sprockets-rails (>= 2.0, < 4.0) tilt (>= 1.1, < 3) - spring (2.0.2) - activesupport (>= 4.2) - spring-watcher-listen (2.0.1) - listen (>= 2.7, < 4.0) - spring (>= 1.2, < 3.0) sprockets (3.7.2) concurrent-ruby (~> 1.0) rack (> 1, < 3) @@ -327,8 +322,6 @@ DEPENDENCIES rspec-rails (~> 3.7) rubocop (= 0.57.2) sass-rails (~> 5.0) - spring - spring-watcher-listen (~> 2.0.0) turbolinks (~> 5) uglifier (>= 1.3.0) web-console (>= 3.3.0) @@ -337,4 +330,4 @@ RUBY VERSION ruby 2.3.3p222 BUNDLED WITH - 1.16.2 + 1.16.6 diff --git a/app/admin/service_configuration/domains.rb b/app/admin/service_configuration/domains.rb new file mode 100644 index 0000000..f3dd433 --- /dev/null +++ b/app/admin/service_configuration/domains.rb @@ -0,0 +1,35 @@ +ActiveAdmin.register Domain do + menu parent: "Services configuration", priority: 20 + + #actions :index + config.batch_actions = false + + permit_params :fqdn + + filter :id + filter :fqdn + + index do + id_column + actions + column :fqdn + column :created_at + column :updated_at + end + + show do + attributes_table do + row :id + row :fqdn + end + end + + form do |f| + f.semantic_errors(*f.object.errors.keys) + f.inputs do + f.input :fqdn + end + f.actions + end + +end diff --git a/app/admin/service_configuration/email_redirects.rb b/app/admin/service_configuration/email_redirects.rb new file mode 100644 index 0000000..3c0cf59 --- /dev/null +++ b/app/admin/service_configuration/email_redirects.rb @@ -0,0 +1,43 @@ +ActiveAdmin.register Email::Redirect do + menu parent: "Services configuration", priority: 30 + #actions :index + config.batch_actions = false + + includes :domain + permit_params :username, :domain_id, :rewrited_destination + + + filter :id + filter :username + filter :domain + + index do + id_column + actions + column :username + column :domain + column :rewrited_destination + column :created_at + column :updated_at + end + + show do + attributes_table do + row :id + row :username + row :domain + row :rewrited_destination + end + end + + form do |f| + f.semantic_errors(*f.object.errors.keys) + f.inputs do + f.input :username + f.input :domain + f.input :rewrited_destination + end + f.actions + end + +end diff --git a/app/admin/services.rb b/app/admin/service_configuration/services.rb similarity index 78% rename from app/admin/services.rb rename to app/admin/service_configuration/services.rb index df19ca0..ea496e2 100644 --- a/app/admin/services.rb +++ b/app/admin/service_configuration/services.rb @@ -1,4 +1,6 @@ ActiveAdmin.register Service do + menu parent: "Services configuration", priority: 10 + actions :index config.batch_actions = false config.filters = false diff --git a/app/models/domain.rb b/app/models/domain.rb new file mode 100644 index 0000000..002b472 --- /dev/null +++ b/app/models/domain.rb @@ -0,0 +1,14 @@ +class Domain < ApplicationRecord + self.table_name='domains' + + has_many :email_redirects, class_name: 'Email::Redirect', foreign_key: :domain_id, dependent: :restrict_with_error + + validates_presence_of :fqdn + validates_uniqueness_of :fqdn + + + def display_name + "#{fqdn}" + end + +end diff --git a/app/models/email/redirect.rb b/app/models/email/redirect.rb new file mode 100644 index 0000000..7babbf0 --- /dev/null +++ b/app/models/email/redirect.rb @@ -0,0 +1,16 @@ +class Email::Redirect < ApplicationRecord + + + self.table_name='email_redirects' + + belongs_to :domain, class_name: 'Domain', foreign_key: :domain_id + + validates_presence_of :rewrited_destination, :username, :domain_id + validates_uniqueness_of :username, scope: :domain_id + + + def display_name + "#{rewrited_destination}" + end + +end diff --git a/db/migrate/20181103182805_add_email.rb b/db/migrate/20181103182805_add_email.rb new file mode 100644 index 0000000..79f8db6 --- /dev/null +++ b/db/migrate/20181103182805_add_email.rb @@ -0,0 +1,30 @@ +class AddEmail < ActiveRecord::Migration[5.2] + def up + execute %q{ + create table domains( + id serial primary key, + fqdn varchar not null unique, + created_at timestamptz, + updated_at timestamptz + ); + + create table email_redirects( + id serial primary key, + username varchar not null, + domain_id integer not null references domains(id), + rewrited_destination varchar not null, + created_at timestamptz, + updated_at timestamptz + ); + create unique index on email_redirects using btree(username, domain_id); + } + end + + def down + execute %q{ + drop table email_redirects; + drop table domains; + } + end + +end From c9c74671595a84394f79aee4185b1181c0e74499 Mon Sep 17 00:00:00 2001 From: sdi Date: Sun, 4 Nov 2018 17:30:18 +0200 Subject: [PATCH 3/3] rubocop --- Gemfile | 4 ++-- app/admin/service_configuration/domains.rb | 5 ++--- app/admin/service_configuration/email_redirects.rb | 6 ++---- app/admin/service_configuration/services.rb | 2 +- .../api/eduroam/accounting_controller.rb | 6 ++---- app/lib/eduroam_authorize.rb | 2 +- app/models/domain.rb | 12 +++++------- app/models/email/redirect.rb | 14 +++++--------- 8 files changed, 20 insertions(+), 31 deletions(-) diff --git a/Gemfile b/Gemfile index 17e22d1..a49d96a 100644 --- a/Gemfile +++ b/Gemfile @@ -62,6 +62,6 @@ group :development do gem 'web-console', '>= 3.3.0' # Spring speeds up development by keeping your application running in the background. # Read more: https://github.com/rails/spring -# gem 'spring' -# gem 'spring-watcher-listen', '~> 2.0.0' + # gem 'spring' + # gem 'spring-watcher-listen', '~> 2.0.0' end diff --git a/app/admin/service_configuration/domains.rb b/app/admin/service_configuration/domains.rb index f3dd433..66f8b70 100644 --- a/app/admin/service_configuration/domains.rb +++ b/app/admin/service_configuration/domains.rb @@ -1,7 +1,7 @@ ActiveAdmin.register Domain do - menu parent: "Services configuration", priority: 20 + menu parent: 'Services configuration', priority: 20 - #actions :index + # actions :index config.batch_actions = false permit_params :fqdn @@ -31,5 +31,4 @@ end f.actions end - end diff --git a/app/admin/service_configuration/email_redirects.rb b/app/admin/service_configuration/email_redirects.rb index 3c0cf59..8ef8159 100644 --- a/app/admin/service_configuration/email_redirects.rb +++ b/app/admin/service_configuration/email_redirects.rb @@ -1,12 +1,11 @@ ActiveAdmin.register Email::Redirect do - menu parent: "Services configuration", priority: 30 - #actions :index + menu parent: 'Services configuration', priority: 30 + # actions :index config.batch_actions = false includes :domain permit_params :username, :domain_id, :rewrited_destination - filter :id filter :username filter :domain @@ -39,5 +38,4 @@ end f.actions end - end diff --git a/app/admin/service_configuration/services.rb b/app/admin/service_configuration/services.rb index ea496e2..8ecf717 100644 --- a/app/admin/service_configuration/services.rb +++ b/app/admin/service_configuration/services.rb @@ -1,5 +1,5 @@ ActiveAdmin.register Service do - menu parent: "Services configuration", priority: 10 + menu parent: 'Services configuration', priority: 10 actions :index config.batch_actions = false diff --git a/app/controllers/api/eduroam/accounting_controller.rb b/app/controllers/api/eduroam/accounting_controller.rb index fb8932b..b01a361 100644 --- a/app/controllers/api/eduroam/accounting_controller.rb +++ b/app/controllers/api/eduroam/accounting_controller.rb @@ -1,10 +1,8 @@ module Api module Eduroam class AccountingController < ApiController - - #fix for Can't verify CSRF token authenticity. - skip_before_action :verify_authenticity_token - + # fix for Can't verify CSRF token authenticity. + skip_before_action :verify_authenticity_token def create record = WifiSessionForm.new(permitted_params) diff --git a/app/lib/eduroam_authorize.rb b/app/lib/eduroam_authorize.rb index d7ece2c..92a13e7 100644 --- a/app/lib/eduroam_authorize.rb +++ b/app/lib/eduroam_authorize.rb @@ -26,7 +26,7 @@ def authorize! def authorization_data_for(record) { -# 'User-Name': record.login, + # 'User-Name': record.login, 'control:Cleartext-Password': record.password, 'Acct-Interim-Interval': 60 } diff --git a/app/models/domain.rb b/app/models/domain.rb index 002b472..26d1b7f 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -1,14 +1,12 @@ class Domain < ApplicationRecord - self.table_name='domains' + self.table_name = 'domains' - has_many :email_redirects, class_name: 'Email::Redirect', foreign_key: :domain_id, dependent: :restrict_with_error - - validates_presence_of :fqdn - validates_uniqueness_of :fqdn + has_many :email_redirects, class_name: 'Email::Redirect', foreign_key: :domain_id, inverse_of: :domain, dependent: :restrict_with_error + validates :fqdn, presence: true + validates :fqdn, uniqueness: true def display_name - "#{fqdn}" + fqdn.to_s end - end diff --git a/app/models/email/redirect.rb b/app/models/email/redirect.rb index 7babbf0..2d7a96e 100644 --- a/app/models/email/redirect.rb +++ b/app/models/email/redirect.rb @@ -1,16 +1,12 @@ class Email::Redirect < ApplicationRecord + self.table_name = 'email_redirects' + belongs_to :domain, class_name: 'Domain', foreign_key: :domain_id, inverse_of: :email_redirects - self.table_name='email_redirects' - - belongs_to :domain, class_name: 'Domain', foreign_key: :domain_id - - validates_presence_of :rewrited_destination, :username, :domain_id - validates_uniqueness_of :username, scope: :domain_id - + validates :rewrited_destination, :username, :domain_id, presence: true + validates :username, uniqueness: { scope: :domain_id } def display_name - "#{rewrited_destination}" + rewrited_destination.to_s end - end