| | 39 | //If check box GUI element does not exist add it |
|---|
| | 40 | if(!class_exists("gui_checkbox")) { |
|---|
| | 41 | class gui_checkbox extends guiinput { |
|---|
| | 42 | function gui_checkbox($elemname, $checked=false, $prompttext='', $helptext='', $value='on', $post_text = '', $jsonclick = '', $disable=false) { |
|---|
| | 43 | $parent_class = get_parent_class($this); |
|---|
| | 44 | parent::$parent_class($elemname, '', $prompttext, $helptext); |
|---|
| | 45 | |
|---|
| | 46 | $itemchecked = $checked ? 'checked' : ''; |
|---|
| | 47 | $disable_state = $disable ? 'disabled="true"' : ''; |
|---|
| | 48 | $js_onclick_include = ($jsonclick != '') ? 'onclick="' . $jsonclick. '"' : ''; |
|---|
| | 49 | $tabindex = function_exists("guielement::gettabindex") ? "tabindex=" . guielement::gettabindex() : ""; |
|---|
| | 50 | |
|---|
| | 51 | $this->html_input = "<input type=\"checkbox\" name=\"$this->_elemname\" id=\"$this->_elemname\" $disable_state $tabindex value=\"$value\" $js_onclick_include $itemchecked/>$post_text\n"; |
|---|
| | 52 | } |
|---|
| | 53 | } |
|---|
| | 54 | } |
|---|
| | 55 | |
|---|
| | 56 | |
|---|
| | 57 | //Main contributing module function------------------------------------------------------------------------------------------------------------------ |
|---|
| 117 | | //Check if default location exists if not create it else update manager connection values to stay consistent |
|---|
| 118 | | if(($iSymphonyLocations = getISymphonyLocationList()) !== false) { |
|---|
| 119 | | if(!in_array("default", $iSymphonyLocations)) { |
|---|
| 120 | | $object = new ISymphonyLocation; |
|---|
| 121 | | $object->name = "default"; |
|---|
| 122 | | $object->admin_password = "secret"; |
|---|
| 123 | | $object->asterisk_host = "localhost"; |
|---|
| 124 | | $object->asterisk_port = "5038"; |
|---|
| 125 | | $object->asterisk_login = "isymphony"; |
|---|
| 126 | | $object->asterisk_password = "ismanager*con"; |
|---|
| 127 | | $object->originate_timeout = "30000"; |
|---|
| 128 | | $object->jabber_host = ""; |
|---|
| 129 | | $object->jabber_port = "5222"; |
|---|
| 130 | | if($object->add()) { |
|---|
| 131 | | isymphony_write_to_file($debugLogFile, "Added location default\n"); |
|---|
| 132 | | } else { |
|---|
| 133 | | isymphony_write_to_file($errorLogFile, "(Add location)" . $ISERROR. "\n"); |
|---|
| 134 | | } |
|---|
| 135 | | } else { |
|---|
| 136 | | if(($object = getISymphonyLocation("default")) !== false) { |
|---|
| 137 | | |
|---|
| 138 | | //Check if update needs to occur |
|---|
| 139 | | if(($object->asterisk_host != "localhost") || ($object->asterisk_port != "5038") || ($object->asterisk_login != "isymphony") || ($object->asterisk_password != "ismanager*con")) { |
|---|
| 140 | | |
|---|
| 141 | | $object->asterisk_host = "localhost"; |
|---|
| 142 | | $object->asterisk_port = "5038"; |
|---|
| 143 | | $object->asterisk_login = "isymphony"; |
|---|
| 144 | | $object->asterisk_password = "ismanager*con"; |
|---|
| 145 | | |
|---|
| 146 | | if($object->update()) { |
|---|
| 147 | | isymphony_write_to_file($debugLogFile, "Updated location default\n"); |
|---|
| 148 | | } else { |
|---|
| 149 | | isymphony_write_to_file($errorLogFile, "(Update location)" . $ISERROR. "\n"); |
|---|
| 150 | | } |
|---|
| 151 | | } |
|---|
| 152 | | } else { |
|---|
| 153 | | isymphony_write_to_file($errorLogFile, "(Query location)" . $ISERROR. "\n"); |
|---|
| 154 | | } |
|---|
| 155 | | } |
|---|
| 156 | | } else { |
|---|
| 157 | | isymphony_write_to_file($errorLogFile, "(List locations)" . $ISERROR. "\n"); |
|---|
| 158 | | } |
|---|
| 159 | | |
|---|
| 160 | | //Check if default tenant exists if not create it else update context values to stay consistent |
|---|
| 161 | | if(($iSymphonyTenants = getISymphonyTenantList("default")) !== false) { |
|---|
| 162 | | if(!in_array("default", $iSymphonyTenants)) { |
|---|
| 163 | | $object = new ISymphonyTenant; |
|---|
| 164 | | $object->name = "default"; |
|---|
| 165 | | $object->admin_password = "secret"; |
|---|
| 166 | | $object->originating_context = "from-internal"; |
|---|
| 167 | | $object->redirecting_context = "from-internal"; |
|---|
| 168 | | $object->music_on_hold_class = "default"; |
|---|
| 169 | | $object->outside_line_number = ""; |
|---|
| 170 | | $object->record_file_name = "%EXT%-%NAME%-%CID_NAME%-%CID_NUMBER%-%DATE%-%TIME%"; |
|---|
| 171 | | $object->record_file_extension = "wav"; |
|---|
| 172 | | $object->mix_mode = "true"; |
|---|
| 173 | | if($object->add("default")) { |
|---|
| 174 | | isymphony_write_to_file($debugLogFile, "Added tenant default\n"); |
|---|
| 175 | | } else { |
|---|
| 176 | | isymphony_write_to_file($errorLogFile, "(Add tenant)" . $ISERROR. "\n"); |
|---|
| 177 | | } |
|---|
| 178 | | } else { |
|---|
| 179 | | if(($object = getISymphonyTenant("default", "default")) !== false) { |
|---|
| 180 | | |
|---|
| 181 | | //Check if update needs to occur |
|---|
| 182 | | if(($object->originating_context != "from-internal") || ($object->redirecting_context != "from-internal")) { |
|---|
| 183 | | |
|---|
| 184 | | $object->originating_context = "from-internal"; |
|---|
| 185 | | $object->redirecting_context = "from-internal"; |
|---|
| 186 | | |
|---|
| 187 | | if($object->update()) { |
|---|
| 188 | | isymphony_write_to_file($debugLogFile, "Updated tenant default\n"); |
|---|
| 189 | | } else { |
|---|
| 190 | | isymphony_write_to_file($errorLogFile, "(Update tenant)" . $ISERROR. "\n"); |
|---|
| 191 | | } |
|---|
| | 134 | //Check for device user mode |
|---|
| | 135 | $deviceUserMode = ($amp_conf["AMPEXTENSIONS"] == "deviceanduser") ? "true" : "false"; |
|---|
| | 136 | |
|---|
| | 137 | //Check if default location exists if not create it else update manager connection values to stay consistent |
|---|
| | 138 | if(($iSymphonyLocations = getISymphonyLocationList()) !== false) { |
|---|
| | 139 | if(!in_array("default", $iSymphonyLocations)) { |
|---|
| | 140 | $object = new ISymphonyLocation; |
|---|
| | 141 | $object->name = "default"; |
|---|
| | 142 | $object->admin_password = "secret"; |
|---|
| | 143 | $object->asterisk_host = "localhost"; |
|---|
| | 144 | $object->asterisk_port = "5038"; |
|---|
| | 145 | $object->asterisk_login = "isymphony"; |
|---|
| | 146 | $object->asterisk_password = "ismanager*con"; |
|---|
| | 147 | $object->originate_timeout = "30000"; |
|---|
| | 148 | $object->jabber_host = ""; |
|---|
| | 149 | $object->jabber_port = "5222"; |
|---|
| | 150 | $object->device_user_mode = $deviceUserMode; |
|---|
| | 151 | if($object->add()) { |
|---|
| | 152 | isymphony_write_to_file($debugLogFile, "Added location default\n"); |
|---|
| | 153 | } else { |
|---|
| | 154 | isymphony_write_to_file($errorLogFile, "(Add location)" . $ISERROR. "\n"); |
|---|
| 194 | | isymphony_write_to_file($errorLogFile, "(Query tenant)" . $ISERROR. "\n"); |
|---|
| 195 | | } |
|---|
| | 157 | if(($object = getISymphonyLocation("default")) !== false) { |
|---|
| | 158 | |
|---|
| | 159 | //Check if update needs to occur |
|---|
| | 160 | if(($object->asterisk_host != "localhost") || ($object->asterisk_port != "5038") || ($object->asterisk_login != "isymphony") || ($object->asterisk_password != "ismanager*con") || ($object->device_user_mode != $deviceUserMode)) { |
|---|
| | 161 | |
|---|
| | 162 | $object->asterisk_host = "localhost"; |
|---|
| | 163 | $object->asterisk_port = "5038"; |
|---|
| | 164 | $object->asterisk_login = "isymphony"; |
|---|
| | 165 | $object->asterisk_password = "ismanager*con"; |
|---|
| | 166 | $object->device_user_mode = $deviceUserMode; |
|---|
| | 167 | |
|---|
| | 168 | if($object->update()) { |
|---|
| | 169 | isymphony_write_to_file($debugLogFile, "Updated location default\n"); |
|---|
| | 170 | } else { |
|---|
| | 171 | isymphony_write_to_file($errorLogFile, "(Update location)" . $ISERROR. "\n"); |
|---|
| | 172 | } |
|---|
| | 173 | } |
|---|
| | 174 | } else { |
|---|
| | 175 | isymphony_write_to_file($errorLogFile, "(Query location)" . $ISERROR. "\n"); |
|---|
| | 176 | } |
|---|
| | 177 | } |
|---|
| | 178 | } else { |
|---|
| | 179 | isymphony_write_to_file($errorLogFile, "(List locations)" . $ISERROR. "\n"); |
|---|
| 197 | | } else { |
|---|
| 198 | | isymphony_write_to_file($errorLogFile, "(List tenants)" . $ISERROR. "\n"); |
|---|
| 199 | | } |
|---|
| 200 | | |
|---|
| 201 | | /* |
|---|
| 202 | | * Grab list of configured users from FreePBX and |
|---|
| 203 | | * compare them to the ones configured in iSymphony. Add, remove, and update |
|---|
| 204 | | * any extensions and profiles that differ from the FreePBX config. |
|---|
| 205 | | */ |
|---|
| 206 | | if((!function_exists("core_users_list")) || (($freePBXUsers = core_users_list()) === null)){ |
|---|
| | 181 | |
|---|
| | 182 | //Check if default tenant exists if not create it else update context values to stay consistent |
|---|
| | 183 | if(($iSymphonyTenants = getISymphonyTenantList("default")) !== false) { |
|---|
| | 184 | if(!in_array("default", $iSymphonyTenants)) { |
|---|
| | 185 | $object = new ISymphonyTenant; |
|---|
| | 186 | $object->name = "default"; |
|---|
| | 187 | $object->admin_password = "secret"; |
|---|
| | 188 | $object->originating_context = "from-internal"; |
|---|
| | 189 | $object->redirecting_context = "from-internal"; |
|---|
| | 190 | $object->music_on_hold_class = "default"; |
|---|
| | 191 | $object->outside_line_number = ""; |
|---|
| | 192 | $object->record_file_name = "%EXT%-%NAME%-%CID_NAME%-%CID_NUMBER%-%DATE%-%TIME%"; |
|---|
| | 193 | $object->record_file_extension = "wav"; |
|---|
| | 194 | $object->mix_mode = "true"; |
|---|
| | 195 | if($object->add("default")) { |
|---|
| | 196 | isymphony_write_to_file($debugLogFile, "Added tenant default\n"); |
|---|
| | 197 | } else { |
|---|
| | 198 | isymphony_write_to_file($errorLogFile, "(Add tenant)" . $ISERROR. "\n"); |
|---|
| | 199 | } |
|---|
| | 200 | } else { |
|---|
| | 201 | if(($object = getISymphonyTenant("default", "default")) !== false) { |
|---|
| | 202 | |
|---|
| | 203 | //Check if update needs to occur |
|---|
| | 204 | if(($object->originating_context != "from-internal") || ($object->redirecting_context != "from-internal")) { |
|---|
| | 205 | |
|---|
| | 206 | $object->originating_context = "from-internal"; |
|---|
| | 207 | $object->redirecting_context = "from-internal"; |
|---|
| | 208 | |
|---|
| | 209 | if($object->update()) { |
|---|
| | 210 | isymphony_write_to_file($debugLogFile, "Updated tenant default\n"); |
|---|
| | 211 | } else { |
|---|
| | 212 | isymphony_write_to_file($errorLogFile, "(Update tenant)" . $ISERROR. "\n"); |
|---|
| | 213 | } |
|---|
| | 214 | } |
|---|
| | 215 | } else { |
|---|
| | 216 | isymphony_write_to_file($errorLogFile, "(Query tenant)" . $ISERROR. "\n"); |
|---|
| | 217 | } |
|---|
| | 218 | } |
|---|
| | 219 | } else { |
|---|
| | 220 | isymphony_write_to_file($errorLogFile, "(List tenants)" . $ISERROR. "\n"); |
|---|
| | 221 | } |
|---|
| | 222 | |
|---|
| | 223 | //Grab list of configured extensions from the database |
|---|
| | 224 | $freePBXTempUsers = isymphony_user_list(); |
|---|
| | 225 | |
|---|
| | 226 | //Filter list to exclude extensions that are not marked for addition |
|---|
| 218 | | //Delete appropriate extensions |
|---|
| 219 | | $deleteExtensionArray = array_diff($iSymphonyExtensions, $freePBXExtensionCheckDeleteArray); |
|---|
| 220 | | foreach($deleteExtensionArray as $val) { |
|---|
| 221 | | if(removeISymphonyExtension("default", "default", $val)) { |
|---|
| 222 | | isymphony_write_to_file($debugLogFile, "Deleted extension {$val}\n"); |
|---|
| 223 | | $iSymphonyExtensions = isymphony_remove_array_item($iSymphonyExtensions, $val); |
|---|
| 224 | | } else { |
|---|
| 225 | | isymphony_write_to_file($errorLogFile, "(Delete extension)" . $ISERROR. "\n"); |
|---|
| | 234 | //Filter the previous list for profiles excluding ones not marked for profile addition |
|---|
| | 235 | $freePBXProfiles = array(); |
|---|
| | 236 | foreach($freePBXUsers as $freePBXUser) { |
|---|
| | 237 | if($freePBXUser["add_profile"] == "1") { |
|---|
| | 238 | array_push($freePBXProfiles, $freePBXUser); |
|---|
| 288 | | //If profile does not exist add it |
|---|
| 289 | | if(!in_array($freePBXUser[0], $iSymphonyProfiles)) { |
|---|
| 290 | | |
|---|
| 291 | | //Check sip and iax for a secret to use as a profile password |
|---|
| 292 | | $profilePassword = ""; |
|---|
| 293 | | if(($sipInfo = core_devices_getsip($freePBXUser[0])) != null) { |
|---|
| 294 | | $profilePassword = $sipInfo['secret']; |
|---|
| 295 | | } else if(($aixInfo = core_devices_getiax2($freePBXUser[0])) != null) { |
|---|
| 296 | | $profilePassword = $aixInfo['secret']; |
|---|
| 297 | | } |
|---|
| 298 | | |
|---|
| 299 | | //If no password was found or secret value is blank set to 'secret' |
|---|
| 300 | | if($profilePassword == "") { |
|---|
| 301 | | $profilePassword = "secret"; |
|---|
| 302 | | } |
|---|
| 303 | | |
|---|
| | 305 | //Build array of freePBX extensions to compare to iSymphony list for deletes |
|---|
| | 306 | $freePBXProfileCheckDeleteArray = array(); |
|---|
| | 307 | foreach($freePBXProfiles as $freePBXProfile) { |
|---|
| | 308 | array_push($freePBXProfileCheckDeleteArray, $freePBXProfile["user_id"]); |
|---|
| | 309 | } |
|---|
| | 310 | |
|---|
| | 311 | //Delete appropriate profiles |
|---|
| | 312 | $deleteProfileArray = array_diff($iSymphonyProfiles, $freePBXProfileCheckDeleteArray); |
|---|
| | 313 | foreach($deleteProfileArray as $val) { |
|---|
| | 314 | if(removeISymphonyProfile("default", "default", $val)) { |
|---|
| | 315 | isymphony_write_to_file($debugLogFile, "Deleted profile {$val}\n"); |
|---|
| | 316 | $iSymphonyProfiles = isymphony_remove_array_item($iSymphonyProfiles, $val); |
|---|
| | 317 | } else { |
|---|
| | 318 | isymphony_write_to_file($errorLogFile, "(Delete profile)" . $ISERROR. "\n"); |
|---|
| | 319 | } |
|---|
| | 320 | } |
|---|
| | 321 | |
|---|
| | 322 | //Add and update profiles |
|---|
| | 323 | foreach($freePBXProfiles as $freePBXProfile) { |
|---|
| | 324 | |
|---|
| | 325 | //If profile does not exist add it else update it |
|---|
| | 326 | if(!in_array($freePBXProfile["user_id"], $iSymphonyProfiles)) { |
|---|
| | 327 | |
|---|
| | 346 | } else { |
|---|
| | 347 | |
|---|
| | 348 | //Query profile configuration and update values |
|---|
| | 349 | if(($object = getISymphonyProfile("default", "default", $freePBXProfile["user_id"])) !== false) { |
|---|
| | 350 | |
|---|
| | 351 | //Check if update needs to occur |
|---|
| | 352 | if($object->password != $freePBXProfile["password"]) { |
|---|
| | 353 | |
|---|
| | 354 | $object->password = $freePBXProfile["password"]; |
|---|
| | 355 | |
|---|
| | 356 | if($object->update()) { |
|---|
| | 357 | isymphony_write_to_file($debugLogFile, "Updated profile {$freePBXProfile['user_id']}\n"); |
|---|
| | 358 | } else { |
|---|
| | 359 | isymphony_write_to_file($errorLogFile, "(Update profile)" . $ISERROR. "\n"); |
|---|
| | 360 | } |
|---|
| | 361 | } |
|---|
| | 362 | } else { |
|---|
| | 363 | isymphony_write_to_file($errorLogFile, "(Query profile)" . $ISERROR. "\n"); |
|---|
| | 364 | } |
|---|
| | 365 | } |
|---|
| | 366 | } |
|---|
| | 367 | } else { |
|---|
| | 368 | isymphony_write_to_file($errorLogFile, "(List extensions/profiles)" . $ISERROR. "\n"); |
|---|
| | 369 | } |
|---|
| | 370 | |
|---|
| | 371 | //Grab list of configured queues from the database |
|---|
| | 372 | $freePBXTempQueues = isymphony_queue_list(); |
|---|
| | 373 | |
|---|
| | 374 | //Filter list to exclude queues that are not marked for addition |
|---|
| | 375 | $freePBXQueues = array(); |
|---|
| | 376 | foreach($freePBXTempQueues as $freePBXTempQueue) { |
|---|
| | 377 | if($freePBXTempQueue["add_queue"] == "1") { |
|---|
| | 378 | array_push($freePBXQueues, $freePBXTempQueue); |
|---|
| | 379 | } |
|---|
| | 380 | } |
|---|
| | 381 | |
|---|
| | 382 | //Add, edit and remove queues |
|---|
| | 383 | if(($iSymphonyQueues = getISymphonyQueueList("default", "default")) !== false) { |
|---|
| | 384 | |
|---|
| | 385 | //Build array of freePBX queues to compare to iSymphony list for deletes |
|---|
| | 386 | $freePBXQueueCheckDeleteArray = array(); |
|---|
| | 387 | foreach($freePBXQueues as $freePBXQueue) { |
|---|
| | 388 | array_push($freePBXQueueCheckDeleteArray, $freePBXQueue["display_name"]); |
|---|
| | 389 | } |
|---|
| | 390 | |
|---|