Просмотр исходного кода

GitHub as update source for WebSite (update module).

DieFeM 9 лет назад
Родитель
Сommit
28c5869ce4
4 измененных файлов с 86 добавлено и 232 удалено
  1. 6 6
      modules/update/blacklist.php
  2. 2 2
      modules/update/module.php
  3. 60 181
      modules/update/update.php
  4. 18 43
      modules/update/updating.php

+ 6 - 6
modules/update/blacklist.php

@@ -28,7 +28,7 @@ function show_back()
     if( isset($_SESSION['fm_cwd']) && preg_match("/^\/*$/",$_SESSION['fm_cwd']) == 0 )
         return "<tr>\n".
 			   "<td align=left colspan='2' >\n".
-			   "<a href=\"?m=update&amp;p=blacklist&amp;back\" style='padding-left:5px;' > ..&nbsp;&nbsp;".get_lang("level_up")."</a>\n".
+			   "<a href=\"?m=".$_GET['m']."&amp;p=blacklist&amp;back\" style='padding-left:5px;' > ..&nbsp;&nbsp;".get_lang("level_up")."</a>\n".
 			   "</td>\n".
 			   "</tr>\n";
 }
@@ -114,7 +114,7 @@ function exec_ogp_module()
 	echo get_lang('blacklist_files');
 	echo "</h2>";
 
-	$baseDir = str_replace( "modules" . DIRECTORY_SEPARATOR . "update","",dirname(__FILE__) );
+	$baseDir = str_replace( "modules" . DIRECTORY_SEPARATOR . $_GET['m'],"",dirname(__FILE__) );
 	$path = clean_path($baseDir."/".@$_SESSION['fm_cwd']);
 	if (!file_exists($path))
 	{
@@ -142,7 +142,7 @@ function exec_ogp_module()
 		if($dirlist === -1)
 		{
 			if ( $path != $baseDir . "/" )
-				$view->refresh('?m=update&amp;p=blacklist',0);
+				$view->refresh('?m='.$_GET['m'].'&amp;p=blacklist',0);
 			else
 				print_failure('The path is too long or there is a file with a very long name inside of your game server\'s home folder.');
 		}
@@ -162,7 +162,7 @@ function exec_ogp_module()
 				}
 				
 				$_SESSION['fm_cwd'] = str_replace( "\\", "", dirname( $_SESSION['fm_cwd'] ) );
-				$view->refresh('?m=update&amp;p=blacklist'.'&amp;path='.$filename,0);
+				$view->refresh('?m='.$_GET['m'].'&amp;p=blacklist'.'&amp;path='.$filename,0);
 			}
 			else
 			{
@@ -224,7 +224,7 @@ function exec_ogp_module()
 				 "</td>".
 				 "<td align=left>".
 				 "<img class=\"viewitem\" src=\"images/folder.png\" alt=\"Directory\" /> ".
-				 "<a href=\"?m=update&amp;p=blacklist&amp;path=" . $directory['filename'] . "\">". 
+				 "<a href=\"?m=".$_GET['m']."&amp;p=blacklist&amp;path=" . $directory['filename'] . "\">". 
 				 $directory['filename'] . "</a></td></tr>\n";
 		}
 		$i = 0;
@@ -249,6 +249,6 @@ function exec_ogp_module()
 			 "</form>\n";
 		
 	}
-	echo create_back_button('update');
+	echo create_back_button($_GET['m']);
 }
 ?>

+ 2 - 2
modules/update/module.php

@@ -25,8 +25,8 @@
 
 // Module general information
 $module_title = "Update";
-$module_version = "1.0";
-$db_version = 1;
+$module_version = "1.1";
+$db_version = 0; // avoid 'duplicate table' error message.
 $module_required = TRUE;
 $module_menus = array(
     array( 'subpage' => '', 'name'=>'Update', 'group'=>'admin' )

+ 60 - 181
modules/update/update.php

@@ -24,25 +24,10 @@
  
  // todo, make checking and updating functions for updateing on the background.
  // todo, more specified updates in smaller packages
-function check_file($local_path, $remote_url, $cookie)
+function check_file($local_path, $remote_url)
 {
-	$ch = curl_init();
-	curl_setopt($ch, CURLOPT_URL, $remote_url);
-	curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)');
-	curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept-Language: es-es,en"));
-	curl_setopt($ch, CURLOPT_TIMEOUT, 60);
-	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
-	curl_setopt($ch, CURLOPT_COOKIE, $cookie);
-	curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
-	if(curl_errno($ch))
-	{
-		print_failure('Can\'t check updater status. Error:' . curl_error($ch));
-		curl_close($ch);
-		return False;
-	}
 	// Load remote file contents in to variable
-	$remote_file = curl_exec($ch);
-	curl_close($ch);
+	$remote_file = file_get_contents($remote_url);
 	// Load local file contents in to variable
 	$local_file = file_get_contents($local_path);
 	if( $remote_file != $local_file and preg_match("/exec_ogp_module/", $remote_file) )
@@ -71,186 +56,80 @@ function exec_ogp_module()
 
 	global $db,$settings;
 	
-	$date = new DateTime();
-	$expires = gmdate('D, d-M-Y H:i:s \G\M\T', $date->getTimestamp() + 31536000000);
-	$cookie = "FreedomCookie=true;path=/;expires=".$expires;
-	
-	/// Checking for changes in the main update files:
-	$main_update_files = array( 'modules/update/update.php' => 'http://svn.code.sf.net/p/hldstart/svn/trunk/upload/modules/update/update.php',
-								'modules/update/updating.php' => 'http://svn.code.sf.net/p/hldstart/svn/trunk/upload/modules/update/updating.php' );
-	$refresh = False;
-	foreach($main_update_files as $local_path => $remote_url)
+	define('REPONAME', 'OGP-Website');
+	define('RSS_REMOTE_PATH', 'https://github.com/OpenGamePanel/'.REPONAME.'/commits/master.atom');
+	define('MODULE_PATH', 'modules/'.$_GET['m'].'/');
+	define('RSS_LOCAL_PATH', MODULE_PATH.'master.atom');
+		
+	if( is_writable(MODULE_PATH) )
 	{
-		$result = check_file($local_path, $remote_url, $cookie);
-		if ($result === 'nochange')
-		{
-			continue;
-		}
-		elseif($result)
+		if( ! file_put_contents(RSS_LOCAL_PATH, file_get_contents(RSS_REMOTE_PATH)))
 		{
-			$refresh = True;
-		}
-		else
-		{
-			return;
-		}
+			print_failure('Unable to download : ' . RSS_REMOTE_PATH);
+		}	
 	}
 	
-	if($refresh)
+	if( file_exists(RSS_LOCAL_PATH) )
 	{
-		header("Refresh:0");
+		$feedXml = new SimpleXMLElement(file_get_contents(RSS_LOCAL_PATH), LIBXML_NOCDATA);
+		$seed = basename(  (string) $feedXml->entry[0]->link['href'] );
+		unlink(RSS_LOCAL_PATH);
+	}
+	else
+	{
+		print_failure('Unable to read : ' . RSS_LOCAL_PATH);
 		return;
 	}
-	/////////////////
-	
-	echo "<h2>".get_lang('update')."</h2>";
-
-	$pversion = $settings['ogp_version'];
-	
-	echo '<a href="?m=update&p=blacklist" >'.get_lang('blacklist_files')."</a>&nbsp;".get_lang('blacklist_files_info')."</br></br>";
-	echo get_lang('panel_version').": ".$pversion."</br></br>";
-	
-	//Get SVN rev.
-	$serverlist_url = "https://sourceforge.net/projects/ogpextras/rss?path=/Alternative-Snapshot&limit=3";
-
-	$ch = curl_init();
-	curl_setopt($ch, CURLOPT_URL, $serverlist_url);
-	curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)');
-	curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept-Language: es-es,en"));
-	curl_setopt($ch, CURLOPT_TIMEOUT, 60);
-	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
-	curl_setopt($ch, CURLOPT_COOKIE, $cookie);
-	
-	// Source forge moved this link in the past to https, so allow redirects to happen.
-	curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
-	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
-	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
 	
-	//Save Page
-	$result = curl_exec($ch);
-	curl_close($ch);
-
-	//Parse the result to get the last version.
-	preg_match_all("(/Alternative-Snapshot/hldstart-code-(.*)\.zip)siU", $result, $matches);
-	$last_svn_version = $matches[1][0];
-	
-	if( isset( $last_svn_version ) and $last_svn_version != "" )
+	if(isset($seed))
 	{
-		echo get_lang('latest_version').": $last_svn_version</br></br>";
-				
-		//Check snapshot file exists.
-		$ch = curl_init("http://master.dl.sourceforge.net/project/ogpextras/Alternative-Snapshot/hldstart-code-${last_svn_version}.zip");
-		curl_setopt($ch, CURLOPT_NOBODY, true);
-		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
-		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
-		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
-		curl_exec($ch);
-		$retcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
-		curl_close($ch);
-
-		// Run the snapshot creation if it does not exists yet.
-		if( $retcode == '404' )
-		{
-			print_failure("The snapshot of the current version has not been created yet.");
-			print_failure("Try again in 5 minutes.");
-		}
-		else
+		/// Checking for changes in the main update files:
+		$main_update_files = array( 'modules/update/update.php' => 'https://raw.githubusercontent.com/OpenGamePanel/'.REPONAME.'/'.$seed.'/modules/update/update.php',
+									'modules/update/updating.php' => 'https://raw.githubusercontent.com/OpenGamePanel/'.REPONAME.'/'.$seed.'/modules/update/updating.php' );
+		$refresh = False;
+		foreach($main_update_files as $local_path => $remote_url)
 		{
-			if ( $last_svn_version != $pversion )
+			$result = check_file($local_path, $remote_url);
+			if ($result === 'nochange')
 			{
-				if(isset($_GET['view_changes']))
-				{
-					echo "<div style=\"text-align:left;width:80%;margin:0 auto;padding: 10px 5px;".
-						 "border: 1px solid rgb(170, 170, 170);border-radius: 4px;background-color: rgb(189, 229, 248);\" >\n".
-						 "<a href='http://sourceforge.net/p/hldstart/svn/commit_browser' target='_blank' ><b>[ All commits ]</b></a><br><br>\n";
-
-					$serverlist_url = "http://sourceforge.net/p/hldstart/svn/feed";
-					$ch = curl_init();
-					curl_setopt($ch, CURLOPT_URL, $serverlist_url);
-					curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)');
-					curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept-Language: es-es,en"));
-					curl_setopt($ch, CURLOPT_TIMEOUT, 10);
-					curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
-					curl_setopt($ch, CURLOPT_COOKIE, $cookie);
-					curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
-					curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
-					curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
-					
-					// Save Page
-					$result = curl_exec($ch);
-					curl_close($ch);
-					
-					$xml = simplexml_load_string($result);
-					$json = json_encode($xml);
-					$feed_info = json_decode($json,TRUE);
-					
-					$items = array_reverse($feed_info['channel']['item']);
-					foreach($items as $item)
-					{
-						$link_arr = explode("/", $item['link']);
-						$revision = $link_arr[6];
-						if($pversion >= $revision)
-							continue;
-						$description = strip_tags(preg_replace("#<br />(.*)</a>#", "", $item['description']));
-						echo "<b>Revision $revision changes</b>&nbsp;".
-							 "<a href='$item[guid]' target='_blank' ><b>[ More details ]</b></a>:\n $description<br><br>";
-						if($last_svn_version == $revision)
-							break;
-					}
-					echo "</div>";
-				}
-				else
-				{
-					echo "<form action='' method='get'>\n".
-						 "<input type='hidden' name='m' value='update' />\n".
-						 "<input type='hidden' name='view_changes' value='true' />\n".
-						 "<input type='submit' value='".get_lang('view_changes')." (Max 10)' /></form>\n";
-				}
-				
-				echo "<br>\n";
-				
-				$url = "http://sourceforge.net/settings/mirror_choices?projectname=ogpextras".
-					   "&filename=Alternative-Snapshot/hldstart-code-$last_svn_version.zip";
-				
-				$ch = curl_init();
-				curl_setopt($ch, CURLOPT_URL, $url);
-				curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)');
-				curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept-Language: es-es,en"));
-				curl_setopt($ch, CURLOPT_TIMEOUT, 10);
-				curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
-				curl_setopt($ch, CURLOPT_COOKIE, $cookie);
-				curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
-				curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
-				curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
-				
-				// Save Page
-				$res = curl_exec($ch);
-				curl_close($ch);
-				
-				preg_match_all("(<li id=\"(.*)\">.*<label for=\".*\">(.*)</label> (.*)</li>)siU", $res, $matching);
-				
-				$sf_mirrors = array();
-				$qty = count($matching[0]);
-				for( $i = 0; $i < $qty; $i++ )
-				{
-					if ( $matching[1][$i] == 'autoselect' AND ( ini_get('open_basedir') or get_true_boolean(ini_get('safe_mode')) ) )
-						continue;
-					$sf_mirrors[$matching[1][$i]] = $matching[2][$i] . " " . $matching[3][$i];
-				}
-				echo "<form action='?m=update&amp;p=updating&amp;version=".$last_svn_version."' method='post'>\n".
-					 get_lang('select_mirror').": ".create_drop_box_from_array($sf_mirrors, "mirror", 'autoselect', false).
-					 "\n<br><br>\n<input type='submit' value='".get_lang('update_now')."' /></form><br><br>\n";
+				continue;
+			}
+			elseif($result)
+			{
+				$refresh = True;
 			}
 			else
 			{
-				print_failure(get_lang('the_panel_is_up_to_date'));
+				return;
 			}
 		}
+		
+		if($refresh)
+		{
+			header("Refresh:0");
+			return;
+		}
+		
+		echo "<h2>".get_lang('update')."</h2>";
+		$pversion = $settings['ogp_version'];
+		echo '<a href="?m='.$_GET['m'].'&p=blacklist" >'.get_lang('blacklist_files')."</a>&nbsp;".get_lang('blacklist_files_info')."</br></br>";
+		echo get_lang('panel_version').": ".$pversion."</br></br>";
+		echo get_lang('latest_version').": $seed</br></br>";
+		
+		if ( $seed != $pversion )
+		{	
+			$dwl = 'https://github.com/OpenGamePanel/'.REPONAME.'/archive/'.$seed.'.zip';
+			$dwlHeaders = get_headers($dwl);
+			if($dwlHeaders[0] != 'HTTP/1.1 302 Found')
+				print_failure('The generated URL for the download returned a bad response code: ' . $dwlHeaders[0]);
+			else
+				echo "<form action='?m=".$_GET['m']."&amp;p=updating&amp;version=".$seed."' method='post'>\n".
+					 "<input type='submit' value='".get_lang('update_now')."' /></form><br><br>\n";
+		}
+		else
+		{
+			print_success(get_lang('the_panel_is_up_to_date'));
+		}
 	}
-	else	
-	{
-		print_failure('sourceforge.net is down or not responding.');
-	}
-	echo "</div>\n";
 }
 ?>

+ 18 - 43
modules/update/updating.php

@@ -21,6 +21,7 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  *
  */
+ 
 function rmdir_recurse($path) {
     $path = rtrim($path, '/').'/';
     $handle = opendir($path);
@@ -36,12 +37,7 @@ function rmdir_recurse($path) {
 
 function exec_ogp_module()
 {
-	if( !function_exists("curl_init") )
-	{
-		print_failure( curl_needed );
-		return;
-	}
-
+	define('REPONAME', 'OGP-Website');
 	if($_SESSION['users_group'] != "admin")
 	{
 		print_failure( no_access );
@@ -51,8 +47,7 @@ function exec_ogp_module()
 	global $db;
 	global $view;
 	
-	$version = $_GET['version'];
-	$vtype = "SVN";
+	$vtype = "HubGit";
 
 	echo "<h4>" . dwl_update . "</h4>\n";
 
@@ -62,7 +57,7 @@ function exec_ogp_module()
 	error_reporting(E_ALL);
 	ini_set('display_errors',true);
 
-	$baseDir = str_replace( "modules" . DIRECTORY_SEPARATOR . "update","",dirname(__FILE__) );
+	$baseDir = str_replace( "modules" . DIRECTORY_SEPARATOR . $_GET['m'],"",dirname(__FILE__) );
 
 	if( !is_writable( $baseDir ) )
 	{
@@ -78,37 +73,17 @@ function exec_ogp_module()
 	if( is_writable( $temp ) )
 	{
 		// Download file to temporary folder
-		if(isset($_POST['mirror']) && !empty($_POST['mirror'])){
-			$mirror = $_POST['mirror'];
-		}else{
-			if( ini_get('open_basedir') or get_true_boolean(ini_get('safe_mode')) )
-				$mirror = "master";
-			else
-				$mirror = "autoselect";
+		$temp_dwl = $temp . DIRECTORY_SEPARATOR . $_GET['version'] . '.zip';
+		$dwl = 'https://github.com/OpenGamePanel/'.REPONAME.'/archive/'.$_GET['version'].'.zip';
+		$zip_raw_data = file_get_contents($dwl);
+		if(! $zip_raw_data)
+		{
+			print_failure( get_lang_f( 'dwl_failed', $url ) ); 
+			return;
 		}
-		$temp_dwl = $temp . DIRECTORY_SEPARATOR . 'svn.tar.gz';
-		$fp = fopen ($temp_dwl, 'w+'); //This is the download destination
-		$date = new DateTime();
-		$expires = gmdate('D, d-M-Y H:i:s \G\M\T', $date->getTimestamp() + 31536000000);
-		if($mirror == "autoselect")
-			$url = "https://sourceforge.net/projects/ogpextras/files/Alternative-Snapshot/hldstart-code-${version}.zip/download";
-		else
-			$url = "http://".$mirror.".dl.sourceforge.net/project/ogpextras/Alternative-Snapshot/hldstart-code-${version}.zip";
-		$ch = curl_init();
-		curl_setopt($ch, CURLOPT_URL, $url);
-		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
-		curl_setopt($ch, CURLOPT_HEADER, false); 
-		curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
-		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
-		curl_setopt($ch, CURLOPT_COOKIE, "FreedomCookie=true;path=/;expires=".$expires);
-		curl_setopt($ch, CURLOPT_TIMEOUT, 1000);
-		curl_setopt($ch, CURLOPT_FILE, $fp);
-		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
-		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
-		curl_exec($ch);
-		curl_close($ch);
-		fclose($fp);
-		
+
+		file_put_contents($temp_dwl, $zip_raw_data);
+
 		// Check if the file exists and the size is bigger than a 404 error page from sf.net
 		if( file_exists( $temp_dwl ) )
 		{
@@ -142,7 +117,7 @@ function exec_ogp_module()
 		$overwritten_files = "";
 		$new_files = "";
 		
-		$unwanted_path = "hldstart-code-${version}/trunk/upload";
+		$unwanted_path = REPONAME . "-" . $_GET['version'];
 		$extract_path = $temp . DIRECTORY_SEPARATOR . "OGP_update";
 		if( !file_exists($extract_path) )
 			mkdir($extract_path, 0775);
@@ -262,12 +237,12 @@ function exec_ogp_module()
 				
 				// update version info in db
 								
-				$db->query("UPDATE OGP_DB_PREFIXsettings SET value = '$version'	WHERE setting = 'ogp_version'");
-				$db->query("UPDATE OGP_DB_PREFIXsettings SET value = '$vtype'	WHERE setting = 'version_type'");
+				$db->query("UPDATE OGP_DB_PREFIXsettings SET value = '$_GET[version]' WHERE setting = 'ogp_version'");
+				$db->query("UPDATE OGP_DB_PREFIXsettings SET value = '$vtype' WHERE setting = 'version_type'");
 
 				// Remove the downloaded package
 				if( file_exists( $temp_dwl ) )
-					unlink( $temp_dwl );
+					//unlink( $temp_dwl );
 				
 				// Remove files that are not related to the panel
 				if( file_exists( $baseDir . DIRECTORY_SEPARATOR . "hldstart-code-${version}" ) )