5 Feb 2009 • Comments
I know these howtos are all over the place but I wanted to keep one handy. We lost one of our dyndns domains today due to inactivity. So I setup this little script to help.
if [ -f ~/.dyndns/ipcheck.dat ]; then
/usr/sbin/ipcheck -r checkip.dyndns.org:8245 \
$USERNAME $PASSWORD $HOSTNAME
/usr/sbin/ipcheck --makedat -r checkip.dyndns.org:8245 \
$USERNAME $PASSWORD $HOSTNAME
Place that in a path hidden to your users (it stores a password in text) and then add a cron to run it every month (Dyndns will expire free accounts after 30 days).
30 Jan 2009 • Comments
Went looking for info on how to dynamically assign paths to uploaded content in a Django app. Found this post and tried it out. Either I have an issue with my attempt or that site is referencing old material.
In that post they claim that the upload_to callable will take 3 arguments. However in reality (or at least with my code, django 1.0+) it only takes two:
def get_path(instance, filename):
return settings.MEDIA_ROOT, 'something', \
That works however I found that you ended up having to do a little more work to sanitize the filename that Django would have done for you. I guess if you customize the path then you should know how to customize the filename. Just seems like it violates DRY a little in that I shouldn't have to mess with the filename if I don't need to (Django should sanitize it like normal unless I tell it not to). Just my opinion.
UPDATE: I had to get this working so I went back to it a couple weeks ago and realized that I could just use os to sanitize the filename. However I'm still sure there is a better way.
def get_path(instance, filename):
return os.path.join(settings.MEDIA_ROOT, 'something', \
14 Jan 2008 • Comments
Fake DFS is a small script that mimics DFS folder grouping without the hassle or overhead of running any kind of server. While the downside of this is that changes to the FS aren’t replicated in real time, you can adjust things (cron) or use it in conjunction with other programs to make things synchronize quickly.
What does that mean?
Let’s say you have 3 machines on your home network. Each has a 200 Gig drive. Say you created a folder structure on Machine A as follows:
Now inside /tv you create a folder called "The Office" and in there you create another folder called "Season 3". So you put episodes 1,2 and 3 of Season 3 into the folder but by the 4th episode have filled the capacity of the drive in Machine A (with Mp3s and movies let's say). However you still have 2 other machines with plenty of room on the drives. So now on Machine B you create an identical folder structure:
And you place episode 4 in the directory.
Now how are you going to see ALL of Season 4 as if they are in the same directory on the same drive?
So to use this script logon to the machine you are going to make the "master" server (IE where the FS’s will be merged). Mount the remote drives as CIFS/SAMBA or NFS. Create a "Master" directory, this is where you will see on single file structure for all of you drives. Then run the script with something like:
$ fdfs parent destination
Where parent is a the top part of the filesystem you want to be centralized and destination is the folder you created as the "Master" folder or a folder within.
Then run the command again for as many sub-structures as you wish to centralize. I create a small shell script that has all of my mappings in it so that re-syncing the FS is simple:
fdfs /media/Archive/TV/ /media/mythtv/TV/
fdfs /media/zxc/TV/ /media/mythtv/TV/
fdfs /media/Archive/Documentary/ /media/mythtv/Documentary/
fdfs /media/zxc/Documentary/ /media/mythtv/Documentary/
fdfs /media/Archive/Movies/ /media/mythtv/Movies/
fdfs /media/zxc/Movies/ /media/mythtv/Movies/
fdfs /media/zxc/Music/ /media/mythtv/Music/
Now you just run the shell script and it will "re-sync" the file system (IE if you change a file on one of the "child" filesystems).
fdfs - download
11 Jan 2008 • Comments
After installing Postfix in Ubuntu 7.10 with the help of this excellent howto (yes it looks very similar to mine, because mine is based on that one as well) I found that the maildirsize file wasn’t being created properly by Postfix. Unable to find the solution within Postfix I wrote this script. It basically builds a fake maildirsize file for all your users. If you have a really large server with many virtual accounts this may not be for you. However it works great for my needs.
First you will need to install the Mysql module for Perl. This can be done by running the following in a shell:
If you’ve never used the cpan shell before you will need to go through the setup. I can’t really help with that (mostly defaults but you are on your own).
Once you get to a prompt type the following:
cpan> force install Bundle::Mysql
That should force it in (it will die if it can’t connect as root to your DB).
Then you need to put the script somewhere, so download it and get it on your server:
mv maildirfix /usr/local/sbin/<br />chown +x /usr/local/sbin/maildirfix
Change the DB info:
and edit the lines as approprate:
my $DBN = "mail";<br />my $DBU = "DBUSER";<br />my $DBP = "DBPASSWORD";<br />my $DBH = "localhost";
Now add it to your crontab:
0 23 * * * /usr/local/sbin/maildirfix
This will run it one hour before the quota_notify script is triggered if you followed the howto.
10 Jan 2008 • Comments
I wrote this script to easily manage mail users on a
Courier/Postfix/mySQL setup. You can find a great how-to on setting up
a server with this configuration at http://nomad.ca/blog/2009/apr/3/virtual-users-and-domains-postfix-courier-and-mysq/ or http://www.howtoforge.com/virtual-users-and-domains-with-postfix-ubuntu-7.10
This script is FAR from perfect. I whipped it together to help a
client at the company I work for. It was only written with them in mind
but it should work for most average users.
THERE IS NO SECURITY!!! You need to provide your own. However .htaccess does the trick.
Fairly simple to setup and use. Unpack the tarball to a web
accessible folder (any you choose). Edit “includes/settings.inc.php”
and modify it so that it is appropriate to your db info. If you change
the “script name” setting don’t forget to rename admin.php to the same.
Then call up your site “http://localhost/admin.php” as an example.
You should be able to do any modifications to domains, users and
forwards. You will see any users etc that are already in the DB. This
script does NOT affect the db any differently than manual input to
mysql so you can use either and/or.
cpAdmin version 0.1