stuff
This commit is contained in:
parent
4e774fb473
commit
66d0d3858b
|
@ -0,0 +1,3 @@
|
||||||
|
[submodule "hyde"]
|
||||||
|
path = hyde
|
||||||
|
url = https://adastra7.net/git/Yessiest/hyde
|
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit f1f13faddf0f4a454c0a13c28957e53146eb529c
|
|
@ -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
|
|
@ -0,0 +1,12 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title> Registration form </title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1> Oops! </h1>
|
||||||
|
<hr />
|
||||||
|
<p> The data your provided is invalid </p>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title> Registration form </title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1> Welcome to adastra7 XMPP </h1>
|
||||||
|
<hr />
|
||||||
|
<p> Before you are able to log into our service, register using the form below </p>
|
||||||
|
<form action="/api/register" method="POST">
|
||||||
|
<div>
|
||||||
|
<label for="email">Your email (to verify the account)</label>
|
||||||
|
<input name="email" id="email" value="" />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label for="user">Your username</label>
|
||||||
|
<input name="user" id="user" value="" />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label for="password">Your password</label>
|
||||||
|
<input name="password" type="password" id="password" value="" />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<button>Register</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title> Registration form </title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1> Success! </h1>
|
||||||
|
<hr />
|
||||||
|
<p> Your account has been registered, and you are now ready to use our XMPP service! </p>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title> Registration form </title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1> Just one more step! </h1>
|
||||||
|
<hr />
|
||||||
|
<p> You have been sent a verification key to your email account. Please enter it here </p>
|
||||||
|
<p> 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. </p>
|
||||||
|
<form action="/api/validate" method="POST">
|
||||||
|
<div>
|
||||||
|
<label for="key">Your verification key</label>
|
||||||
|
<input name="key" id="key" value="" />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<button>Validate</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
Loading…
Reference in New Issue