protocols: add client side protocol handler implementations
[oweals/luci.git] / modules / luci-base / htdocs / luci-static / resources / protocol / dhcp.js
1 'use strict';
2 'require rpc';
3 'require form';
4 'require network';
5
6 var callHostname = rpc.declare({
7         object: 'luci',
8         method: 'getHostname',
9         expect: { result: '' }
10 });
11
12 return network.registerProtocol('dhcp', {
13         getI18n: function() {
14                 return _('DHCP client');
15         },
16
17         renderFormOptions: function(s) {
18                 var dev = this.getL2Device() || this.getDevice(), o;
19
20                 o = s.taboption('general', form.Value, 'hostname', _('Hostname to send when requesting DHCP'));
21                 o.datatype    = 'hostname';
22                 o.load = function(section_id) {
23                         return callHostname().then(L.bind(function(hostname) {
24                                 this.placeholder = hostname;
25                                 return form.Value.prototype.load.apply(this, [section_id]);
26                         }, this));
27                 };
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
32                 o = s.taboption('advanced', form.Flag, 'defaultroute', _('Use default gateway'), _('If unchecked, no default route is configured'));
33                 o.default = o.enabled;
34
35                 o = s.taboption('advanced', form.Flag, 'peerdns', _('Use DNS servers advertised by peer'), _('If unchecked, the advertised DNS server addresses are ignored'));
36                 o.default = o.enabled;
37
38                 o = s.taboption('advanced', form.DynamicList, 'dns', _('Use custom DNS servers'));
39                 o.depends('peerdns', '0');
40                 o.datatype = 'ipaddr';
41                 o.cast     = 'string';
42
43                 o = s.taboption('advanced', form.Value, 'metric', _('Use gateway metric'));
44                 o.placeholder = '0';
45                 o.datatype    = 'uinteger';
46
47                 o = s.taboption('advanced', form.Value, 'clientid', _('Client ID to send when requesting DHCP'));
48                 o.datatype  = 'hexstring';
49
50                 s.taboption('advanced', form.Value, 'vendorid', _('Vendor Class to send when requesting DHCP'));
51
52                 o = s.taboption('advanced', form.Value, 'macaddr', _('Override MAC address'));
53                 o.datatype = 'macaddr';
54                 o.placeholder = dev ? (dev.getMAC() || '') : '';
55
56                 o = s.taboption('advanced', form.Value, 'mtu', _('Override MTU'));
57                 o.placeholder = dev ? (dev.getMTU() || '1500') : '1500';
58                 o.datatype    = 'max(9200)';
59         }
60 });