• Home
  • Consultancy
  • Contact
  • How to set up ProFTP, MySQL and Virtual Users

    June 15th, 2010 by Marcus Povey

    ProFTP is a configurable FTP server available on most *nix platforms.

    I recently had the need to get this working and authenticating off a PHP maintained MySQL backend, and this post is primarily to aid my own memory should I ever have to do it again.

    Installing ProFTP

    In order to use MySQL as a back end you need to install some packages. If you’re using a Debian based distro like Ubuntu, this is easy:

    apt-get install mysql-server proftpd proftpd-mod-mysql

    The database schema

    Next, you need to install the database schema to store your users and passwords.

    CREATE TABLE IF NOT EXISTS users (
    userid varchar(30) NOT NULL default '',
    passwd varchar(128) NOT NULL default '',
    uid int(11) default NULL,
    gid int(11) default NULL,
    homedir varchar(255) default NULL,
    shell varchar(255) default NULL,
    UNIQUE KEY uid (uid),
    UNIQUE KEY userid (userid)
    ) TYPE=MyISAM;

    CREATE TABLE IF NOT EXISTS groups (
    groupname varchar(30) NOT NULL default '',
    gid int(11) NOT NULL default '0',
    members varchar(255) default NULL
    ) TYPE=MyISAM;

    One important thing to note here – that caused me a fair amount of hair pulling when I tried to use encrypted passwords – is that the password field shown in many howtos on the internet is much too short. This causes the hashed password to be quietly truncated by MySQL when saved.

    This results in a somewhat misleading “No such user found” error to appear in the logs when using encrypted passwords.

    To end all argument I’ve allowed passwords up to 128 chars, but this field could probably be a good deal shorter.

    The user table looks much like /etc/passwd and is largely self explanatory. The uid & gid fields correspond to a system user in most cases, but since we’re using virtual users they can largely be ignored. Homedir points to a location which will serve as the user’s default directory. Shell is largely unused and can be set to /bin/false or similar.

    Configuring ProFTP

    Next, you need to make some changes to the ProFTP configuration files stored in /etc/proftpd. While doing this it is handy to run proftp in debug mode from the console:

    proftpd -nd6

    proftpd.conf

    1. Make sure the AuthOrder line looks like:

      AuthOrder mod_sql.c

    2. Ensure that the following line is uncommented:

      Include /etc/proftpd/sql.conf

    3. For belts and braces I’ve included the following at the end, although I’m not entirely sure it’s strictly required:

      <IfModule mod_auth_pam.c>
      AuthPAM off
      </IfModule>

    4. Our users don’t need a valid shell, so:

      RequireValidShell off

    modules.conf

    1. Make sure the following lines are uncommented:

      LoadModule mod_sql.c
      LoadModule mod_sql_mysql.c

    sql.conf

    1. Set your SQL backend and ensure that authentication is turned on:

      SQLBackend mysql
      SQLEngine on
      SQLAuthenticate on

    2. Tell proftp how passwords are stored. You have a number of options here, but since I was using mysql’s PASSWORD function, I’ll defer to the backend.

      SQLAuthTypes backend

    3. Tell proftp how to connect to your database by providing the required connection details, ensure that the user has full access to these tables.

      SQLConnectInfo database@host user password

    4. Define your table structure in the format tablename fields….

      SQLUserInfo users userid passwd uid gid homedir shell
      SQLGroupInfo groups groupname gid members

    Adding users

    I manage users from within a PHP web application that I’m developing, but in a nutshell adding FTP users from this point is a simple insert statement looking something like:

    mysql_query("REPLACE INTO users
    (userid, passwd, uid, gid, homedir, shell)
    VALUES
    ('$userid', PASSWORD('$password'), $uid, $gid, '$homedir', '$shell')");

    Have fun!

    Multiple site support with MP’s Multisite Elgg

    April 19th, 2010 by Marcus Povey

    I have just Open Sourced an “itch scratching” project I’ve been hacking on for a little while. So, without much further ado, I’d like to introduce you to Marcus Povey’s Multisite Elgg!

    It is currently in Beta and the code could do with a bit of a tidy, but this is Open Source so roll up your sleeves and get involved.

    What is it?
    Multisite Elgg allows you to run multiple separate Elgg sites off of the same install of the codebase, saving disk space and making administration a whole bunch easier.

    Currently based around the latest Elgg 1.7 release, once installed adding new Elgg sites is a matter of clicking on a button and entering in some details.

    What can I do with it?
    You can do everything that you can do with Elgg, but with the ability to create new networks on demand. This will for example let you:

    • Set up your own version of Ning! What with Ning phasing out free accounts, it is my hope that Multisite Elgg will let a thousand more Nings bloom!
    • In your organisation or institution, easily set up Elgg sites for each department.
    • If your one of the Elgg hosting companies out there, you may want to look at multisite in order to simplify your work flow.
    • … etc…

    Installation
    Once you have downloaded the installation package you will need to do a few things in order to get up and running. Multisite Elgg assumes that you have some knowledge of how to set up and run a server – there is no wizard just yet!

    1. Unzip the package on your web server.
    2. Point your master domain at the contents of the install location on your web server. This is your master control domain, go here to configure your sites. Because of this you might want to consider putting this behind some further access restrictions.
    3. Point any sub domains to the contents of the docroot folder, eg (/var/multisite/docroot). This directory forms the base of all your Elgg installs. To make things even more automated you may want to consider making this an Apache wildcard domain, if your DNS provider supports it.
    4. Chmod 777 docroot/data: This is the default location for multisite domains.
    5. Install schema/multisite_mysql.sql: Create a new database on your Mysql server and install the Multisite schema – this is your master control database.
    6. Rename settings.example.php in docroot/elgg/engine/ to settings.php and configure:

      $CONFIG->multisite->dbuser = ‘your username’;
      $CONFIG->multisite->dbpass = ‘password’;
      $CONFIG->multisite->dbhost = ‘host’;

      Make sure this user has sufficient privileges to create and grant access to databases and tables on your server. This will allow the admin tool to create the databases for your hosted sites automatically.

    7. Visit your master domain and configure your admin user
    8. Begin configuring your sites!

    Creating sites
    Once you have created an admin user, adding sites is easy. Currently you can only create one type of site, but in the future Multisite Elgg will let you create sites which have quotas and other access restrictions.

    You have a box to enter database details, or you can leave them blank to use Multisite Elgg user defined above (which you may not want to do for security reasons).

    You can also select which of the installed plugins you want to allow, this lets have different sites have different plugins available while still installing them on the same codebase.

    Contributing
    So, that was a brief introduction to Multisite Elgg. I hope that at least some of you out there find it useful!

    As I said before, it’s Open Source, so if you want to get involved here are the important details:

    If you want to contribute patches, feel free to use the bug tracker or discussion forum!

    Enjoy!

    [audioblog] Google buzz and privacy

    February 12th, 2010 by Marcus Povey

    Unless you have been living under a rock the last few days you will be aware of Google’s new social networking product – Google Buzz.

    Unfortunately it would seem that some assumptions made by the designers and the automatic opt-in nature of the service has lead to some serious issues.

    For me it underlines some of the problems with entrusting your personal data to the cloud. That is not to say of course that it is a user’s fault that their data gets shared in such a way – everything in the day to day usage of these tools gives the user a reasonable expectation of privacy.

    The trouble is, that this expectation is largely an illusion. When using cloud services, you are entrusting them and you hope that they will exercise the same care when dealing with your data as you would – but unfortunately this is rarely the case.

    Whether through carelessness or malicious action information has a tendency to leak. Assumptions made by the design team can be proved poor. So in short, never put anything on the internet that you wouldn’t be happy to see on a billboard.

    Audio clip: Adobe Flash Player (version 9 or above) is required to play this audio clip. Download the latest version here. You also need to have JavaScript enabled in your browser.

    Akismet plugin for Elgg

    January 18th, 2010 by Marcus Povey

    I have just written a very small Akismet plugin for Elgg.

    When enabled and configured, this plugin will scan newly submitted comments of the ‘generic_comment’ annotation class.

    While spam comments are rarer on Elgg due to the fact that most sites don’t allow anonymous comments, this could be useful for people who are getting spam comments from people who have signed up.

    This plugin comes into its own when you allow anonymous comments, such as on a site I recently built for a client.

    Extending this plugin to scan other content should be fairly straight forward for even a novice coder, but if I have time I’ll provide an interface to do so.

    Anyway, go get it here, or check out the project page on google code!

    Image “Spam! [don't buy]” by David Trattnig

    Using an XBOX 360 wireless controller with XBMC on Ubuntu

    December 29th, 2009 by Marcus Povey

    This Christmas I finally bit the bullet and treated myself to a shiny XBox 360. Ostensibly this was so that I could experiment with console development, but mostly I have used it to play Gears of War.

    In a slight departure from what I usually talk about, I thought I’d quickly jot down how I got the wireless controller to work with my Ubuntu XBMC media PC.

    The wireless controller provides a slightly more usable remote than my iPhone (which must first be unlocked making quick pauses impossible) or rather flaky wireless keyboard, so hopefully this will be useful to someone.

    Getting started

    My media PC currently runs Ubuntu Karmic with XBMC. To begin with you will need to install the XBox kernel driver (already installed on Karmic).

    Most importantly however, you will need to get yourself a XBox wireless gaming receiver for Windows – which I got included with my second controller. Xbox controllers do not use standard bluetooth, so you can’t just pair in the normal way using your existing hardware.

    This howto has some more info

    Configuring XBMC

    Assuming you have your module installed and controller paired you will need to tell XBMC about it by configuring a keyfile:

    1. I used this keyfile as a starting point. Download and save it as ~/.xbmc/userdata/keymaps/Keymap.xml (note case).
    2. Find out what your computer thinks the controller is by looking at the output from: cat /proc/bus/input/devices – you want a "Name" that says something like "Xbox 360 Wireless Receiver"
    3. Replace all occurrences of "Microsoft Xbox Controller S" with this value.

    At this point if you start XBMC it should respond to the controller. If you are lucky this is all you will have to do, however for me I had to mess around with the key bindings a bit since the example keymap file didn’t match my controller exactly.

    If this happens to you there’s not much I can suggest other than to bind one key at a time, restart XBMC and see what button that maps to then repeat until all your keys are mapped. I’m sure there must be an easier way that I’ve overlooked, feel free to comment below!

    For what it’s worth, here is my modified (but somewhat incomplete) key file which has largely sensible bindings. Hack away to get it working how you like.

    » Modified Keymap

    Image “XBMC” by Miskan

    Next Page »
    All content is © Copyright Marcus Povey 2008-2010 and released under a Creative Commons licence unless otherwise stated.

    Creative Commons License