gosa-plugin-gofon-2.7.4/ 0000755 0001750 0001750 00000000000 11752422556 014064 5 ustar cajus cajus gosa-plugin-gofon-2.7.4/contrib/ 0000755 0001750 0001750 00000000000 11752422555 015523 5 ustar cajus cajus gosa-plugin-gofon-2.7.4/contrib/gophone.sql 0000644 0001750 0001750 00000021250 11473412636 017702 0 ustar cajus cajus DROP DATABASE IF EXISTS `gophone`;
CREATE DATABASE `gophone`;
use gophone;
-- MySQL dump 10.11
--
-- Host: localhost Database: gophone
-- ------------------------------------------------------
-- Server version 5.0.51a-24+lenny4
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
--
-- Table structure for table `cdr`
--
DROP TABLE IF EXISTS `cdr`;
SET @saved_cs_client = @@character_set_client;
SET character_set_client = utf8;
CREATE TABLE `cdr` (
`calldate` datetime NOT NULL default '0000-00-00 00:00:00',
`clid` varchar(80) NOT NULL default '',
`src` varchar(80) NOT NULL default '',
`dst` varchar(80) NOT NULL default '',
`dcontext` varchar(80) NOT NULL default '',
`channel` varchar(80) NOT NULL default '',
`dstchannel` varchar(80) NOT NULL default '',
`lastapp` varchar(80) NOT NULL default '',
`lastdata` varchar(80) NOT NULL default '',
`duration` int(11) NOT NULL default '0',
`billsec` int(11) NOT NULL default '0',
`disposition` varchar(45) NOT NULL default '',
`amaflags` int(11) NOT NULL default '0',
`accountcode` varchar(20) NOT NULL default '',
`uniqueid` varchar(32) NOT NULL default '',
`userfield` varchar(255) NOT NULL default ''
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
SET character_set_client = @saved_cs_client;
--
-- Table structure for table `extensions`
--
DROP TABLE IF EXISTS `extensions`;
SET @saved_cs_client = @@character_set_client;
SET character_set_client = utf8;
CREATE TABLE `extensions` (
`id` int(11) NOT NULL auto_increment,
`context` varchar(20) NOT NULL default '',
`exten` varchar(20) NOT NULL default '',
`priority` tinyint(4) NOT NULL default '0',
`app` varchar(20) NOT NULL default '',
`appdata` varchar(128) NOT NULL default '',
PRIMARY KEY (`context`,`exten`,`priority`),
KEY `id` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1670 DEFAULT CHARSET=latin1;
SET character_set_client = @saved_cs_client;
--
-- Table structure for table `queue_members`
--
DROP TABLE IF EXISTS `queue_members`;
SET @saved_cs_client = @@character_set_client;
SET character_set_client = utf8;
CREATE TABLE `queue_members` (
`uniqueid` int(10) unsigned NOT NULL auto_increment,
`membername` varchar(40) default NULL,
`queue_name` varchar(128) default NULL,
`interface` varchar(128) default NULL,
`penalty` int(11) default NULL,
`paused` tinyint(1) default NULL,
PRIMARY KEY (`uniqueid`),
UNIQUE KEY `queue_interface` (`queue_name`,`interface`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
SET character_set_client = @saved_cs_client;
--
-- Table structure for table `queues`
--
DROP TABLE IF EXISTS `queues`;
SET @saved_cs_client = @@character_set_client;
SET character_set_client = utf8;
CREATE TABLE `queues` (
`name` varchar(128) NOT NULL,
`musiconhold` varchar(128) default NULL,
`announce` varchar(128) default NULL,
`context` varchar(128) default NULL,
`timeout` int(11) default NULL,
`monitor_join` tinyint(1) default NULL,
`monitor_format` varchar(128) default NULL,
`queue_youarenext` varchar(128) default NULL,
`queue_thereare` varchar(128) default NULL,
`queue_callswaiting` varchar(128) default NULL,
`queue_holdtime` varchar(128) default NULL,
`queue_minutes` varchar(128) default NULL,
`queue_seconds` varchar(128) default NULL,
`queue_lessthan` varchar(128) default NULL,
`queue_thankyou` varchar(128) default NULL,
`queue_reporthold` varchar(128) default NULL,
`announce_frequency` int(11) default NULL,
`announce_round_seconds` int(11) default NULL,
`announce_holdtime` varchar(128) default NULL,
`retry` int(11) default NULL,
`wrapuptime` int(11) default NULL,
`maxlen` int(11) default NULL,
`servicelevel` int(11) default NULL,
`strategy` varchar(128) default NULL,
`joinempty` varchar(128) default NULL,
`leavewhenempty` varchar(128) default NULL,
`eventmemberstatus` tinyint(1) default NULL,
`eventwhencalled` tinyint(1) default NULL,
`reportholdtime` tinyint(1) default NULL,
`memberdelay` int(11) default NULL,
`weight` int(11) default NULL,
`timeoutrestart` tinyint(1) default NULL,
`periodic_announce` varchar(50) default NULL,
`periodic_announce_frequency` int(11) default NULL,
PRIMARY KEY (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
SET character_set_client = @saved_cs_client;
--
-- Table structure for table `sip_users`
--
DROP TABLE IF EXISTS `sip_users`;
SET @saved_cs_client = @@character_set_client;
SET character_set_client = utf8;
CREATE TABLE `sip_users` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(80) NOT NULL default '',
`host` varchar(31) NOT NULL default '',
`nat` varchar(5) NOT NULL default 'no',
`type` enum('user','peer','friend') NOT NULL default 'friend',
`accountcode` varchar(20) default NULL,
`amaflags` varchar(13) default NULL,
`callgroup` varchar(10) default NULL,
`callerid` varchar(80) default NULL,
`cancallforward` char(3) default 'yes',
`canreinvite` char(3) default 'yes',
`context` varchar(80) default NULL,
`defaultip` varchar(15) default NULL,
`dtmfmode` varchar(7) default NULL,
`fromuser` varchar(80) default NULL,
`fromdomain` varchar(80) default NULL,
`insecure` varchar(4) default NULL,
`language` char(2) default NULL,
`mailbox` varchar(50) default NULL,
`md5secret` varchar(80) default NULL,
`deny` varchar(95) default NULL,
`permit` varchar(95) default NULL,
`mask` varchar(95) default NULL,
`musiconhold` varchar(100) default NULL,
`pickupgroup` varchar(10) default NULL,
`qualify` char(3) default NULL,
`regexten` varchar(80) default NULL,
`restrictcid` char(3) default NULL,
`rtptimeout` char(3) default NULL,
`rtpholdtimeout` char(3) default NULL,
`secret` varchar(80) default NULL,
`setvar` varchar(100) default NULL,
`disallow` varchar(100) default 'all',
`allow` varchar(100) default 'g729;ilbc;gsm;ulaw;alaw',
`fullcontact` varchar(80) NOT NULL default '',
`ipaddr` varchar(15) NOT NULL default '',
`port` smallint(5) unsigned NOT NULL default '0',
`regserver` varchar(100) default NULL,
`regseconds` int(11) NOT NULL default '0',
`username` varchar(80) NOT NULL default '',
PRIMARY KEY (`id`),
UNIQUE KEY `name` (`name`),
KEY `name_2` (`name`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC;
SET character_set_client = @saved_cs_client;
--
-- Table structure for table `voicemail_users`
--
DROP TABLE IF EXISTS `voicemail_users`;
SET @saved_cs_client = @@character_set_client;
SET character_set_client = utf8;
CREATE TABLE `voicemail_users` (
`uniqueid` int(11) NOT NULL auto_increment,
`customer_id` varchar(11) NOT NULL default '0',
`context` varchar(50) NOT NULL default '',
`mailbox` varchar(11) NOT NULL default '0',
`password` varchar(5) NOT NULL default '0',
`fullname` varchar(150) NOT NULL default '',
`email` varchar(50) NOT NULL default '',
`pager` varchar(50) NOT NULL default '',
`tz` varchar(10) NOT NULL default 'central',
`attach` varchar(4) NOT NULL default 'yes',
`saycid` varchar(4) NOT NULL default 'yes',
`dialout` varchar(10) NOT NULL default '',
`callback` varchar(10) NOT NULL default '',
`review` varchar(4) NOT NULL default 'no',
`operator` varchar(4) NOT NULL default 'no',
`envelope` varchar(4) NOT NULL default 'no',
`sayduration` varchar(4) NOT NULL default 'no',
`saydurationm` tinyint(4) NOT NULL default '1',
`sendvoicemail` varchar(4) NOT NULL default 'no',
`delete` varchar(4) NOT NULL default 'no',
`nextaftercmd` varchar(4) NOT NULL default 'yes',
`forcename` varchar(4) NOT NULL default 'no',
`forcegreetings` varchar(4) NOT NULL default 'no',
`hidefromdir` varchar(4) NOT NULL default 'yes',
`stamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
PRIMARY KEY (`uniqueid`),
KEY `mailbox_context` (`mailbox`,`context`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=latin1;
SET character_set_client = @saved_cs_client;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
gosa-plugin-gofon-2.7.4/gofon/ 0000755 0001750 0001750 00000000000 11752422556 015174 5 ustar cajus cajus gosa-plugin-gofon-2.7.4/gofon/migration/ 0000755 0001750 0001750 00000000000 11752422556 017165 5 ustar cajus cajus gosa-plugin-gofon-2.7.4/gofon/migration/class_migrate_phoneConferenceRDN.inc 0000644 0001750 0001750 00000000235 11424307333 026211 0 ustar cajus cajus
gosa-plugin-gofon-2.7.4/gofon/migration/class_migrate_phoneMacroRDN.inc 0000644 0001750 0001750 00000000223 11424307335 025202 0 ustar cajus cajus
gosa-plugin-gofon-2.7.4/gofon/migration/class_migrate_phoneRDN.inc 0000644 0001750 0001750 00000000216 11373175351 024226 0 ustar cajus cajus
gosa-plugin-gofon-2.7.4/gofon/phoneaccount/ 0000755 0001750 0001750 00000000000 11752422555 017661 5 ustar cajus cajus gosa-plugin-gofon-2.7.4/gofon/phoneaccount/class_phoneAccount.inc 0000644 0001750 0001750 00000245701 11750776073 024205 0 ustar cajus cajus delimiter = $this->config->get_cfg_value("phoneAccount","delimiter");
/* Assemble phone numbers */
if (isset($this->attrs['telephoneNumber'])){
for ($i= 0; $i<$this->attrs['telephoneNumber']['count']; $i++){
$number= $this->attrs['telephoneNumber'][$i];
$this->phoneNumbers[$number]= $number;
}
}
$this->sip_contexts = $this->get_asterisk_sip_contexts();
$this->voicemail_contexts = $this->get_asterisk_voicemail_contexts();
/* Set parent object to tab object */
if(is_object($parent)){
$this->parent = $parent->parent;
}
/* Get current uid and cn
*/
if(isset($this->attrs['uid'][0])){
$this->uid = $this->attrs['uid'][0];
}
if(isset($this->attrs['cn'][0])){
$this->cn = $this->attrs['cn'][0];
}
if(isset($this->attrs['mail'][0])){
$this->mailAddress = $this->attrs['mail'][0];
$this->has_mailAccount = true;
}
if(isset($this->attrs['pager'][0])){
$this->pager = $this->attrs['pager'][0];
}
/* If there is a parent object present, use references
*/
if(isset($this->parent->by_object['user']->uid)){
$this->uid = &$this->parent->by_object['user']->uid;
}
if(isset($this->parent->by_object['user']->cn)){
$this->cn =&$this->parent->by_object['user']->cn;
}
if(isset($this->parent->by_object['user']->pager)){
$this->pager =&$this->parent->by_object['user']->pager;
}
if(isset($this->parent->by_object['mailAccount']->mail)){
$this->mailAddress = &$this->parent->by_object['mailAccount']->mail;
$this->has_mailAccount = &$this->parent->by_object['mailAccount']->is_account;
}
/* Check server configurations
* Load all server configuration in $this->goFonHomeServers if available
* and first server as default if necessary.
* Check if connection is successfull for the selected server $this->goFonHomeServer
*/
/* Set available server */
$config = session::get('config');
if(isset($config->data['SERVERS']['FON'])){
$this->goFonHomeServers = $config->data['SERVERS']['FON'];
}
$a_SETUP= array();
if($this->is_account && isset($config->data['SERVERS']['FON']) &&
array_key_exists('FON',$config->data['SERVERS']) &&
is_callable("mysql_connect")
) {
/* Servers defined? Watch here... */
if (count($this->goFonHomeServers)){
/* Set default server */
if(empty($this->goFonHomeServer) || $this->goFonHomeServer == "0"){
$this->goFonHomeServer= $this->goFonHomeServers[0]['DN'];
}
/* Remember inital home server, to be able to remove old entries */
$this->init_HomeServer = $this->goFonHomeServer;
/* Get config */
if(!isset($this->goFonHomeServers[$this->goFonHomeServer])){
msg_dialog::display(_("Obsolete entry"), sprintf(_("The current home server is not available anymore. It will be moved to '%s' if you save this entry!"), preg_replace("/,/",", ",$this->goFonHomeServers[0]['DN'])), ERROR_DIALOG);
$this->goFonHomeServer = $this->goFonHomeServers[0]['DN'];
$this->init_HomeServer = $this->goFonHomeServers[0]['DN'];
}
$cur_cfg = $this->goFonHomeServers[$this->goFonHomeServer];
$r_con = @mysql_pconnect($cur_cfg['SERVER'],$cur_cfg['LOGIN'],$cur_cfg['PASSWORD']);
if(!$r_con){
new log("debug","gofonreport/".get_class($this),"",array(),@mysql_error());
}
$db = @mysql_select_db($cur_cfg['DB'],$r_con);
if(!$db){
new log("debug","gofonreport/".get_class($this),"",array(),@mysql_error());
}
$first = false;
foreach($this->phoneNumbers as $key => $val){
if(!$first){
$first = $key;
}
}
}
}
/* Get available phone hardware
* Search for all available phone hardware
*/
$tmp = get_sub_list("(objectClass=goFonHardware)","phone",array(get_ou("phoneGeneric", "phoneRDN")),
$this->config->current['BASE'],array("cn","description"), GL_SUBSEARCH);
foreach($tmp as $attrs){
$cn= $attrs['cn'][0];
$description= "";
if (isset($attrs['description'])){
$description= " - ".$attrs['description'][0];
}
$this->hardware_list[$cn]= "$cn$description";
}
$this->hardware_list["automatic"]= _("automatic");
ksort($this->hardware_list);
/* Collect all usd phones
goFonHardware set.
*/
$deps_a = array(
get_people_ou(),
get_ou("group", "ogroupRDN"),
get_ou("servgeneric", "serverRDN"),
get_ou("termgeneric", "terminalRDN"),
get_ou("workgeneric", "workstationRDN"),
get_ou("printgeneric", "printerRDN"),
get_ou("componentGeneric", "componentRDN"),
get_ou("phoneGeneric", "phoneRDN"));
$tmp = get_sub_list("(goFonHardware=*)","phone",$deps_a,$this->config->current['BASE'],
array('cn','dn','goFonHardware'),GL_SUBSEARCH);
foreach($tmp as $attrs){
$cn = $attrs['goFonHardware'][0];
if(isset($this->hardware_list[$cn])){
$this->used_hardware[$cn]= $cn;
}
}
/* Get available Macros
* Search for all Macros that are visible and create
* an array with name and parameters
*/
$tmp = get_sub_list("(&(objectClass=goFonMacro)(goFonMacroVisible=1))","gofonmacro",array(get_ou("macro", "phoneMacroRDN")),
$this->config->current['BASE'],array("displayName","goFonMacroParameter","dn","cn"), GL_NO_ACL_CHECK | GL_SUBSEARCH );
/* Add none for no macro*/
$this->macros['none']=_("no macro");
$this->macro ="none";
/* Fetch all Macros*/
foreach($tmp as $attrs){
$ui = get_userinfo();
$acl = $ui->get_permissions($attrs['dn'],"gofonmacro/macro","");
/* Skip all macros we are not able to read
execpt, the currently selected macro.
*/
if(!preg_match("/r/",$acl) && !preg_match("/^".preg_quote($attrs['dn'], '/')."/",$this->goFonMacro)){
continue;
}
/* unset Count, we don't need that here */
unset($attrs['displayName']['count']);
/* Parse macro data, unset count for parameterarrays */
if (isset($attrs['goFonMacroParameter']['count'])){
unset($attrs['goFonMacroParameter']['count']);
}
/* fill Selectfield variable with Macros */
if(isset($attrs['displayName'][0])){
$this->macros[$attrs['dn']] = $attrs['displayName'][0]." (".$attrs['cn'][0].")";
}else{
$this->macros[$attrs['dn']] = _("undefined");
}
/* Go through available parameters and parse all attributes, like parametername, type, default ...*/
if((isset($attrs['goFonMacroParameter']))&&(is_array($attrs['goFonMacroParameter']))){
foreach($attrs['goFonMacroParameter'] as $pkey=>$pval){
/* Split Data in readable values, by delimiter ! */
$data = explode("!",$attrs['goFonMacroParameter'][$pkey]);
$string = $data[3];
$string=preg_replace("/%uid/i",$this->uid,$string);
$string=preg_replace("/%pager/i",$this->pager,$string);
$string=preg_replace("/%context/i",$this->context,$string);
$string=preg_replace("/%voicemailcontext/i",$this->voice_context,$string);
if(isset($this->cn)){
$string=preg_replace("/%cn/i",$this->cn,$string);
}
$tmp = array();
foreach($this->phoneNumbers as $phonenum){
$tmp[] = $phonenum;
}
for($i = 0 ; $i < 10; $i++){
if(isset($tmp[$i])){
$string = preg_replace("/%telephoneNumber_".($i+1)."/i",$tmp[$i],$string);
}
}
if(isset($tmp[0])){
$string = preg_replace("/%telephoneNumber/i",$tmp[0],$string);
}
$data[3] = $string;
/* Set all attrs */
$id = $data[0];
$this->macroarray[$attrs['dn']][$id]['var'] ="var".$id;
$this->macroarray[$attrs['dn']][$id]['choosen']=$data[3];
$this->macroarray[$attrs['dn']][$id]['id'] =$id;
$this->macroarray[$attrs['dn']][$id]['name'] =$data[1];
$this->macroarray[$attrs['dn']][$id]['type'] =$data[2];
$this->macroarray[$attrs['dn']][$id]['default']=$data[3];
if($data[2] == "bool"){
$this->macroarray[$attrs['dn']][$id]['choosen']=$data[3];
}
}//foreach
}//is_array
}//while
/* Parse used Macro
* If we have a macro selected, parse it and set values
* in $this->macroarray[$this->macro].
*/
$tmp = explode("!",$this->goFonMacro);
if(is_array($tmp)){
/* First value is the macroname */
$this->macro = $tmp[0];
/* Macroname saved, delete that index */
unset($tmp[0]);
/* Check if makro has been removed */
if(!isset($this->macros[$this->macro])){
$this->macrostillavailable = false;
}else{
$this->macrostillavailable = true;
}
/* for each parametervalues ( parameterID#value like 25#twentyfive) */
foreach($tmp as $var){
/* Split this, so we have $varar[0] = parameterID $varar[1] = SelectedValue */
$varar = explode("#",$var);
/* Only insert if the parameter still exists */
if(isset($this->macroarray[$this->macro][$varar[0]])){
/* Assign value */
$this->macroarray[$this->macro][$varar[0]]['choosen']=$varar[1];
}
}
}
$this->a_old_telenums = $this->phoneNumbers;
/* Get voicemail PIN from MySQL DB
* Because every user can change his PIN directly from the phone
* without any update to the ldap
* This means, the PIN in the DB is up to date
*/
// Connect to DB server
$num = key($this->phoneNumbers);
if( (is_callable("mysql_pconnect"))&&
(isset($cur_cfg))&&
(isset($cur_cfg['SERVER']))&&
(isset($cur_cfg['LOGIN']))&&
(isset($cur_cfg['PASSWORD']))){
$r_con = @mysql_pconnect($cur_cfg['SERVER'],$cur_cfg['LOGIN'],$cur_cfg['PASSWORD']);
if($r_con){
// Try to select the gophone database
$r_db = @mysql_select_db($cur_cfg['DB'],$r_con);
if(!$r_db){
msg_dialog::display(_("Warning"), msgPool::dbselect($cur_cfg['DB'],mysql_error()), WARNING_DIALOG);
}
$query_tmp = "SELECT ".$cur_cfg['VOICE_TABLE'].".context as 'v_context',
".$cur_cfg['SIP_TABLE'].".context,
".$cur_cfg['VOICE_TABLE'].".password
FROM ".$cur_cfg['VOICE_TABLE'].",
".$cur_cfg['SIP_TABLE']."
WHERE ".$cur_cfg['VOICE_TABLE'].".mailbox = ".mysql_real_escape_string($num)."
AND ".$cur_cfg['SIP_TABLE'].".name='".mysql_real_escape_string($this->uid)."'";
$res = mysql_query($query_tmp);
$vp = mysql_fetch_assoc($res);
if(!isset($vp['context'])){
$this->is_modified= TRUE;
msg_dialog::display(_("Warning"), sprintf(_("Cannot identify telephone extension in database, please try to save again.")), WARNING_DIALOG);
}
@DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,$query_tmp, "Database query");
if((isset($vp['password']))&&(!empty($vp['password']))){
$this->goFonPINVoice = $vp['password'];
}
if((isset($vp['context']))&&(!empty($vp['context']))){
$this->context = $vp['context'];
}
if((isset($vp['v_context']))&&(!empty($vp['v_context']))){
$this->voice_context = $vp['v_context'];
}
}
}
$this->lastmacro=$this->macro;
if(is_callable("mysql_close")&&(isset($r_con))&&($r_con)){
@mysql_close($r_con) ;
}
}
/* Transaction will only work with InnoDB tables
*/
public static function checkRealtimeTables($config)
{
$ret =TRUE;
// Connect to DB server
if( (is_callable("mysql_pconnect"))&&
(isset($config))&&
(isset($config['SERVER']))&&
(isset($config['LOGIN']))&&
(isset($config['PASSWORD']))){
$r_con = @mysql_pconnect($config['SERVER'],$config['LOGIN'],$config['PASSWORD']);
if($r_con){
$r_db = @mysql_select_db($config['DB'],$r_con);
/* Validate Table Type - it must be InnoDB to be able to use transactions
*/
$inno_tables = array("SIP_TABLE","EXT_TABLE","VOICE_TABLE","QUEUE_TABLE","QUEUE_MEMBER_TABLE");
foreach($inno_tables as $inno_table){
$sql = "show table status like '".mysql_real_escape_string($config[$inno_table])."';";
$res = mysql_query($sql);
$vp = mysql_fetch_assoc($res);
if(!preg_match("/^InnoDB$/i",$vp['Engine'])){
/* Not an InnoDB Table type, try to modify type.
*/
$sql = "ALTER TABLE `".$config[$inno_table]."` ENGINE = INNODB; ";
$res = mysql_query($sql);
if(!$res){
@DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,"".$sql."",
"FAILED!. Transactions will not work!");
$ret = FALSE;
}else{
@DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,"".$sql."",
"Table '".$config[$inno_table]."' is now of type InnoDB, this enables transactions.");
}
}else{
@DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,"",
"Table type of '".$config[$inno_table]."' OK, using transactions!");
}
}
}
}
return($ret);
}
function stripInvalidChars($tele){
/* Strip invalid chars, but maintain a leading + for international numbers */
$t_tele= preg_replace("/[^0-9]/","",$tele);
if (preg_match('/^\+/', $tele)) {
$t_tele= "+".$t_tele;
}
return($t_tele);
}
/* This function generates the Database entries.
* The Parameter 'save' could be true or false.
* false - means only testing no database transactions.
* true - write database entries.
*
* 'sip_users','voice_mail' and 'extensions' table entries will be created.
*
* If the phone hardware is 'automatic' the table entries will only be removed
* and not added.
*/
function generate_mysql_entension_entries($save = false)
{
/* Check if there is at least one server available
* If not, return and tell the user that saving failed
*/
if(!count($this->goFonHomeServers)){
if($save){
msg_dialog::display(_("Configuration error"), msgPool::noserver(_("GOfon")), WARNING_DIALOG);
}
return(true);
}
/* Check if Mysql extension is available */
if(!is_callable("mysql_pconnect")){
if($save){
msg_dialog::display(_("Configuration error"), msgPool::missingext("php-mysql"), WARNING_DIALOG);
}
return(true);
}
/**********************
* Attribute Initialisation
**********************/
$old_connection = false;
// Get Configuration for Mysql database Server
$s_parameter = ""; // Contains paramter for selected Macro
$r_con = false; // DB connection
$r_db = false; // Selected DB
$r_res = false; // Result resource
$a_ldap_attrs = array(); //
$s_ip = NULL; // Contains ip for Sip entry
$s_host = NULL; // Contains host for Sip entry
$s_qualify = "yes"; // Qualify entry
$s_pin = NULL; // Entry for secret
$s_type = "friend"; // Entry for phone type (friend , peer ..)
// Set the default to the default of the db
$sip_data_array = array(); // Contains complete sip entry, to generate SQL syntax
$i_old_key = false; // Contains index for first old phonenumber, to delete old entries corectly
$i_new_key = false; // Contains index for first new phonenumber, to generate new entries corectly
$s_sip_values = ""; // Contains string with all values for given attributes in SQL syntax
$s_sip_keys = ""; // Contains all needed attributes to generate sip entry in DB
$s_sip_key = ""; // Key for SIP entry index
$s_sip_val = ""; // Value for SIP entry index
$b_first_deleted= false; // Only delete first entry,
$s_telenums = ""; // for each value variable
$i_is_accounted = false; // Ensure that extension entry, for name to number is only once in table
/* Prepare some basic attributes */
$oldnums = array();
foreach($this->a_old_telenums as $tele){
$oldnums[]= $this->stripInvalidChars($tele);
}
foreach($this->phoneNumbers as $tele){
$newnums[]= $this->stripInvalidChars($tele);
}
if(empty($this->uid)) trigger_error("Uid is empty.");
/* Create voicemail entry
*/
if((!isset($this->cn))||(empty($this->cn))){
$CNname= $this->uid;
}else{
$CNname= $this->cn;
}
$s_mail = "";
if($this->has_mailAccount){
$s_mail = $this->mailAddress;;
}
/* Get phonehardware to setup sip entry */
$ldap = $this->config->get_ldap_link();
$ldap->cd ($this->config->current['BASE']);
$r_res = $ldap->search("(&(objectClass=goFonHardware)(cn=".$this->goFonHardware."))", array('*'));
$a_ldap_attrs = $ldap->fetch();
/* Check selected phone hardware, is a default IP set? */
if(((isset($a_ldap_attrs['goFonDefaultIP'][0]))&&($a_ldap_attrs['goFonDefaultIP'][0] != "dynamic"))){
$s_ip = $a_ldap_attrs['goFonDefaultIP'][0];
$s_host = $s_ip;
}else{
$s_ip = NULL;
$s_host = "dynamic";
}
// Attribute GoFonQualify set ?
if(isset($a_ldap_attrs['goFonQualify'])){
$s_qualify = $a_ldap_attrs['goFonQualify'][0];
}
// Attribute GoFonPIN set ?
if(isset($this->goFonPIN)){
$s_pin = $this->goFonPIN;
}
// Attribute GoFonType set ?
if(isset($a_ldap_attrs['goFonType'])){
$s_type = $a_ldap_attrs['goFonType'][0];
}
if(isset($a_ldap_attrs['goFonDmtfMode'][0])){
$sip_data_array['dtmfmode'] = $a_ldap_attrs['goFonDmtfMode'][0];
}else{
$sip_data_array['dtmfmode'] ="rfc2833";
}
/* Check if phone number is used */
if($this->is_number_used()){
$this->generate_error = $this->is_number_used();
return false;
}
/**********************
* Check Server Connection Information
**********************/
/* Create Mysql handle for the current goFonHomeServer, if possible
* Get configuration to old asterisk home server
*/
$a_New = $this->goFonHomeServers[$this->goFonHomeServer]; // DB Configuration
$new_connection = @mysql_pconnect($a_New['SERVER'],$a_New['LOGIN'],$a_New['PASSWORD']);
if(!$new_connection){
$this->generate_error = msgPool::dbconnect($a_New['SERVER'],@mysql_error($new_connection),
_("Abort saving entries to keep the database consistent."));
new log("debug","gofonreport/".get_class($this),"",array(),@mysql_error($new_connection));
return false;
}
$new_database = @mysql_select_db($a_New['DB'],$new_connection);
if(!$new_database){
$this->generate_error = msgPool::dbselect($a_New['DB'],@mysql_error($new_connection),
_("Abort saving entries to keep the database consistent."));
new log("debug","gofonreport/".get_class($this),"",array(),@mysql_error($new_connection));
return false;
}
/* If the home server has changed, we must remove entries from old
* server and add new entries in new server.
*/
if($this->init_HomeServer != $this->goFonHomeServer){
/* Get configuration to old asterisk home server */
$a_Remove = $this->goFonHomeServers[$this->init_HomeServer]; // DB Configuration
/* Create connection to the database that contains the old entry.
*/
$old_connection = @mysql_pconnect($a_Remove['SERVER'],$a_Remove['LOGIN'],$a_Remove['PASSWORD']);
if(!$old_connection){
$this->generate_error = msgPool::dbconnect($a_Remove['SERVER'],@mysql_error($old_connection),
_("Abort saving entries to keep the database consistent."));
new log("debug","gofonreport/".get_class($this),"",array(),@mysql_error($old_connection));
return false;
}
$old_database = @mysql_select_db($a_Remove['DB'],$old_connection);
if(!$old_database){
$this->generate_error = msgPool::dbselect($a_Remove['DB'],@mysql_error($old_connection),
_("Abort saving entries to keep the database consistent."));
new log("debug","gofonreport/".get_class($this),"",array(),@mysql_error($old_connection));
return false;
}
}
/* Save means that we must save changes, not only test */
if($save == true){
/**********************
* Remove entries from old home server
**********************/
/* Check if there is an old entry
* If there is an old entry, get callerid and remove voicemail and extensions
*/
if($old_connection){
/* Check table definitions
*/
if(!phoneAccount::checkRealtimeTables($a_Remove)){
msg_dialog::display(_("Warning"),
sprintf(_("GOsa identified problems with your MySQL table definition!")),
WARNING_DIALOG);
}
$query = "SELECT id,name,callerid FROM ".$a_Remove['SIP_TABLE']." WHERE name='".mysql_real_escape_string($this->uid)."';";
$rid = mysql_query($query,$old_connection);
@DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,$query,
"Reguest callerid to be able to identify the user.");
/* Old entry found, remove it */
$query_a = array();
if(mysql_affected_rows($old_connection)){
$result = mysql_fetch_assoc($rid);
/* Set mode to strict
Strict disallows the addition of entries that do not match the targets field length.
*/
$query_a[]= "SET @@sql_mode = STRICT_ALL_TABLES;";
$query_a[]= "DELETE FROM ".$a_Remove['SIP_TABLE']." WHERE name='".mysql_real_escape_string($this->uid)."';";
$query_a[]= "DELETE FROM ".$a_Remove['VOICE_TABLE']." WHERE customer_id='".mysql_real_escape_string($result['callerid'])."';";
$query_a[]= "DELETE FROM ".$a_Remove['EXT_TABLE']." WHERE exten='".mysql_real_escape_string($this->uid)."';";
foreach($oldnums as $s_telenums) {
$query_a[]= "DELETE FROM ".$a_Remove['EXT_TABLE']." WHERE exten='".mysql_real_escape_string($s_telenums)."';";
}
/* Start transaction, to be able to rollback
*/
@DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,"---Removing entry from old server---","");
mysql_query("begin;",$old_connection);
@DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,"begin;","Starting transaction!");
foreach($query_a as $query){
@DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,"".$query."", "");
if(!mysql_query($query,$old_connection)){
$err = mysql_error($old_connection);
@DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,"\n".$err, "FAILED");
msg_dialog::display(_("Error"),
msgPool::mysqlerror($err,__CLASS__)." ".
"\n
"._("Please activate debugging for details!")."
",
ERROR_DIALOG);
mysql_query("rollback;",$old_connection);
@DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,"rollback;", "ERROR Rollback transaction!");
@mysql_close($old_connection);
return(false);
}
}
/* Let changes get active, everything was fine;
*/
mysql_query("commit;",$old_connection);
@DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,"commit;", "");
@DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,"---Transaction sucessful!---", "");
}
}
/**********************
* Update / Insert sip_users entry
**********************/
/* Check table definitions
*/
if(!phoneAccount::checkRealtimeTables($a_New)){
msg_dialog::display(_("Warning"),
sprintf(_("GOsa identified problems with your MySQL table definition!")),
WARNING_DIALOG);
}
/* Set the first given phone number as callerid */
reset($newnums);
$i_new_key = key($newnums);
$sip_data_array['callerid'] =$newnums[$i_new_key];
$sip_data_array['mailbox'] =$newnums[$i_new_key]."@".$this->voice_context;
/* Check if there is already an entry in sip_users for this uid */
$SQL_query_array = array();
/* Enforce strict mode, ensures inout validation, e.g. target field length
*/
$SQL_query_array[] = "SET @@sql_mode = STRICT_ALL_TABLES;";
$query = "SELECT * FROM ".$a_New['SIP_TABLE']." WHERE name='".mysql_real_escape_string($this->uid)."';\n";
$rid = mysql_query($query,$new_connection);
@DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,$query, "Receive current mysql entries.");
if(mysql_affected_rows($new_connection)){
/**********************
* Update sip_users entry
**********************/
$result = mysql_fetch_assoc($rid);
$sip_data_array['host'] = $s_host;
$sip_data_array['qualify'] = $s_qualify;
$sip_data_array['secret'] = $this->goFonPIN;
$sip_data_array['type'] = $s_type ;
$sip_data_array['username'] = $this->uid;
$sip_data_array['ipaddr'] = $s_ip;
$sip_data_array['context'] = $this->context;
/* Remove not changed attributes, to avoid updating table with same values */
foreach($sip_data_array as $name => $value){
if($result[$name] == $value){
unset($sip_data_array[$name]);
}
}
/* Only update entry if there is something to uopdate */
if(count($sip_data_array)){
$query = "UPDATE ".$a_New['SIP_TABLE']." SET ";
foreach($sip_data_array as $key => $val){
$query.= "".$key."='".mysql_real_escape_string($val)."',";
}
$query = preg_replace("/,$/","",$query);
$query.= " WHERE name='".mysql_real_escape_string($this->uid)."';";
$SQL_query_array[] = $query;
}
} else {
/**********************
* Insert sip_users entry
**********************/
//generate SIP entry
$sip_data_array['name'] = $this->uid;
$sip_data_array['accountcode'] = NULL;
$sip_data_array['amaflags'] = NULL;
$sip_data_array['callgroup'] = NULL;
$sip_data_array['canreinvite'] = "no";
$sip_data_array['context'] = $this->context;
$sip_data_array['defaultip'] = NULL;
$sip_data_array['fromuser'] = NULL;
$sip_data_array['fromdomain'] = NULL;
$sip_data_array['host'] = $s_host;
$sip_data_array['insecure'] = NULL;
$sip_data_array['language'] = NULL;
$sip_data_array['mailbox'] = $newnums[$i_new_key]."@".$this->voice_context;
$sip_data_array['md5secret'] = NULL;
$sip_data_array['nat'] = "no";
$sip_data_array['permit'] = NULL;
$sip_data_array['deny'] = NULL;
$sip_data_array['mask'] = NULL;
$sip_data_array['pickupgroup'] = NULL;
$sip_data_array['port'] = NULL;
$sip_data_array['qualify'] = $s_qualify;
$sip_data_array['restrictcid'] = "n";
$sip_data_array['rtptimeout'] = NULL;
$sip_data_array['rtpholdtimeout']=NULL;
$sip_data_array['secret'] = $this->goFonPIN;
$sip_data_array['type'] = $s_type ;
$sip_data_array['username'] = $this->uid;
$sip_data_array['disallow'] = NULL;
$sip_data_array['allow'] = NULL;
$sip_data_array['musiconhold'] = NULL;
$sip_data_array['regseconds'] = NULL;
$sip_data_array['ipaddr'] = $s_ip;
$sip_data_array['regexten'] = NULL;
$sip_data_array['cancallforward']=NULL;
/* There is currently no entry for this user in the sip_users table.
* We should create one i
*/
foreach($sip_data_array as $s_sip_key=>$s_sip_val){
if($s_sip_val === NULL) continue;
$s_sip_values.="'".mysql_real_escape_string($s_sip_val)."',";
$s_sip_keys .="`".$s_sip_key."`,";
}
$s_sip_values = preg_replace("/,$/","",$s_sip_values);
$s_sip_keys = preg_replace("/,$/","",$s_sip_keys);
/* Add sip entries to mysql queries */
$SQL_query_array[] ="INSERT INTO ".$a_New['SIP_TABLE']." (".$s_sip_keys.") VALUES (".$s_sip_values.");";
}
/**********************
* Update / Insert Voice mail entry
**********************/
$customer_id = $newnums[$i_new_key];
$query = "SELECT id,name,callerid FROM ".$a_New['SIP_TABLE']." WHERE name='".mysql_real_escape_string($this->uid)."';";
$rid = mysql_query($query,$new_connection);
@DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,$query, "Receive callerid");
$result = mysql_fetch_assoc($rid);
$old_customer_id = "";
if($result){
$old_customer_id = $result['callerid'];
}
$voice_data_array = array(
"customer_id" => $customer_id,
"mailbox" => $customer_id,
"password" => $this->goFonVoicemailPIN,
"fullname" => $CNname,
"context" => $this->voice_context,
"email" => $s_mail);
$voice_data_array['pager'] = $this->pager;
/* Check if there is already an entry in sip_users for this uid */
$query_tmp = "SELECT * FROM ".$a_New['VOICE_TABLE']." WHERE customer_id='".mysql_real_escape_string($old_customer_id)."';\n";
$rid = mysql_query($query_tmp,$new_connection);
@DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,$query_tmp, "Check if voicemail entry exists");
if(mysql_affected_rows($new_connection)){
/**********************
* Update Voice mail entry
**********************/
@DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,"", "Voicemail entry exists, adding updating to queue.");
$result = mysql_fetch_assoc($rid) ;
foreach($voice_data_array as $name => $value){
if($result[$name] == $value){
unset($voice_data_array[$name]);
}
}
/* Only update entry if there is something to update */
if(count($voice_data_array)){
$query = "UPDATE ".$a_New['VOICE_TABLE']." SET ";
foreach($voice_data_array as $key => $val){
$query.= "".$key."='".$val."',";
}
$query = preg_replace("/,$/","",$query);
$query.= " WHERE customer_id='".mysql_real_escape_string($old_customer_id)."';";
$SQL_query_array[] = $query;
}
}else{
/**********************
* Insert Voice mail entry
**********************/
@DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,"", "No voicemail entry found, add 'create' to queue.");
$voice_data_array['context'] = $this->voice_context;
/* There is currently no voice mail entry for this user.
* We should create one
*/
$s_voi_values = $s_voi_keys = "";
foreach($voice_data_array as $s_voi_key=>$s_voi_val){
if($s_voi_val === NULL) continue;
$s_voi_values.="'".mysql_real_escape_string($s_voi_val)."',";
$s_voi_keys .="`".$s_voi_key."`,";
}
$s_voi_values = preg_replace("/,$/","",$s_voi_values);
$s_voi_keys = preg_replace("/,$/","",$s_voi_keys);
/* Add sip entries to mysql queries */
$SQL_query_array[] ="INSERT INTO ".$a_New['VOICE_TABLE']." (".$s_voi_keys.") VALUES (".$s_voi_values.");";
}
/**********************
* Remove/Insert extension entries
**********************/
/* Initiate transaction
*/
$SQL_query_array[]= "DELETE FROM ".$a_New['EXT_TABLE']." WHERE exten=\"".mysql_real_escape_string($this->uid)."\";";
$oldnums= array();
foreach($oldnums as $s_telenums){
$SQL_query_array[]= "DELETE FROM ".$a_New['EXT_TABLE']." WHERE exten=\"".mysql_real_escape_string($s_telenums)."\";";
}
foreach($newnums as $s_telenums){
$SQL_query_array[]= "DELETE FROM ".$a_New['EXT_TABLE']." WHERE exten=\"".mysql_real_escape_string($s_telenums)."\";";
}
/**********************
* Insert extension entries
**********************/
// Get selected Macro Parameter and create parameter entry
if(isset($this->macroarray[$this->macro])){
foreach($this->macroarray[$this->macro] as $key => $val ){
$s_parameter .= $val['choosen'].$this->delimiter;
}
$s_parameter = rtrim($s_parameter, $this->delimiter);
}
$i = 0;
$EXT = array();
if(!is_numeric($this->uid)){
$EXT[$i]['context'] = 'GOsa';
$EXT[$i]['exten'] = $this->uid;
$EXT[$i]['priority']= 1;
$EXT[$i]['app'] = "Goto";
$EXT[$i]['appdata'] = $newnums[$i_new_key].$this->delimiter."1";
$i ++;
}
// Entension entries Hint / Dial / Goto
foreach($newnums as $s_telenums){
/* Hint Entry */
$EXT[$i]['context'] = 'GOsa';
$EXT[$i]['exten'] = $s_telenums;
$EXT[$i]['priority']= 0;
$EXT[$i]['app'] = 'SIP/'.$this->uid;
$i ++;
/* SetCID */
//$EXT[$i]['context'] = 'GOsa';
//$EXT[$i]['exten'] = $s_telenums;
//$EXT[$i]['priority']= 1;
//$EXT[$i]['app'] = "SetCIDName";
//$EXT[$i]['appdata'] = $CNname;
//$i ++;
// If no macro is selected use Dial
if($this->macro!="none"){
$macroname = preg_replace("/,.*$/","",$this->macro);
$macroname = preg_replace("/^.*=/","",$macroname);
$s_app = "Macro";$macroname;
$s_par = $macroname.$this->delimiter.$s_parameter;
}else{
$s_app = "Dial";
$s_par = 'SIP/'.$this->uid.$this->delimiter."20".$this->delimiter."r";
}
$EXT[$i]['context'] = 'GOsa';
$EXT[$i]['exten'] = $s_telenums;
$EXT[$i]['priority']= 1;
$EXT[$i]['app'] = $s_app;
$EXT[$i]['appdata'] = $s_par;
$i ++;
}
// Append all these Entries
foreach($EXT as $entr){
$SQL_syn = "INSERT INTO ".$a_New['EXT_TABLE']." (";
foreach($entr as $key2 => $val2){
$SQL_syn.= "`".$key2."`,";
}
$SQL_syn = preg_replace("/,$/","",$SQL_syn);
$SQL_syn .= ") VALUES (";
foreach($entr as $key2 => $val2){
$SQL_syn .= "'".mysql_real_escape_string($val2)."',";
}
$SQL_syn = preg_replace("/,$/","",$SQL_syn);
$SQL_syn .=");\n";
$SQL_query_array[] =$SQL_syn;
$SQL_syn ="";
}
/* Start transaction, to be able to rollback
*/
@DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,"---Insert/Update new entry---","");
mysql_query("begin;",$new_connection);
@DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,"begin;","Starting transaction!");
foreach($SQL_query_array as $query){
@DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,"".$query."", "");
if(!mysql_query($query,$new_connection)){
$err = mysql_error($new_connection);
@DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,"\n".$err, "FAILED");
msg_dialog::display(_("Error"),
msgPool::mysqlerror($err,__CLASS__)." ".
"\n
"._("Please activate debugging for details!")."
",
ERROR_DIALOG);
mysql_query("rollback;",$new_connection);
@DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,"rollback;", "ERROR Rollback transaction!");
@mysql_close($new_connection);
return(false);
}
}
/* Let changes get active, everything was fine;
*/
mysql_query("commit;",$new_connection);
@DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,"commit;", "Perform transaction!");
@DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,"---Transaction sucessful!---", "");
}
@mysql_close($new_connection);
return true;
}
function execute()
{
/* Call parent execute */
plugin::execute();
/* Log view */
if($this->is_account && !$this->view_logged){
$this->view_logged = TRUE;
new log("view","users/".get_class($this),$this->dn);
}
$display = "";
$SkipWrite = (!isset($this->parent) || !$this->parent) && !session::is_set('edit');
if(empty($this->macro)&&(!empty($this->goFonMacro))){
/* Go through already saved values, for a parameter */
$tmp = explode("!",$this->goFonMacro);
/* it is possible that nothing has been saved yet */
if(is_array($tmp)){
/* First value is the macroname */
$this->macro = $tmp[0];
/* Macroname saved, delete that index */
unset($tmp[0]);
/* Check if macro has been removed */
if(!isset($this->macroarray[$this->macro])){
$this->macrostillavailable = false;
}else{
$this->macrostillavailable = true;
}
/* for each parametervalues ( parameterID#value like 25#twentyfive) */
foreach($tmp as $var){
/* Split this, so we have $varar[0] = parameterID $varar[1] = SelectedValue */
$varar = explode("#",$var);
/* Only insert if the parameter still exists */
if(isset($this->macroarray[$this->macro][$varar[0]])){
/* Assign value */
$this->macroarray[$this->macro][$varar[0]]['choosen']=$varar[1];
}
}
}
}
/* Do we represent a valid account? */
if (!$this->is_account && $this->parent === NULL){
$display= "".
msgPool::noValidExtension(_("Phone"))."";
$display.= back_to_main();
return ($display);
}
/* Do we need to flip is_account state? */
if (isset($_POST['modify_state'])){
$this->is_account= !$this->is_account;
}
/* Do we represent a valid account? */
if (!$this->is_account && $this->parent === NULL){
$display= "".
msgPool::noValidExtension(_("Phone"))."";
$display.= back_to_main();
return($display);
}
$display= "";
/* Show tab dialog headers */
if (!$this->multiple_support_active && $this->parent !== NULL){
if ($this->is_account){
$display= $this->show_disable_header(_("Remove phone account"),
msgPool::featuresEnabled(_("Phone")));
} else {
if(empty($this->uid)){
$display= $this->show_enable_header(_("Create phone account"),
msgPool::featuresDisabled(_("Phone"),_("User UID")));
}else{
$display= $this->show_enable_header(_("Create phone account"),
msgPool::featuresDisabled(_("Phone")));
}
return ($display);
}
}
/* Select no macro if, state is empty, this is the case, if the selected macro is no longer available */
if(empty($this->macro)){
$this->macro ="none";
}
/* Prepare templating */
$smarty= get_smarty();
/* tell user that the selected plugin is no longer available */
if((!$this->macrostillavailable)&&($this->macro!="none")){
msg_dialog::display(_("Error"), _("Selected macro is not available anymore!"), ERROR_DIALOG);
}
/* Assing macroselectbox values */
$smarty->assign("macros",set_post($this->macros));
$smarty->assign("macro", set_post($this->macro));
/* Assign contexts */
$smarty->assign("voicemail_contexts", set_post($this->voicemail_contexts));
$smarty->assign("sip_contexts", set_post($this->sip_contexts));
$smarty->assign("context" , set_post($this->context));
$smarty->assign("voice_context" , set_post($this->voice_context));
/* check if there is a FON server created */
if(!count($this->goFonHomeServer)){
msg_dialog::display(_("Configuration error"), msgPool::noserver(_("GOfon")), WARNING_DIALOG);
}
/* Create html parameter table for selected macro parameters
* skip if no parameters given
*/
if(!isset($this->macroarray[$this->macro])){
$macrotab="";
}else{
$macrotab ="
";
/* for every single parameter-> display textfile,combo, or true false switch*/
foreach($this->phoneNumbers as $phonenum){
$tmp[] = $phonenum;
}
if($this->macro != $this->lastmacro){
/* Go through all params */
foreach($this->macroarray[$this->macro] as $key => $paras){
$string = $paras['default'];
$string=preg_replace("/%uid/i",$this->uid,$string);
$string=preg_replace("/%pager/i",$this->pager,$string);
$string=preg_replace("/%context/i",$this->context,$string);
$string=preg_replace("/%voicemailcontext/i",$this->voice_context,$string);
if(isset($this->cn)){
$string=preg_replace("/%cn/i",$this->cn,$string);
}
for($i = 0 ; $i < 10; $i++){
if(isset($tmp[$i])){
$string = preg_replace("/%telephoneNumber_".($i+1)."/i",$tmp[$i],$string);
}
}
if(isset($tmp[0])){
$string = preg_replace("/%telephoneNumber/i",$tmp[0],$string);
}
$this->macroarray[$this->macro][$key]['choosen']=$string;
}
}
foreach($this->macroarray[$this->macro] as $paras){
/* get al vars */
$var = $paras['var'];
$name = $paras['name'];
$default = $paras['default'];
$type = $paras['type'];
$choosen = $paras['choosen'] ;
$str = $default;
$dis = "";
if(!$this->acl_is_writeable("goFonMacro",$SkipWrite)){
$dis = " disabled ";
}
/* in case of a combo box display a combobox with selected attr */
$macrotab.= "
";
switch ($type){
case "combo":{
$str= "";
$macrotab.= "
{t}You are not allowed to view the macro parameter settings{/t}
{/if}
gosa-plugin-gofon-2.7.4/gofon/macro/macro-filter.xml 0000644 0001750 0001750 00000002063 11350165727 021402 0 ustar cajus cajus
gofonmacrotruedefaultautodnobjectClasscndescriptiondefaultLDAP(&(objectClass=goFonMacro)(|(cn=$)(displayName=$)))cn0.53visibleOnlyLDAP(&(objectClass=goFonMacro)(|(cn=$)(displayName=$))(goFonMacroVisible=1))cn0.53
gosa-plugin-gofon-2.7.4/gofon/macro/class_gofonMacroManagement.inc 0000644 0001750 0001750 00000004753 11424307323 024243 0 ustar cajus cajus config = $config;
$this->ui = $ui;
$this->storagePoints = array(get_ou("macro", "phoneMacroRDN"));
// Build filter
if (session::global_is_set(get_class($this)."_filter")){
$filter= session::global_get(get_class($this)."_filter");
} else {
$filter = new filter(get_template_path("macro-filter.xml", true));
$filter->setObjectStorage($this->storagePoints);
}
$this->setFilter($filter);
// Build headpage
$headpage = new listing(get_template_path("macro-list.xml", true));
$headpage->setFilter($filter);
// Add copy&paste and snapshot handler.
if ($this->config->boolValueIsTrue("core", "copyPaste")){
$this->cpHandler = new CopyPasteHandler($this->config);
}
if($this->config->get_cfg_value("core","enableSnapshots") == "true"){
$this->snapHandler = new SnapshotHandler($this->config);
}
parent::__construct($config, $ui, "macros", $headpage);
}
}
// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
?>
gosa-plugin-gofon-2.7.4/gofon/macro/tabs_macros.inc 0000644 0001750 0001750 00000002002 11424307331 021244 0 ustar cajus cajus addSpecialTabs();
}
function save($ignore_account= FALSE)
{
$baseobject= $this->by_object['macro'];
/* Check for new 'dn', in order to propagate the
'dn' to all plugins */
$cn = preg_replace('/,/', '\,', $baseobject->cn);
$cn = preg_replace('/"/', '\"', $cn);
$new_dn= @LDAP::convert("cn=".$cn.",".get_ou("macro", "phoneMacroRDN").$baseobject->base);
/* Move group? */
if ($this->dn != $new_dn){
/* Write entry on new 'dn' */
if ($this->dn != "new"){
$baseobject->move($this->dn, $new_dn);
$this->by_object['macro']= $baseobject;
}
/* Happen to use the new one */
$this->dn= $new_dn;
}
tabs::save();
}
}
?>
gosa-plugin-gofon-2.7.4/gofon/macro/generic.tpl 0000644 0001750 0001750 00000004051 11417300103 020407 0 ustar cajus cajus
{$must}
{render acl=$cnACL}
{/render}
{$must}
{render acl=$displayNameACL}
{/render}
{$must}
{render acl=$baseACL}
{$base}
{/render}
{render acl=$descriptionACL}
{/render}
{render acl=$goFonMacroVisibleACL}
{t}Visible for user{/t}
{/render}
{t}Macro text{/t}
{render acl=$goFonMacroContentACL}
{/render}
gosa-plugin-gofon-2.7.4/gofon/macro/class_gofonMacroParameters.inc 0000644 0001750 0001750 00000035005 11613742614 024272 0 ustar cajus cajus array("selected", "", ""),
"combo" => array("", "selected", ""),
"bool" => array("", "", "selected"));
/*! attribute list for save action */
var $attributes= array("base","goFonMacroParameter");
/*! Objectclasses needed by the class*/
var $objectclasses= array("top", "goFonMacro");
var $ui;
//! The konstructor of macroParameter
/*! The konstructor of macroParameter...
- reads goFonMacroParameter and parses them to an array
- Set attributes from openldap (edit)
- Set attributes from default (new)
*/
function macroParameter (&$config, $dn= NULL, $parent= NULL)
{
plugin::plugin ($config, $dn, $parent);
$tmp = array(); // temporary Var
$tmp2 = array(); // temporary Var ...
$tmp3 = "";
$ldap= $config->get_ldap_link();
$this->dn = $dn;
/* This is always an account */
$this->is_account= TRUE;
/* Edit or new one ?*/
if ($this->dn == "new"){
$ui= get_userinfo();
$this->base= dn2base($ui->dn);
} else {
$this->base= dn2base($this->dn);
}
/* initialising macro parameter */
if(isset($this->attrs['goFonMacroParameter']) &&
isset($this->attrs['goFonMacroParameter']['count'])){
unset($this->attrs['goFonMacroParameter']['count']);
}
/* Set Parameters, or a new array if ther are no parameters */
if(isset($this->attrs['goFonMacroParameter'])){
$this->goFonMacroParameter = $this->attrs['goFonMacroParameter'];
}else{
$this->goFonMacroParameter =array();
}
/* Create an array for parameters if not given yet */
if(!is_array($this->goFonMacroParameter)){
$tmp3 = $this->goFonMacroParameter;
$this->goFonMacroParameter =array();
if(!empty($tmp3)) {
$this->goFonMacroParameter[] = $tmp3;
}
}
/* Load parametersettings*/
foreach($this->goFonMacroParameter as $para){
$tmp = explode("!",$para);
$num = $tmp[0];
$tmp2[$num]['name'] = base64_decode($tmp[1]);
$tmp2[$num]['type'] = $tmp[2];
$tmp2[$num]['default'] = $tmp[3];
$tmp2[$num]['var'] = "var".$num;
}
/* Assign this array */
$this->goFonMacroParameter = $tmp2;
$this->para_count = count ($tmp2);
$this->ui= get_userinfo();
}
//! Perform Parameter check
/*!
Compares the given parameters (goFonMacroParameters) with the parameters defined in goFonContent\n
-> Decide which attrs are new and which are unused\n
-> Sort result array (containing both parameters 'goFonMacroParameters/goFonContent' and new / unused info)\n
\param $content The given goFonContent for this macro\n
\param $goFonMacroParameter Array with the already given parameters \n
*/
function check_paras($content,$goFonMacroParameter)
{
/* Check contents for parameters */
preg_match_all("/[$]\{ARG[0-9]*\}/",$content,$res,PREG_OFFSET_CAPTURE);
$new = array();
/* Detect parameters with positions */
foreach($res[0] as $val){
$num = preg_replace("/[^0-9]/","",$val[0]);
$new[$num]['val'] = $val[0];
$new[$num]['num'] = $num;
}
/* Compare content parameter and macro parameter */
foreach($goFonMacroParameter as $gokey => $goval){
foreach($new as $nkey => $nval){
if($gokey == $nval['num']){
/* sign this as OK */
$goFonMacroParameter[$gokey]['check']= true;
}
}
}
/* Now check if there is new parameter in the content, which is not assigned yet */
foreach($new as $key => $val){
/* Assign std values */
$goFonMacroParameter[$key]['var']="var".$key;
$goFonMacroParameter[$key]['check']= true;
/* If this is a new Parameter, name it ${ARG#} by default*/
if((!isset($goFonMacroParameter[$key]['name']))||(empty($goFonMacroParameter[$key]['name']))){
$goFonMacroParameter[$key]['name']="\${ARG".$key."}";
}
}
foreach($goFonMacroParameter as $key => $val){
/* All attributes with check == false, are unneeded so mark them with ['check']= false */
if(!isset($goFonMacroParameter[$key]['check'])){
$goFonMacroParameter[$key]['check']= false;
}
/* Ah no default given assign ="" to prevent unsigned index */
if(!isset($goFonMacroParameter[$key]['default'])){
$goFonMacroParameter[$key]['default'] = "";
}
}
/* Sort output for better reading */
asort($goFonMacroParameter);
return($goFonMacroParameter);
}
//! Execute this Plugin
/*!
Perform Parameter check \n
Draw paramter table\n
Show tpl \n
*/
function execute()
{
/* Call parent execute */
plugin::execute();
/* Variables */
$vars = "";
$tmp = array();
$number = 0;
/* Get acls for this tab,
there is only one attribute to write,
so we use the acls from gofon/marco */
if($this->is_new){
$ACLs = $this->ui->get_permissions($this->base,"gofonmacro/macro","goFonMacroContent");
}else{
$ACLs = $this->ui->get_permissions($this->dn,"gofonmacro/macro","goFonMacroContent");
}
/* get current content */
$content = $this->parent->by_object['macro']->goFonMacroContent;
if(strstr($content,"ARG")){
$vorpos = strpos($content,"ARG");
$rest = substr($content,$vorpos, strlen($content));
}
/* Do we represent a valid group? */
if (!$this->is_account && $this->parent === NULL){
$display= "".
msgPool::noValidExtension(_("Phone macro"))."";
return ($display);
}
/* Fill templating stuff */
$smarty= get_smarty();
/* Add an empty Parameter */
if(isset($_POST['addvar']) && preg_match("/w/",$ACLs)){
if(!is_array($this->goFonMacroParameter)){
$vars = $this->goFonMacroParameter;
$this->goFonMacroParameter = array();
$this->goFonMacroParameter[]= $vars;
}
$number= count($this->goFonMacroParameter);
$number++;
$this->goFonMacroParameter[]=array("var"=>"var","name"=>"new","type"=>"string","default"=>"test");
}
/*generate Table which shows als parameters */
$FonParas = $this->check_paras($content,$this->goFonMacroParameter);
/* Sort by Parameterid, and keep keys */
ksort($FonParas);
if(!preg_match("/r/",$ACLs)){
$smarty->assign("readable",false);
}else{
$smarty->assign("readable",true);
foreach($FonParas as $key=>$para) {
/* Select correct item of combobox */
if(isset($para['type'])){
list($sel1, $sel2, $sel3)= $this->type_shortcut[$para['type']];
}else{
list($sel1, $sel2, $sel3)= array("", "", "");
}
/* Disable all input fields if we are not allowed to change the parameters */
$disabled = "";
if(!preg_match("/w/",$ACLs)){
$key = "";
$disabled = " disabled ";
}
/* Assemble output table */
$vars .="
";
}
}
/* Checkboxes */
$smarty->assign("base_select", $this->base);
$smarty->assign("vars", $vars);
/* Show main page */
return($smarty->fetch (get_template_path('parameter.tpl', TRUE)));
}
//! Unused here
/*!
Unused here because goFonMacro will remove this Macro\n
*/
function remove_from_parent()
{
}
//! Save our data
/*!
Save POST data to object \n
This gives us the possibility to leave a tab, without losing our typed informations\n
\n
Read the POST fields for the parameters and saves their info the the class\n
*/
function save_object()
{
if (isset($_POST['phoneparameters'])){
plugin::save_object();
}
/* read out post data, and assign it to the parameters */
/* And or delete */
foreach($_POST as $name=>$value){
/* Test if there is a variable begining with "del" */
if(preg_match("/^del/",$name)){
/* Extract entry id to delete */
$nr = str_replace("del","",$name) ;
/* unset entry */
unset($this->goFonMacroParameter[$nr]);
}elseif(preg_match("/^number/",$name)){
/* Set Post vars */
$key = get_post($name);
$this->goFonMacroParameter[$key]['var'] = get_post("var".$key);
$this->goFonMacroParameter[$key]['name'] = get_post("varname".$key);
$this->goFonMacroParameter[$key]['type'] = get_post("vartype".$key);
$this->goFonMacroParameter[$key]['default']= get_post("default".$key);
}
}
}
//! Checks given values
/*!
Check values\n
If a user enters an invalid value, then this function will output an error msg\n
(In better words :prepare the errormessages that will be put out )\n
*/
function check()
{
/* Call common method to give check the hook */
$message= plugin::check();
foreach($this->goFonMacroParameter as $key=>$val){
$v1 = utf8_encode($val['default']);
$v2 = utf8_decode($val['default']);
if($v1 != $v2){
$allowed = preg_quote('[]()-+_,.;:/?*\ ','/');
$message[] = msgPool::invalid(sprintf(_("Parameter %s contains invalid character!"), $val['name']),
$val['default'],"/[a-z0-9{$allowed}]/i");
}
switch($val['type']){
case 'bool' : $possible = array("","0","1");
if(!in_array_strict($val['default'],$possible)) {
$message[] = sprintf(_("Parameter %s is invalid!"),$val['name']);
};break;
case 'string' :
case 'combo' :
default : ;
}
}
return $message;
}
//! Save changes to openldap
/*!
Save to LDAP
This function saves given attributes to the ldap
*/
function save()
{
/* Post checks */
plugin::save();
$this->attrs['goFonMacroParameter']=array();
foreach($this->goFonMacroParameter as $key=>$fonpara){
$this->attrs['goFonMacroParameter'][]=$key."!".base64_encode($fonpara['name'])."!".$fonpara['type']."!".$fonpara['default'];
}
if($this->para_count != count($this->attrs['goFonMacroParameter'])){
msg_dialog::display(_("Information"), _("Number of parameters for this macro has changed. Please update all users using it!"), INFO_DIALOG);
}
unset($this->attrs['base']);
/* Write back to ldap */
$ldap= $this->config->get_ldap_link();
$ldap->cat($this->dn, array('dn'));
$a= $ldap->fetch();
if (count($a)){
$ldap->cd($this->dn);
$this->cleanup();
$ldap->modify ($this->attrs);
$this->handle_post_events("modify");
} else {
if(count($this->attrs['goFonMacroParameter']==0)){
unset($this->attrs['goFonMacroParameter']);
}
$ldap->cd($this->dn);
$ldap->create_missing_trees( $this->dn);
$ldap->cd($this->dn);
$ldap->add($this->attrs);
$this->handle_post_events("add");
}
if (!$ldap->success()){
msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
}
}
function PrepareForCopyPaste($source)
{
plugin::PrepareForCopyPaste($source);
$source_o = new macroParameter($this->config,$source['dn']);
$this->goFonMacroParameter = $source_o-> goFonMacroParameter;
}
}
// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
?>
gosa-plugin-gofon-2.7.4/gofon/macro/paste_generic.tpl 0000644 0001750 0001750 00000000363 11352631662 021624 0 ustar cajus cajus
{$must}
gosa-plugin-gofon-2.7.4/gofon/macro/class_gofonMacro.inc 0000644 0001750 0001750 00000054660 11475226265 022263 0 ustar cajus cajus is_account= TRUE;
/* Edit or new one ?*/
if ($this->dn == "new"){
if(session::is_set('CurrentMainBase')){
$this->base = session::get('CurrentMainBase');
}else{
$ui= get_userinfo();
$this->base= dn2base($ui->dn);
}
} else {
$this->orig_cn=$this->cn;
$this->base= preg_replace ("/^[^,]+,".preg_quote(get_ou("macro", "phoneMacroRDN"), '/')."/i", "", $this->dn);
}
/* Check server configurations
* Load all server configuration in $this->goFonHomeServers if available
*/
$a_SETUP= array();
if(isset($config->data['SERVERS']['FON'])){
/* Set available server */
$this->goFonHomeServers = $config->data['SERVERS']['FON'];
/* Remove default entry, not necessary here */
if(isset($this->goFonHomeServers[0])){
unset($this->goFonHomeServers[0]);
}
}
$this->orig_base = $this->base;
$this->orig_dn = $this->dn;
/* Instanciate base selector */
$this->baseSelector= new baseSelector($this->get_allowed_bases(), $this->base);
$this->baseSelector->setSubmitButton(false);
$this->baseSelector->setHeight(300);
$this->baseSelector->update(true);
}
/*! Execute this plugin */
function execute()
{
/* Call parent execute */
plugin::execute();
/* Log view */
if($this->is_account && !$this->view_logged){
$this->view_logged = TRUE;
new log("view","gofonmacro/".get_class($this),$this->dn);
}
/* Variables */
$tmp = array();
$number = 0;
/* Fill templating stuff */
$smarty= get_smarty();
$tmp = $this->plInfo();
foreach($tmp['plProvidedAcls'] as $name => $translation){
$smarty->assign($name."ACL",$this->getacl($name));
}
if($this->acl_is_writeable("base")){
$smarty->assign("baseSelect",true);
}else{
$smarty->assign("baseSelect",false);
}
/* Assign all vars to Smarty */
foreach($this->attributes as $ar){
$smarty->assign($ar, set_post($this->$ar));
}
$smarty->assign("base", $this->baseSelector->render());
if($this->goFonMacroVisible){
$smarty->assign("goFonMacroVisibleChecked"," checked ");
}else{
$smarty->assign("goFonMacroVisibleChecked","");
}
$smarty->assign("cnACL",$this->getacl("cn",$this->initially_was_account));
$smarty->assign("cn",set_post($this->cn));
/* Ensure that macro content is displayed correctly encoded */
$smarty->assign("goFonMacroContent",set_post($this->goFonMacroContent));
/* Show main page */
return($smarty->fetch (get_template_path('generic.tpl', TRUE)));
}
/* This method check if all databases are reachable.
* Returns with error message or an empty string on success.
*
* - Is mysql extension available
* - Is every server reachable
* - Does the database exists/is accessible
*/
function check_database_accessibility()
{
/* Check if mysql extension is available */
if(!is_callable("mysql_pconnect")){
return(msgPool::missingext("php-mysql"));
}
/********************
* Check all home server
********************/
foreach($this->goFonHomeServers as $goFonHomeServer => $cfg_Current){
$r_current = @mysql_pconnect($cfg_Current['SERVER'],$cfg_Current['LOGIN'],$cfg_Current['PASSWORD']);
if(!$r_current){
new log("debug","gofonmacro/".get_class($this),"",array(),@mysql_error($r_current));
return ( msgPool::dbconnect("GOfon",@mysql_error(),$cfg_Current['SERVER']));
}
$db_current = @mysql_select_db($cfg_Current['DB'],$r_current);
if(!$db_current){
new log("debug","gofonmacro/".get_class($this),"",array(),@mysql_error($r_current));
mysql_close($r_current);
return ( msgPool::dbselect("GOfon",@mysql_error(),$cfg_Current['DB']));
}
}
}
/* Remove current macro from all asterisk server.
* First of all check if we have access to all databases.
* - Remove old entries
*/
function remove_from_database($save)
{
/* Check if all databases are reachable */
$str = $this->check_database_accessibility();
if($str){
return($str);
}
/* Create query string */
$context = addslashes("macro-".$this->cn);
/* Remove current macro from each server available */
if($save){
foreach($this->goFonHomeServers as $dn => $Server){
$query = "DELETE FROM ".$Server['EXT_TABLE']." WHERE context='".mysql_real_escape_string($context)."';";
$r_current = @mysql_pconnect($Server['SERVER'],$Server['LOGIN'],$Server['PASSWORD']);
$db_current = @mysql_select_db($Server['DB'],$r_current);
$res = @mysql_query($query,$r_current);
@DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,$query, "Database query");
if(!$res){
new log("debug","gofonmacro/".get_class($this),"",array(),@mysql_error($r_current));
@DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,"".$query."", "ERROR");
trigger_error(mysql_error($r_current));
return(
sprintf(
_("Macro could not be removed from server '%s', please check database consistency!"),
$Server['SERVER']));
}
@mysql_close($r_current);
}
}
}
/* Add current macro to all asterisk server.
* First of all check if we have access to all databases.
* - Remove old entries
* - Add new entries
*/
function add_to_database($save)
{
/* Check if all databases are reachable */
$str = $this->check_database_accessibility();
if($str){
return($str);
}
/* Remove old entries first. Else we got duplicated entries */
$str = $this->remove_from_database($save);
if($str){
return($str);
}
/* Create query string */
$context = "macro-".$this->cn;
/* Macro are spread to each asterisk server */
foreach($this->goFonHomeServers as $dn => $cfg){
$r_con = @mysql_pconnect($cfg['SERVER'],$cfg['LOGIN'],$cfg['PASSWORD']);
$db = @mysql_select_db($cfg['DB'],$r_con);
/************
* Parse Macro content
************/
$sql =
"INSERT INTO %TABLENAME% ".
" (context,exten,priority,app,appdata) ".
" VALUES ";
$a_contentLines = preg_split("/\n/",$this->goFonMacroContent);
// Keep all macro priorities to avoid duplicates!
$priorities = array();
foreach($a_contentLines as $i_linenum => $s_linestr){
/* Remove the 'exten => ' string in front of the macro content line
* example line 'exten => s,2,GotoIf(${ARG3}?3:5)'
* Remove comments introduced by ;
* Skip empty lines
*/
$s_linestr = trim($s_linestr);
$s_linestr = preg_replace("/;.*$/","",$s_linestr) ;
$s_linestr = preg_replace ("/^.*=\> /","",$s_linestr);
if(empty($s_linestr)){
continue;
}
/* A line that passes the check above should look like this
* s,1,SetLanguage(de)
* 3 parts seperated by ,
* If there are more or less parts, abort.
* The preg_replace exclude parameters from split ..
*/
$tmp = explode(",", $s_linestr,3);
/* Check if there is an application given */
if(!isset($tmp[2]) || $tmp[2] == ""){
return(sprintf(_("Application missing in line %s!"),$i_linenum));
}
if(!isset($tmp[1]) || $tmp[1] == ""){
return(sprintf(_("Priority missing in line %s!"),$i_linenum));
}
/* Check if there is an extension given */
if(!isset($tmp[0]) || $tmp[0] == ""){
return(sprintf(_("Extension missing in line %s!"),$i_linenum));
}
// Table 'extensions' has a primary key over the following fields
// 'context', 'exten' and 'priority' -
// Ensure that we do not write duplicates here.
$du = $context.$tmp[0].$tmp[1];
if(!isset($priorities[$du])){
$priorities[$du] = 1;
}else{
return(sprintf(_("Duplicate combination of 'extension' and 'priority' in line %s!"),$i_linenum));
}
/* Create extension entry for current line
* and add this line to an array that will be inserted
* to each database.
*/
$context= mysql_real_escape_string($context);
$exten = mysql_real_escape_string($tmp[0]);
$prio = mysql_real_escape_string($tmp[1]);
$app = mysql_real_escape_string(preg_replace("/\(.*\).*$/","",$tmp[2]));
$para = mysql_real_escape_string(preg_replace("/^[^(]*\((.*)\)[^)]*$/", "$1", $tmp[2]));
$sql.= " ('".$context."','".$exten."','".$prio."','".$app."','".$para."'),";
}
/* Remove last , from query string */
$sql = preg_replace("/,$/","",$sql);
/* Save current changes to the database */
$query = preg_replace("/%TABLENAME%/",$cfg['EXT_TABLE'],$sql);
if($save){
$res = @mysql_query($query,$r_con);
@DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,$query, "Database query");
if(!$res){
new log("debug","gofonmacro/".get_class($this),"",array(),@mysql_error($r_con));
@DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,"".$query."", "ERROR");
trigger_error(mysql_error($r_con));
return(
sprintf(
_("Macro could not be added to server '%s', please check database consistency!"),
$cfg['SERVER']));
}
}
@mysql_close($r_con);
}
}
function save_object()
{
if (isset($_POST['gofonMacroGenericPosted'])){
$old_cn = $this->cn;
$old_visible = $this->goFonMacroVisible;
/* Create a base backup and reset the
base directly after calling plugin::save_object();
Base will be set seperatly a few lines below */
$base_tmp = $this->base;
plugin::save_object();
$this->base = $base_tmp;
/* Refresh base */
if ($this->acl_is_moveable($this->base)){
if (!$this->baseSelector->update()) {
msg_dialog::display(_("Error"), msgPool::permMove(), ERROR_DIALOG);
}
if ($this->base != $this->baseSelector->getBase()) {
$this->base= $this->baseSelector->getBase();
$this->is_modified= TRUE;
}
}
/* Restore old cn if we have insuficient acls to change cn ... */
if(!$this->acl_is_writeable("cn",$this->initially_was_account)){
$this->cn = $old_cn;
}
/* check if we are allowed to toggle visibility */
if($this->acl_is_writeable("goFonMacroVisible")) {
/* Checkbox selected ? */
if(isset($_POST['goFonMacroVisible'])) {
$this->goFonMacroVisible= 1 ;
}else {
if(isset($_POST['displayName'])){
$this->goFonMacroVisible= 0 ;
}
}
}else{
$this->goFonMacroVisible = $old_visible;
}
}
}
/*! Check values */
function check()
{
/* Call common method to give check the hook */
$message= plugin::check();
if(!count($this->goFonHomeServers)){
$message[] = msgPool::noserver(_("GOfon"));
}
/* Check if insert/replace is possible and all servers are available */
$str = $this->add_to_database(false);
if($str){
$message[] = $str;
}
/* Check if cn is already used */
if(($this->dn=="new")||($this->orig_cn!=$this->cn)){
$ldap = $this->config->get_ldap_link();
$ldap->search("(&(objectClass=goFonMacro)(cn=".$this->cn."))",array("cn"));
if($ldap->count()>0){
$message[]= msgPool::duplicated(_("Name"));
}
}
// Check if a wrong base was supplied
if(!$this->baseSelector->checkLastBaseUpdate()){
$message[]= msgPool::check_base();;
}
/* Check if display name is set */
if($this->displayName == ""){
$message[] = msgPool::required(_("Name"));
}
/* CN is restricted to 20 chars */
if(strlen("Makro-".$this->cn)>20 ){
$message[]=_("Name can be 20 characters at maximum!");
}
/* If this macro is still in use we should not change the visible for user flag to invisible */
if(!$this->goFonMacroVisible){
$ldap = $this->config->get_ldap_link();
$res = $ldap->search("(&(objectClass=goFonAccount)(objectClass=gosaAccount)(goFonMacro=*))", array("goFonMacro"));
while ($val = $ldap->fetch()){
if(strstr($val['goFonMacro'][0],$this->dn)){
$message[] = _("Macro is still in use!");
return($message);
}
}
}
if(empty($this->goFonMacroContent)){
$message[] = _("Macro is empty!");
}
/* Check if we are allowed to create or move this object
*/
if($this->orig_dn == "new" && !$this->acl_is_createable($this->base)){
$message[] = msgPool::permCreate();
}elseif($this->orig_dn != "new" && $this->base != $this->orig_base && !$this->acl_is_moveable($this->base)){
$message[] = msgPool::permMove();
}
return $message;
}
/*! Remove makro from all given databases
* and ldap too.
*/
function remove_from_parent()
{
$ldap= $this->config->get_ldap_link();
/* Skip remove if this macro is still in use */
$res = $ldap->search("(&(objectClass=goFonAccount)(objectClass=gosaAccount)(goFonMacro=*))", array("goFonMacro", "cn"));
while ($val = $ldap->fetch()){
if(strstr($val['goFonMacro'][0],$this->dn)){
msg_dialog::display(_("Error"), sprintf(_("Cannot delete entry because it is still in use by '%s'!"), $val['cn'][0]), ERROR_DIALOG);
return false;
}
}
/* Try to remove from database */
if(count($this->goFonHomeServers)){
$str = $this->remove_from_database(true);
if($str){
msg_dialog::display(_("Error"), $str, ERROR_DIALOG);
return false;
}
}else{
msg_dialog::display(_("Configuration error"), msgPool::noserver(_("GOfon")), WARNING_DIALOG);
return false;
}
/* Remove phone macro */
$ldap->rmDir($this->dn);
new log("remove","gofonmacro/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
if (!$ldap->success()){
msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class()));
}
/* Delete references to object groups */
$ldap->cd ($this->config->current['BASE']);
$ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".LDAP::prepare4filter($this->dn)."))", array("cn"));
while ($ldap->fetch()){
$og= new ogroup($this->config, $ldap->getDN());
unset($og->member[$this->dn]);
$og->save ();
if (!$ldap->success()){
msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
}
}
}
/*! Save to LDAP */
function save()
{
plugin::save();
unset($this->attrs['base']);
/* Try to add entries to databases */
$str = $this->add_to_database(true);
if($str){
msg_dialog::display(_("Error"), $str, ERROR_DIALOG);
}
/* Write back to ldap */
$ldap= $this->config->get_ldap_link();
$ldap->cat($this->dn, array('dn'));
$a= $ldap->fetch();
if (count($a)){
$ldap->cd($this->dn);
$this->cleanup();
$ldap->modify ($this->attrs);
$this->handle_post_events("modify");
} else {
$ldap->cd($this->config->current['BASE']);
$ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
$ldap->cd($this->dn);
$ldap->add($this->attrs);
$this->handle_post_events("add");
}
if (!$ldap->success()){
msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
}
/* Log last action */
if($this->initially_was_account){
new log("modify","gofonmacro/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
}else{
new log("create","gofonmacro/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
}
}
function getCopyDialog()
{
$smarty = get_smarty();
$smarty->assign("cn" ,set_post($this->cn));
$str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE));
$ret = array();
$ret['string'] = $str;
$ret['status'] = "";
return($ret);
}
function saveCopyDialog()
{
if(isset($_POST['cn'])){
$this->cn = get_post('cn');
}
}
static function plInfo()
{
return (array(
"plShortName" => _("Generic"),
"plDescription" => _("Asterisk macro management"),
"plSelfModify" => FALSE,
"plDepends" => array(),
"plPriority" => 0,
"plSection" => array("administration"),
"plRequirements"=> array(
'ldapSchema' => array('goFonMacro' => '>=2.7'),
'onFailureDisablePlugin' => array(get_class(),'phoneAccount','phoneConferenceManagment','goFonMacro')
),
"plCategory" => array("gofonmacro" => array("description" => _("GOfon macro"),
"objectClass" => "goFonMacro")),
"plProperties" =>
array(
array(
"name" => "phoneMacroRDN",
"type" => "rdn",
"default" => "ou=macros,ou=asterisk,ou=configs,ou=systems,",
"description" => _("RDN for macro storage."),
"check" => "gosaProperty::isRdn",
"migrate" => "migrate_phoneMacroRDN",
"group" => "plugin",
"mandatory" => FALSE
)
),
"plProvidedAcls" => array(
"cn" => _("Macro name"),
"base" => _("Base"),
"description" => _("Description"),
"displayName" => _("Display name"),
"goFonMacroContent" => _("Macro content and parameter"),
"goFonMacroVisible" => _("Visibility flag"))
));
}
}
// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
?>
gosa-plugin-gofon-2.7.4/gofon/macro/remove.tpl 0000644 0001750 0001750 00000001030 11350162633 020274 0 ustar cajus cajus