5 callInitList: rpc.declare({
11 callInitAction: rpc.declare({
13 method: 'setInitAction',
14 params: [ 'name', 'action' ],
15 expect: { result: false }
18 callFileRead: rpc.declare({
25 callFileWrite: rpc.declare({
28 params: [ 'path', 'data' ]
33 this.callFileRead('/etc/rc.local'),
38 handleAction: function(name, action, ev) {
39 return this.callInitAction(name, action).then(function(success) {
41 throw _('Command failed');
44 }).catch(function(e) {
45 L.ui.addNotification(null, E('p', _('Failed to execute "/etc/init.d/%s %s" action: %s').format(name, action, e)));
49 handleEnableDisable: function(name, isEnabled, ev) {
50 return this.handleAction(name, isEnabled ? 'disable' : 'enable', ev).then(L.bind(function(name, isEnabled, cell) {
51 L.dom.content(cell, this.renderEnableDisable({
55 }, this, name, !isEnabled, ev.currentTarget.parentNode));
58 handleRcLocalSave: function(ev) {
59 var value = (document.querySelector('textarea').value || '').trim().replace(/\r\n/g, '\n') + '\n';
61 return this.callFileWrite('/etc/rc.local', value).then(function(rc) {
63 throw rpc.getStatusText(rc);
65 document.querySelector('textarea').value = value;
66 L.ui.addNotification(null, E('p', _('Contents have been saved.')), 'info');
67 }).catch(function(e) {
68 L.ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e)));
72 renderEnableDisable: function(init) {
74 class: 'btn cbi-button-%s'.format(init.enabled ? 'positive' : 'negative'),
75 click: L.ui.createHandlerFn(this, 'handleEnableDisable', init.name, init.enabled)
76 }, init.enabled ? _('Enabled') : _('Disabled'));
79 render: function(data) {
80 var rcLocal = data[0],
84 var table = E('div', { 'class': 'table' }, [
85 E('div', { 'class': 'tr table-titles' }, [
86 E('div', { 'class': 'th' }, _('Start priority')),
87 E('div', { 'class': 'th' }, _('Initscript')),
88 E('div', { 'class': 'th' }, _('Enable/Disable')),
89 E('div', { 'class': 'th' }, _('Start')),
90 E('div', { 'class': 'th' }, _('Restart')),
91 E('div', { 'class': 'th' }, _('Stop'))
95 for (var init in initList)
96 if (initList[init].index < 100)
97 list.push(Object.assign({ name: init }, initList[init]));
99 list.sort(function(a, b) {
100 if (a.index != b.index)
101 return a.index - b.index
103 return a.name > b.name;
106 for (var i = 0; i < list.length; i++) {
108 '%02d'.format(list[i].index),
110 this.renderEnableDisable(list[i]),
111 E('button', { 'class': 'btn cbi-button-action', 'click': L.ui.createHandlerFn(this, 'handleAction', list[i].name, 'start') }, _('Start')),
112 E('button', { 'class': 'btn cbi-button-action', 'click': L.ui.createHandlerFn(this, 'handleAction', list[i].name, 'restart') }, _('Restart')),
113 E('button', { 'class': 'btn cbi-button-action', 'click': L.ui.createHandlerFn(this, 'handleAction', list[i].name, 'stop') }, _('Stop'))
117 cbi_update_table(table, rows);
119 var view = E('div', {}, [
120 E('h2', _('Startup')),
122 E('div', { 'data-tab': 'init', 'data-tab-title': _('Initscripts') }, [
123 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>')),
126 E('div', { 'data-tab': 'rc', 'data-tab-title': _('Local Startup') }, [
127 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.')),
128 E('p', {}, E('textarea', { 'style': 'width:100%', 'rows': 20 }, rcLocal != null ? rcLocal : '')),
129 E('div', { 'class': 'cbi-page-actions' }, [
131 'class': 'btn cbi-button-save',
132 'click': L.ui.createHandlerFn(this, 'handleRcLocalSave')
139 L.ui.tabs.initTabGroup(view.lastElementChild.childNodes);
144 handleSaveApply: null,