Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a Domain Password field to the installation's web UI #7

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions assets/js/main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
let YUNOHOSTDOMAINS = [".noho.st",".ynh.fr",".nohost.me"]

$(document).ready(function() {

if (window.location.pathname != "/install") {
Expand Down Expand Up @@ -184,6 +186,25 @@ $(document).ready(function() {
};
};

function form_update_subscribe(){
var yunohost = false;
for (let i in YUNOHOSTDOMAINS){
if ($("#main_domain").val().endsWith(YUNOHOSTDOMAINS[i])){
yunohost = true;
}
}
var body = $(".subscribe-password-div")
if (yunohost){
body.show();
$("input", body).addClass("validate");
} else {
body.hide();
$("#domain_password").val("");
$("#domain_password_repeat").val("");
$("input", body).removeClass("validate");
}
}

function form_update_optional_section(name)
{
status_ = $("#enable_" + name)[0].checked;
Expand Down Expand Up @@ -232,6 +253,14 @@ $(document).ready(function() {
}
return true;
}
else if (id == "domain_password_repeat")
{
if (item.val() !== $("input[id='domain_password']").val())
{
return "nomatch";
}
return true;
}
};

function form_validate_item(item)
Expand Down Expand Up @@ -290,6 +319,9 @@ $(document).ready(function() {
$(".invalid-feedback").hide();
$(".invalid-feedback.default").css("display", "");

$("#main_domain").on("change",form_update_subscribe)
form_update_subscribe()

cube_input = $("input[id='cubefile']");
cube_input.change(form_update_cube_file_input);
if (cube_input.val())
Expand Down
9 changes: 4 additions & 5 deletions install_procedure.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,11 @@ def upgrade(install_params):

@step
def postinstall(install_params):
command = "yunohost tools postinstall --force-diskspace -d '{main_domain}' -p '{password}'".format(**install_params)
if install_params["use_dyndns_domain"] and len(install_params["domain_password"])>0:
command+=f" --subscribe {install_params['domain_password']}"

run_cmd(
"yunohost tools postinstall -d '{main_domain}' -p '{password}'".format(
**install_params
)
)
run_cmd(command)


@step
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ Jinja2==2.11.3
MarkupSafe==1.1.1
pytz==2020.1
requests==2.24.0
urllib3==1.26.5
urllib3==1.24
Werkzeug==1.0.1
65 changes: 46 additions & 19 deletions templates/form.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,52 @@
{% block main %}
<form id="install_form" action="/" method="POST" novalidate class="mt-5">
<div class="row justify-content-center">
<div class="col-lg-8 col-sm-10 mb-3">
<div class="card">
<h4 class="card-header">{{ _("Server configuration") }}</h4>
<div class="alert alert-info card-header">
<i class="fa fa-info-circle" aria-hidden="true"></i>
{{ _("This is the domain that will be used to name and reach your internet cube. If you do not already own a domain name, you can pick a free domain ending with .nohost.me, .noho.st or .ynh.fr. It will automatically be configured during the setup.") }}
</div>
<div class="card-body">
<div class="form-group row">
<label for="main_domain" class="col-3 col-form-label">{{ _("Main domain") }}</label>
<div class="col-9">
<input type="text" class="validate form-control" name="main_domain" id="main_domain" placeholder="{{ _("myserver.nohost.me") }}" pattern="^([^\W_A-Z]+([-]*[^\W_A-Z]+)*\.)+([^\W\d_]{2,})$">
<div class="invalid-feedback default">
{{ _("Please specify a valid domain") }}
</div>
</div>
</div>
</div>
</div>
<div class="col-lg-8 col-sm-10 mb-3">
<div class="card">
<h4 class="card-header">{{ _("Server configuration") }}</h4>
<div class="alert alert-info card-header">
<i class="fa fa-info-circle" aria-hidden="true"></i>
{{ _("This is the domain that will be used to name and reach your internet cube. If you do not already own a domain name, you can pick a free domain ending with .nohost.me, .noho.st or .ynh.fr. It will automatically be configured during the setup.") }}
</div>
<div class="card-body">
<div class="form-group row">
<label for="main_domain" class="col-3 col-form-label">{{ _("Main domain") }}</label>
<div class="col-9">
<input type="text" class="validate form-control" name="main_domain" id="main_domain" placeholder="{{ _("myserver.nohost.me") }}" pattern="^([^\W_A-Z]+([-]*[^\W_A-Z]+)*\.)+([^\W\d_]{2,})$">
<div class="invalid-feedback default">
{{ _("Please specify a valid domain") }}
</div>
</div>
</div>
<div class="subscribe-password-div">
<div class="form-group row">
<div class="alert alert-info card-header">
<i class="fa fa-info-circle" aria-hidden="true"></i>
{{ _("This kind of domain is freely provided by the YunoHost project. Please remember the password you enter, it will be used to keep control of the domain even if you loose control of your server.") }}
</div>
<label for="domain_password" class="col-3 col-form-label">{{ _("Domain password") }}</label>
<div class="col-9">
<input type="password" class="validate form-control" name="domain_password" id="domain_password" pattern="^.{8,}$">
<div class="invalid-feedback default">
{{ _("Passwords must be at least 8 characters") }}
</div>
</div>
</div>
<div class="form-group row">
<label for="domain_password_repeat" class="col-3 col-form-label">{{ _("Domain Password (repeat)") }}</label>
<div class="col-9">
<input type="password" class="validate form-control" name="domain_password_repeat" id="domain_password_repeat" pattern="^.{8,}$" custom-validation>
<div class="invalid-feedback default">
{{ _("Passwords must be at least 8 characters") }}
</div>
<div class="invalid-feedback nomatch">
{{ _("Passwords do not match") }}
</div>
</div>
</div>
</div>
</div>
</div>
</div>

<div class="col-lg-8 col-sm-10 mb-3">
Expand Down