mirror of
https://github.com/internetee/registry.git
synced 2025-06-10 06:34:46 +02:00
updated approach for loading schemas in xml console
This commit is contained in:
parent
ad23a7cbd2
commit
5b8b18f584
18 changed files with 258 additions and 55 deletions
|
@ -1,15 +1,22 @@
|
|||
class Registrar
|
||||
class XmlConsolesController < DeppController
|
||||
PREFS = %w[
|
||||
domain-ee
|
||||
contact-ee
|
||||
eis
|
||||
epp-ee
|
||||
].freeze
|
||||
|
||||
authorize_resource class: false
|
||||
|
||||
def show
|
||||
end
|
||||
def show; end
|
||||
|
||||
def create
|
||||
begin
|
||||
@result = depp_current_user.server.request(params[:payload])
|
||||
checking_schema_valid_path(params[:payload])
|
||||
rescue
|
||||
|
||||
check_schema_path(params[:payload])
|
||||
rescue StandardError
|
||||
@result = 'CONNECTION ERROR - Is the EPP server running?'
|
||||
end
|
||||
render :show
|
||||
|
@ -19,31 +26,78 @@ class Registrar
|
|||
cl_trid = "#{depp_current_user.tag}-#{Time.zone.now.to_i}"
|
||||
xml_dir_path = Rails.root + 'app/views/registrar/xml_consoles/epp_requests'
|
||||
xml = File.read("#{xml_dir_path}/#{params[:obj]}/#{params[:epp_action]}.xml")
|
||||
xml.gsub!('<clTRID>ABC-12345</clTRID>', "<clTRID>#{cl_trid}</clTRID>")
|
||||
xml = prepare_payload(xml, cl_trid)
|
||||
|
||||
render plain: xml
|
||||
end
|
||||
|
||||
private
|
||||
protected
|
||||
|
||||
def checking_schema_valid_path(payload)
|
||||
path = regex_to_find_domain_schema(payload)
|
||||
def check_schema_path(payload)
|
||||
path = nil
|
||||
path = regex_to_find_domain_schema(payload) if regex_to_find_domain_schema(payload).present?
|
||||
path = regex_to_find_contact_schema(payload) if regex_to_find_contact_schema(payload).present?
|
||||
path = regex_to_find_poll_schema(payload) if regex_to_find_poll_schema(payload).present?
|
||||
|
||||
@result = template_wrong_path unless array_valid_paths.include? path
|
||||
end
|
||||
@result = wrong_path_response unless array_valid_paths.include? path
|
||||
end
|
||||
|
||||
def array_valid_paths
|
||||
Xsd::Schema::PREFIXES.map{|prefix| Xsd::Schema.filename(for_prefix: prefix)}
|
||||
end
|
||||
def array_valid_paths
|
||||
Xsd::Schema::PREFIXES.map { |prefix| Xsd::Schema.filename(for_prefix: prefix) }
|
||||
end
|
||||
|
||||
def template_wrong_path
|
||||
'Wrong schema path'
|
||||
def wrong_path_response
|
||||
cl_trid = "#{depp_current_user.tag}-#{Time.zone.now.to_i}"
|
||||
|
||||
<<~XML
|
||||
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
|
||||
<epp xmlns=\"https://epp.tld.ee/schema/epp-ee-1.0.xsd\"
|
||||
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
|
||||
xsi:schemaLocation=\"lib/schemas/epp-ee-1.0.xsd\">
|
||||
<response>
|
||||
<result code=\"2100\">
|
||||
<msg lang=\"en\">Wrong schema</msg>
|
||||
</result>
|
||||
<trID>
|
||||
<clTRID>#{cl_trid}</clTRID>
|
||||
<svTRID>eePrx-#{Time.zone.now.to_i}</svTRID>
|
||||
</trID>
|
||||
</response>
|
||||
</epp>
|
||||
XML
|
||||
end
|
||||
|
||||
def regex_to_find_domain_schema(payload)
|
||||
domain_schema_tag = payload.scan(/xmlns:domain[\S]+/)
|
||||
schema_path = domain_schema_tag.to_s.match(/https?:\/\/[\S]+/)[0]
|
||||
path = schema_path.split('\\')[0]
|
||||
path
|
||||
domain_schema_tag = payload.scan(/xmlns:domain\S+/)
|
||||
return if domain_schema_tag.empty?
|
||||
|
||||
schema_path = domain_schema_tag.to_s.match(%r{https?://\S+})[0]
|
||||
schema_path.split('\\')[0]
|
||||
end
|
||||
|
||||
def regex_to_find_contact_schema(payload)
|
||||
contact_schema_tag = payload.scan(/xmlns:contact\S+/)
|
||||
return if contact_schema_tag.empty?
|
||||
|
||||
schema_path = contact_schema_tag.to_s.match(%r{https?://\S+})[0]
|
||||
schema_path.split('\\')[0]
|
||||
end
|
||||
|
||||
def regex_to_find_poll_schema(payload)
|
||||
contact_schema_tag = payload.scan(/poll\S+/)
|
||||
return if contact_schema_tag.empty?
|
||||
|
||||
'https://epp.tld.ee/schema/epp-ee-1.0.xsd'
|
||||
end
|
||||
|
||||
def prepare_payload(xml, cl_trid)
|
||||
PREFS.map do |pref|
|
||||
xml.gsub!('"' + pref.to_s + '"',
|
||||
"\"#{Xsd::Schema.filename(for_prefix: pref.to_s)}\"")
|
||||
end
|
||||
|
||||
xml.gsub!('<clTRID>ABC-12345</clTRID>', "<clTRID>#{cl_trid}</clTRID>")
|
||||
xml
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<epp xmlns="#{Xsd::Schema.filename(for_prefix: 'epp-ee')}">
|
||||
<epp xmlns="epp-ee">
|
||||
<command>
|
||||
<check>
|
||||
<contact:check
|
||||
xmlns:contact="#{Xsd::Schema.filename(for_prefix: 'contact-ee')}">
|
||||
xmlns:contact="contact-ee">
|
||||
<contact:id>sh8013</contact:id>
|
||||
</contact:check>
|
||||
</check>
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<epp xmlns="#{Xsd::Schema.filename(for_prefix: 'epp-ee')}">
|
||||
<epp xmlns="epp-ee">
|
||||
<command>
|
||||
<check>
|
||||
<contact:check
|
||||
xmlns:contact="#{Xsd::Schema.filename(for_prefix: 'contact-ee')}">
|
||||
xmlns:contact="contact-ee">
|
||||
<contact:id>sh8013</contact:id>
|
||||
<contact:id>sh13</contact:id>
|
||||
<contact:id>vsdfvq</contact:id>
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<epp xmlns="#{Xsd::Schema.filename(for_prefix: 'epp-ee')}">
|
||||
<epp xmlns="epp-ee">
|
||||
<command>
|
||||
<create>
|
||||
<contact:create xmlns:contact="#{Xsd::Schema.filename(for_prefix: 'contact-ee')}">
|
||||
<contact:create xmlns:contact="contact-ee">
|
||||
<contact:postalInfo>
|
||||
<contact:name>Sillius Soddus</contact:name>
|
||||
<contact:addr>
|
||||
|
@ -20,7 +20,7 @@
|
|||
</contact:create>
|
||||
</create>
|
||||
<extension>
|
||||
<eis:extdata xmlns:eis="#{Xsd::Schema.filename(for_prefix: 'eis')}">
|
||||
<eis:extdata xmlns:eis="eis">
|
||||
<eis:ident type="org" cc="EE">123</eis:ident>
|
||||
<eis:legalDocument type="pdf">
|
||||
dGVzdCBmYWlsCg==
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<epp xmlns="#{Xsd::Schema.filename(for_prefix: 'epp-ee')}">
|
||||
<epp xmlns="epp-ee">
|
||||
<command>
|
||||
<delete>
|
||||
<contact:delete
|
||||
xmlns:contact="#{Xsd::Schema.filename(for_prefix: 'contact-ee')}">
|
||||
xmlns:contact="contact-ee">
|
||||
<contact:id>sh8013</contact:id>
|
||||
<contact:authInfo>
|
||||
<contact:pw>wrong-one</contact:pw>
|
||||
|
@ -11,7 +11,7 @@
|
|||
</contact:delete>
|
||||
</delete>
|
||||
<extension>
|
||||
<eis:extdata xmlns:eis="#{Xsd::Schema.filename(for_prefix: 'eis')}">
|
||||
<eis:extdata xmlns:eis="eis">
|
||||
<eis:legalDocument type="pdf">
|
||||
dGVzdCBmYWlsCg==
|
||||
</eis:legalDocument>
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<epp xmlns="#{Xsd::Schema.filename(for_prefix: 'epp-ee')}">
|
||||
<epp xmlns="epp-ee">
|
||||
<command>
|
||||
<info>
|
||||
<contact:info xmlns:contact="#{Xsd::Schema.filename(for_prefix: 'contact-ee')}">
|
||||
<contact:info xmlns:contact="contact-ee">
|
||||
<contact:id>sh8013</contact:id>
|
||||
<contact:authInfo>
|
||||
<contact:pw>Aas34fq</contact:pw>
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<epp xmlns="#{Xsd::Schema.filename(for_prefix: 'epp-ee')}">
|
||||
<epp xmlns="epp-ee">
|
||||
<command>
|
||||
<update>
|
||||
<contact:update xmlns:contact="#{Xsd::Schema.filename(for_prefix: 'contact-ee')}">
|
||||
<contact:update xmlns:contact="contact-ee">
|
||||
<contact:id>sh8013</contact:id>
|
||||
<contact:chg>
|
||||
<contact:postalInfo>
|
||||
|
@ -25,7 +25,7 @@
|
|||
</contact:update>
|
||||
</update>
|
||||
<extension>
|
||||
<eis:extdata xmlns:eis="#{Xsd::Schema.filename(for_prefix: 'eis')}">
|
||||
<eis:extdata xmlns:eis="eis">
|
||||
<eis:legalDocument type="pdf">
|
||||
dGVzdCBmYWlsCg==
|
||||
</eis:legalDocument>
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
|
||||
<epp xmlns="epp-ee">
|
||||
<command>
|
||||
<check>
|
||||
<domain:check
|
||||
xmlns:domain="https://epp.tld.ee/schema/domain-ee-1.1.xsd">
|
||||
xmlns:domain="domain-ee">
|
||||
<domain:name>example.ee</domain:name>
|
||||
</domain:check>
|
||||
</check>
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
|
||||
<epp xmlns="epp-ee">
|
||||
<command>
|
||||
<update>
|
||||
<domain:update
|
||||
xmlns:domain="https://epp.tld.ee/schema/domain-ee-1.1.xsd">
|
||||
xmlns:domain="domain-ee">
|
||||
<domain:name>example.ee</domain:name>
|
||||
<domain:rem>
|
||||
<domain:status s="clientHold"/>
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
|
||||
<epp xmlns="epp-ee">
|
||||
<command>
|
||||
<create>
|
||||
<domain:create
|
||||
xmlns:domain="https://epp.tld.ee/schema/domain-ee-1.1.xsd">
|
||||
xmlns:domain="domain-ee">
|
||||
<domain:name>example.ee</domain:name>
|
||||
<domain:period unit="y">1</domain:period>
|
||||
<domain:ns>
|
||||
|
@ -31,7 +31,7 @@
|
|||
<secDNS:pubKey>AwEAAddt2AkLfYGKgiEZB5SmIF8EvrjxNMH6HtxWEA4RJ9Ao6LCWheg8</secDNS:pubKey>
|
||||
</secDNS:keyData>
|
||||
</secDNS:create>
|
||||
<eis:extdata xmlns:eis="#{Xsd::Schema.filename(for_prefix: 'eis')}">
|
||||
<eis:extdata xmlns:eis="eis">
|
||||
<eis:legalDocument type="pdf">
|
||||
dGVzdCBmYWlsCg==
|
||||
</eis:legalDocument>
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
|
||||
<epp xmlns="epp-ee">
|
||||
<command>
|
||||
<delete>
|
||||
<domain:delete
|
||||
xmlns:domain="https://epp.tld.ee/schema/domain-ee-1.1.xsd">
|
||||
xmlns:domain="domain-ee">
|
||||
<domain:name>example.ee</domain:name>
|
||||
</domain:delete>
|
||||
</delete>
|
||||
<extension>
|
||||
<eis:extdata xmlns:eis="#{Xsd::Schema.filename(for_prefix: 'ee')}">
|
||||
<eis:extdata xmlns:eis="eis">
|
||||
<eis:legalDocument type="pdf">
|
||||
dGVzdCBmYWlsCg==
|
||||
</eis:legalDocument>
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
|
||||
<epp xmlns="epp-ee">
|
||||
<command>
|
||||
<info>
|
||||
<domain:info
|
||||
xmlns:domain="https://epp.tld.ee/schema/domain-ee-1.1.xsd">
|
||||
xmlns:domain="domain-ee">
|
||||
<domain:name hosts="all">example.ee</domain:name>
|
||||
<domain:authInfo>
|
||||
<domain:pw>2fooBAR</domain:pw>
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
|
||||
<epp xmlns="epp-ee">
|
||||
<command>
|
||||
<renew>
|
||||
<domain:renew
|
||||
xmlns:domain="https://epp.tld.ee/schema/domain-ee-1.1.xsd">
|
||||
xmlns:domain="domain-ee">
|
||||
<domain:name>example.ee</domain:name>
|
||||
<domain:curExpDate>2014-08-07</domain:curExpDate>
|
||||
<domain:period unit="y">1</domain:period>
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
|
||||
<epp xmlns="epp-ee">
|
||||
<command>
|
||||
<transfer op="request">
|
||||
<domain:transfer
|
||||
xmlns:domain="https://epp.tld.ee/schema/domain-ee-1.1.xsd">
|
||||
xmlns:domain="domain-ee">
|
||||
<domain:name>example.ee</domain:name>
|
||||
<domain:authInfo>
|
||||
<domain:pw roid="JD1234-REP">2BARfoo</domain:pw>
|
||||
|
@ -11,7 +11,7 @@
|
|||
</domain:transfer>
|
||||
</transfer>
|
||||
<extension>
|
||||
<eis:extdata xmlns:eis="#{Xsd::Schema.filename(for_prefix: 'ee')}">
|
||||
<eis:extdata xmlns:eis="eis">
|
||||
<eis:legalDocument type="pdf">
|
||||
dGVzdCBmYWlsCg==
|
||||
</eis:legalDocument>
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
|
||||
<epp xmlns="epp-ee">
|
||||
<command>
|
||||
<update>
|
||||
<domain:update
|
||||
xmlns:domain="https://epp.tld.ee/schema/domain-ee-1.1.xsd">
|
||||
xmlns:domain="domain-ee">
|
||||
<domain:name>example.ee</domain:name>
|
||||
<domain:add>
|
||||
<domain:ns>
|
||||
|
@ -43,7 +43,7 @@
|
|||
</secDNS:keyData>
|
||||
</secDNS:rem>
|
||||
</secDNS:update>
|
||||
<eis:extdata xmlns:eis="#{Xsd::Schema.filename(for_prefix: 'eis')}">
|
||||
<eis:extdata xmlns:eis="eis">
|
||||
<eis:legalDocument type="pdf">
|
||||
dGVzdCBmYWlsCg==
|
||||
</eis:legalDocument>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<epp xmlns="#{Xsd::Schema.filename(for_prefix: 'epp-ee')}">
|
||||
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
|
||||
<command>
|
||||
<poll op="req"/>
|
||||
<clTRID>ABC-12345</clTRID>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue