-
Notifications
You must be signed in to change notification settings - Fork 0
/
sdsfTutosysserver.js
executable file
·146 lines (140 loc) · 4.71 KB
/
sdsfTutosysserver.js
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
const http = require('http');
const url = require('url');
const fs = require('fs');
const { exec } = require('child_process');
const acceptedPanels = [
'VMAP', 'AS', 'ST',
'RM', 'PROC', 'PARM', 'LNK', 'SYM',
'LPA', 'FS', 'ENQ', 'SYS', 'ENC'
];
const interval = 180000;
//const interval = 10000;
var tsosessionid = '';
var tsopinginterval = null;
http.createServer(function (req, res) {
handleRequest (req, res)
}).listen(8080);
// if (tsosessionid == '') {
createTsosession();
// };
console.log('Listening on port 8080');
function createTsosession () {
exec('zowex zos-tso start address-space --zosmf-profile "tutosys" --sko', (err, stdout, stderr) => {
if (err) {
console.log('Error start Tso session');
};
if (stdout) {
tsosessionid = stdout.substr(0,stdout.length-1);
console.log('Tso sessionid : ' + tsosessionid);
var secondfunc = 'zowex zos-tso send address-space "';
secondfunc = secondfunc + tsosessionid+'"';
secondfunc = secondfunc + ' --data "\\"ex (PANELSRV)\\""';
console.log (`zowecmd: ${secondfunc}`);
exec(secondfunc, {maxBuffer : 1024 * 1024} , (seconderr, secondstdout, secondstderr) => {
if (seconderr) {
console.log('zowex error func 2'+secondstderr);
};
if (secondstdout) {
if (secondstdout.indexOf("PANELSRV started")>-1) {
console.log('PANELSRV started');
tsopinginterval = setInterval(function(){
pingTsosession ();
}, interval);
};
};
});
};
if (stderr) {
console.log(stderr);
}
});
};
function pingTsosession () {
zowecmd = 'zowex zos-tso ping address-space "';
zowecmd = zowecmd + tsosessionid;
zowecmd = zowecmd + '"';
exec(zowecmd, (err, stdout, stderr) => {
if (err) {
console.log('Error pinging ' + tsosessionid);
};
if (stdout) {
console.log(stdout.substr(0,stdout.length-1));
};
if (stderr) {
console.log(stderr);
}
});
};
function processZowe (zowecmd, func, res) {
console.log (`zowecmd: ${zowecmd}`);
exec(zowecmd, {maxBuffer : 1024 * 1024} , (err, stdout, stderr) => {
if (err) {
console.log('zowex error');
};
if (stdout) {
console.log(stdout);
if (stdout.indexOf("SDSF output created!")>-1) {
var secondfunc = "zowex zos-files download data-set ";
secondfunc = secondfunc+'"Z40275.SDSFSERV.OUTPUT.PDSE('+func+')"';
console.log (`zowecmd: ${secondfunc}`);
exec(secondfunc, {maxBuffer : 1024 * 1024} , (seconderr, secondstdout, secondstderr) => {
if (seconderr) {
console.log('zowex error func 2'+secondstderr);
};
if (secondstdout) {
if (secondstdout.indexOf("Data set downloaded successfully")>-1) {
console.log('zowex download done '+func);
var filename = "z40275/sdsfserv/output/pdse/"+func.toLowerCase()+".txt"
fs.readFile('./' + filename, function(err, data) {
if (err) {
res.writeHead(404, {'Content-Type': 'text/html'});
return res.end("404 Not Found");
};
res.writeHead(200, {'Content-Type': 'text/html'});
res.write(data);
return res.end();
})
}
}
})
}
else {
console.log(stderr);
};
};
if (stderr) {
console.log(stderr);
}
});
clearInterval(tsopinginterval);
tsopinginterval = setInterval(function(){
pingTsosession ();
}, interval);
}
function handleRequest(req, res) {
var q = url.parse(req.url, true);
var filename = "." + q.pathname;
var qdata = q.query;
if (( q.search.length == 0 )
&& (q.pathname == '/sdsfTutosys.html' || q.pathname == '/favicon.ico' || q.pathname == '/sdsfTutosys.css')) {
fs.readFile('.' + q.pathname, function(err, data) {
if (err) {
res.writeHead(404, {'Content-Type': 'text/html'});
return res.end("404 Not Found");
};
res.writeHead(200, {'Content-Type': 'text/html'});
res.write(data);
return res.end();
});
} else if ((q.pathname == '/sdsfTutosys.html')
&& (q.search.length > 0 )
&& (acceptedPanels.indexOf(qdata.panel)) > -1) {
zowecmd = 'zowex zos-tso send address-space "';
zowecmd = zowecmd + tsosessionid+'"';
zowecmd = zowecmd + ' --data "' + qdata.panel + '"';
processZowe (zowecmd, qdata.panel, res);
} else {
res.writeHead(400, {'Content-Type': 'text/html'});
return res.end("400 Invalid Request");
};
}