Skip to content

ChrisHinde/ServerUtils

Repository files navigation

This is a collection of scripts, written in Ruby, that can be useful for administrating servers

Created by Christopher Hindefjord - chris@hindefjord.se - http://chris@hindefjord.se - 2014
Licensed under the MIT License (see LICENSE file)

These scripts were written to be used on a specific server (but they should work on similar setups), so there’s no guarantee that they will work “out of the box” for you (but they might become more general in the future). It also means that all the output to the user is in Swedish, even so, all comments in the scripts are in English, so it shouldn’t be impossible to figure out what’s the output texts mean (a i18n version may come in the future).

The setup of the server is based on Debian with Postfix and Dovecot using virtual users (stored in a PostgreSQL database) and the Mailbox format. You can find how to set up a similar configuration here: wiki2.dovecot.org/HowTo/DovecotPostgresql

Please Note: These scripts are ment to be run by a server administrator (someone who knows what they are doing)! So limit the access to these script (like by changing the install directory to /usr/sbin/) Currently the scripts are vulnerable to SQL injections! Also limit the read access of the config file, since it contains the password to your “mail database”!

  • generate_password.rb - Generates a secure but user friendly password using random words

  • addemailaccount.rb - Lets you add an virtual e-mail account, handles all the steps that are involved (run this without any arguments to use it in interactive mode)

  • listemailaccounts.rb - Lists existing email accounts (tip: use with |less if there’s a lot of accounts)

  • deleteemailaccount.rb - Lets you delete an virtual e-mail account, handles all the steps that are involved

  • addemaildomain.rb - Lets you add a “virtual” e-mail domain, handles all the steps that are involved

  • listemaildomains.rb - Lists existing email domains (tip: use with |less if there’s a lot of accounts)

  • deleteemaildomain.rb - Lets you delete a virtual e-mail domain, handles all the steps that are involved (NOTE: Can delete accounts as well)

  • addemailalias.rb - Lets you add an e-mail alias

  • listemailalias.rb - Lists existing email aliases (tip: use with |less if there’s a lot of accounts)

  • deleteemailalias.rb - Lets you delete a e-mail alias

  • su_lib.rb - Contains a library of methods used by the other scripts

  • su_config.rb - Holds the configuration that controlls the behaviours of the scripts

All runable scripts (except generate_password.rb) will output help/usage information if you run them with the -h flag!

Requires pg, nokogiri (and ruby of course)

To install the requirements run

gem install pg nokogiri

or include the install requirements flag: -r (or --install-requirements) when you run install.rb:

./install.rb -r

Note: The requirements should be installed as root, as that’s who’s going to run the scripts! (the scripts can be run without root, but their functionality will be limited [depending on your setup]!)

If you get an error saying something like `require': cannot load such file -- mkmf, try installing the following (for Debian based systems):

sudo apt-get install postgresql-client libpq5 libpq-dev
sudo apt-get install ruby-dev
sudo apt-get install make

and then running this again

gem install pg nokogiri

Use the install.rb to install the scripts:

./install.rb

or

ruby install.rb

Check the usage information for more on how to use the install script:

./install.rb -h

By default the script won’t overwrite existing files in the install dir. If the file already exists, you get a message like Couldn't link the file and the script will continue to the next file. You can force the overwriting by using the -f flag (If you’re using the install script to update you should use -n to avoid overwriting your config file):

./install.rb -f   # or    ./install.rb -nf
  • Add functionality to the install script to actually move/copy the files

  • Add an unistall script

  • Maybe: Store config file in /etc instead of ./

About

A collection of scripts for handling a server

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages