PHP – Writing An A to Z Loop

I was recently developing a PHP scraping script to extract the contents of a couple of websites and I wanted to find a quick way to run through a loop for each letter of the alphabet.  I figured since PHP was so versatile there had to be a quick and easy way, so I did a bit of thinking and came up with this:

for($alpha = 65; $alpha <= 90; $alpha++) {
      echo chr($alpha);
}

Simple!

Tags: , ,

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • Twitter
  • RSS
read comments

How to Configure a Static IP in Ubuntu 9.04

Start off by editing the file /etc/network/interfaces with your favourite text editor.  You will need to have root access to modify this file, so for example use the following command:

sudo pico /etc/networking/interfaces

Now tweak the file to your needs, this example sets the IP address to 192.168.1.123 on eth0.  I suggest running the command ifconfig beforehand and reviewing its output to determine which ethernet or wifi adapter you’ll be using (ie: eth0) and your network (ie: 192.168.1.x).

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interfaceauto loiface lo inet loopback
# This is a list of hotpluggable network interfaces.
# They will be activated automatically by the hotplug subsystem.mapping hotplug
script grep
map eth0

# The primary network interfaceauto eth0

# Enable for DHCP
#iface eth0 inet dhcp

# Enable for Static IP
iface eth0 inet static
address 192.168.1.123
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.1

Now restart your networking interfaces using the following command:

sudo /etc/init.d/networking restart

Tags: , , , , ,

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • Twitter
  • RSS
read comments

Installing Pure-FTPd on Ubuntu 8.04 Server

Until recently my choice for an FTP server had always been ProFTPd, however I found its difficulty to install made it a constant chore every time I had to set up a server.  So I sought out an alternative that was quick and easy to install yet did not sacrifice functionality or security.  The answer was Pure-FTPd.

I’m sure these instructions are very similar for most distributions, but I thought I’d specifically target Ubuntu 8.04 Server since that is what I am installing it on today. If you are using the desktop edition of Ubuntu or another distrobution that has a GUI you can most likely use that alternative.  Instead of apt-get commands you would simply fire up the Synaptic Package Manager and search for the install package.

I tend to jump right to the super user when I log in (bad habit, I know).  So if you’re not doing that you will have to prefix all commands with ’sudo’ or they might not work. Start off by installing the program and all of its required packages.

apt-get install pure-ftpd

When prompted, enter Y and hit enter.

Now, set up a new account using the ‘useradd’ command. You’ll also need to specify the home directory for the user by adding ‘-d /home/directoryname -m’ so when the user logs in they have a folder to upload/download files from.  You don’t have to use the /home dirctory for this but I always do to make things simple.  Here is the command I used.

useradd -d /home/username -m username
passwd username

Since I don’t want this user being able to cruise through the file system and see everything I’m going to lock the user to the home directory we just made. Open up /etc/passwd for editing. I use pico for this, you can use whatever program you like. Search for the user you just made (ctrl+w in pico) and add /./ to their home directory like this:

/home/username/./

Note that the line will be a lot messier than that, so just squeeze it in where appropriate.

Also, make sure to put in a shell at the end of that line… /bin/bash works fine. After all of that, add their username to /etc/ftpallow if you want to manually allow access to certain accounts.

Now just type pure-ftpd-control restart on the command line and you’re ready to test out your account!  Hop on another computer, or just SSH into another one and try from there.  If it doesn’t work its possible your install didn’t set up some of the proper configuration.  This happens automatically on Ubuntu 8.04 Server but on other distrobutions you may need to perform this next step.

Edit /etc/pam.d/pure-ftpd using your favourite editor to look like this:

auth sufficient pam_ftp.so
auth required pam_unix_auth.so shadow use_first_pass
auth required pam_listfile.so item=user sense=deny file=/etc/ftpusers onerr=succeed
auth required pam_listfile.so item=user sense=allow file=/etc/ftpallow onerr=fail
auth required pam_shells.so

Save the file, restart the server again and try it out again.  If you’re having troubles still I suggest seeking help from the Documentation.

Tags: , , , , , ,

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • Twitter
  • RSS
read comments
 Page 27 of 30  « First  ... « 25  26  27  28  29 » ...  Last »