-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
luci-app-squid: convert to JavaScript
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 <[email protected]>
- Loading branch information
Showing
44 changed files
with
1,859 additions
and
300 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 <[email protected]> | ||
PKG_MAINTAINER:=Marko Ratkaj <[email protected]>, \ | ||
Daniel Nilsson <[email protected]> | ||
PKG_LICENSE:=Apache-2.0 | ||
|
||
include ../../luci.mk | ||
|
134 changes: 134 additions & 0 deletions
134
applications/luci-app-squid/htdocs/luci-static/resources/view/squid.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 getOptions = 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, getOptions()]); | ||
}, | ||
|
||
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(); | ||
}, | ||
|
||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.