From 80090daea15f7169bd5c4465dd3eacf590cbf968 Mon Sep 17 00:00:00 2001 From: "sussurro@happypacket.net" Date: Tue, 12 Jul 2011 17:25:15 +0000 Subject: [PATCH] adding postgres support for msf git-svn-id: https://beef.googlecode.com/svn/trunk@1061 b87d56ec-f9c0-11de-8c8a-61c5e9addfc9 --- README.databases | 30 ++++++++++++++++++++++++++++++ beef | 18 +++++++++--------- config.yaml | 46 ++++++++++++++-------------------------------- 3 files changed, 53 insertions(+), 41 deletions(-) create mode 100644 README.databases diff --git a/README.databases b/README.databases new file mode 100644 index 000000000..ba15ddc62 --- /dev/null +++ b/README.databases @@ -0,0 +1,30 @@ + MySQL Notes: + * It's recommended to install MySQL >= 5.5.x + * Your system will require MySQL, MySQL-Server, MySQL-Devel and Ruby's MySQL libraries installed + * You will also need to "sudo gem install dm-mysql-adapter" + + * UTF8 notes. Update/Add in my.cnf (or my.ini on Win) the following. Then save and reboot MySQL. + - Read more here: http://cameronyule.com/2008/07/configuring-mysql-to-use-utf-8 + [mysql] + default-character-set=utf8 + [mysqld] + character-set-server=utf8 + collation-server=utf8_general_ci + init-connect='SET NAMES utf8' + [client] + default-character-set=utf8 + + * Please note that the db must exists. Schema will be created automatically. + mysql> CREATE DATABASE beef CHARACTER SET utf8 COLLATE utf8_general_ci; + mysql> grant all privileges on beef.* to 'beef'@'localhost' identified by 'beef123'; + + + +Postgres Notes + * You will need to install the postgresql package as well as the libpq-dev package + * You will need to "sudo gem install dm-postgres-adapter" + * As the postgres user: + - createuser -P beef + - createdb --owner=beef beef + * you may also need to change the pg_hba.conf file in /etc/postgresql so that the local all all optionis labeled as either trust or md5 + diff --git a/beef b/beef index 978308f2e..3546ef3c3 100755 --- a/beef +++ b/beef @@ -45,20 +45,20 @@ BeEF::Modules.load Socket.do_not_reverse_lookup = true # setup database -case config.get("beef.database.default") +case config.get("beef.database.driver") when "sqlite" - DataMapper.setup(:default, "sqlite3://#{$root_dir}/#{config.get("beef.database.sqlite.db_name")}") - when "mysql" + DataMapper.setup(:default, "sqlite3://#{$root_dir}/#{config.get("beef.database.db_file")}") + when "mysql","postgres" # === Remove comment of next line for logging queries (very verbose) === # DataMapper::Logger.new($stdout, :debug) # DataMapper.setup(:default, - :adapter => 'mysql', - :host => config.get("beef.database.mysql.db_host"), - :username => config.get("beef.database.mysql.db_user"), - :password => config.get("beef.database.mysql.db_passwd"), - :database => config.get("beef.database.mysql.db_name"), - :encoding => config.get("beef.database.mysql.db_encoding") + :adapter => config.get("beef.database.driver"), + :host => config.get("beef.database.db_host"), + :username => config.get("beef.database.db_user"), + :password => config.get("beef.database.db_passwd"), + :database => config.get("beef.database.db_name"), + :encoding => config.get("beef.database.db_encoding") ) else print_error 'No default database selected. Please add one in config.yaml' diff --git a/config.yaml b/config.yaml index 203b8a2fc..372995f45 100644 --- a/config.yaml +++ b/config.yaml @@ -39,39 +39,21 @@ beef: session_cookie_name: "BEEFSESSION" database: - #supported DBs: sqlite, mysql - - default: "sqlite" - # MySQL Notes: - # It's recommended to install MySQL >= 5.5.x - # Your system will require MySQL, MySQL-Server, MySQL-Devel and Ruby's MySQL libraries installed - # You will also need to "sudo gem install dm-mysql-adapter" - # - # UTF8 notes. Update/Add in my.cnf (or my.ini on Win) the following. Then save and reboot MySQL. - # Read more here: http://cameronyule.com/2008/07/configuring-mysql-to-use-utf-8 - # [mysql] - # default-character-set=utf8 - # [mysqld] - # character-set-server=utf8 - # collation-server=utf8_general_ci - # init-connect='SET NAMES utf8' - # [client] - # default-character-set=utf8 - # - # Please note that the db must exists. Schema will be created automatically. - # mysql> CREATE DATABASE beef CHARACTER SET utf8 COLLATE utf8_general_ci; - # mysql> grant all privileges on beef.* to 'beef'@'localhost' identified by 'beef123'; - # - - mysql: - db_host: "localhost" - db_name: "beef" - db_user: "beef" - db_passwd: "beef123" - db_encoding: "UTF-8" + # For information on using other databases please read the + # README.databases file - sqlite: - db_name: "beef.db" + # supported DBs: sqlite, mysql, postgres + driver: "sqlite" + + # db_file is only used for sqlite + db_file: "beef.db" + + # db connection information is only used for mysql/postgres + db_host: "localhost" + db_name: "beef" + db_user: "beef" + db_passwd: "beef123" + db_encoding: "UTF-8" crypto_default_value_length: 80