<!-- Tempalte for server configuration -->
<br>
[% UNLESS user_info.admin %]
<h1>You are not authorised to change server configuration </h1>
[% RETURN %]
[% END %]

<h1>Server configuration (common for all test stations on this server)</h1>

<div class="content-container fit-content">
<table class=misc_conf>
<tr style="height:1px;"><td></td><td></td><td></tr>
<tr><td colspan=3><b>Warning: Only change these settings if you know what you are doing!</b></td></tr>
<tr><th colspan=3>Global</th></tr>
<!--<tr><td title="List of email addresses who will recieve error emails once pr day
if one or more errors occoured the previous day"> Errormails </td><td><input type="text" name="errormails" onchange="change_val(this,'global')" id="errormails" class="textfield" value="[% data.global.errormails %]" autocomplete=off></td></tr>-->
<tr><td title="Regular expression used to validate if users starting a new test has supplied a valid project number"> Project number validation regex </td><td><input type="text" name="account_number_regexp" onchange="change_val(this,'global')" id="account_number_regexp" class="textfield" value="[% data.global.account_number_regexp %]" autocomplete=off></td></tr>
<tr><td title="Display name for the RFCcontrol server"> Server name </td><td><input type="text" name="server_name" onchange="change_val(this,'global')" id="server_name" class="textfield" value="[% data.global.server_name %]" autocomplete=off></td></tr>
<tr><td title="Hostname used as sender for emails to users
(used in case the user replies to an email from RFCcotrol)"> Mail host </td><td><input type="text" name="mailhost" onchange="change_val(this,'global')" id="mailhost" class="textfield" value="[% data.global.mailhost %]" autocomplete=off></td></tr>
<tr><td title="Username used as sender for emails to users
(used in case the user replies to an email from RFCcotrol)"> Mail user </td><td><input type="text" name="mailuser" onchange="change_val(this,'global')" id="mailuser" class="textfield" value="[% data.global.mailuser %]" autocomplete=off></td></tr>
<tr><td title="Derermines how often the process values on the GUI (user interface) updates.
Note has no influenct on the actual data logging which is determined by crontab"> GUI data reload time (seconds)</td><td><input type="text" name="GUI_reload_time" onchange="change_val(this,'global')" id="GUI_reload_time" class="textfield" value="[% data.global.GUI_reload_time %]" autocomplete=off></td></tr>
<tr><td title=""> Project number validate URL </td><td colspan=2><input type="text" name="project_number_validate_url" onchange="change_val(this,'global')" id="project_number_validate_url" class="textfield" value="[% data.global.project_number_validate_url %]" autocomplete=off></td></tr>
<tr><td title="URL used to find valid project numbers
Should have a suitable validator which will return a list of potential valid project numbers
based on the supplied partial information."> Project number autocomplete url </td><td colspan=2><input type="text" name="project_number_autocomplete_url" onchange="change_val(this,'global')" id="project_number_autocomplete_url" class="textfield" value="[% data.global.project_number_autocomplete_url %]" autocomplete=off></td></tr>
<tr><td title="URL for writing to a remote logbook."> Remote log url </td><td colspan=2><input type="text" name="remote_log_url" onchange="change_val(this,'global')" id="remote_log_url" class="textfield" value="[% data.global.remote_log_url %]" autocomplete=off></td></tr>
<tr><td title="URL to display the logbook for the RRCcontrol test station"> Logbook url </td><td colspan=2><input type="text" name="logbook_url" onchange="change_val(this,'global')" id="logbook_url" class="textfield" value="[% data.global.logbook_url %]" autocomplete=off></td></tr>
<tr><td title="Remote database ID"> Equipment ID </td><td><input type="text" name="equipmentid" onchange="change_val(this,'global')" id="equipmentid" class="textfield" value="[% data.global.equipmentid %]" autocomplete=off></td></tr>
<tr><td title="Authorisation id used for determining if a user is allowed to view standard reports
Note that if no value is specified all users will be allowed to see all reports.
In order to remove access use a negative number (-1) or an ohter non-existing record ID."> Report authorisation ID </td><td><input type="text" name="report_authorisationid" onchange="change_val(this,'global')" id="report_authorisationid" class="textfield" value="[% data.global.report_authorisationid %]" autocomplete=off></td></tr>

<!--<tr><td title=""> Set warning email on start </td><td>
<select name="set_warning_email_on_start" onchange="change_val(this,'global')" id="set_warning_email_on_start" autocomplete=off>
[% IF data.global.set_warning_email_on_start.lower == 'yes' %]
<option value="No">No</option>
<option value="Yes" selected=selected>Yes</option>
[% ELSE %]
<option value="No" selected=selected>No</option>
<option value="Yes">Yes</option>
[% END %]
</select>
</td></tr>-->


<tr><td title="Warning: Allowing execution of external programs can be a security risk if said programs are not properly designed!"> Allow external program execution </td><td>
<select name="allow_exec" onchange="change_val(this,'global')" id="allow_exec" autocomplete=off>
[% IF data.global.allow_exec.lower == 'yes' %]
<option value="No">No</option>
<option value="Yes" selected=selected>Yes</option>
[% ELSE %]
<option value="No" selected=selected>No</option>
<option value="Yes">Yes</option>
[% END %]
</select>
</td></tr>

<tr><td title="Only allow access to data to the test owner and users who has explicit access
(Requires an extarnal password server)"> Only allow explicit data access </td><td>
<select name="only_allow_explicit_data_access" onchange="change_val(this,'global')" id="only_allow_explicit_data_access" autocomplete=off>
[% IF data.global.only_allow_explicit_data_access.lower == 'yes' %]
<option value="No">No</option>
<option value="Yes" selected=selected>Yes</option>
[% ELSE %]
<option value="No" selected=selected>No</option>
<option value="Yes">Yes</option>
[% END %]
</select>
</td></tr>

<tr><td title="Only allow authorised users to see the rig main page
(even if non-authorised users can not do anything)"> Authorised users only </td><td>
<select name="restrict_access_auth_only" onchange="change_val(this,'global')" id="restrict_access_auth_only" autocomplete=off>
[% IF data.global.restrict_access_auth_only.lower == 'yes' %]
<option value="No">No</option>
<option value="Yes" selected=selected>Yes</option>
[% ELSE %]
<option value="No" selected=selected>No</option>
<option value="Yes">Yes</option>
[% END %]
</select>
</td></tr>

<tr><td title=""> Allow all authorised users to see curent test data </td><td>
<select name="allow_access_current_test_to_auth_users" onchange="change_val(this,'global')" id="allow_access_current_test_to_auth_users" autocomplete=off>
[% IF data.global.allow_access_current_test_to_auth_users.lower == 'yes' %]
<option value="No">No</option>
<option value="Yes" selected=selected>Yes</option>
[% ELSE %]
<option value="No" selected=selected>No</option>
<option value="Yes">Yes</option>
[% END %]
</select>
</td></tr>

<tr><th colspan=3>Admin</th></tr>
<tr><td title="Save the raw simpælechannel data in separate files
(usually results in doplication of data)"> Save raw kanaldata </td><td>
<select name="save_raw_kanaldata" onchange="change_val(this,'admin')" id="save_raw_kanaldata" autocomplete=off>
[% IF data.admin.save_raw_kanaldata.lower == 'yes' %]
<option value="No">No</option>
<option value="Yes" selected=selected>Yes</option>
[% ELSE %]
<option value="No" selected=selected>No</option>
<option value="Yes">Yes</option>
[% END %]
</select>
</td></tr>
<tr><td title="List of email addresses who will recieve error emails once pr day
if one or more errors occoured the previous day"> System mail users </td><td><input type="text" name="system_mail_users" onchange="change_val_reload(this,'admin')" id="system_mail_users" class="textfield" value="[% data.admin.system_mail_users %]" autocomplete=off></td></tr>

<tr><th colspan=3>Password control</th></tr>
<tr><td title=""> Password server </td><td colspan=2><input type="text" name="passwd_server" onchange="change_val(this,'passwds')" id="passwd_server" class="textfield" value="[% data.passwds.passwd_server %]" autocomplete=off></td></tr>
<tr><td title=""> Password server port </td><td><input type="text" name="passwd_server_port" onchange="change_val(this,'passwds')" id="passwd_server_port" class="textfield" value="[% data.passwds.passwd_server_port %]" autocomplete=off></td></tr>
<tr><td title=""> Password server URL </td><td colspan=2><input type="text" name="passwd_server_url" onchange="change_val(this,'passwds')" id="passwd_server_url" class="textfield" value="[% data.passwds.passwd_server_url %]" autocomplete=off></td></tr>
<tr><td title=""> SSO URL </td><td colspan=2><input type="text" name="sso_url" onchange="change_val(this,'passwds')" id="sso_url" class="textfield" value="[% data.passwds.sso_url %]" autocomplete=off></td></tr>
<tr><td title=""> SSO logout URL </td><td colspan=2><input type="text" name="sso_logout_url" onchange="change_val(this,'passwds')" id="sso_logout_url" class="textfield" value="[% data.passwds.sso_logout_url %]" autocomplete=off></td></tr>

<tr><th colspan=3>Servers</th></tr>
<tr><td title=""> Listserver </td><td colspan=2><input type="text" name="listserver" onchange="change_val_reload(this,'servers')" id="listserver" class="textfield" value="[% data.servers.listserver %]" autocomplete=off></td></tr>
<tr><td title="Comma separated list of IP addresses which is allowed to get data from this server without user authentification"> Allowed hosts </td><td colspan=2><input type="text" name="allowed_ip" onchange="change_val_reload(this,'global')" id="allowed_ip" class="textfield" value="[% data.global.allowed_ip %]" autocomplete=off></td></tr>

[% IF data.servers.listserver == data.hostname || data.servers.listserver == '' || data.servers.listserver == 'localhost' %]
<tr><td title=""> Server names </td><td colspan=2>
<input type="text" name="server_names" onchange="change_val(this,'servers')" id="server_names" class="textfield" value="[% data.servers.server_names %]" autocomplete=off style="display:none;">
<div style="display:flex;flex-direction:column;gap:5px;">
[% FOR i IN data.servers.server_list %]
<div>[% i %] <button title="Delete" onclick="remove_server('[% i %]')"><i class="fa fa-trash-alt"></i></button></div>
[% END %]
<div><input id=new_server type=text value="" placeholder="Input new server name" autocomplete=off> <button title="Save" onclick="add_server(document.getElementById('new_server').value)"><i class="fa fa-save"></i></button></div>
</div>
</td></tr>
[% END %]


<tr><th colspan=3>Test stations</th></tr>
<tr><td title="List of users who will recieve an email if a new test is started."> Start test mail users </td><td><input type="text" name="start_test_mail_users" onchange="change_val_reload(this,'celltest')" id="start_test_mail_users" class="textfield" value="[% data.celltest.start_test_mail_users %]" autocomplete=off></td></tr>
<tr><td title=""> Active test stations </td><td><input type="text" name="rigs" onchange="change_val(this,'celltest')" id="rigs" class="textfield" value="[% data.celltest.rigs %]" autocomplete=off></td></tr>
<tr><td title="If left blank, the default is to show al test stations listed in the setting above.
Only if test stations are disabled (removed from the list of active test stations)
should this setting be used in order to show the historical data for the disabled test staiton(s)"> All test stations on this server </td><td><input type="text" name="[% data.celltest.all_rigs_key %]" onchange="change_val(this,'celltest')" id="[% data.celltest.all_rigs_key %]" class="textfield" value="[% data.celltest.all_rigs %]" autocomplete=off></td></tr>


<tr><th colspan=3>iV curve control limits</th></tr>
<tr><td title=""> Current limit (absolute value in A) </td><td><input type="text" name="current_limit" onchange="change_val(this,'iVcurves')" id="current_limit" class="textfield" value="[% data.iVcurves.current_limit %]" autocomplete=off></td></tr>
<tr><td title=""> Minimum voltage cutoff (mV) for iV curve control </td><td><input type="text" name="minimum_cell_voltage_for_iv" onchange="change_val(this,'iVcurves')" id="minimum_cell_voltage_for_iv" class="textfield" value="[% data.iVcurves.minimum_cell_voltage_for_iv %]" autocomplete=off></td></tr>
<tr><td title=""> Maximum voltage cutoff (mV) for iV curve control </td><td><input type="text" name="maximum_cell_voltage_for_iv" onchange="change_val(this,'iVcurves')" id="maximum_cell_voltage_for_iv" class="textfield" value="[% data.iVcurves.maximum_cell_voltage_for_iv %]" autocomplete=off></td></tr>

[% IF data.RFCfurnace %]
<tr><th colspan=3>Furnace control</th></tr>
<tr><td title="URL used to find valid sample numbers
Should have a suitable validator which will return a list of potential valid sample numbers
based on the supplied partial information."> Sample number autocomplete url </td><td colspan=2><input type="text" name="sample_number_autocomplete_url" onchange="change_val(this,'global')" id="sample_number_autocomplete_url" class="textfield" value="[% data.global.sample_number_autocomplete_url %]" autocomplete=off></td></tr>

<tr><td title="Regular espression used for validating project numbers. Note this overrides the global value!"> Project number regex (Note override)</td><td colspan=2><input type="text" name="project_regex" onchange="change_val(this,'RFCfurnace')" id="project_regex" class="textfield" value="[% data.RFCfurnace.project_regex %]" autocomplete=off></td></tr>
<tr><td title="Comma separated list of IP addresses which are allowed to start and stoip furnaces"> Allowed hosts </td><td colspan=2><input type="text" name="host_allow" onchange="change_val(this,'RFCfurnace')" id="host_allow" class="textfield" value="[% data.RFCfurnace.host_allow %]" autocomplete=off></td></tr>
<tr><td title="Comma separated list of IP addresses which are allowed to retrieve data without user validation"> Certified hosts </td><td colspan=2><input type="text" name="host_certify" onchange="change_val(this,'RFCfurnace')" id="host_certify" class="textfield" value="[% data.RFCfurnace.host_certify %]" autocomplete=off></td></tr>
<tr><td title="URL of a soap interfface who can supply a list of allowed elements"> Remote element list url </td><td colspan=2><input type="text" name="remote_element_list_soap" onchange="change_val(this,'RFCfurnace')" id="remote_element_list_soap" class="textfield" value="[% data.RFCfurnace.remote_element_list_soap %]" autocomplete=off></td></tr>



[% END %]

</table>

<form name=reload>
<input type=hidden name=action value=conf>
[% INCLUDE print_hidden.tt %]
</form>

</div>

<style>

.textfield {
    width:100%;
    resize:horizontal;
    overflow:hidden;
}

.misc_conf {
    text-align:left;
}

.misc_conf th, .misc_conf td {
    padding:5px;
    max-width:300px;
    min-width:200px;
}

.misc_conf th {
/*    text-align:center;*/
    font-size:1.2em;
    padding-top:20px;
}
</style>


<script>



function add_server(name)
{
    var e = document.getElementById('server_names');
    e.value = e.value + ',' + name;
    change_val_reload(e,'servers');
}

function remove_server(name)
{
    if (confirm('Remove server '+name+' from list of servers'))
    {	
	var e = document.getElementById('server_names');
	var list = e.value.split(',');
	var list2 = [];
	for (var x = 0; x < list.length; x++)
	{
	    if (list[x] != name)
	    {
	    	list2.push(list[x]);
 	    }
        }
	e.value = list2.join(',');
	change_val_reload(e,'servers');
    }
}

function set_val(res)
{
    var arr = res.split("\n");
    if (arr[0] == "OK" || arr[0] == "WARN")
    {
        if (arr[0] == "WARN")
        {
            alert(arr[3]);
        }
        var obj = document.getElementById(arr[2]);
        obj.disabled = false;
        obj.value = arr[3];
    }
    else
    {
        alert(arr[0]);
    }
}

function set_val_reload(res)
{
    var arr = res.split("\n");
    if (arr[0] == "OK" || arr[0] == "WARN")
    {
        if (arr[0] == "WARN")
        {
            alert(arr[3]);
        }
        var obj = document.getElementById(arr[2]);
        obj.disabled = false;
        obj.value = arr[3];
    }
    else
    {
        alert(arr[0]);
    }
    document.reload.submit();
}

function change_val(element,section)
{
    var n = element.name;
    var val = encodeURIComponent(element.value);
    element.disabled = true;
    run_ajax('ajax.cgi','&action=change_global_cv&section='+section+'&key='+n+'&value='+val,set_val);
}

function change_val_reload(element,section)
{
    var n = element.name;
    var val = encodeURIComponent(element.value);
    element.disabled = true;
    run_ajax('ajax.cgi','&action=change_global_cv&section='+section+'&key='+n+'&value='+val,set_val_reload);
}

</script>
