{"size": 1556, "ext": "js", "max_stars_repo_path": "services/validator.js", "max_stars_repo_name": "Hakall/esup-otp", "max_stars_repo_stars_event_min_datetime": "2018-12-11T07:42:42.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-22T12:56:42.000Z", "max_issues_repo_path": "services/validator.js", "max_issues_repo_name": "Hakall/esup-otp", "max_issues_repo_issues_event_min_datetime": "2020-12-11T14:24:47.000Z", "max_issues_repo_issues_event_max_datetime": "2020-12-18T18:24:03.000Z", "max_forks_repo_path": "services/validator.js", "max_forks_repo_name": "Hakall/esup-otp", "max_forks_repo_forks_event_min_datetime": "2017-07-26T11:54:11.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-29T15:52:47.000Z"}
{"max_stars_count": 3, "max_issues_count": 2, "max_forks_count": 6, "avg_line_length": 30.5098039216, "max_line_length": 84, "alphanum_fraction": 0.6767352185}
var restify = require('restify');
var properties = require(__dirname + '/../properties/properties');
var utils = require(__dirname + '/../services/utils');
var logger = require(__dirname + '/../services/logger').getInstance();

exports.check_hash = check_hash;

function check_hash(req, res, next) {
    var hashes = utils.get_hash(req.params.uid);
    for (hash in hashes){
        if (req.params.hash == hashes[hash]) return next();
    }
    return next(new restify.ForbiddenError());
}

exports.check_hash_socket = check_hash_socket;

function check_hash_socket(uid, hash) {
    var hashes = utils.get_hash(uid);
    for (_hash in hashes){
        if (hash == hashes[_hash]) return true;
    }
    return false;
}

exports.check_api_password = check_api_password;

function check_api_password(req, res, next) {
    let param = req.params.api_password
    if (req.headers.authorization && param === '') {
        param = utils.get_auth_bearer(req.headers)
    }
    if (param == properties.getEsupProperty('api_password')) return next();
    else return next(new restify.ForbiddenError());
}

exports.esupnfc_check_server_ip = function esupnfc_check_server_ip(req, res, next) {
    let ip = req.headers["x-forwarded-for"];
    //logger.debug(req.headers);
    if(ip == undefined) {
	ip = req.connection.remoteAddress;
    }
    if (ip == properties.getEsupProperty('esupnfc').server_ip) {
	return next();
    }
    else {
	logger.info("remote ip : " + ip + " is not esupnfc server ip -> forbidden");
	return next(new restify.ForbiddenError());
    }
};
