8 callInitList
: rpc
.declare({
10 method
: 'getInitList',
14 callInitAction
: rpc
.declare({
16 method
: 'setInitAction',
17 params
: [ 'name', 'action' ],
18 expect
: { result
: false }
23 L
.resolveDefault(fs
.read('/etc/rc.local'), ''),
28 handleAction: function(name
, action
, ev
) {
29 return this.callInitAction(name
, action
).then(function(success
) {
31 throw _('Command failed');
34 }).catch(function(e
) {
35 ui
.addNotification(null, E('p', _('Failed to execute "/etc/init.d/%s %s" action: %s').format(name
, action
, e
)));
39 handleEnableDisable: function(name
, isEnabled
, ev
) {
40 return this.handleAction(name
, isEnabled
? 'disable' : 'enable', ev
).then(L
.bind(function(name
, isEnabled
, btn
) {
41 btn
.parentNode
.replaceChild(this.renderEnableDisable({
45 }, this, name
, !isEnabled
, ev
.currentTarget
));
48 handleRcLocalSave: function(ev
) {
49 var value
= (document
.querySelector('textarea').value
|| '').trim().replace(/\r\n/g, '\n') + '\n';
51 return fs
.write('/etc/rc.local', value
).then(function() {
52 document
.querySelector('textarea').value
= value
;
53 ui
.addNotification(null, E('p', _('Contents have been saved.')), 'info');
54 }).catch(function(e
) {
55 ui
.addNotification(null, E('p', _('Unable to save contents: %s').format(e
.message
)));
59 renderEnableDisable: function(init
) {
61 class: 'btn cbi-button-%s'.format(init
.enabled
? 'positive' : 'negative'),
62 click
: ui
.createHandlerFn(this, 'handleEnableDisable', init
.name
, init
.enabled
)
63 }, init
.enabled
? _('Enabled') : _('Disabled'));
66 render: function(data
) {
67 var rcLocal
= data
[0],
71 var table
= E('div', { 'class': 'table' }, [
72 E('div', { 'class': 'tr table-titles' }, [
73 E('div', { 'class': 'th' }, _('Start priority')),
74 E('div', { 'class': 'th' }, _('Initscript')),
75 E('div', { 'class': 'th nowrap cbi-section-actions' })
79 for (var init
in initList
)
80 if (initList
[init
].index
< 100)
81 list
.push(Object
.assign({ name
: init
}, initList
[init
]));
83 list
.sort(function(a
, b
) {
84 if (a
.index
!= b
.index
)
85 return a
.index
- b
.index
87 return a
.name
> b
.name
;
90 for (var i
= 0; i
< list
.length
; i
++) {
92 '%02d'.format(list
[i
].index
),
95 this.renderEnableDisable(list
[i
]),
96 E('button', { 'class': 'btn cbi-button-action', 'click': ui
.createHandlerFn(this, 'handleAction', list
[i
].name
, 'start') }, _('Start')),
97 E('button', { 'class': 'btn cbi-button-action', 'click': ui
.createHandlerFn(this, 'handleAction', list
[i
].name
, 'restart') }, _('Restart')),
98 E('button', { 'class': 'btn cbi-button-action', 'click': ui
.createHandlerFn(this, 'handleAction', list
[i
].name
, 'stop') }, _('Stop'))
103 cbi_update_table(table
, rows
);
105 var view
= E('div', {}, [
106 E('h2', _('Startup')),
108 E('div', { 'data-tab': 'init', 'data-tab-title': _('Initscripts') }, [
109 E('p', {}, _('You can enable or disable installed init scripts here. Changes will applied after a device reboot.<br /><strong>Warning: If you disable essential init scripts like "network", your device might become inaccessible!</strong>')),
112 E('div', { 'data-tab': 'rc', 'data-tab-title': _('Local Startup') }, [
113 E('p', {}, _('This is the content of /etc/rc.local. Insert your own commands here (in front of \'exit 0\') to execute them at the end of the boot process.')),
114 E('p', {}, E('textarea', { 'style': 'width:100%', 'rows': 20 }, [ (rcLocal
!= null ? rcLocal
: '') ])),
115 E('div', { 'class': 'cbi-page-actions' }, [
117 'class': 'btn cbi-button-save',
118 'click': ui
.createHandlerFn(this, 'handleRcLocalSave')
125 ui
.tabs
.initTabGroup(view
.lastElementChild
.childNodes
);
130 handleSaveApply
: null,