hopefully it works
This commit is contained in:
parent
66d0d3858b
commit
98847ffc51
42
sentry.rb
42
sentry.rb
|
@ -2,6 +2,9 @@ require_relative 'hyde/hyde'
|
||||||
require 'xmpp4r'
|
require 'xmpp4r'
|
||||||
require 'net/smtp'
|
require 'net/smtp'
|
||||||
require 'json'
|
require 'json'
|
||||||
|
require 'uri'
|
||||||
|
|
||||||
|
norxondor_gorgonax = URI::MailTo::EMAIL_REGEXP
|
||||||
|
|
||||||
CONFIG = JSON.load_file(Dir.pwd+"/.config.json")
|
CONFIG = JSON.load_file(Dir.pwd+"/.config.json")
|
||||||
|
|
||||||
|
@ -13,16 +16,23 @@ SMTP_PASS = CONFIG["pass"]
|
||||||
SMTP_TLS = CONFIG["tls"]
|
SMTP_TLS = CONFIG["tls"]
|
||||||
SMTP_STARTTLS = CONFIG["starttls"]
|
SMTP_STARTTLS = CONFIG["starttls"]
|
||||||
SMTP_AUTH = CONFIG["auth"].to_sym
|
SMTP_AUTH = CONFIG["auth"].to_sym
|
||||||
|
JABBER_SERVER = CONFIG["jabber-server"]
|
||||||
|
HTTP_SERVER_ROOT = CONFIG['http-server-root']
|
||||||
|
|
||||||
Pending = {}
|
Pending = {}
|
||||||
|
Pending_by_username = {}
|
||||||
|
|
||||||
def myroot(req)
|
def myroot(req)
|
||||||
if req.ssl? then
|
if req.ssl? then
|
||||||
return "https://#{req.host}:#{req.port}"
|
return "https://#{HTTP_SERVER_ROOT}"
|
||||||
else
|
else
|
||||||
return "http://#{req.host}:#{req.port}"
|
return "http://#{HTTP_SERVER_ROOT}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def register(username,password)
|
||||||
|
cl = Jabber::Client.new(Jabber::JID.new(
|
||||||
|
|
||||||
def sendmail(code,email)
|
def sendmail(code,email)
|
||||||
smtp = Net::SMTP.new(SMTP_SERVER, SMTP_PORT)
|
smtp = Net::SMTP.new(SMTP_SERVER, SMTP_PORT)
|
||||||
msg_headers = ''
|
msg_headers = ''
|
||||||
|
@ -49,19 +59,26 @@ server = Hyde::Server.new Port: 8001 do
|
||||||
end
|
end
|
||||||
path "api" do
|
path "api" do
|
||||||
post 'register' do |ctx|
|
post 'register' do |ctx|
|
||||||
|
server_uri = myroot ctx.request
|
||||||
# Add pending user
|
# Add pending user
|
||||||
key = (1..32).map { |x| "0123456789ABCDEF"[(rand()*15).round] }.join
|
key = (1..32).map { |x| "0123456789ABCDEF"[(rand()*15).round] }.join
|
||||||
user = ctx.request.query['user']
|
user = ctx.request.query['user']
|
||||||
password = ctx.request.query['password']
|
password = ctx.request.query['password']
|
||||||
email = ctx.request.query['email']
|
email = ctx.request.query['email']
|
||||||
expires_on = Time.now+60*60*2
|
expires_on = Time.now+60*60*2
|
||||||
Pending[key] = {
|
unless user.match /^[\w_-]+$/ and
|
||||||
|
email.match norxondor_gorgonax and
|
||||||
|
password.match /^.{8,}$/ then
|
||||||
|
redirect server_uri+"/register/error.html"
|
||||||
|
end
|
||||||
|
if Pending_by_username[user] then
|
||||||
|
redirect server_uri+"/register/error.html"
|
||||||
|
end
|
||||||
|
Pending_by_username[user] = Pending[key] = {
|
||||||
"user" => user,
|
"user" => user,
|
||||||
"password" => password,
|
"password" => password,
|
||||||
"email" => email,
|
"expires_on" => expires_on
|
||||||
"expires_one" => expires_on
|
|
||||||
}
|
}
|
||||||
server_uri = myroot ctx.request
|
|
||||||
begin
|
begin
|
||||||
sendmail(key,email)
|
sendmail(key,email)
|
||||||
redirect server_uri+"/register/validate.html"
|
redirect server_uri+"/register/validate.html"
|
||||||
|
@ -73,11 +90,18 @@ server = Hyde::Server.new Port: 8001 do
|
||||||
server_uri = myroot ctx.request
|
server_uri = myroot ctx.request
|
||||||
key = ctx.request.query['key']
|
key = ctx.request.query['key']
|
||||||
if Pending.has_key? key then
|
if Pending.has_key? key then
|
||||||
# do things here
|
if Pending[key].expires_on < Time.now then
|
||||||
puts Pending[key], "successfully verified"
|
puts "#{Pending.delete key} expired"
|
||||||
|
redirect server_uri+"/register/error.html"
|
||||||
|
end
|
||||||
|
cl = Jabber::Client.new(Jabber::JID.new(Pending[key]["user"]+"@"+JABBER_SERVER))
|
||||||
|
cl.connect
|
||||||
|
cl.register(Pending[key]["password"])
|
||||||
|
cl.close
|
||||||
|
puts "#{Pending[key]} successfully verified"
|
||||||
redirect server_uri+"/register/success.html"
|
redirect server_uri+"/register/success.html"
|
||||||
else
|
else
|
||||||
puts Pending[key], "failed to verify"
|
puts "#{Pending[key]} failed to verify"
|
||||||
redirect server_uri+"/register/error.html"
|
redirect server_uri+"/register/error.html"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -24,6 +24,13 @@
|
||||||
<button>Register</button>
|
<button>Register</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
<p> Requirements: </p>
|
||||||
|
<ul>
|
||||||
|
<li> Valid email (only for verification) </li>
|
||||||
|
<li> A password that is at least 8 characters long </li>
|
||||||
|
<li> A username that contains slashes, dashes, and alphanumeric characters</li>
|
||||||
|
</ul>
|
||||||
|
<p> Review the source code of this <a href="https://adastra7.net/git/Yessiest/sentry">registration page</a></p>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue