Advertisement
Guest User

Untitled

a guest
Feb 2nd, 2018
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.28 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Demo Script for Provisioner
  4.  *
  5.  * @author Darren Schreiber & Andrew Nagy
  6.  * @license MPL / GPLv2 / LGPL
  7.  * @package Provisioner
  8.  */
  9. echo "<pre>";
  10. error_reporting(E_ALL);
  11. ini_set('display_errors', 1);
  12. define('PROVISIONER_BASE', '../');
  13.  
  14. //Get line options
  15. $line_options = array();
  16. $loops_options = array();
  17. $options = array();
  18. $line_static = array();
  19.  
  20. foreach($_REQUEST as $key => $data) {
  21.     if(preg_match("/lineloop\|(.*)\|(.*)/i",$key,$matches)) {
  22.         $stuff = $matches;
  23.         $line = $stuff[1];
  24.         $var = $stuff[2];
  25.         $req = $stuff[0];
  26.    
  27.         $line_options['line'][$line][$var] = $_REQUEST[$req];
  28.         $line_options['line'][$line]['line'] = $line;
  29.         unset($_REQUEST[$req]);
  30.     }elseif(preg_match("/loop\|.*\|(.*)_([\d]*)_(.*)/i",$key,$matches)) {
  31.         $stuff = $matches;     
  32.         $loop = $stuff[1];
  33.         $var = $stuff[3];
  34.         $count = $stuff[2];
  35.         $req = $stuff[0];
  36.    
  37.         $loops_options[$loop][$count][$var] = $_REQUEST[$req];
  38.         unset($_REQUEST[$req]);
  39.     }elseif(preg_match("/option\|(.*)/i",$key,$matches)) {
  40.         $stuff = $matches;
  41.         $var = $stuff[1];
  42.         $req = $stuff[0];
  43.  
  44.         $options[$var] = $_REQUEST[$req];
  45.         unset($_REQUEST[$req]);
  46.     }elseif(preg_match("/line_static\|(.*)\|(.*)/i",$key,$matches)) {
  47.         $stuff = $matches;
  48.         $line = $stuff[1];
  49.         $var = $stuff[2];
  50.         $req = $stuff[0];
  51.  
  52.         $line_static[$line][$var] = $_REQUEST[$req];
  53.         unset($_REQUEST[$req]);
  54.     }
  55. }
  56. if(!empty($loops_options) && !empty($options)) {
  57.     $final_ops2 = array_merge($loops_options,$options);
  58. } elseif(empty($loops_options) && !empty($options)) {
  59.     $final_ops2 = $options;
  60. } elseif(!empty($loops_options) && empty($options)) {
  61.     $final_ops2 = $loops_options;
  62. }
  63.  
  64. $temp = $line_options['line'];
  65. $line_options = array();
  66. $line_options['line'] = array_values($temp);
  67.  
  68. $final_ops = array_merge($line_options,$final_ops2);
  69.  
  70. require('../autoload.php');
  71. require('../includes/json.php');
  72.  
  73. $brand = $_REQUEST['brand'];
  74. $family = $_REQUEST['product'];
  75. $model = $_REQUEST['model'];
  76.  
  77. $class = "endpoint_" . $brand . "_" . $family . '_phone';
  78.  
  79. $endpoint = new $class();
  80.  
  81. //All Endpoint Settings
  82. $endpoint->settings = $final_ops;
  83.  
  84. //Mac Address
  85. $endpoint->mac = $final_ops['mac'];
  86.  
  87. //have to because of versions less than php5.3
  88. $endpoint->brand_name = $brand;
  89. $endpoint->family_line = $family;
  90. $endpoint->model = $model; //Phone Model (Please reference family_data.xml in the family directory for a list of recognized models)
  91.  
  92. //Processor Information, tagged to the top of most configuration files
  93. $endpoint->processor_info = "Web Provisioner 2.0";
  94.  
  95. //Timezone
  96. if (!class_exists("DateTimeZone")) { require('../includes/timezone.php'); }
  97. $endpoint->DateTimeZone = new DateTimeZone($_REQUEST['timezone']);;
  98.  
  99. //Provide alternate Configuration file instead of the one from the hard drive
  100. //$endpoint->config_files_override['$mac.cfg'] = "{\$srvip}\n{\$admin_pass|0}\n{\$test.line.1}";
  101.  
  102. $endpoint->settings['provision']['type'] = 'dynamic';
  103. $endpoint->settings['provision']['protocol'] = 'http';
  104. $endpoint->settings['provision']['path'] = $_SERVER["SERVER_ADDR"] . dirname($_SERVER['REQUEST_URI']) . '/';
  105. $endpoint->settings['provision']['encryption'] = FALSE;
  106.  
  107. $endpoint->settings['network']['dhcp'] = TRUE;
  108. $endpoint->settings['network']['ipv4'] = '';
  109. $endpoint->settings['network']['ipv6'] = '';
  110. $endpoint->settings['network']['subnet'] = '255.255.255.0';
  111. $endpoint->settings['network']['gateway'] = '';
  112. $endpoint->settings['network']['vlan']['id'] = '';
  113. $endpoint->settings['network']['vlan']['qos'] = '';
  114. $endpoint->settings['network']['local_port'] = $endpoint->settings['local_port'];
  115.  
  116. $endpoint->settings['network']['ntp'] = $endpoint->settings['ntp'];
  117.  
  118. // Because every brand is an extension (eventually) of endpoint, you know this function will exist regardless of who it is
  119.  
  120. //$endpoint->debug = TRUE;
  121.  
  122. $returned_data = $endpoint->generate_all_files();
  123.  
  124. //print_r($endpoint->debug_return);
  125.  
  126. ksort($returned_data);
  127.  
  128.  
  129. echo 'Ok <br/>';
  130.  
  131. echo '<br/>';
  132.  
  133. if (isset($_REQUEST['brand'])) {
  134.     foreach($returned_data as $key => $files) {
  135.         echo 'File:'.$key;
  136.         if(in_array($key, $endpoint->protected_files)){
  137.                 echo " [<b>PROTECTED</b>]";
  138.         }
  139.         echo '<br/><textarea rows="50" cols="100">'.$files.'</textarea><br/><br/>';
  140.     }
  141. } else {
  142.     print_r($returned_data);
  143. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement