Ver Fonte

Rework of OGP Custom GitHub URL

own3mall há 9 anos atrás
pai
commit
7a2df89309

+ 31 - 9
includes/helpers.php

@@ -171,6 +171,8 @@ function get_first_existing_file($paths, $referrer = "", $agent = "")
 		
 		
         if (file_exists($path)) return $path;
         if (file_exists($path)) return $path;
     }
     }
+    
+    return false;
 }
 }
 
 
 function cURLEnabled(){
 function cURLEnabled(){
@@ -345,17 +347,37 @@ function removeOldGameConfigs(){ // Wrote this function in-case we rename config
 	}	 
 	}	 
 }
 }
 
 
-function getOGPGitHubURL($gitHubURL){
-	if(!isset($gitHubURL) || empty($gitHubURL)){
-		$gitHubURL = "https://github.com/OpenGamePanel/"; 
-	}else{
-		// validation
-		if(substr($gitHubURL, -1) != "/" || stripos($gitHubURL, "github.com") === false){
-			$gitHubURL = "https://github.com/OpenGamePanel/";
-		}
+function getOGPGitHubURL($gitHubUsername, $repo){
+	$OGPGitHub = "https://github.com/OpenGamePanel/";
+	$gitHubURL = $OGPGitHub; 
+	if(isset($gitHubUsername) && !empty($gitHubUsername)){
+		$gitHubURL = "https://github.com/" . $gitHubUsername . "/"; 
+	}
+	
+	$paths[] = $gitHubURL . $repo . "/commits/master.atom";
+	$exists = get_first_existing_file($paths);
+	if($exists !== false){
+		return $gitHubURL;
+	}
+	
+	return $OGPGitHub;
+}
+
+function getOGPGitHubURLUnstrict($gitHubUsername){
+	$OGPGitHub = "https://github.com/OpenGamePanel/";
+	$gitHubURL = $OGPGitHub; 
+	if(isset($gitHubUsername) && !empty($gitHubUsername)){
+		$gitHubURL = "https://github.com/" . $gitHubUsername . "/"; 
+	}
+	
+	$paths[] = $gitHubURL;
+	
+	$exists = get_first_existing_file($paths);
+	if($exists !== false){
+		return $gitHubURL;
 	}
 	}
 	
 	
-	return $gitHubURL;
+	return $OGPGitHub;
 }
 }
 
 
 function getGitHubOrganization($gitHubURL){
 function getGitHubOrganization($gitHubURL){

+ 2 - 2
lang/English/modules/settings.php

@@ -91,8 +91,8 @@ define('recaptcha_use_login', "Use Recaptcha on Login");
 define('recaptcha_use_login_info', "If enabled, users will have to solve the Not a Robot Recaptcha when attempting to login.");
 define('recaptcha_use_login_info', "If enabled, users will have to solve the Not a Robot Recaptcha when attempting to login.");
 define('login_attempts_before_banned', "Number of failed login attempts before user is banned");
 define('login_attempts_before_banned', "Number of failed login attempts before user is banned");
 define('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('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('custom_github_update_URL', "GitHub update URL used by the update module");
-define('custom_github_update_URL_info', "This should only be changed by developers who wish to use their own repo for development rather than checking in possibly buggy code into the main branch.");
+define('custom_github_update_username', "GitHub update username");
+define('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('remote_query', "Remote query");
 define('remote_query', "Remote query");
 define('remote_query_info', "Use the remote server (agent) to make queries to the game servers (Only GameQ and LGSL).");
 define('remote_query_info', "Use the remote server (agent) to make queries to the game servers (Only GameQ and LGSL).");
 define('check_expiry_by', "Check expiration using");
 define('check_expiry_by', "Check expiration using");

+ 3 - 3
modules/extras/extras.php

@@ -239,9 +239,9 @@ function exec_ogp_module()
 	}
 	}
 		
 		
 	// GitHub URL
 	// GitHub URL
-	if(function_exists("getOGPGitHubURL")){
-		$gitHubURL = $settings["custom_github_update_URL"];	
-		$gitHubURL = getOGPGitHubURL($gitHubURL);
+	if(function_exists("getOGPGitHubURLUnstrict") && function_exists("getGitHubOrganization")){
+		$gitHubUsername = $settings["custom_github_update_username"];	
+		$gitHubURL = getOGPGitHubURLUnstrict($gitHubUsername);
 		$gitHubOrganization = getGitHubOrganization($gitHubURL);
 		$gitHubOrganization = getGitHubOrganization($gitHubURL);
 	}else{
 	}else{
 		$gitHubURL = "https://github.com/OpenGamePanel/";
 		$gitHubURL = "https://github.com/OpenGamePanel/";

+ 2 - 2
modules/settings/settings.php

@@ -66,7 +66,7 @@ function exec_ogp_module()
 			"recaptcha_secret_key" => $_REQUEST['recaptcha_secret_key'],
 			"recaptcha_secret_key" => $_REQUEST['recaptcha_secret_key'],
 			"recaptcha_use_login" => $_REQUEST['recaptcha_use_login'],
 			"recaptcha_use_login" => $_REQUEST['recaptcha_use_login'],
 			"login_attempts_before_banned" => $_REQUEST['login_attempts_before_banned'],
 			"login_attempts_before_banned" => $_REQUEST['login_attempts_before_banned'],
-			"custom_github_update_URL" => $_REQUEST['custom_github_update_URL'],
+			"custom_github_update_username" => $_REQUEST['custom_github_update_username'],
 		);
 		);
 		
 		
 		$db->setSettings($settings);
 		$db->setSettings($settings);
@@ -161,7 +161,7 @@ function exec_ogp_module()
 	$ft->add_field('string','login_attempts_before_banned',$login_attempts_before_banned);
 	$ft->add_field('string','login_attempts_before_banned',$login_attempts_before_banned);
 	
 	
 	
 	
-	$ft->add_field('string','custom_github_update_URL',@$row['custom_github_update_URL']);
+	$ft->add_field('string','custom_github_update_username',@$row['custom_github_update_username']);
 	
 	
 	$ft->end_table();
 	$ft->end_table();
 	$ft->add_button("submit","update_settings",get_lang('update_settings'));
 	$ft->add_button("submit","update_settings",get_lang('update_settings'));

+ 5 - 3
modules/update/update.php

@@ -56,15 +56,17 @@ function exec_ogp_module()
 
 
 	global $db, $settings;
 	global $db, $settings;
 	
 	
+	define('REPONAME', 'OGP-Website');
+	
 	// GitHub URL
 	// GitHub URL
 	if(function_exists("getOGPGitHubURL")){
 	if(function_exists("getOGPGitHubURL")){
-		$gitHubURL = $settings["custom_github_update_URL"];	
-		$gitHubURL = getOGPGitHubURL($gitHubURL);
+		$gitHubUsername = $settings["custom_github_update_username"];	
+		$gitHubURL = getOGPGitHubURL($gitHubUsername, REPONAME);
 	}else{
 	}else{
 		$gitHubURL = "https://github.com/OpenGamePanel/";
 		$gitHubURL = "https://github.com/OpenGamePanel/";
 	}
 	}
 	
 	
-	define('REPONAME', 'OGP-Website');
+	
 	define('RSS_REMOTE_PATH', $gitHubURL . REPONAME . '/commits/master.atom');
 	define('RSS_REMOTE_PATH', $gitHubURL . REPONAME . '/commits/master.atom');
 	define('MODULE_PATH', 'modules/'.$_GET['m'].'/');
 	define('MODULE_PATH', 'modules/'.$_GET['m'].'/');
 	define('RSS_LOCAL_PATH', MODULE_PATH.'master.atom');
 	define('RSS_LOCAL_PATH', MODULE_PATH.'master.atom');

+ 2 - 2
modules/update/updating.php

@@ -49,8 +49,8 @@ function exec_ogp_module()
 	
 	
 	// GitHub URL
 	// GitHub URL
 	if(function_exists("getOGPGitHubURL")){
 	if(function_exists("getOGPGitHubURL")){
-		$gitHubURL = $settings["custom_github_update_URL"];	
-		$gitHubURL = getOGPGitHubURL($gitHubURL);
+		$gitHubUsername = $settings["custom_github_update_username"];	
+		$gitHubURL = getOGPGitHubURL($gitHubUsername, REPONAME);
 	}else{
 	}else{
 		$gitHubURL = "https://github.com/OpenGamePanel/";
 		$gitHubURL = "https://github.com/OpenGamePanel/";
 	}
 	}