<commit_before>var fs = require('fs');
var code = fs.readFileSync(__dirname+'/common.js','utf8');
eval(code);

var exec = require('child_process').exec;
var proPath = __dirname.replace('/routes','');
var Mode = require('stat-mode');
var mysql = require('mysql');
var updateconfigs = require(`${__dirname.replace('routes','')}/utils/updateconfigs`);
var connect = require(`${__dirname.replace('routes','')}/utils/connect`);
var dataFile = fs.readFileSync(`${__dirname.replace('routes','')}utils/install/original.json`,'utf-8');
var updaterouter = require(`${__dirname.replace('routes','utils')}/updaterouter`);

module.exports = {
    index:function(req, res, next) {
        
        var infomations = {};
        
        global.dataLength = 0;
        
        res.render(`${__dirname.replace('routes','utils')}/install/views/index.ejs`,{title:'install',infomations:infomations,assets:'/install/'});
        
    },
    configure:function(req, res, next) {
        var type = req.body.type || null,
            value = req.body.value || null;
        
        if(!type || !value){
            return res.json({
                msg:'缺少必填字段'
            });
        }

        ( () => new Promise( (resolve,reject) => {
            if(value!='nginx'){
                var ps = proPath+value;
                if(!fs.existsSync(ps)){
                    return res.json({
                        msg:'该文件不存在'
                    })
                }
                
                var stat = fs.statSync(ps);
                var mode = new Mode(stat);
                if(!mode.owner.write){
                    return res.json({
                        msg:'请将目录设置为可写'
                    })
                }
                
                res.json({
                    result:'ok'
                });
            }else{
                try{
                    execSync('nginx -t');
                    resolve();
                }catch(e){
                    res.json({
                        msg:'该环境无nginx'
                    });
                }
            }
        } ) )().then( () => new Promise( (resolve,reject) => {
            
            exec('nginx -t',function(err,s,d){
                res.json({
                    msg:'可直接绑定域名'
                });
            });
            
        } ) )
    },
    checksql:function(req, res, next) {
        
        var sqlhost = req.body.sqlhost || null,
            database = req.body.database || null,
            user = req.body.user || null,
            password = req.body.password || null,
            sqlport = req.body.sqlport || null;
        
        if(!sqlhost || !database || !user || !password || !sqlport){
            return json({<commit_msg>some err<commit_after>var fs = require('fs');
var code = fs.readFileSync(__dirname+'/common.js','utf8');
eval(code);

var exec = require('child_process').exec;
var proPath = __dirname.replace('/routes','');
var Mode = require('stat-mode');
var mysql = require('mysql');
var updateconfigs = require(`${__dirname.replace('routes','')}/utils/updateconfigs`);
var connect = require(`${__dirname.replace('routes','')}/utils/connect`);
var dataFile = fs.readFileSync(`${__dirname.replace('routes','')}utils/install/original.json`,'utf-8');
var updaterouter = require(`${__dirname.replace('routes','utils')}/updaterouter`);

module.exports = {
    index:function(req, res, next) {
        
        var infomations = {};
        
        global.dataLength = 0;
        
        res.render(`${__dirname.replace('routes','utils')}/install/views/index.ejs`,{title:'install',infomations:infomations,assets:'/install/'});
        
    },
    configure:function(req, res, next) {
        var type = req.body.type || null,
            value = req.body.value || null;
        
        if(!type || !value){
            return res.json({
                msg:'缺少必填字段'
            });
        }

        ( () => new Promise( (resolve,reject) => {
            if(value!='nginx'){
                var ps = proPath+value;
                if(!fs.existsSync(ps)){
                    return res.json({
                        msg:'该文件不存在'
                    })
                }
                
                var stat = fs.statSync(ps);
                var mode = new Mode(stat);
                if(!mode.owner.write){
                    return res.json({
                        msg:'请将目录设置为可写'
                    })
                }
                
                res.json({
                    result:'ok'
                });
            }else{
                try{
                    execSync('nginx -t');
                    resolve();
                }catch(e){
                    res.json({
                        msg:'该环境无nginx'
                    });
                }
            }
        } ) )().then( () => new Promise( (resolve,reject) => {
            
            exec('nginx -t',function(err,s,d){
                res.json({
                    result:'可直接绑定域名'
                });
            });
            
        } ) )
    },
    checksql:function(req, res, next) {
        
        var sqlhost = req.body.sqlhost || null,
            database = req.body.database || null,
            user = req.body.user || null,
            password = req.body.password || <PASSWORD>,
            sqlport = req.body.sqlport || null;
        
        if(!sqlhost || !database || !user || !password || !sqlport){
            return json({
{'fraction_non_alphanumeric': 0.1548883192969608, 'fraction_numerical': 0.0010984987184181618, 'mean_word_length': 1.377284595300261, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '1256847', 'n_tokens_mistral': 1538, 'n_tokens_neox': 1527, 'n_words': 242}