<commit_before>var fs = require('fs');
var moment = require('moment');
var winston = require('winston');

var common = require('../../../core/lib/common');
var misc = require('../../../core/lib/misc');
var connection = require('../../../core/lib/connection');   // todo: can load from CLI modules

var db = require('./database');
var query = require('./query');

var routeData = require('../route.json');
var routeTable = misc.getRouteTable(routeData);
var controllerHubFlag = misc.commonFlag().controllerHub;

function gatewayList(req, res) {
    var params = {
        title: "넷 앱 컨트롤러 허브",
        pinnedNetAppCount: 4,
        pinnedNetAppList: [],
        recentNetAppCount: 8,
        recentNetAppList: [],
        categoryList: []
    };

    var mysql = connection.get();

    db.getGatewayGroupList(mysql, function (error, results) {
        params.groupList = results;
        db.getGatewayList(mysql, function (error, results) {
            results.map(function (item) {
                item.vmList = item.installed_apps && item.installed_apps.split(',').map(function (app) {
                        return app.trim();
                    }).filter(function (app) {
                        return !!app;
                    });
            });

            params.gatewayList = results;

            res.render(BLITITOR.config.site.theme + '/page/controller_hub/controller_hub', params);
        });
    });
}

function viewGateway(req, res) {
    var params = {
        title: '넷 앱 컨트롤러 허브',
        gateway_id: req.params.gatewayID,
        gatewayInfo: {},
        rtvmList: []
    };

    if (!params.gateway_id) {
        return res.redirect('back');
    }

    var mysql = connection.get();

    db.getGatewayInfo(mysql, Number(params.gateway_id), function (error, result) {
        if (result && result[0]) {
            params.gatewayInfo = result[0];
        }

        db.getRtvmList(mysql, Number(params.gateway_id), function (error, results) {
            if (!error && results) {
                params.rtvmList = results;
            }

            res.render(BLITITOR.config.site.theme + '/page/controller_hub/gateway', params);
        });
    });
}<commit_msg>added controller binary<commit_after>var fs = require('fs');
var path = require('path');
var moment = require('moment');
var winston = require('winston');

var childProcess = require('child_process');

var common = require('../../../core/lib/common');
var misc = require('../../../core/lib/misc');
var connection = require('../../../core/lib/connection');   // todo: can load from CLI modules

var db = require('./database');
var query = require('./query');

var routeData = require('../route.json');
var routeTable = misc.getRouteTable(routeData);
var controllerHubFlag = misc.commonFlag().controllerHub;

function gatewayList(req, res) {
    var params = {
        title: "넷 앱 컨트롤러 허브",
        pinnedNetAppCount: 4,
        pinnedNetAppList: [],
        recentNetAppCount: 8,
        recentNetAppList: [],
        categoryList: []
    };

    var mysql = connection.get();

    db.getGatewayGroupList(mysql, function (error, results) {
        params.groupList = results;
        db.getGatewayList(mysql, function (error, results) {
            results.map(function (item) {
                item.vmList = item.installed_apps && item.installed_apps.split(',').map(function (app) {
                        return app.trim();
                    }).filter(function (app) {
                        return !!app;
                    });
            });

            params.gatewayList = results;

            res.render(BLITITOR.config.site.theme + '/page/controller_hub/controller_hub', params);
        });
    });
}

function viewGateway(req, res) {
    var params = {
        title: '넷 앱 컨트롤러 허브',
        gateway_id: req.params.gatewayID,
        gatewayInfo: {},
        rtvmList: []
    };

    if (!params.gateway_id) {
        return res.redirect('back');
    }

    var executePath = path.join(BLITITOR.root, 'theme', BLITITOR.config.site.theme, 'bin')
    var cmd = {
        list: path.join(executePath, 'list'),
        create: path.join(executePath, 'create'),
        connect: path.join(executePath, 'connect')
    };

    var gatewayConnectionInfo = {
        'MANAGER_IP': '192.168.100.254',
        'MANAGER_PORT': '1111'
    };

    childProcess.execFile(cmd.list, { env: gatewayConnectionInfo }, function (error, stdout, stderr) {
        var result = stdout.toString().replace(/\\n/g, '\n');

        console.log(result);

        var mysql = connection.get();

        db.getGatewayInfo(mysql, Number(params.gateway_id), function (error, result) {
            if (result && result[0]) {
                params.gatewayInfo = result[0];
            }

            db.getRtvmList(mysql, Number(params.gateway_id), function (error, results) {
                if (!error && results) {
                    params.rtvmList = results;
                }

                res.render(BLITITOR.config.site.theme + '/page/controller_hub/gateway', params);
            });
        });
    });
}
{'fraction_non_alphanumeric': 0.15212264150943397, 'fraction_numerical': 0.0047169811320754715, 'mean_word_length': 2.168742216687422, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '81', 'n_tokens_mistral': 1569, 'n_tokens_neox': 1522, 'n_words': 303}