function itslenny_hookGet_config($engine)
{
    // This generates the dialplan
    global $ext;
    global $asterisk_conf;
    switch ($engine) {
        case "asterisk":
            $config = itslenny_config();
            $context = "app-blacklist-check";
            $exten = "s";
            if ($config[0]['enable'] == 'CHECKED') {
                if ($config[0]['record'] == 'CHECKED') {
                    $ext->splice($context, $exten, 4, new ext_gosub('1', 's', 'sub-record-check', 'rg,s,always'));
                }
                $ext->splice($context, $exten, 5, new ext_goto('1', 's', 'app-nv-itslenny'));
                $ext->splice($context, $exten, 6, new ext_hangup());
            }
            $id = "app-nv-itslenny";
            $c = "s";
            $config = itslenny_config();
            $silence = $config[0]['silence'];
            $itterations = $config[0]['itterations'];
            $ext->addInclude('from-internal-additional', $id);
            $ext->add($id, $c, '', new ext_answer(''));
            if ($config[0]['record'] == 'CHECKED') {
                $ext->add($id, $c, '', new ext_playback('en/this-call-may-be-monitored-or-recorded'));
            }
            $ext->add($id, $c, '', new ext_gosub('playitonce', '', '', 'Lenny01'));
            $ext->add($id, $c, '', new ext_gosub('playitonce', '', '', 'Lenny02'));
            $ext->add($id, $c, '', new ext_gosub('playitonce', '', '', 'Lenny03'));
            $ext->add($id, $c, '', new ext_gosub('playitonce', '', '', 'Lenny04'));
            $ext->add($id, $c, '', new ext_gosub('playitonce', '', '', 'Lenny05'));
            $ext->add($id, $c, '', new ext_gosub('playitonce', '', '', 'Lenny06'));
            $ext->add($id, $c, '', new ext_gosub('playitonce', '', '', 'Lenny07'));
            $ext->add($id, $c, '', new ext_gosub('playitonce', '', '', 'Lenny08'));
            $ext->add($id, $c, '', new ext_gosub('playitonce', '', '', 'Lenny09'));
            $ext->add($id, $c, '', new ext_gosub('playitonce', '', '', 'Lenny10'));
            $ext->add($id, $c, '', new ext_gosub('playitonce', '', '', 'Lenny11'));
            $ext->add($id, $c, '', new ext_gosub('playitonce', '', '', 'Lenny12'));
            $ext->add($id, $c, '', new ext_gosub('playitonce', '', '', 'Lenny13'));
            $ext->add($id, $c, '', new ext_gosub('playitonce', '', '', 'Lenny14'));
            $ext->add($id, $c, '', new ext_gosub('playitonce', '', '', 'Lenny15'));
            $ext->add($id, $c, '', new ext_gosub('playitonce', '', '', 'Lenny02'));
            $ext->add($id, $c, '', new ext_gosub('playitonce', '', '', 'Lenny03'));
            $ext->add($id, $c, '', new ext_gosub('playitonce', '', '', 'Lenny06'));
            $ext->add($id, $c, '', new ext_gosub('playitonce', '', '', 'Lenny08'));
            $ext->add($id, $c, '', new ext_gosub('playitonce', '', '', 'Lenny09'));
            $ext->add($id, $c, '', new ext_gosub('playitonce', '', '', 'Lenny10'));
            $ext->add($id, $c, '', new ext_gosub('playitonce', '', '', 'Lenny14'));
            $ext->add($id, $c, '', new ext_playback('en/tt-monkeys'));
            $ext->add($id, $c, '', new ext_hangup());
            $ext->add($id, $c, 'playitonce', new ext_noop('Lenny speaks once'));
            $ext->add($id, $c, '', new ext_playback('lenny/${ARG1}'));
            $ext->add($id, $c, '', new extension("WaitForSilence({$silence},{$itterations})"));
            $ext->add($id, $c, '', new ext_return());
            break;
    }
}
$cm =& cronmanager::create($db);
$online_updates = $cm->updates_enabled() ? true : false;
// check dev site to see if new version of module is available
if ($online_updates && ($foo = itslenny_vercheck())) {
    print "<br>A <b>new version of this module is available</b> from the <a target='_blank' href='http://pbxossa.org'>PBX Open Source Software Alliance</a><br>";
}
// check form and define var for form action
isset($_REQUEST['action']) ? $action = $_REQUEST['action'] : ($action = '');
//if submitting form, update database
if (isset($_POST['submit'])) {
    itslenny_edit(1, $_POST);
    redirect_standard();
}
$module_local = itslenny_xml2array("modules/itslenny/module.xml");
$module_version = $module_local['module']['version'];
$config = itslenny_config();
?>

<h2>Its Lenny Module</h2>

<form autocomplete="off" name="edit" action="<?php 
$_SERVER['PHP_SELF'];
?>
" method="post" >
<table>
		<tr>			
			<td colspan="2">			
			    <?php 
echo _("This module is used to modify the standard FreePBX blacklist so that banned callers interact with a series of recordings attempting to fool them into thinking it is a real person. The sound files were originally developed for the online service, <a href='http://www.itslenny.com'>Its Lenny</a> and have been made available to users free of charge by the owner. The Asterisk dial plan for this module was developed by Ward Mundy at <a href='http://www.nerdvittles.com'>Nerd Vittles</a>.");
?>
			</td>			
function itslenny_hookGet_config($engine)
{
    // This generates the dialplan
    global $ext;
    global $asterisk_conf;
    switch ($engine) {
        case "asterisk":
            $config = itslenny_config();
            $context = "app-blacklist-check";
            $exten = "s";
            if ($config[0]['enable'] == 'CHECKED') {
                if ($config[0]['record'] == 'CHECKED') {
                    $ext->splice($context, $exten, 4, new ext_gosub('1', 's', 'sub-record-check', 'rg,s,always'));
                }
                $ext->splice($context, $exten, 5, new ext_goto('1', 's', 'app-itslenny'));
                $ext->splice($context, $exten, 6, new ext_hangup());
            }
            // Destination so we can trasnfer calls to lenny from an active call
            if ($config[0]['extension'] != '' and $config[0]['extension'] != '0') {
                $id = "app-itslenny-dest";
                $c = $config[0]['extension'];
                $ext->addInclude('from-internal-additional', $id);
                if ($config[0]['blacklist'] == 'CHECKED') {
                    $ext->add($id, $c, '', new ext_noop('Blacklisting caller in: ' . $id));
                    $ext->add($id, $c, '', new ext_set('lastcaller', '${CALLERID(num)}'));
                    $ext->add($id, $c, '', new ext_gotoif('$[ $[ "${lastcaller}" = "" ] | $[ "${lastcaller}" = "unknown" ] ]', 'noinfo'));
                    $ext->add($id, $c, '', new ext_set('DB(blacklist/${lastcaller})', '${CALLERID(name)} - Blacklisted by: ' . $id . ''));
                    $ext->add($id, $c, 'noinfo', new ext_noop('Unidentified Caller'));
                }
                if ($config[0]['record'] == 'CHECKED') {
                    $ext->add($id, $c, '', new ext_gosub('1', 's', 'sub-record-check', 'rg,s,always'));
                }
                $ext->add($id, $c, '', new ext_goto('1', 's', 'app-itslenny'));
            }
            $id = "app-itslenny";
            $c = "s";
            $config = itslenny_config();
            $silence = $config[0]['silence'];
            $itterations = $config[0]['itterations'];
            $ext->addInclude('from-internal-additional', $id);
            $ext->add($id, $c, 'begin', new ext_answer(''));
            $ext->add($id, $c, '', new ext_set('CDR(userfield)', '"ItsLenny!"'));
            if ($config[0]['record'] == 'CHECKED') {
                //$ext->add($id, $c, '', new ext_playback('en/this-call-may-be-monitored-or-recorded'));
            }
            $ext->add($id, $c, '', new ext_gosub('playitonce', '', '', 'Lenny01'));
            // Hello this is lenny
            $ext->add($id, $c, '', new ext_gosub('playitonce', '', '', 'Lenny02'));
            // Sorry I can barely hear you thereY
            $ext->add($id, $c, '', new ext_gosub('playitonce', '', '', 'Lenny03'));
            // Yes, yes, yes...
            $ext->add($id, $c, '', new ext_gosub('playitonce', '', '', 'Lenny04'));
            // Oh good, yes, yes, yes
            $ext->add($id, $c, '', new ext_gosub('playitonce', '', '', 'Lenny05'));
            // Yes, yes, some did call last week, was that you?
            $ext->add($id, $c, '', new ext_gosub('playitonce', '', '', 'Lenny06'));
            // Sorry what was your name again
            $ext->add($id, $c, '', new ext_gosub('playitonce', '', '', 'Lenny07'));
            // Well its funny you should call, 3rd eldest larissa...
            $ext->add($id, $c, '', new ext_gosub('playitonce', '', '', 'Lenny08'));
            // I'm sorry I couldnt quite cath you there, what was that again
            $ext->add($id, $c, '', new ext_gosub('playitonce', '', '', 'Lenny09'));
            // Sorry, again...
            $ext->add($id, $c, '', new ext_gosub('playitonce', '', '', 'Lenny10'));
            // Would you say that again please
            $ext->add($id, $c, '', new ext_gosub('playitonce', '', '', 'Lenny11'));
            // Yes, yes, yes
            $ext->add($id, $c, '', new ext_gosub('playitonce', '', '', 'Lenny12'));
            // Sorry which company did you say you were calling from again?
            $ext->add($id, $c, '', new ext_gosub('playitonce', '', '', 'Lenny13'));
            // Last time I went for and got in trouble
            $ext->add($id, $c, '', new ext_gosub('playitonce', '', '', 'Lenny14'));
            // Since you put it that way, youve been friendly, hello... hello are you there, sorry bad connection
            $ext->add($id, $c, '', new ext_gosub('playitonce', '', '', 'Lenny15'));
            // With the world finance as they are, how is this going to work
            $ext->add($id, $c, '', new ext_gosub('playitonce', '', '', 'Lenny16'));
            // ducks
            $ext->add($id, $c, '', new ext_gosub('playitonce', '', '', 'Lenny02'));
            // Sorry I can barely hear you there
            $ext->add($id, $c, '', new ext_gosub('playitonce', '', '', 'Lenny03'));
            // Yes, yes, yes...
            $ext->add($id, $c, '', new ext_gosub('playitonce', '', '', 'Lenny06'));
            // Sorry what was your name again
            $ext->add($id, $c, '', new ext_gosub('playitonce', '', '', 'Lenny08'));
            // I'm sorry I couldnt quite cath you there, what was that again
            $ext->add($id, $c, '', new ext_gosub('playitonce', '', '', 'Lenny09'));
            // Sorry, again...
            $ext->add($id, $c, '', new ext_gosub('playitonce', '', '', 'Lenny10'));
            // Would you say that again please
            $ext->add($id, $c, '', new ext_gosub('playitonce', '', '', 'Lenny14'));
            // Since you put it that way, youve been friendly, hello... hello are you there, sorry bad connection
            $ext->add($id, $c, '', new ext_playback('en/tt-somethingwrong'));
            $ext->add($id, $c, '', new ext_playback('en/tt-monkeysintro'));
            $ext->add($id, $c, '', new ext_playback('en/tt-monkeys'));
            $ext->add($id, $c, '', new ext_hangup());
            $ext->add($id, $c, 'playitonce', new ext_noop('Lenny speaks once'));
            $ext->add($id, $c, '', new ext_playback('lenny/${ARG1}'));
            $ext->add($id, $c, '', new extension("WaitForSilence({$silence},{$itterations})"));
            $ext->add($id, $c, '', new ext_return());
            break;
    }
}