-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathRun_FinTSServer.js
134 lines (125 loc) · 3.86 KB
/
Run_FinTSServer.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
/*
* Copyright 2015-2016 Jens Schyma [email protected]
*
* This File is a Part of the source of Open-Fin-TS-JS-Client.
*
*
*
* This file is licensed to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* or in the LICENSE File contained in this project.
*
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*
*
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership.
*
*
*/
var express = require('express')
var cors = require('cors')
var http = require('http')
var textBody = require('body')
var FinTSServer = require('./FinTSServer.js')
var https = require('https')
var url = require('url')
var fs = require('fs')
var ipaddr = process.env.IP || '127.0.0.1' // process.env.IP;
var port = process.env.PORT || 3000 // process.env.PORT;
var app = express()
var myFINTSServer = new FinTSServer()
var myFINTSServer22 = new FinTSServer()
myFINTSServer22.proto_version = 220
app.use(
cors({
origin: true,
credentials: true
})
)
app.get('/', function (req, res) {
res.setHeader('Content-Type', 'text/html')
res.send('Test FinTS Server - at /cgi-bin/hbciservlet und BLZ = 12345678')
})
app.post('/cgi-bin/hbciservlet', function (req, res) {
textBody(req, res, function (err, body) {
// err probably means invalid HTTP protocol or some shiz.
if (err) {
res.statusCode = 500
return res.end('NO U')
}
res.setHeader('Content-Type', 'text/plain')
res.send(myFINTSServer.handleIncomeMessage(body))
})
})
app.post('/cgi-bin/hbciservlet22', function (req, res) {
textBody(req, res, function (err, body) {
// err probably means invalid HTTP protocol or some shiz.
if (err) {
res.statusCode = 500
return res.end('NO U')
}
res.setHeader('Content-Type', 'text/plain')
res.send(myFINTSServer.handleIncomeMessage(body))
})
})
app.post('/cgi-bin/hbciservlet_proxy', function (req2, res2) {
textBody(req2, res2, function (err, body) {
// err probably means invalid HTTP protocol or some shiz.
if (err) {
res2.statusCode = 500
return res2.end('NO U')
}
// create a connection
var post_data = body
var clear_txt_2 = new Buffer(body, 'base64').toString('utf8')
console.log('Send: ' + clear_txt_2)
fs.appendFileSync('log_proxy_msg.txt', 'Send: ' + clear_txt_2 + '\n\r')
var u = url.parse('TODO')
var options = {
hostname: u.hostname,
port: u.port,
path: u.path,
method: 'POST',
headers: {
'Content-Type': 'text/plain',
'Content-Length': post_data.length
}
}
var data = ''
var req = https.request(options, function (res) {
res.on('data', function (chunk) {
data += chunk
})
res.on('end', function () {
var clear_txt = new Buffer(data, 'base64').toString('utf8')
console.log('Recv: ' + clear_txt)
fs.appendFileSync('log_proxy_msg.txt', 'Recv: ' + clear_txt + '\n\r')
res2.setHeader('Content-Type', 'text/plain')
res2.send(data)
})
})
req.on('error', function () {
// Hier wird dann weiter gemacht :)
res2.end()
})
req.write(post_data)
req.end()
})
})
var server = http.createServer(app)
console.log('Listening at IP ' + ipaddr + ' on port ' + port)
server.listen(port, ipaddr, function () {
var addr = server.address()
console.log('FinTS server running at:', addr.address + ':' + addr.port + '/cgi-bin/hbciservlet')
})