ksmbd.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. 'use strict';
  2. 'require view';
  3. 'require fs';
  4. 'require form';
  5. 'require uci';
  6. 'require tools.widgets as widgets';
  7. return view.extend({
  8. load: function() {
  9. return Promise.all([
  10. L.resolveDefault(fs.stat('/sbin/block'), null),
  11. L.resolveDefault(fs.stat('/etc/config/fstab'), null),
  12. L.resolveDefault(fs.exec('/usr/sbin/ksmbd.mountd', ['-V']), {}).then(function(res) { return L.toArray((res.stdout || '').match(/version : (\S+)/))[1] }),
  13. L.resolveDefault(fs.exec('/sbin/modinfo', ['ksmbd']), {}).then(function(res) { return L.toArray((res.stdout || '').match(/vermagic:\t(\S+)/))[1] }),
  14. ]);
  15. },
  16. render: function(stats) {
  17. var m, s, o, v, v2;
  18. v = '?';
  19. v2 = '?';
  20. m = new form.Map('ksmbd', _('Network Shares'));
  21. if (stats[2])
  22. v = stats[2].trim();
  23. if (stats[3])
  24. v2 = stats[3].trim();
  25. if (v != v2)
  26. v = v +'/'+ v2;
  27. s = m.section(form.TypedSection, 'globals', 'Ksmbd/Kmod Version ' + v);
  28. s.anonymous = true;
  29. s.tab('general', _('General Settings'));
  30. s.tab('template', _('Edit Template'), _('Edit the template that is used for generating the ksmbd configuration.'));
  31. o = s.taboption('general', widgets.NetworkSelect, 'interface', _('Interface'),
  32. _('Listen only on the given interface or, if unspecified, on lan'));
  33. o.multiple = true;
  34. o.cfgvalue = (section_id => L.toArray(uci.get('ksmbd', section_id, 'interface')));
  35. o.write = function(section_id, formvalue) {
  36. var cfgvalue = this.cfgvalue(section_id),
  37. oldNetworks = L.toArray(cfgvalue),
  38. newNetworks = L.toArray(formvalue);
  39. oldNetworks.sort();
  40. newNetworks.sort();
  41. if (oldNetworks.join(' ') == newNetworks.join(' '))
  42. return;
  43. return uci.set('ksmbd', section_id, 'interface', newNetworks.join(' '));
  44. };
  45. o = s.taboption('general', form.Value, 'workgroup', _('Workgroup'));
  46. o.placeholder = 'WORKGROUP';
  47. o = s.taboption('general', form.Value, 'description', _('Description'));
  48. o.placeholder = 'Ksmbd on OpenWrt';
  49. o = s.taboption('general', form.Flag, 'allow_legacy_protocols', _('Allow legacy (insecure) protocols/authentication.'),
  50. _('Allow legacy smb(v1)/Lanman connections, needed for older devices without smb(v2.1/3) support.'));
  51. o = s.taboption('template', form.TextValue, '_tmpl',
  52. null,
  53. _("This is the content of the file '/etc/ksmbd/ksmbd.conf.template' from which your ksmbd configuration will be generated. \
  54. Values enclosed by pipe symbols ('|') should not be changed. They get their values from the 'General Settings' tab."));
  55. o.rows = 20;
  56. o.cfgvalue = function(section_id) {
  57. return fs.trimmed('/etc/ksmbd/ksmbd.conf.template');
  58. };
  59. o.write = function(section_id, formvalue) {
  60. return fs.write('/etc/ksmbd/ksmbd.conf.template', formvalue.trim().replace(/\r\n/g, '\n') + '\n');
  61. };
  62. s = m.section(form.TableSection, 'share', _('Shared Directories'),
  63. _('Please add directories to share. Each directory refers to a folder on a mounted device.'));
  64. s.anonymous = true;
  65. s.addremove = true;
  66. s.option(form.Value, 'name', _('Name'));
  67. o = s.option(form.Value, 'path', _('Path'));
  68. if (stats[0] && stats[1]) {
  69. o.titleref = L.url('admin', 'system', 'mounts');
  70. }
  71. o = s.option(form.Flag, 'browseable', _('Browse-able'));
  72. o.enabled = 'yes';
  73. o.disabled = 'no';
  74. o.default = 'yes';
  75. o = s.option(form.Flag, 'read_only', _('Read-only'));
  76. o.enabled = 'yes';
  77. o.disabled = 'no';
  78. o.default = 'no'; // ksmbd.conf default is 'yes'
  79. o.rmempty = false;
  80. s.option(form.Flag, 'force_root', _('Force Root'));
  81. o = s.option(form.Value, 'users', _('Allowed users'));
  82. o.rmempty = true;
  83. o = s.option(form.Flag, 'guest_ok', _('Allow guests'));
  84. o.enabled = 'yes';
  85. o.disabled = 'no';
  86. o.default = 'yes'; // ksmbd.conf default is 'no'
  87. o.rmempty = false;
  88. o = s.option(form.Flag, 'inherit_owner', _('Inherit owner'));
  89. o.enabled = 'yes';
  90. o.disabled = 'no';
  91. o.default = 'no';
  92. o = s.option(form.Flag, 'hide_dot_files', _('Hide dot files'));
  93. o.enabled = 'yes';
  94. o.disabled = 'no';
  95. o.default = 'yes';
  96. o = s.option(form.Value, 'create_mask', _('Create mask'));
  97. o.maxlength = 4;
  98. o.default = '0666'; // ksmbd.conf default is '0744'
  99. o.placeholder = '0666';
  100. o.rmempty = false;
  101. o = s.option(form.Value, 'dir_mask', _('Directory mask'));
  102. o.maxlength = 4;
  103. o.default = '0777'; // ksmbd.conf default is '0755'
  104. o.placeholder = '0777';
  105. o.rmempty = false;
  106. return m.render();
  107. }
  108. });