Browse Source

Custom GitHub Update URL

own3mall 9 years ago
parent
commit
c18a4eb28f

+ 9 - 0
includes/database_mysql.php

@@ -113,6 +113,15 @@ class OGPDatabaseMySQL extends OGPDatabase
 		if(!isset($results["login_attempts_before_banned"]) || empty($results["login_attempts_before_banned"]) || !is_numeric($results["login_attempts_before_banned"])){
 			$results["login_attempts_before_banned"] = 6;
 		}
+		
+		if(!isset($results["custom_github_update_URL"]) || empty($results["custom_github_update_URL"])){
+			$results["custom_github_update_URL"] = "https://github.com/OpenGamePanel/";
+		}else{
+			// validation
+			if(substr($results["custom_github_update_URL"], -1) != "/" || stripos($results["custom_github_update_URL"], "github.com") === false){
+				$results["custom_github_update_URL"] = "https://github.com/OpenGamePanel/";
+			}
+		}
 
 		return $results;
 	}

+ 9 - 0
includes/database_mysqli.php

@@ -110,6 +110,15 @@ class OGPDatabaseMySQL extends OGPDatabase
 		if(!isset($results["login_attempts_before_banned"]) || empty($results["login_attempts_before_banned"]) || !is_numeric($results["login_attempts_before_banned"])){
 			$results["login_attempts_before_banned"] = 6;
 		}
+		
+		if(!isset($results["custom_github_update_URL"]) || empty($results["custom_github_update_URL"])){
+			$results["custom_github_update_URL"] = "https://github.com/OpenGamePanel/";
+		}else{
+			// validation
+			if(substr($results["custom_github_update_URL"], -1) != "/" || stripos($results["custom_github_update_URL"], "github.com") === false){
+				$results["custom_github_update_URL"] = "https://github.com/OpenGamePanel/";
+			}
+		}
 
 		return $results;
 	}

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

@@ -91,6 +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('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('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('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('check_expiry_by', "Check expiration using");

+ 9 - 5
modules/extras/extras.php

@@ -212,6 +212,11 @@ function deeperPathFirst($a, $b)
  
 function exec_ogp_module() 
 {
+	global $db, $settings;		
+	
+	// GitHub URL
+	$gitHubURL = $settings["custom_github_update_URL"];	
+	
 	set_time_limit(0);
 	$baseDir = str_replace( "modules" . DIRECTORY_SEPARATOR . $_GET['m'],"",dirname(__FILE__) );
 	define('DATA_PATH', realpath('modules/'.$_GET['m'].'/') . DIRECTORY_SEPARATOR . "data" . DIRECTORY_SEPARATOR);
@@ -327,7 +332,7 @@ function exec_ogp_module()
 		if(preg_match('/^(OGP-Website|OGP-Agent-Linux|OGP-Agent-Windows)$/',$repository['name']))
 			continue;
 		
-		$REMOTE_REPO_FILE = 'https://github.com/OpenGamePanel/'.$repository['name'].'/commits/master.atom';
+		$REMOTE_REPO_FILE = $gitHubURL . $repository['name'] . '/commits/master.atom';
 		$LOCAL_REPO_FILE = DATA_PATH . $repository['name'] . '.atom';
 		if(!file_exists($LOCAL_REPO_FILE) OR (isset($_GET['searchForUpdates']) and $_GET['searchForUpdates'] == $repository['name']) OR isset($_POST['update']))
 		{
@@ -362,7 +367,7 @@ function exec_ogp_module()
 					$modules[$m]['title'] = $module_title;
 					$modules[$m]['reponame'] = $repository['name'];
 					$modules[$m]['file'] = $seed.'.zip';
-					$modules[$m]['link'] = 'https://github.com/OpenGamePanel/'.$repository['name'].'/archive/'.$seed.'.zip';
+					$modules[$m]['link'] = $gitHubURL . $repository['name'] . '/archive/'.$seed.'.zip';
 					$modules[$m]['date'] = (string) $feedXml->entry[0]->updated;
 					$modules[$m]['timestamp'] = strtotime((string) $feedXml->entry[0]->updated);
 					$modules[$m]['remove_path'] = $repository['name']."-".$seed;
@@ -375,7 +380,7 @@ function exec_ogp_module()
 					$themes[$t]['title'] = $theme_title;
 					$themes[$t]['reponame'] = $repository['name'];
 					$themes[$t]['file'] = $seed.'.zip';
-					$themes[$t]['link'] = 'https://github.com/OpenGamePanel/'.$repository['name'].'/archive/'.$seed.'.zip';
+					$themes[$t]['link'] = $gitHubURL . $repository['name'] . '/archive/'.$seed.'.zip';
 					$themes[$t]['date'] = (string) $feedXml->entry[0]->updated;
 					$themes[$t]['timestamp'] = strtotime((string) $feedXml->entry[0]->updated);
 					$themes[$t]['remove_path'] = $repository['name']."-".$seed;
@@ -394,7 +399,6 @@ function exec_ogp_module()
 
 	}
 
-	global $db;
 	$installed_modules = $db->getInstalledModules();
 	
 	if(isset($_POST['update']))
@@ -557,4 +561,4 @@ function exec_ogp_module()
 		 "' ></div>";
 
 }
-?>
+?>

+ 6 - 1
modules/settings/settings.php

@@ -65,7 +65,9 @@ function exec_ogp_module()
 			"recaptcha_site_key" => $_REQUEST['recaptcha_site_key'],
 			"recaptcha_secret_key" => $_REQUEST['recaptcha_secret_key'],
 			"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'],
+		);
 		
 		$db->setSettings($settings);
 		echo "<h2>".get_lang('settings')."</h2>";
@@ -158,6 +160,9 @@ function exec_ogp_module()
 	$login_attempts_before_banned = (isset($row['login_attempts_before_banned']) and $row['login_attempts_before_banned'] != "" and is_numeric($row['login_attempts_before_banned']))? $row['login_attempts_before_banned'] : "6";
 	$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->end_table();
 	$ft->add_button("submit","update_settings",get_lang('update_settings'));
 	$ft->end_form();

+ 5 - 2
modules/update/update.php

@@ -56,8 +56,11 @@ function exec_ogp_module()
 
 	global $db,$settings;
 	
+	// GitHub URL
+	$gitHubURL = $settings["custom_github_update_URL"];	
+	
 	define('REPONAME', 'OGP-Website');
-	define('RSS_REMOTE_PATH', 'https://github.com/OpenGamePanel/'.REPONAME.'/commits/master.atom');
+	define('RSS_REMOTE_PATH', $gitHubURL . REPONAME . '/commits/master.atom');
 	define('MODULE_PATH', 'modules/'.$_GET['m'].'/');
 	define('RSS_LOCAL_PATH', MODULE_PATH.'master.atom');
 		
@@ -133,7 +136,7 @@ function exec_ogp_module()
 		
 		if ( $seed != $pversion )
 		{	
-			$dwl = 'https://github.com/OpenGamePanel/'.REPONAME.'/archive/'.$seed.'.zip';
+			$dwl = $gitHubURL . 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]);

+ 5 - 2
modules/update/updating.php

@@ -44,9 +44,12 @@ function exec_ogp_module()
 		return;
 	}
 
-	global $db;
+	global $db, $settings;
 	global $view;
 	
+	// GitHub URL
+	$gitHubURL = $settings["custom_github_update_URL"];		
+	
 	$vtype = "HubGit";
 
 	echo "<h4>" . dwl_update . "</h4>\n";
@@ -74,7 +77,7 @@ function exec_ogp_module()
 	{
 		// Download file to temporary folder
 		$temp_dwl = $temp . DIRECTORY_SEPARATOR . $_GET['version'] . '.zip';
-		$dwl = 'https://github.com/OpenGamePanel/'.REPONAME.'/archive/'.$_GET['version'].'.zip';
+		$dwl = $gitHubURL . REPONAME . '/archive/'.$_GET['version'].'.zip';
 		$zip_raw_data = file_get_contents($dwl);
 		if(! $zip_raw_data)
 		{