Jump to content

MTA Server Automatic Updater (File for latest Version Descr)


Recommended Posts

nightly.mtasa.com running on php, can create and upload a script for get the latest and recommend version for the Linux Server?

Is less work for me, because then I could build my project better (I have my own MTA Panel for hosting and need this for a update interface)

Link to post

youre free to alter the code and host it

edit: service edited to do nightlies now and update time set to 2 hrs

http://uhm.sparksptpm.co.uk/mta-linux/latest

http://uhm.sparksptpm.co.uk/mta-linux/get

new source code:

  
<?php 
  
    /**************************************************** 
        MTA LINUX SERVER LATEST BUILD FETCH SERVICE  
        Documentation: [url=http://uhm.sparksptpm.co.uk/mta-linux/]http://uhm.sparksptpm.co.uk/mta-linux/[/url] 
        Developed by uhm under Apache License v2.0 
    *****************************************************/ 
  
  
    function get_data($url) { 
        $ch = curl_init(); 
        curl_setopt($ch, CURLOPT_URL, $url); 
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3); 
        $data = curl_exec($ch); 
        curl_close($ch); 
        return $data; 
    } 
     
         
    function getBetween($haystack,$start,$end,$index=0) 
    { 
        $positions = array(); 
        $positionsB = array(); 
        $count = 0; 
        $cnt2=0; 
  
        while($cnt2<($index+1) && $count = strpos($haystack , $start , $count+1)) { $positions[] = $count+strlen($start); $cnt2++; }  
  
        $cnt2=0; 
        while($cnt2<($index+1) && $count = strpos($haystack , $end , $positions[$cnt2]+1)) { $positionsB[] = $count; $cnt2++; }  
  
        return substr($haystack,$positions[$index],$positionsB[$index]-$positions[$index]); 
    } 
  
  
  
    // get last check date 
    $time = filemtime('cache.txt'); 
    if ((time() - $time) >  7200)   // has it been longer than 2 hrs? (7200 seconds) 
    { 
        $data = get_data('http://nightly.mtasa.com/'); 
        $version = getBetween($data,'<img src="mta_nightly.php?image=gz" alt="gz" /> <a href="','"'); 
        file_put_contents ( 'cache.txt' , $version ); // make sure to chmod this file to 777 
    } 
    else 
    { 
        $version = file_get_contents('cache.txt'); 
    } 
     
     
  
    if (isset($_GET['latest'])) 
    { 
        echo getBetween($version,'/','.tar'); 
    } 
    elseif (isset($_GET['get'])) 
    { 
        header('Location: ' . 'http://nightly.mtasa.com/' . $version); 
    } 
    else 
    { 
        echo 'Invalid request; see [url=http://uhm.sparksptpm.co.uk/mta-linux/']http://uhm.sparksptpm.co.uk/mta-linux/'[/url]; 
    } 
  
  
?> 

Link to post

its work for me, http://mtasa.keppe.org (I am running PHP5.4 on my Server)

My Public Code

  
<?php 
  
    /**************************************************** 
        MTA LINUX SERVER LATEST BUILD FETCH SERVICE 
        Documentation: [url=http://uhm.sparksptpm.co.uk/mta-linux/]http://uhm.sparksptpm.co.uk/mta-linux/[/url] 
        Developed by uhm under Apache License v2.0 
        Edited by KPT (Keppe Project-Team) 
    *****************************************************/ 
  
  
    function get_data($url) { 
        $ch = curl_init(); 
        curl_setopt($ch, CURLOPT_URL, $url); 
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3); 
        $data = curl_exec($ch); 
        curl_close($ch); 
        return $data; 
    } 
    
        
    function getBetween($haystack,$start,$end,$index=0) 
    { 
        $positions = array(); 
        $positionsB = array(); 
        $count = 0; 
        $cnt2=0; 
  
        while($cnt2<($index+1) && $count = strpos($haystack , $start , $count+1)) { $positions[] = $count+strlen($start); $cnt2++; } 
  
        $cnt2=0; 
        while($cnt2<($index+1) && $count = strpos($haystack , $end , $positions[$cnt2]+1)) { $positionsB[] = $count; $cnt2++; } 
  
        return substr($haystack,$positions[$index],$positionsB[$index]-$positions[$index]); 
    } 
  
  
  
    // get last check date 
    $time = filemtime('cache.txt'); 
    if ((time() - $time) >  7200)   // has it been longer than 2 hrs? (7200 seconds) 
    { 
        $data = get_data('http://nightly.mtasa.com/'); 
        $psdata = explode("- Current release version",$data); 
        $version = getBetween($psdata[1],'<img src="mta_nightly.php?image=gz" alt="gz" /> <a href="','"'); 
        file_put_contents ( 'cache.txt' , $version ); // make sure to chmod this file to 644, 755, 775 or 777 
    } 
    else 
    { 
        $version = file_get_contents('cache.txt'); 
    } 
    
  
    if (isset($_GET['latest'])) 
    { 
        echo getBetween($version,'/','.tar'); 
    } 
    elseif (isset($_GET['ver'])) 
    { 
        $gdata = getBetween($version,'/','.tar'); 
        $psg1data = explode("-",$gdata); 
        $psg2data = explode("-",$psg1data[1]); 
        echo $psg2data[0]; 
    } 
    elseif (isset($_GET['build'])) 
    { 
        $gdata = getBetween($version,'/','.tar'); 
        $psg1data = explode("-",$gdata); 
        $psg2data = explode("-",$psg1data[3]); 
        echo $psg2data[0]; 
    } 
    elseif (isset($_GET['get'])) 
    { 
        header('Location: ' . 'http://nightly.mtasa.com/' . $version); 
    } 
    else 
    { 
        echo 'Invalid request; see [url=http://uhm.sparksptpm.co.uk/mta-linux/']http://uhm.sparksptpm.co.uk/mta-linux/'[/url]; 
    } 
  

Thank your for the help :D thx

Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...