Jquery: Running Events As You Leave a Page

June 29th, 2008

I recently attended “An Event Apart, Boston.” While there someone asked for my thoughts on a jquery problem which intrigued me. Mostly I was interested because I couldn’t come up with a solid solution in the 5 minutes or so we had left before the next session started.

The troubling spot for me was executing an animation on a link click before redirecting to the href of the link. I’ve seen the $("#content").animate({ opacity:1}, 100); trick to add delays within a queue, but for some reason that doesn’t work when applied to the document.

My proposed solution actually uses settimeout() which is what was suggested by the person asking the question. My question to the greater community is: Is there a better way to delay a call to document.location.href?

Here’s my proposed jquery page redirect delay solution.

Zipped for easy consumption

One note: I’m using jquery to move the content box off to the left and then bring it back in, so that people without javascript enabled will still see the content, but it seems to add an annoying flash of content sometimes. To avoid this, just remove the jquery line $("#content").css('left', '-3000%'); and add left: 3000%; to your css file.

Backing up linux, Mac, and Windows servers vi rsync

September 23rd, 2006

These scripts allows for remote incremental daily snapshot backups of linux, mac, and windows based servers.
The theory is that we want a full snapshot of any given day without taking up the full disk space required. The solution us to use rsync with hard links.
In addition I’ve made it backup to an encrypted disk image stored on a usb drive in OS X.
This makes it fairly portable and secure.
So far the only down-side is that the password for the encrypted drive must be stored in the script (or in another text file) as plain text. To avoid prying eyes the script has been chmod’ded 700, and is owned by root.

The setup:

  1. Create a public and private key pair and distribute the public to all linux servers to be backed up, and make sure sudo rsync can be run by the local backup user without requiring a password.
  2. Create an encrypted disk image using Disk Utility under Mac OS X. Ours is on a 250GB removable USB drive, but if you have access to a RAID drive with more space make it as large as you like.
  3. Our setup creates a daily snapshot and maintains the last 30 days, rotating out the oldest to save space, adjust to the availability of your space.

  4. Because rsync doesn’t run natively or easily on Windows I’m using XCOPY to backup windows servers to an intermediary Samba share on a linux box and then rsync’ing that. While not perfect, it does allow for hard-linking, and daily snapshots.

The script:
#!/bin/sh

# make sure we're running as root
if (( `id -u` != 0 )) ;
then { echo "Sorry, must be root. Exiting..."; exit; }
fi

# Tell the log file we're starting:
echo "==========================================="
echo "Backup Started: "
date

echo "Mounting the disk image"
echo -n 'DiskImagePassword' | hdiutil attach -stdinpass /Volumes/backup1/backupimagename.dmg

echo "Rotating the backups"
# Repeat for as many days as you would like to maintain your backup.
# If you choose to run your cron job only once a week, this would be
# the number of weekly backups
mv /Volumes/backupimagename/daily-30 /Volumes/backupimagename/daily-tmp
mv /Volumes/backupimagename/daily-29 /Volumes/backupimagename/daily-30
mv /Volumes/backupimagename/daily-28 /Volumes/backupimagename/daily-29
mv /Volumes/backupimagename/daily-27 /Volumes/backupimagename/daily-28
mv /Volumes/backupimagename/daily-26 /Volumes/backupimagename/daily-27
mv /Volumes/backupimagename/daily-25 /Volumes/backupimagename/daily-26
mv /Volumes/backupimagename/daily-24 /Volumes/backupimagename/daily-25
mv /Volumes/backupimagename/daily-23 /Volumes/backupimagename/daily-24
mv /Volumes/backupimagename/daily-22 /Volumes/backupimagename/daily-23
mv /Volumes/backupimagename/daily-21 /Volumes/backupimagename/daily-22
mv /Volumes/backupimagename/daily-20 /Volumes/backupimagename/daily-21
mv /Volumes/backupimagename/daily-19 /Volumes/backupimagename/daily-20
mv /Volumes/backupimagename/daily-18 /Volumes/backupimagename/daily-19
mv /Volumes/backupimagename/daily-17 /Volumes/backupimagename/daily-18
mv /Volumes/backupimagename/daily-16 /Volumes/backupimagename/daily-17
mv /Volumes/backupimagename/daily-15 /Volumes/backupimagename/daily-16
mv /Volumes/backupimagename/daily-14 /Volumes/backupimagename/daily-15
mv /Volumes/backupimagename/daily-13 /Volumes/backupimagename/daily-14
mv /Volumes/backupimagename/daily-12 /Volumes/backupimagename/daily-13
mv /Volumes/backupimagename/daily-11 /Volumes/backupimagename/daily-12
mv /Volumes/backupimagename/daily-10 /Volumes/backupimagename/daily-11
mv /Volumes/backupimagename/daily-9 /Volumes/backupimagename/daily-10
mv /Volumes/backupimagename/daily-8 /Volumes/backupimagename/daily-9
mv /Volumes/backupimagename/daily-7 /Volumes/backupimagename/daily-8
mv /Volumes/backupimagename/daily-6 /Volumes/backupimagename/daily-7
mv /Volumes/backupimagename/daily-5 /Volumes/backupimagename/daily-6
mv /Volumes/backupimagename/daily-4 /Volumes/backupimagename/daily-5
mv /Volumes/backupimagename/daily-3 /Volumes/backupimagename/daily-4
mv /Volumes/backupimagename/daily-2 /Volumes/backupimagename/daily-3
mv /Volumes/backupimagename/daily-1 /Volumes/backupimagename/daily-2
mv /Volumes/backupimagename/daily-0 /Volumes/backupimagename/daily-1
mkdir /Volumes/backupimagename/daily-0

echo "Backing up a Server"
# Repeat as necessary
# rsync uses RAM exponentially with the number of files you are backing up
# You may want to break this command up into multiple if you have a server with many files such as a mail server
rsync -az --delete --link-dest=/Volumes/backupimagename/daily-1/server.domain.com -e "ssh -i /path/to/private/key" backupuser@serverIP:/folder/to/backup /Volumes/backupimagename/daily-0/server.domain.com/

echo "Remote backup completed"
date
touch /Volumes/backupimagename/daily-0

echo "Deleting temp files"
rm -rf /Volumes/backupimagename/daily-tmp

# See how full the drive is
df -h

date

echo "Unmounting the disk image:"
hdiutil detach /Volumes/backupimagename

# Tell the log file we're done:
echo "Backup Finished: "
echo "==========================================="
echo " "
date

Backing up the Windows to a Samba share is relatively straight forward. For security purposes I created Samba shares that are only accessible to one user, the account that runs the script on the Windows servers.

Samba Share:
[global]
workgroup = yourdomain
security = user
wins support = yes
[WinBackups]
path = /var/winbackups
comment = Windows Backups
public = no
write list = administrator

The Window script:
echo off
:: variables
set drive="\\linux-box\sambashare\backupfolder"
set backup1="E:\FirstLocation"
set backup2="E:\SecondLocation"
set backupcmd=xcopy /s /c /d /e /h /i /r /k /y

echo ### Backing up First Location...
%backupcmd% %backup1% %drive%

echo ### Backing up Second Location...
%backupcmd% %backup2% %drive%

I’ve scheduled the xcopy script to run nightly well before the rsync script, with large sets of data you might have to run them on different days.

I’ve also scheduled the rsync backup script to run nightly and send me an email detailing what it wrote to the log.
MAILTO=" email@yourdomain.com"
30 22 * * * /private/var/root/backup-scripts/backup-daily.sh 2>&1 | tee -a /private/var/root/backup-scripts/logs/backup-daily.log | mail -s "Daily Backup" email@yourdomain.com

If you wish to make a backup of your backup, simply copy the entire disk image to another drive. Make sure the image isn’t mounted when you copy it.

Creating ssh keys:

This is based on this article.

create a key pair on your backup server machine.

This section should only be done once.

ssh-keygen -t rsa -f ~/rsync-key

This creates two files public and private keys.

place the private key into /etc/ssl/private/rsync.key and secure it.
mv rsync-key /etc/ssl/private/rsync.key
chown root:root /etc/ssl/private/rsync.key
chmod 600 /etc/ssl/private/rsync.key

The public key is the file that you place in the /home/(rsync_user)/.ssh/authorized_keys file on all your clients so that they know to allow you to use rsync as that user without a password. (Note that (rsync_user) should be replaced with the user you are using to connect with so a command that looks like this: rsync -avz -e “ssh -i /etc/ssl/private/rsync.key” user@server:/files/to/backup /backup/location, you would replace it with eanders.

Before you place it on your client machines you’ll want to tell it that it should only be valid if used from your backup server and that it is only valid for the rsync command. This is security for your client not your server. Having this public key means that anyone on a machine with the private key can connect and execute stuff on your machine without a password.

You should place the following at the beginning of the rsync-key.pub file:
from="ip.of.backup.server",command="/home/(rsync_user)/.rsync/validate-rsync.sh"
The file would then look something like this:
from="10.0.100.5",command="/home/(rsync_user)/.rsync/validate-rsync.sh" ssh-rsa AAAAB3NzaC1yc2...

Repeat the following section as needed:

In most circumstances you will only be backing up information that the user you connect as has permission to. In these cases you should copy the edited rsync-key.pub file to the users home directory and place it in the .ssh/authorized_keys file. If your user was eanders you would move the file to eanders’ home directory and do something like this:

mkdir /home/(rsync-user)/.ssh
cat rsync-key.pub >> .ssh/authorized_keys

This will place the key at the end of the authorized_keys file. It is now safe to delete the key.
Finally you’ll need to place the validate-rsync script in the /home/(rsync-user)/.rsync/ directory on your client computer so that you can allow rsync to be run without a password, but nothing else will work.
You can just create the .rsync directory and then paste the following into validate-rsync.sh within that file.
mkdir /home/(rsync-user)/.rsync
vi /home/(rsync-user)/.rsync/validate-rsync.sh

#!/bin/sh
case "$SSH_ORIGINAL_COMMAND" in
*\&*)
echo "Rejected"
;;
*\;*)
echo "Rejected"
;;
rsync*)
$SSH_ORIGINAL_COMMAND
;;
*)
echo "Rejected"
;;
esac

Then we tell it that the validate-rsync.sh file should be executable
chmod 755 /home/(rsync-user)/.rsync/validate-rsync.sh

At this point you should be able to run an rsync command from your backup server as root to backup anything that (rsync-user) has permission to backup. Something like:
rsync -avz -e "ssh -i /etc/ssl/private/rsync.key" (rsync-user)@client_ip_address:/files/to/backup /backup/location

If you want to backup a machine which contains files that are only readable by root you need to do the following

This will be the case where you have a file server that hosts files which are only readable by inidividual users (root always has access) but your administrator user can’t access their files without the use of sudo.

First you will create an unprivileged user on the client machine, we are using the username rsync:
adduser rsync
Give this user whatever password you want.

Then follow the instructions above replacing (rsync-user) with the user rsync.

Next you will need to login and gain root access to the server and we’ll move the rsync application and replace it with a script.
mv /usr/bin/rsync /usr/bin/rsync_real
vi /usr/bin/rsync

Fill the file with this script:

#!/bin/sh
/usr/bin/sudo /usr/bin/rsync_real "$@"

Then make it executable:

chmod 755 /usr/bin/rsync

This tells the computer that when you ask it to run rsync it should actually run it as root, so issuing:
rsync
will result in this command actually running:
sudo rsync_real

Finally you need to tell your client computer that the (rsync-user) should be able to run rsync_real as sudo without a password since we’ll be running it without an interactive shell. To do this run, as root:
visudo
and add the following line:
(rsync-user) ALL= NOPASSWD: /usr/bin/rsync_real

For our purposes we are making a single script that will run various rsync commands to backup servers across the wan, this script will reside in /var/usb1/backup-district.sh
In addition we will rsync /var/usb1 to /var/usb2 each night with an rsync command.

If you are having problems where it is continually asking for your password (even though you’ve done all the key stuff) make sure that the line you added to visudo is at the bottom. That file appears to be processed from the top down instead of going from broad to granular.
This is especially a problem when your user is also an administrator and already has an entry in visudo.

Allow users to reset their Active Directory passwords via a web form.

September 23rd, 2006

This is the functioning post that allowed us to be able to reset user’s Active Directory passwords via a php page hosted on a linux box. Combine this with the password resetting delegation of a previous post for a bit more security. We’re also going to set this up to figure out what group someone is in and let teachers reset thier students passwords.

Before you do this you need to generate an ssl certificate on the windows box and import it into the linux box, see a previous post.

This information was mostly gleaned from here:
———————————————————
The post: http://forums.devshed.com/ldap-programming-76/modifying-active-directory-passwords-through-php-and-iis-74683-7.html
———————————————————

Here is the final script I am using for a user to change his or her password.
The form to submit to the script:
<form method="post" action="change_password.php">
username: <input type="text" name="uid" />
<br />
password: <input type="password" name="password" />
<br />
new password: <input type="password" name="newpass1" />
<br />
confirm new password: <input type="password" name="newpass2" />
<br />
<input type="submit" name="submit" value="Change Password" />
</form>

Config File:
< ?PHP
/*** Variable Settings ***/
// administrative bind user
// Admin account with permission to reset passwords
$adminUID = 'adminusername';
$adminPass = 'AdministrativePassword';
// ldap server info, moved to config file
$ldapserver = 'ldapserver.mydomain.com';
$baseDN = 'DC=mydomain,DC=com';
?>

Script:
< ?PHP
require_once('/var/www_config_files/secure/change_password.inc.php');
/*** Variable Settings ***/
$uid = $_POST['uid']; // Should be something like jsmith
$userbindDN = $uid . '@yourdomain.com'; // jsmith@yourdomain.com
//existing password
$userbindPass = $_POST['password'];
// new password
$passwd1 = $_POST['newpass1'];
$passwd2 = $_POST['newpass2'];
// administrative bind user
// Admin account with permission to reset passwords
$authbindDN = $adminUID . '@yourdomain.com';
$authbindPass = $adminPass;

// ldap server info, moved to config file
//$ldapserver = 'ldapserver.yourdomain.com';
//$baseDN = 'DC=mydomain,DC=com';
/**************************/

/************* Main Script Code ***************/
/** Connect SSL to Ldap Server **/

$ldap = ldap_connect('ldaps://'.$ldapserver,686);
//$ldap = ldap_connect($ldapserver);
ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);

echo "Verifying old password ...<br>";

ldap_bind($ldap, $userbindDN, $userbindPass);

if (ldap_errno($ldap) !== 0)
{
exit('ERROR: Username or Password Invalid - Please Try again');
// exit('ERROR: User ID/Password Invalid - '.ldap_error($ldap));
}
/** We got this far, let's bind with an admin user **/
echo "Authenticated, changing password ...<br />";

ldap_bind($ldap, $authbindDN, $authbindPass);
if (ldap_errno($ldap) !== 0)
{
exit('ERROR: Unable to bind with admin user info - '.ldap_error
($ldap));
}

// Searching for the user
$filter = "(|(samaccountname=$uid))";
$justthese = array("cn");

$searchResults = ldap_search($ldap, $baseDN, $filter, $justthese);
// no matching records
$info = ldap_get_entries($ldap, $searchResults);
if ($searchResults === false)
{
exit('User ($uid) not found.');
}
if (!is_resource($searchResults))
{
exit('Error in search results.');
}

//echo "<pre>";
//print_r($info);
//echo "</pre>";

$entry = ldap_first_entry($ldap, $searchResults);
if (!is_resource($entry))
{
exit('Couldn\'t get entry');
}
$userDn = ldap_get_dn($ldap, $entry);

if ($passwd1 == $passwd2){
// prepare data
$newPassword = $passwd1;
$newPassword = "\"" . $newPassword . "\"";
$len = strlen($newPassword);
for($i = 0; $i < $len; $i++)
{
$newPassw .= "{$newPassword{$i}}\000";
}
$newPassword = $newPassw;
$userdata['unicodePwd'] = $newPassword;

// echo "Changing Password<br /><br />";
echo "Username = ".$uid."<br />";
// echo "User login ID = ".$userbindDN."<br />";

$result = ldap_mod_replace($ldap, $userDn , $userdata);
if($result)
{
// echo "User modified!<br />" ;
}else{
echo "There was a problem!<br />";
echo ldap_error($ldap)."<br />";
}
/** Now try to bind with the username and new password to
ensure change**/
echo "Now testing new password to insure change<br />";
ldap_bind($ldap, $userbindDN, $passwd1);
if (ldap_errno($ldap) !== 0)
{
exit('ERROR: User ID/Password Invalid - '.ldap_error($ldap));
}else{
echo "Password Verified.<br />Password change complete.<br />";
echo "<p>You may now close this window, your password for
your computer, email, and web access has been updated.</p>";
}
}
?>

In addition I have modified this script to allow teachers to reset student passwords:
The page that requests information:
<html>
<head>
<title>Reset Student Password</title>
</head>
<body>
<h2>Reset a Student Password</h2>
<p>Teachers may use this form to reset the password of a student in their class. Simply fill out all of the fields and click the "Reset Student Password" button.</p>
<form method="post" action="change_password.php">
Teacher Username: <input type="text" name="uid" />
<br />
Teacher Password: <input type="password" name="password" />
<br />
Student Username: <input type="text" name="student_uid" />
<br />
New Student Password: <input type="password" name="newpass1" />
<br />
Confirm Student Password: <input type="password" name="newpass2" />
<br />
<input type="submit" name="submit" value="Reset Student Password" />
</form>
</body>
</html>

Uses the same config file from above.

The script:
< ?PHP
require_once('/var/www_config_files/secure/change_password.inc.php');
/*** Variable Settings ***/
$uid = $_POST['uid']; // Should be something like jsmith
$student_uid = $_POST['student_uid'];
$userbindDN = $uid . '@yourdomain.com'; // jsmith@yourdomain.com
//existing password
$userbindPass = $_POST['password'];
// new password
$passwd1 = $_POST['newpass1'];
$passwd2 = $_POST['newpass2'];
// administrative bind user
// Admin account with permission to reset passwords
$authbindDN = $adminUID . '@yourdomain.com';
$authbindPass = $adminPass;
// ldap server info, moved to config file
//$ldapserver = 'ldapserver.yourdomain.com';
//$baseDN = 'DC=yourdomain,DC=com';
/**************************/
/*
The theory: Bind as the teacher to verify password and get group membership
Bind as the admin
Grab student dn and group membership
if the teacher is a member of teachers and the student is a member of students
check to see that they are both a member of another group (other than Domain Users)
If they are: reset the student password

*/
/************* Main Script Code ***************/
/** Connect SSL to LDAP Server **/
?>
<html>
<head>
<title>Reset Student Password Results</title>
</head>
<body>
< ?
//echo "Connecting SSL to server<br>";
$ldap = ldap_connect('ldaps://'.$ldapserver,686);
//$ldap = ldap_connect($ldapserver);
ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);
/** Now try to bind with the username and password **/
echo "Verifying teacher credentials ...<br />";
ldap_bind($ldap, $userbindDN, $userbindPass);
if (ldap_errno($ldap) !== 0)
{
exit('ERROR: User Teacher username or password invalid');
//exit('ERROR: User ID/Password Invalid - '.ldap_error($ldap));
}
echo "Teacher credentials verified. <br />";

/** We got this far, let's bind with an admin user **/
ldap_bind($ldap, $authbindDN, $authbindPass);
if (ldap_errno($ldap) !== 0)
{
exit('ERROR: Unable to bind with admin user info - '.ldap_error
($ldap));
}

// Figure out who the teacher is so we can get their membership info
$filter = "(&(samaccountname=".$uid."))";
$justthese = array("dn");

$searchResults = ldap_search($ldap, $baseDN, $filter, $justthese);
// no matching records
$info = ldap_get_entries($ldap, $searchResults);
if ($searchResults === false)
{
exit('User ($uid) not found in AD');
}
if (!is_resource($searchResults))
{
exit('Error in search results.');
}

//echo "<pre>";
//print_r($info);
for ($i=0; $i < $info["count"]; $i++) {
//print "LDAP DN: " . $info[$i]['dn'];
//echo "<br /><br />";
$userDN = $info[$i]['dn'];
}
//echo "</pre>";

$filter = "(&(samaccountname=".$student_uid."))";
$justthese = array("dn");

$searchResults = ldap_search($ldap, $baseDN, $filter, $justthese);
// no matching records
$info = ldap_get_entries($ldap, $searchResults);
if ($searchResults === false)
{
exit('User ($uid) not found in AD');
}
if (!is_resource($searchResults))
{
exit('Error in search results.');
}

for ($i=0; $i < $info["count"]; $i++) {
//print "LDAP DN: " . $info[$i]['dn'];
//echo "<br /><br />";
$student_userDN = $info[$i]['dn'];
}

// Searching for the teacher
$filter = "(&(objectCategory=group)(member=".$userDN."))";
$justthese = array("dn");

$searchResults = ldap_search($ldap, $baseDN, $filter, $justthese);
// no matching records
$info = ldap_get_entries($ldap, $searchResults);
if ($searchResults === false)
{
exit('User ($uid) not found in AD');
}
if (!is_resource($searchResults))
{
exit('Error in search results.');
}

//echo "<pre>";
for ($i=0; $i < $info["count"]; $i++) {
$teacher_groups[] = $info[$i]['dn'];
}
//print_r($teacher_groups);
//echo "</pre>";

// Searching for the student
$filter = "(&(objectCategory=group)(member=".$student_userDN."))";
$justthese = array("dn");

$searchResults = ldap_search($ldap, $baseDN, $filter, $justthese);
// no matching records
$info = ldap_get_entries($ldap, $searchResults);
if ($searchResults === false)
{
exit('User ($student_uid) not found in AD');
}
if (!is_resource($searchResults))
{
exit('Error in search results.');
}

//echo "</pre><pre>";
for ($i=0; $i < $info["count"]; $i++) {
$student_groups[] = $info[$i]['dn'];
}
//print_r($student_groups);
//echo "</pre>";

foreach ($teacher_groups as $teacher_group) {
$is_teacher = stristr($teacher_group, 'Teacher');
}
//echo "$is_teacher <br />";
if($is_teacher !== 'FALSE') {
echo "Verifying group membership...";
// In this case the teacher must be a member of the same group as the student
// This was added to allow fifth grade teachers to reset fifth grades student
// passwords, but not sixth grade student passwords.
foreach ($student_groups as $student_group) {
$same_group = array_search($student_group, $teacher_groups);
//echo $same_group;

}
if($same_group !== 'FALSE') {
echo "Group membership verified";
echo "<br />";
echo "Resetting student password...";

//---------------------------------------------//
// Check Passwords to make sure they match.
if ($passwd1 == $passwd2){
// prepare data
$newPassword = $passwd1;
$newPassword = "\"" . $newPassword . "\"";
$len = strlen($newPassword);
for($i = 0; $i < $len; $i++) {
$newPassw .= "{$newPassword{$i}}\000";
}
$newPassword = $newPassw;
$userdata['unicodePwd'] = $newPassword;

echo "for username = ".$student_uid."<br />";

$result = ldap_mod_replace($ldap, $student_userDN, $userdata);
if($result)
{
echo "User modified!<br />" ;
}else{
echo "There was a problem!<br />";
echo ldap_error($ldap)."<br />";
}
/** Now try to bind with the username and new password to
insure change**/
echo "Now testing new password to ensure change<br />";
ldap_bind($ldap, $student_userDN, $passwd1);
if (ldap_errno($ldap) !== 0)
{
exit('ERROR: User ID/Password Invalid - '.ldap_error($ldap));
}else{
echo "Password Verified.<br />Password change complete.<br />";
echo "<p>You may now close this window, the student password has been modified.</p><p>";
}
}

//--------------------------------------------------//

}
}
else {
echo "Sorry we could not verity that you are a teacher.";
}
?>
</p></pre></body>
</html>

Delegate Password Resetting Control in Active Directory

September 23rd, 2006

This allows you to have a user who can reset passwords for other users, but not necessarily administer the domain. We are using it so people can reset their passwords from a PHP page and so teachers will be able to reset their students’ passwords.
See:http://support.microsoft.com/default.aspx?scid=KB;en-us;296999

  1. Create a group that you want to be able to reset passwords
  2. Add the users you want to give the password resetting ability to to that group.
  3. Right Click on an OU that you want the resetters to be able to reset and choose “Delegate Control”
  4. Click Next and then add the Group you just created to the empty box.
  5. Click Next and then Check the Reset Password Box.
  6. Click Finish

Network Printers Assigned by Computer via a script run by a GPO

September 23rd, 2006

To assign a network printer via GPO you can either assign them to the user or to a computer. Scripting Printer installation for a user is fairly simple and straight forward.

  1. Create a script to map the appropriate printer:
    Option Explicit
    Dim objNetwork

    Set ObjNetwork=CreateObject("Wscript.Network")
    objNetwork.addWindowsPrinterConnection"\\serveripaddress\printername"
    Wscript.Quit

  2. In windows explorer copy the file. Open GPMC.
  3. Create a GPO for the appropriate user OU. Edit the settings and navigate to:
    User Configuration->Windows Settings->Scripts->Logon
  4. Add a script, just type the name of the file, not the path.
  5. Click the Show Files button and Paste your script into the Folder that opens.

If you login as a user within this OU you should now see the printer is available to you.

To assign a printer by computer, such as in a lab situation where anyone who logs in should have access to the printer follow the previous steps, but make the GPO on the OU that contains the computers. Note that you are making a GPO that targets users, but applying it to computers. To make this work you need to add one more setting to your GPO.

  1. Navigate to:
    Computer Configuration->Administrative Templates->System->Group Policy
  2. Set the value of “User Group Policy loopback processing mode” to Enabled and use the “Merge” option.

If you now login to a computer in the OU that you just applied the policy to you will have access to that printer, but if you move to a computer outside the OU it won’t be available to you.

The Group Policy Loopback processing mode of merge essentially means that policies should be applied to the computer at startup, the user at login, and then the user section of the computer policy afterward (still at login.)

Here is a relatively concise set of information on GPO loopback.

LTSP booting old mac hardware

May 18th, 2006

This will help you boot 333mhz and 350mhz imacs.
Some places to start:

https://wiki.edubuntu.org/EdubuntuDocumentation/LTSPCrossArchSetup
http://linuxcommand.org/man_pages/dhcpd8.html

The trick I’ve found is that the ltsp-build-client script doesn’t complete correctly unless you run it all locally. So, after you have completed the server section, move to the client. Instead of a live disk I strongly suggest installing edubuntu locally and getting it up-to-date with apt-get update && apt-get upgrade.
After running ltsp-build-client you need to move two folders from the client to the server.
You can
scp -r /var/lib/tftboot/* administrator@serverip:~/
and then move it (as root) to the /var/lib/tftpboot folder on the server)

Then I found that mounting /opt/ltsp from the server onto the client in a different location worked well for moving the files.

mkdir /opt/ltsp/server
sudo mount serverip:/opt/ltsp /opt/ltsp/server
cp -a /opt/ltsp/powerpc /opt/ltsp/server/

Finally to boot 333mhz machines it looks like you’ll have to run though the whole thing again, but on the older machine. Then it needs to netboot using bootp instead of dhcp so you have to add individual lines for each client in /etc/ltsp/dhcpd.conf that references the mac address of the machine.
Something like this:
host orange1 {
hardware ethernet 00:50:e4:b9:18:07;
fixed-address 192.168.0.201;
filename "/ltsp/yaboot";
option root-path "/opt/ltsp/powerpc";
}

Your entire dhcpd.conf file should look like this:

authoritative;

allow booting;
allow bootp;

subnet 192.168.0.0 netmask 255.255.255.0 {
range 192.168.0.20 192.168.0.200;
option broadcast-address 192.168.0.255;
option routers 192.168.0.1;
option subnet-mask 255.255.255.0;

}

option root-path "/opt/ltsp/powerpc_indigo";

if substring (option vendor-class-identifier, 0, 9) = "AAPLBSDPC" {
filename "/ltsp/yaboot";
option vendor-class-identifier "AAPLBSDPC";
option vendor-encapsulated-options
01:01:02:08:04:01:00:00:01:82:05:69:6d:61:63:34;
}
else {
filename "/ltsp/pxelinux.0";
}

host orange1 {
hardware ethernet 00:50:e4:b9:18:07;
fixed-address 192.168.0.201;
filename "/ltsp/yaboot";
option root-path "/opt/ltsp/powerpc";
}

Modifying a styleswitcher to make a language switcher.

March 26th, 2005

This is a modified version of Alistapart’s PHP styleswitcher. The idea was to take a site that is both in English and Spanish and allow someone to make a semi-permanent decision on which language they would like to use. This project came through a friend of mine, and with few details, so I figured I’d pick a method that could be easily changed if it didn’t fit his current setup.

Here is a rudimentary example if you want to see it in action. (After you’ve chosen your language just try going to the other page in the address bar!)

My idea was that the english pages would be named something like index_en.html and the spanish pages would be named index_es.html. This means that to switch from one to the other, all you need to do is swap out the bit at the end of the filename. (You could modify this so that it swapped out a directory name instead, and then you could have a /en/ directory and a /es/ directory in the path name and essentially maintain two different folder structurers.) Okay, enough hypotheticals. Here is how to do it.

The first page you need to build is a modified version of the alistapart styleswitcher. Place this code in a file called switcher.php:
< ?php
setcookie ('sitelang', $set, time()+31536000, '/', 'yourdomain.com', '0');
header("Location: $HTTP_REFERER");
?>

This simply takes an argument passed to it through the url bar and redirects the user back to the same page but with a cookie set that contains the information passed to it. (Don’t forget to change the domain name.)

Next you need to put the following snippets of code a the very top of each of your pages, one for the Spanish pages and one for the English pages:

< ?php
if ($sitelang == '_en') {
$location = $_SERVER["PHP_SELF"];
$goto = str_replace("_es", "_en", "$location");
header("Location: $goto");
die();
}
?>

The first one goes in the top of your Spanish pages, an simply checks to see if the cookie says you should be on an english page, if it does, it replaces the _es in the page you are currently on with _en and then redirects you to the English page.
< ?php
if ($sitelang == '_es') {
$location = $_SERVER["PHP_SELF"];
$goto = str_replace("_en", "_es", "$location");
header("Location: $goto");
die();
}
?>

The English version works exactly the same way, except that it replaces _en with _es.

Finally you need to have some way for your browsers to choose their preferred language. In this case I chose to pass the argument through the URL, but you could create a form on your page that had a submit button and some radio buttons to make your choice. The following two links should be present somewhere on every page.
Oprima aquí para español!
<br />
Click here for English!

The first line lets you choose Spanish as your language and the second lets you choose English.
Sorry if my Spanish is a little out of practice. . .
Post a comment if you find this useful.

Update 3-28-05

After a little more discussion about the specifics of what my friend wanted, we came to the conclusion that while this works really well, it wasn’t quite what he was looking for.

The site he was looking to use this is actually 3 sites, where the first is a splash site for the other two.
So, the final decision was made to have the splash site allow a user to choose their language and to choose if that language is permanent or not. Were still working out the specifics, but here’s a way to set the language and forward people to the correct url based on their decision.

The index page for the splash site would contain the following code:
< ?PHP
if ($sitelang == '_es') {
header("Location: http://www.thespanishsite.org");
die();
}
if ($sitelang == '_en') {
header("Location: http://www. thesenglishsite.org");
die();
}
?>

Then within the body you need a form:
<form action="switcher.php" method="post" name="radio">
<label for="set">Español</label>
<input name="set" id="set" type="radio" value="_es" checked="checked" />
<br />
<label for="set">English</label>
<input name="set" id="set" type="radio" value="_en" />
<br />
<label for="length">Remember this setting</label><input name="length" id="length" type="checkbox" value="year" />
<br />
<input type="submit" value="Set Language"/>
</form>

Then the switcher needs to be changed so that it knows about temporary and long term cookies:
< ?php
if ($length == 'year') {
setcookie ('sitelang', $set, time()+31536000, '/', 'yoursplashdomain.com', '0');
}
else {
// this cookie just needs to survive long enough to get the user to the right place
// one time.
setcookie ('sitelang', $set, time()+60, '/', 'yoursplashdomain.com', '0');
}
header("Location: $HTTP_REFERER");
?>

That should do it.
You can try out a demo here.

Safari Double-dip, slow dns, and page load failure final fix

February 22nd, 2005

This issue seems to have cropped up in Panther (10.3.5 or 10.3.6) Macworld covered it in their September 2004 issue, but their fix didn’t seem to help me. It’s been posted on numerous bulletin boards and people seem to be of the impression that 10.3.6 fixed the problem for them.

The Codepoet found that turning off IPv6 worked for himself. This had no effect for me. It seems that the general consensus is either that the new handling of IPv6 records by DNS servers or slow ping times to DNS servers was to blame for this new bug.

The Mac Fix it article above eluded to my final solution. If the problem had to do with other people’s DNS servers, why not run one locally. I went into /etc/hostconfig and changed the DNSSERVER line to read: DNSSERVER=-YES- (open with sudo). Problem fixed. This seems to have worked on both my G5 and my girlfriend’s iBook. Finally for good measure I added 0 0 1 * * root /usr/bin/curl ftp://ftp.rs.internic.net/domain/named.root > /var/named/named.ca to /etc/crontab so that the root server list will get updated once a month. Thanks to the O’rielly Mac Dev Center for a bit of a BIND Tutorial.

If anyone knows a reason why it might be bad to run BIND on a laptop I’d love to hear it. That was my only hesitation.

My latest million dollar idea

January 30th, 2005

These ideas come to me at the oddest times, thoughts about how to make the world just a little better, or more often, how to make a piece of technology a bit more fun. My latest one happened when I was at MASS MoCA with a few friends. We were in a dark room where there was a video playing of a car full of fireworks exploding super-imposed over Times Square. At the end of the video it faded to black before repeating. But the room was still lit by the LCD projectors that couldn’t quite do “black.”

My million dollar idea would make LCD projectors go all the way black. It seems like a simple task, yet hasn’t been done to my knowledge.

If anyone manages to use this theory, I’d appreciate some credit, or royalties, though I know that by putting this out on my public blog, for all 2 readers to read, I’m essentially giving my idea away.

Here it goes.

Take an idea like those sunglasses that get darker when you walk outside and lighter when you go inside. As far as I know those are just a photo sensitive skin placed on the lens. If there were a way to tell those glasses to go totally dark immediately or totally light immediately you have just created an electronic shutter. All you need is some material that when electrically activated (or deactivated) goes completely opaque. Then you simply have to test the incoming signal to the projector and see if it is supposed to turn on any of its pixels. If the answer is no, then you activate the shutter. If a single pixel is supposed to be on, then you deactivate it. The benefit over a real shutter is simply that it shouldn’t increase the internal heat inside the projector where a physical barrier would.

Alright, time for bed for me, I’ll see if this still looks good in the morning.

Rediscovering JavaScript

January 30th, 2005

It’s been a long time since I played around with JavaScript. I was pretty much under the impression it was dead and basically made editing pages more difficult. When I would go back and try and update pages that I had written long ago with a smattering of script in the header, and some strewn throughout to make things happen, I basically found that it was just too much work for the benefit it provided. With CSS I could accomplish 90% of what I used to do with JavaScript and it was much easier to read and maintain.

I think I’m a born again JavaScript fiend. After recently discovering the great site Unobtrusive Javascript, I’m once again sold. This site makes it easy to separate the script from the CSS from the HTML, and all work harmoniously together.

After playing around with their method of separating CSS and JS from the HTML I was finally able to elegantly solve an issue I’ve been wanting a solution to for years. I love how gmail does the whole stack of cards thing with your email. But more than that I love how they show and hide parts of the page arbitrarily. When you are reading a message there is a nice little reply box down at the bottom that when you put your cursor in to write a reply gets bigger, but doesn’t refresh the page so you can continue to type. And when you want to look back through some old messages all you do is click on the stack of cards and viola there you go, your old messages are right there.

My dilemma was more simplistic. I need to make a large form that I wanted to display on a single page, but not force people to scroll down through the whole thing, and I didn’t want people to have to click through sections of it because I want people to go right where they need to go without having to navigate a menu if they don’t want to. And I wanted to allow people to check over the entire form before submitting it, so they could fill in the whole thing at once if they wanted to, or could submit just parts, and through the wonders of MYSQL they could come back later and finish up.

The solution I had in mind was to show the headings for the sections of the form, and then allow people to click on the header to expand or collapse the section of the form. In addition I wanted a way to expand and collapse the whole form so that if you wanted to jump around from one section to another you could with minimal scrolling.

JavaScript to the rescue.

Using the basic function provided by the fine folks over at Unobtrusive Javascript I was able to make a page where all h2 tags turn into buttons that expand and contract their sibling divs. Then after some trial and error as I got my mind wrapped around what they were doing, I was able to take h3 tags and make them expand and contract all of the divs that immediately proceed h2 tags. The beauty is that all the CSS and all of the JavaScript are in their own files, no body tag onload() functions, no extra classes or id’s even. When CSS is needed for a specific application it is called and generated by the javascript, and the javacript file itself tells the HTML page to load it when the window loads, so all you have to change in your HTML is to include a single line telling it where to find the JavaScript file.

Alright, enough talk here are the three files: (note this is part of a php file so the values for the form fields are self populating with php code, get rid of it if you don’t want this.)

First the HTML File:

<html>
<head>
</head>
<body>
<h3>Collapse All Sections</h3>
<form action="processupdates.php" method="post">
<h2>Personal Inforamtion</h2>
<div>
<label for="FirstName">First Name: </label>
<input type="text" id="FirstName" name="FirstName" value="First" size="30" maxlength="60" tabindex="1"/>
<label for="LastName">Last Name: </label>
<input type="text" id="LastName" name="LastName" value="last" size="30" maxlength="60" tabindex="2"/>
</div>
<h2>Other Inforamtion</h2>
<div>
<label for="FirstName">First Name: </label>
<input type="text" id="FirstName" name="FirstName" value="<? echo $line["FirstName"]; ?/>" size="30" maxlength="60" tabindex="1">
<label for="LastName">Last Name: </label>
<input type="text" id="LastName" name="LastName" value="<? echo $line["LastName"]; ?/>" size="30" maxlength="60" tabindex="2">
</div>
<h2>More Inforamtion</h2>
<div>
<label for="FirstName">First Name: </label>
<input type="text" id="FirstName" name="FirstName" value="<? echo $line["FirstName"]; ?/>" size="30" maxlength="60" tabindex="1">
<label for="LastName">Last Name: </label>
<input type="text" id="LastName" name="LastName" value="<? echo $line["LastName"]; ?/>" size="30" maxlength="60" tabindex="2">
</div>
<br />
<input type="submit" id="Save Application" value="submit"/>
</form>
<h3>Collapse All Sections</h3>
</body>
</html>

Next the CSS:

body{
background:#f8f8f8;
color:#333;
font-family:Arial, Helvetica, sans-serif;
}
h2{
font-size:110%;
font-weight:normal;
width: 40em;
}
h3{
font-size:110%;
font-weight:normal;
width: 40em;
}
.hidden{
display:none;
}
.shown{
display:block;
}
.trigger{
background:#ccf;
cursor:n-resize;
}
.open{
background:#66f;
cursor:s-resize;
}
.hover{
background:#99c;
}

Finally the JavaScript:

function collapse()
{
//Collapses and expands siblings of h2 tags in html file
if(!document.createTextNode){return;}
var heads=document.getElementsByTagName('h2');
for(var i=0;i<heads .length;i++)
{
//Figure out what should be opened and closed.
var tohide=heads[i].nextSibling;
while(tohide.nodeType!=1)
{
tohide=tohide.nextSibling;
}
//open all parts that should be open, and set their parents to be ready to close them
cssjs('add',tohide,'shown')
cssjs('add',heads[i],'trigger')
heads[i].tohide=tohide;
//Make them act more like links so the user gets a response
heads[i].onmouseover=function()
{
cssjs('add',this,'hover');
}
heads[i].onmouseout=function()
{
cssjs('remove',this,'hover');
}
heads[i].onclick=function()
{
if(cssjs('check',this.tohide,'hidden'))
{
cssjs('swap',this,'trigger','open');
cssjs('swap',this.tohide,'hidden','shown');
} else {
cssjs('swap',this,'open','trigger');
cssjs('swap',this.tohide,'shown','hidden');
}
}
}
var mainhead=document.getElementsByTagName('h3');
for(var i=0;i<mainhead.length;i++)
{
//run through and make h3's into close and open all links
cssjs('add',mainhead[i],'trigger');
this.innerHTML = 'Collapse all Sections';
mainhead[i].onmouseover=function()
{
cssjs('add',this,'hover');
}
mainhead[i].onmouseout=function()
{
cssjs('remove',this,'hover');
}
mainhead[i].onclick=function()
{
heads=document.getElementsByTagName('h2');
if(cssjs('check',this,'trigger'))
//This runs through and opens all sections cleaning up the h2's so that they are ready to close again
{
for(var j=0;j<heads.length;j++)
{
if(cssjs('check',heads[j],'trigger'))
{
cssjs('swap',heads[j],'trigger','open');
cssjs('swap',heads[j].tohide,'hidden','shown');
}
}
for(var l=0;l<mainhead.length;l++)
{
//Makes sure that all h3s are ready to close the sections
mainhead[l].innerHTML = 'Expand all Sections';
cssjs('swap',mainhead[l],'trigger','open');
}
} else {
//This runs through and closes all sections cleaning up the h2's so that they are ready to open again
for(var k=0;k<heads.length;k++)
{
if(cssjs('check',heads[k],'open'))
{
cssjs('swap',heads[k],'open','trigger');
cssjs('swap',heads[k].tohide,'shown','hidden');
}
}
for(var m=0;m<mainhead.length;m++)
{
//Makes sure that all h3s are ready to re-open the sections
cssjs('swap',mainhead[m],'open','trigger');
mainhead[m].innerHTML = 'Collapse all Sections';
}
}
}
}
}
function cssjs(a,o,c1,c2)
{
//Applies action a to object o by adding, removing, swapping, or checking for classes c1 or c2.
switch (a){
case 'swap':
o.className=!cssjs('check',o,c1)?o.className.replace(c2,c1):o.className.replace(c1,c2);
break;
case 'add':
if(!cssjs('check',o,c1)){o.className+=o.className?' '+c1:c1;}
break;
case 'remove':
var rep=o.className.match(' '+c1)?' '+c1:c1;
o.className=o.className.replace(rep,'');
break;
case 'check':
return new RegExp('b'+c1+'b').test(o.className)
break;
}
}
//make it all happen when the page loads
window.onload=collapse;

Geektool

November 22nd, 2004

Since finding geektool (for the second time) a few weeks ago, I’ve come to really love this little app. It sits nicely in the background constantly gathering information, in a very matrix-esk way, quietly displaying it on the desktop. I just wrote my first “from scratch” script after being unable to find an equivalent online anywhere.

Here’s the script:
curl http://slashdot.org/index.rss | grep <title | sed -e ’s/<title>Slashdot</title>//g’ | sed -e ’s/<title>Search Slashdot</title>//g’ | sed -e ’s/<title>//g’ | sed -e ’s/</title>//g’

If you haven’t guessed it from the liberal use of ’slashdot’ in the script, it simply pulls the rss feed from slashdot and puts the titles of the current slashdot articles on your desktop, one per line.

Be careful, slashdot has a policy I didn’t know about “You may only load headlines every 30 minutes.” So set your refresh time above 1800 seconds. You have been warned, you will be banned if you don’t follow this rule.

Maybe not the most useful script, but it’s always nice to know you haven’t missed a post. In addition I found the best weather info I could get was from nws.noaa.gov, give them a look.

Movable Type is dead, long live Word Press

November 21st, 2004

Somewhat on the spur of the moment I decided to switch from to WordPress for the blog portion of this site. The switchover was all but seamless.

I’m sure no one really wants to hear the details, but what started as a Sunday morning project quickly became a Sunday project. The initial transfer to WP was actually quite simple and painless, it was the CSS that had me tinkering. I probably should have just done a quick re-work of the site and come out with a simple new design, but I wanted to see how hard it would be. In the end things look roughly the same and some parts look better in my opinion.

The main draw to WP for me was the simplicity of the configuration and ease of use of the admin section. It took me hours to get the archival format right for MT, but I had that done within the first 5 minutes of the install today. I also felt a need to switch shortly after MT decided to start charging for their previously free software. That kind of change irks me.

Well my Mental Train just derailed, so I guess . . . stay tuned for some pictures or notes about my upcoming project building one of these.

Migrating PHP

November 3rd, 2004

I think the server switch over is just about complete, I have a few parts of my gallery to upload yet. While most things have been working for a while the little stylsheet switcher was failing because the new server has a different version of PHP installed and old variables weren’t working. Took me a while to figure out why Safari was refusing to go to a null address. I was under the impression it was supposed to be re-directed back to where it was. Seems $HTTP_REFERER isn’t good enough any more, you need $_SERVER[’HTTP_REFERER’]. In addition on my old server I could simply use the variable name of an item passed through the url so somepage.php?variable=true, could be referred to as $variable. No longer. Now it has to be gotten with $_GET[’variable’]. I guess that is a good thing because you really might not want your variables to have values when you think they are empty, but for crying out loud, that took me way too long to figure out.

Everyday is a learning experience. . . . election day being one of the biggest.

Switching Servers

October 27th, 2004

Just a quick not to all million of my visitors, I’m in the process of switching servers so there will be some down time of parts of this site. From now on it will be mainly the gallery and the older stuff that is not available.
Thanks for your patience.

More Backing up via VBScript

October 14th, 2004

A few days late, and perhaps not in it’s most efficient form (well not perhaps . . .) Here is the script that copies a directory from one place to another. Slight enhancements enable it to keep the previous two backups and to keep a relatively well formed log detailing start and finish. Enjoy!

I use it to copy my ‘My Documents’ folder to a networked drive. I make no guarantees that it will work for you, in fact, I can almost guarantee that it will often fail, since it does so on a relatively regular basis for me, most likely because my wireless connection which it uses to do the copying is a bit spotty on service at times.

‘A quick script by Elliot Anders to backup a folder to another drive.
‘This script will keep 2 copies of the backed up folder.
‘It deletes the old copy, renames the more recent copy as the old one and copies
‘the current source folder to become the new backup.

‘”'’Configure the folders here:
sourceFolder = “C:\Documents and Settings\USERNAME\My Documents”
previousBackup = “K:\Previous My Documents”
currentBackup = “K:\Current My Documents”

logFile = “K:\backupTheStore.log” ‘This should probably be located on
the drive with the backups but not in the backup folder

‘”'’Do not make changes below this line”””’

Dim FSO, logFileStream, tempFileStream
Dim strSrcDir
Set logFSO = CreateObject(”Scripting.FileSystemObject”)
Set tempFSO = CreateObject(”Scripting.FileSystemObject”)
Set backupFSO = CreateObject(”Scripting.FileSystemObject”)

‘”'’Make a log file if this is the first time

if logFSO.FileExists(logFile) = false Then
       logFSO.CreateTextFile logFile, True
       Set initialize = logFSO.openTextFile(logFile, 2)
       firstText = “Log Created at ” & Now
       initialize.writeLine firstText
       initialize.close
End If

‘”'’Tell the log that we are starting

beginningText = “Backup of ” & sourceFolder & ” began at: ” & Now

‘”’Error here
tmp = “C:\temp\tmp.txt”
if tempFSO.FileExists(tmp) = false Then
       tempFSO.CreateTextFile tmp, True
End if

Set tempFileStream = tempFSO.OpenTextFile( tmp, 2)
tempFileStream.WriteLine beginningText
tempFileStream.close

Dim tmp, logFile
‘Create FileSystemObject
Set appendFSO = CreateObject(”Scripting.FileSystemObject”)
‘Open file for appending, don’t create
Set ftop = appendFSO.OpenTextFile( tmp, 8, false)
‘Open for reading
Set fbot = appendFSO.OpenTextFile( logFile, 1, true)
‘Append the contents of second file to first
ftop.Write fbot.ReadAll
fbot.close
ftop.close
appendFSO.DeleteFile(logFile)
appendFSO.CopyFile tmp, logFile

‘”'’Delete the old backup

If backupFSO.FolderExists(previousBackup) Then
       backupFSO.DeleteFolder previousBackup, true
End If

‘”'’Move the new to be the new old

If backupFSO.FolderExists(currentBackup) Then
       backupFSO.MoveFolder currentBackup, previousBackup
       Set f = backupFSO.CreateFolder(currentBackup)

End If

‘”'’Copy the source folder to the backup location

backupFSO.CopyFolder sourceFolder, currentBackup

‘”'’Tell the log we are done

endText = “Backup of ” & sourceFolder & ” was Successfully Completed at: ” & Now
Set tempFileStream = tempFSO.OpenTextFile( tmp, 2)
tempFileStream.WriteLine endText
tempFileStream.close

‘Open file for appending, don’t create
Set ftop = appendFSO.OpenTextFile( tmp, 8, false)
‘Open for reading
Set fbot = appendFSO.OpenTextFile( logFile, 1, true)
‘Append the contents of second file to first
ftop.Write fbot.ReadAll
fbot.close
ftop.close
appendFSO.DeleteFile(logFile)
appendFSO.MoveFile tmp, logFile

Windows Script Host VBscripting

October 1st, 2004

Before I begin, if anyone is interested, I start my new part-time job today working at an elementary school for The Mohawk Regional School District.

Lately I’ve been diving deeper into the world of Windows, I generally stick to my comfortable, stable, and virus free OS X, but once in a while (much more than before since my new job will be 99% windows work) I delve into the inner workings of a Windows machine. Lately it has been Windows Script Host, or WSH.

I’ve been working on a project that never seems to go away. Not that I didn’t finish the project, but it involves backing up a computer. Something I should do way more diligently and often. So the basic idea here was that the computer was usually backed up every evening onto a CD. Only 200 MB of data needed to be saved at any given time, but that’s some 313 CD’s a year (no Sunday backup.) And really only the past day or two needed t be saved. So along I come, and thinking there must be an equivalent to AppleScript for PC, I thought this would be an easy job. To tell the truth, copying the data wasn’t really that hard, writing the log got messy.

Network issues aside (this was a wireless connection to get the data out of the building) the basic concept was to use Windows Explorer and Scheduled Tasks to move the data to another machine each morning at 2:00 AM. After dinking around for a while with the Backup Utility I decided to go with WSH as it would give me a usable backup. With the backup utility everything is placed in one archive file and can’t be used unless it is restored.

WSH can mount a file server, but I thought it might be nicer to pass this job off to XP, so I mapped a drive and had it re-connect at login (Windows calls it Logon?) Then I simply copied the contents of the folder to be backed up over to this new drive. Voila! It worked, sort-of . . . as long as the network was up. So back to fixing the network. . . And then, the great idea that took 2 or 3 times as long to implement. A log file. To cut to the chase, I wanted the log file written in reverse chronological order so the newest information would be at the top. This requires more work than it should. It seems to me Perl can do this in it’s sleep (correct me if I’m wrong.) Any way, after lots of grammar errors and a temp file I got it all working, and wish to share the fruits of my labor with all of you. Except you’ll have to wait, because I left the final version of the other computer and haven’t backed it up yet. Ooops.

One final comment, then hopefully later today I’ll post that script, though I better preface it with this note:

Use the script at your own risk, the code is not pretty . . . yet, but I’ll work on it eventually (or not.) It works for me, if it erases all of your files, they are gone.

Oh yeah, it keeps two backups of whatever directory you send it, so that if it stops in the middle of a backup you still have the previous.

So now onto my current Beef with Windows file sharing. . . .
Can someone explain to me why I can connect to an XP share with OS X without a password . . . OR USERNAME?!!!??! Hello security risk! With XP to XP it behaves okay, though both machines have the same user account so I guess I don’t really know if it is using a password scheme. But with my Mac I’m in like Flynn! I just don’t get it, commmon Redmond, lets get this thing locked down tight.

Okay, enough already, and this should be long enough to push my previous post so that it doesn’t run into my navigation. If anyone knows a quick and dirty fix for removing Safari’s cache permanently (that doesn’t involve installing an application, I’d love to hear it, because last I checked that wasn’t sticking out the right side of the middle section.

Centered 2 Column Design

September 24th, 2004

After successfully finding a centered 2 column design and hacking it to pieces before installing it on my own site, I had some trouble with forms, IE 5.2 Mac, and the two column layout. I thought I would share my experience with all of you here.
I’ll pretty much cut to the chase, but I wanted to point out that for some reasonALA’s form did not work for me. There were a variety of others that I found that also didn’t work, I can’t say why because I really don’t know. I think it had something to do with my wanting the form on the left side of a 2 column layout.
So the final solution was this:

<div id="allcontent">
<h4> Interested in Pixel Conductor's services? </h4> <h5> Send him a note below. </h5>
<div id="leftcontent">
<div id="form">
<form method="post" action="http://www.pixelconductor.com/cgi-bin/cgiemail/cgiemail/station.txt">
<div>
<label for="name">Name:</label><input type="text" name="name" id="name" />
</div>
<div>
<label for="email">E-mail:</label><input type="text" name="email-required" id="email" />
</div>
<div>
<label for="text">Request:</label>
<textarea name="request" id="text" cols="20" rows="8">
</textarea>
</div>
<div>
<input type="submit" value="Send Your Message" class="formbutton" />
</div>
<div class="spacer">
</div>
</form>
</div>
</div>
<div id="rightcontent">
<img src="/images/ticketstub.jpg" alt="Ticket Stub" />
</div>
</div>

(Thanks to BBedit for the code converison.)

Nothing special here, just three main divs, one that holds everything and one for each side. The CSS here:
div#form {
width: 320px;
padding: 0;
margin: 1em;
margin-top: 0;
border: 1px solid #AF9101;
text-align: right;
}

label, input, textarea {
display: block;
width: 180px;
float: left;
margin-bottom: 10px;
}

label {
text-align: right;
width: 100px;
padding-right: 10px;
}

input.formbutton {
margin-left: 110px;
width: 80px;
width: auto;
text-align: center;
padding-right: 2em;
}

This bit of code comes mostly from a form on html dog. It seems that getting the textarea and associated label to line up correctly was the most difficult part, (which actually doesn’t happen on the html dog site, but does on the ALA site) IE Mac does not like placing a label to the left of a text box. Ah well, so bask in it’s functionality and let me know if you have any better solutions.

Managing DNS Servers

September 18th, 2004

I never cease learning. Today I woke up worrying about a site I just moved to a new server. For some reason the DNS hadn’t propagated overnight. In my experience this usually takes a couple hours at most. After dinking around for a couple of minutes wondering if it was ever going to change, a light bulb went off in my head. Why not use the new DNS server as my DNS server, then I would be sure to get the moved site as opposed to the old site.

The additional benefit of this thought cloud is raining down on me harder than the deluge outside. This is AMAZING! This means that whenever I move a site I can move it to the new server, tell that host that the site is going to be moved so they update their DNS servers, and then before I ever actually switch over, I can plug in their DNS server into my Network Control Panel and see and work on the new site as it will appear until I’m satisfied and then I can make the official switch later.

Have a great weekend everyone.

pixelconductor.com

September 16th, 2004

At long last I have found enough free time between working on livesuperfoods (selling health food online soon) and my various other projects to put together a site advetising my coding skills and my freedom to work for others.

I am actually quite happy with the result and pleased with myself for getting it together so quickly. It was a battle with CSS once again to get the placement of everything correct, and I still haven’t figured out how to do two columns of div’s centered on the page, but that will come soon. Thanks to glish for their reservoir of good coding for some hints to get me pointed in the right direction.

Only one more thing on my agenda and that is to wait for my new PC to come in the mail. I finally broke down, mostly because of the various bugs in IE Win CSS and bought a bran-spanking-new 2.4 GHz machine so that I can hack my standards compliant coding into pieces that actually work in that environment. Ah well, you can’t win everything I guess. If anyone is looking for a standards compliant hand coder for websites let me know.

Comments

August 29th, 2004

I have returned. It’s been over 2 months since my last post, and I’m still short on time. Farm camp was amazing, the goats are my favorite, not to mention fresh goat cheese.
Imagine my surprise when I returned and found that my comments had been generally filled up. People were actually reading my site! That is something I had never expected.
As you can probably guess only one of the comments was actually real. Sad but true. I had been spammed, I’m not even really sure what you would call it, but it seems that others think it is okay to advertise their questionable practices on my site. I’m not sure what they think they are going to get out of posting multiple identical links in a row that congratulate me on the coolness of my site in exactly the same language, but then are posted by “great teens” or some name to that effect. So for now commenting will be turned off, at least until I update my blacklist.
If you are a regular reader, or irregular, thanks for dropping in. Don’t expect a new post in the too near future as I still have a bunch of work to do on my new digs that takes priority over my blogging.