forked from gchq/CyberChef
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGenerateSystemdUnit.mjs
More file actions
126 lines (114 loc) · 3.46 KB
/
GenerateSystemdUnit.mjs
File metadata and controls
126 lines (114 loc) · 3.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/**
* @author 0xff1ce [github.com/0xff1ce]
* @copyright Crown Copyright 2026
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
const RESTART_OPTIONS = ["no", "on-sucess", "on-failure", "on-abnormal", "on-watchdog", "on-abort", "always"];
const TYPE_OPTIONS = ["simple", "exec", "forking", "oneshot", "dbus", "notify", "idle"];
/**
* GenerateSystemdUnit operation
*/
class GenerateSystemdUnit extends Operation {
/**
* GenerateSystemdUnit constructor
*/
constructor() {
super();
this.name = "Generate Systemd Unit";
this.module = "Default";
this.description = "Generates a systemd unit file based on provided inputs";
this.inputType = "string";
this.outputType = "string";
this.args = [
{
"name": "Description",
"type": "string",
"value": "",
},
{
"name": "After",
"type": "string",
"value": "network.target",
},
{
"name": "Wants",
"type": "string",
"value": "network-online.target",
},
{
"name": "Restart",
"type": "option",
"value": RESTART_OPTIONS,
},
{
"name": "Type",
"type": "option",
"value": TYPE_OPTIONS,
},
{
"name": "ExecStart",
"type": "string",
"value": "",
},
{
"name": "Environment",
"type": "string",
"value": "KEY=VALUE",
},
{
"name": "User",
"type": "string",
"value": "",
},
{
"name": "WorkingDirectory",
"type": "string",
"value": "",
},
{
"name": "WantedBy",
"type": "string",
"value": "multi-user.target",
},
];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
run(_, args) {
const description = args[0];
const after = args[1];
const wants = args[2];
const restart = args[3];
const type = args[4];
const execStart = args[5];
const environment = args[6];
const user = args[7];
const workingDirectory = args[8];
const wantedBy = args[9];
const lines = [];
// [Unit] section
lines.push("[Unit]");
if (description) lines.push(`Description=${description}`);
if (after) lines.push(`After=${after}`);
if (wants) lines.push(`Wants=${wants}`);
// [Service] section
lines.push("");
lines.push("[Service]");
if (restart) lines.push(`Restart=${restart}`);
if (type) lines.push(`Type=${type}`);
if (execStart) lines.push(`ExecStart=${execStart}`);
if (environment) lines.push(`Environment=${environment}`);
if (user) lines.push(`User=${user}`);
if (workingDirectory) lines.push(`WorkingDirectory=${workingDirectory}`);
// [Install] section
lines.push("");
lines.push("[Install]");
if (wantedBy) lines.push(`WantedBy=${wantedBy}`);
return lines.join("\n");
}
}
export default GenerateSystemdUnit;