Changeset 12767

Show
Ignore:
Timestamp:
10/05/11 17:17:17 (2 years ago)
Author:
tm1000
Message:

Fixed package manager once-and-for-all

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/branches/2.10/endpointman/includes/brand_model_manager.inc

    r12708 r12767  
    77 * @package Provisioner 
    88 */ 
    9  
    109$check_for_updates = FALSE; 
    1110global $type; 
     
    4443  } 
    4544} elseif(isset($_REQUEST['button_check_for_updates'])) { 
     45    //die('hi'); 
    4646  $brand_up = $endpoint->update_check(); 
    4747        $endpoint->tpl->assign("update_check", 1); 
     
    146146} 
    147147 
    148 //draw the template  
     148//draw the template 
     149//echo "test";   
    149150echo $endpoint->tpl->draw( 'brand_model_manager' ); 
  • modules/branches/2.10/endpointman/includes/functions.inc

    r12766 r12767  
    17061706        $temp_file = PHONE_MODULES_PATH.'temp/'.$directory.'.xml'; 
    17071707        file_exists(dirname($temp_file)) ? '' : mkdir(dirname($temp_file)); 
     1708                 
    17081709        if($this->download_xml_file($location, $temp_file)) { 
    17091710            $handle = fopen($temp_file, "rb"); 
    17101711            $contents = fread($handle, filesize($temp_file)); 
    17111712            fclose($handle); 
     1713             
    17121714            @$a = simplexml_load_string($contents); 
    17131715            if($a===FALSE) { 
     
    17321734    function update_check() { 
    17331735        $master_result = $this->download_xml(UPDATE_PATH . "master.xml"); 
     1736         
     1737         
    17341738        if(!$master_result) { 
    17351739            $this->error['brand_update_check_master'] = "Not able to connect to repository. Using local master file instead."; 
    17361740        } 
    1737  
     1741         
    17381742        $temp = $this->xml2array(PHONE_MODULES_PATH.'master.xml'); 
    1739  
    17401743        $endpoint_package = $temp['data']['package']; 
    17411744        $endpoint_last_mod = $temp['data']['last_modified']; 
     
    17431746        $sql = "SELECT value FROM endpointman_global_vars WHERE var_name LIKE 'endpoint_vers'"; 
    17441747        $data = $this->db->getOne($sql); 
    1745  
    1746         $handle = fopen(UPDATE_PATH."/update_status", "rb"); 
    1747         $contents = stream_get_contents($handle); 
    1748         fclose($handle); 
     1748         
     1749        $contents = file_get_contents(UPDATE_PATH."/update_status"); 
     1750 
     1751         
    17491752        if($contents != '1') { 
    17501753            if(($data == "") OR ($data <= $endpoint_last_mod)) { 
     
    23002303        return false; 
    23012304    } 
    2302  
    2303     /** 
    2304      * cURL function to download files with a progress bar and echo output while downloading to the screen 
    2305      * @global <type> $ch 
    2306      * @global <type> $fout 
    2307      * @global <type> $file_size 
    2308      * @global <type> $downloaded 
    2309      * @global <type> $pkg_interface 
    2310      * @global <type> $progress_bar 
    2311      * @param <type> $url_file 
    2312      * @param <type> $destination_file 
    2313      * @return <type> 
    2314      */ 
     2305     
     2306    function run_in_background($Command, $Priority = 0) { 
     2307        if ($Priority) 
     2308            $PID = shell_exec("nohup nice -n $Priority $Command 2> /dev/null & echo $!"); 
     2309        else 
     2310            $PID = shell_exec("nohup $Command > /dev/null 2> /dev/null & echo $!"); 
     2311        return($PID); 
     2312    } 
     2313 
     2314    function is_process_running($PID) { 
     2315        exec("ps $PID", $ProcessState); 
     2316        return(count($ProcessState) >= 2); 
     2317    } 
     2318 
    23152319    function download_file_with_progress_bar($url_file, $destination_file) { 
    2316         global $ch, $fout, $file_size, $downloaded, $pkg_interface, $progress_bar; 
    23172320        set_time_limit(0); 
    2318         $progress_bar = 1; 
    2319         $file_size  = 1; 
    2320         $downloaded = 1; 
    2321         echo "&nbsp;"; 
    2322         /* open destination file */ 
    2323         $fout = fopen($destination_file, "wb"); 
    2324  
    2325         /* 
    2326      *  Originally by Author: Keyvan Minoukadeh 
    2327      *  Modified by Scott Ullrich to return Content-Length size 
    2328         */ 
    2329  
    2330         $ch = curl_init(); 
    2331         curl_setopt($ch, CURLOPT_URL, $url_file); 
    2332         curl_setopt($ch, CURLOPT_HEADERFUNCTION, 'endpointmanager_read_header'); 
    2333         curl_setopt($ch, CURLOPT_WRITEFUNCTION, 'endpointmanager_read_body'); 
    2334         curl_setopt($ch, CURLOPT_NOPROGRESS, '1'); 
    2335         curl_setopt($ch, CURLOPT_TIMEOUT, 120); 
    2336  
    2337         curl_exec($ch); 
    2338         $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); 
    2339         if($fout) 
    2340             fclose($fout); 
    2341         curl_close($ch); 
    2342         return ($http_code == 200) ? true : $http_code; 
     2321        $headers = get_headers($url_file, 1);  
     2322        $size = $headers['Content-Length'];  
     2323 
     2324        if(preg_match('/200/', $headers[0])) { 
     2325            $pid = $this->run_in_background("wget ". $url_file . " -O " . $destination_file); 
     2326 
     2327            while($this->is_process_running($pid)) {  
     2328 
     2329                $out = 100 * round(filesize($destination_file) / $size,2); 
     2330                echo '<script type="text/javascript">document.getElementById(\'DivExample\').innerHTML="%'.$out.'";</script>'; 
     2331 
     2332                usleep('500'); 
     2333                endpointman_flush_buffers(); 
     2334 
     2335                clearstatcache(); // make sure PHP actually checks dest. file size  
     2336            } 
     2337            return true; 
     2338        } else { 
     2339            return false; 
     2340        } 
    23432341    } 
    23442342 
    23452343    function download_file_no_progress_bar($url_file, $destination_file) { 
    2346         global $ch, $fout, $file_size, $downloaded, $pkg_interface, $progress_bar; 
    2347         set_time_limit(0); 
    2348         $progress_bar = 0; 
    2349         $file_size  = 1; 
    2350         $downloaded = 1; 
    2351         /* open destination file */ 
    2352         $fout = fopen($destination_file, "wb"); 
    2353  
    2354         /* 
    2355      *  Originally by Author: Keyvan Minoukadeh 
    2356      *  Modified by Scott Ullrich to return Content-Length size 
    2357         */ 
    2358  
    2359         $ch = curl_init(); 
    2360         curl_setopt($ch, CURLOPT_URL, $url_file); 
    2361         curl_setopt($ch, CURLOPT_HEADERFUNCTION, 'endpointmanager_read_header'); 
    2362         curl_setopt($ch, CURLOPT_WRITEFUNCTION, 'endpointmanager_read_body'); 
    2363         curl_setopt($ch, CURLOPT_NOPROGRESS, '1'); 
    2364         curl_setopt($ch, CURLOPT_TIMEOUT, 120); 
    2365  
    2366         curl_exec($ch); 
    2367         $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); 
    2368         if($fout) 
    2369             fclose($fout); 
    2370         curl_close($ch); 
    2371         return ($http_code == 200) ? true : $http_code; 
     2344        $contents = file_get_contents($url_file); 
     2345        if(preg_match('/200/', $http_response_header[0])) { 
     2346            file_put_contents($destination_file,$contents); 
     2347            //check file placement 
     2348            if(!file_exists($destination_file)) { 
     2349                return false; 
     2350            } 
     2351            return true; 
     2352        } else { 
     2353            return false; 
     2354        } 
    23722355    } 
    23732356 
    23742357    function download_xml_file($url_file, $destination_file) { 
    2375         global $ch, $fout, $file_size, $downloaded, $pkg_interface, $progress_bar; 
    2376         set_time_limit(0); 
    2377         $progress_bar = 0; 
    2378         $file_size  = 1; 
    2379         $downloaded = 1; 
    2380         /* open destination file */ 
    2381         $fout = fopen($destination_file, "wb"); 
    2382  
    2383         /* 
    2384      *  Originally by Author: Keyvan Minoukadeh 
    2385      *  Modified by Scott Ullrich to return Content-Length size 
    2386         */ 
    2387  
    2388         $ch = curl_init(); 
    2389         curl_setopt($ch, CURLOPT_URL, $url_file); 
    2390         curl_setopt($ch, CURLOPT_HEADERFUNCTION, 'endpointmanager_read_header'); 
    2391         curl_setopt($ch, CURLOPT_WRITEFUNCTION, 'endpointmanager_read_body'); 
    2392         curl_setopt($ch, CURLOPT_NOPROGRESS, '1'); 
    2393         curl_setopt($ch, CURLOPT_TIMEOUT, 20); 
    2394  
    2395         curl_exec($ch); 
    2396         $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); 
    2397         if($fout) 
    2398             fclose($fout); 
    2399         curl_close($ch); 
    2400         return ($http_code == 200) ? true : $http_code; 
     2358        $contents = file_get_contents($url_file); 
     2359        if(preg_match('/200/', $http_response_header[0])) { 
     2360            file_put_contents($destination_file,$contents); 
     2361            //check file placement 
     2362            if(!file_exists($destination_file)) { 
     2363                return false; 
     2364            } 
     2365            return true; 
     2366        } else { 
     2367            return false; 
     2368        } 
    24012369    } 
    24022370 
     
    29792947    ob_start(); 
    29802948} 
    2981  
    2982 function endpointman_update_progress_bar($out) { 
    2983     echo '<script type="text/javascript">document.getElementById(\'DivExample\').innerHTML="%'.$out.'";</script>'; 
    2984 } 
    2985  
    2986 function endpointmanager_read_header($ch, $string) { 
    2987     global $file_size, $fout; 
    2988     $length = strlen($string); 
    2989     $regs = ""; 
    2990     preg_match("/(Content-Length:) (.*)/i", $string, $regs); 
    2991     if((isset($regs[2])) AND ($regs[2] <> "")) { 
    2992         $file_size = intval($regs[2]); 
    2993     } 
    2994     //ob_flush(); 
    2995     endpointman_flush_buffers(); 
    2996     return $length; 
    2997 } 
    2998  
    2999 function endpointmanager_read_body($ch, $string) { 
    3000     global $fout, $file_size, $downloaded, $lastseen, $progress_bar; 
    3001     $length = strlen($string); 
    3002     $downloaded += intval($length); 
    3003     $downloadProgress = round(100 * (1 - $downloaded / $file_size), 0); 
    3004     $downloadProgress = 100 - $downloadProgress; 
    3005     if($lastseen <> $downloadProgress and $downloadProgress < 101) { 
    3006         if($progress_bar) { 
    3007             endpointman_update_progress_bar($downloadProgress); 
    3008         } 
    3009         $lastseen = $downloadProgress; 
    3010     } 
    3011     if($fout) 
    3012         fwrite($fout, $string); 
    3013     //ob_flush(); 
    3014     endpointman_flush_buffers(); 
    3015     return $length; 
    3016 } 
  • modules/branches/2.10/endpointman/install.php

    r12766 r12767  
    862862    } 
    863863 
    864     if($ver <= "2920") { 
     864    if ($ver <= "2920") { 
    865865        out("Adding new Network Time Protocol Setting"); 
    866         $sql = "INSERT INTO `endpointman_global_vars` (`idnum`, `var_name`, `value`) VALUES (NULL, 'ntp', '".$_SERVER["SERVER_ADDR"]."')"; 
     866        $sql = "INSERT INTO `endpointman_global_vars` (`idnum`, `var_name`, `value`) VALUES (NULL, 'ntp', '" . $_SERVER["SERVER_ADDR"] . "')"; 
    867867        $db->query($sql); 
    868868        out("Upgrading all timezone data to new improved simplified system"); 
     
    958958 
    959959        out('Creating symlink to web provisioner'); 
    960         if(!symlink(LOCAL_PATH."provisioning",$amp_conf['AMPWEBROOT']."/provisioning")) { 
    961             out("<strong>Your permissions are wrong on ".$amp_conf['AMPWEBROOT'].", web provisioning link not created!</strong>"); 
     960        if (!symlink(LOCAL_PATH . "provisioning", $amp_conf['AMPWEBROOT'] . "/provisioning")) { 
     961            out("<strong>Your permissions are wrong on " . $amp_conf['AMPWEBROOT'] . ", web provisioning link not created!</strong>"); 
    962962        } 
    963963 
     
    965965        $old_tz_gmt = $db->getOne($sql); 
    966966 
    967         $sql = "SELECT id FROM `endpointman_time_zones_new` WHERE `gmt` LIKE '".$old_tz_gmt."'"; 
     967        $sql = "SELECT id FROM `endpointman_time_zones_new` WHERE `gmt` LIKE '" . $old_tz_gmt . "'"; 
    968968        $new_tz_id = $db->getOne($sql); 
    969969 
    970         $sql = "UPDATE endpointman_global_vars SET value = '".$new_tz_id.".0' WHERE var_name = 'tz'"; 
     970        $sql = "UPDATE endpointman_global_vars SET value = '" . $new_tz_id . ".0' WHERE var_name = 'tz'"; 
    971971        $db->query($sql); 
    972972 
     
    974974        $db->query($sql); 
    975975 
    976   $sql = 'ALTER TABLE `endpointman_mac_list` ADD `specific_settings` LONGBLOB NULL;'; 
    977   $db->query($sql); 
     976        $sql = 'ALTER TABLE `endpointman_mac_list` ADD `specific_settings` LONGBLOB NULL;'; 
     977        $db->query($sql); 
     978    } 
     979     
     980    if ($ver <= "21002") { 
     981        out('Updating Mirror Location...again'); 
     982        $sql = "UPDATE endpointman_global_vars SET value = 'http://mirror.freepbx.org/provisioner/v2.5/' WHERE var_name ='update_server'"; 
     983        $db->query($sql); 
    978984    } 
    979985 
     
    10321038            (4, 'gmthr', ''), 
    10331039            (5, 'config_location', '/tftpboot/'), 
    1034             (6, 'update_server', 'http://mirror.freepbx.org/provisioner/'), 
     1040            (6, 'update_server', 'http://mirror.freepbx.org/provisioner/v2.5/'), 
    10351041            (7, 'version', '".$version."'), 
    10361042            (8, 'enable_ari', '0'), 
     
    12211227 
    12221228out("Update Version Number to ".$version); 
    1223 $sql = "UPDATE endpointman_global_vars SET value = '".$full_vers."' WHERE var_name = 'version'"; 
     1229$sql = "UPDATE endpointman_global_vars SET value = '".$version."' WHERE var_name = 'version'"; 
    12241230$db->query($sql); 
    12251231 
    1226 $sql = "UPDATE endpointman_global_vars SET value = 'http://mirror.freepbx.org/provisioner/' WHERE var_name = 'update_server'"; 
     1232$sql = "UPDATE endpointman_global_vars SET value = 'http://mirror.freepbx.org/provisioner/v2.5/' WHERE var_name = 'update_server'"; 
    12271233$db->query($sql); 
    12281234 
  • modules/branches/2.10/endpointman/module.xml

    r12766 r12767  
    33  <repo>standard</repo> 
    44  <name>PBX End Point Manager</name> 
    5   <version>2.10.0.4</version> 
     5  <version>2.10.0.3</version> 
    66  <type>setup</type> 
    77  <category>Connectivity</category>