diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..868ad39 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "hyde"] + path = hyde + url = https://adastra7.net/git/Yessiest/hyde diff --git a/hyde b/hyde new file mode 160000 index 0000000..f1f13fa --- /dev/null +++ b/hyde @@ -0,0 +1 @@ +Subproject commit f1f13faddf0f4a454c0a13c28957e53146eb529c diff --git a/sentry.rb b/sentry.rb new file mode 100644 index 0000000..321f9de --- /dev/null +++ b/sentry.rb @@ -0,0 +1,87 @@ +require_relative 'hyde/hyde' +require 'xmpp4r' +require 'net/smtp' +require 'json' + +CONFIG = JSON.load_file(Dir.pwd+"/.config.json") + +SERVER_NAME = CONFIG["service_name"] +SMTP_SERVER = CONFIG["server"] +SMTP_PORT = CONFIG["port"] +SMTP_USER = CONFIG["user"] +SMTP_PASS = CONFIG["pass"] +SMTP_TLS = CONFIG["tls"] +SMTP_STARTTLS = CONFIG["starttls"] +SMTP_AUTH = CONFIG["auth"].to_sym +Pending = {} + +def myroot(req) + if req.ssl? then + return "https://#{req.host}:#{req.port}" + else + return "http://#{req.host}:#{req.port}" + end +end + +def sendmail(code,email) + smtp = Net::SMTP.new(SMTP_SERVER, SMTP_PORT) + msg_headers = '' + msg_headers << "From: #{SMTP_USER}\r\n" + msg_headers << "To: #{email}\r\n" + msg_headers << "Subject: #{SERVER_NAME} email verification\r\n" + msg_headers << "Date: "+Time.now.to_s+"\r\n" + msg = msg_headers + "\r\nTo finish your account registration, enter the following code: \"#{code}\"\r\n" + SMTP_TLS ? smtp.enable_tls : smtp.disable_tls + SMTP_STARTTLS ? smtp.enable_starttls : smtp.disable_starttls + puts(smtp.start "localhost", SMTP_USER, SMTP_PASS, SMTP_AUTH) + puts(smtp.send_message msg, SMTP_USER, [email]) +end + +server = Hyde::Server.new Port: 8001 do + path "register" do + preprocess do |ctx| + puts "#{ctx.request.remote_ip} is registering" + puts Dir.pwd+"/static/index.html" + end + remap Dir.pwd+"/static/" + index ['index.html'] + serve "*.html" + end + path "api" do + post 'register' do |ctx| + # Add pending user + key = (1..32).map { |x| "0123456789ABCDEF"[(rand()*15).round] }.join + user = ctx.request.query['user'] + password = ctx.request.query['password'] + email = ctx.request.query['email'] + expires_on = Time.now+60*60*2 + Pending[key] = { + "user" => user, + "password" => password, + "email" => email, + "expires_one" => expires_on + } + server_uri = myroot ctx.request + begin + sendmail(key,email) + redirect server_uri+"/register/validate.html" + rescue Exception => e + redirect server_uri+"/register/error.html" + end + end + post 'validate' do |ctx| + server_uri = myroot ctx.request + key = ctx.request.query['key'] + if Pending.has_key? key then + # do things here + puts Pending[key], "successfully verified" + redirect server_uri+"/register/success.html" + else + puts Pending[key], "failed to verify" + redirect server_uri+"/register/error.html" + end + end + end +end + +server.start diff --git a/static/error.html b/static/error.html new file mode 100644 index 0000000..ddf27ea --- /dev/null +++ b/static/error.html @@ -0,0 +1,12 @@ + + +
+The data your provided is invalid
+ + + diff --git a/static/index.html b/static/index.html new file mode 100644 index 0000000..26450dd --- /dev/null +++ b/static/index.html @@ -0,0 +1,29 @@ + + + +Before you are able to log into our service, register using the form below
+ + + + diff --git a/static/success.html b/static/success.html new file mode 100644 index 0000000..92976c6 --- /dev/null +++ b/static/success.html @@ -0,0 +1,12 @@ + + + +Your account has been registered, and you are now ready to use our XMPP service!
+ + + diff --git a/static/validate.html b/static/validate.html new file mode 100644 index 0000000..242725f --- /dev/null +++ b/static/validate.html @@ -0,0 +1,22 @@ + + + +You have been sent a verification key to your email account. Please enter it here
+If you wish to abort account creation, simply close the page. Your validation key will expire in 2 hours, and you can create your account again.
+ + + +