haraka / Haraka

A fast, highly extensible, and event driven SMTP server
https://haraka.github.io
MIT License
5.09k stars 662 forks source link

How to fetch user and password data in auth_flat_file.ini through mysql database. #1113

Closed vivek779 closed 9 years ago

vivek779 commented 9 years ago

hello I was working on haraka and i was trying to fetch user data and password in auth_flat_file so that i dont have to type repeatedly for evry single user and password is there any way to do that i am new so dont have knowlege it would really helpful if you guide me

smfreegard commented 9 years ago

Sorry - you need to have some Javascript and node.js experience to do this. You can look at the other plugins as a guide, but it's up to you to learn it well enough to do it yourself as I personally have no requirement for an auth_mysql plugin or the time to teach you how to code it.

vivek779 commented 9 years ago

thanks for quick revert i am saying to teach me just guide as how to do it i am able to fetch data from database in javscript bt i am still blank on which line i should edit so that user data and password ar fetched automatically to auth_flat file if you just guide it would really helpful thank u

smfreegard commented 9 years ago

This function: https://github.com/baudehlo/Haraka/blob/master/plugins/auth/flat_file.js#L37 is passed the username (user) and a callback function (cb). You look up the username and return the password to the callback function (the password must be in plain-text) or return the bare callback without any arguments if the user is not found.

vivek779 commented 9 years ago

Hi there as per you suggestion i created a small mysql code and fetch the values in function and put it into flat_file and compared the function with function with function (user, cb) bt it is giving me errors as folllows: [CRIT] [-] [core] Compiling plugin: auth/flat_file failed [CRIT] [-] [core] /usr/local/lib/node_modules/Haraka/plugins/auth/flat_file.js:5 0 [CRIT] [-] [core] exports.get_plain_passwd = function (user, cb) { [CRIT] [-] [core] ^^^^^^^ [CRIT] [-] [core] SyntaxError: Unexpected identifier [CRIT] [-] [core] at Object.exports.runInNewContext (vm.js:68:16) [CRIT] [-] [core] at Object.plugins._load_and_compile_plugin (/usr/local/lib /node_modules/Haraka/plugins.js:181:12) [CRIT] [-] [core] at plugins.load_plugin (/usr/local/lib/node_modules/Haraka /plugins.js:120:26) [CRIT] [-] [core] at Array.map (native) [CRIT] [-] [core] at Object.plugins.load_plugins (/usr/local/lib/node_module s/Haraka/plugins.js:113:39) [CRIT] [-] [core] at Object.Server.createServer (/usr/local/lib/node_modules /Haraka/server.js:116:13) [CRIT] [-] [core] at Object. (/usr/local/lib/node_modules/Haraka/ haraka.js:66:8) [CRIT] [-] [core] at Module._compile (module.js:460:26) [CRIT] [-] [core] at Object.Module._extensions..js (module.js:478:10) [CRIT] [-] [core] at Module.load (module.js:355:32)

my flat_file modication is as follows

// Auth against a flat file
var net_utils = require('./net_utils');
var mysql      = require('mysql');
var connection = mysql.createConnection({
  host     : 'localhost',
  user     : 'root',
  password : 'vivek',
  database : 'haraka'
});
connection.connect();

connection.query('SELECT * FROM users', function(err, rows )
{
  if (err) throw err;

});

connection.end();

exports.register = function () {
    var plugin = this;
    plugin.inherits('auth/auth_base');
    plugin.load_flat_ini();
};

exports.load_flat_ini = function () {
    var plugin = this;
    plugin.cfg = plugin.config.get('auth_flat_file.ini', function () {
        plugin.load_flat_ini();
    });
};

exports.hook_capabilities = function (next, connection) {
    var plugin = this;
    // don't allow AUTH unless private IP or encrypted

    var methods = null;
    if (plugin.cfg.core && plugin.cfg.core.methods ) {
        methods = plugin.cfg.core.methods.split(',');
    }
    if (methods && methods.length > 0) {
        connection.capabilities.push('AUTH ' + methods.join(' '));
        connection.notes.allowed_auth_methods = methods;
    }
    next();
};
var rows =user=function(users)
exports.get_plain_passwd = function (user, cb) {
    var plugin = this;
    if (plugin.cfg.users[user]) {
        return cb(plugin.cfg.users[user]);
    }
    return cb();
};

normally If I fetch the values from database from that small code it would return as { name: 'vivek', password: 'vivek' } please guide me i tried bt not getting the results

Dexus commented 9 years ago

can you please push your code to pastebin.com and put the link here?

EDIT: is your code really:

var rows =user=function(users)
exports.get_plain_passwd = function (user, cb) {

that can't work... if you don't know what you are making there - please pay a developer to do this for you... if you need help related to haraka - we will help you - but not if you don't know what you doing in code.

vivek779 commented 9 years ago

Could you please tell how to do it i know it wont work i just comapred the functions i know what i am doing bt dosent know how to do it that why i pasted it here