FreePBX and a Cisco 7940 Phone

So, it has been months since I posted something technical on my website. For the most part it has been music stuff as well as general updates on the overall infrastructure of the site. However, for the past month or so I’ve been working on getting a Cisco SIP phone working with FreePBX. However, the problem was that I was not able to receive inbound calls.

This was the not so descriptive error:

    -- Called 2000 
; my sip extension
    -- Got SIP response 400 "Bad Request" back from 192.168.1.102 
; sip reply
    -- SIP/2000-7b88 is circuit-busy 
; this cause the call to go straight to VM

Looking at the logs and googling for weeks on the problem, it was possible that the problem was the following:

    -- Executing NoOp("Zap/1-1", "Using CallerID 
""LastName FirstName   "" <11234567890>") in new stack

Please note the double quotes around my name.Now, after talking to X-Rob on the #freepbx channel, he pointed me to the extensions.conf file where the CallerID seems to be handled or generated.

I looked at the last commit X-Rob made and compared it to the previous one:

Revision 1891:

exten => s,n,GotoIf($["${AMPUSERCIDNAME:1:2}" = ""]?report)
exten => s,n,Set(CALLERID(all)="${AMPUSERCIDNAME}" <${AMPUSER}>)

Revision 1900:

exten => s,n,GotoIf($["x${AMPUSERCIDNAME:1:2}" = "x"]?report)
exten => s,n,Set(CALLERID(all)=${AMPUSERCIDNAME} <${AMPUSER}>)

However, this latest change still did not eliminate the double quotes from the CallerID.

So, I removed the quotes around the variable x and inbound calls finally worked! Looking at the logs however I do get an unknown name for the CallerID field, but at this point I don’t really care. I will try to work on the code and see if I can figure out the “correct” way to fix this issue, but for now I’m just happy I’m able to receive inbound calls.

Here is what the logs show with the “” removed from around the x:

    -- Called 2000 
; my sip ext againg
    -- SIP/2000-0e25 is ringing 
; my phone ringing
    -- SIP/2000-0e25 answered Zap/1-1 
; me answering the phone



Cheers

The net, lost in cyber space? Part 2

December 4th was when I posted the first part of this little project. The whole point of this little “experiment” was to see how high I could get my name to come up on the google ranks. Well, after 6 months I am not up to #4. Actually, I am sure this just happened with this months google index update. Also, there are a couple of things I did. Linked this site from a couple of different sites. Slashdot was probably the one that mattered the most, but along with that one others were used. Also, I made sure to sign my whole name after any story or comment, that way increasing the instances of David Macias coming up.



So, that is that, I will continue seeing how long it takes for my name to reach #1 but I don’t see that being possible, I would need a lot more referers. Oh well, it is nice to know where I stand according to google.



~david macias



Old story



PS: I am not sure how google works with dynamic sites specially since the front page of this website constantly changes. Hmmm…?

dmacias.org now with 99% less SPAM.

So my site had been getting hit daily by SPAM. The SPAM would come in the form of a comment to random stories. The comments would be nothing but links to porn sites or financial helps sites. So I finally tracked down about 5-7 IPs that were the ones who did this, banned them, and now it has been 3 days with no SPAM. So I think the attack has settled down a bit, but I am sure it will start again eventually, it is all a matter of time.

~david macias

irony: Getting SPAM comments in this story :–)

RSS and PHP with a hint of CSS

Well this is the continuation from ealier story to my earlier post about messing around with RSS feeds with PHP. The synopsis of my little project was to capture the recents job postings from a really good job posting website. Take a look below for the code.



~david maciasSome limitations: I need to learn how to reuse the XML parser that way I don’t have to build it and clean it up new everytime, creates really messy code. I am not sure how bad of a load it is causing on the RSS home website. Among other things, but hey for 2 hours of hacking this works out pretty decent. Check out a live example at: Example


<html>
<head>
<title>Bottom Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
//CSS to ensure that text starts on top of colum regarldless of how many entries are received
<style type="text/css">
<!--
.veralign {
        vertical-align: top;
}
-->
</style>
</head>

<body>
<p>
  <?php
        if (($_GET['city']) == NULL){
                printf("No City Selected");
//if there is no city selected do not process and code, saves resources
        }
        else {
                printf("<p>City: ");
                printf($_GET['city']);
                printf("</p>");

                class RSSParser {
                        var $insideitem = false;
                        var $sectitle = "";
                        var $title = "";
                        var $link = "";
                        var $creator = "";
                        var $language = "";
                        var $source = "";
                        var $rights = "";
                        var $date = "";
                        var $type = "";

                        function startElement($parser, $tagName, $attrs) {
                                if ($this->insideitem) {
                                        $this->tag = $tagName;
                                }
                                elseif ($tagName == "ITEM") {
                                        $this->insideitem = true;
                                }
                        }

                        function endElement($parser, $tagName) {
                                if ($tagName == "ITEM") {
                                        printf("<font size =\"2\"><b><a href='%s'>%s</a></b> [ %s ]</font><BR>", trim($this->link), htmlspecialchars(trim($this->title)), htmlspecialchars(trim($this->source)));
                                        printf("<font size=\"2\"><b>Date: %s </b></font><BR>", htmlspecialchars(trim($this->date)));
                                        printf("<font size=\"1\">Creator: %s</font><BR>", htmlspecialchars(trim($this->creator)));
                                        printf("<font size=\"1\">Rights: %s</font><BR><BR>", htmlspecialchars(trim($this->rights)));
                                        $this->title = "";
                                        $this->link = "";
                                        $this->source = "";
                                        $this->date = "";
                                        $this->rights = "";
                                        $this->creator = "";
                                        $this->insideitem = false;
                                }
                        }

                        function characterData($parser, $data) {
                                if ($this->insideitem) {
                                        switch ($this->tag) {
                                                case "DC:TITLE":
                                                        $this->title .= $data;
                                                break;
                                                case "LINK":
                                                        $this->link .= $data;
                                                break;
                                                case "DC:CREATOR":
                                                        $this->creator .= $data;
                                                break;
                                                case "DC:RIGHTS":
                                                        $this->rights .= $data;
                                                break;
                                                case "DC:DATE":
                                                        $this->date .= $data;
                                                break;
                                                case "DC:SOURCE":
                                                        $this->source .= $data;
                                                break;
                                        }
                                }
                        }
                }
 printf("<table width=\"100%%\" border=\"1\" cellspacing=\"0\" cellpadding=\"10\"><tr>");
        printf("<td class=\"veralign\">");

                $xml_parser = xml_parser_create();
                $rss_parser = new RSSParser();

                xml_set_object($xml_parser,&$rss_parser);
                xml_set_element_handler($xml_parser, "startElement", "endElement");
                xml_set_character_data_handler($xml_parser, "characterData");

                printf("<B>%s Internet Engineering</B><BR>", $_GET['city']);
                $fp = fopen("http://".$_GET['city'].".craigslist.org/eng/index.rss","r")
                or die("Error reading RSS data.");
                while ($data = fread($fp, 4096))
                        xml_parse($xml_parser, $data, feof($fp))
                or die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser)));
                fclose($fp);

                xml_parser_free($xml_parser);
        printf("</td>");

        //////////////
        printf("<td class=\"veralign\">");

                $xml_parser = xml_parser_create();
                $rss_parser = new RSSParser();
                xml_set_object($xml_parser,&$rss_parser);
                xml_set_element_handler($xml_parser, "startElement", "endElement");
                xml_set_character_data_handler($xml_parser, "characterData");

                printf("<B>%s Software/DBA</B><BR>", $_GET['city']);
                $fp1 = fopen("http://".$_GET['city'].".craigslist.org/sof/index.rss","r")
                or die("Error reading RSS data.");
                while ($data = fread($fp1, 4096))
                        xml_parse($xml_parser, $data, feof($fp1))
                or die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser)));
                fclose($fp1);

                xml_parser_free($xml_parser);

        printf("</td>");

        ///////////
        printf("<td class=\"veralign\">");

                $xml_parser = xml_parser_create();
        $rss_parser = new RSSParser();
        xml_set_object($xml_parser,&$rss_parser);
        xml_set_element_handler($xml_parser, "startElement", "endElement");
        xml_set_character_data_handler($xml_parser, "characterData");

        printf("<B>%s Systems/Networking</B><BR>", $_GET['city']);
        $fp1 = fopen("http://".$_GET['city'].".craigslist.org/sad/index.rss","r")
        or die("Error reading RSS data.");
        while ($data = fread($fp1, 4096))
                xml_parse($xml_parser, $data, feof($fp1))
        or die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser)));
        fclose($fp1);

        xml_parser_free($xml_parser);

        printf("</td>");

        ///////////

        printf("<td class=\"veralign\">");

        $xml_parser = xml_parser_create();
        $rss_parser = new RSSParser();
        xml_set_object($xml_parser,&$rss_parser);
        xml_set_element_handler($xml_parser, "startElement", "endElement");
        xml_set_character_data_handler($xml_parser, "characterData");

        printf("<B>%s Web/Design</B><BR>", $_GET['city']);
        $fp1 = fopen("http://".$_GET['city'].".craigslist.org/art/index.rss","r")
        or die("Error reading RSS data.");
        while ($data = fread($fp1, 4096))
                xml_parse($xml_parser, $data, feof($fp1))
        or die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser)));
        fclose($fp1);

        xml_parser_free($xml_parser);

        printf("</td>");

        ///////////
        printf("<td class=\"veralign\">");

        $xml_parser = xml_parser_create();
        $rss_parser = new RSSParser();
        xml_set_object($xml_parser,&$rss_parser);
        xml_set_element_handler($xml_parser, "startElement", "endElement");
        xml_set_character_data_handler($xml_parser, "characterData");

        printf("<B>%s Tech Support</B><BR>", $_GET['city']);
        $fp1 = fopen("http://".$_GET['city'].".craigslist.org/tch/index.rss","r")
        or die("Error reading RSS data.");
        while ($data = fread($fp1, 4096))
                xml_parse($xml_parser, $data, feof($fp1))
        or die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser)));
        fclose($fp1);

        xml_parser_free($xml_parser);

        printf("</td>");
        printf("</tr></table>");
        }

?>
</p>
</body>
</html>

RSS and PHP

So I decided to play around with PHP and XML. My objective was to create a site which will retrieve job postings from a RSS feed. I am currently tweaking it but so far it is working great. Here are some pointers for any souls trying to to do something similar.



~david macias



I retrieved this tutorial from this Great Site.



I have updated this article with this new story.Please take a look at the comments made in the source code. This code will retrieve a feed, parse it, then print only the parts I really care about. For the most part the code is self explanatory, but I have included some comments to help out the newbies like me.



<html>
<head>
<title>DAM's RSS/XML and PHP</title>
</head>
<body>
<h2>Currently...</h2>
<dl>
<?php
	class RSSParser {
		var $insideitem = false; //Check out the what is inside the <title> tags, and these variables should reflect what you want to pull out
		var $sectitle = "";
		var $title = "";
		var $link = "";
		var $creator = "";
		var $language = "";
		var $source = "";
		var $rights = "";
		var $date = "";
		var $type = "";
		//This function checks if you are inside a new item
		function startElement($parser, $tagName, $attrs) {
			if ($this->insideitem) {
				$this->tag = $tagName;
			} 
			elseif ($tagName == "ITEM") {
				$this->insideitem = true;				
			}
		}	
	//functions prints out the data retreived from the RSS feed
		function endElement($parser, $tagName) {
			if ($tagName == "ITEM") {
				printf("<dt><b><a href='%s'>%s</a></b> [ %s ]</dt>", trim($this->link),htmlspecialchars(trim($this->title)),htmlspecialchars(trim($this->source)));
				printf("Date: %s <BR>",htmlspecialchars(trim($this->date)));
				printf("Creator: %s<BR>",htmlspecialchars(trim($this->creator)));
				printf("Rights: %s<BR><BR>",htmlspecialchars(trim($this->rights)));
				$this->title = "";
				$this->link = "";
				$this->source = "";
				$this->date = "";
				$this->rights = "";
				$this->creator = "";
				$this->insideitem = false;
			}
		}
	
		function characterData($parser, $data) {
			if ($this->insideitem) {
				switch ($this->tag) {
					case "DC:TITLE":
						$this->title .= $data;
					break;
					case "LINK":
						$this->link .= $data;
					break;
					case "DC:CREATOR":
						$this->creator .= $data;
					break;
					case "DC:RIGHTS":
						$this->rights .= $data;
					break;
					case "DC:DATE":
						$this->date .= $data;
					break;
					case "DC:SOURCE":
						$this->source .= $data;
					break;
				}
			}
		}
	}

	$xml_parser = xml_parser_create();
	$rss_parser = new RSSParser();
	xml_set_object($xml_parser,&$rss_parser);
	xml_set_element_handler($xml_parser, "startElement", "endElement");
	xml_set_character_data_handler($xml_parser, "characterData");
	
	$xml_parser = xml_parser_create();
	$rss_parser = new RSSParser();
	xml_set_object($xml_parser,&$rss_parser);
	xml_set_element_handler($xml_parser, "startElement", "endElement");
	xml_set_character_data_handler($xml_parser, "characterData");
	
	$fp1 = fopen("htt://YourSiteFeedGoesHere/rss.xml","r")
	or die("Error reading RSS data.");
	while ($data = fread($fp1, 4096))
		xml_parse($xml_parser, $data, feof($fp1))
	or die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser)));
	fclose($fp1);
	xml_parser_free($xml_parser);
?>
</dl>
</body>
</html>

The net, lost in cyber space? Part 1

So it seems that when you search for David Macias on google.com I am not in the top results. What does that mean? It means that people who might be interested in finding me (old friends, family members), will not be able to locate me using google and just my name. So what can be done?If you are familiar with how google works, you might know about page ranking and how people can manipulate search results. Of course this takes more than one person however I am a patient man, and slowly but surely I will climb up the google.com latter. I will post a new story periodically detailing my undertaking and my results, but I will give you a small hint misearable failure



-david macias

Quest for my ideal AIM name!

So there is this person who has the AIM name I always wanted, he never uses it, maybe once every couple of months, I finally got a chance to talk to him and see if there was a possibility of maybe him passing it on to me. Below is the conversation that ensued…DAMWorking: hey
**********: who is this
DAMWorking: you don’t know me
**********: no
**********: do you know me?
DAMWorking: nope i dont, I just know that you are the person who has ********** as their screen name on AIM, and I wasn wandering if you would ever consider letting it go?
DAMWorking: however I think i got on the AIM bandwagon a little late and ********** was taken :-(
DAMWorking: so yeah, kinda of sad, i know
**********: i need 100 US dollars
DAMWorking: damn!
DAMWorking: i need a 100 US dollars too
**********: and i will happily give it up i don’t even ue the name
DAMWorking: i know you don’t use it, i’ve only seen you online like once
DAMWorking: that’s why I was hoping you might be willing to give it up
DAMWorking: but sorry $100 is too much for this broke college student
DAMWorking: can I ask you why did you pick it?
**********: cause i could
**********: i collect the tightest names
**********: i had "box"
DAMWorking: thats a cool hobby
DAMWorking: box?
**********: i am computer genius
**********: so they say
**********: i am very particular
DAMWorking: i see
**********: where do you go to school?
DAMWorking: Texas A&M
DAMWorking: you?
**********: moorpark california
DAMWorking: hmm, what are you studying?
**********: psychology, philosophy
**********: listen to trail of dead
********** signed off at 3:09:29 PM.

And just like that it ended, mind games perhaps…