Create blocked domains #2564

This commit is contained in:
Martin Lensment 2015-07-01 12:45:58 +03:00
parent cd277c25ed
commit d93d43e75c
13 changed files with 254 additions and 80 deletions

View file

@ -0,0 +1,22 @@
class Admin::BlockedDomainsController < AdminController
load_and_authorize_resource
def index
bd = BlockedDomain.first_or_initialize
@blocked_domains = bd.names.join("\n")
end
def create
names = params[:blocked_domains].split("\r\n").map(&:strip)
bd = BlockedDomain.first_or_create
if bd.update(names: names)
flash[:notice] = I18n.t('record_updated')
else
flash.now[:alert] = I18n.t('failed_to_update_record')
end
redirect_to :back
end
end

View file

@ -106,6 +106,7 @@ class Ability
def admin
customer_service
can :manage, Setting
can :manage, BlockedDomain
can :manage, ZonefileSetting
can :manage, DomainVersion
can :manage, Pricelist

View file

@ -0,0 +1,5 @@
class BlockedDomain < ActiveRecord::Base
include Versions
after_initialize -> { self.names = [] if names.nil? }
end

View file

@ -62,7 +62,8 @@ class Epp::Domain < Domain
],
'2302' => [ # Object exists
[:name_dirty, :taken, { value: { obj: 'name', val: name_dirty } }],
[:name_dirty, :reserved, { value: { obj: 'name', val: name_dirty } }]
[:name_dirty, :reserved, { value: { obj: 'name', val: name_dirty } }],
[:name_dirty, :blocked, { value: { obj: 'name', val: name_dirty } }]
],
'2304' => [ # Object status prohibits operation
[:base, :domain_status_prohibits_operation]

View file

@ -0,0 +1,4 @@
class BlockedDomainVersion < PaperTrail::Version
self.table_name = :log_blocked_domains
self.sequence_name = :log_blocked_domains_id_seq
end

View file

@ -1,11 +1,17 @@
class DomainNameValidator < ActiveModel::EachValidator
# rubocop: disable Metrics/PerceivedComplexity
# rubocop: disable Metrics/CyclomaticComplexity
def validate_each(record, attribute, value)
if !self.class.validate_format(value)
record.errors[attribute] << (options[:message] || record.errors.generate_message(attribute, :invalid))
elsif !self.class.validate_blocked(value)
record.errors.add(attribute, (options[:message] || record.errors.generate_message(attribute, :blocked)))
elsif !self.class.validate_reservation(value)
record.errors.add(attribute, (options[:message] || record.errors.generate_message(attribute, :reserved)))
end
end
# rubocop: enable Metrics/PerceivedComplexity
# rubocop: enable Metrics/CyclomaticComplexity
class << self
def validate_format(value)
@ -31,6 +37,11 @@ class DomainNameValidator < ActiveModel::EachValidator
# rubocop: enable Style/DoubleNegation
end
def validate_blocked(value)
return true unless value
BlockedDomain.where("names @> ?::varchar[]", "{#{value}}").count == 0
end
def validate_reservation(value)
return true unless value
!ReservedDomain.exists?(name: value.mb_chars.downcase.strip)

View file

@ -0,0 +1,10 @@
= render 'shared/title', name: t(:blocked_domains)
= form_tag([:admin, :blocked_domains]) do |f|
.row
.col-md-12
= text_area_tag :blocked_domains, @blocked_domains, class: 'form-control', rows: 30
%hr
.row
.col-md-12.text-right
%button.btn.btn-warning=t(:save)

View file

@ -59,9 +59,7 @@
%li.dropdown-header= t(:system)
%li= link_to t(:settings), admin_settings_path
%li= link_to t(:zonefile), admin_zonefile_settings_path
%li.dropdown-header= t(:system)
%li= link_to t(:settings), admin_settings_path
%li= link_to t(:zonefile), admin_zonefile_settings_path
%li= link_to t(:blocked_domains), admin_blocked_domains_path
-# %li= link_to t(:domains_history), admin_domain_versions_path
%li= link_to t(:epp_logs), admin_epp_logs_path
%li= link_to t(:repp_logs), admin_repp_logs_path

View file

@ -62,7 +62,8 @@ en:
key_data_not_allowed: 'keyData object is not allowed'
name_dirty:
invalid: 'Domain name is invalid'
reserved: 'Domain name is reserved or restricted'
reserved: 'Domain name is reserved'
blocked: 'Domain name is blocked'
taken: 'Domain name already exists'
puny_label:
too_long: 'Domain name is too long (maximum is 63 characters)'
@ -852,3 +853,4 @@ en:
registry_state: 'State / Province'
registry_zip: 'Postcode'
registry_country_code: 'Country'
blocked_domains: 'Blocked domains'

View file

@ -189,6 +189,8 @@ Rails.application.routes.draw do
resources :settings
resources :blocked_domains
resources :registrars do
resources :api_users
resources :white_ips

View file

@ -0,0 +1,25 @@
class CreateBlockedDomains < ActiveRecord::Migration
def change
create_table :blocked_domains do |t|
t.string :names, array: true
t.timestamps
t.string "creator_str"
t.string "updator_str"
end
create_table "log_blocked_domains", force: :cascade do |t|
t.string "item_type", null: false
t.integer "item_id", null: false
t.string "event", null: false
t.string "whodunnit"
t.json "object"
t.json "object_changes"
t.datetime "created_at"
t.string "session"
t.json "children"
end
add_index "log_blocked_domains", ["item_type", "item_id"], name: "index_log_blocked_domains_on_item_type_and_item_id", using: :btree
add_index "log_blocked_domains", ["whodunnit"], name: "index_log_blocked_domains_on_whodunnit", using: :btree
end
end

View file

@ -119,17 +119,17 @@ ZonefileSetting.where({
master_nameserver: 'ns.tld.ee'
}).first_or_create!
Registrar.where(
name: 'EIS',
reg_no: '90010019',
phone: '+3727271000',
country_code: 'EE',
vat_no: 'EE101286464',
email: 'info@internet.ee',
state: 'Harjumaa',
city: 'Tallinn',
street: 'Paldiski mnt 80',
zip: '10617',
url: 'www.internet.ee',
code: 'EIS'
).first_or_create!
# Registrar.where(
# name: 'EIS',
# reg_no: '90010019',
# phone: '+3727271000',
# country_code: 'EE',
# vat_no: 'EE101286464',
# email: 'info@internet.ee',
# state: 'Harjumaa',
# city: 'Tallinn',
# street: 'Paldiski mnt 80',
# zip: '10617',
# url: 'www.internet.ee',
# code: 'EIS'
# ).first_or_create!

View file

@ -41,7 +41,7 @@ CREATE FUNCTION generate_zonefile(i_origin character varying) RETURNS text
ret text;
BEGIN
-- define filters
include_filter = '%' || i_origin;
include_filter = '%.' || i_origin;
-- for %.%.%
IF i_origin ~ '\.' THEN
@ -74,7 +74,7 @@ CREATE FUNCTION generate_zonefile(i_origin character varying) RETURNS text
SELECT concat(d.name_puny, '. IN NS ', ns.hostname, '.')
FROM domains d
JOIN nameservers ns ON ns.domain_id = d.id
WHERE d.name LIKE include_filter AND d.name NOT LIKE exclude_filter
WHERE d.name LIKE include_filter AND d.name NOT LIKE exclude_filter OR d.name = i_origin
ORDER BY d.name
),
chr(10)
@ -198,7 +198,7 @@ CREATE TABLE account_activities (
id integer NOT NULL,
account_id integer,
invoice_id integer,
sum numeric(10,2),
sum numeric(8,2),
currency character varying,
bank_transaction_id integer,
created_at timestamp without time zone,
@ -236,7 +236,7 @@ CREATE TABLE accounts (
id integer NOT NULL,
registrar_id integer,
account_type character varying,
balance numeric(10,2) DEFAULT 0 NOT NULL,
balance numeric(8,2) DEFAULT 0.0 NOT NULL,
created_at timestamp without time zone,
updated_at timestamp without time zone,
currency character varying,
@ -394,7 +394,7 @@ CREATE TABLE bank_transactions (
buyer_name character varying,
document_no character varying,
description character varying,
sum numeric(10,2),
sum numeric(8,2),
reference_no character varying,
paid_at timestamp without time zone,
created_at timestamp without time zone,
@ -435,7 +435,7 @@ CREATE TABLE banklink_transactions (
vk_rec_id character varying,
vk_stamp character varying,
vk_t_no character varying,
vk_amount numeric(10,2),
vk_amount numeric(8,2),
vk_curr character varying,
vk_rec_acc character varying,
vk_rec_name character varying,
@ -472,6 +472,39 @@ CREATE SEQUENCE banklink_transactions_id_seq
ALTER SEQUENCE banklink_transactions_id_seq OWNED BY banklink_transactions.id;
--
-- Name: blocked_domains; Type: TABLE; Schema: public; Owner: -; Tablespace:
--
CREATE TABLE blocked_domains (
id integer NOT NULL,
names character varying[],
created_at timestamp without time zone,
updated_at timestamp without time zone,
creator_str character varying,
updator_str character varying
);
--
-- Name: blocked_domains_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE blocked_domains_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: blocked_domains_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE blocked_domains_id_seq OWNED BY blocked_domains.id;
--
-- Name: cached_nameservers; Type: TABLE; Schema: public; Owner: -; Tablespace:
--
@ -639,6 +672,15 @@ CREATE SEQUENCE countries_id_seq
ALTER SEQUENCE countries_id_seq OWNED BY countries.id;
--
-- Name: data_migrations; Type: TABLE; Schema: public; Owner: -; Tablespace:
--
CREATE TABLE data_migrations (
version character varying NOT NULL
);
--
-- Name: delegation_signers; Type: TABLE; Schema: public; Owner: -; Tablespace:
--
@ -951,7 +993,7 @@ CREATE TABLE invoice_items (
description character varying NOT NULL,
unit character varying,
amount integer,
price numeric(10,2),
price numeric(8,2),
created_at timestamp without time zone,
updated_at timestamp without time zone,
creator_str character varying,
@ -992,7 +1034,7 @@ CREATE TABLE invoices (
currency character varying NOT NULL,
description character varying,
reference_no character varying,
vat_prc numeric(10,2) NOT NULL,
vat_prc numeric(8,2) NOT NULL,
paid_at timestamp without time zone,
seller_id integer,
seller_name character varying NOT NULL,
@ -1025,7 +1067,7 @@ CREATE TABLE invoices (
updator_str character varying,
number integer,
cancelled_at timestamp without time zone,
sum_cache numeric(10,2)
sum_cache numeric(8,2)
);
@ -1349,6 +1391,43 @@ CREATE SEQUENCE log_bank_transactions_id_seq
ALTER SEQUENCE log_bank_transactions_id_seq OWNED BY log_bank_transactions.id;
--
-- Name: log_blocked_domains; Type: TABLE; Schema: public; Owner: -; Tablespace:
--
CREATE TABLE log_blocked_domains (
id integer NOT NULL,
item_type character varying NOT NULL,
item_id integer NOT NULL,
event character varying NOT NULL,
whodunnit character varying,
object json,
object_changes json,
created_at timestamp without time zone,
session character varying,
children json
);
--
-- Name: log_blocked_domains_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE log_blocked_domains_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: log_blocked_domains_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE log_blocked_domains_id_seq OWNED BY log_blocked_domains.id;
--
-- Name: log_certificates; Type: TABLE; Schema: public; Owner: -; Tablespace:
--
@ -2287,7 +2366,7 @@ CREATE TABLE pricelists (
id integer NOT NULL,
"desc" character varying,
category character varying,
price_cents numeric(8,2) DEFAULT 0 NOT NULL,
price_cents numeric(8,2) DEFAULT 0.0 NOT NULL,
price_currency character varying DEFAULT 'EUR'::character varying NOT NULL,
valid_from timestamp without time zone,
valid_to timestamp without time zone,
@ -2325,8 +2404,8 @@ ALTER SEQUENCE pricelists_id_seq OWNED BY pricelists.id;
CREATE TABLE que_jobs (
priority smallint DEFAULT 100 NOT NULL,
run_at timestamp with time zone DEFAULT now() NOT NULL,
job_id bigint NOT NULL,
run_at timestamp without time zone DEFAULT '2015-06-30 14:16:49.190473'::timestamp without time zone NOT NULL,
job_id bigint DEFAULT 0 NOT NULL,
job_class text NOT NULL,
args json DEFAULT '[]'::json NOT NULL,
error_count integer DEFAULT 0 NOT NULL,
@ -2335,32 +2414,6 @@ CREATE TABLE que_jobs (
);
--
-- Name: TABLE que_jobs; Type: COMMENT; Schema: public; Owner: -
--
COMMENT ON TABLE que_jobs IS '3';
--
-- Name: que_jobs_job_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE que_jobs_job_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: que_jobs_job_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE que_jobs_job_id_seq OWNED BY que_jobs.job_id;
--
-- Name: registrant_verifications; Type: TABLE; Schema: public; Owner: -; Tablespace:
--
@ -2551,7 +2604,7 @@ CREATE TABLE users (
crt text,
type character varying,
registrant_ident character varying,
encrypted_password character varying DEFAULT ''::character varying,
encrypted_password character varying DEFAULT ''::character varying NOT NULL,
remember_created_at timestamp without time zone,
failed_attempts integer DEFAULT 0 NOT NULL,
locked_at timestamp without time zone
@ -2766,6 +2819,13 @@ ALTER TABLE ONLY bank_transactions ALTER COLUMN id SET DEFAULT nextval('bank_tra
ALTER TABLE ONLY banklink_transactions ALTER COLUMN id SET DEFAULT nextval('banklink_transactions_id_seq'::regclass);
--
-- Name: id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY blocked_domains ALTER COLUMN id SET DEFAULT nextval('blocked_domains_id_seq'::regclass);
--
-- Name: id; Type: DEFAULT; Schema: public; Owner: -
--
@ -2920,6 +2980,13 @@ ALTER TABLE ONLY log_bank_statements ALTER COLUMN id SET DEFAULT nextval('log_ba
ALTER TABLE ONLY log_bank_transactions ALTER COLUMN id SET DEFAULT nextval('log_bank_transactions_id_seq'::regclass);
--
-- Name: id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY log_blocked_domains ALTER COLUMN id SET DEFAULT nextval('log_blocked_domains_id_seq'::regclass);
--
-- Name: id; Type: DEFAULT; Schema: public; Owner: -
--
@ -3102,13 +3169,6 @@ ALTER TABLE ONLY people ALTER COLUMN id SET DEFAULT nextval('people_id_seq'::reg
ALTER TABLE ONLY pricelists ALTER COLUMN id SET DEFAULT nextval('pricelists_id_seq'::regclass);
--
-- Name: job_id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY que_jobs ALTER COLUMN job_id SET DEFAULT nextval('que_jobs_job_id_seq'::regclass);
--
-- Name: id; Type: DEFAULT; Schema: public; Owner: -
--
@ -3228,6 +3288,14 @@ ALTER TABLE ONLY banklink_transactions
ADD CONSTRAINT banklink_transactions_pkey PRIMARY KEY (id);
--
-- Name: blocked_domains_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
--
ALTER TABLE ONLY blocked_domains
ADD CONSTRAINT blocked_domains_pkey PRIMARY KEY (id);
--
-- Name: certificates_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
--
@ -3404,6 +3472,14 @@ ALTER TABLE ONLY log_bank_transactions
ADD CONSTRAINT log_bank_transactions_pkey PRIMARY KEY (id);
--
-- Name: log_blocked_domains_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
--
ALTER TABLE ONLY log_blocked_domains
ADD CONSTRAINT log_blocked_domains_pkey PRIMARY KEY (id);
--
-- Name: log_certificates_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
--
@ -3612,14 +3688,6 @@ ALTER TABLE ONLY pricelists
ADD CONSTRAINT pricelists_pkey PRIMARY KEY (id);
--
-- Name: que_jobs_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
--
ALTER TABLE ONLY que_jobs
ADD CONSTRAINT que_jobs_pkey PRIMARY KEY (queue, priority, run_at, job_id);
--
-- Name: registrant_verifications_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
--
@ -4014,6 +4082,20 @@ CREATE INDEX index_log_bank_transactions_on_item_type_and_item_id ON log_bank_tr
CREATE INDEX index_log_bank_transactions_on_whodunnit ON log_bank_transactions USING btree (whodunnit);
--
-- Name: index_log_blocked_domains_on_item_type_and_item_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
--
CREATE INDEX index_log_blocked_domains_on_item_type_and_item_id ON log_blocked_domains USING btree (item_type, item_id);
--
-- Name: index_log_blocked_domains_on_whodunnit; Type: INDEX; Schema: public; Owner: -; Tablespace:
--
CREATE INDEX index_log_blocked_domains_on_whodunnit ON log_blocked_domains USING btree (whodunnit);
--
-- Name: index_log_certificates_on_item_type_and_item_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
--
@ -4378,6 +4460,13 @@ CREATE INDEX index_whois_records_on_domain_id ON whois_records USING btree (doma
CREATE INDEX index_whois_records_on_registrar_id ON whois_records USING btree (registrar_id);
--
-- Name: unique_data_migrations; Type: INDEX; Schema: public; Owner: -; Tablespace:
--
CREATE UNIQUE INDEX unique_data_migrations ON data_migrations USING btree (version);
--
-- Name: unique_schema_migrations; Type: INDEX; Schema: public; Owner: -; Tablespace:
--
@ -4593,8 +4682,6 @@ INSERT INTO schema_migrations (version) VALUES ('20150227092508');
INSERT INTO schema_migrations (version) VALUES ('20150227113121');
INSERT INTO schema_migrations (version) VALUES ('20150302130224');
INSERT INTO schema_migrations (version) VALUES ('20150302161712');
INSERT INTO schema_migrations (version) VALUES ('20150303130729');
@ -4653,8 +4740,6 @@ INSERT INTO schema_migrations (version) VALUES ('20150417082723');
INSERT INTO schema_migrations (version) VALUES ('20150421134820');
INSERT INTO schema_migrations (version) VALUES ('20150422090645');
INSERT INTO schema_migrations (version) VALUES ('20150422092514');
INSERT INTO schema_migrations (version) VALUES ('20150422132631');
@ -4699,8 +4784,6 @@ INSERT INTO schema_migrations (version) VALUES ('20150519115050');
INSERT INTO schema_migrations (version) VALUES ('20150519140853');
INSERT INTO schema_migrations (version) VALUES ('20150519142542');
INSERT INTO schema_migrations (version) VALUES ('20150519144118');
INSERT INTO schema_migrations (version) VALUES ('20150520163237');
@ -4713,7 +4796,9 @@ INSERT INTO schema_migrations (version) VALUES ('20150522164020');
INSERT INTO schema_migrations (version) VALUES ('20150525075550');
INSERT INTO schema_migrations (version) VALUES ('20150603141054');
INSERT INTO schema_migrations (version) VALUES ('20150601083516');
INSERT INTO schema_migrations (version) VALUES ('20150601083800');
INSERT INTO schema_migrations (version) VALUES ('20150603141549');
@ -4721,8 +4806,12 @@ INSERT INTO schema_migrations (version) VALUES ('20150603211318');
INSERT INTO schema_migrations (version) VALUES ('20150603212659');
INSERT INTO schema_migrations (version) VALUES ('20150609093515');
INSERT INTO schema_migrations (version) VALUES ('20150609103333');
INSERT INTO schema_migrations (version) VALUES ('20150610111019');
INSERT INTO schema_migrations (version) VALUES ('20150610112238');
INSERT INTO schema_migrations (version) VALUES ('20150610144547');
@ -4731,3 +4820,7 @@ INSERT INTO schema_migrations (version) VALUES ('20150611124920');
INSERT INTO schema_migrations (version) VALUES ('20150612123111');
INSERT INTO schema_migrations (version) VALUES ('20150612125720');
INSERT INTO schema_migrations (version) VALUES ('20150701074344');