Commit a88fa9fb74274b2eb7907adf0fdad81b2fb4ece2

Authored by Adhidarma Hadiwinoto
1 parent 89c79031c9
Exists in master

hapus aaa dan httpserver

Showing 2 changed files with 0 additions and 249 deletions Side-by-side Diff

... ... @@ -1,159 +0,0 @@
1   -var request = require('request');
2   -var strftime = require('strftime');
3   -
4   -var max_retry = 10;
5   -var sleep_before_retry = 3000;
6   -
7   -var config;
8   -var partner;
9   -
10   -var available_products = [];
11   -
12   -function unaliasResponseCode(response_code, config_responsecode_alias) {
13   - if (config_responsecode_alias == undefined && config && config.h2h_out && config.h2h_out.responsecode_alias) {
14   - config_responsecode_alias = config.h2h_out.responsecode_alias;
15   - }
16   -
17   - if (!config_responsecode_alias) {
18   - return response_code;
19   - }
20   -
21   - items = config_responsecode_alias.split(',');
22   - items_count = items.length;
23   -
24   - for (var i=0; i < items_count; i++) {
25   - codes = items[i].split(':');
26   -
27   - if (codes.length <= 0) { continue; }
28   -
29   - if (response_code == codes[0]) {
30   - console.log('Change response code from ' + codes[0] + ' to ' + codes[1]);
31   - return codes[1];
32   - }
33   - }
34   -
35   - return response_code;
36   -}
37   -
38   -function pullCity() {
39   - var url = config.globals.aaa_host + '/pull_city';
40   - console.log('Pull cities from AAA - ' + url);
41   - request(url, function (error, response, body) {
42   - if (!error && response.statusCode == 200) {
43   - //console.log('city=' + body);
44   - } else {
45   - console.log('Error in pull city');
46   - }
47   - });
48   -}
49   -
50   -function pullProduct() {
51   - var url = config.globals.aaa_host + '/pull_product?opr_name=' + config.globals.operators;
52   - console.log('Pull products from AAA - ' + url);
53   -
54   - request(url, function (error, response, body) {
55   - if (error || response.statusCode != 200) {
56   - console.log('Error in pull products');
57   - return;
58   - }
59   -
60   - var productsAndOperators = body.split(';');
61   - var productsCount = productsAndOperators.length;
62   -
63   - for (var i=0; i < productsCount; i++) {
64   - var product = productsAndOperators[i].split(',', 1)[0];
65   - available_products.push(product);
66   - }
67   - //console.log(available_products);
68   - });
69   -}
70   -
71   -function pull() {
72   - var url = config.globals.aaa_host
73   - + '/pull?city=ALL&nom=' + config.globals.products
74   - + '&chip_info=' + config.globals.gateway_name;
75   -
76   - //console.log('AAA PULL - ' + url);
77   - request(url, function (error, response, body) {
78   - if (!error && response.statusCode == 200) {
79   - if (body == 'NONE') {
80   - return;
81   - }
82   - console.log(body);
83   -
84   - var result = body.split(';');
85   - if (result[0] != 'OK') {
86   - return;
87   - }
88   -
89   - var task = [];
90   - task['requestId'] = result[1];
91   - task['timestamp'] = result[3];
92   - task['destination'] = result[4];
93   - task['product'] = result[7];
94   -
95   - if (config.products[task['product']] !== undefined) {
96   - task['remoteProduct'] = config.products[task['product']];
97   - } else {
98   - task['remoteProduct'] = task['product'];
99   - }
100   -
101   - partner.topupRequest(task);
102   -
103   - } else {
104   - console.log('Error in pull task');
105   - return;
106   - }
107   - });
108   -}
109   -
110   -function pullLoop() {
111   - if (!config.globals.pause) {
112   - pull();
113   - }
114   -
115   - setTimeout(pullLoop, config.globals.interval);
116   -}
117   -
118   -function callbackReport(requestId, responseCode, message, retry) {
119   - if (retry === undefined) {
120   - retry = max_retry;
121   - }
122   -
123   - responseCode = unaliasResponseCode(responseCode);
124   -
125   - timestamp = strftime('%Y%m%d%H%M%S');
126   - var url = config.globals.aaa_host
127   - + '/topup?trans_id=' + requestId
128   - + '&trans_date' + timestamp
129   - + '&trans_date=' + timestamp
130   - + '&resp_code=' + responseCode
131   - + '&ussd_msg=' + config.globals.gateway_name
132   - + '$' + encodeURIComponent(message);
133   -
134   - console.log('Report to AAA - ' + url);
135   - request(url, function (error, response, body) {
136   - if (error || response.statusCode != 200) {
137   - console.log('Error report to AAA');
138   -
139   - if (retry) {
140   - console.log('Retrying to report to AAA (' + retry + ')');
141   - callbackReport(requestId, responseCode, message, retry - 1);
142   - }
143   - }
144   - });
145   -}
146   -
147   -function start(_config, _partner) {
148   - config = _config;
149   - partner = _partner;
150   -
151   - pullCity();
152   - pullProduct();
153   -
154   - setTimeout(pullLoop, 10 * 1000);
155   -}
156   -
157   -exports.start = start;
158   -exports.callbackReport = callbackReport;
159   -exports.unaliasResponseCode = unaliasResponseCode;
httpserver.js
... ... @@ -1,90 +0,0 @@
1   -var http = require('http');
2   -var nsr = require('node-simple-router');
3   -var router = nsr();
4   -
5   -var config;
6   -var httpServer;
7   -
8   -function start(_config) {
9   - if (_config != undefined) {
10   - config = _config;
11   - }
12   - listenPort = config.globals.admin_port;
13   -
14   - router.get("/info", function(request, response) {
15   - response.setHeader("Content-Type", "text/plain");
16   - response.write('CHIPINFO / GATEWAY NAME: ' + config.globals.gateway_name + "\n");
17   - response.write('PRODUCTS: ' + config.globals.products + "\n");
18   - response.write('AAA HOST: ' + config.globals.aaa_host + "\n");
19   - response.write('PARTNER: ' + config.h2h_out.partner + "\n");
20   - response.write('PAUSED: ' + config.globals.pause + "\n");
21   - response.write('UPTIME: ' + process.uptime() + "\n");
22   - response.write('REQUESTS COUNT: ' + config.globals.requests_count + "\n");
23   - response.write('ACTIVE REQUESTS COUNT: ' + config.globals.active_requests_count + "\n");
24   - response.write('MAX ACTIVE REQUESTS COUNT: ' + config.globals.max_active_requests_count + "\n");
25   -
26   - response.end();
27   - });
28   -
29   - router.get("/pause/:apikey", function(request, response) {
30   - if (!config.globals.apikey) {
31   - response.end('Undefined APIKEY on config');
32   - return;
33   - }
34   -
35   - if (request.params.apikey != config.globals.apikey) {
36   - response.end('Invalid APIKEY');
37   - return;
38   - }
39   -
40   - config.globals.pause = 1;
41   - response.end('Paused');
42   - });
43   -
44   - router.get("/resume/:apikey", function(request, response) {
45   - if (!config.globals.apikey) {
46   - response.end('Undefined APIKEY on config');
47   - return;
48   - }
49   -
50   - if (request.params.apikey != config.globals.apikey) {
51   - response.end('Invalid APIKEY');
52   - return;
53   - }
54   -
55   - delete config.globals.pause;
56   - response.end('Resume');
57   - });
58   -
59   - router.get("/reset-stats/:apikey", function(request, response) {
60   - if (!config.globals.apikey) {
61   - response.end('Undefined APIKEY on config');
62   - return;
63   - }
64   -
65   - if (request.params.apikey != config.globals.apikey) {
66   - response.end('Invalid APIKEY');
67   - return;
68   - }
69   -
70   - config.globals.max_active_requests_count = 0;
71   -
72   - response.writeHead(307, {
73   - 'Location': '/info'
74   - });
75   -
76   - response.end();
77   - });
78   -
79   - httpServer = http.createServer(router).listen(listenPort);
80   - console.log('HTTP server listens on port ' + listenPort);
81   -
82   - return httpServer;
83   -}
84   -
85   -function setConfig(_config) {
86   - config = _config;
87   -}
88   -
89   -exports.start = start;
90   -exports.setConfig = setConfig;