7 var isReadonlyView = !L.hasViewPermission() || null;
10 callInitList: rpc.declare({
12 method: 'getInitList',
16 callInitAction: rpc.declare({
18 method: 'setInitAction',
19 params: [ 'name', 'action' ],
20 expect: { result: false }
25 L.resolveDefault(fs.read('/etc/rc.local'), ''),
30 handleAction: function(name, action, ev) {
31 return this.callInitAction(name, action).then(function(success) {
33 throw _('Command failed');
36 }).catch(function(e) {
37 ui.addNotification(null, E('p', _('Failed to execute "/etc/init.d/%s %s" action: %s').format(name, action, e)));
41 handleEnableDisable: function(name, isEnabled, ev) {
42 return this.handleAction(name, isEnabled ? 'disable' : 'enable', ev).then(L.bind(function(name, isEnabled, btn) {
43 btn.parentNode.replaceChild(this.renderEnableDisable({
47 }, this, name, !isEnabled, ev.currentTarget));
50 handleRcLocalSave: function(ev) {
51 var value = (document.querySelector('textarea').value || '').trim().replace(/\r\n/g, '\n') + '\n';
53 return fs.write('/etc/rc.local', value).then(function() {
54 document.querySelector('textarea').value = value;
55 ui.addNotification(null, E('p', _('Contents have been saved.')), 'info');
56 }).catch(function(e) {
57 ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e.message)));
61 renderEnableDisable: function(init) {
63 class: 'btn cbi-button-%s'.format(init.enabled ? 'positive' : 'negative'),
64 click: ui.createHandlerFn(this, 'handleEnableDisable', init.name, init.enabled),
65 disabled: isReadonlyView
66 }, init.enabled ? _('Enabled') : _('Disabled'));
69 render: function(data) {
70 var rcLocal = data[0],
74 var table = E('div', { 'class': 'table' }, [
75 E('div', { 'class': 'tr table-titles' }, [
76 E('div', { 'class': 'th' }, _('Start priority')),
77 E('div', { 'class': 'th' }, _('Initscript')),
78 E('div', { 'class': 'th nowrap cbi-section-actions' })
82 for (var init in initList)
83 if (initList[init].index < 100)
84 list.push(Object.assign({ name: init }, initList[init]));
86 list.sort(function(a, b) {
87 if (a.index != b.index)
88 return a.index - b.index
90 return a.name > b.name;
93 for (var i = 0; i < list.length; i++) {
95 '%02d'.format(list[i].index),
98 this.renderEnableDisable(list[i]),
99 E('button', { 'class': 'btn cbi-button-action', 'click': ui.createHandlerFn(this, 'handleAction', list[i].name, 'start'), 'disabled': isReadonlyView }, _('Start')),
100 E('button', { 'class': 'btn cbi-button-action', 'click': ui.createHandlerFn(this, 'handleAction', list[i].name, 'restart'), 'disabled': isReadonlyView }, _('Restart')),
101 E('button', { 'class': 'btn cbi-button-action', 'click': ui.createHandlerFn(this, 'handleAction', list[i].name, 'stop'), 'disabled': isReadonlyView }, _('Stop'))
106 cbi_update_table(table, rows);
108 var view = E('div', {}, [
109 E('h2', _('Startup')),
111 E('div', { 'data-tab': 'init', 'data-tab-title': _('Initscripts') }, [
112 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>')),
115 E('div', { 'data-tab': 'rc', 'data-tab-title': _('Local Startup') }, [
116 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.')),
117 E('p', {}, E('textarea', { 'style': 'width:100%', 'rows': 20, 'disabled': isReadonlyView }, [ (rcLocal != null ? rcLocal : '') ])),
118 E('div', { 'class': 'cbi-page-actions' }, [
120 'class': 'btn cbi-button-save',
121 'click': ui.createHandlerFn(this, 'handleRcLocalSave'),
122 'disabled': isReadonlyView
129 ui.tabs.initTabGroup(view.lastElementChild.childNodes);
134 handleSaveApply: null,