Forráskód Böngészése

Extension import is built into the FusionPBX by default.

FusionPBX 2 éve
szülő
commit
da52150b89

+ 0 - 36
bulk_import_extensions/README.rst

@@ -1,36 +0,0 @@
-*********
-Bulk Import Extensions/Voicemails/Devices
-*********
-
-Bulk import extensions with voicemails and devices to your server.
-Just upload CSV file from your computer to FusionPBX server and select fields you want
-to populate from this file. Other this app will do for you.
-This app version is working with FusionPBX 4.4 branch.
-
-
-Prerequisites
-^^^^^^^^^^^^^^
-
-* Working install of FusionPBX
-* CSV file with your extensions
-* Bit of luck
-
-Install Steps
-^^^^^^^^^^^^^^
-
-On your server
-
-::
-
-  cd /usr/src
-  git clone https://github.com/fusionpbx/fusionpbx-apps
-  Move the directory 'bulk_import_extensions' into your main FusionPBX directory
-  mv fusionpbx-apps/bulk_import_extensions /var/www/fusionpbx/app
-  chown -R www-data:www-data /var/www/fusionpbx/app/bulk_import_extensions
-
-::
-
- Log into the FusionPBX webpage
- Advanced -> Upgrade
- Menu Defaults and Permission Defaults.
- Log out and back in.

+ 0 - 48
bulk_import_extensions/app_config.php

@@ -1,48 +0,0 @@
-<?php
-
-	//application details
-		$apps[$x]['name'] = "Import Extensions";
-		$apps[$x]['uuid'] = "9257cf72-e70c-4187-a84b-cefe66a9ebeb";
-		$apps[$x]['category'] = "Switch";
-		$apps[$x]['subcategory'] = "";
-		$apps[$x]['version'] = "";
-		$apps[$x]['license'] = "Mozilla Public License 1.1";
-		$apps[$x]['url'] = "http://www.fusionpbx.com";
-		$apps[$x]['description']['en-us'] = "Possibility to import extensions and devices from CSV file";
-		$apps[$x]['description']['es-cl'] = "";
-		$apps[$x]['description']['de-de'] = "";
-		$apps[$x]['description']['de-ch'] = "";
-		$apps[$x]['description']['de-at'] = "";
-		$apps[$x]['description']['fr-fr'] = "";
-		$apps[$x]['description']['fr-ca'] = "";
-		$apps[$x]['description']['fr-ch'] = "";
-		$apps[$x]['description']['pt-pt'] = "";
-		$apps[$x]['description']['pt-br'] = "";
-
-	//permission details
-		$y = 0;
-		$apps[$x]['permissions'][$y]['name'] = "import_extensions";
-		$apps[$x]['permissions'][$y]['menu']['uuid'] = "70934a0a-b49f-4e91-ba11-a7849cc30ed6";
-		$apps[$x]['permissions'][$y]['groups'][] = "superadmin";
-		$apps[$x]['permissions'][$y]['groups'][] = "admin";
-		$y++;
-
-		//default settings
-		$y = 0;
-		$apps[$x]['default_settings'][$y]['default_setting_uuid'] = '44fe8455-6c5c-4772-a1b7-e3827f32b520';
-		$apps[$x]['default_settings'][$y]['default_setting_category'] = 'import_extensions';
-		$apps[$x]['default_settings'][$y]['default_setting_subcategory'] = 'rows_to_show';
-		$apps[$x]['default_settings'][$y]['default_setting_name'] = 'numeric';
-		$apps[$x]['default_settings'][$y]['default_setting_value'] = '4';
-		$apps[$x]['default_settings'][$y]['default_setting_enabled'] = 'true';
-		$apps[$x]['default_settings'][$y]['default_setting_description'] = 'Set the maximum lines from file to show on Import screen';
-		$y++;
-		$apps[$x]['default_settings'][$y]['default_setting_uuid'] = '54fe8455-0c5c-4772-a2b7-f3827f32b520';
-		$apps[$x]['default_settings'][$y]['default_setting_category'] = 'import_extensions';
-		$apps[$x]['default_settings'][$y]['default_setting_subcategory'] = 'csv_delimiter';
-		$apps[$x]['default_settings'][$y]['default_setting_name'] = 'text';
-		$apps[$x]['default_settings'][$y]['default_setting_value'] = ';';
-		$apps[$x]['default_settings'][$y]['default_setting_enabled'] = 'false';
-		$apps[$x]['default_settings'][$y]['default_setting_description'] = 'Set CSV file delimiter. If not set, app will try to guess it';
-		$y++;
-?>

+ 0 - 127
bulk_import_extensions/app_languages.php

@@ -1,127 +0,0 @@
-<?php
-$text['title-import_extensions']['en-us'] = "Import Extensions";
-
-$text['header-import_extensions']['en-us'] = "Import Extensions";
-
-$text['description-import_extensions']['en-us'] = "Here you can upload CSV file and bulk add extensions and devices to system";
-
-$text['label-skip_first_line']['en-us'] = "Skip first line of file";
-
-
-// Extension part
-$text['label-extensions']['en-us'] = "Extensions";
-
-$text['label-extension']['en-us'] = "Extension";
-
-$text['label-password']['en-us'] = "Password";
-
-$text['label-number_alias']['en-us'] = "Number Alias";
-
-$text['label-extension_user']['en-us'] = "User";
-
-$text['label-accountcode']['en-us'] = "Account Code";
-
-$text['label-call_timeout']['en-us'] = "Call Timeout";
-
-$text['label-effective_caller_id_name']['en-us'] = "Effective Caller ID Name";
-
-$text['label-effective_caller_id_number']['en-us'] = "Effective Caller ID Number";
-
-$text['label-outbound_caller_id_name']['en-us'] = "Outbound Caller ID Name";
-
-$text['label-outbound_caller_id_number']['en-us'] = "Outbound Caller ID Number";
-
-$text['label-directory_first_name']['en-us'] = "Directory First Name";
-
-$text['label-directory_last_name']['en-us'] = "Directory Last Name";
-
-$text['label-directory_visible']['en-us'] = "Directory Visible";
-
-$text['label-limit_max']['en-us'] = "Limit Max";
-
-$text['label-toll_allow']['en-us'] = "Toll Allow";
-
-$text['label-call_timeout']['en-us'] = "Call Timeout";
-
-$text['title-call_group']['en-us'] = "Call Group";
-
-$text['label-user_record']['en-us'] = "User Record";
-
-$text['label-hold_music']['en-us'] = "Hold Music";
-
-$text['label-description']['en-us'] = "Description";
-
-// -- Extension part end
-// Devices part
-
-$text['label-device']['en-us'] = "Device";
-
-$text['label-device_mac_address']['en-us'] = "MAC Address";
-
-$text['label-device_profile']['en-us'] = "Profile";
-
-$text['label-device_label']['en-us'] = "Label";
-
-$text['label-device_vendor']['en-us'] = "Vendor";
-
-$text['label-device_model']['en-us'] = "Model";
-
-$text['label-device_template']['en-us'] = "Template";
-
-$text['label-device_description']['en-us'] = "Description";
-
-// -- Devices part end
-// Voicemail part
-
-$text['label-voicemail']['en-us'] = "Voicemail";
-
-$text['label-voicemail_enabled']['en-us'] = "Enabled";
-
-$text['label-voicemail_mail_to']['en-us'] = "Mail To";
-
-$text['label-voicemail_password']['en-us'] = "Password";
-
-$text['label-voicemail_attach_file']['en-us'] = "Attach file";
-
-$text['label-voicemail_description']['en-us'] = "Description";
-
-// -- Voicemail part end
-
-$text['label-ignore']['en-us'] = "Ignore";
-
-$text['description-selector']['en-us'] = "Select field to use";
-
-$text['description-file_column']['en-us'] = "File line #";
-
-
-$text['button-process']['en-us'] = "Process uploaded extensions and devices";
-
-// File upload section
-
-$text['message-unsupported_file_type']['en-us'] = "File format is not supported. Please use .csv";
-
-$text['label-select_a_file']['en-us'] = "Please, select a file to import";
-
-$text['button-reset']['en-us'] = "Reset file";
-
-$text['button-preview']['en-us'] = "Preview";
-
-$text['message-extensions_not_found']['en-us'] = "Extension (number) field not found";
-
-// Messages to process window
-
-$text['message-csv_info_missing']['en-us'] = "Cannot process file. CSV fields info is missing";
-
-$text['message-process_csv_file_start']['en-us'] = "Start processing CSV file...";
-
-$text['message-process_csv_file_skip_first_line']['en-us'] = "Skipping first line...";
-
-$text['message-process_csv_file_end']['en-us'] = "End processing CSV file. Operation completed successfully";
-
-$text['message-process_csv_file_stats']['en-us'] = "Statistics:";
-
-$text['message-process_csv_file_added_lines']['en-us'] = "Processed added/updated lines:";
-
-$text['message-process_csv_file_skipped_lines']['en-us'] = "Skipped lines:";
-
-?>

+ 0 - 18
bulk_import_extensions/app_menu.php

@@ -1,18 +0,0 @@
-<?php
-	$apps[$x]['menu'][0]['title']['en-us'] = "Import Extensions";
-	$apps[$x]['menu'][0]['title']['es-mx'] = "";
-	$apps[$x]['menu'][0]['title']['de-de'] = "";
-	$apps[$x]['menu'][0]['title']['de-ch'] = "";
-	$apps[$x]['menu'][0]['title']['de-at'] = "";
-	$apps[$x]['menu'][0]['title']['fr-fr'] = "";
-	$apps[$x]['menu'][0]['title']['fr-ca'] = "";
-	$apps[$x]['menu'][0]['title']['fr-ch'] = "";
-	$apps[$x]['menu'][0]['title']['pt-pt'] = "";
-	$apps[$x]['menu'][0]['title']['pt-br'] = "";
-	$apps[$x]['menu'][0]['uuid'] = "b8a54b3f-330d-4574-a52a-37f907dd212e";
-	$apps[$x]['menu'][0]['parent_uuid'] = "fd29e39c-c936-f5fc-8e2b-611681b266b5";
-	$apps[$x]['menu'][0]['category'] = "internal";
-	$apps[$x]['menu'][0]['path'] = "/app/bulk_import_extensions/import_extensions.php";
-	$apps[$x]['menu'][0]['groups'][] = "superadmin";
-	$apps[$x]['menu'][0]['groups'][] = "admin";
-?>

+ 0 - 237
bulk_import_extensions/import_extensions.php

@@ -1,237 +0,0 @@
-<?php
-/*
-	FusionPBX
-	Version: MPL 1.1
-
-	The contents of this file are subject to the Mozilla Public License Version
-	1.1 (the "License"); you may not use this file except in compliance with
-	the License. You may obtain a copy of the License at
-	http://www.mozilla.org/MPL/
-
-	Software distributed under the License is distributed on an "AS IS" basis,
-	WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
-	for the specific language governing rights and limitations under the
-	License.
-
-	The Original Code is FusionPBX
-
-	The Initial Developer of the Original Code is
-	Mark J Crane <[email protected]>
-	Portions created by the Initial Developer are Copyright (C) 2008-2016
-	the Initial Developer. All Rights Reserved.
-
-	Contributor(s):
-	Mark J Crane <[email protected]>
-	Igor Olhovskiy <[email protected]>
-*/
-require_once "root.php";
-require_once "resources/require.php";
-require_once "resources/check_auth.php";
-
-if (permission_exists('import_extensions')) {
-	//access granted
-}
-else {
-	echo "access denied";
-	exit;
-}
-
-//add multi-lingual support
-$text = (new text)->get();
-
-require_once "resources/header.php";
-
-$document['title'] = $text['title-import_extensions'];
-
-require_once "resources/paging.php";
-
-//$csv_file_path = '/var/www/fusionpbx/app/bulk_import_extensions/';
-$csv_file_path = '/tmp/';
-$csv_file_name = $csv_file_path . "import.csv";
-
-// Get variables here
-
-$rows_to_show = isset($_SESSION['import_extensions']['rows_to_show']['numeric']) ? (int) $_SESSION['import_extensions']['rows_to_show']['numeric'] : 4;
-$csv_delimiter = isset($_SESSION['import_extensions']['csv_delimiter']['text']) ? (int) $_SESSION['import_extensions']['csv_delimiter']['text'] : False;
-
-$is_import = isset($_REQUEST['is_import']) ? filter_var($_REQUEST['is_import'], FILTER_VALIDATE_BOOLEAN) : False;
-$skip_first_line = isset($_REQUEST['skip_first_line']) ? filter_var($_REQUEST['skip_first_line'], FILTER_VALIDATE_BOOLEAN) : False;
-$csv_fields_order = isset($_REQUEST['csv_field']) ? $_REQUEST['csv_field'] : False;
-
-// Show the content
-
-// Get table row width. 90 - cause 10% is always to show selector.
-$table_row_width = (int) 90 / $rows_to_show;
-
-$c = 0;
-$row_style["0"] = "row_style0";
-$row_style["1"] = "row_style1";
-
-
-// File operations
-
-if (isset($_FILES['file'])) {
-	//if ($_FILES["file"]["error"] == UPLOAD_ERR_OK && ($_FILES["file"]["type"] == 'text/csv' || $_FILES["file"]["type"] == 'application/octet-stream')) {
-	if ($_FILES["file"]["error"] == UPLOAD_ERR_OK) {
-		move_uploaded_file($_FILES["file"]["tmp_name"], $csv_file_name);
-	}
-}
-
-
-// Check if we have CSV file on place
-$import_file = new csv_file_process($csv_file_name, $csv_delimiter);
-
-$action = '';
-if ($import_file->is_valid() && $is_import && $csv_fields_order) {
-	$action = 'import';
-} elseif ($import_file->is_valid()) {
-	$action = 'show';
-}
-
-// Check if fields are all set before show content
-
-if ($action == 'import') {
-
-	if (!in_array('extension', $csv_fields_order)) {
-		$_SESSION['message_mood'] = 'negative';
-		$_SESSION['message'] = $text['message-extensions_not_found'];
-		header('Location: import_extensions.php');
-		return;
-	}
-}
-
-//show the content
-
-// Javascript function for file upload
-echo "<script language='JavaScript' type='text/javascript'>\n";
-
-echo "  function check_filetype(file_input) {\n";
-echo "          file_ext = file_input.value.substr((~-file_input.value.lastIndexOf('.') >>> 0) + 2);\n";
-echo "          if (file_ext != 'csv' && file_ext != '') {\n";
-echo "                  display_message(\"".$text['message-unsupported_file_type']."\", 'negative', '2750');\n";
-echo "          }\n";
-echo "          var selected_file_path = file_input.value;\n";
-echo "          selected_file_path = selected_file_path.replace(\"C:\\\\fakepath\\\\\",'');\n";
-echo "          document.getElementById('file_label').innerHTML = selected_file_path;\n";
-echo "          document.getElementById('button_reset').style.display='inline';\n";
-echo "  }\n";
-
-echo "</script>";
-echo "<script language='JavaScript' type='text/javascript' src='".PROJECT_PATH."/resources/javascript/reset_file_input.js'></script>\n";
-
-echo "<table width='100%' cellpadding='0' cellspacing='0 border='0'>\n";
-echo "	<tr>\n";
-echo "		<td width='50%' align='left' nowrap='nowrap'><b>".$text['header-import_extensions']."</b></td>\n";
-echo "		<td width='50%' align='right'>&nbsp;</td>\n";
-echo "	</tr>\n";
-echo "	<tr>\n";
-echo "		<td align='left'>\n";
-echo "			".$text['description-import_extensions']."<br /><br />\n";
-echo "		</td>\n";
-echo "		<td>";
-echo "			<form name='frmimport' method='POST' enctype='multipart/form-data' style='float: right;' action=''>\n";
-echo "				<input name='file' id='file' type='file' style='display: none;' accept='.csv' onchange='check_filetype(this);'>";
-echo "				<label id='file_label' for='file' class='txt' style='width: 200px; overflow: hidden; white-space: nowrap;'>".$text['label-select_a_file']."</label>\n";
-echo " 				<input id='button_reset' type='reset' class='btn' style='display: none;' value='".$text['button-reset']."' onclick=\"reset_file_input('file'); document.getElementById('file_label').innerHTML = '".$text['label-select_a_file']."'; this.style.display='none'; return true;\">\n";
-echo "				<input name='upload' type='submit' class='btn' id='upload' value=\"".$text['button-preview']."\">\n";
-echo "			</form>";
-echo "		</td>";
-echo "	</tr>\n";
-echo "</table>\n";
-echo "<br/>\n";
-
-
-if ($action == 'import') {
-	// Import data to database
-
-	$csv_fields_order = array_map('check_str', $csv_fields_order);
-
-	
-	$import_file->set_csv_fields_order($csv_fields_order);
-
-	$process_csv_file_options = array(
-		'db' => $db,
-		'vm_password_length' => $_SESSION['voicemail']['password_length']['numeric'],
-		'domain_uuid' => $domain_uuid,
-		'domain_name' => $_SESSION['domain_name'],
-		'skip_first_line' => $skip_first_line,
-		'line_sip_transport' => $_SESSION['provision']['line_sip_transport']['text'],
-		'line_sip_port' => $_SESSION['provision']['line_sip_port']['numeric'],
-		'line_register_expires' => $_SESSION['provision']['line_register_expires']['numeric'],
-	);
-	
-
-	// Show debug messages of processing file
-	echo "<pre>";
-	echo $import_file->process_csv_file($process_csv_file_options);
-	echo "</pre>";
-
-	unset($import_file);
-	unlink($csv_file_name); 
-
-} elseif ($action == 'show') {
-
-	// Here we got first 4 lines of file. As usual, CSV holds first line as a fields desccription.
-	// And we will use it to count number of fields in file.
-	$import_lines = $import_file->read_first($rows_to_show);
-	$row_count = count($import_lines[0]);
-
-	// Initialize array if not full for normal show after.
-	for ($i = 1; $i <= 3; $i++) {
-		if (!isset($import_lines[$i])) {
-			$import_lines[$i] = array();
-		}
-		for ($j = 0; $j < $row_count; $j++) {
-			if (!isset($import_lines[$i][$j])) {
-				$import_lines[$i][$j] = '';
-			}
-		}
-	}
-
-	$selector = new bulk_import_extensions_options_selector();
-
-	// Show content in a case of valid file
-	echo "<form method='post' name='frm' action=''>\n";
-	echo "<table width='100%' cellpadding='0' cellspacing='0' border='0'>\n";
-	echo "<tr class='" . $row_style[$c] . "'>\n";
-	echo "<th width='10%' align='center' nowrap='nowrap'>" . $text['description-selector'] . "</th>\n";
-	for ($i = 1; $i <= $rows_to_show; $i++) {
-		echo "<th align='left' nowrap='nowrap' width='" . $table_row_width . "%'>" . $text['description-file_column'] . " " .$i . "</th>\n";
-	}
-	echo "</tr>\n";
-	$c = 1 - $c;
-	// Show table rows
-	for ($row_index = 0; $row_index < $row_count; $row_index++) {
-		// Show table columns. By default - show 3 first columns to check.
-		echo "<tr class='" . $row_style[$c] . "'>\n";
-		// Show selector
-		echo "<td width='10%' align='center' nowrap='nowrap'>";
-		echo $selector->draw_selector("csv_field[$row_index]", $row_index);
-		echo "</td>\n";
-		for ($i = 0; $i < $rows_to_show; $i++) {
-			echo "<td align='left' nowrap='nowrap' width='" . $table_row_width . "%'>" . $import_lines[$i][$row_index] . "</td>\n";
-		}
-		echo "</tr>\n";
-		$c = 1 - $c;
-	}
-	echo "</table>\n";
-	echo "<input type='hidden' name='is_import' value='true'>\n";
-	echo "<br/>\n";
-	echo "<table width='100%' cellpadding='0' cellspacing='0' border='0'>\n";
-	echo "	<tr>\n";
-	echo "		<td width='50%'>";
-	echo "			<input type='checkbox' name='skip_first_line' id='skip_first_line' value='true' checked>&nbsp;" . $text['label-skip_first_line'] . "\n";
-	echo "		</td>";
-	echo "		<td width='50%'>";
-	echo "			<input type='submit' name='submit' style='float: right;' class='btn' value='".$text['button-process']."'>\n";
-	echo "		</td>";
-	echo "	</tr>\n";
-	echo "</table>\n";
-	echo "<br/><br/>";
-	echo "</form>";
-	
- } // End show content for CSV file is present
-
-//include the footer
-require_once "resources/footer.php";
-?>

+ 0 - 82
bulk_import_extensions/resources/classes/bulk_import_extensions_options_selector.php

@@ -1,82 +0,0 @@
-<?php
-
-if (!class_exists('bulk_import_extensions_options_selector')) {
-    class bulk_import_extensions_options_selector {
-
-        private $optgroups;
-
-        public function __construct() {
-            $this->text = (new text)->get();
-
-            $this->optgroups = array(
-                $this->text['label-extensions'] => array(
-                    'extension' => $this->text['label-extension'],
-                    'password' => $this->text['label-password'],
-                    'number_alias' => $this->text['label-number_alias'],
-                    'extension_user' => $this->text['label-extension_user'],
-                    'accountcode' => $this->text['label-accountcode'],
-                    'call_timeout' => $this->text['label-call_timeout'],
-                    'effective_caller_id_name' => $this->text['label-effective_caller_id_name'],
-                    'effective_caller_id_number' => $this->text['label-effective_caller_id_number'],
-                    'outbound_caller_id_name' => $this->text['label-outbound_caller_id_name'],
-                    'outbound_caller_id_number' => $this->text['label-outbound_caller_id_number'],
-                    'directory_first_name' => $this->text['label-directory_first_name'],
-                    'directory_last_name' => $this->text['label-directory_last_name'],
-                    'directory_visible' => $this->text['label-directory_visible'],
-                    'limit_max' => $this->text['label-limit_max'],
-                    'toll_allow' => $this->text['label-toll_allow'],
-                    'call_timeout' => $this->text['label-call_timeout'],
-                    'call_group' => $this->text['title-call_group'],
-                    'user_record' => $this->text['label-user_record'],
-                    'hold_music' => $this->text['label-hold_music'],
-                    'description' => $this->text['label-description'],
-                ),
-                // To each device add black phone symbol at the end to differ
-                $this->text['label-device'] => array(
-                    'device_mac_address' => $this->text['label-device_mac_address'] . " &#x260E;",
-                    'device_profile' => $this->text['label-device_profile'] . " &#x260E;",
-                    'device_label' => $this->text['label-device_label'] . " &#x260E;",
-                    'device_vendor' => $this->text['label-device_vendor'] . " &#x260E;",
-                    'device_model' => $this->text['label-device_model'] . " &#x260E;",
-                    'device_template' => $this->text['label-device_template'] . " &#x260E;",
-                    'device_description' => $this->text['label-device_description'] . " &#x260E;",
-                ),
-                $this->text['label-voicemail'] => array(
-                    'voicemail_enabled' => $this->text['label-voicemail_enabled'] . " &#x2709;",
-                    'voicemail_mail_to' => $this->text['label-voicemail_mail_to'] . " &#x2709;",
-                    'voicemail_password' => $this->text['label-voicemail_password'] . " &#x2709;",
-                    'voicemail_attach_file' => $this->text['label-voicemail_attach_file'] . " &#x2709;",
-                    'voicemail_description' => $this->text['label-voicemail_description'] . " &#x2709;",
-                ),
-                $this->text['label-ignore'] => array(
-                    'ignore' => $this->text['label-ignore'],
-                ),
-            );
-        }
-
-
-        public function getopts() {
-            return $this->optgroups;
-        }
-
-        public function draw_selector($name = '', $selected_id = 0) {
-            $i = 0;
-            $selector_text .= "<select name = '" . $name . "' id = '" . $name . "' class='formfld'>";
-            $selector_text .= "<option value=''></option>\n";
-            foreach ($this->optgroups as $optgroup_label => $optgroup_data) {
-                $selector_text .= "<optgroup label = '" . $optgroup_label . "'>\n";
-
-                foreach ($optgroup_data as $key => $value) {
-                    $selector_text .= "<option " . (($i == $selected_id) ? "selected " : " " );
-                    $selector_text .= "value='" . $key . "'>" . $value . "</option>\n";
-                    $i += 1;
-                }
-                $selector_text .= "</optgroup>\n";
-            }
-            $selector_text .= "</select>\n";
-            return $selector_text;
-        }
-    }
-}
-
-?>

+ 0 - 564
bulk_import_extensions/resources/classes/csv_file_process.php

@@ -1,564 +0,0 @@
-<?php
-if (!class_exists('csv_file_process')) {
-    class csv_file_process {
-        
-        private $csv_file;
-        private $csv_fields_order;
-
-        
-        private $is_generate_vm_pass;
-        private $is_generate_ext_pass;
-        private $is_add_device_profile;
-        private $is_add_extension_user;
-        private $is_add_device;
-
-        private $vm_password_length;
-
-        private $db;
-        private $domain_uuid;
-        private $domain_name;
-        private $line_sip_transport;
-        private $line_sip_port;
-        private $line_register_expires;
-
-        public function __construct($file_path, $csv_delimiter = False) {
-            if (!file_exists($file_path)) {
-                $this->csv_file = False;
-                return;
-            }
-
-            $this->is_import_devices = False;
-            $this->csv_fields_order = False;
-            $this->is_generate_vm_pass = False;
-            $this->is_generate_ext_pass = False;
-            $this->is_is_add_device_profile = False;
-
-            //$this->numerical_fields = ['number_alias', 'call_timeout', 'voicemail_id'];
-
-            $this->csv_file = new SplFileObject($file_path);
-            
-
-            if ($csv_delimiter) {
-                $this->csv_file->setCsvControl($csv_delimiter);
-                return;
-            }
-
-            // Guessing CSV delimiter
-
-            if (count($this->csv_file->fgetcsv()) != 1) {
-                return;
-            }
-
-            // Trying ';'
-            $this->csv_file->rewind();
-            $this->csv_file->setCsvControl(";");
-            if (count($this->csv_file->fgetcsv()) != 1) {
-                return;
-            }
-
-            // Trying 'tab'
-            $this->csv_file->rewind();
-            $this->csv_file->setCsvControl("\t");
-            if (count($this->csv_file->fgetcsv()) != 1) {
-                return;
-            }
-
-            // Trying 'space'
-            $this->csv_file->rewind();
-            $this->csv_file->setCsvControl(" ");
-            if (count($this->csv_file->fgetcsv()) != 1) {
-                return;
-            }
-            // Trying ':'
-            $this->csv_file->rewind();
-            $this->csv_file->setCsvControl(":");
-            if (count($this->csv_file->fgetcsv()) != 1) {
-                return;
-            }
-            // Cannot get csv file delimiter. Unsetting file
-            unset($this->csv_file);
-        }
-
-        public function __destruct() {
-            unset($this->csv_file);
-        }
-
-        // Creation part end
-        // Private functions start
-
-
-        private function starts_with($haystack, $needle) {
-            return strncmp($haystack, $needle, strlen($needle)) === 0;
-        }
-
-        private function ends_with($haystack, $needle) {
-            return $needle === '' || substr_compare($haystack, $needle, -strlen($needle)) === 0;
-        }
-
-        // Funcion to add missing fields if any and check if some of actual fields are correct.
-        private function normalize_line($csv_line) {
-
-            $result = array();
-
-            foreach ($this->csv_fields_order as $index => $value) {
-                $csv_field = (isset($csv_line[$index])) ? $csv_line[$index] : '';
-                switch ($value) {
-                    case 'extension':
-                        if (strlen($csv_field) == 0) {
-                            // Immediate exit if extension field is empty
-                            return False;
-                        }
-                        $result['voicemail_id'] = (is_numeric($csv_field)) ? (int) $csv_field : False;
-                        break;
-                    case 'number_alias':
-                    case 'voicemail_password':
-                        $csv_field = (is_numeric($csv_field)) ? (int) $csv_field : '';
-                        break;
-                    case 'limit_max':
-                        $csv_field = (is_numeric($csv_field)) ? (int) $csv_field : 5;
-                        break;
-                    case 'call_timeout':
-                        $csv_field = (is_numeric($csv_field)) ? (int) $csv_field : 30;
-                        break;
-                    case 'voicemail_enabled': 
-                        $csv_field = (filter_var($csv_field, FILTER_VALIDATE_BOOLEAN)) ? 'true' : 'false';
-                        break;
-                }       
-                $result[$value] = $csv_field;
-            }
-
-            if ($this->is_generate_vm_pass) {
-                $result['voicemail_password'] = generate_password($this->vm_password_length, 1);
-            }
-
-            if ($this->is_generate_ext_pass) {
-                $result['password'] = generate_password();
-            }
-
-            // Set defaults that might be set before
-
-            $result['limit_max'] = isset($result['limit_max']) ? $result['limit_max'] : 5;
-            $result['call_timeout'] = isset($result['call_timeout']) ? $result['call_timeout'] : 30;
-            $result['directory_visible'] = isset($result['directory_visible']) ? $result['directory_visible'] : 'true';
-            $result['directory_exten_visible'] = $result['directory_visible'];
-            $result['description'] = isset($result['description']) ? $result['description'] : '';
-
-            $result['voicemail_mail_to'] = isset($result['voicemail_mail_to']) ? $result['voicemail_mail_to'] : '';
-            $result['voicemail_enabled'] = isset($result['voicemail_enabled']) ? $result['voicemail_enabled'] : 'true';
-            $result['voicemail_description'] = $result['description'];
-            
-            // Set various defaults that is not controlled by user
-            
-            $result['limit_destination'] = 'error/user_busy';
-            $result['call_screen_enabled'] = 'false';
-            $result['user_context'] = $this->domain_name;
-            $result['enabled'] = 'true';
-            $result['voicemail_file'] = 'attach';
-            $result['voicemail_local_after_email'] = 'true';
-
-            // Device section
-            if ($this->is_add_device) {
-
-                // Normalize mac address
-                $result['device_mac_address'] = strtolower($result['device_mac_address']);
-                $result['device_mac_address'] = preg_replace("/[^a-f0-9]+/", "", $result['device_mac_address']);
-
-                $result['device_label'] = isset($result['device_label']) ? $result['device_label'] : $result['extension'];
-                $result['device_template'] = isset($result['device_template']) ? strtolower($result['device_template']) : '';
-
-                $result['device_enabled'] = 'true';
-                $result['device_vendor'] = explode('/', $result['device_template'])[0];
-            }
-
-            return $result;
-        }
-
-        private function get_one_result($sql) {
-            $prep_statement = $this->db->prepare(check_sql($sql));
-            $prep_statement->execute();
-            $result = $prep_statement->fetch(PDO::FETCH_NUM);
-            $result_count = count($result);
-            if ($result_count == 0) {
-                return False;
-            }
-            return $result[0];
-        }
-
-        private function form_prepare_insert_statement($csv_line) {
-            
-            // Funcion to form part of INSERT statement with PDO prepared form
-            // like '(extension_uuid, domain_uuid) VALUES (?, ?)
-            // ? symbols replaced on execute() stage.
-
-            $sql = '';
-
-            $keys = array_keys($csv_line);
-            $sql .= "(" . implode(',', $keys) . ") VALUES (";
-            $sql .= str_repeat('?,', count($keys));
-            $sql = rtrim($sql, ", ") . ")";
-
-            return $sql;
-        }
-
-        private function form_prepare_update_statement($csv_line) {
-
-            // Function to form part of UPDATE statement with PDO prepared form
-            // like 'extension_uuid = ?, domain_uuid = ?'
-            // ? symbols replaced on execute() stage.
-
-            $sql = '';
-            $keys = array_keys($csv_line);
-            $sql .= implode(' = ?,', $keys);
-
-            $sql .= " = ?";
-            return $sql;
-        }
-
-        private function prepare_and_execute_statement($sql, $insert_array = NULL) {
-
-            // Function for prepare end execute statements. Mostly done for extensive logging errors.
-
-            $prep_statement = $this->db->prepare(check_sql($sql));
-            if (!$prep_statement) {
-                // Not that efficient logging for errors, but better than nothing
-                echo $sql . "\n";
-                echo "Prepare error: ". json_encode($this->db->errorInfo()) . "\n" . json_encode($prep_statement->errorInfo()) . "\n";
-                return;
-            }
-
-            if (!$prep_statement->execute(array_values($insert_array))) {
-                echo "Execute error: ". json_encode($prep_statement->errorInfo()) . "\n";
-                echo $sql . "\n" . json_encode(array_values($insert_array)) . "\n";
-            }
-        }
-
-        private function add_extension($csv_line) {
-
-            // Check if extension is there
-            $sql = "SELECT extension_uuid FROM v_extensions";
-            $sql .= " WHERE domain_uuid = '" . $this->domain_uuid . "'";
-            $sql .= " AND extension = '" . $csv_line['extension'] . "'";
-            $sql .= " LIMIT 1";
-            // Getting UUID if exists
-
-            $extension_csv_line = array();
-            $extension_csv_line['extension_uuid'] = $this->get_one_result($sql);
-
-            // Remove non-needed entires from CSV
-
-            foreach ($csv_line as $key => $value) {
-                if ($this->starts_with($key, 'device_') or $this->starts_with($key, 'voicemail_') or $this->starts_with($key, 'extension_')) {
-                    continue;
-                }
-                $extension_csv_line[$key] = $value;
-            }
-
-            if ($extension_csv_line['extension_uuid']) {
-                // Update existing extension
-                $sql = "UPDATE v_extensions SET ";
-                $sql .= $this->form_prepare_update_statement($extension_csv_line);
-                $sql .= " WHERE extension_uuid = '" . $extension_csv_line['extension_uuid'] . "'";
-                $sql .= " AND domain_uuid = '" . $this->domain_uuid . "'";
-            } else {
-                // Insert new extension
-                $extension_csv_line['domain_uuid'] = $this->domain_uuid;
-                $extension_csv_line['extension_uuid'] = uuid();
-                $sql = "INSERT INTO v_extensions ";
-                $sql .= $this->form_prepare_insert_statement($extension_csv_line);
-            }
-
-            $this->prepare_and_execute_statement($sql, $extension_csv_line);
-
-            if ($this->is_add_extension_user) {
-                // Get user id by name
-                $sql = "SELECT user_uuid FROM v_users";
-                $sql .= " WHERE domain_uuid = '" . $this->domain_uuid . "'";
-                $sql .= " AND username = '" . $csv_line['extension_user']  . "'";
-                $sql .= " LIMIT 1";
-                $user_uuid = $this->get_one_result($sql);
-                
-                if (!$user_uuid) {
-                    // Cannot find this user_uuid. So, can't add user to extension
-                    return;
-                }
-
-                // Check if this link is already exists
-                $sql = "SELECT extension_user_uuid FROM v_extension_users";
-                $sql .= " WHERE domain_uuid = '" . $this->domain_uuid . "'";
-                $sql .= " AND extension_uuid = '" . $extension_csv_line['extension_uuid'] . "'";
-                $sql .= " AND user_uuid = '" . $user_uuid . "'";
-                $sql .= " LIMIT 1";
-
-                if ($this->get_one_result($sql)) {
-                    // Link is already exists
-                    return;
-                }
-
-                // Prepare data to insert into database
-                $extension_to_user = array(
-                    'extension_user_uuid' => uuid(),
-                    'domain_uuid' => $this->domain_uuid,
-                    'extension_uuid' => $extension_csv_line['extension_uuid'],
-                    'user_uuid' => $user_uuid,
-                );
-
-                $sql = "INSERT INTO v_extension_users";
-                $sql .= $this->form_prepare_insert_statement($extension_to_user);
-
-                $this->prepare_and_execute_statement($sql, $extension_to_user);
-
-            }
-        }
-
-        private function add_voicemail($csv_line) {
-
-            if (strlen($csv_line['voicemail_id']) == 0) {
-                return;
-            }
-
-            // Check if VM id is there
-            $sql = "SELECT voicemail_uuid FROM v_voicemails";
-            $sql .= " WHERE domain_uuid = '" . $this->domain_uuid . "'";
-            $sql .= " AND voicemail_id = '" . $csv_line['voicemail_id'] . "'";
-            $sql .= " LIMIT 1";
-            
-            $voicemail_csv_line = array();
-
-            // Getting UUID if exists
-            $voicemail_csv_line['voicemail_uuid'] = $this->get_one_result($sql);
-
-            // Leaving only necessary data
-            foreach ($csv_line as $key => $value) {
-                if ($this->starts_with($key, 'voicemail_')) {
-                    $voicemail_csv_line[$key] = $value;
-                }
-            }
-
-            if ($voicemail_csv_line['voicemail_uuid']) {
-                $sql = "UPDATE v_voicemails SET ";
-                $sql .= $this->form_prepare_update_statement($voicemail_csv_line);
-                $sql .= " WHERE voicemail_uuid = '" . $voicemail_csv_line['voicemail_uuid'] . "'";
-                $sql .= " AND domain_uuid = '" . $this->domain_uuid . "'";
-            } else {
-                $voicemail_csv_line['domain_uuid'] = $this->domain_uuid;
-                $voicemail_csv_line['voicemail_uuid'] = uuid();
-                $sql = "INSERT INTO v_voicemails";
-                $sql .= $this->form_prepare_insert_statement($voicemail_csv_line);
-            }
-            $this->prepare_and_execute_statement($sql, $voicemail_csv_line);
-
-        }
-
-        private function add_device($csv_line) {
-            if (!$this->is_add_device) {
-                return;
-            }
-
-            // Check if it is MAC address actually
-            if (strlen($csv_line['device_mac_address']) != 12) {
-                return;
-            }
-
-            // First - check if device exists
-            $sql = "SELECT device_uuid FROM v_devices";
-            $sql .= " WHERE domain_uuid = '" . $this->domain_uuid . "'";
-            $sql .= " AND device_mac_address = '" . $csv_line['device_mac_address'] . "'";
-            $sql .= " LIMIT 1";
-            
-            $device_csv_line = array();
-
-            $device_csv_line['device_uuid'] = $this->get_one_result($sql);
-
-            // Cleanup CSV file
-            foreach ($csv_line as $key => $value) {
-                if ($this->starts_with($key, 'device_')) {
-                    $device_csv_line[$key] = $value;
-                }
-            }
-
-            // Check for profile UUID
-            if (isset($device_csv_line['device_profile'])) {
-                $sql = "SELECT device_profile_uuid FROM v_device_profiles";
-                $sql .= " WHERE domain_uuid = '" . $this->domain_uuid . "'";
-                $sql .= " AND device_profile_name = '" . $device_csv_line['device_profile'] . "'";
-                $sql .= " AND device_profile_enabled = 'true'";
-                $sql .= " LIMIT 1";
-
-                $device_csv_line['device_profile_uuid'] = $this->get_one_result($sql);
-                if (!$device_csv_line['device_profile_uuid']) {
-                    unset($device_csv_line['device_profile_uuid']);
-                }
-                unset($device_csv_line['device_profile']);
-            }
-
-            if ($device_csv_line['device_uuid']) {
-                $sql = "UPDATE v_devices SET ";
-                $sql .= $this->form_prepare_update_statement($device_csv_line);
-                $sql .= " WHERE device_uuid = '" . $device_csv_line['device_uuid'] . "'";
-                $sql .= " AND domain_uuid = '" . $this->domain_uuid . "'";
-            } else {
-                $device_csv_line['domain_uuid'] = $this->domain_uuid;
-                $device_csv_line['device_uuid'] = uuid();
-                $sql = "INSERT INTO v_devices ";
-                $sql .= $this->form_prepare_insert_statement($device_csv_line);
-            }
-
-            $this->prepare_and_execute_statement($sql, $device_csv_line);
-
-            // Add line 1 for extension
-
-            $device_line_array = array(
-                'line_number' => '1',
-                'server_address' => $this->domain_name,
-                'display_name' => $csv_line['extension'],
-                'user_id' => $csv_line['extension'],
-                'auth_id' => $csv_line['extension'],
-                'password' => $csv_line['password'],
-                'sip_port' => $this->line_sip_port,
-                'sip_transport' => $this->line_sip_transport,
-                'register_expires' => $this->line_register_expires,
-                'enabled' => 'true',
-                'device_uuid' => $device_csv_line['device_uuid'],
-            );
-
-            // Check if line 1 for this device already exists
-
-            $sql = "SELECT device_line_uuid FROM v_device_lines";
-            $sql .= " WHERE domain_uuid = '" . $this->domain_uuid . "'";
-            $sql .= " AND device_uuid = '" . $device_csv_line['device_uuid'] . "'";
-            $sql .= " LIMIT 1";
-
-            $device_line_array['device_line_uuid'] = $this->get_one_result($sql);
-
-            if ($device_line_array['device_line_uuid']) {
-                $sql = "UPDATE v_device_lines SET ";
-                $sql .= $this->form_prepare_update_statement($device_line_array);
-                $sql .= " WHERE device_line_uuid = '" . $device_line_array['device_line_uuid'] . "'";
-                $sql .= " AND domain_uuid = '" . $this->domain_uuid . "'";
-            } else {
-                $device_line_array['domain_uuid'] = $this->domain_uuid;
-                $device_line_array['device_line_uuid'] = uuid();
-                $sql = "INSERT INTO v_device_lines";
-                $sql .= $this->form_prepare_insert_statement($device_line_array);
-            }
-
-            $this->prepare_and_execute_statement($sql, $device_line_array);
-        }
-
-        // Private funcions end
-        // Public functions start
-
-        public function is_valid() {
-            if ($this->csv_file) {
-                return True;
-            }
-            return False;
-        }
-
-        public function read_first($number_to_read = 4) {
-
-            $this->csv_file->rewind();
-            
-            if (!$this->csv_file->valid()) {
-                return False;
-            }
-            $result = array();
-            for ($i = 1; $i <= $number_to_read; $i++) {
-                if (!$this->csv_file->valid()) {
-                    break;
-                }
-                $result[] = array_map('escape',$this->csv_file->fgetcsv());
-                //$result[] = $this->csv_file->fgetcsv();
-            }
-            $this->csv_file->rewind();
-            return $result;
-        }
-
-        public function set_csv_fields_order($csv_fields_order) {
-            $this->csv_fields_order = $csv_fields_order;
-
-            $this->is_add_device = in_array('device_mac_address', $csv_fields_order);
-            $this->is_generate_ext_pass = !in_array('password',  $csv_fields_order);
-
-            $this->is_generate_vm_pass = !in_array('voicemail_password',  $csv_fields_order);
-            $this->is_add_extension_user = in_array('extension_user', $csv_fields_order);
-
-            if ($this->is_import_devices) {
-                $this->is_add_device_profile = in_array('device_profile',  $csv_fields_order);
-            }
-        }
-
-        public function process_csv_file($options) {
-
-            // Increase running time to 5 min
-            set_time_limit(5 * 60);
-            $result_message = '';
-
-            $text = (new text)->get();
-            $this->vm_password_length = $options['vm_password_length'];
-            $this->db = $options['db'];
-            $this->domain_uuid = $options['domain_uuid'];
-            $this->domain_name = $options['domain_name'];
-            $this->line_sip_transport = $options['line_sip_transport'];
-            $this->line_sip_port = $options['line_sip_port'];
-            $this->line_register_expires = $options['line_register_expires'];
-
-            $skip_first_line = $options['skip_first_line'];
-
-            if (!$this->csv_fields_order) {
-                $result_message .= $text['message-csv_info_missing'] . "\n";
-                return $result_message;
-            }
-
-            // Read file line by line
-            $this->csv_file->rewind();
-            $result_message .= $text['message-process_csv_file_start'] . "\n";
-            // Skip first line if applied
-            if ($skip_first_line) {
-                $result_message .= $text['message-process_csv_file_skip_first_line'] . "\n";
-                $this->csv_file->current();
-                $this->csv_file->next();
-            }
-
-            $added_lines_count = 0;
-            $skipped_lines_count = 0;
-            $skipped_lines_array = array();
-
-            while (!$this->csv_file->eof()) {
-
-                // Read CSV line and sterialize it
-                $csv_line = array_map('check_str', $this->csv_file->fgetcsv());
-                $csv_line = $this->normalize_line($csv_line);
-
-                if (array_key_exists('ignore', $csv_line)) {
-                    unset($csv_line['ignore']);
-                }
-                
-                if ($csv_line) { // CSV line is correct and extension is present
-                    $this->add_extension($csv_line);
-                    $this->add_voicemail($csv_line);
-                    $this->add_device($csv_line);
-                    $added_lines_count += 1;
-                } else {
-                    $skipped_lines_count += 1;
-                    $skipped_lines_array[] = $csv_line;
-                }
-
-            }
-            $result_message .= $text['message-process_csv_file_end'] . "\n\n";
-            // Add statistics to result message
-            $result_message .= $text['message-process_csv_file_stats'] . "\n";
-            $result_message .= " " . $text['message-process_csv_file_added_lines'] . " " . $added_lines_count . "\n";
-            $result_message .= " " . $text['message-process_csv_file_skipped_lines'] . " " . $skipped_lines_count . "\n";
-            if ($skipped_lines > 0) {
-                foreach ($skipped_lines_array as $skipped_line) {
-                    $result_message .= "   " . implode(',', $skipped_line) . "\n";
-                }
-            }
-
-            return $result_message;
-
-        }
-    }
-}
-?>

+ 0 - 90
bulk_import_extensions/root.php

@@ -1,90 +0,0 @@
-<?php
-/*
-	FusionPBX
-	Version: MPL 1.1
-
-	The contents of this file are subject to the Mozilla Public License Version
-	1.1 (the "License"); you may not use this file except in compliance with
-	the License. You may obtain a copy of the License at
-	http://www.mozilla.org/MPL/
-
-	Software distributed under the License is distributed on an "AS IS" basis,
-	WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
-	for the specific language governing rights and limitations under the
-	License.
-
-	The Original Code is FusionPBX
-
-	The Initial Developer of the Original Code is
-	Mark J Crane <[email protected]>
-	Portions created by the Initial Developer are Copyright (C) 2008-2012
-	the Initial Developer. All Rights Reserved.
-
-	Contributor(s):
-	Mark J Crane <[email protected]>
-*/
-
-// make sure the PATH_SEPARATOR is defined
-	umask(2);
-	if (!defined("PATH_SEPARATOR")) {
-		if (strpos($_ENV["OS"], "Win") !== false) {
-			define("PATH_SEPARATOR", ";");
-		} else {
-			define("PATH_SEPARATOR", ":");
-		}
-	}
-
-	if (!isset($output_format)) $output_format = (PHP_SAPI == 'cli') ? 'text' : 'html';
-
-	// make sure the document_root is set
-	$_SERVER["SCRIPT_FILENAME"] = str_replace("\\", '/', $_SERVER["SCRIPT_FILENAME"]);
-	if(PHP_SAPI == 'cli'){
-		chdir(pathinfo(realpath($_SERVER["PHP_SELF"]), PATHINFO_DIRNAME));
-		$script_full_path = str_replace("\\", '/', getcwd() . '/' . $_SERVER["SCRIPT_FILENAME"]);
-		$dirs = explode('/', pathinfo($script_full_path, PATHINFO_DIRNAME));
-		if (file_exists('/project_root.php')) {
-			$path = '/';
-		} else {
-			$i    = 1;
-			$path = '';
-			while ($i < count($dirs)) {
-				$path .= '/' . $dirs[$i];
-				if (file_exists($path. '/project_root.php')) {
-					break;
-				}
-				$i++;
-			}
-		}
-		$_SERVER["DOCUMENT_ROOT"] = $path;
-	}else{
-		$_SERVER["DOCUMENT_ROOT"]   = str_replace($_SERVER["PHP_SELF"], "", $_SERVER["SCRIPT_FILENAME"]);
-	}
-	$_SERVER["DOCUMENT_ROOT"]   = realpath($_SERVER["DOCUMENT_ROOT"]);
-// try to detect if a project path is being used
-	if (!defined('PROJECT_PATH')) {
-		if (is_dir($_SERVER["DOCUMENT_ROOT"]. '/fusionpbx')) {
-			define('PROJECT_PATH', '/fusionpbx');
-		} elseif (file_exists($_SERVER["DOCUMENT_ROOT"]. '/project_root.php')) {
-			define('PROJECT_PATH', '');
-		} else {
-			$dirs = explode('/', str_replace('\\', '/', pathinfo($_SERVER["PHP_SELF"], PATHINFO_DIRNAME)));
-			$i    = 1;
-			$path = $_SERVER["DOCUMENT_ROOT"];
-			while ($i < count($dirs)) {
-				$path .= '/' . $dirs[$i];
-				if (file_exists($path. '/project_root.php')) {
-					break;
-				}
-				$i++;
-			}
-			if(!file_exists($path. '/project_root.php')){
-				die("Failed to locate the Project Root by searching for project_root.php please contact support for assistance");
-			}
-			$project_path = str_replace($_SERVER["DOCUMENT_ROOT"], "", $path);
-			define('PROJECT_PATH', $project_path);
-		}
-		$_SERVER["PROJECT_ROOT"] = realpath($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH);
-		set_include_path(get_include_path() . PATH_SEPARATOR . $_SERVER["PROJECT_ROOT"]);
-	}
-
-?>