587f867aa6feba078e9bb98b785cd1953c85acd7
7 callInitList
: rpc
.declare({
13 callInitAction
: rpc
.declare({
15 method
: 'setInitAction',
16 params
: [ 'name', 'action' ],
17 expect
: { result
: false }
22 L
.resolveDefault(fs
.read('/etc/rc.local'), ''),
27 handleAction: function(name
, action
, ev
) {
28 return this.callInitAction(name
, action
).then(function(success
) {
30 throw _('Command failed');
33 }).catch(function(e
) {
34 ui
.addNotification(null, E('p', _('Failed to execute "/etc/init.d/%s %s" action: %s').format(name
, action
, e
)));
38 handleEnableDisable: function(name
, isEnabled
, ev
) {
39 return this.handleAction(name
, isEnabled
? 'disable' : 'enable', ev
).then(L
.bind(function(name
, isEnabled
, btn
) {
40 btn
.parentNode
.replaceChild(this.renderEnableDisable({
44 }, this, name
, !isEnabled
, ev
.currentTarget
));
47 handleRcLocalSave: function(ev
) {
48 var value
= (document
.querySelector('textarea').value
|| '').trim().replace(/\r\n/g, '\n') + '\n';
50 return fs
.write('/etc/rc.local', value
).then(function() {
51 document
.querySelector('textarea').value
= value
;
52 ui
.addNotification(null, E('p', _('Contents have been saved.')), 'info');
53 }).catch(function(e
) {
54 ui
.addNotification(null, E('p', _('Unable to save contents: %s').format(e
.message
)));
58 renderEnableDisable: function(init
) {
60 class: 'btn cbi-button-%s'.format(init
.enabled
? 'positive' : 'negative'),
61 click
: ui
.createHandlerFn(this, 'handleEnableDisable', init
.name
, init
.enabled
)
62 }, init
.enabled
? _('Enabled') : _('Disabled'));
65 render: function(data
) {
66 var rcLocal
= data
[0],
70 var table
= E('div', { 'class': 'table' }, [
71 E('div', { 'class': 'tr table-titles' }, [
72 E('div', { 'class': 'th' }, _('Start priority')),
73 E('div', { 'class': 'th' }, _('Initscript')),
74 E('div', { 'class': 'th nowrap cbi-section-actions' })
78 for (var init
in initList
)
79 if (initList
[init
].index
< 100)
80 list
.push(Object
.assign({ name
: init
}, initList
[init
]));
82 list
.sort(function(a
, b
) {
83 if (a
.index
!= b
.index
)
84 return a
.index
- b
.index
86 return a
.name
> b
.name
;
89 for (var i
= 0; i
< list
.length
; i
++) {
91 '%02d'.format(list
[i
].index
),
94 this.renderEnableDisable(list
[i
]),
95 E('button', { 'class': 'btn cbi-button-action', 'click': ui
.createHandlerFn(this, 'handleAction', list
[i
].name
, 'start') }, _('Start')),
96 E('button', { 'class': 'btn cbi-button-action', 'click': ui
.createHandlerFn(this, 'handleAction', list
[i
].name
, 'restart') }, _('Restart')),
97 E('button', { 'class': 'btn cbi-button-action', 'click': ui
.createHandlerFn(this, 'handleAction', list
[i
].name
, 'stop') }, _('Stop'))
102 cbi_update_table(table
, rows
);
104 var view
= E('div', {}, [
105 E('h2', _('Startup')),
107 E('div', { 'data-tab': 'init', 'data-tab-title': _('Initscripts') }, [
108 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>')),
111 E('div', { 'data-tab': 'rc', 'data-tab-title': _('Local Startup') }, [
112 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.')),
113 E('p', {}, E('textarea', { 'style': 'width:100%', 'rows': 20 }, [ (rcLocal
!= null ? rcLocal
: '') ])),
114 E('div', { 'class': 'cbi-page-actions' }, [
116 'class': 'btn cbi-button-save',
117 'click': ui
.createHandlerFn(this, 'handleRcLocalSave')
124 ui
.tabs
.initTabGroup(view
.lastElementChild
.childNodes
);
129 handleSaveApply
: null,