diff --git a/Gemfile b/Gemfile index fc35731..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/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..66f8b70 --- /dev/null +++ b/app/admin/service_configuration/domains.rb @@ -0,0 +1,34 @@ +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..8ef8159 --- /dev/null +++ b/app/admin/service_configuration/email_redirects.rb @@ -0,0 +1,41 @@ +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..8ecf717 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/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..b01a361 100644 --- a/app/controllers/api/eduroam/accounting_controller.rb +++ b/app/controllers/api/eduroam/accounting_controller.rb @@ -1,6 +1,9 @@ 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..92a13e7 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/app/models/domain.rb b/app/models/domain.rb new file mode 100644 index 0000000..26d1b7f --- /dev/null +++ b/app/models/domain.rb @@ -0,0 +1,12 @@ +class Domain < ApplicationRecord + self.table_name = 'domains' + + 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.to_s + end +end diff --git a/app/models/email/redirect.rb b/app/models/email/redirect.rb new file mode 100644 index 0000000..2d7a96e --- /dev/null +++ b/app/models/email/redirect.rb @@ -0,0 +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 + + validates :rewrited_destination, :username, :domain_id, presence: true + validates :username, uniqueness: { scope: :domain_id } + + def display_name + rewrited_destination.to_s + end +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" 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