<commit_before>'use strict';


var mongoose = require('mongoose'),
Database = mongoose.model('Database'),
_ = require('lodash'),
redis=require('redis');

var getErrorMessage = function(err) {
  var message = '';

  if (err.code) {
    switch (err.code) {
      case 11000:
        case 11001:
        message = 'Database already exists';
      break;
      default:
        message = 'Something went wrong';
    }
  } else {
    for (var errName in err.errors) {
      if (err.errors[errName].message) message = err.errors[errName].message;
    }
  }
  return message;
};

exports.create = function(req, res) {
  var database = new Database(req.body);
  database.user = req.user;

  database.save(function(err) {
    if (err) {
      return res.send(400, {
        message: getErrorMessage(err)
      });
    } else {
      res.jsonp(database);
    }
  });
};

exports.read = function(req, res) {
  res.jsonp(req.database);
};

exports.info = function(req,res){
  var client = redis.createClient(req.database.port, req.database.host);
  client.info(function( err, info) {
    if (err) {
      return res.send(400, { message: getErrorMessage(err) });
    } else {
      var goodlist = client.server_info;
      res.jsonp(goodlist);
    }
  });
};

exports.execute = function(req,res){
  var client = redis.createClient(req.database.port, req.database.host);
  client.send_command(req.param('command'),[], function( err, result){
    if(err){
      return res.send(400, {message: getErrorMessage(err) });
    } else {
      res.json({result: result});
    }
  });
};

exports.update = function(req, res) {
  var database = req.database ;

  database = _.extend(database , req.body);

  database.save(function(err) {
    if (err) {
      return res.send(400, {
        message: getErrorMessage(err)
      });
    } else {
      res.jsonp(database);
    }
  });
};

exports.delete = function(req, res) {
  var database = req.database ;

  database.remove(function(err) {
    if (err) {
      return res.send(400, {
        message: getErrorMessage(err)
      });
    } else {<commit_msg>[Hari]Disable flush commands from redis console issue #25<commit_after>'use strict';


var mongoose = require('mongoose'),
Database = mongoose.model('Database'),
_ = require('lodash'),
redis=require('redis');

var getErrorMessage = function(err) {
  var message = '';

  if (err.code) {
    switch (err.code) {
      case 11000:
        case 11001:
        message = 'Database already exists';
      break;
      default:
        message = 'Something went wrong';
    }
  } else {
    for (var errName in err.errors) {
      if (err.errors[errName].message) message = err.errors[errName].message;
    }
  }
  return message;
};

exports.create = function(req, res) {
  var database = new Database(req.body);
  database.user = req.user;

  database.save(function(err) {
    if (err) {
      return res.send(400, {
        message: getErrorMessage(err)
      });
    } else {
      res.jsonp(database);
    }
  });
};

exports.read = function(req, res) {
  res.jsonp(req.database);
};

exports.info = function(req,res){
  var client = redis.createClient(req.database.port, req.database.host);
  client.info(function( err, info) {
    if (err) {
      return res.send(400, { message: getErrorMessage(err) });
    } else {
      var goodlist = client.server_info;
      res.jsonp(goodlist);
    }
  });
};

exports.execute = function(req,res){
  if(req.param('command')==='flushdb'||req.param('command')==='flushall'){
    res.json({result:'You can not flush db'});
  }
  else{
    var client = redis.createClient(req.database.port, req.database.host);
    client.send_command(req.param('command'),[], function( err, result){
      if(err){
        return res.send(400, {message: getErrorMessage(err) });
      } else {
        res.json({result: result});
      }
    });
  }
};

exports.update = function(req, res) {
  var database = req.database ;

  database = _.extend(database , req.body);

  database.save(function(err) {
    if (err) {
      return res.send(400, {
        message: getErrorMessage(err)
      });
    } else {
      res.jsonp(database);
    }
  });
};

exports.delete = function(req, res) {
  var database = req.database ;

  database.remove(function(err) {
    if (err) {
      return res.send(400, {
        message: getErrorMessage(err)
      });
    } else {
{'fraction_non_alphanumeric': 0.15811182401466545, 'fraction_numerical': 0.011915673693858845, 'mean_word_length': 2.835676625659051, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1553021', 'n_tokens_mistral': 1486, 'n_tokens_neox': 1441, 'n_words': 286}