From a88fa9fb74274b2eb7907adf0fdad81b2fb4ece2 Mon Sep 17 00:00:00 2001
From: Adhidarma Hadiwinoto <gua@adhisimon.org>
Date: Wed, 19 Aug 2015 11:53:12 +0700
Subject: [PATCH] hapus aaa dan httpserver

---
 aaa.js        | 159 ----------------------------------------------------------
 httpserver.js |  90 ---------------------------------
 2 files changed, 249 deletions(-)
 delete mode 100644 aaa.js
 delete mode 100644 httpserver.js

diff --git a/aaa.js b/aaa.js
deleted file mode 100644
index 752bfe3..0000000
--- a/aaa.js
+++ /dev/null
@@ -1,159 +0,0 @@
-var request = require('request');
-var strftime = require('strftime');
-
-var max_retry = 10;
-var sleep_before_retry = 3000;
-
-var config;
-var partner;
-
-var available_products = [];
-
-function unaliasResponseCode(response_code, config_responsecode_alias) {
-    if (config_responsecode_alias == undefined && config && config.h2h_out && config.h2h_out.responsecode_alias) {
-        config_responsecode_alias = config.h2h_out.responsecode_alias;
-    }
-    
-    if (!config_responsecode_alias) {
-        return response_code;
-    }
-    
-    items = config_responsecode_alias.split(',');
-    items_count = items.length;
-    
-    for (var i=0; i < items_count; i++) {
-        codes = items[i].split(':');
-        
-        if (codes.length <= 0) { continue; }
-        
-        if (response_code == codes[0]) {
-            console.log('Change response code from ' + codes[0] + ' to ' + codes[1]);
-            return codes[1];
-        }
-    }
-    
-    return response_code;
-}
-
-function pullCity() {
-    var url = config.globals.aaa_host + '/pull_city';
-    console.log('Pull cities from AAA - ' + url);
-    request(url, function (error, response, body) {
-        if (!error && response.statusCode == 200) {
-            //console.log('city=' + body);
-        } else {
-            console.log('Error in pull city');
-        }
-    });
-}
-
-function pullProduct() {
-    var url = config.globals.aaa_host + '/pull_product?opr_name=' + config.globals.operators;
-    console.log('Pull products from AAA - ' + url);
-
-    request(url, function (error, response, body) {
-        if (error || response.statusCode != 200) {
-            console.log('Error in pull products');
-            return;
-        }
-
-        var productsAndOperators = body.split(';');
-        var productsCount = productsAndOperators.length;
-
-        for (var i=0; i < productsCount; i++) {
-            var product = productsAndOperators[i].split(',', 1)[0];
-            available_products.push(product);
-        }
-        //console.log(available_products);
-    });
-}
-
-function pull() {
-    var url = config.globals.aaa_host
-        + '/pull?city=ALL&nom=' + config.globals.products
-        + '&chip_info=' + config.globals.gateway_name;
-
-    //console.log('AAA PULL - ' + url);
-    request(url, function (error, response, body) {
-        if (!error && response.statusCode == 200) {
-            if (body == 'NONE') {
-                return;
-            }
-            console.log(body);
-
-            var result = body.split(';');
-            if (result[0] != 'OK') {
-                return;
-            }
-
-            var task = [];
-            task['requestId'] = result[1];
-            task['timestamp'] = result[3];
-            task['destination'] = result[4];
-            task['product'] = result[7];
-
-            if (config.products[task['product']] !== undefined) {
-                task['remoteProduct'] = config.products[task['product']];
-            } else {
-                task['remoteProduct'] = task['product'];
-            }
-
-            partner.topupRequest(task);
-
-        } else {
-            console.log('Error in pull task');
-            return;
-        }
-    });
-}
-
-function pullLoop() {
-    if (!config.globals.pause) {
-        pull();
-    }
-    
-    setTimeout(pullLoop, config.globals.interval);
-}
-
-function callbackReport(requestId, responseCode, message, retry) {
-    if (retry === undefined) {
-        retry = max_retry;
-    }
-    
-    responseCode = unaliasResponseCode(responseCode);
-    
-    timestamp = strftime('%Y%m%d%H%M%S');
-    var url = config.globals.aaa_host
-        + '/topup?trans_id=' + requestId
-        + '&trans_date' + timestamp
-        + '&trans_date=' + timestamp
-        + '&resp_code=' + responseCode
-        + '&ussd_msg=' + config.globals.gateway_name
-        + '$' + encodeURIComponent(message);
-
-    console.log('Report to AAA - ' + url);
-    request(url, function (error, response, body) {
-        if (error || response.statusCode != 200) {
-            console.log('Error report to AAA');
-            
-            if (retry) {
-                console.log('Retrying to report to AAA (' + retry + ')');
-                callbackReport(requestId, responseCode, message, retry - 1);
-            }
-        }
-    });
-}
-
-function start(_config, _partner) {
-    config = _config;
-    partner = _partner;
-
-    pullCity();
-    pullProduct();
-
-    setTimeout(pullLoop, 10 * 1000);
-}
-
-exports.start = start;
-exports.callbackReport = callbackReport;
-exports.unaliasResponseCode = unaliasResponseCode;
diff --git a/httpserver.js b/httpserver.js
deleted file mode 100644
index d90ecc6..0000000
--- a/httpserver.js
+++ /dev/null
@@ -1,90 +0,0 @@
-var http = require('http');
-var nsr = require('node-simple-router');
-var router = nsr();
-
-var config;
-var httpServer;
-
-function start(_config) {
-    if (_config != undefined) {
-        config = _config;
-    }
-    listenPort = config.globals.admin_port;
-    
-    router.get("/info", function(request, response) {
-        response.setHeader("Content-Type", "text/plain");
-        response.write('CHIPINFO / GATEWAY NAME: ' + config.globals.gateway_name + "\n");
-        response.write('PRODUCTS: ' + config.globals.products + "\n");
-        response.write('AAA HOST: ' + config.globals.aaa_host + "\n");
-        response.write('PARTNER: ' + config.h2h_out.partner + "\n");
-        response.write('PAUSED: ' + config.globals.pause + "\n");
-        response.write('UPTIME: ' + process.uptime() + "\n");
-        response.write('REQUESTS COUNT: ' + config.globals.requests_count + "\n");
-        response.write('ACTIVE REQUESTS COUNT: ' + config.globals.active_requests_count + "\n");
-        response.write('MAX ACTIVE REQUESTS COUNT: ' + config.globals.max_active_requests_count + "\n");
-        
-        response.end();
-    });
-    
-    router.get("/pause/:apikey", function(request, response) {
-        if (!config.globals.apikey) {
-            response.end('Undefined APIKEY on config');
-            return;
-        }
-        
-        if (request.params.apikey != config.globals.apikey) {
-            response.end('Invalid APIKEY');
-            return;
-        }
-        
-        config.globals.pause = 1;
-        response.end('Paused');
-    });
-    
-    router.get("/resume/:apikey", function(request, response) {
-        if (!config.globals.apikey) {
-            response.end('Undefined APIKEY on config');
-            return;
-        }
-        
-        if (request.params.apikey != config.globals.apikey) {
-            response.end('Invalid APIKEY');
-            return;
-        }
-        
-        delete config.globals.pause;
-        response.end('Resume');
-    });
-    
-    router.get("/reset-stats/:apikey", function(request, response) {
-        if (!config.globals.apikey) {
-            response.end('Undefined APIKEY on config');
-            return;
-        }
-        
-        if (request.params.apikey != config.globals.apikey) {
-            response.end('Invalid APIKEY');
-            return;
-        }
-        
-        config.globals.max_active_requests_count = 0;
-        
-        response.writeHead(307, {
-          'Location': '/info'
-        });
-        
-        response.end();
-    });
-
-    httpServer = http.createServer(router).listen(listenPort);
-    console.log('HTTP server listens on port ' + listenPort);
-
-    return httpServer;
-}
-
-function setConfig(_config) {
-    config = _config;
-}
-
-exports.start = start;
-exports.setConfig = setConfig;
-- 
1.9.0