Bladeren bron

Merge pull request #555 from own3mall/master

Custom Github Branch
OwN-3m-All 5 jaren geleden
bovenliggende
commit
859120cc9e

+ 2 - 2
includes/helpers.php

@@ -429,14 +429,14 @@ function runPostUpdateOperations(){
 	}
 }
 
-function getOGPGitHubURL($gitHubUsername, $repo){
+function getOGPGitHubURL($gitHubUsername, $repo, $branch = "master"){
 	$OGPGitHub = "https://github.com/OpenGamePanel/";
 	$gitHubURL = $OGPGitHub; 
 	if(isset($gitHubUsername) && !empty($gitHubUsername)){
 		$gitHubURL = "https://github.com/" . $gitHubUsername . "/"; 
 	}
 	
-	$paths[] = $gitHubURL . $repo . "/commits/master.atom";
+	$paths[] = $gitHubURL . $repo . "/commits/" . $branch . '.atom';
 	$exists = get_first_existing_file($paths);
 	if($exists !== false){
 		return $gitHubURL;

+ 3 - 0
lang/English/modules/settings.php

@@ -91,6 +91,9 @@ define('OGP_LANG_login_attempts_before_banned', "Number of failed login attempts
 define('OGP_LANG_login_attempts_before_banned_info', "If a user tries to login with invalid credentials more than this many times, the user will be banned temporarily by the panel.");
 define('OGP_LANG_custom_github_update_username', "GitHub update username");
 define('OGP_LANG_custom_github_update_username_info', "Enter your GitHub username ONLY to use your own forked repositories to update OGP. This should only be changed by developers who wish to use their own repos for development rather than checking in possibly buggy code into the main branch.");
+define('OGP_LANG_custom_github_update_branch_name', "GitHub branch name");
+define('OGP_LANG_custom_github_update_branch_name_info', "Enter the branch name you want to use for updating OGP. This should only be changed by developers who wish to use their own repos for development rather than checking in possibly buggy code into the main branch.  Leave this field blank to default to \"master\"");
+
 define('OGP_LANG_remote_query', "Remote query");
 define('OGP_LANG_remote_query_info', "Use the remote server (agent) to make queries to the game servers (Only GameQ and LGSL).");
 define('OGP_LANG_check_expiry_by', "Check expiration using");

+ 3 - 1
modules/extras/extras.php

@@ -417,7 +417,9 @@ function exec_ogp_module()
 			$isTheme = true;
 		}
 		
-		$REMOTE_REPO_FILE = $gitHubURL . $repository['name'] . '/commits/master.atom';
+		$gitHubBranchName = (!empty($settings['custom_github_update_branch_name']) ? $settings['custom_github_update_branch_name'] : 'master');
+		
+		$REMOTE_REPO_FILE = $gitHubURL . $repository['name'] . '/commits/' . $gitHubBranchName . '.atom';
 		$LOCAL_REPO_FILE = DATA_PATH . $repository['name'] . '.atom';
 		if(!file_exists($LOCAL_REPO_FILE) 
 			OR (isset($_GET['searchForUpdates']) and $_GET['searchForUpdates'] == $repository['name']) 

+ 15 - 0
modules/settings/settings.php

@@ -31,6 +31,9 @@ function exec_ogp_module()
 	{
 		$ssl = (isset($_POST['smtp_secure']) and $_POST['smtp_secure'] == 'ssl') ? 1 : 0;
 		$tls = (isset($_POST['smtp_secure']) and $_POST['smtp_secure'] == 'tls') ? 1 : 0;
+		
+		$oldSettings = $db->getSettings();
+		
 		$settings = array("panel_name" => $_REQUEST['panel_name'],
 			"header_code" => $_REQUEST['header_code'],
 			"maintenance_mode" => $_REQUEST['maintenance_mode'],
@@ -66,6 +69,7 @@ function exec_ogp_module()
 			"recaptcha_use_login" => $_REQUEST['recaptcha_use_login'],
 			"login_attempts_before_banned" => $_REQUEST['login_attempts_before_banned'],
 			"custom_github_update_username" => $_REQUEST['custom_github_update_username'],
+			"custom_github_update_branch_name" => $_REQUEST['custom_github_update_branch_name'],
 			"show_server_id_game_monitor" => $_REQUEST['show_server_id_game_monitor'],
 			"default_game_server_home_path_prefix" => $_REQUEST['default_game_server_home_path_prefix'],
 			"use_authorized_hosts" => $_REQUEST['use_authorized_hosts'],
@@ -80,6 +84,16 @@ function exec_ogp_module()
 			$db->resetGameServerOrder();
 		}
 		
+		if($oldSettings["custom_github_update_branch_name"] != $settings["custom_github_update_branch_name"] || $oldSettings["custom_github_update_usernam"] != $settings["custom_github_update_usernam"]){
+			// Delete any old atom files for extras module
+			$extrasPathData = realpath('modules/extras/') . DIRECTORY_SEPARATOR . "data" . DIRECTORY_SEPARATOR;
+			array_map('unlink', glob($extrasPathData . "*.atom"));
+			
+			// Delete any branch atom for update module
+			$updatesPath = realpath('modules/update/');
+			array_map('unlink', glob($updatesPath . "*.atom"));
+		}
+		
 		echo "<h2>".get_lang('settings')."</h2>";
 		print_success(get_lang('settings_updated'));
 		$view->refresh("?m=settings");
@@ -176,6 +190,7 @@ function exec_ogp_module()
 	$ft->add_field('string','login_ban_time', array_key_exists("login_ban_time", $row) && !empty($row["login_ban_time"]) && is_numeric($row["login_ban_time"]) ? $row["login_ban_time"] : '');
 	
 	$ft->add_field('string','custom_github_update_username',@$row['custom_github_update_username']);
+	$ft->add_field('string','custom_github_update_branch_name',@$row['custom_github_update_branch_name']);
 	
 	$ft->add_field('on_off','show_server_id_game_monitor',@$row['show_server_id_game_monitor']);
 	

+ 15 - 7
modules/update/update.php

@@ -66,16 +66,18 @@ function exec_ogp_module()
 	// GitHub URL
 	if(function_exists("getOGPGitHubURL") && function_exists("getOGPGitHubURLUnstrict") && function_exists("getGitHubOrganization")){
 		$gitHubUsername = $settings["custom_github_update_username"];	
-		$gitHubURL = getOGPGitHubURL($gitHubUsername, REPONAME);
+		$gitHubBranch = (!empty($settings['custom_github_update_branch_name']) ? $settings['custom_github_update_branch_name'] : 'master');
+		$gitHubURL = getOGPGitHubURL($gitHubUsername, REPONAME, $gitHubBranch);
 		$gitHubOrganization = getGitHubOrganization($gitHubURL);
 	}else{
 		$gitHubURL = "https://github.com/OpenGamePanel/";
 	}
 	
+	$gitHubBranchName = (!empty($settings['custom_github_update_branch_name']) ? $settings['custom_github_update_branch_name'] : 'master');
 	
-	define('RSS_REMOTE_PATH', $gitHubURL . REPONAME . '/commits/master.atom');
+	define('RSS_REMOTE_PATH', $gitHubURL . REPONAME . '/commits/' . $gitHubBranchName . '.atom');
 	define('MODULE_PATH', 'modules/'.$_GET['m'].'/');
-	define('RSS_LOCAL_PATH', MODULE_PATH.'master.atom');
+	define('RSS_LOCAL_PATH', MODULE_PATH . $gitHubBranchName . '.atom');
 		
 	if( is_writable(MODULE_PATH) )
 	{
@@ -105,9 +107,14 @@ function exec_ogp_module()
 	if(isset($seed))
 	{
 		/// Checking for changes in the main update files:
-		$main_update_files = array( 'modules/update/update.php' => 'https://raw.githubusercontent.com/' . $gitHubOrganization . '/'.REPONAME.'/'.$seed.'/modules/update/update.php',
-									'modules/update/updating.php' => 'https://raw.githubusercontent.com/' . $gitHubOrganization . '/'.REPONAME.'/'.$seed.'/modules/update/updating.php',
-									'modules/update/unzip.php' => 'https://raw.githubusercontent.com/' . $gitHubOrganization . '/'.REPONAME.'/'.$seed.'/modules/update/unzip.php');
+		$main_update_files = array(
+			'includes/functions.php' => 'https://raw.githubusercontent.com/' . $gitHubOrganization . '/'.REPONAME.'/'.$seed.'/includes/functions.php',
+			'includes/helpers.php' => 'https://raw.githubusercontent.com/' . $gitHubOrganization . '/'.REPONAME.'/'.$seed.'/includes/helpers.php',
+			'modules/update/update.php' => 'https://raw.githubusercontent.com/' . $gitHubOrganization . '/'.REPONAME.'/'.$seed.'/modules/update/update.php',
+			'modules/update/updating.php' => 'https://raw.githubusercontent.com/' . $gitHubOrganization . '/'.REPONAME.'/'.$seed.'/modules/update/updating.php',
+			'modules/update/unzip.php' => 'https://raw.githubusercontent.com/' . $gitHubOrganization . '/'.REPONAME.'/'.$seed.'/modules/update/unzip.php'
+		);
+		
 		$refresh = False;
 		foreach($main_update_files as $local_path => $remote_url)
 		{
@@ -155,6 +162,7 @@ function exec_ogp_module()
 					$commitsToShow = 5;
 					
 					$gitHubUpdateName = (!empty($settings['custom_github_update_username']) ? $settings['custom_github_update_username'] : 'OpenGamePanel');
+					
 					$ch = curl_init();
 					curl_setopt($ch, CURLOPT_URL, 'https://api.github.com/repos/'.$gitHubUpdateName.'/'.REPONAME.'/commits');
 					curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:51.0) Gecko/20100101 Firefox/51.0');
@@ -175,7 +183,7 @@ function exec_ogp_module()
 								echo '<b>'.str_replace("*", "<br><br>", $v['commit']['message']) .'</b></li><br>';
 								++$commitsStart;
 							}
-							echo '</ul><a href="https://github.com/'.$gitHubUpdateName.'/'.REPONAME.'/commits/master" target="_blank">View more commits...</a>';
+							echo '</ul><a href="https://github.com/'.$gitHubUpdateName.'/'.REPONAME.'/commits/' . $gitHubBranchName . '" target="_blank">View more commits...</a>';
 						}
 					}
 				}

+ 2 - 1
modules/update/updating.php

@@ -50,7 +50,8 @@ function exec_ogp_module()
 	// GitHub URL
 	if(function_exists("getOGPGitHubURL") && function_exists("getOGPGitHubURLUnstrict")){
 		$gitHubUsername = $settings["custom_github_update_username"];	
-		$gitHubURL = getOGPGitHubURL($gitHubUsername, REPONAME);
+		$gitHubBranch = (!empty($settings['custom_github_update_branch_name']) ? $settings['custom_github_update_branch_name'] : 'master');
+		$gitHubURL = getOGPGitHubURL($gitHubUsername, REPONAME, $gitHubBranch);
 	}else{
 		$gitHubURL = "https://github.com/OpenGamePanel/";
 	}