2
0

squid.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. 'use strict';
  2. 'require form';
  3. 'require fs';
  4. 'require rpc';
  5. 'require uci';
  6. 'require view';
  7. var getCompileTimeOptions = rpc.declare({
  8. object: 'luci.squid',
  9. method: 'getCompileTimeOptions',
  10. expect: { options: [] }
  11. });
  12. function validateFile(path) {
  13. if (!path.startsWith('/etc/squid/')) {
  14. return _('File must be located in directory /etc/squid');
  15. }
  16. return true;
  17. }
  18. function writeFile(path, content) {
  19. if (content) {
  20. var normalized = content.replaceAll('\r\n', '\n');
  21. fs.write(path, normalized);
  22. }
  23. }
  24. return view.extend({
  25. load: function() {
  26. var load_squid = uci.load('squid')
  27. .then(() => uci.get('squid', 'squid'));
  28. return Promise.all([load_squid, getCompileTimeOptions()]);
  29. },
  30. render: function(data) {
  31. var { config_file, mime_table } = data[0];
  32. var options = data[1];
  33. var m, s, o;
  34. m = new form.Map('squid', _('Squid'));
  35. s = m.section(form.TypedSection, 'squid');
  36. s.anonymous = true;
  37. s.addremove = false;
  38. s.tab('general', _('General Settings'));
  39. s.tab('advanced', _('Advanced Settings'));
  40. var o = s.taboption('general', form.Value, 'config_file', _('Config file'));
  41. o.datatype = 'string';
  42. o.default = '/etc/squid/squid.conf';
  43. o.validate = function(section_id, value) {
  44. return validateFile(value);
  45. };
  46. o = s.taboption('general', form.Value, 'mime_table', _('Mime table'));
  47. o.datatype = 'string';
  48. o.default = '/etc/squid/mime.conf';
  49. o.validate = function(section_id, value) {
  50. return validateFile(value);
  51. };
  52. o = s.taboption('general', form.Value, 'http_port', _('Port'));
  53. o.datatype = 'portrange';
  54. o.placeholder = '0-65535';
  55. o = s.taboption('general', form.Value, 'http_port_options', _('HTTP port options'));
  56. o.datatype = 'string';
  57. o.optional = true;
  58. o = s.taboption('general', form.Value, 'ssl_db', _('SSL DB'));
  59. o.datatype = 'string';
  60. o.optional = true;
  61. o = s.taboption('general', form.Value, 'ssldb_options', _('SSL DB options'));
  62. o.datatype = 'string';
  63. o.optional = true;
  64. o = s.taboption('general', form.Value, 'visible_hostname', _('Visible Hostname'));
  65. o.datatype = 'string';
  66. o.placeholder = 'OpenWrt';
  67. o = s.taboption('general', form.Value, 'coredump_dir', _('Coredump files directory'));
  68. o.datatype = 'string';
  69. o.placeholder = '/tmp/squid';
  70. var enable_icmp_option = '--enable-icmp';
  71. var is_enable_icmp_defined = options.includes(enable_icmp_option);
  72. o = s.taboption('general', form.Flag, 'pinger_enable', _('Enable ICMP pinger'),
  73. !is_enable_icmp_defined ? _('Can only be set if Squid is compiled with the %s option').format(`<code>${enable_icmp_option}</code>`) : null);
  74. o.datatype = 'string';
  75. o.enabled = 'on';
  76. o.disabled = 'off';
  77. o.readonly = !is_enable_icmp_defined;
  78. o = s.taboption('advanced', form.SectionValue, '_advanced', form.TypedSection, '_advanced', null,
  79. _('Advanced settings grants you direct access to the configuration files.'));
  80. var advanced = o.subsection;
  81. advanced.anonymous = true;
  82. advanced.cfgsections = function() { return [ '_advanced' ] };
  83. advanced.tab('_config_file', _('Config file'));
  84. advanced.tab('_mime_table', _('Mime table'));
  85. o = advanced.taboption('_config_file', form.TextValue, '_config_file_data');
  86. o.wrap = false;
  87. o.rows = 25;
  88. o.rmempty = false;
  89. o.cfgvalue = function(section_id) {
  90. return fs.read(config_file);
  91. };
  92. o.write = function(section_id, value) {
  93. writeFile(config_file, value);
  94. };
  95. o = advanced.taboption('_mime_table', form.TextValue, '_mime_table_data');
  96. o.wrap = false;
  97. o.rows = 25;
  98. o.rmempty = false;
  99. o.cfgvalue = function(section_id) {
  100. return fs.read(mime_table);
  101. };
  102. o.write = function(section_id, value) {
  103. writeFile(mime_table, value);
  104. };
  105. return m.render();
  106. },
  107. });