Compiling glibc fails on Gentoo with gcc 4.1 must provide cpuid.h

Upgrading Gentoo is a bitch (see below). Follow these steps to get glibc to compile if you’re getting an error about gcc not providing cpuid.h:

# emerge -v gcc
# gcc-config -l (lists gcc profiles; select the newest gcc you see in the list)
# gcc-config 2 (where 2 is the number of the newest profile from above)
# source /etc/profile
# emerge -v glibc

The package glibc should now complile and install (emerge) without any further gcc related issues.

Tags: , , ,

Leave a Comment

Creating .tif images for Digium’s fax for asterisk

In order to really leverage Digium’s fax for asterisk and free fax for asterisk add-ons, one needs to be able to programatically convert a pdf file into a .tiff file that is compatible with ffa. After much searching, asking jeeves, dogpiling and altavistaing, I was able to dig up this ghostscript command that is able to make a ffa-compatible .tiff file out of a pdf from the command line:

# gs —q —dNOPAUSE —dBATCH —sDEVICE=tiffg4 —sPAPERSIZE=letter —sOutputFile=<DESTINATIONFILENAME.tif> <SOURCEPDF.pdf>

You may not even actually realize that your .tif is incompatible with ffa based on the debug offered by the add-on at the Asterisk console. The only error it throws is that it’s unable to queue the .tif file. Apparently this is asteriskese for ‘incompatible file type or resolution’. You can change the options above to create a different type of tiff or use:

# tiffinfo <TIFFNAME.tif>

to reverse engineer a .tif file that Asterisk generates internally using the ReceiveFax() dialplan command. Either way you should be able to get Asterisk faxing pretty quickly with ghostscript.

Tags: , , , , , ,

Comments (1)

Fixing the e2fsprogs com_err ss block on Gentoo

I can’t explain in standard written English how much I hate Gentoo. It is by far the lamest distribution of linux out there for a number of reasons, not the least of which is that attempting to upgrade has a tendency to break the whole system. This is the reason that I typically don’t update my Gentoo systems unless I have to; this can also be a problem because when you’re years behind on package updates more problems tend to crop up and compound each other.

In any event, the most recent problem I’ve seen is this (now old) block because com_err and ss were merged into the e2fsprogs/e2fsprogs-libs package on Gentoo. Emerge can’t handle the block and leaves the user to ‘take care of it manually’. Based on what I asked jeeves, this has caused many Gentoo users to break their systems. Here’s the process that worked for me (based on http://www.odi.ch/weblog/posting.php?posting=524):

# emerge –fetchonly world
# quickpkg e2fsprogs
com_err ss

# emerge -C ss com_err
# emerge -BO linux-headers
# emerge -K linux-headers
# emerge -BO util-linux
# emerge -K util-linux
# emerge -BO e2fsprogs e2fsprogs-libs
# emerge -K e2fsprogs e2fsprogs-libs

In order to upgrade anything else after that, I also had to re-emerge gcc (maybe I didn’t, but it worked when I did):

# emerge -v gcc
# gcc-config <profileid>

Tags: , , , , , ,

Leave a Comment

Server 2008R2 and Exchange 2010 Backup

Using server 2008R2 for Exchange 2010 has one great inherent benefit for small or cash-constrained shops: windows backup now has built-in support for exchange and VSS. This means that full backups of exchange 2010 can be performed without shelling out the cash for another backup product like Symantec Backup Exec.

If you run into ‘Checking Consistency of Application Exchange’ when you’re doing a backup, the rule of thumb is that this step will take 2x the amount of time it takes to read all of your log files. So if you have 20GB of log files being read at 150Mb/s, you need to calculate based on 40GB of data at that rate.

Leave a Comment

Hyper-V to VMWare ESXi 4 Conversion

There are *TONS* of blog entries out there with pretty specific steps about going FROM VMWare TO Hyper-V because Hyper-V is generating a lot of Hype (and that’s about it). Turns out that many people want to move back into VMWare after they become aware of the some of the shortcomings of Hyper-V. Proceeding is my internal-use guide to take a Hyper-V machine and convert it into a VMWare machine.

  1. Log in to the machine while it’s running under Hyper-V and remove VMWare additions. This *must* be completed while the VM is on a Hyper-V host because VM additions throws an error during removal if it isn’t. There must be some API between the HV guest and host that gets cranky otherwise.
  2. Shut down the VM
  3. Open the .vhd in winimage and select disk > convert. Specify the .vhd as the source file and the .vmdk as the destination file. I use dynamically expanding .vmdk files as the destination because they’re temporary anyway and a zeroed file will be quicker to duplicate.
  4. Copy the resultant .vmdk up to your ESXi host.
  5. Create a new VM on the ESXi host. Make sure that you select the correct operating system type or you could end up with 32 PCI-E bridges. Add the converted .vmdk to the new VM (leaving the SCSI disk that was created with the new VM intact).
  6. Power on the VM and boot windows.
  7. Install VMWare tools. Reboot.
  8. Open administrative tools > computer management > logical disk manager. Ensure that the unitialized SCSI disk can be seen. If it’s not there, go back to step 7 and install VMWare tools for real this time.
  9. Power down the VM.
  10. Load the ghost CD into the VM drive and boot from it.
  11. Ghost from the converted .vmdk into the SCSI .vmdk, then power down.
  12. Remove the converted .vmdk by editing the settings of the VM.
  13. That’s it! Boot your VM and enjoy!

Leave a Comment

Facebook-Style Elastic Textarea

I have been working on a lot of UI design lately. The other day I wanted a textbox that grows and shrinks as needed like Facebook.

Here’s what I came up with in jQuery:

$(’#workdescription’).keyup(function(e){
var key = (e.keyCode ? e.keyCode : e.which);
var ln = $(this).val().length;
var growAt = 47;

var normal = false; //a ‘normal’ key (a-z)
if((key > 106 && key < 113) || (key > 83 && key < 93) || (key > 60 && key < 71))
normal = true;

if(ln % growAt == 0 || normal == false){
ln = Math.floor(ln / growAt);
var h = 24;
if(ln != 0)
h += 20 * ln;
if($(this).css(’height’) == h + ‘px’)
return;
h = h + ‘px’;
$(this).animate({height: h}, 200,\”swing\”, function(){});
}
});

It worked pretty well, but lagged the browser a lot. Turns out someone beat me to the punch: http://www.unwrongest.com/projects/elastic/.

The plugin referenced at the link above is really pretty cool, and uses a hidden div to calculate height rather than the static-int sizes I was using. Check it out!

Leave a Comment

Ubuntu VPNC Magic MTU!

For several weeks I have been struggling on and off with VPNC and Ubuntu. I would attempt to start VPNC and receive the following error:

vpnc: receiving packet: Message too long

After googling countless strings, I finally found the answer here. Turns out that the MTU Comcast gives me on my linux router via DHCP is 576:

eth1      Link encap:Ethernet  HWaddr 00:1a:4d:25:c9:e2
inet addr:71.00.00.000  Bcast:255.255.255.255  Mask:255.255.248.0
UP BROADCAST RUNNING MULTICAST  MTU:576  Metric:1
RX packets:270273362 errors:0 dropped:0 overruns:0 frame:0
TX packets:69828544 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2837531408 (2.6 GiB)  TX bytes:1325116523 (1.2 GiB)
Interrupt:18 Base address:0xe000

Because my desktop’s MTU was set at 1500, the ipsec packets became fragmented and VPNC pooped its pants. Setting the MTU to 576 solved the problem INSTANTLY:

ifconfig eth1 mtu 576

I hope this helps someone else!

Leave a Comment

Cisco XML/SIP via Active Directory Auto Provisioning

Here are the scripts I use to automatically provision cisco phones via AD information. The phone number (extension)  is taken from AD’s ‘phone number’ field and the mac address comes from AD’s ‘IP Phone’ field.

As with the reboot script below, these scripts require PHP to be installed and compiled with LDAP and CLI on the asterisk server. It is possible (obviously) to perform these tasks remotely (not on the asterisk server) but that’s outside the scope of this post.

The PHP script reads the template files and does simple string replacement as needed. If the user is brand new, it adds their voicemail account, picks a psuedo-random extension password and tells asterisk what their email address is for the voicemail-to-email setup. The email information will only be in AD if you put it there or are running an exchange server in the same forest (as in the example).

It’s useful to note that all of the extensions I use in this example setup are in the format of 3xx. We then have another extension of the format 4xx set up to auto-answer so that we can do paging and intercom. You may need to modify if you have more than 100 extensions.

In order to add the extension, we read the config template in the directory listed and perform string replacement:

function add_extension($name,$extension,$secret,$email){
$template = file_get_contents(”/etc/asterisk/phones/conf.template”);
$template = str_replace(”<<<mainextension>>>”,$extension,$template);
$template = str_replace(”<<<email>>>”,$email,$template);
$template = str_replace(”<<<fullname>>>”,$name,$template);
$template = str_replace(”<<<secret>>>”,$secret,$template);
$template = str_replace(”<<<pageextension>>>”,”4″.substr($extension,1),$template);
file_put_contents(”/etc/asterisk/phones/”.$extension.”.conf”,$template);

}

The XML config file creation/modification follows the same format:

function provision_phone($name,$extension,$secret,$mac){
$template = file_get_contents(”/tftpboot/SEPCONF.template”);
$template = str_replace(”<<<mainextension>>>”,$extension,$template);
$template = str_replace(”<<<email>>>”,$email,$template);
$template = str_replace(”<<<fullname>>>”,$name,$template);
$template = str_replace(”<<<secret>>>”,$secret,$template);
$template = str_replace(”<<<pageextension>>>”,”4″.substr($extension,1),$template);
file_put_contents(”/tftpboot/SEP”.$mac.”.cnf.xml”,$template);
}

And finally we add the voicemail account:

function add_voicemail($name,$extension,$email){
$template = file_get_contents(”/etc/asterisk/voicemail.conf”);
$template .= “\n”.$extension.” => 1234,”.$name.”,”.$email;
file_put_contents(”/etc/asterisk/voicemail.conf”,$template);
}

These functions are really rather trivial but save a world of time when it comes to installing 75 new phones in one fell swoop — or even when you’re attempting to maintain continuity between installations separated lots of time.

I attached the the script to this post as well as some screen shots and config templates (SEPCONF and EXTENCONF) to facilitate setting up your AD objects to allow for automatic phone provisioning.

http://dave.vc/wordpress/wp-content/uploads/2008/11/phoneadd.zip

Leave a Comment

Remotely Reboot a Cisco 79xx Phone (without SIP NOTIFY)

After several days of emailing back and forth with Ciscos tech support, I got tired of waiting for an official way to restart Cisco 79xx phones. Then it hit me that I could do it using something I like to call EUI for emulated user interaction.

It’s pretty basic: I have a PHP script based on the push2phone function that was designed by Alex to remotely dial these phones. Since rebooting the phone is just a matter of pressing Settings -> **#**, all we have to do is tell the phone to dial these digits and it will reboot. (This script assumes that you already have the authorization script set up in SEP<MAC>.cnf.xml and that it is allowing the username and password at the top to reboot the phone.

First we need to be able to convert an extension to an IP address to make things user friendly. That shouldn’t be too hard with asterisk and ’sip show peers’:

$ips = array();
exec(”asterisk -r -x \”sip show peers\”",$ips);

$ip = false;
foreach($ips as $key => $data){
if(strpos($data,$exten.”/”.$exten) !== false){
$data = preg_split(”/[\s]+/”, $data);
$ip = $data[1];
$data = preg_split(”/[\/]+/”, $data[0]);
}
}
if(!$ip)
die(”Couldn’t find extension: “.$exten.”\n”);

This function actually does the dirty work of pushing commands out to the phone and is based on this: http://www.voip-info.org/wiki-Cisco+79XX+XML+Push

function push2phone($ip, $uri, $uid, $pwd){
$auth = base64_encode($uid.”:”.$pwd);
$xml  = “<CiscoIPPhoneExecute><ExecuteItem Priority=\”0\” URL=\”".$uri.”\”/></CiscoIPPhoneExecute>”;
echo $xml.”\n”;
$xml  = “XML=”.urlencode($xml);

$post  = “POST /CGI/Execute HTTP/1.0\r\n”;
$post .= “Host: $ip\r\n”;
$post .= “Authorization: Basic $auth\r\n”;
$post .= “Connection: close\r\n”;
$post .= “Content-Type: application/x-www-form-urlencoded\r\n”;
$post .= “Content-Length: “.strlen($xml).”\r\n\r\n”;

$fp = fsockopen ( $ip, 80, $errno, $errstr, 30);
if(!$fp){ echo “$errstr ($errno)<br>\n”; }
else
{
fputs($fp, $post.$xml);
flush();
while (!feof($fp))
{
$response .= fgets($fp, 128);
flush();
}
}
return $response;
}

Now all we have to do is create something to call this script with the correct URIs and wait until the phone has had time to respond in between our virtual button pushes. This is the bit of code that I use to set up the URI/wait sequences to reboot the phones. The first part of the second array is the key we want to press and the second is how long we should wait after pressing it. You can figure out the wait time by performing the EUI yourself:

$actions['reboot'][0] = array(0 => “Key:Settings”, 1 => “2″);
$actions['reboot'][1] = array(0 => “Key:KeyPadStar”, 1 => “.3″);
$actions['reboot'][2] = array(0 => “Key:KeyPadStar”, 1 => “.3″);
$actions['reboot'][3] = array(0 => “Key:KeyPadPound”, 1 => “.3″);
$actions['reboot'][4] = array(0 => “Key:KeyPadStar”, 1 => “.3″);
$actions['reboot'][5] = array(0 => “Key:KeyPadStar”, 1 => “.3″);

phonePush is attached. It needs to be run on the asterisk server with PHP installed and compiled with CLI. The syntax is like this: php phonePush.php reboot 363 (<action> <extension>).

Download the script here!

These pages were helpful to me:
http://www.cisco.com/en/US/docs/voice_ip_comm/cuipph/all_models/xsi/3_3_4/english/programming/guide/ip334ch3.html#wp1033107
http://search.cpan.org/src/MRPALMER/Cisco-IPPhone-0.05/IPPhone.pm

Leave a Comment

AD Password Expiration Email (LDAP/Exchange/AD/PHP)

Often users that telecommute or don’t use windows are blindsided by Active Directory password expirations. Given this, it seems a bit odd that AD doesn’t have functionality built in to email users when they are nearing expiration. Enter this script. The prerequisites are: a working AD setup with Exchange, a working server with php compiled with CLI and LDAP.

Here goes:

$ldap_host = “ldap://yourDCipaddress”;
$base_dn = “CN=Users,DC=yourcompanydomain,DC=com”;
$filter = “(CN=*)”;
$ldap_user = “CN=administrator,”.$base_dn;
$ldap_pass = “youradministratorpassword”;

As you can see, we are defining an LDAP host and CN filter (you can filter based on custom CNs, ie: one for linux users so they get this email). I wasn’t able to get this LDAP connection working with any account other than administrator. Anyone know how to enable LDAP access for normal users?

The only other function that may require some explaining is calculating the password age. Windows uses Jan 1,1601 as the base date for its time stamps. Unix uses Jan 1, 1970 thus requiring some conversion to make the two time stamps compatible.

$pwdlast = $data["pwdlastset"][0]/10000000;
$pwdlast = round($pwdlast,0);
$pwdlast -= 11644505700;
$numDays = (time()) - ($pwdlast + 10368000);
$numDays = $numDays/86400;
$numDays = round($numDays);

I believe that the rest of the code should be rather self explanatory. If you can’t follow for loops and sending emails in PHP, you have no business using this script :).

Download the script now!

Microsoft Date Conversion Resource

Leave a Comment