Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix eduroam accounting and auth #10

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dmitry-sinina why did you remove spring? Have you encountered some issues with it?

# gem 'spring'
# gem 'spring-watcher-listen', '~> 2.0.0'
end
9 changes: 1 addition & 8 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -337,4 +330,4 @@ RUBY VERSION
ruby 2.3.3p222

BUNDLED WITH
1.16.2
1.16.6
34 changes: 34 additions & 0 deletions app/admin/service_configuration/domains.rb
Original file line number Diff line number Diff line change
@@ -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
41 changes: 41 additions & 0 deletions app/admin/service_configuration/email_redirects.rb
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
ActiveAdmin.register Service do
menu parent: 'Services configuration', priority: 10

actions :index
config.batch_actions = false
config.filters = false
Expand Down
8 changes: 4 additions & 4 deletions app/admin/wifi_sessions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -67,8 +69,6 @@
row 'Calling Station ID' do
resource.calling_station_id
end
row :created_at
row :updated_at
end
end
end
3 changes: 3 additions & 0 deletions app/controllers/api/eduroam/accounting_controller.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 3 additions & 2 deletions app/lib/eduroam_authorize.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ def authorize!

def authorization_data_for(record)
{
'User-Name': record.login,
'Cleartext-Password': record.password
# 'User-Name': record.login,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why we don't need to provide login in response anymore?

'control:Cleartext-Password': record.password,
'Acct-Interim-Interval': 60
}
end

Expand Down
12 changes: 12 additions & 0 deletions app/models/domain.rb
Original file line number Diff line number Diff line change
@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dmitry-sinina you can omit foreign_key key cause it will be equal to :domain_id by default according to Rails convention


validates :fqdn, presence: true
validates :fqdn, uniqueness: true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dmitry-sinina you can write it in a single line:

validates :fqdn, presence: true, uniqueness: true


def display_name
fqdn.to_s
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dmitry-sinina you don't need to add .to_s explicitly because you've already have a valiation that value can't be nil

end
end
12 changes: 12 additions & 0 deletions app/models/email/redirect.rb
Original file line number Diff line number Diff line change
@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dmitry-sinina you can omit foreign_key key cause it will be equal to :domain_id by default according to Rails convention


validates :rewrited_destination, :username, :domain_id, presence: true
validates :username, uniqueness: { scope: :domain_id }

def display_name
rewrited_destination.to_s
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dmitry-sinina you don't need to add .to_s explicitly because you've already have a valiation that value can't be nil

end
end
6 changes: 6 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,9 @@

en:
hello: "Hello world"
date:
formats:
long: "%Y-%m-%d"
time:
formats:
long: "%Y-%m-%d %H:%M:%S"
30 changes: 30 additions & 0 deletions db/migrate/20181103182805_add_email.rb
Original file line number Diff line number Diff line change
@@ -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