Realm creation

This commit is contained in:
Craig Everett 2018-05-31 19:58:42 +09:00
parent 014909f79b
commit 28598cccf0
2 changed files with 32 additions and 26 deletions

5
zomp/etc/otpr/zxq9.user Normal file
View File

@ -0,0 +1,5 @@
{realm,"otpr"}.
{username,"zxq9"}.
{realmname,"Craig Everett"}.
{contact_info,{"email","zxq9@zxq9.com"}}.
{keys,["zxq9-root"]}.

View File

@ -777,11 +777,12 @@ create_user(Realm, Username) ->
%% realm file to the user. %% realm file to the user.
create_realm() -> create_realm() ->
ok = log(info, "WOOHOO! Making a new realm!"),
Instructions = Instructions =
"~n" "~nNAMING~n"
" Enter a name for your new realm.~n" "Enter a name for your new realm.~n"
" Names can contain only lower-case letters, numbers and the underscore.~n" "Names can contain only lower-case letters, numbers and the underscore.~n"
" Names must begin with a lower-case letter.~n", "Names must begin with a lower-case letter.~n",
ok = io:format(Instructions), ok = io:format(Instructions),
Realm = zx_tty:get_input(), Realm = zx_tty:get_input(),
case zx_lib:valid_lower0_9(Realm) of case zx_lib:valid_lower0_9(Realm) of
@ -812,11 +813,11 @@ create_realm(Realm) ->
prompt_address() -> prompt_address() ->
Message = Message =
"~n" "~nHOST ADDRESS~n"
" Enter a static, valid hostname or IPv4 or IPv6 address at which this host " "Enter a static, valid hostname or IPv4 or IPv6 address at which this host "
"can be reached from the public internet (or internal network if it will never " "can be reached from the public internet (or internal network if it will never "
"need to be reached from the internet).~n" "need to be reached from the internet).~n"
" DO NOT INCLUDE A PORT NUMBER IN THIS STEP~n", "DO NOT INCLUDE A PORT NUMBER IN THIS STEP~n",
ok = io:format(Message), ok = io:format(Message),
case zx_tty:get_input() of case zx_tty:get_input() of
"" -> "" ->
@ -842,8 +843,8 @@ parse_address(String) ->
create_realm(Realm, Address) -> create_realm(Realm, Address) ->
Message = Message =
"~n" "~nPUBLIC PORT NUMBER~n"
" Enter the public (external) port number at which this service should be " "Enter the public (external) port number at which this service should be "
"available. (This might be different from the local port number if you are " "available. (This might be different from the local port number if you are "
"forwarding ports or have a complex network layout.)~n", "forwarding ports or have a complex network layout.)~n",
ok = io:format(Message), ok = io:format(Message),
@ -857,8 +858,8 @@ create_realm(Realm, Address) ->
prompt_port_number(Current) -> prompt_port_number(Current) ->
Instructions = Instructions =
" A valid port is any number from 1 to 65535." "A valid port is any number from 1 to 65535."
" [Press enter to accept the current setting: ~tw]~n", "[Press enter to accept the current setting: ~tw]~n",
ok = io:format(Instructions, [Current]), ok = io:format(Instructions, [Current]),
case zx_tty:get_input() of case zx_tty:get_input() of
"" -> "" ->
@ -888,10 +889,10 @@ prompt_port_number(Current) ->
create_realm(Realm, Address, Port) -> create_realm(Realm, Address, Port) ->
Instructions = Instructions =
"~n" "~nSYSOP USERNAME~n"
" Enter a username for the realm sysop.~n" "Enter a username for the realm sysop.~n"
" Names can contain only lower-case letters, numbers and the underscore.~n" "Names can contain only lower-case letters, numbers and the underscore.~n"
" Names must begin with a lower-case letter.~n", "Names must begin with a lower-case letter.~n",
ok = io:format(Instructions), ok = io:format(Instructions),
UserName = zx_tty:get_input(), UserName = zx_tty:get_input(),
case zx_lib:valid_lower0_9(UserName) of case zx_lib:valid_lower0_9(UserName) of
@ -911,9 +912,9 @@ create_realm(Realm, Address, Port) ->
create_realm(Realm, Address, Port, UserName) -> create_realm(Realm, Address, Port, UserName) ->
Instructions = Instructions =
"~n" "~nSYSOP EMAIL~n"
" Enter an email address for the realm sysop.~n" "Enter an email address for the realm sysop.~n"
" Valid email address rules apply though the checking done here is quite " "Valid email address rules apply though the checking done here is quite "
"minimal. Check the address you enter carefully. The only people who will " "minimal. Check the address you enter carefully. The only people who will "
"suffer from an invalid address are your users.~n", "suffer from an invalid address are your users.~n",
ok = io:format(Instructions), ok = io:format(Instructions),
@ -946,9 +947,9 @@ create_realm(Realm, Address, Port, UserName) ->
create_realm(Realm, Address, Port, UserName, Email) -> create_realm(Realm, Address, Port, UserName, Email) ->
Instructions = Instructions =
"~n" "~nSYSOP REAL NAME~n"
" Enter the real name (or whatever name people recognize) for the sysop.~n" "Enter the real name (or whatever name people recognize) for the sysop.~n"
" There are no rules for this one. Any valid UTF-8 printables are legal.~n", "There are no rules for this one. Any valid UTF-8 printables are legal.~n",
ok = io:format(Instructions), ok = io:format(Instructions),
RealName = zx_tty:get_input(), RealName = zx_tty:get_input(),
create_realm(Realm, Address, Port, UserName, Email, RealName). create_realm(Realm, Address, Port, UserName, Email, RealName).
@ -976,7 +977,7 @@ create_realm(Realm, Address, Port, UserName, Email, RealName) ->
[{realm, Realm}, [{realm, Realm},
{username, UserName}, {username, UserName},
{realmname, RealName}, {realmname, RealName},
{contact_info, {"email", Email}}, {contact_info, [{"email", Email}]},
{keys, [KeyName]}], {keys, [KeyName]}],
RealmConfPath = filename:join(zx_lib:path(etc, Realm), "realm.conf"), RealmConfPath = filename:join(zx_lib:path(etc, Realm), "realm.conf"),
ok = zx_lib:write_terms(RealmConfPath, RealmConf), ok = zx_lib:write_terms(RealmConfPath, RealmConf),
@ -988,7 +989,7 @@ create_realm(Realm, Address, Port, UserName, Email, RealName) ->
"===========================================================================~n" "===========================================================================~n"
"DONE!~n" "DONE!~n"
"~n" "~n"
"The realm ~tp has been created and is accessible from the current system.~n" "The realm ~tp has been created and is accessible from this system.~n"
"~n" "~n"
"Other zomp nodes and zx users will need the new realm file, ~ts, to~n" "Other zomp nodes and zx users will need the new realm file, ~ts, to~n"
"access the realm. It does not include any public keys.~n" "access the realm. It does not include any public keys.~n"
@ -1046,10 +1047,10 @@ configure_zomp() ->
Dir :: file:filename(). Dir :: file:filename().
create_realmfile(Realm, Dir) -> create_realmfile(Realm, Dir) ->
RealmConf = zx_lib:load_realm_conf(Realm), {ok, RealmConf} = zx_lib:load_realm_conf(Realm),
ok = log(info, "Realm found, creating realm file..."), ok = log(info, "Realm found, creating realm file..."),
KeyName = proplists:get_value(key, RealmConf), KeyName = maps:get(key, RealmConf),
PubKeyPath = zx_key:name(pub, KeyName), PubKeyPath = zx_key:keypath(public, {Realm, KeyName}),
{ok, PubDER} = file:read_file(PubKeyPath), {ok, PubDER} = file:read_file(PubKeyPath),
Blob = term_to_binary({RealmConf, PubDER}), Blob = term_to_binary({RealmConf, PubDER}),
ZRF = filename:join(Dir, Realm ++ ".zrf"), ZRF = filename:join(Dir, Realm ++ ".zrf"),