This is an old revision of the document!


fun_plug

fun_plug is the name of a script that will run after the DNS323 has booted (see fun_plug).

The fonz fun_plug (ffp) is a fun_plug script plus a collection of applications compiled and packaged by fonz. The system uses the DNS-323 fun_plug capability to hook your own start procedures to the startup.

To get started, read the README for current information.

Homepage: http://www.inreto.de/dns323/fun-plug/

Version 0.5

Links

Installation

For installation instructions, please follow the links for your device. Also, read the sections on the root user and shells. If the installation does not work as expected see the Troubleshooting section below.

Telnet Access

If installation was successful, a telnet server has been started. It does not ask for user name and password, and directly starts a root shell.

Note: Because fun_plug enables telnet access without a password, it would be exceptionally foolhardy to expose your DNS-323 to the public internet at this point.

A telnet client utility is available by default in Windows XP and in most Linux distributions. It's not available in Cygwin. Windows Vista has a telnet client which is disabled by default but can be enabled easily in Control Panel → Programs → Programs And Features → Turn Windows features on or off → Telnet Client.

See “The root user” below for more information.

Upgrading from 0.3/0.4

The recommend upgrade method is to reinstall. Except for the fun_plug script, 0.5 will not overwrite any files of your 0.3/0.4 funplug. After successful installation of 0.5, you can cleanup your 0.3/0.4 files:

cd /mnt/HD_a2
rm -rf fun_plug.d

Upgrading packages

If you want to upgrade packages, use

cd /path/to/new/packages
funpkg -u package-file.tgz

This will install the new version and remove any now obsolete files from the old version.

WARNING: Before any other packages, you should upgrade the funpkg package itself (funpkg -u funpkg-…tgz). This ensures that additional functions become available that some recent packages may need during installation. After this, you should check for an updated uclibc package.

WARNING: Any configuration files, start scripts, etc will be overwritten with the versions in the new package. If you want to keep your changes, you need to backup your custom files and restore them after the upgrade. A simple way to create backups of your config files and start scripts is:

cd /ffp
mkdir my-etc my-start
cp -ar etc/* my-etc
cp -ar start/* my-start

If you want to restore one or more files, e.g. the ssh config files:

cd /ffp
cp -ar my-etc/ssh etc

Not all packages overwrite existing config files. Some install new versions as “*.new” files (e.g. /ffp/etc/profile.new). It's up to you to remove existing config files and rename the new versions (remove .new from the file name, e.g. cd /ffp/etc; mv profile.new profile). Be sure to keep a backup old versions and to merge your custom changes, first.

To find any pending *.new files, you can use find:

cd /ffp/etc
find -name \*.new

To compare an old version with the new file, you can use diff:

diff profile profile.new

Finally, to replace the config file with the new version, use mv:

mv profile.new profile

Upgrading ffp itself

From Fonz, the developer: There's nothing in the install tarball (fun_plug.tgz) that's not in a package. The simplest way to stay current is to install all the main packages ( http://www.inreto.de/dns323/fun-plug/0.5/packages/ ).

I suggest to keep a local copy of the packages using rsync (don't forget –delete). Then use 'funpkg -i *.tgz' and 'funpkg -u *.tgz' to install and upgrade.

Sometimes, there's special care needed (like with the ffp-scripts package). Before upgrading packages, you should have a look at the ChangeLog ( http://www.inreto.de/dns323/fun-plug/0.5/ChangeLog.txt ) for specific instructions.

Currently, the ffp-base package needs special attention. It contains all the busybox links, and conflicts at least with coreutils. If you have coreutils installed, ffp-base will overwrite many of the coreutils programs with links to busybox. I therefore recommend to not upgrade ffp-base unless you have a specific reason to do so.


The root user

'root' is the system administrator on Linux. A lot of tasks require root permissions, it's essential to have a working root account.

The firmware comes with a disabled root account that cannot login the 'normal' way. For this reason, the funplug starts an open telnet server that circumvents the normal login procedure to provide a root shell directly.

To fix the root account, you should run pwconv to update /etc/shadow, set a password and change the shell. NOTE: We'll store the password with store-passwd.sh once we check a few things in later steps:

pwconv
passwd
usermod -s /ffp/bin/sh root

If you omit the usermod command, login will start the shell configured for root in /etc/passwd. Usually, this is the firmware shell /bin/sh (requires unlock code, type 5784468 and press Enter). For more information on shells, see the 'Shells' section below.

Before saving your changes, you should run additional checks on the password and group files. Some firmware versions duplicate the ftp user, and now is a good time to fix this, too.

pwck
grpck

You may ignore warnings about missing home directories and invalid group names. If asked to remove a duplicate user, say 'yes' to remove one of them. Rerun the commands to check that it's fixed.

Test your changes with the login program:

login

If that worked, save the password files to flash memory:

store-passwd.sh

To enable login for telnet, edit the telnetd.sh start script and remove the '-l /ffp/bin/sh' option. You can do this from the command line like this:

cd /ffp/start
sed -i '/flags/ s@^@#@' telnetd.sh

Restarting telnet while logged in via telnet requires special care (the telnet session will be aborted!):

cd /tmp
nohup sh /ffp/start/telnetd.sh restart

Alternatively, you can disable telnet and start the SSH server instead. First, test ssh login:

cd /ffp/start
sh sshd.sh start

Login from a remote host now (as root, of course). If it works, disable telnet and enable sshd permanently:

cd /ffp/start
chmod a-x telnetd.sh
chmod a+x sshd.sh

Reactivating telnet. If for some reason, sshd stops working or the root password is lost, the minimal fun_plug.tgz created by bq041 can re-enable password-less telnet: http://forum.dsmg600.info/p19176-Today-23%3A27%3A18.html#p19176

root without password. If you want to use the normal login to benefit from the better environment, but don't want to set a real password for root, you can remove root's password (login won't even ask for a password, then):

usermod -p '' root

This can easily be added to a start script. WARNING: ssh does not allow root to login without a password.


Shells

User login shells are stored in /etc/passwd. The default shell in /etc/passwd for all users is /bin/sh. The configured login shell is started when a user connects via telnet (with username and password) or ssh.

/bin/sh is included in the firmware. On D-Link and Conceptronic devices, you need to type the unlock code 5784468 and press Enter to get a prompt. The environment of /bin/sh does not include any ffp extensions (see also /ffp/etc/profile)!

ffp provides two alternative shells:

  • /ffp/bin/sh - the busybox ash shell (like /bin/sh, but a more recent version, and without unlock code)
  • /ffp/bin/bash - the popular bourne-again shell (must be installed manually using funpkg, download from inreto.de)

The root user can change login shells using chsh (or usermod) for all users:

chsh -s /ffp/bin/sh username

Remember to run 'store-passwd.sh' to make the changes permanent.

By default, only root can change login shells. You can allow each user to change his login shell himself by granting root permissions to the chsh program. As root, run:

chmod u+s /ffp/bin/chsh

To change their login shells, non-root users can now run:

chsh -s /ffp/bin/sh

or, if bash has been installed:

chsh -s /ffp/bin/bash

Many scripts will refer to ”#!/bin/sh”, especially if those scripts are intended to work in various environments (applies to Optware and others). However, the shell in DNS323 is limited (ex.: doesn’t support pattern replacement such as ${var/${original_string}/${replacement_string}} nor simple expressions such as $( ( + 1 )) ). You then have 3 options:

1) Manually edit all your scripts.

2) Redirect /bin/sh

ln –fs /ffp/bin/sh /bin/sh

3) Redirect the entire Busybox (this will take care or /bin/sh, but also any other references to Busybox tools in /bin).

mv /bin/busybox /bin/busybox-dns323 ; ln -fs /ffp/bin/busybox /bin/busybox

Basic configuration

During startup, various scripts are run that you can enable, disable, and modify to your needs.

Scripts to start, stop, and restart various network servers and a few other functions are stored in /ffp/start/. The scripts that are marked 'executable' will be run automatically at startup. To activate a script, e.g. mediatomb.sh, run:

chmod a+x /ffp/start/mediatomb.sh

To remove the 'executable' flag, run:

chmod a-x /ffp/start/mediatomb.sh

Example configuration files for some services are included in /ffp/etc/examples.

Before the scripts in /ffp/start, /ffp/etc/fun_plug.local is run, if present and executable. You can use fun_plug.local for any commands you want to run during startup that don't fit in real start scripts. Examples:

  • adjust clock ticks to reduce drift
  • set your timezone
  • remove firmware cronjobs

/ffp/etc/examples/ contains an example fun_plug.local script. Note that you should set the PATH yourself early in in fun_plug.local. The fun_plug.local function was added in version 2008-08-11 of the fun_plug script.


Contributed Packages, Help, Howtos, Guides, Discussions

AFP (netatalk), Bonjour (avahi) Installing Avahi and AFP on the DNS-323 by Avinash Meetoo

BackupPC: backup software suite with a web-based frontend

Cleanboot (Proper shutdown): cleanboot 1.0 for DNS-323 / CH3SNAS by pof

curl:

duplicity duplicity for the dns323 by drak0

Fan Control How to control the fan speed by Uli and PeterH

Firefly: ffp 0.5 Firefly package (with ogg and flac) by Delekhan

FUSE (File System in User-Space) Fuse packages for fonz fun_plug by pof

lftp: Addons to fonz's fun_plug 0.5 experimental by SweMart

lighttpd with webdav Building webdav-enabled lighttpd for DNS-323 by ianalis

llink llink-2.1.0 for the dns323 by drak0

Mediatomb MediaTomb 0.12.0 SVN 1899 by boilerjt

Mediatomb on DNS-313 Musicpal streaming Music from my DNS-313 by gary

Musicbrowser Light-weight web based music browser / streamer by mingoto

MySQL: packages for Fonz Funplug 0.5. by forre

nano editor: CH3SNAS:Tutorials/nano by Uli

PHP/MySQL: packages for Fonz Funplug 0.5. by forre

Polipo Web Proxy: Polipo - proxy for funplug 0.5 by rejong

ProFTPD: Addons to fonz's fun_plug 0.5 experimental by SweMart

Python: Python for Fonz funplug 0.5 by forre

Squeezecenter: There are three alternatives that Yannick summarized accurately in the slimdevices forums slimdevices forums

  • You can use the Squeezecenter packages from ffp-0.5 (needs some manual configuration, see Setting up SqueezeCenter on DNS-323 in Sidney's blog)
  • or the Squeezecenter-only funplug based on ffp-0.5, available at inreto.de
  • or follow Yannick's DIY guide at slimdevices.com.
    • BTW: Yannick's DIY guide has a very good step-by-step proceedure for MySQL installation

Samba Web Administration Tool (SWAT) Enabling SWAT

smartmontools: SMART monitoring tools on DNS-323?

SSH with denyhosts DenyHosts for Fonz ffp 0.5 by forre

start/usbdisk.sh (Mount external USB disk):

Subversion svnserve: DIY: Turn your NAS into a Subversion Server by mas-tech-talk

sudo: Addons to fonz's fun_plug 0.5 experimental by SweMart

Time Machine, OS X, AppleTalk: HOWTO: Mac OS X (10.5.4) Time Machine and the DNS-323 by TimN

Transmission (Bittorrent):

unrar: http://linux.yes.nu/ffp-0.5/packages/

UPS support with nut: NUT (Network UPS Tool)

wget

Build scripts:

funplug on DNS-313: HOWTO: DNS-313 & fun_plug for dummies by Bronek

funplug on Zyxel NSA-220:


Troubleshooting

  • The two installation files are fun_plug and fun_plug.tgz, all lower case, the former without extension. Some systems (e.g. OSX) seem to silently rename the fun_plug script to fun_plug.sh or fun_plug.txt. This will not work, you must remove any extension. Mac Os X 10.6.2 uncompress the fun_plug.tgz automatic , you must compress the tar before copy to the Volume
  • DNS-313: Older firmware versions start their own telnet server that conflicts with ffp. Upgrade to the latest firmware.
  • DNS-343: Firmware 1.03+ support only. FW less than 1.03 will have symbolic link errors. 1.03beta70 is confirmed to work.
  • First disk in left bay: If you put the first disk in the left bay, and later added a second disk in the right bay, internal paths are swapped. Two options:
    • Try installing ffp on Volume_2
    • Remove second disk and move first disk to right bay. Boot with only one disk and install ffp. Power off and re-add second disk to left bay. (Confirmed on a DNS-321. Works as described.)
  • FFP relies on the “ps” that is in /ffp/bin/ps. However, if you are a fan of Optware, you will likely want to install procps (which gives a “ps” much closer to the standard) and have your path with Optware first. If you do this, make sure to edit /ffp/etc/ffp.subr and put replace the call to “ps” with /ffp/bin/ps.

Lighttpd Web Server

Before starting lighttpd, you need to create a config file. To get started, just copy the example config and create the essential directories:

cd /ffp/etc
cp examples/lighttpd.conf .
cd /mnt/HD_a2
mkdir -p www/logs www/pages
sh /ffp/start/lighttpd.sh start

For detail regarding server security see http://forum.dsmg600.info/t793-Request-secure-setup-info-lighttpd.html

This will start the web server on port 8080. Copy your web files to the www/pages directory. Log files are written to www/logs.

PHP

To enable PHP, you need to install the php package and use the lighttpd.conf-with-php example config:

funpkg -i /path/to/php-xxxxx.tgz
cd /ffp/etc
cp examples/lighttpd.conf-with-php lighttpd.conf
sh /ffp/start/lighttpd.sh restart
Port 80

The example config files start lighttpd on port 8080, because the default HTTP port 80 is used by the administration interface (goahead web server). Using a little trick, you can move goahead to port 81 and run lighttpd on port 80: http://forum.dsmg600.info/t246-Change-http-port.html

To setup your lighttpd for port 80, disable the server.port directive in lighttpd.conf, and activate the kickwebs.sh and lighttpd.sh start scripts:

cd /ffp/etc
sed -i '/server.port/ s/^/#/' lighttpd.conf
cd /ffp/start
chmod a+x kickwebs.sh lighttpd.sh

After reboot, lighttpd should run on port 80. To manually activate the changes, run (in quick succession):

cd /ffp/start
sh kickwebs.sh start
sh lighttpd.sh restart

Note that the above will kill the goahead web server process. It will restart automatically, but this may take a few minutes.


OpenSSH Secure Shell Server

To start openssh, just run:

sh /ffp/start/sshd.sh start

On the first start, it will create the essential key files (may take a minute or two).

SSH sessions will start into the shell configured for the user in /etc/passwd. This defaults to the firmware's busybox shell /bin/sh (enter 5784468 to get a shell prompt).

As root, you can manually change the login shell for user bob:

chsh -s /ffp/bin/bash bob

If you receive

WARNING: Your password has expired. You must change your password now and login again!

messages on login, try if running 'pwconv' (as root) fixes it. See also: http://forum.dsmg600.info/p13142-2008-04-08-12%3A59%3A43.html#p13142

To make your changes permanent, you can store the updated passwd and shadow files to flash memory (TEST YOUR CHANGES BEFORE DOING THIS!!):

store-passwd.sh

To set sshd to run at startup: (TEST YOUR CHANGES BEFORE TURNING OFF telnetd):

chmod a+x /mnt/HD_a2/ffp/start/sshd.sh

To turn off telnetd: (TEST YOUR CHANGES BEFORE TURNING OFF telnetd):

chmod -x /mnt/HD_a2/ffp/start/telnetd.sh

Alternatively, you can store your modified passwd and shadow files in /ffp/etc/ and copy them to /etc on every startup. There's not start script included for this, yet.


NTP Network Time Protocol

Before starting ntpd, you need to create a config file. To get started, just copy and edit the example config:

cd /ffp/etc
cp examples/ntp.conf .
vi ntp.conf

Unless you live in Germany, you should change the four server entries. If in doubt, remove '.de' from each line:

server 0.pool.ntp.org iburst
...

See also: http://www.pool.ntp.org/use.html

On my DNS-323, the clock drift is too large for ntpd and needs additional changes. The start/adjtimex.sh script is included to fix clock drift by adjusting the ticks value.

cd /ffp/start
chmod a+x adjtimex.sh ntpd.sh
sh adjtimex.sh start
sh ntpd.sh start

Check synchronization status with

ntpq -p

ntpd will write a drift file /ffp/etc/ntp.drift (may take a few hours until it's written the first time). If it contains 500 or -500, your clock drift is still too large for ntpd.

WORD OF WARNING I've experienced several crashes using ntpd and have never succesfully had it running. Running v0.5


Mediatomb UPnP Media Server

The included mediatomb server will search media files in /mnt/HD_a2/home/media. If you have you files in a different location, edit /ffp/start/mediatomb.sh and change the media_dir variable.

Start mediatomb with:

sh /ffp/start/mediatomb.sh start

To make it automatically start after reboot:

cd /ffp/start
chmod a+x mediatomb.sh

The mediatomb configuration web interface starts on port 49152: http://bob:49152/ The mediatomb config.xml is in /ffp/var/mediatomb/


NFS Network File System

Two NFS servers are included:

  • UNFS3 is a user-space NFS server that does not require kernel support
  • NFS-utils contains required utilities to activate a kernel NFS server (Kernel-level NFS support is available on the CH3SNAS, and not on the DNS-323 unless you install your own kernel). More information can be found in the Linux NFS-HOWTO at http://nfs.sourceforge.net/nfs-howto/

To start unfs3, run:

sh /ffp/start/unfsd.sh start

To start the kernel-level NFS server:

sh /ffp/start/nfsd.sh start

On the first start, a default exports file is created in /ffp/etc (and a symlink in /etc).

Note that the exports file differs slightly between unfsd and nfsd. Before switching NFS servers, you should remove the exports file.


Uninstalling fun_plug

Versions 0.3/0.4

Help, Howtos, Guides, Discussions

There's a lot of useful information in the forum and in various blogs. If you find a good guide, please add it to the list.

Backup:

Bittorrent:

Cleanboot (Proper shutdown): cleanboot 1.0 for DNS-323 / CH3SNAS by pof

DynDNS: Utilities for D-link DNS-323 NAS

File System Checks: Modified fun_plug for disk maintenance by skydreamer

FUSE (File System in User Space): Fuse packages for fonz fun_plug by pof

Lighttpd (Web Server): Turning on authentication in lighttpd by shadowandy

Llink (Media Streamer): Compiled & working: llink, media streamer for Syabas based mp's by hps

MediaTomb (UPnP A/V Server) Compiled & working: Mediatomb! by HaydnH

Midnight commander MP (File Manager) Midnight commander by jules

MySQL: MySQL on DNS-323 by petter

Ncurses (Terminal library): http://www.bitmuse.com/funplug/

NFS (Network File System): Full instruction s on how to install NFS on my DNS-323 by moquilok

OpenVPN (Virtual Private Networks): Compiled & Working: OpenVPN by HaydnH

SSH:

Subversion:

timezone.sh: DNS-323 Time Sync with funplug-0.3 timezone.sh

UnRAR: unrar for the DNS-323

USB Storage: Attaching USB Storage to the DNS-323 for Linux Newbies & Dummies by DNS323-Talker

Other Sites


Navigation

Personal Tools