Monday, July 11, 2011

Our (Brief) Foray into a Brother HL-2280DW All In One Laser Printer

Update at bottom (7/12/2011)
The Bad:
Can't scan multiple pages in to a single document
Wireless is not so easy to configure (I'm in IT).
Drivers won't be automatically detected (It's 2011 guys)

The Good:
It prints quickly
It scans (one page) quickly, with decent image quality.


Review:

We have been printing and scanning quite a bit so decided we would get an AIO.  We wanted a laser printer as an ink toner cartridge that lasts 500 pages won't go far with 30-40 page documents.  That said we spent quite a bit of time looking around and we found the Brother HL-2280 Printer was a small and inexpensive device which takes a Brother TN-450 toner cartridge that provides a decent cost per page.  My girlfriend went to Staples to play with and purchase the said printer and the cashier, the clerk informed her that the starter toner in the printer would only print 20 (twenty) pages before running out, and therefore she should purchase a new toner to go with it; he offered to sell her a TN-420.  Really?  Lying Thieves, thankfully she wasn't suckered in by this gimmick.  For reference, the printer comes with a TN-420 toner cartridge which according to staples.com prints 1,200 pages.  I can only assume that the pimply geek with huge gauge holes in his ears was flat out lying in order to get her to purchase a toner cartridge and improve his sales attach rate.  Also, the two year warranty is only 29.99.  Thanks, we'll pass. I hope it dies before two years is up so it can fill a dumpster somewhere.

Step 1) Plug in, configure wifi (Fail #1)
With the printer at home I plug it in, and turn it on.  Open the menu, go to wifi and use the wifi protected setup menu, which i've admittedly never used.  I choose the option where it gives me a code that i type in to the router, and then the devices pair.  60 seconds later my belkin router says device connected successfully, and the printer spits out a page saying failed.  I tried a couple variations of this and eventually gave up.  Ultimately I connected to the printer via an ethernet cable, connected to the web interface with the default username of admin and the default password of password and managed to configure the wireless from there.

Step 2) Connect to computer (Fail #2)
I used the add a printer wizard in Windows 7 and to my delight it was quickly detected.  Except the printer driver wasn't found.  I went to the brother website and download the printer driver, installed it via computer management and I'm off to the races!

Step 3) Print a document (The only successful step)
It prints. Oh, and it can print on both sides / duplex perfectly.

Step 4) Scan a document (Fail #3) (Update below)
I press the scan button expecting the scan to email function similar to other brother AIO's I've used.  It says check connection.  This device can only perform the scanning functions through the brother software.  No problem I say! I download the 130MB software, install it (reboot required... ugh it's 2011), and scan a document.  All of the defaults scan to JPG, including scan to email or file.  I change it to default to PDF and go to scan my document.  As it turns out, this brother All In One HL-2280DW IS NOT CAPABLE of scanning multiple pages in to a single document.  Say you want to scan and email a 2 page document, you will need to scan it in to two separate files and email them separately.  The scanner we had some 12 or 15 years ago was capable of this simple functionality.  Press scan, it scans the document, asks you if there are any more pages, and either scans the next page or finishes with the file.

Step 5) Return for full refund.
Reason stated on return claim: defective.




My Backstory:
I have installed and used multiple brother all in one laser devices and figured I'd give them a shot since at the budget end their cost per page is far lower than the competing HP model (1.7c/page vs 5c/page).  I have no previous hatred of brother until this new device was purchased (and about to become returned).




UPDATE: 
It turns out it is possible to scan multiple pages. The preferences menu doesn't show the option, but if you right click on the email or file button for example, and go to settings you get almost the exact same menu you find under preferences, but it has a checkbox for manual scan. It does work. The downside is you must return to your computer to press the next page button, and the software on the computer effectively does a new scan job and stitches the two together. This is clearly a piece of equipment meant for scanning one page things, and the software isn't well designed (why does the checkbox only show up on right click -> settings, instead of the main preferences tab you get?

Thursday, July 7, 2011

Embedding a User Editable Google Maps and Street View Control in a Website

We recently added a feature allowing our users to show the Google Street View of their property on our website and there wasn't a lot of documentation about how to do it.  Ideally we wanted to be able to display the street view of a real estate listing so prospective buyers could get a better feel for the property and the surrounding area, and it seemed like a solveable problem.

The final solution ended up looking like this:

In order to accomplish this we needed to do several things.  First, we already know the address of the property that is being entered because as a real estate listing site that is something users enter with their listing info.  Therefore we simply need to use the google maps and google street view API to display the map and street view version to our users so they can confirm the location and angle of the view.  Once they have done this we store the POV information and the location of the property (in case the google approximation is incorrect) in our database to ensure we display the correct info.

Step 1) Display the approximate location for the street view and map controls and allow the user to adjust the view to their liking

[code]
var map1;
var panoramaOptions;
var myPano;
var point;
var point1;
var marker1;

/*********************************************************/
//Use the validate form code to set hidden textboxes to the values
//from the streetview Pano, so when the form gets submitted the
//values get passed to the server to be saved
/*********************************************************/
function validateForm(){
this.document.getElementById('pitch').value = myPano.getPov().pitch;
this.document.getElementById('heading').value = myPano.getPov().heading;
this.document.getElementById('svzoom').value = myPano.getPov().zoom;
this.document.getElementById('sv_latitude').value = myPano.getPosition().lat();
this.document.getElementById('sv_longitude').value = myPano.getPosition().lng();
this.document.getElementById('latitude').value = map.getPosition().lat();
this.document.getElementById('longitude').value = map.getPosition().lng();
return true;
}

function load() {
//set the point for the panoramic
//at this point we don't know the POV info so we set them all
//to 0, the user will have to adjust the POV and we will save
//that information
point = new google.maps.LatLng(66.6666, 66.6666);
panoramaOptions =
{
position:point,
pov: {
heading: 0,
pitch:0,
zoom:0
}
};
/*********************************************************/
//use a div with elementid pano to display the streetview panorama
/*********************************************************/
myPano = new google.maps.StreetViewPanorama(document.getElementById("pano"), panoramaOptions);
myPano.setVisible(true);


var sv = new google.maps.StreetViewService();
var availability_cb = function(data, status) {
/*********************************************************/
//if the streetview service can't display teh location (due to lack of data)
//then we use a bunch of hidden fields to display an error message
//apologizing for the inability to use streetview
/*********************************************************/
if (status !== 'OK')
{
document.getElementById('sv_enabled').checked = true;
document.getElementById('pano').style.display='none';
document.getElementById('pano').style.visibility='hidden';
document.getElementById('panotext').style.display='none';
document.getElementById('panotext').style.visibility='hidden';
document.getElementById('panoerror').style.display='';
document.getElementById('panoerror').style.visibility='';
}
/*********************************************************/
//show the panoramic
/*********************************************************/
else
{
myPano.setVisible(true);
}
}

sv.getPanoramaByLocation(myPano.getPosition(),50,availability_cb);

/*********************************************************/
//this code displays the normal streetview map and allows
//the user to drag the pushpin to set the proper location
//in the event the google provided position isn't quite accurate
//this map gets put in a div with the id map
/*********************************************************/
map1 = new google.maps.Map(document.getElementById("map"),
{
center: new google.maps.LatLng(66.6666, 66.6666),
zoom: 15,
mapTypeId: 'roadmap'
});

point1 = new google.maps.LatLng(
parseFloat(66.6666),
parseFloat(66.6666));

marker1 = new google.maps.Marker({
map: map1,
position: point1,
draggable: true
});
}


[/code]
All of the preceding code creates the following layout in the website:


Step 2) We store the information from the streetview and normal map in our database, that way when we display the listing to users they get the previously-set location.

Step 3) We display the street view control and the normal roadmap view on our site.
[code]
var map1;
var panoramaOptions;
var myPano;
var point;


function load() {
/*********************************************************/
//Set up the street view position
/*********************************************************/
point = new google.maps.LatLng(66.6666, 66.6666);
panoramaOptions =
{
position:point,
pov: {
heading: 61.4137, //This is the custom POV that was set
pitch:9.02999, //by the user
zoom:0
}
};

/*********************************************************/
//use the same divs as before, pano for streetview and map
//for the roadmap.
/*********************************************************/
myPano = new google.maps.StreetViewPanorama(document.getElementById("pano"), panoramaOptions);
myPano.setVisible(true);




/*********************************************************/
//set up the roadmap
/*********************************************************/
map1 = new google.maps.Map(document.getElementById("map"), {
center: new google.maps.LatLng(66.6666, 66.6666),
zoom: 15,
mapTypeId: 'roadmap'
});
var point1 = new google.maps.LatLng(
parseFloat(66.6666),
parseFloat(66.6666));

var marker1 = new google.maps.Marker({
map: map1,
position: point1
});

}

[/code]

Wrap Up
And once again this creates the final picture:
I've left out some things like storing the POV info in my database as well as how to convert an address in to a Lat/Lng via the google maps API so you'll have to read the API's to figure out how to do that.  This should help you a bit with the street view functionality :)
If you'd like to see it in action this code is what currently drives the street view and property map functionality of all the Commercial Real Estate Listings at www.cimls.com 

Wednesday, June 29, 2011

Asterisk Directory Application Crash With Asterisk Realtime in 1.6.2

I recently discovered that asterisk-addons-1.6.2.3 has a bug in res_config_mysql that causes asterisk to segfault if you send a user to the Directory() app while using realtime asterisk for voicemail.  This bug is fixed in the asterisk-addons branch of 1.6.2 so be sure to use the latest res_config_mysql.c if you are using asterisk-addons-1.6.2.3.  The SVN is available here: http://svn.digium.com/svn/asterisk-addons/branches/1.6.2/

I spent a fair amount of time tracing down this crash before attempting to use the latest version out of SVN and discovered that this crash had been patched about a month ago.  I guess the moral of the story is to always test the latest code out of SVN if you are experiencing segfaults.  Not just the latest release, but test against the latest code in SVN as well, it could save you a lot of time debugging.

Asterisk 1.6.2.18, 1.6.2.18.1, 1.6.2.18.2 Crash With Microsoft Exchange Unified Messaging

We use Unified Messaging to provide mailboxes to our users in Asterisk along with the added features UM provides over the built in Voicemail app, and we recently upgraded from 1.6.2.11 to 1.6.2.18 and found a new bug.  The bug was introduced in 1.6.2.18, and is fixed in the asterisk 1.6.2 branch in SVN as of 6/29/2011.  The 1.6.2.19-rc1 tag has the fix included as well, so be sure to use that if you are planning to use Exchange Unified Messaging with Asterisk.


Example:

    -- Called 1593@Exchange2010LCYEX2
Segmentation fault (core dumped)

I didn't bother to do much investigation considering the fix is included in 1.6.2.19-rc1.

Wednesday, May 25, 2011

Dynamically Restrict Access to Asterisk SIP 5060 using iptables

We have an asterisk deployment where we have users who work from home so their phones need to be able to connect to asterisk remotely.  In order to limit the number of security threats to our system we lock it down by using the permit and deny settings of SIP Peers to make sure that only those users can get in.

In order to do this for external users we originally allowed every IP to connect, simply relying on using very strong random passwords (40+ character random passwords, unique per extension), and fail2ban to block repeated attempts.  This has been working for us for the last year and a half but I decided to take our security one step further and lock it down to the exact IP of the phone.

We use Aastra 6731i and 6757i devices which have the ability to grab a URL when they boot up, the startup event.  In the aastra.cfg you would have this line:
action uri startup: http://asteriskpbx/aastraphone.php?action=register&ext=$$SIPUSERNAME$$

This tells the phone to grab aastraphone.php at startup.  We use this to keep track of phones, so I decided I would use it to add an addtional layer of IP security to our system.

First, you need to have access to iptables from your web server (or you can pass commands another way, this is a quick and dirty method).

Install & Configure Sudo
apt-get install sudo
add the following lines to /etc/sudoers
#give access to iptables
Cmnd_Alias IPT=/sbin/iptables

#give access to iptables to the account apache is running under, for me www-data
# User privilege specification
www-data ALL=NOPASSWD: IPT

Build aastraphone.php
This will insert an allow rule for the given IP at the top of the input chain.  It will not be removed automatically, so you should probably use some mechanism for going through and cleaning up these entries.  A quick and dirty method would be to put the allow rules in a chain and then flush the chain nightly.  The next time the phone polls the web page it would then be re-authorized for access.  Not a great solution, but for 9-5 shops it would work great at midnight.  A more elegant solution would be to track them in a database and check the database every once in a while for IP's that need to be removed.  


Additionally, the realtime version of this is able to check and see if an IP is supposed to be allowed to connect in from the outside world, this solution does not do that it assumes that if the phone knows how to get to the aastraphone.php file that it is allowed to connect externally.  Because of this it is important to have configured the permit and deny options in sip.conf to prevent peers from being used externally if they shouldn't.

aastraphone.php:
$ext = $_REQUEST['ext'];
if($ext > 0 && is_numeric($ext)){
system("sudo /sbin/iptables -I INPUT 1 -s {$_SERVER['REMOTE_ADDR']} -p udp --dport 5060 -j ACCEPT");
}


Configure IPTables Default Rules
Your system will need to be configured to allow internal hosts to connect, and reject external hosts to connect to your SIP port by default.  Using the following commands should handle this for you.  Using the related/established rule is important so that your communication with your SIP providers stays fully functional.
#by default block all access from the outside work to your asterisk system
iptables -A INPUT -s 0.0.0.0/0.0.0.0 -d 0.0.0.0/0.0.0.0 -m state --state INVALID -j DROP
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -I INPUT -p udp --dport 5060 -s 192.168.0.0/16 -j ACCEPT #allow all 192.168.x.x hosts to connect
iptables -I INPUT -p udp --dport 5060 -j DROP #block all others that don't match a rule.  Alternatively you could use the default policy for input drop.
iptables -I INPUT -p tcp --dport 80 -j ACCEPT #allow web traffic for the aastraphone.php file to function


Notes
This solution assumes you leave the web server open to the world, as the phones will need to be able to get to that to gain access to SIP/5060.  

Tuesday, May 24, 2011

Dynamically Restrict Access to Realtime Asterisk SIP Peer by IP

We have an asterisk deployment where we have users who work from home so their phones need to be able to connect to asterisk remotely.  In order to limit the number of security threats to our system we lock it down by using the permit and deny settings of SIP Peers to make sure that only those users can get in.

In order to do this for external users we originally allowed every IP to connect, simply relying on using very strong random passwords (40+ character random passwords, unique per extension).  This has been working for us for the last year and a half but I decided to take our security one step further and lock it down to the exact IP of the phone.

We use Aastra 6731i and 6757i devices which have the ability to grab a URL when they boot up, the startup event.  In the aastra.cfg you would have this line:
action uri startup: http://asteriskpbx/aastraphone.php?action=register&ext=$$SIPUSERNAME$$

This tells the phone to grab aastraphone.php at startup.  We use this to keep track of phones, so I decided I would use it to add an addtional layer of IP security to our system.

First, I had to add a new column to my Realtime Asterisk sippeers table called externalaccess, which I will only set to true for devices that are allowed to connect to asterisk from the outside world.
mysql> ALTER TABLE  `sippeers` ADD  `externalaccess` BOOL NOT NULL ;

Second, I added the following code to aastraphone.php:


$ext = $_REQUEST['ext'];
if($ext > 0 && is_numeric($ext)){
$query="update sippeers set deny = '0.0.0.0/0.0.0.0', permit = '{$_SERVER['REMOTE_ADDR']}/255.255.255.255' where name = '$ext' and externalaccess = true";
mysql_query($query);
}


Finally, I tested it out by setting externalaccess to 0, booting the phone and verifying that the phone's ip did NOT get updated, which it did not.  Then i set it to 1, and rebooted the phone and it was succesful in updating the realtime peer.  This instantly allows the phone to register, and because the page load happens quickly enough the phone has no problem registering right away. 

Please note that this does still have vulnerabilities, it is not foolproof, just an additional layer of security.  At the moment if you query aastraphone.php with the right extension you automatically grant yourself access to that peer, assuming you know the password you could then make calls, and if you didn't you could then attempt to brute force the system.  It may be prudent to add a little more security to this system by passing another parameter from the phone to the aastraphone.php script to help verify the peer is who it says it is.  Maybe pass through the callerid of the extension, or the context that extension should be dialing from and verify that against sippeers.

Additionally this solution should work for other brands of phones that are able to poll a URL at an interval, or at startup such as Cisco, and Polycom.  I haven't touched my Polycom IP 650 in a while but I'll test it out on that phone in the next few days and update this post with the results.  

Monday, May 23, 2011

After upgrading from CRM 4.0 to CRM 2011 I get javascript errors

We just upgraded to CRM 2011 and whenever we opened the accounts page we were getting a javascript error saying:
"There was an error with this field's customized event.
Field:window
Event:onload
Error:The value of the property 'Form_onload' is null or undefined, not a Function object"
I did not build our original CRM implementation so I'm not familiar with a lot of the JavaScript code in use, so I simply tried to disable the code from executing, and that actually solved the problem I was having.  


To do so:

  1. Open the form that has the error by Clicking New to add a new Record
  2. Click Customize
  3. Click Form
  4. Once you do that you should be at this screen:


  1. Now you need to click the Form Properties button and you should land at the window on the right
  2. I found the offending javascript
  3. Clicked Edit
  4. Unchecked the Enabled button
  5. Clicked Okay, Okay, and then Save and Publish on the Prior window.  


Now go back and try to create a new account and it won't error out anymore.  So something is wrong with the javascript from the old CRM 4.0 system and I'll need to figure out if we need it, and how to fix it if we do.