dhcp.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. 'use strict';
  2. 'require rpc';
  3. 'require form';
  4. 'require network';
  5. var callFileRead = rpc.declare({
  6. object: 'file',
  7. method: 'read',
  8. params: [ 'path' ],
  9. expect: { data: '' },
  10. filter: function(value) { return value.trim() }
  11. });
  12. return network.registerProtocol('dhcp', {
  13. getI18n: function() {
  14. return _('DHCP client');
  15. },
  16. renderFormOptions: function(s) {
  17. var dev = this.getL2Device() || this.getDevice(), o;
  18. o = s.taboption('general', form.Value, 'hostname', _('Hostname to send when requesting DHCP'));
  19. o.default = '';
  20. o.value('', _('Send the hostname of this device'));
  21. o.value('*', _('Do not send a hostname'));
  22. o.datatype = 'or(hostname, "*")';
  23. o.load = function(section_id) {
  24. return callFileRead('/proc/sys/kernel/hostname').then(L.bind(function(hostname) {
  25. this.placeholder = hostname;
  26. return form.Value.prototype.load.apply(this, [section_id]);
  27. }, this));
  28. };
  29. o = s.taboption('advanced', form.Flag, 'broadcast', _('Use broadcast flag'), _('Required for certain ISPs, e.g. Charter with DOCSIS 3'));
  30. o.default = o.disabled;
  31. o = s.taboption('advanced', form.Value, 'clientid', _('Client ID to send when requesting DHCP'));
  32. o.datatype = 'hexstring';
  33. s.taboption('advanced', form.Value, 'vendorid', _('Vendor Class to send when requesting DHCP'));
  34. o = s.taboption('advanced', form.Value, 'macaddr', _('Override MAC address'));
  35. o.datatype = 'macaddr';
  36. o.placeholder = dev ? (dev.getMAC() || '') : '';
  37. o = s.taboption('advanced', form.Value, 'mtu', _('Override MTU'));
  38. o.placeholder = dev ? (dev.getMTU() || '1500') : '1500';
  39. o.datatype = 'max(9200)';
  40. }
  41. });