Skip to content

Commit

Permalink
feat(node,server): implement certpath validate
Browse files Browse the repository at this point in the history
Signed-off-by: Tianling Shen <[email protected]>
  • Loading branch information
1715173329 committed Dec 4, 2024
1 parent 1d815e1 commit f82fce5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
11 changes: 11 additions & 0 deletions htdocs/luci-static/resources/homeproxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,17 @@ return baseclass.extend({
return true;
},

validateCertificatePath: function(rmempty, section_id, value) {
if (section_id)
if (!value && !rmempty)
return _('Expecting: %s').format(_('non-empty value'));

if (!value.match(/^(\/etc\/homeproxy\/certs\/|\/etc\/acme\/|\/etc\/ssl\/).+$/))
return _('Expecting: %s').format('/etc/homeproxy/certs/..., /etc/acme/..., /etc/ssl/...');

return true;
},

validateUniqueValue: function(uciconfig, ucisection, ucioption, section_id, value) {
if (section_id) {
if (!value)
Expand Down
2 changes: 1 addition & 1 deletion htdocs/luci-static/resources/view/homeproxy/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@ function renderNodeSettings(section, data, features, main_node, routing_mode) {
_('The path to the server certificate, in PEM format.'));
o.value('/etc/homeproxy/certs/client_ca.pem');
o.depends('tls_self_sign', '1');
o.rmempty = false;
o.validate = L.bind(hp.validateCertificatePath, this, false);
o.modalonly = true;

o = s.option(form.Button, '_upload_cert', _('Upload certificate'),
Expand Down
4 changes: 2 additions & 2 deletions htdocs/luci-static/resources/view/homeproxy/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ return view.extend({
o.depends({'tls': '1', 'tls_acme': '0', 'tls_reality': '0'});
o.depends({'tls': '1', 'tls_acme': null, 'tls_reality': '0'});
o.depends({'tls': '1', 'tls_acme': null, 'tls_reality': null});
o.rmempty = false;
o.validate = L.bind(hp.validateCertificatePath, this, false);
o.modalonly = true;

o = s.option(form.Button, '_upload_cert', _('Upload certificate'),
Expand All @@ -763,7 +763,7 @@ return view.extend({
o.depends({'tls': '1', 'tls_acme': '0', 'tls_reality': null});
o.depends({'tls': '1', 'tls_acme': null, 'tls_reality': '0'});
o.depends({'tls': '1', 'tls_acme': null, 'tls_reality': null});
o.rmempty = false;
o.validate = L.bind(hp.validateCertificatePath, this, false);
o.modalonly = true;

o = s.option(form.Button, '_upload_key', _('Upload key'),
Expand Down

0 comments on commit f82fce5

Please sign in to comment.