2
0
mirror of https://github.com/ACSPRI/queXS synced 2024-04-02 12:12:16 +00:00

Added freepbx 2.8.0 integration functions

Added htpasswd integration functions
Adding an operator can now add a freepbx extension and/or a password for apache htpasswd authentication
Adding a client can now add a password for apache htpasswd authentication
Updated template for ACSPRI
Added .htaccess files by default
This commit is contained in:
azammitdcarf
2010-12-22 04:51:51 +00:00
parent eb743c2f9b
commit 7cd1a21d84
9 changed files with 796 additions and 13 deletions

16
.htaccess Normal file
View File

@@ -0,0 +1,16 @@
php_flag display_startup_errors on
php_flag display_errors on
php_flag html_errors on
php_flag ignore_repeated_errors off
php_flag ignore_repeated_source off
php_flag report_memleaks on
php_flag track_errors on
php_value docref_root 0
php_value docref_ext 0
php_value error_reporting -1
AuthType Basic
AuthName "queXS CATI: Authentication Required"
AuthUserFile /var/opt/quexs/htpasswd
AuthGroupFile /var/opt/quexs/htgroup
require group interviewers

5
admin/.htaccess Normal file
View File

@@ -0,0 +1,5 @@
AuthType Basic
AuthName "queXS CATI: Authentication Required"
AuthUserFile /var/opt/quexs/htpasswd
AuthGroupFile /var/opt/quexs/htgroup
require group admin

View File

@@ -66,15 +66,34 @@ if (isset($_POST['client']))
VALUES (NULL , $client, $firstname , $lastname, $time_zone_name);";
if ($db->Execute($sql))
{
if (HTPASSWD_PATH !== false && HTGROUP_PATH !== false)
{
//Get password and add it to the configured htpassword
include_once("../functions/functions.htpasswd.php");
$htp = New Htpasswd(HTPASSWD_PATH);
$htg = New Htgroup(HTGROUP_PATH);
$htp->addUser($_POST['client'],$_POST['password']);
$htg->addUserToGroup($_POST['client'],HTGROUP_CLIENT);
}
$a = T_("Added: $client");
}
else
$a = T_("Could not add") . " " . $client . ". " . T_("There may already be an client of this name");
$a = T_("Could not add") . " " . $client . ". " . T_("There may already be a client of this name");
}
}
xhtml_head(T_("Add a client"));
$sql = "SELECT Time_zone_name as value, Time_zone_name as description
FROM timezone_template";
$rs = $db->GetAll($sql);
if ($a)
{
?>
@@ -86,10 +105,13 @@ if ($a)
<p><? echo T_("Adding a client here will allow them to access project information in the client subdirectory. You can assign a client to a particular project using the"); ?> <a href="clientquestionnaire.php"><? echo T_("Assign client to Questionnaire"); ?></a> <? echo T_("tool."); ?></p>
<p><? echo T_("Use this form to enter the username of a user based on your directory security system. For example, if you have secured the base directory of queXS using Apache file based security, enter the usernames of the users here."); ?></p>
<form enctype="multipart/form-data" action="" method="post">
<p><? echo T_("Enter the username of an client to add:"); ?> <input name="client" type="text"/></p>
<p><? echo T_("Enter the first name of an client to add:"); ?> <input name="firstname" type="text"/></p>
<p><? echo T_("Enter the surname of an client to add:"); ?> <input name="lastname" type="text"/></p>
<p><? echo T_("Enter the Time Zone of an client to add:"); ?> <input name="Time_zone_name" type="text" value="<? echo DEFAULT_TIME_ZONE; ?>"/></p>
<p><? echo T_("Enter the username of a client to add:"); ?> <input name="client" type="text"/></p>
<? if (HTPASSWD_PATH !== false && HTGROUP_PATH !== false) { ?>
<p><? echo T_("Enter the password of a client to add:"); ?> <input name="password" type="text"/></p>
<? } ?>
<p><? echo T_("Enter the first name of a client to add:"); ?> <input name="firstname" type="text"/></p>
<p><? echo T_("Enter the surname of a client to add:"); ?> <input name="lastname" type="text"/></p>
<p><a href='timezonetemplate.php'><? echo T_("Enter the Time Zone of a client to add:"); echo "</a>"; display_chooser($rs,"Time_zone_name","Time_zone_name",false,false,false,false,array("value",DEFAULT_TIME_ZONE)); ?> </p>
<p><input type="submit" value="<? echo T_("Add user"); ?>" /></p>
</form>

View File

@@ -55,8 +55,45 @@ if (isset($_POST['operator']))
$firstname = $db->qstr($_POST['firstname'],get_magic_quotes_gpc());
$lastname = $db->qstr($_POST['lastname'],get_magic_quotes_gpc());
$time_zone_name = $db->qstr($_POST['Time_zone_name'],get_magic_quotes_gpc());
$extension = $db->qstr($_POST['extension'],get_magic_quotes_gpc());
$extensionp = $db->qstr($_POST['extensionp'],get_magic_quotes_gpc());
$extension = 1000;
$extensionp = "";
if (FREEPBX_PATH == false)
{
//Manually add extension information
$extension = $db->qstr($_POST['extension'],get_magic_quotes_gpc());
$extensionp = $db->qstr($_POST['extensionp'],get_magic_quotes_gpc());
}
else
{
//Generate new extension from last one in database and random password
$sql = "SELECT SUBSTRING_INDEX(extension, '/', -1) as ext
FROM operator
ORDER BY ext DESC
LIMIT 1";
$laste = $db->GetRow($sql);
$extensionn = "1000";
$extension = "'IAX2/1000'";
//increment if exists
if (!empty($laste))
{
$extensionn = $laste['ext'] + 1;
$extension = "'IAX2/$extensionn'";
}
//generate random 8 length password
$extensionnp = "";
$length = 12;
$chars = "abcdefghijklmnopqrstuvwxyz0123456789";
for ($i = 0; $i < $length; $i++)
$extensionnp .= $chars[(rand() % strlen($chars))];
//quote for SQL
$extensionp = "'$extensionnp'";
}
$supervisor = 0;
$temporary = 0;
$refusal = 0;
@@ -65,6 +102,7 @@ if (isset($_POST['operator']))
if (isset($_POST['refusal']) && $_POST['refusal'] == "on") $refusal = 1;
if (isset($_POST['temporary']) && $_POST['temporary'] == "on") $temporary = 1;
if (isset($_POST['voip']) && $_POST['voip'] == "on") $voip = 1;
if (!empty($_POST['operator']))
{
$sql = "INSERT INTO operator
@@ -73,7 +111,31 @@ if (isset($_POST['operator']))
if ($db->Execute($sql))
{
$a = "Added: $operator";
if (FREEPBX_PATH !== false)
{
//Generate new extension in freepbx
include_once("../functions/functions.freepbx.php");
freepbx_add_extension($extensionn, $_POST["firstname"] . " " . $_POST["lastname"], $extensionnp);
}
if (HTPASSWD_PATH !== false && HTGROUP_PATH !== false)
{
//Get password and add it to the configured htpassword
include_once("../functions/functions.htpasswd.php");
$htp = New Htpasswd(HTPASSWD_PATH);
$htg = New Htgroup(HTGROUP_PATH);
$htp->addUser($_POST['operator'],$_POST['password']);
$htg->addUserToGroup($_POST['operator'],HTGROUP_INTERVIEWER);
if ($supervisor)
$htg->addUserGroup(HTGROUP_ADMIN);
}
$a = T_("Added:") . " " . $operator;
if (FREEPBX_PATH !== false)
$a .= "<br/>" . T_("Please reload FreePBX for the new VoIP extension to take effect");
$oid = $db->Insert_ID();
@@ -95,9 +157,10 @@ if (isset($_POST['operator']))
}else
}
else
{
$a = "Could not add $operator. There may already be an operator of this name";
$a = T_("Could not add operator. There may already be an operator of this name:") . " $operator" ;
}
@@ -125,11 +188,16 @@ $rs = $db->GetAll($sql);
<p><? echo T_("Use this form to enter the username of a user based on your directory security system. For example, if you have secured the base directory of queXS using Apache file based security, enter the usernames of the users here."); ?></p>
<form enctype="multipart/form-data" action="" method="post">
<p><? echo T_("Enter the username of an operator to add:"); ?> <input name="operator" type="text"/></p>
<? if (HTPASSWD_PATH !== false && HTGROUP_PATH !== false) { ?>
<p><? echo T_("Enter the password of an operator to add:"); ?> <input name="password" type="text"/></p>
<? } ?>
<p><? echo T_("Enter the first name of an operator to add:"); ?> <input name="firstname" type="text"/></p>
<p><? echo T_("Enter the surname of an operator to add:"); ?> <input name="lastname" type="text"/></p>
<p><a href='timezonetemplate.php'><? echo T_("Enter the Time Zone of an operator to add:"); echo "</a>"; display_chooser($rs,"Time_zone_name","Time_zone_name",false,false,false,false,array("value",DEFAULT_TIME_ZONE)); ?> </p>
<? if (FREEPBX_PATH == false) { ?>
<p><? echo T_("Enter the telephone extension number:"); ?> <input name="extension" type="text"/></p>
<p><? echo T_("Enter the telephone extension password:"); ?> <input name="extensionp" type="text"/></p>
<? } ?>
<p><? echo T_("Will this operator be using VoIP?"); ?> <input name="voip" type="checkbox" checked="checked"/></p>
<p><? echo T_("Is the operator a normal interviewer?"); ?> <input name="temporary" type="checkbox" checked="checked"/></p>
<p><? echo T_("Is the operator a supervisor?"); ?> <input name="supervisor" type="checkbox"/></p>

5
client/.htaccess Normal file
View File

@@ -0,0 +1,5 @@
AuthType Basic
AuthName "queXS CATI: Authentication Required"
AuthUserFile /var/opt/quexs/htpasswd
AuthGroupFile /var/opt/quexs/htgroup
require group clients

View File

@@ -89,6 +89,16 @@ if (!defined('VOIP_ADMIN_PASS')) define('VOIP_ADMIN_PASS','amp111');
*/
if (!defined('VOIP_PORT')) define('VOIP_PORT','5038');
/**
* The freepbx root path (if installed) otherwise false to disable freepbx integration
*/
if (!defined ('FREEPBX_PATH')) define('FREEPBX_PATH', false);
/**
* The freepbx database name
*/
if (!defined ('FREEPBX_DATABASE')) define('FREEPBX_DATABASE', 'asterisk');
/**
* The meet me room id for the VOIP Server
*/
@@ -146,6 +156,32 @@ if (!defined('PHP_EXEC')) define('PHP_EXEC', "php");
*/
if (!defined('ADODB_PATH')) define('ADODB_PATH',dirname(__FILE__).'/../adodb/');
/**
* Path to the HTPASSWD file read/writable by the web server user for htpasswd integration
*/
if (!defined('HTPASSWD_PATH')) define('HTPASSWD_PATH',false);
/**
* Path to the HTGROUP file read/writable by the web server user for htpasswd integration
*/
if (!defined('HTGROUP_PATH')) define('HTGROUP_PATH',false);
/**
* The name of the admin group for htaccess
*/
if (!defined('HTGROUP_ADMIN')) define('HTGROUP_ADMIN','admin');
/**
* The name of the interviewers group for htaccess
*/
if (!defined('HTGROUP_INTERVIEWER')) define('HTGROUP_INTERVIEWER','interviewers');
/**
* The name of the clients group for htaccess
*/
if (!defined('HTGROUP_CLIENT')) define('HTGROUP_CLIENT','clients');
/**
* Database configuration for queXS
*/

View File

@@ -0,0 +1,436 @@
<?
/**
* FreePBX Functions
*
*
* This file is part of queXS
*
* queXS is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* queXS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with queXS; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*
* @author Adam Zammit <adam.zammit@acspri.org.au>
* @copyright Australian Consortium for Social and Political Research Incorporated (ACSPRI) 2007,2008,2009,2010,2011
* @package queXS
* @subpackage functions
* @link http://www.acspri.org.au/software queXS was writen for ACSPRI
* @license http://opensource.org/licenses/gpl-2.0.php The GNU General Public License (GPL) Version 2
*
*/
/**
* Configuration file
*/
include_once(dirname(__FILE__).'/../config.inc.php');
/**
* FreePBX functions to add an extension
* This needs to be re-implemented here as there are too many code conflicts in including freepbx code
* The queXS database user should have access to the FreePBX database to avoid making a new connection
* FREEPBX_DATABASE needs to be set to the freepbx database name (i.e. asterisk)
*
* @param string $extension The extension number
* @param string $name The name of the extension
* @param string $password The password for the extension
* @return bool True if successfully added else false
*/
function freepbx_add_extension($extension,$name,$password)
{
global $amp_conf_defaults;
if (FREEPBX_PATH == false) return false; //break out if not defined
//include freepbx functions
require_once(FREEPBX_PATH . "/functions.inc.php");
require_once(FREEPBX_PATH . "/common/php-asmanager.php");
// get settings
$amp_conf = parse_amportal_conf("/etc/amportal.conf");
$asterisk_conf = parse_asterisk_conf($amp_conf["ASTETCDIR"]."/asterisk.conf");
$astman = new AGI_AsteriskManager();
// attempt to connect to asterisk manager proxy
if (!isset($amp_conf["ASTMANAGERPROXYPORT"]) || !$res = $astman->connect($amp_conf["ASTMANAGERHOST"] . ":" . $amp_conf["ASTMANAGERPROXYPORT"], $amp_conf["AMPMGRUSER"] , $amp_conf["AMPMGRPASS"])) {
// attempt to connect directly to asterisk, if no proxy or if proxy failed
if (!$res = $astman->connect($amp_conf["ASTMANAGERHOST"] . ":" . $amp_conf["ASTMANAGERPORT"], $amp_conf["AMPMGRUSER"] , $amp_conf["AMPMGRPASS"], 'off')) {
// couldn't connect at all
unset( $astman );
}
}
//Defines from bulkextensions module of FreePBX
$vars = array (
"action" => "add",
"extension" => $extension,
"name" => $name,
"cid_masquerade" => $extension,
"ringtimer" => 0,
"callwaiting" => "disabled",
"call_screen" => 0,
"pinless" => "disabled",
"tech" => "iax2",
"devinfo_secret" => $password,
"devinfo_notransfer" => "yes", // for iax2 devices
"devinfo_context" => "from-internal",
"devinfo_host" => "dynamic",
"devinfo_type" => "friend",
"devinfo_port" => 4569,
"devinfo_qualify" => "yes",
"devinfo_dial" => "IAX2/$extension",
"devinfo_mailbox" => $extension . "@device",
"devinfo_deny" => "0.0.0.0/0.0.0.0",
"devinfo_permit" => "0.0.0.0/0.0.0.0",
"deviceid" => $extension,
"devicetype" => "fixed",
"deviceuser" => $extension,
"description" => $name,
"dictenabled" => "disabled",
"dictformat" => "ogg",
"record_in" => "Adhoc",
"record_out" => "Adhoc",
"vm" => "disabled",
"voicemail" => "disabled",
"attach" => "attach=no",
"saycid" => "saycid=no",
"envelope" => "envelope=no",
"delete" => "delete=no",
"requirecalltoken" => "no",
"vmx_play_instructions" => "checked",
"vmx_option_0_system_default" => "checked",
"emergency_cid" => "null"
);
freepbx_core_users_add($amp_conf,$astman,$vars);
freepbx_core_devices_add($amp_conf,$astman,$vars["deviceid"],$vars["tech"],$vars["devinfo_dial"],$vars["devicetype"],$vars["deviceuser"],$vars["description"],$vars["emergency_cid"],false,$vars);
freepbx_need_reload();
}
function freepbx_need_reload()
{
global $db;
$sql = "UPDATE ".FREEPBX_DATABASE.".admin SET value = 'true' WHERE variable = 'need_reload'";
$db->Execute($sql);
}
function freepbx_core_devices_add(&$amp_conf,&$astman,$id,$tech,$dial,$devicetype,$user,$description,$emergency_cid=null,$editmode=false,$vars){
global $db;
//ensure this id is not already in use
$sql = "SELECT *
FROM ".FREEPBX_DATABASE.".devices
WHERE id = '$id'";
$rs = $db->GetAll($sql);
if (!empty($rs))
return false; //device already exists
//unless defined, $dial is TECH/id
if ( $dial == '' ) {
$dial = strtoupper($tech)."/".$id;
}
//check to see if we are requesting a new user
if ($user == "new") {
$user = $id;
$jump = true;
}
//insert into devices table
$sql="INSERT INTO ".FREEPBX_DATABASE.".devices (id,tech,dial,devicetype,user,description,emergency_cid) values (\"$id\",\"$tech\",\"$dial\",\"$devicetype\",\"$user\",\"$description\",\"$emergency_cid\")";
$db->Execute($sql);
//add details to astdb
if ($astman) {
// if adding or editting a fixed device, user property should always be set
if ($devicetype == 'fixed' || !$editmode) {
$astman->database_put("DEVICE",$id."/user",$user);
}
// If changing from a fixed to an adhoc, the user property should be intialized
// to the new default, not remain as the previous fixed user
if ($editmode) {
$previous_type = $astman->database_get("DEVICE",$id."/type");
if ($previous_type == 'fixed' && $devicetype == 'adhoc') {
$astman->database_put("DEVICE",$id."/user",$user);
}
}
$astman->database_put("DEVICE",$id."/dial",$dial);
$astman->database_put("DEVICE",$id."/type",$devicetype);
$astman->database_put("DEVICE",$id."/default_user",$user);
if($emergency_cid != '') {
$astman->database_put("DEVICE",$id."/emergency_cid","\"".$emergency_cid."\"");
}
if ($user != "none") {
$existingdevices = $astman->database_get("AMPUSER",$user."/device");
if (empty($existingdevices)) {
$astman->database_put("AMPUSER",$user."/device",$id);
} else {
$existingdevices_array = explode('&',$existingdevices);
if (!in_array($id, $existingdevices_array)) {
$existingdevices_array[]=$id;
$existingdevices = implode('&',$existingdevices_array);
$astman->database_put("AMPUSER",$user."/device",$existingdevices);
}
}
}
} else {
die("Cannot connect to Asterisk Manager with ".$amp_conf["AMPMGRUSER"]."/".$amp_conf["AMPMGRPASS"]);
}
// create a voicemail symlink if needed
/*
$thisUser = core_users_get($user);
if(isset($thisUser['voicemail']) && ($thisUser['voicemail'] != "novm")) {
if(empty($thisUser['voicemail'])) {
$vmcontext = "default";
} else {
$vmcontext = $thisUser['voicemail'];
}
//voicemail symlink
exec("rm -f /var/spool/asterisk/voicemail/device/".$id);
exec("/bin/ln -s /var/spool/asterisk/voicemail/".$vmcontext."/".$user."/ /var/spool/asterisk/voicemail/device/".$id);
}
*/
//take care of sip/iax/zap config
$funct = "freepbx_core_devices_add".strtolower($tech);
if(function_exists($funct)){
$funct($id,$vars);
}
return true;
}
function freepbx_core_devices_addiax2($account,$vars) {
global $db;
$flag = 2;
foreach ($vars as $req=>$data) {
if ( substr($req, 0, 8) == 'devinfo_' ) {
$keyword = substr($req, 8);
if ( $keyword == 'dial' && $data == '' ) {
$iaxfields[] = array($account, $keyword, 'IAX2/'.$account, $flag++);
} elseif ($keyword == 'mailbox' && $data == '') {
$iaxfields[] = array($account,'mailbox',$account.'@device', $flag++);
} else {
$iaxfields[] = array($account, $keyword, $data, $flag++);
}
}
}
if ( !is_array($iaxfields) ) { // left for compatibilty....lord knows why !
$iaxfields = array(
array($account,'secret',$db->qstr(($vars['secret'])?$vars['secret']:''),$flag++),
array($account,'notransfer',$db->qstr(($vars['notransfer'])?$vars['notransfer']:'yes'),$flag++),
array($account,'context',$db->qstr(($vars['context'])?$vars['context']:'from-internal'),$flag++),
array($account,'host',$db->qstr(($vars['host'])?$vars['host']:'dynamic'),$flag++),
array($account,'type',$db->qstr(($vars['type'])?$vars['type']:'friend'),$flag++),
array($account,'mailbox',$db->qstr(($vars['mailbox'])?$vars['mailbox']:$account.'@device'),$flag++),
array($account,'username',$db->qstr(($vars['username'])?$vars['username']:$account),$flag++),
array($account,'port',$db->qstr(($vars['port'])?$vars['port']:'4569'),$flag++),
array($account,'qualify',$db->qstr(($vars['qualify'])?$vars['qualify']:'yes'),$flag++),
array($account,'deny',$db->qstr((isset($vars['deny']))?$vars['deny']:''),$flag++),
array($account,'permit',$db->qstr((isset($vars['permit']))?$vars['permit']:''),$flag++),
array($account,'disallow',$db->qstr(($vars['disallow'])?$vars['disallow']:''),$flag++),
array($account,'allow',$db->qstr(($vars['allow'])?$vars['allow']:''),$flag++),
array($account,'accountcode',$db->qstr(($vars['accountcode'])?$vars['accountcode']:''),$flag++),
array($account,'requirecalltoken',$db->qstr(($vars['requirecalltoken'])?$vars['requirecalltoken']:'no'),$flag++)
);
}
// Very bad
$iaxfields[] = array($account,'account',($account),$flag++);
$iaxfields[] = array($account,'callerid',((isset($vars['description']) && $vars['description'] != '')?$vars['description']." <".$account.'>':'device'." <".$account.'>'),$flag++);
// Asterisk treats no caller ID from an IAX device as 'hide callerid', and ignores the caller ID
// set in iax.conf. As we rely on this for pretty much everything, we need to specify the
// callerid as a variable which gets picked up in macro-callerid.
// Ref - http://bugs.digium.com/view.php?id=456
$iaxfields[] = array($account,'setvar',"REALCALLERIDNUM=$account",$flag++);
// Where is this in the interface ??????
$iaxfields[] = array($account,'record_in',(($vars['record_in'])?$vars['record_in']:'On-Demand'),$flag++);
$iaxfields[] = array($account,'record_out',(($vars['record_out'])?$vars['record_out']:'On-Demand'),$flag++);
$iaxfields[] = array($account,'requirecalltoken','no',$flag++);
$compiled = $db->Prepare('INSERT INTO '.FREEPBX_DATABASE.'.iax (id, keyword, data, flags) values (?,?,?,?)');
foreach($iaxfields as $i)
$db->Execute($compiled, $i);
}
function freepbx_core_users_add(&$amp_conf, &$astman, $vars, $editmode=false) {
extract($vars);
global $db;
$thisexten = isset($thisexten) ? $thisexten : '';
if (trim($extension) == '' ) {
return false;
}
//ensure this id is not already in use
$sql = "SELECT *
FROM ".FREEPBX_DATABASE.".users
WHERE extension = '$extension'";
$rs = $db->GetAll($sql);
if (!empty($rs))
return false; //device already exists
$newdid_name = isset($newdid_name) ? $db->qstr($newdid_name) : '';
$newdid = isset($newdid) ? $newdid : '';
$newdid = preg_replace("/[^0-9._XxNnZz\[\]\-\+]/" ,"", trim($newdid));
$newdidcid = isset($newdidcid) ? trim($newdidcid) : '';
if (!preg_match('/^priv|^block|^unknown|^restrict|^unavail|^anonym/',strtolower($newdidcid))) {
$newdidcid = preg_replace("/[^0-9._XxNnZz\[\]\-\+]/" ,"", $newdidcid);
}
//build the recording variable
$recording = "out=".$record_out."|in=".$record_in;
//escape quotes and any other bad chddddars:
if(!get_magic_quotes_gpc()) {
$outboundcid = '';
$name = $db->qstr($name);
}
// Clean replace any <> with () in display name - should have javascript stopping this but ...
//
$name = preg_replace(array('/</','/>/'), array('(',')'), trim($name));
//insert into users table
$sql="INSERT INTO ".FREEPBX_DATABASE.".users (extension,password,name,voicemail,ringtimer,noanswer,recording,outboundcid,sipname) values (\"";
$sql.= "$extension\", \"";
$sql.= isset($password)?$password:'';
$sql.= "\", ";
$sql.= isset($name)?$name:'';
$sql.= ", \"";
$sql.= isset($voicemail)?$voicemail:'novm';
$sql.= "\", \"";
$sql.= isset($ringtimer)?$ringtimer:'';
$sql.= "\", \"";
$sql.= isset($noanswer)?$noanswer:'';
$sql.= "\", \"";
$sql.= isset($recording)?$recording:'';
$sql.= "\", \"";
$sql.= isset($outboundcid)?$outboundcid:'';
$sql.= "\", \"";
$sql.= isset($sipname)?$sipname:'';
$sql.= "\")";
$db->Execute($sql);
//write to astdb
if ($astman) {
$cid_masquerade = (isset($cid_masquerade) && trim($cid_masquerade) != "")?trim($cid_masquerade):$extension;
$astman->database_put("AMPUSER",$extension."/password",isset($password)?$password:'');
$astman->database_put("AMPUSER",$extension."/ringtimer",isset($ringtimer)?$ringtimer:'');
$astman->database_put("AMPUSER",$extension."/noanswer",isset($noanswer)?$noanswer:'');
$astman->database_put("AMPUSER",$extension."/recording",isset($recording)?$recording:'');
$astman->database_put("AMPUSER",$extension."/outboundcid",isset($outboundcid)?"\"".$outboundcid."\"":'');
$astman->database_put("AMPUSER",$extension."/cidname",isset($name)?"\"".$name."\"":'');
$astman->database_put("AMPUSER",$extension."/cidnum",$cid_masquerade);
$astman->database_put("AMPUSER",$extension."/voicemail","\"".isset($voicemail)?$voicemail:''."\"");
switch ($call_screen) {
case '0':
$astman->database_del("AMPUSER",$extension."/screen");
break;
case 'nomemory':
$astman->database_put("AMPUSER",$extension."/screen","\"nomemory\"");
break;
case 'memory':
$astman->database_put("AMPUSER",$extension."/screen","\"memory\"");
break;
default:
}
if (!$editmode) {
$astman->database_put("AMPUSER",$extension."/device","\"".((isset($device))?$device:'')."\"");
}
if (trim($callwaiting) == 'enabled') {
$astman->database_put("CW",$extension,"\"ENABLED\"");
} else if (trim($callwaiting) == 'disabled') {
$astman->database_del("CW",$extension);
} else {
echo "ERROR: this state should not exist<br>";
}
if (trim($pinless) == 'enabled') {
$astman->database_put("AMPUSER",$extension."/pinless","\"NOPASSWD\"");
} else if (trim($pinless) == 'disabled') {
$astman->database_del("AMPUSER",$extension."/pinless");
} else {
echo "ERROR: this state should not exist<br>";
}
// Moved VmX setup to voicemail module since it is part of voicemail
//
} else {
die("Cannot connect to Asterisk Manager with ".$amp_conf["AMPMGRUSER"]."/".$amp_conf["AMPMGRPASS"]);
}
// OK - got this far, if they entered a new inbound DID/CID let's deal with it now
// remember - in the nice and ugly world of this old code, $vars has been extracted
// newdid and newdidcid
// Now if $newdid is set we need to add the DID to the routes
//
if ($newdid != '' || $newdidcid != '') {
$did_dest = 'from-did-direct,'.$extension.',1';
$did_vars['extension'] = $newdid;
$did_vars['cidnum'] = $newdidcid;
$did_vars['privacyman'] = '';
$did_vars['alertinfo'] = '';
$did_vars['ringing'] = '';
$did_vars['mohclass'] = 'default';
$did_vars['description'] = $newdid_name;
$did_vars['grppre'] = '';
$did_vars['delay_answer']= '0';
$did_vars['pricid']= '';
freepbx_core_did_add($did_vars, $did_dest);
}
return true;
}
function freepbx_core_did_add($incoming,$target=false){
global $db;
foreach ($incoming as $key => $val) { ${$key} = $val; } // create variables from request
$destination= ($target) ? $target : ${$goto0.'0'};
$sql="INSERT INTO ".FREEPBX_DATABASE.".incoming (cidnum,extension,destination,privacyman,pmmaxretries,pmminlength,alertinfo, ringing, mohclass, description, grppre, delay_answer, pricid) values ('$cidnum','$extension','$destination','$privacyman','$pmmaxretries','$pmminlength','$alertinfo', '$ringing', '$mohclass', '$description', '$grppre', '$delay_answer', '$pricid')";
return($db->Execute($sql));
}
?>

View File

@@ -0,0 +1,195 @@
<?
/**
* htpasswd/htgroup functions for authentication integration
*
*
* This file is part of queXS
*
* queXS is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* queXS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with queXS; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*
* @author Adam Zammit <adam.zammit@acspri.org.au>
* @copyright Australian Consortium for Social and Political Research Incorporated (ACSPRI) 2007,2008,2009,2010,2011
* @package queXS
* @subpackage functions
* @link http://www.acspri.org.au/software queXS was writen for ACSPRI
* @license http://opensource.org/licenses/gpl-2.0.php The GNU General Public License (GPL) Version 2
*
*/
/**
* Configuration file
*/
include_once(dirname(__FILE__).'/../config.inc.php');
/**
* Class Htpasswd from:
* @link http://www.kavoir.com/backyard/showthread.php?28-Use-PHP-to-generate-edit-and-update-.htpasswd-and-.htgroup-authentication-files
*/
class Htpasswd {
private $file = '';
public function __construct($file) {
if (file_exists($file)) {
$this -> file = $file;
} else {
return false;
}
}
private function write($pairs = array()) {
$str = '';
foreach ($pairs as $username => $password) {
$str .= "$username:{SHA}$password\n";
}
file_put_contents($this -> file, $str);
}
private function read() {
$pairs = array();
$fh = fopen($this -> file, 'r');
while (!feof($fh)) {
$pair_str = str_replace("\n", '', fgets($fh));
$pair_array = explode(':{SHA}', $pair_str);
if (count($pair_array) == 2) {
$pairs[$pair_array[0]] = $pair_array[1];
}
}
return $pairs;
}
public function addUser($username = '', $clear_password = '') {
if (!empty($username) && !empty($clear_password)) {
$all = $this -> read();
if (!array_key_exists($username, $all)) {
$all[$username] = $this -> getHash($clear_password);
$this -> write($all);
}
} else {
return false;
}
}
public function deleteUser($username = '') {
$all = $this -> read();
if (array_key_exists($username, $all)) {
unset($all[$username]);
$this -> write($all);
} else {
return false;
}
}
public function doesUserExist($username = '') {
$all = $this -> read();
if (array_key_exists($username, $all)) {
return true;
} else {
return false;
}
}
private function getHash($clear_password = '') {
if (!empty($clear_password)) {
return base64_encode(sha1($clear_password, true));
} else {
return false;
}
}
}
/**
* Class Htgroup from:
* @link http://www.kavoir.com/backyard/showthread.php?28-Use-PHP-to-generate-edit-and-update-.htpasswd-and-.htgroup-authentication-files
*/
class Htgroup {
private $file = '';
public function __construct($file) {
if (file_exists($file)) {
$this -> file = $file;
} else {
return false;
}
}
private function write($groups = array()) {
$str = '';
foreach ($groups as $group => $users) {
$users_str = '';
foreach ($users as $user) {
if (!empty($users_str)) {
$users_str .= ' ';
}
$users_str .= $user;
}
$str .= "$group: $users_str\n";
}
file_put_contents($this -> file, $str);
}
private function read() {
$groups = array();
$groups_str = file($this -> file, FILE_IGNORE_NEW_LINES);
foreach ($groups_str as $group_str) {
if (!empty($group_str)) {
$group_str_array = explode(': ', $group_str);
if (count($group_str_array) == 2) {
$users_array = explode(' ', $group_str_array[1]);
$groups[$group_str_array[0]] = $users_array;
}
}
}
return $groups;
}
public function addUserToGroup($username = '', $group = '') {
if (!empty($username) && !empty($group)) {
$all = $this -> read();
if (isset($all[$group])) {
if (!in_array($username, $all[$group])) {
$all[$group][] = $username;
}
} else {
$all[$group][] = $username;
}
$this -> write($all);
} else {
return false;
}
}
public function deleteUserFromGroup($username = '', $group = '') {
$all = $this -> read();
if (array_key_exists($group, $all)) {
$user_index = array_search($username, $all[$group]);
if ($user_index !== false) {
unset($all[$group][$user_index]);
if (count($all[$group]) == 0) {
unset($all[$group]);
}
$this -> write($all);
}
} else {
return false;
}
}
}
?>

View File

@@ -20,11 +20,11 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*
* @author Adam Zammit <adam.zammit@deakin.edu.au>
* @copyright Deakin University 2007,2008
* @author Adam Zammit <adam.zammit@acspri.org.au>
* @copyright Australian Consortium for Social and Political Research Incorporated (ACSPRI) 2007,2008,2009,2010,2011
* @package queXS
* @subpackage functions
* @link http://www.deakin.edu.au/dcarf/ queXS was writen for DCARF - Deakin Computer Assisted Research Facility
* @link http://www.acspri.org.au/software queXS was writen for ACSPRI
* @license http://opensource.org/licenses/gpl-2.0.php The GNU General Public License (GPL) Version 2
*
*/