Sep
21
2009
0

PHP array example

Hello all. It’s been a few weeks since I posted… I’ve been teaching myself PHP to create a web interface for a Asterisk based project I’m working on. My goal is to create a LAMP(Linux, Apache, MySQL, PHP) web managment tool for creating calling cards for use with Asterisk. The project is called ACCWA(pronounced aqua), the Asterisk Calling Card Web Administration tool. As I put this altogether I will keep my loyal readers updated about what I’ve learned about PHP.

Today I will cover Arrays. PHP handles arrays in manner similar to PERL. Each value can have an optional indice. In my example below, we simply have a list with no idiceses.

example:

<?php

$myarray[]=”hi” ;
$myarray[]=”how” ;
$myarray[]=”are” ;
$myarray[]=”you?” ;

// Now we will ‘echo’ each value in the array
foreach ($myarray as $i) {
echo “$i ” ; }

?>

output of myarray.php:

Above we did two simple task. First we defined a list of words in our array, then we echo’ed each one individually with the ‘foreach’ function. Very similar to BASH.  Your PHP page should display:

hi how are you?

Jun
20
2009
3

Fedora 11 detects and installs on-board Intel RAID driver correctly

Do you own a Mainboard that has built-in RAID, only offers Windows drivers?  have you always wanted to use the RAID BIOS for managing disks, but only had the Linux MD Soft RAID as option?  Not anymore!  I’m using a INTEL D945 GNT Desktop board with two 160 GB, Serial ATA drives.  I entered the BIOS menu and selected the RAID option.  After a reboot a RAID BIOS menu appeared and I was able to create a RAID 0 array.

Then I booted to Fedora 11 with a Live USB device.  From the Desktop I double clicked on the ‘install to hard drive’ icon.  I was really surprised to see a single 320 GB disk!  I did the install and it booted perfectly!

Now, some naysayers will complain, “It’s still Soft RAID anyways…”.  It’s a crappy point to make, obviously it’s still Soft RAID, but the main difference is the ability to create and manage RAID disks from the BIOS as opposed to using a Linux boot disk or the OS(if you can).  Most consumer grade RAID PCI cards use Soft RAID anyways.

Also lets consider, that in the past it was necessary to have a special RAID controller for performance gains.  But modern SATA boards have the PCI bus and the processing power to make those gains negligible(except compared to very pricey cards).  The real feature most of us want is the ability to access the RAID arrays from the BIOS boot screen.  Thank You Redhat, I’m already really liking fedora 11, I don’t need to throw away $150 on 3Ware SATA RAID cards anymore!  Please post your on-board Linux RAID success stories!

Oct
15
2008
0

Simple Bash script that copy’s a directory of files and renames them with a Time Stamp

NOTE: I myself am a novice with BASH. I hate scripting, but hey, it’s necessary part of most sysadmin jobs. I came across several hurdles (like changing a name and adding a time stamp in the same loop). I hope this document helps. Please click on my adds, they help pay for the hosting. Thanks and enjoy.

-Matt

—————————————————————–

In this scenario I have a customer that I did a custom Asterisk(Open Source PBX) installation for.  They want the capability to backup all voicemails for management to review.  So naturally I made a cron job that copied Asterisk voicemails to a web directory that was htaccess protected.   It seemed to work except I forgot that asterisk copies messages in the format ‘msg001.wav’.

The problem is that if a user erases the messages in his/her mailbox, then the next new incoming voicemail is named ‘msg001’ again. Next, the voicemail gets copied to the web directory and overwrites the original ‘msg001’.  So my challenge is to create a cron job, that copies the new messages and then renames them on the fly with a new name and an appended time stamp.

Every minute the script copies Asterisk voicemail accounts to another arbitrary directory.   Two loops are run on the contents of that directory matching the pattern ‘5???/mess*'(or in Asterisk syntax 5XXX/mess.).  In the case of my customer their VM boxes are all 5XXX(5001,5002,etc..).  The first loops adds a time stamp from when the voicemail was originally created.  The second loop strips ‘message??’ and replaces it with ‘voicemail_’. The result being something like: ‘voicemail_2008-09-15-03:14:09.wav’. I have to change the messages part because if I dont the first loop will add a second time stamp to previously stamped files.

At the end of the script we want to delete the message00?.txt file, because it is not relevent to simply downloading voicemail and may confuse some users. Also we have to change the owner/group to apache so the web server has permission to host the files.

The voicemail are protected with ‘.htaccess’ file, but with some additional work we could make user access based on PAM, LDAP, or MySQL.

Avaya sells voicemail auditing servers for $40,000 per server. But with the Open Source Asterisk PBX and a simple BASH script we can create a comparable system for under $1,000. However this script can be re-purposed for copying and renaming files for any task. Take care.

-Matt

script:

#!/bin/bash



#set -x



# Variable containing array
#==========================================================================



DIRECTORY1=”/var/spool/asterisk/voicemail/default/????”
DIRECTORY2=”/var/www/html/voicemail/”
AUDIT=”/var/www/html/voicemail/????/INBOX/msg*.wav”
MSGFILES=”/var/www/html/voicemail/????/INBOX/msg????.txt”



# copy files to web directory
cp -ruvp $DIRECTORY1 $DIRECTORY2



#rename those files with a time stamp
for i in $AUDIT ;



do mv $i $i$(date -r $i +%F-%T).wav ;



done



#——————————————————



#strip the ‘messages’ part of the name and replace w/ ‘voicemail’
for i in $AUDIT ;



do mv “$i” “${i/msg????.wav/voicemail_}” ;



done



# remove any msg????.txt files



rm -rf $MSGFILES



chown -R apache $DIRECTORY2
chgrp -R apache $DIRECTORY2

With Apache, Asterisk and this simple BASH script we have just created a web accessible way to check and back up voicemail!