Skip to content

Commit

Permalink
luci-app-squid: convert to JavaScript
Browse files Browse the repository at this point in the history
The conversion adds the missing parameters in the UI which is
configurable in the principal package.

Assumption has been made that the config file is stored in /etc/squid
since the principal package limits the sysconfdir to this directory. If
that assumption is changed in the future we need to adjust the ACL.

Signed-off-by: Daniel Nilsson <dannil+github@protonmail.com>
  • Loading branch information
dannil authored and systemcrash committed Oct 17, 2024
1 parent ade3606 commit 5c6b08c
Show file tree
Hide file tree
Showing 44 changed files with 1,859 additions and 300 deletions.
5 changes: 3 additions & 2 deletions applications/luci-app-squid/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
include $(TOPDIR)/rules.mk

LUCI_TITLE:=Squid LuCI Interface
LUCI_DEPENDS:=+luci-compat +luci-base +squid
LUCI_DEPENDS:=+luci-base +squid

PKG_MAINTAINER:=Marko Ratkaj <marko.ratkaj@sartura.hr>
PKG_MAINTAINER:=Marko Ratkaj <marko.ratkaj@sartura.hr>, \
Daniel Nilsson <dannil+github@protonmail.com>
PKG_LICENSE:=Apache-2.0

include ../../luci.mk
Expand Down
134 changes: 134 additions & 0 deletions applications/luci-app-squid/htdocs/luci-static/resources/view/squid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
'use strict';

'require form';
'require fs';
'require rpc';
'require uci';
'require view';

var getCompileTimeOptions = rpc.declare({
object: 'luci.squid',
method: 'getCompileTimeOptions',
expect: { options: [] }
});

function validateFile(path) {
if (!path.startsWith('/etc/squid/')) {
return _('File must be located in directory /etc/squid');
}
return true;
}

function writeFile(path, content) {
if (content) {
var normalized = content.replaceAll('\r\n', '\n');
fs.write(path, normalized);
}
}

return view.extend({

load: function() {
var load_squid = uci.load('squid')
.then(() => uci.get('squid', 'squid'));
return Promise.all([load_squid, getCompileTimeOptions()]);
},

render: function(data) {
var { config_file, mime_table } = data[0];
var options = data[1];

var m, s, o;

m = new form.Map('squid', _('Squid'));

s = m.section(form.TypedSection, 'squid');
s.anonymous = true;
s.addremove = false;

s.tab('general', _('General Settings'));
s.tab('advanced', _('Advanced Settings'));

var o = s.taboption('general', form.Value, 'config_file', _('Config file'));
o.datatype = 'string';
o.default = '/etc/squid/squid.conf';
o.validate = function(section_id, value) {
return validateFile(value);
};

o = s.taboption('general', form.Value, 'mime_table', _('Mime table'));
o.datatype = 'string';
o.default = '/etc/squid/mime.conf';
o.validate = function(section_id, value) {
return validateFile(value);
};

o = s.taboption('general', form.Value, 'http_port', _('Port'));
o.datatype = 'portrange';
o.placeholder = '0-65535';

o = s.taboption('general', form.Value, 'http_port_options', _('HTTP port options'));
o.datatype = 'string';
o.optional = true;

o = s.taboption('general', form.Value, 'ssl_db', _('SSL DB'));
o.datatype = 'string';
o.optional = true;

o = s.taboption('general', form.Value, 'ssldb_options', _('SSL DB options'));
o.datatype = 'string';
o.optional = true;

o = s.taboption('general', form.Value, 'visible_hostname', _('Visible Hostname'));
o.datatype = 'string';
o.placeholder = 'OpenWrt';

o = s.taboption('general', form.Value, 'coredump_dir', _('Coredump files directory'));
o.datatype = 'string';
o.placeholder = '/tmp/squid';

var enable_icmp_option = '--enable-icmp';
var is_enable_icmp_defined = options.includes(enable_icmp_option);
o = s.taboption('general', form.Flag, 'pinger_enable', _('Enable ICMP pinger'),
!is_enable_icmp_defined ? _('Can only be set if Squid is compiled with the %s option').format(`<code>${enable_icmp_option}</code>`) : null);
o.datatype = 'string';
o.enabled = 'on';
o.disabled = 'off';
o.readonly = !is_enable_icmp_defined;

o = s.taboption('advanced', form.SectionValue, '_advanced', form.TypedSection, '_advanced', null,
_('Advanced settings grants you direct access to the configuration files.'));

var advanced = o.subsection;
advanced.anonymous = true;
advanced.cfgsections = function() { return [ '_advanced' ] };

advanced.tab('_config_file', _('Config file'));
advanced.tab('_mime_table', _('Mime table'));

o = advanced.taboption('_config_file', form.TextValue, '_config_file_data');
o.wrap = false;
o.rows = 25;
o.rmempty = false;
o.cfgvalue = function(section_id) {
return fs.read(config_file);
};
o.write = function(section_id, value) {
writeFile(config_file, value);
};

o = advanced.taboption('_mime_table', form.TextValue, '_mime_table_data');
o.wrap = false;
o.rows = 25;
o.rmempty = false;
o.cfgvalue = function(section_id) {
return fs.read(mime_table);
};
o.write = function(section_id, value) {
writeFile(mime_table, value);
};

return m.render();
},

});
67 changes: 0 additions & 67 deletions applications/luci-app-squid/luasrc/model/cbi/squid.lua

This file was deleted.

50 changes: 44 additions & 6 deletions applications/luci-app-squid/po/ar/squid.po
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,69 @@ msgstr ""
"&& n%100<=10 ? 3 : n%100>=11 ? 4 : 5;\n"
"X-Generator: Weblate 5.7-dev\n"

#: applications/luci-app-squid/luasrc/model/cbi/squid.lua:42
#: applications/luci-app-squid/htdocs/luci-static/resources/view/squid.js:50
msgid "Advanced Settings"
msgstr "إعدادات متقدمة"

#: applications/luci-app-squid/luasrc/model/cbi/squid.lua:38
#: applications/luci-app-squid/htdocs/luci-static/resources/view/squid.js:100
msgid "Advanced settings grants you direct access to the configuration files."
msgstr ""

#: applications/luci-app-squid/htdocs/luci-static/resources/view/squid.js:93
msgid "Can only be set if Squid is compiled with the %s option"
msgstr ""

#: applications/luci-app-squid/htdocs/luci-static/resources/view/squid.js:52
#: applications/luci-app-squid/htdocs/luci-static/resources/view/squid.js:106
msgid "Config file"
msgstr ""

#: applications/luci-app-squid/htdocs/luci-static/resources/view/squid.js:86
msgid "Coredump files directory"
msgstr "دليل ملفات Coredump"

#: applications/luci-app-squid/luasrc/model/cbi/squid.lua:28
#: applications/luci-app-squid/htdocs/luci-static/resources/view/squid.js:92
msgid "Enable ICMP pinger"
msgstr ""

#: applications/luci-app-squid/htdocs/luci-static/resources/view/squid.js:17
msgid "File must be located in directory /etc/squid"
msgstr ""

#: applications/luci-app-squid/htdocs/luci-static/resources/view/squid.js:49
msgid "General Settings"
msgstr "الاعدادات العامة"

#: applications/luci-app-squid/root/usr/share/rpcd/acl.d/luci-app-squid.json:3
msgid "Grant UCI access for luci-app-squid"
msgstr "منح UCI حق الوصول إلى luci - app - squid"

#: applications/luci-app-squid/luasrc/model/cbi/squid.lua:30
#: applications/luci-app-squid/htdocs/luci-static/resources/view/squid.js:70
msgid "HTTP port options"
msgstr ""

#: applications/luci-app-squid/htdocs/luci-static/resources/view/squid.js:59
#: applications/luci-app-squid/htdocs/luci-static/resources/view/squid.js:107
msgid "Mime table"
msgstr ""

#: applications/luci-app-squid/htdocs/luci-static/resources/view/squid.js:66
msgid "Port"
msgstr "المنفذ"

#: applications/luci-app-squid/luasrc/model/cbi/squid.lua:21
#: applications/luci-app-squid/htdocs/luci-static/resources/view/squid.js:74
msgid "SSL DB"
msgstr ""

#: applications/luci-app-squid/htdocs/luci-static/resources/view/squid.js:78
msgid "SSL DB options"
msgstr ""

#: applications/luci-app-squid/htdocs/luci-static/resources/view/squid.js:43
#: applications/luci-app-squid/root/usr/share/luci/menu.d/luci-app-squid.json:3
msgid "Squid"
msgstr "حبار"

#: applications/luci-app-squid/luasrc/model/cbi/squid.lua:34
#: applications/luci-app-squid/htdocs/luci-static/resources/view/squid.js:82
msgid "Visible Hostname"
msgstr "اسم المضيف المرئي"
50 changes: 44 additions & 6 deletions applications/luci-app-squid/po/bg/squid.po
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,69 @@ msgstr ""
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Weblate 5.5-dev\n"

#: applications/luci-app-squid/luasrc/model/cbi/squid.lua:42
#: applications/luci-app-squid/htdocs/luci-static/resources/view/squid.js:50
msgid "Advanced Settings"
msgstr "Разширени настройки"

#: applications/luci-app-squid/luasrc/model/cbi/squid.lua:38
#: applications/luci-app-squid/htdocs/luci-static/resources/view/squid.js:100
msgid "Advanced settings grants you direct access to the configuration files."
msgstr ""

#: applications/luci-app-squid/htdocs/luci-static/resources/view/squid.js:93
msgid "Can only be set if Squid is compiled with the %s option"
msgstr ""

#: applications/luci-app-squid/htdocs/luci-static/resources/view/squid.js:52
#: applications/luci-app-squid/htdocs/luci-static/resources/view/squid.js:106
msgid "Config file"
msgstr ""

#: applications/luci-app-squid/htdocs/luci-static/resources/view/squid.js:86
msgid "Coredump files directory"
msgstr ""

#: applications/luci-app-squid/luasrc/model/cbi/squid.lua:28
#: applications/luci-app-squid/htdocs/luci-static/resources/view/squid.js:92
msgid "Enable ICMP pinger"
msgstr ""

#: applications/luci-app-squid/htdocs/luci-static/resources/view/squid.js:17
msgid "File must be located in directory /etc/squid"
msgstr ""

#: applications/luci-app-squid/htdocs/luci-static/resources/view/squid.js:49
msgid "General Settings"
msgstr "Общи настройки"

#: applications/luci-app-squid/root/usr/share/rpcd/acl.d/luci-app-squid.json:3
msgid "Grant UCI access for luci-app-squid"
msgstr ""

#: applications/luci-app-squid/luasrc/model/cbi/squid.lua:30
#: applications/luci-app-squid/htdocs/luci-static/resources/view/squid.js:70
msgid "HTTP port options"
msgstr ""

#: applications/luci-app-squid/htdocs/luci-static/resources/view/squid.js:59
#: applications/luci-app-squid/htdocs/luci-static/resources/view/squid.js:107
msgid "Mime table"
msgstr ""

#: applications/luci-app-squid/htdocs/luci-static/resources/view/squid.js:66
msgid "Port"
msgstr "Порт"

#: applications/luci-app-squid/luasrc/model/cbi/squid.lua:21
#: applications/luci-app-squid/htdocs/luci-static/resources/view/squid.js:74
msgid "SSL DB"
msgstr ""

#: applications/luci-app-squid/htdocs/luci-static/resources/view/squid.js:78
msgid "SSL DB options"
msgstr ""

#: applications/luci-app-squid/htdocs/luci-static/resources/view/squid.js:43
#: applications/luci-app-squid/root/usr/share/luci/menu.d/luci-app-squid.json:3
msgid "Squid"
msgstr ""

#: applications/luci-app-squid/luasrc/model/cbi/squid.lua:34
#: applications/luci-app-squid/htdocs/luci-static/resources/view/squid.js:82
msgid "Visible Hostname"
msgstr ""
Loading

0 comments on commit 5c6b08c

Please sign in to comment.