directory.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  1. <?php
  2. /*
  3. FusionPBX
  4. Version: MPL 1.1
  5. The contents of this file are subject to the Mozilla Public License Version
  6. 1.1 (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.mozilla.org/MPL/
  9. Software distributed under the License is distributed on an "AS IS" basis,
  10. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11. for the specific language governing rights and limitations under the
  12. License.
  13. The Original Code is FusionPBX
  14. The Initial Developer of the Original Code is
  15. Mark J Crane <[email protected]>
  16. Copyright (C) 2010
  17. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <[email protected]>
  20. */
  21. include "root.php";
  22. //define the directory class
  23. class switch_directory {
  24. public $domain_uuid;
  25. public $domain_name;
  26. public $db_type;
  27. public $extension;
  28. public $number_alias;
  29. public $password;
  30. public $vm_password;
  31. public $accountcode;
  32. public $effective_caller_id_name;
  33. public $effective_caller_id_number;
  34. public $outbound_caller_id_name;
  35. public $outbound_caller_id_number;
  36. public $limit_max=5;
  37. public $limit_destination;
  38. public $vm_enabled=1;
  39. public $vm_mailto;
  40. public $vm_attach_file;
  41. public $vm_keep_local_after_email;
  42. public $user_context;
  43. public $range;
  44. public $autogen_users;
  45. public $toll_allow;
  46. public $call_group;
  47. public $hold_music;
  48. public $auth_acl;
  49. public $cidr;
  50. public $sip_force_contact;
  51. public $sip_force_expires;
  52. public $nibble_account;
  53. public $mwi_account;
  54. public $sip_bypass_media;
  55. public $enabled;
  56. public $description;
  57. // get domain_uuid
  58. public function get_domain_uuid() {
  59. return $this->domain_uuid;
  60. }
  61. // set domain_uuid
  62. public function set_domain_uuid($domain_uuid){
  63. $this->domain_uuid = $domain_uuid;
  64. }
  65. // get domain_name
  66. public function get_domain_name() {
  67. return $this->domain_name;
  68. }
  69. // set domain_name
  70. public function set_domain_name($domain_name){
  71. $this->domain_name = $domain_name;
  72. }
  73. // get db_type
  74. public function get_db_type() {
  75. return $this->db_type;
  76. }
  77. // set db_type
  78. public function set_db_type($db_type){
  79. $this->db_type = $db_type;
  80. }
  81. // get extension
  82. public function get_extension() {
  83. return $this->extension;
  84. }
  85. // set extension
  86. public function set_extension($extension){
  87. $this->extension = $extension;
  88. }
  89. public function add() {
  90. global $db;
  91. $domain_uuid = $this->domain_uuid;
  92. $domain_name = $this->domain_name;
  93. $extension = $this->extension;
  94. $number_alias = $this->number_alias;
  95. $password = $this->password;
  96. $autogen_users = $this->autogen_users;
  97. $provisioning_list = $this->provisioning_list;
  98. $vm_password = $this->vm_password;
  99. $accountcode = $this->accountcode;
  100. $effective_caller_id_name = $this->effective_caller_id_name;
  101. $effective_caller_id_number = $this->effective_caller_id_number;
  102. $outbound_caller_id_name = $this->outbound_caller_id_name;
  103. $outbound_caller_id_number = $this->outbound_caller_id_number;
  104. $limit_max = $this->limit_max;
  105. $limit_destination = $this->limit_destination;
  106. $vm_enabled = $this->vm_enabled;
  107. $vm_mailto = $this->vm_mailto;
  108. $vm_attach_file = $this->vm_attach_file;
  109. $vm_keep_local_after_email = $this->vm_keep_local_after_email;
  110. $user_context = $this->user_context;
  111. $toll_allow = $this->toll_allow;
  112. $call_group = $this->call_group;
  113. $hold_music = $this->hold_music;
  114. $auth_acl = $this->auth_acl;
  115. $cidr = $this->cidr;
  116. $sip_force_contact = $this->sip_force_contact;
  117. $sip_force_expires = $this->sip_force_expires;
  118. $nibble_account = $this->nibble_account;
  119. $mwi_account = $this->mwi_account;
  120. $sip_bypass_media = $this->sip_bypass_media;
  121. $enabled = $this->enabled;
  122. $description = $this->description;
  123. $db->beginTransaction();
  124. for ($i=1; $i<=$range; $i++) {
  125. if (extension_exists($extension)) {
  126. //extension exists
  127. }
  128. else {
  129. //extension does not exist add it
  130. $password = generate_password();
  131. $sql = "insert into v_extensions ";
  132. $sql .= "(";
  133. $sql .= "domain_uuid, ";
  134. $sql .= "extension_uuid, ";
  135. $sql .= "extension, ";
  136. $sql .= "number_alias, ";
  137. $sql .= "password, ";
  138. $sql .= "provisioning_list, ";
  139. $sql .= "vm_password, ";
  140. $sql .= "accountcode, ";
  141. $sql .= "effective_caller_id_name, ";
  142. $sql .= "effective_caller_id_number, ";
  143. $sql .= "outbound_caller_id_name, ";
  144. $sql .= "outbound_caller_id_number, ";
  145. $sql .= "limit_max, ";
  146. $sql .= "limit_destination, ";
  147. $sql .= "vm_enabled, ";
  148. $sql .= "vm_mailto, ";
  149. $sql .= "vm_attach_file, ";
  150. $sql .= "vm_keep_local_after_email, ";
  151. $sql .= "user_context, ";
  152. $sql .= "toll_allow, ";
  153. $sql .= "call_group, ";
  154. $sql .= "hold_music, ";
  155. $sql .= "auth_acl, ";
  156. $sql .= "cidr, ";
  157. $sql .= "sip_force_contact, ";
  158. if (strlen($sip_force_expires) > 0) {
  159. $sql .= "sip_force_expires, ";
  160. }
  161. if (strlen($nibble_account) > 0) {
  162. $sql .= "nibble_account, ";
  163. }
  164. if (strlen($mwi_account) > 0) {
  165. $sql .= "mwi_account, ";
  166. }
  167. $sql .= "sip_bypass_media, ";
  168. $sql .= "enabled, ";
  169. $sql .= "description ";
  170. $sql .= ")";
  171. $sql .= "values ";
  172. $sql .= "(";
  173. $sql .= "'$domain_uuid', ";
  174. $sql .= "'$extension_uuid', ";
  175. $sql .= "'$extension', ";
  176. $sql .= "'$number_alias', ";
  177. $sql .= "'$password', ";
  178. $sql .= "'$provisioning_list', ";
  179. $sql .= "'user-choose', ";
  180. $sql .= "'$accountcode', ";
  181. $sql .= "'$effective_caller_id_name', ";
  182. $sql .= "'$effective_caller_id_number', ";
  183. $sql .= "'$outbound_caller_id_name', ";
  184. $sql .= "'$outbound_caller_id_number', ";
  185. $sql .= "'$limit_max', ";
  186. $sql .= "'$limit_destination', ";
  187. $sql .= "'$vm_enabled', ";
  188. $sql .= "'$vm_mailto', ";
  189. $sql .= "'$vm_attach_file', ";
  190. $sql .= "'$vm_keep_local_after_email', ";
  191. $sql .= "'$user_context', ";
  192. $sql .= "'$toll_allow', ";
  193. $sql .= "'$call_group', ";
  194. $sql .= "'$hold_music', ";
  195. $sql .= "'$auth_acl', ";
  196. $sql .= "'$cidr', ";
  197. $sql .= "'$sip_force_contact', ";
  198. if (strlen($sip_force_expires) > 0) {
  199. $sql .= "'$sip_force_expires', ";
  200. }
  201. if (strlen($nibble_account) > 0) {
  202. $sql .= "'$nibble_account', ";
  203. }
  204. if (strlen($mwi_account) > 0) {
  205. if (strpos($mwi_account, '@') === false) {
  206. if (count($_SESSION["domains"]) > 1) {
  207. $mwi_account .= "@".$domain_name;
  208. }
  209. else {
  210. $mwi_account .= "@\$\${domain}";
  211. }
  212. }
  213. $sql .= "'$mwi_account', ";
  214. }
  215. $sql .= "'$sip_bypass_media', ";
  216. $sql .= "'$enabled', ";
  217. $sql .= "'$description' ";
  218. $sql .= ")";
  219. $db->exec(check_sql($sql));
  220. unset($sql);
  221. }
  222. $extension++;
  223. }
  224. $db->commit();
  225. }
  226. public function update() {
  227. global $db;
  228. $domain_uuid = $this->domain_uuid;
  229. $domain_name = $this->domain_name;
  230. $extension = $this->extension;
  231. $number_alias = $this->number_alias;
  232. $password = $this->password;
  233. $autogen_users = $this->autogen_users;
  234. $provisioning_list = $this->provisioning_list;
  235. $vm_password = $this->vm_password;
  236. $accountcode = $this->accountcode;
  237. $effective_caller_id_name = $this->effective_caller_id_name;
  238. $effective_caller_id_number = $this->effective_caller_id_number;
  239. $outbound_caller_id_name = $this->outbound_caller_id_name;
  240. $outbound_caller_id_number = $this->outbound_caller_id_number;
  241. $limit_max = $this->limit_max;
  242. $limit_destination = $this->limit_destination;
  243. $vm_enabled = $this->vm_enabled;
  244. $vm_mailto = $this->vm_mailto;
  245. $vm_attach_file = $this->vm_attach_file;
  246. $vm_keep_local_after_email = $this->vm_keep_local_after_email;
  247. $user_context = $this->user_context;
  248. $toll_allow = $this->toll_allow;
  249. $call_group = $this->call_group;
  250. $hold_music = $this->hold_music;
  251. $auth_acl = $this->auth_acl;
  252. $cidr = $this->cidr;
  253. $sip_force_contact = $this->sip_force_contact;
  254. $sip_force_expires = $this->sip_force_expires;
  255. $nibble_account = $this->nibble_account;
  256. $mwi_account = $this->mwi_account;
  257. $sip_bypass_media = $this->sip_bypass_media;
  258. $enabled = $this->enabled;
  259. $description = $this->description;
  260. //$user_list_array = explode("|", $user_list);
  261. //foreach($user_list_array as $tmp_user){
  262. // $user_password = generate_password();
  263. // if (strlen($tmp_user) > 0) {
  264. // user_add($tmp_user, $user_password, $user_email);
  265. // }
  266. //}
  267. //unset($tmp_user);
  268. if (strlen($password) == 0) {
  269. $password = generate_password();
  270. }
  271. $sql = "update v_extensions set ";
  272. $sql .= "extension = '$extension', ";
  273. $sql .= "number_alias = '$number_alias', ";
  274. $sql .= "password = '$password', ";
  275. $sql .= "provisioning_list = '$provisioning_list', ";
  276. if (strlen($vm_password) > 0) {
  277. $sql .= "vm_password = '$vm_password', ";
  278. }
  279. else {
  280. $sql .= "vm_password = 'user-choose', ";
  281. }
  282. $sql .= "accountcode = '$accountcode', ";
  283. $sql .= "effective_caller_id_name = '$effective_caller_id_name', ";
  284. $sql .= "effective_caller_id_number = '$effective_caller_id_number', ";
  285. $sql .= "outbound_caller_id_name = '$outbound_caller_id_name', ";
  286. $sql .= "outbound_caller_id_number = '$outbound_caller_id_number', ";
  287. $sql .= "limit_max = '$limit_max', ";
  288. $sql .= "limit_destination = '$limit_destination', ";
  289. $sql .= "vm_enabled = '$vm_enabled', ";
  290. $sql .= "vm_mailto = '$vm_mailto', ";
  291. $sql .= "vm_attach_file = '$vm_attach_file', ";
  292. $sql .= "vm_keep_local_after_email = '$vm_keep_local_after_email', ";
  293. $sql .= "user_context = '$user_context', ";
  294. $sql .= "toll_allow = '$toll_allow', ";
  295. $sql .= "call_group = '$call_group', ";
  296. $sql .= "hold_music = '$hold_music', ";
  297. $sql .= "auth_acl = '$auth_acl', ";
  298. $sql .= "cidr = '$cidr', ";
  299. $sql .= "sip_force_contact = '$sip_force_contact', ";
  300. if (strlen($sip_force_expires) == 0) {
  301. $sql .= "sip_force_expires = null, ";
  302. }
  303. else {
  304. $sql .= "sip_force_expires = '$sip_force_expires', ";
  305. }
  306. if (strlen($nibble_account) == 0) {
  307. $sql .= "nibble_account = null, ";
  308. }
  309. else {
  310. $sql .= "nibble_account = '$nibble_account', ";
  311. }
  312. if (strlen($mwi_account) > 0) {
  313. if (strpos($mwi_account, '@') === false) {
  314. if (count($_SESSION["domains"]) > 1) {
  315. $mwi_account .= "@".$domain_name;
  316. }
  317. else {
  318. $mwi_account .= "@\$\${domain}";
  319. }
  320. }
  321. }
  322. $sql .= "mwi_account = '$mwi_account', ";
  323. $sql .= "sip_bypass_media = '$sip_bypass_media', ";
  324. $sql .= "enabled = '$enabled', ";
  325. $sql .= "description = '$description' ";
  326. $sql .= "where domain_uuid = '$domain_uuid' ";
  327. $sql .= "and extension_uuid = '$extension_uuid'";
  328. $db->exec(check_sql($sql));
  329. unset($sql);
  330. }
  331. function delete() {
  332. global $db;
  333. $domain_uuid = $this->domain_uuid;
  334. $extension_uuid = $this->extension_uuid;
  335. if (strlen($extension_uuid)>0) {
  336. $sql = "delete from v_extensions ";
  337. $sql .= "where domain_uuid = '$domain_uuid' ";
  338. $sql .= "and extension_uuid = '$extension_uuid' ";
  339. $prep_statement = $db->prepare(check_sql($sql));
  340. $prep_statement->execute();
  341. unset($sql);
  342. }
  343. }
  344. function import_sql($data){
  345. $count=count($data);
  346. $keys=$values=SplFixedArray($count);
  347. $keys=array_keys($data);
  348. $values=array_values($data);
  349. for($i=0;$i<$count;$i++){
  350. $keys[$i]= str_replace("-", "_", $keys[$i]);
  351. $this->{$keys[$i]}=$values[$i];
  352. }
  353. }
  354. function set_bool(&$var,$default=null){
  355. $var=strtolower($var);
  356. if ($var==="true") return;
  357. elseif ($var==="false") return;
  358. elseif ($var==true) $var="true";
  359. elseif ($var==false) $var="false";
  360. elseif(!is_null($default)) {
  361. $var=$default;
  362. $this->set_bool($var);
  363. }
  364. }
  365. function generate_xml($single=1){
  366. //switch_account_code!! How should we be passing this??
  367. if ($this->enabled== "false" || !$this->enabled) {
  368. return false;//This the best way??
  369. }
  370. $this->vm_password = str_replace("#", "", $this->vm_password); //preserves leading zeros//**Generic Validation!
  371. /*if(!in_array($this->vm_enabled,array("false","true"))) {//**Generic Validation!
  372. $this->vm_enabled = "true";
  373. }
  374. if(!in_array($this->vm_attach_file,array("false","true"))) {//**Generic Validation!
  375. $this->vm_attach_file = "true";
  376. }
  377. if(!in_array($this->vm_keep_local_after_email,array("false","true"))) {//**Generic Validation!
  378. $this->vm_keep_local_after_email = "true";
  379. }
  380. */
  381. $this->set_bool($this->vm_enabled,1);
  382. $this->set_bool($this->vm_attach_file,1);
  383. $this->set_bool($this->vm_keep_local_after_email,1);
  384. //remove invalid characters from the file names //**Generic Validation!
  385. $this->extension = str_replace(" ", "_", $this->extension);
  386. $this->extension = preg_replace("/[\*\:\\/\<\>\|\'\"\?]/", "", $this->extension);
  387. /*if (!$extension_xml_condensed) { <--- what do I do with this??
  388. $fout = fopen($_SESSION['switch']['extensions']['dir']."/v_".$extension.".xml","w");
  389. $xml .= "<include>\n";
  390. }*/
  391. if (strlen($this->cidr)) {
  392. $this->cidr = " cidr=\"" . $this->cidr . "\"";
  393. }
  394. if (strlen($this->number_alias)) {
  395. $this->number_alias = " number-alias=\"".$this->number_alias."\"";
  396. }
  397. if($single) $xml = "<include>\n";
  398. else $xml = "";
  399. $xml .= " <user id=\"".$this->extension."\"".$this->cidr."".$this->number_alias.">\n";
  400. $xml .= " <params>\n";
  401. $xml .= " <param name=\"password\" value=\"" . $this->password . "\"/>\n";
  402. $xml .= " <param name=\"vm-enabled\" value=\"".$this->vm_enabled."\"/>\n";
  403. if ($this->vm_enabled=="true"){
  404. $xml .= " <param name=\"vm-password\" value=\"" . $this->vm_password . "\"/>\n";
  405. if(strlen($this->vm_mailto)) {
  406. $xml .= " <param name=\"vm-email-all-messages\" value=\"true\"/>\n";
  407. $xml .= " <param name=\"vm-attach-file\" value=\"".$this->vm_attach_file."\"/>\n";
  408. $xml .= " <param name=\"vm-keep-local-after-email\" value=\"".$this->vm_keep_local_after_email."\"/>\n";
  409. $xml .= " <param name=\"vm-mailto\" value=\"" . $this->vm_mailto . "\"/>\n";
  410. }
  411. }
  412. if (strlen($this->mwi_account)) {
  413. $xml .= " <param name=\"MWI-Account\" value=\"" . $this->mwi_account . "\"/>\n";
  414. }
  415. if (strlen($this->auth_acl)) {
  416. $xml .= " <param name=\"auth-acl\" value=\"" . $this->auth_acl . "\"/>\n";
  417. }
  418. $xml .= " </params>\n";
  419. $xml .= " <variables>\n";
  420. if (strlen($this->hold_music)) {
  421. $xml .= " <variable name=\"hold_music\" value=\"" . $this->hold_music . "\"/>\n";
  422. }
  423. if (strlen($this->toll_allow)){
  424. $xml .= " <variable name=\"toll_allow\" value=\"" . $this->toll_allow . "\"/>\n";
  425. }
  426. if (strlen($this->accountcode)){
  427. $xml .= " <variable name=\"accountcode\" value=\"" . $this->accountcode . "\"/>\n";
  428. }
  429. $xml .= " <variable name=\"user_context\" value=\"" . $this->user_context . "\"/>\n";
  430. if (strlen($this->effective_caller_id_name)) {
  431. $xml .= " <variable name=\"effective_caller_id_name\" value=\"" . $this->effective_caller_id_name . "\"/>\n";
  432. }
  433. if (strlen($this->outbound_caller_id_number)) {
  434. $xml .= " <variable name=\"effective_caller_id_number\" value=\"" . $this->effective_caller_id_number . "\"/>\n";
  435. }
  436. if (strlen($this->outbound_caller_id_name)) {
  437. $xml .= " <variable name=\"outbound_caller_id_name\" value=\"" . $this->outbound_caller_id_name . "\"/>\n";
  438. }
  439. if (strlen($this->outbound_caller_id_number)) {
  440. $xml .= " <variable name=\"outbound_caller_id_number\" value=\"" . $this->outbound_caller_id_number . "\"/>\n";
  441. }
  442. if (!strlen($this->limit_max)) {//**validation
  443. $this->limit_max=5;
  444. }
  445. $xml .= " <variable name=\"limit_max\" value=\"" . $this->limit_max . "\"/>\n";
  446. if (strlen($this->limit_destination)) {
  447. $xml .= " <variable name=\"limit_destination\" value=\"" . $this->limit_destination . "\"/>\n";
  448. }
  449. if (strlen($this->sip_force_contact)) {
  450. $xml .= " <variable name=\"sip-force-contact\" value=\"" . $this->sip_force_contact . "\"/>\n";
  451. }
  452. if (strlen($this->sip_force_expires)) {
  453. $xml .= " <variable name=\"sip-force-expires\" value=\"" . $this->sip_force_expires . "\"/>\n";
  454. }
  455. if (strlen($this->nibble_account)) {
  456. $xml .= " <variable name=\"nibble_account\" value=\"" . $this->nibble_account . "\"/>\n";
  457. }
  458. switch ($this->sip_bypass_media) {
  459. case "bypass-media":
  460. $xml .= " <variable name=\"bypass_media\" value=\"true\"/>\n";
  461. break;
  462. case "bypass-media-after-bridge":
  463. $xml .= " <variable name=\"bypass_media_after_bridge\" value=\"true\"/>\n";
  464. break;
  465. case "proxy-media":
  466. $xml .= " <variable name=\"proxy_media\" value=\"true\"/>\n";
  467. break;
  468. }
  469. $xml .= " </variables>\n";
  470. $xml .= " </user>\n";
  471. if($single) { $xml .= "</include>\n"; }
  472. return $xml;
  473. }
  474. function xml_save_all() {
  475. global $db, $config;
  476. $domain_uuid = $this->domain_uuid;
  477. $domain_name = $this->domain_name;
  478. //get the system settings paths and set them as variables
  479. $settings_array = v_settings();
  480. foreach($settings_array as $name => $value) {
  481. $$name = $value;
  482. }
  483. //determine the extensions parent directory
  484. $extension_parent_dir = realpath($_SESSION['switch']['extensions']['dir']."/..");
  485. // delete all old extensions to prepare for new ones
  486. if($dh = opendir($_SESSION['switch']['extensions']['dir'])) {
  487. $files = Array();
  488. while($file = readdir($dh)) {
  489. if($file != "." && $file != ".." && $file[0] != '.') {
  490. if(is_dir($dir . "/" . $file)) {
  491. //this is a directory do nothing
  492. } else {
  493. //check if file is an extension; verify the file numeric and the extension is xml
  494. if (substr($file,0,2) == 'v_' && substr($file,-4) == '.xml') {
  495. unlink($_SESSION['switch']['extensions']['dir']."/".$file);
  496. }
  497. }
  498. }
  499. }
  500. closedir($dh);
  501. }
  502. $sql = "select * from v_extensions ";
  503. $sql .= "where domain_uuid = '$domain_uuid' ";
  504. $sql .= "order by call_group asc ";
  505. $prep_statement = $db->prepare(check_sql($sql));
  506. $prep_statement->execute();
  507. $i = 0;
  508. $extension_xml_condensed = false;
  509. if ($extension_xml_condensed) {
  510. $fout = fopen($_SESSION['switch']['extensions']['dir']."/v_extensions.xml","w");
  511. $xml = "<include>\n";
  512. }
  513. while($row = $prep_statement->fetch(PDO::FETCH_ASSOC)) {
  514. $call_group = $row['call_group'];
  515. $call_group = str_replace(";", ",", $call_group);
  516. $tmp_array = explode(",", $call_group);
  517. foreach ($tmp_array as &$tmp_call_group) {
  518. if (strlen($tmp_call_group) > 0) {
  519. if (strlen($call_group_array[$tmp_call_group]) == 0) {
  520. $call_group_array[$tmp_call_group] = $row['extension'];
  521. }
  522. else {
  523. $call_group_array[$tmp_call_group] = $call_group_array[$tmp_call_group].','.$row['extension'];
  524. }
  525. }
  526. $i++;
  527. }
  528. if ($row['enabled'] != "false") {
  529. //$this->import_sql($row);//Do I need to be worried about ghost values? Maybe I should make a new object?
  530. //if (strlen($switch_account_code)) $this->accountcode=$switch_account_code;
  531. //$xml.=$this->generate_xml(1);
  532. $one_row=new fs_directory;
  533. $one_row->import_sql($row);//make a new object to flush ghost rows. And we can call this as static.
  534. if (strlen($switch_account_code)) $one_row->accountcode=$switch_account_code;
  535. $xml.=$one_row->generate_xml(false);
  536. if (!$extension_xml_condensed) {
  537. $xml .= "</include>\n";
  538. fwrite($fout, $xml);
  539. unset($xml);
  540. fclose($fout);
  541. }
  542. }
  543. }
  544. unset ($prep_statement);
  545. if ($extension_xml_condensed) {
  546. $xml .= "</include>\n";
  547. fwrite($fout, $xml);
  548. unset($xml);
  549. fclose($fout);
  550. }
  551. //define the group members
  552. $xml = "<!--\n";
  553. $xml .= " NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE\n";
  554. $xml .= "\n";
  555. $xml .= " FreeSWITCH works off the concept of users and domains just like email.\n";
  556. $xml .= " You have users that are in domains for example [email protected].\n";
  557. $xml .= "\n";
  558. $xml .= " When freeswitch gets a register packet it looks for the user in the directory\n";
  559. $xml .= " based on the from or to domain in the packet depending on how your sofia profile\n";
  560. $xml .= " is configured. Out of the box the default domain will be the IP address of the\n";
  561. $xml .= " machine running FreeSWITCH. This IP can be found by typing \"sofia status\" at the\n";
  562. $xml .= " CLI. You will register your phones to the IP and not the hostname by default.\n";
  563. $xml .= " If you wish to register using the domain please open vars.xml in the root conf\n";
  564. $xml .= " directory and set the default domain to the hostname you desire. Then you would\n";
  565. $xml .= " use the domain name in the client instead of the IP address to register\n";
  566. $xml .= " with FreeSWITCH.\n";
  567. $xml .= "\n";
  568. $xml .= " NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE\n";
  569. $xml .= "-->\n";
  570. $xml .= "\n";
  571. $xml .= "<include>\n";
  572. $xml .= " <!--the domain or ip (the right hand side of the @ in the addr-->\n";
  573. if ($extension_dir_name == "default") {
  574. $xml .= " <domain name=\"\$\${domain}\">\n";
  575. }
  576. else {
  577. $xml .= " <domain name=\"".$extension_dir_name."\">\n";
  578. }
  579. $xml .= " <params>\n";
  580. //$xml .= " <param name=\"dial-string\" value=\"{sip_invite_domain=\${domain_name},presence_id=\${dialed_user}@\${dialed_domain}}\${sofia_contact(\${dialed_user}@\${dialed_domain})}\"/>\n";
  581. $xml .= " </params>\n";
  582. $xml .= "\n";
  583. $xml .= " <variables>\n";
  584. $xml .= " <variable name=\"record_stereo\" value=\"true\"/>\n";
  585. $xml .= " <variable name=\"default_gateway\" value=\"\$\${default_provider}\"/>\n";
  586. $xml .= " <variable name=\"default_areacode\" value=\"\$\${default_areacode}\"/>\n";
  587. $xml .= " <variable name=\"transfer_fallback_extension\" value=\"operator\"/>\n";
  588. $xml .= " <variable name=\"export_vars\" value=\"domain_name\"/>\n";
  589. $xml .= " </variables>\n";
  590. $xml .= "\n";
  591. $xml .= " <groups>\n";
  592. $xml .= " <group name=\"".$extension_dir_name."\">\n";
  593. $xml .= " <users>\n";
  594. $xml .= " <X-PRE-PROCESS cmd=\"include\" data=\"".$extension_dir_name."/*.xml\"/>\n";
  595. $xml .= " </users>\n";
  596. $xml .= " </group>\n";
  597. $xml .= "\n";
  598. $previous_call_group = "";
  599. foreach ($call_group_array as $key => $value) {
  600. $call_group = $key;
  601. $extension_list = $value;
  602. if (strlen($call_group) > 0) {
  603. if ($previous_call_group != $call_group) {
  604. $xml .= " <group name=\"$call_group\">\n";
  605. $xml .= " <users>\n";
  606. $xml .= " <!--\n";
  607. $xml .= " type=\"pointer\" is a pointer so you can have the\n";
  608. $xml .= " same user in multiple groups. It basically means\n";
  609. $xml .= " to keep searching for the user in the directory.\n";
  610. $xml .= " -->\n";
  611. $extension_array = explode(",", $extension_list);
  612. foreach ($extension_array as &$tmp_extension) {
  613. $xml .= " <user id=\"$tmp_extension\" type=\"pointer\"/>\n";
  614. }
  615. $xml .= " </users>\n";
  616. $xml .= " </group>\n";
  617. $xml .= "\n";
  618. }
  619. $previous_call_group = $call_group;
  620. }
  621. unset($call_group);
  622. }
  623. $xml .= " </groups>\n";
  624. $xml .= "\n";
  625. $xml .= " </domain>\n";
  626. $xml .= "</include>";
  627. //remove invalid characters from the file names
  628. $extension_dir_name = str_replace(" ", "_", $extension_dir_name);
  629. $extension_dir_name = preg_replace("/[\*\:\\/\<\>\|\'\"\?]/", "", $extension_dir_name);
  630. //write the xml file
  631. $fout = fopen($extension_parent_dir."/".$extension_dir_name.".xml","w");
  632. fwrite($fout, $xml);
  633. unset($xml);
  634. fclose($fout);
  635. //syncrhonize the phone directory
  636. sync_directory();
  637. //apply settings reminder
  638. $_SESSION["reload_xml"] = true;
  639. //call reloadxml direct
  640. //$cmd = "api reloadxml";
  641. //event_socket_request_cmd($cmd);
  642. //unset($cmd);
  643. } //end function
  644. } //class
  645. ?>