Ik moet een document werkend zien te krijgen, echter word er een database gebruikt, die ik niet heb. Zou ik deze op een of andere manier eruit kunnen halen, en de functionaliteit daarmee weer goed te krijgen?
Code:
Code:
Code:
<?php
session_start();
/*
YEALINK T46G aangepast:
- Timezone, Dataformat, Timeformat
- NTP server
- Custom URL voor achtergrond
- Timezone name (hard in mac.cfg)
account.{$line_m1}.sip_server_host = {$server_host}
phone_setting.inactive_backlight_level = 1
*/
//error_reporting(E_ALL);
//include('../../public_html/includes/config.php');
define('PROVISIONER_BASE', 'c:/xampp/htdocs/Provisioner-master/'); //Location to the root directory where you unpackaged provisioner,
require(PROVISIONER_BASE.'includes/json.php'); //Required for PHP less than 5.3
require_once(PROVISIONER_BASE.'autoload.php'); //Load the autoloader (there is another way to do this if the autoloader doesn't work
// DEBUG
// Email ERROR
$subject2 = "[PROV] - " . date("d-m-Y H:i:s") . "";
$body2 = "=====================================\r\n";
$body2 .= "Prov informatie\r\n";
$body2 .= "=====================================\r\n";
$body2 .= "req: " . $_GET['req'] . "\r\n";
$body2 .= "=====================================\r\n";
//mail("bernard.buitenhuis@gmail.com", $subject2, $body2, "From: no-reply@maxitel.nl");
if($_GET['brand'] == 'yealink'){
switch ($_GET['model']) {
/* case 'T20':
$model = 'T20';
$family = 't2x';
$prov_path = 'mtsip.nl/provisioning/yealink/T20/';
break;
case 'T22':
$model = 'T22';
$family = 't2x';
$prov_path = 'mtsip.nl/provisioning/yealink/T22/';
break;
case 'T26':
$model = 'T26';
$family = 't2x';
$prov_path = 'mtsip.nl/provisioning/yealink/T26/';
break;
case 'T28':
$model = 'T28';
$family = 't2x';
$prov_path = 'mtsip.nl/provisioning/yealink/T26/';
break; */
case 'T42G':
// Zoek MAC in user agent
preg_match("/(.*) (.*)/", $_SERVER['HTTP_USER_AGENT'], $mac);
$mac = str_replace(':', '', $mac[2]);
$brand = 'yealinkv70';
$model = 'T42G';
$family = 't4x';
$prov_path = 'http://www.provisioner.besaba.com/endpoint/yealinkv70/t4x/';
break;
case 'T46G':
// Zoek MAC in user agent
preg_match("/(.*) (.*)/", $_SERVER['HTTP_USER_AGENT'], $mac);
$mac = str_replace(':', '', $mac[2]);
//$mac = '0015656c8348';
$brand = 'yealinkv70';
$model = 'T46G';
$family = 't4x';
$prov_path = 'http://www.provisioner.besaba.com/endpoint/yealinkv70/t4x/';
break;
default:
echo "## Yealink - not supported model for auto provisioning";
}
}
/*
elseif($_GET['brand'] == 'grandstream'){
$_GET['req'] = str_replace("cfg", "", $_GET['req']);
$_GET['req'] = str_replace(".xml", "", $_GET['req']);
$mac = strtolower($_GET['req']);
switch ($_GET['model']) {
case 'GXP2110':
$model = 'GXP2110';
$family = 'gxphd';
$prov_path = 'mtsip.nl/provisioning/grandstream/GXP2110';
break;
case 'GXP2200':
$model = 'GXP2200';
$family = 'gxphd';
$prov_path = 'mtsip.nl/provisioning/grandstream/GXP2200';
break;
default:
echo "## Grandstream - not supported model for auto provisioning";
}
} elseif($_GET['brand'] == 'cisco'){
$_GET['req'] = str_replace("cfg", "", $_GET['req']);
$_GET['req'] = str_replace(".xml", "", $_GET['req']);
$_GET['req'] = str_replace("spa", "", $_GET['req']);
$mac = strtolower($_GET['req']);
switch ($_GET['model']) {
case 'SPA504G':
$model = 'SPA504G';
$family = 'spa5xx';
$prov_path = 'mtsip.nl/provisioning/cisco/SPA504G';
break;
default:
echo "## Cisco - not supported model for auto provisioning";
}
}
*/
$MTAPIKEY = 10;
$MTAPIURL = "http://www.provisioner.besaba.com/web/provision";
$MTCLIENTID = 10;
$data = array("apikey"=>$MTAPIKEY,"clientid"=>$MTCLIENTID,"mac" => $mac);
$ch = curl_init($MTAPIURL.'tools/GetProvisioningProfile/');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
$result = json_decode($result);
if(@$result->Profile < 1)
{
echo "## No records found for MAC/ID";
exit();
}
$aProv = @get_object_vars($result->Profile[0]);
/* if(empty($aProv['id']))
{
$aProv = $_SESSION['aProv'];
$mac = $_SESSION['mac'];
}
else
{
$_SESSION['aProv'] = $aProv;
$_SESSION['mac'] = $mac;
} */
if (!class_exists("DateTimeZone")) { require(PROVISIONER_BASE.'includes/timezone.php'); }
$class = "endpoint_" . $brand . "_" . $family . '_phone';
$endpoint = new $class();
$endpoint->brand_name = $brand;
$endpoint->family_line = $family;
$endpoint->model = $model;
$endpoint->mac = $mac;
$endpoint->processor_info = "MT Provisioner";
$endpoint->DateTimeZone = new DateTimeZone('Europe/Amsterdam');;
$endpoint->settings['network']['dhcp'] = TRUE;
$endpoint->settings['network']['ipv4'] = '';
$endpoint->settings['network']['ipv6'] = '';
$endpoint->settings['network']['subnet'] = '255.255.255.0';
$endpoint->settings['network']['gateway'] = '';
//$endpoint->settings['network']['vlan']['id'] = '0';
//$endpoint->settings['network']['vlan']['qos'] = '0';
$endpoint->settings['rtpstart'] = $aProv['rtp_start'];
$endpoint->settings['rtpstop'] = $aProv['rtp_stop'];
$endpoint->settings['line'][0]['displayname'] = $aProv['display_1'];
$endpoint->settings['line'][0]['username'] = $aProv['account_1'];
$endpoint->settings['line'][0]['authname'] = $aProv['account_1'];
$endpoint->settings['line'][0]['secret'] = $aProv['password_1'];
$endpoint->settings['line'][0]['line'] = 1;
$endpoint->settings['line'][0]['line_enabled'] = true;
$endpoint->settings['line'][0]['server_host'] = 'sip.mtsip.nl';
$endpoint->settings['line'][0]['server_port'] = 5060;
$endpoint->settings['line'][0]['server_expires'] = 3600;
$endpoint->settings['line'][0]['outbound_host'] = 'sip.mtsip.nl';
$endpoint->settings['line'][0]['outbound_port'] = 5060;
if(!empty($aProv['account_2'])){
$endpoint->settings['line'][1]['displayname'] = $aProv['display_2'];
$endpoint->settings['line'][1]['username'] = $aProv['account_2'];
$endpoint->settings['line'][1]['authname'] = $aProv['account_2'];
$endpoint->settings['line'][1]['secret'] = $aProv['password_2'];
$endpoint->settings['line'][1]['line'] = 2;
$endpoint->settings['line'][1]['line_enabled'] = true;
$endpoint->settings['line'][1]['server_host'] = 'sip.mtsip.nl';
$endpoint->settings['line'][1]['server_port'] = 5060;
$endpoint->settings['line'][1]['server_expires'] = 3600;
$endpoint->settings['line'][1]['outbound_host'] = 'sip.mtsip.nl';
$endpoint->settings['line'][1]['outbound_port'] = 5060;
}
if(!empty($aProv['account_3'])){
$endpoint->settings['line'][2]['displayname'] = $aProv['display_3'];
$endpoint->settings['line'][2]['username'] = $aProv['account_3'];
$endpoint->settings['line'][2]['authname'] = $aProv['account_3'];
$endpoint->settings['line'][2]['secret'] = $aProv['password_3'];
$endpoint->settings['line'][2]['line'] = 3;
$endpoint->settings['line'][2]['line_enabled'] = true;
$endpoint->settings['line'][2]['server_host'] = 'sip.mtsip.nl';
$endpoint->settings['line'][2]['server_port'] = 5060;
$endpoint->settings['line'][2]['server_expires'] = 3600;
$endpoint->settings['line'][2]['outbound_host'] = 'sip.mtsip.nl';
$endpoint->settings['line'][2]['outbound_port'] = 5060;
}
if(!empty($aProv['account_4'])){
$endpoint->settings['line'][3]['displayname'] = $aProv['display_4'];
$endpoint->settings['line'][3]['username'] = $aProv['account_4'];
$endpoint->settings['line'][3]['authname'] = $aProv['account_4'];
$endpoint->settings['line'][3]['secret'] = $aProv['password_4'];
$endpoint->settings['line'][3]['line'] = 4;
$endpoint->settings['line'][3]['line_enabled'] = true;
$endpoint->settings['line'][3]['server_host'] = 'sip.mtsip.nl';
$endpoint->settings['line'][3]['server_port'] = 5060;
$endpoint->settings['line'][3]['server_expires'] = 3600;
$endpoint->settings['line'][3]['outbound_host'] = 'sip.mtsip.nl';
$endpoint->settings['line'][3]['outbound_port'] = 5060;
}
// Line keys
if(!empty($aProv['line_keys']))
{
$type_array = array('Default'=>15, 'Line'=>15, 'BLF'=>16, 'SpeedDial'=>13);
$aProv['line_keys'] = unserialize($aProv['line_keys']);
foreach($aProv['line_keys'] as $line=>$value)
{
$endpoint->settings['loops']['linekey'][$line]['line'] = $line;
$endpoint->settings['loops']['linekey'][$line]['label'] = $value['label'];
$endpoint->settings['loops']['linekey'][$line]['value'] = $value['ext'];
$endpoint->settings['loops']['linekey'][$line]['type'] = $type_array[$value['type']];
}
}
$endpoint->settings['ntp'] = '0.pool.ntp.org';
$endpoint->settings['timezone_name'] = 'CEST';
$endpoint->settings['timezone_offset'] = '+1';
$endpoint->settings['provision']['type'] = 'dynamic';
$endpoint->settings['provision']['protocol'] = 'http';
$endpoint->settings['provision']['path'] = $prov_path;
$endpoint->settings['adminpw'] = $aProv['admin_pw'];
// Logo
if(!empty($aProv['custom_logo']))
{
$endpoint->settings['logo_url'] = $aProv['custom_logo'];
$endpoint->settings['uselogo'] = 'Config:'.basename($aProv['custom_logo']);
}
try{
$returned_data = $endpoint->generate_all_files();
} catch (Exception $e) {
die('Error from Provisioner Lib: '.$e);
}
//print_r($returned_data);
if($_GET['brand'] == 'yealink'){
$export = $_GET['req'].'.'.$_GET['ext'];
echo $returned_data[$export];
}
elseif($_GET['brand'] == 'grandstream'){
$export = 'cfg'.$mac;
echo $returned_data[$export];
}
elseif($_GET['brand'] == 'cisco'){
//print_r($returned_data);
$export = 'spa'.$mac.'.xml';
echo $returned_data[$export];
}
// Update info
//$mysqli = new mysqli(DB_SERVER, DB_USER, DB_PASS, DB_DB);
//$mysqli->query("UPDATE provisioning SET last_prov = now(), last_phone ='".$brand."-".$family."-".$model."' WHERE mac = '{$mac}'");
?>
Laatst bewerkt: