Here's what I figured out, in case anyone else finds this useful:
In its most basic form, if you have an external page, you need 3 pages on the mikrotik:
rlogin.html:
Redirects to your login page when client tries to access any other page, and is not logged in.
<html>
<head>
<title>Login</title>
<meta http-equiv="refresh" content="0; url=http://EXTERNAL_LOGIN_PAGE_IP">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="expires" content="-1">
<style>
body {
background-color: #222222;
}
</style>
</head>
<body>
</body>
</html>
Where EXTERNAL_LOGIN_PAGE_IP is the IP address or domain name of your external login page.
The <style> element is optional. Here's its only purpose is to have the same colored background as my external page.
alogin.html
Required to login, and redirect user to the page they were trying to get to originally (before they were redirected to your external page).
<html>
<head>
<title>Redirect</title>
<meta http-equiv="refresh" content="0; url=$(link-redirect)">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="expires" content="-1">
<style>
body {
background-color: #222222;
}
</style>
</head>
<body>
</body>
</html>
Same thing here - <style> element is optional, and only used to have the same background as external page.
logout.html:
Used to log a user out. Redirects back to your external login page after user has been logged out.
<html>
<head>
<title>Logout</title>
<meta http-equiv="refresh" content="0; url=http://EXTERNAL_LOGIN_PAGE_IP">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="expires" content="-1">
<style>
body {
background-color: #222222;
}
</style>
</head>
<body>
</body>
</html>
Where EXTERNAL_LOGIN_PAGE_IP is the IP address or domain name of your external login page.
The <style> element is optional. Here's its only purpose is to have the same colored background as my external page.
External Page:
Now my external page has:
A logout button on a page the user sees when the are logged in
Redirects to logout.html on the mikrotik (the page above), which logs the user out, and sends us back to the external login page
A login form
User enters username and password, and that gets sent to the mikrotik (see below)
An account creation page
In my case, when users get created, I make entries in my RADIUS server - I don't do anything with the mikrotik directly here
External Login Form:
<form name="redirect" method="POST" action="http://MIKROTIK_IP/login" target="_self">
<input type="text" name="username" autofocus >
<input type="password" name="password" >
<input type="hidden" name="domain" value="">
<input type="hidden" name="dst" value="http://EXTERNAL_LOGIN_PAGE_IP/my_account">
<input type="submit" value="Submit" >
</form>
Where MIKROTIK_IP is the IP address of the mikrotik device.
Where EXTERNAL_LOGIN_PAGE_IP is the IP or hostname of the external login page.
This page will allow user to enter username and password, and send it to the mikrotik.
The mikrotik will either check its internal user/password database, or the RADIUS server you configured it with.
In my case, before I send the username and password to the mikrotik, I already know they are correct (my code is quite a bit more complicated then the one above).
If you are using the above code, you'll need a way to handle invalid username/password entries. You'd probably need another page like flogin.html on the mikrotik that will redirect back to a page on your external login page, and tell users the username/password was wrong.
You will probably need more content than that, but that's a good starting point.
To pass info from the Mikrotik back to the external page, use a form on the mikrotik with variables for values that the mikrotik will fill in.