Author Archive

How to disable sleep or screen blank when closing laptop lids

Posted by on Saturday, 18 September, 2010

I have an awesome HDMI out on my laptop – works flawlessly on the TV. This is handy for watching movies and plugging into the big screen. problem is that I want to close the laptop lid, and that puts the laptop to sleep!
I’m using Gnome, so this tutorial is specific for that.

First of all, i went into System -> Preferences -> Power Management

This gives me the options of ‘sleep’, ‘shutdown’, or ‘blank’. This is great for the most part, but did not work when playing movies on an external screen with laptop lid. Also if i happened to just want to use an external screen plugged into the laptop for work things it wasnt going to work.
To fix this, i opened up console and typed in

gconf-editor

This brings up the power editor of gnome, sort of like windows registry edit.
I clicked on apps -> gnome-power-manager -> buttons
In here i found the one which was lid_ac – this means its the lid when the laptop is plugged into the AC. I right clicked on that, then clicked “Edit Key”. Changed the Value to be ‘nothing’ (the actual word nothing).
Bingo, this is now done. You can tweak other settings in here, when you click on them normally it has a description of what they do and what options work.
I would advise against deleting anything!


How to enable multi user in wordpress 3

Posted by on Wednesday, 23 June, 2010

Do your usual install on wordpress, and get it up and running. If you are not sure what that is, download the zip, upload the contents to your website, then point your browser at it to finish the configuration.
Once you have filled out your database information, and sorted themes etc you can then move onto the next step. Do not enable any plugins at this stage, some may be incompatible with multiuser!

Look for the file wp-config.php on your server, you need to edit it and add in one line to it.

define('WP_ALLOW_MULTISITE', true);

Once you have added it, refresh your dashboard and go to Network settings under Tools section. This will give you two Options
* Subdirectories as in http://yourdomain.com/someuser/
* Subdomains as in http://user.yourdomain.com

Most people will want to use subdomains, This will require a wildcard DNS entry however. That means just add an A record of * pointing to the IP of your server, then add in the apache config below before restarting.

ServerAlias *.yourdomain.com

Once you have done this you can go under the SuperUser menu and add a site in.

Some extra wordpress notes:
* make the plugins/themes folder writable by the web server. It needs to be owned by the same user not just chmod 777/666 for some reason on a lot/most systems. This is so it can read/write plugins etc without the FTP details. Using the FTP is a more secure option, however it can be painful and annoying to do.
* Not all plugins are compatible with multiuser
* Security can be a problem, one site gets compromised, all sites may be.


Virtual Hosting Hosting for the new sysadmin – Apache – Postfix

Posted by on Wednesday, 23 June, 2010

We have some users who own servers who dont want to fork out for automated systems like Plesk or Virtualmin, but don’t really want to deal with adding domains and email addresses all the time (and sometimes get lost)

I decided today after one such user emailed us to add another 3 domains and bunch of email addresses to write something simple to help him out, and thought I would share them with you.

I put the following in a plain text file in /root/adddomain.sh

#!/bin/bash
if [ ! $1 ];then
echo "Usage: $0 domainname.com"
exit 0
fi
 
echo Adding the virtualhost to apache
cat >/tmp/httpd.tmp < < EOF
 
<VirtualHost *:80>
DocumentRoot /var/www/CHANGEME/html
ServerName CHANGEME
ServerAlias www.CHANGEME
<directory "/var/www/CHANGEME">
allow from all
Options +Indexes
</directory>
 
 
EOF
cat /tmp/httpd.tmp | sed s/CHANGEME/$1/g >> /etc/httpd/conf/httpd.conf
 
echo Making the directory at /var/www/$1
mkdir -p /var/www/$1/html
 
echo reloading apache
/etc/init.d/httpd reload
 
echo Adding domain to mail
echo $1 /etc/postfix/virtual_domain # this was his postfix virtual domain name list

Then run

chmod +x adddomain.sh

Now I can add domains like this very easily

[root@hostname ~]# ./adddomain.sh
Usage: ./adddomain.sh domainname.com
[root@hostname ~]# ./adddomain.sh domain.co.nz
Adding the virtualhost to apache
Making the directory at /var/www/domain.co.nz
reloading apache
Reloading httpd:                                           [  OK  ]
Adding domain to mail
[root@hostname ~]#

Please note: do not add the ‘www’ part onto the domain name. That is done in the script itself where required.

Since he had set up virtual hosting in postfix, i then created another text file at /root/addmailuser.sh – this was so he could add email addresses easily and quickly. The contents were

#!/bin/bash
 
if [ ! $2 ]; then
echo "Usage: $0 [username|destination] emailaddress"
exit 0
fi
 
if [ -z $(echo $1 | grep @) ];then
echo Looks like a username to me, adding the user
adduser -s /sbin/nologin $1
passwd $1
else
echo Looks like a redirect off site, adding it as such
fi
 
echo Adding the email address
echo $2  $1 >> /etc/postfix/virtual
 
echo Running postmap
postmap /etc/postfix/virtual
 
echo Reloading postfix
/etc/init.d/postfix restart

Again i run the chmod on it

chmod +x addmailuser.sh

This is how I can use it

[root@hostname ~]# ./addmailuser.sh
Usage: ./addmailuser.sh [username|destination] emailaddress 
[root@hostname ~]# ./addmailuser.sh julie.domain julie@domain.co.nz
Looks like a username to me, adding the user
Changing password for user julie.domain.
New UNIX password:
BAD PASSWORD: it is too short
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
Adding the email address
Running postmap
Reloading postfix
Shutting down postfix:                                     [  OK  ]
Starting postfix:                                          [  OK  ]
[root@hostname ~]#

Or I can use it to create an off site alias

[root@hostname ~]# ./addmailuser.sh james.someguy@gmail.com james@domain.co.nz
Looks like a redirect offsite, adding it as such
Adding the email address
Running postmap
Reloading postfix
Shutting down postfix:                                     [  OK  ]
Starting postfix:                                          [  OK  ]
[root@hostname ~]#

These were designed/written for Centos/RedHat based systems, let me know if you want it for Debian/Ubuntu based ones. Also, strictly speaking, things don’t need to be restarted, but it doesn’t hurt and is a good way of testing things work ok.
There is no error checking in either of these scripts, feel free to contribute patches/fixes 🙂