Explorar el Código

Merge pull request #337 from own3mall/master

Various Fixes for Issues - New Optional Prerequisites System for Modules
OwN-3m-All hace 8 años
padre
commit
dd83c33774

+ 7 - 0
includes/functions.php

@@ -829,4 +829,11 @@ function utf8ize($d, $htmlEntities = true) {
     }
     }
     return $d;
     return $d;
 }
 }
+
+function preReqInstalled($prereq){
+	if (($prereq['type'] === "f" && function_exists($prereq['value'])) || ($prereq['type'] === "c" && class_exists($prereq['value'])) || ($prereq['type'] === "x" && extension_loaded($prereq['value']))){
+		return true;
+	}
+	return false;
+}
 ?>
 ?>

+ 10 - 7
index.php

@@ -235,13 +235,10 @@ function ogpHome()
 			
 			
 			$banlist_info = $db->resultQuery("SELECT logging_attempts, banned_until FROM `OGP_DB_PREFIXban_list` WHERE client_ip='".$client_ip."';");
 			$banlist_info = $db->resultQuery("SELECT logging_attempts, banned_until FROM `OGP_DB_PREFIXban_list` WHERE client_ip='".$client_ip."';");
 			$login_attempts = !$banlist_info ? 0 : $banlist_info['0']['logging_attempts'];
 			$login_attempts = !$banlist_info ? 0 : $banlist_info['0']['logging_attempts'];
-			
-			if( !$banlist_info )
-				$db->query("INSERT INTO `OGP_DB_PREFIXban_list` (`client_ip`) VALUES('$client_ip');");
 
 
 			if( $banlist_info AND $banlist_info['0']['banned_until'] > 0 AND $banlist_info['0']['banned_until'] <= time() )
 			if( $banlist_info AND $banlist_info['0']['banned_until'] > 0 AND $banlist_info['0']['banned_until'] <= time() )
 			{
 			{
-				$db->query("UPDATE `OGP_DB_PREFIXban_list` SET logging_attempts='0', banned_until='0' WHERE client_ip='$client_ip';");
+				$db->query("DELETE FROM `OGP_DB_PREFIXban_list` WHERE client_ip='$client_ip';");
 				$login_attempts = 0;
 				$login_attempts = 0;
 			}
 			}
 			
 			
@@ -285,7 +282,7 @@ function ogpHome()
 				$_SESSION['users_theme'] = $userInfo['users_theme'];
 				$_SESSION['users_theme'] = $userInfo['users_theme'];
 				print_success( get_lang("logging_in") ."...");
 				print_success( get_lang("logging_in") ."...");
 				$db->logger( get_lang("logging_in") ."...");
 				$db->logger( get_lang("logging_in") ."...");
-				$db->query("UPDATE `OGP_DB_PREFIXban_list` SET logging_attempts='0', banned_until='0' WHERE client_ip = '$client_ip';");
+				$db->query("DELETE FROM `OGP_DB_PREFIXban_list` WHERE client_ip='$client_ip';");
 				$view->refresh("home.php?$default_page",2);
 				$view->refresh("home.php?$default_page",2);
 			}
 			}
 			else
 			else
@@ -295,13 +292,19 @@ function ogpHome()
 				if( $login_attempts == $settings["login_attempts_before_banned"] )
 				if( $login_attempts == $settings["login_attempts_before_banned"] )
 				{
 				{
 					$banned_until = time() + 300; // Five minutes banned from the panel.
 					$banned_until = time() + 300; // Five minutes banned from the panel.
-					$banlist_info['0']['banned_until'] = $banned_until;
+					
+					if( !$banlist_info )
+						$db->query("INSERT INTO `OGP_DB_PREFIXban_list` (`client_ip`) VALUES('$client_ip');");
+						
 					$db->logger( get_lang("bad_login") . " ( Banned until " . date("r", $banned_until) . " ) [ " . login . ": $_POST[ulogin], " . password . ": $_POST[upassword] ]" );
 					$db->logger( get_lang("bad_login") . " ( Banned until " . date("r", $banned_until) . " ) [ " . login . ": $_POST[ulogin], " . password . ": $_POST[upassword] ]" );
 					$db->query("UPDATE `OGP_DB_PREFIXban_list` SET logging_attempts='$login_attempts', banned_until='$banned_until' WHERE client_ip='$client_ip';");
 					$db->query("UPDATE `OGP_DB_PREFIXban_list` SET logging_attempts='$login_attempts', banned_until='$banned_until' WHERE client_ip='$client_ip';");
-					print_failure("Banned until " . date("r",$banlist_info['0']['banned_until']));
+					print_failure("Banned until " . date("r",$banned_until));
 				}
 				}
 				else
 				else
 				{
 				{
+					if( !$banlist_info )
+						$db->query("INSERT INTO `OGP_DB_PREFIXban_list` (`client_ip`) VALUES('$client_ip');");
+					
 					$db->logger( get_lang("bad_login") . " ( $login_attempts ) [ " . login . ": $_POST[ulogin], " . password . ": $_POST[upassword] ]" );
 					$db->logger( get_lang("bad_login") . " ( $login_attempts ) [ " . login . ": $_POST[ulogin], " . password . ": $_POST[upassword] ]" );
 					$db->query("UPDATE `OGP_DB_PREFIXban_list` SET logging_attempts='$login_attempts' WHERE client_ip='$client_ip';");
 					$db->query("UPDATE `OGP_DB_PREFIXban_list` SET logging_attempts='$login_attempts' WHERE client_ip='$client_ip';");
 					$view->refresh("index.php",2);
 					$view->refresh("index.php",2);

+ 24 - 10
install.php

@@ -239,20 +239,22 @@ function install() {
             array( "name" => "PHP Curl module", "type" => "f", "value" => "curl_init" ),
             array( "name" => "PHP Curl module", "type" => "f", "value" => "curl_init" ),
             array( "name" => "PHP XML Reader", "type" => "c", "value" => "XMLReader" ),
             array( "name" => "PHP XML Reader", "type" => "c", "value" => "XMLReader" ),
 			array( "name" => "PHP JSON Extension", "type" => "f", "value" => "json_decode" ),
 			array( "name" => "PHP JSON Extension", "type" => "f", "value" => "json_decode" ),
+			array( "name" => "PHP Zip Extension", "type" => "c", "value" => "ZipArchive" ),
 			array( "name" => "PHP mbstring Extension", "type" => "x", "value" => "mbstring" ));
 			array( "name" => "PHP mbstring Extension", "type" => "x", "value" => "mbstring" ));
+			
+		$optional_properties_to_check = array(
+			array( "name" => "PHP BCMath Extension", "type" => "f", "value" => "bcadd" ),
+		);
+		
         echo "<h3>".get_lang('checking_required_modules')."</h3>\n<table class='install'>";
         echo "<h3>".get_lang('checking_required_modules')."</h3>\n<table class='install'>";
 
 
         foreach ( $properties_to_check as $propertie ) {
         foreach ( $properties_to_check as $propertie ) {
-            if ( ( $propertie['type'] === "f" && function_exists($propertie['value']) ) ||
-                ( $propertie['type'] === "c" && class_exists($propertie['value']) ) ||
-				( $propertie['type'] === "x" && extension_loaded($propertie['value']) ) ) {
-                    echo "<tr><td>".$propertie['name']."</td>
-                        <td><span class='success'>".get_lang('found')."</span></td></tr>";
-                } else {
-                    echo "<tr><td>".$propertie['name']."</td>
-                        <td><span class='failure'>".get_lang('not_found')."</span></td></tr>";
-                    $failed = true;
-                }
+			if(preReqInstalled($propertie)){
+				echo "<tr><td>".$propertie['name']."</td><td><span class='success'>".get_lang('found')."</span></td></tr>";
+			}else{
+				echo "<tr><td>".$propertie['name']."</td><td><span class='failure'>".get_lang('not_found')."</span></td></tr>";
+				$failed = true;
+			}
         }
         }
 
 
         echo "<tr><td>Pear XXTEA</td><td>";
         echo "<tr><td>Pear XXTEA</td><td>";
@@ -325,6 +327,18 @@ function install() {
         echo "</td></tr>";
         echo "</td></tr>";
 
 
         echo "</table>\n";
         echo "</table>\n";
+        
+        echo "<h3>".get_lang('checking_optional_modules')."</h3>\n<table class='install'>";
+        
+        foreach ( $optional_properties_to_check as $propertie ) {
+			if(preReqInstalled($propertie)){
+				echo "<tr><td>".$propertie['name']."</td><td><span class='success'>".get_lang('found')."</span></td></tr>";
+			}else{
+				echo "<tr><td>".$propertie['name']."</td><td><span class='warning'>".get_lang('not_found')."</span></td></tr>";
+			}
+        }
+		
+		echo "</table>\n";
 
 
         if ( $failed ) {
         if ( $failed ) {
             echo "<p><a href='?'>".get_lang('refresh')."</a></p>\n";
             echo "<p><a href='?'>".get_lang('refresh')."</a></p>\n";

+ 2 - 1
lang/English/install.php

@@ -34,6 +34,7 @@ define('OGP_LANG_not_found', "Not found");
 define('OGP_LANG_pear_xxtea_info', "Pear Crypt_XXTEA is required for OGP usage. In the most of the Linux distributions this module can be installed with the following Pear command 'pear install Crypt_XXTEA-beta'.");
 define('OGP_LANG_pear_xxtea_info', "Pear Crypt_XXTEA is required for OGP usage. In the most of the Linux distributions this module can be installed with the following Pear command 'pear install Crypt_XXTEA-beta'.");
 define('OGP_LANG_refresh', "Refresh");
 define('OGP_LANG_refresh', "Refresh");
 define('OGP_LANG_checking_required_modules', "Checking required modules:");
 define('OGP_LANG_checking_required_modules', "Checking required modules:");
+define('OGP_LANG_checking_optional_modules', "Checking optional modules:");
 define('OGP_LANG_database_type', "Database type");
 define('OGP_LANG_database_type', "Database type");
 define('OGP_LANG_database_settings', "Database access settings");
 define('OGP_LANG_database_settings', "Database access settings");
 define('OGP_LANG_database_hostname', "Database Hostname");
 define('OGP_LANG_database_hostname', "Database Hostname");
@@ -65,4 +66,4 @@ define('OGP_LANG_go_to_panel', "Click here to login to your OGP.");
 define('OGP_LANG_unable_to_resolve', "If you are unable to resolve this problem please visit OGP website ");
 define('OGP_LANG_unable_to_resolve', "If you are unable to resolve this problem please visit OGP website ");
 define('OGP_LANG_slogan', "The Open-Source one!");
 define('OGP_LANG_slogan', "The Open-Source one!");
 define('OGP_LANG_default_welcome_title_message', "Welcome! <b style='font-size:12px; font-weight:normal;'>You can change this title in '<a href='?m=settings&p=themes'>Theme Settings</a>' under the '<a href='?m=administration&p=main'>Administration</a>' tab.</b>");
 define('OGP_LANG_default_welcome_title_message', "Welcome! <b style='font-size:12px; font-weight:normal;'>You can change this title in '<a href='?m=settings&p=themes'>Theme Settings</a>' under the '<a href='?m=administration&p=main'>Administration</a>' tab.</b>");
-?>
+?>

+ 2 - 1
lang/English/modules/modulemanager.php

@@ -52,4 +52,5 @@ define('OGP_LANG_failed_del_db', "Failed to delete module from database.");
 define('OGP_LANG_updated_module', "Updated module: '%s'.");
 define('OGP_LANG_updated_module', "Updated module: '%s'.");
 define('OGP_LANG_updating_modules', "Updating Modules");
 define('OGP_LANG_updating_modules', "Updating Modules");
 define('OGP_LANG_updating_finished', "Updating Finished");
 define('OGP_LANG_updating_finished', "Updating Finished");
-?>
+define('OGP_LANG_prereqs_missing', "Prerequisites of %s must be installed on the server before %s can be installed.");
+?>

+ 2 - 2
modules/administration/banlist.php

@@ -34,7 +34,7 @@ function exec_ogp_module()
 		foreach($_POST as $name => $ip)
 		foreach($_POST as $name => $ip)
 		{
 		{
 			$ip = $db->real_escape_string($ip);
 			$ip = $db->real_escape_string($ip);
-			$db->query("UPDATE `OGP_DB_PREFIXban_list` SET logging_attempts='0', banned_until='0' WHERE client_ip = '$ip';");
+			$db->query("DELETE FROM `OGP_DB_PREFIXban_list` WHERE client_ip = '$ip';");
 		}
 		}
 	}
 	}
 	$ban_list = $db->resultQuery("SELECT logging_attempts, banned_until, client_ip FROM `OGP_DB_PREFIXban_list`;");
 	$ban_list = $db->resultQuery("SELECT logging_attempts, banned_until, client_ip FROM `OGP_DB_PREFIXban_list`;");
@@ -64,4 +64,4 @@ function exec_ogp_module()
 	}
 	}
 	echo create_back_button($_GET['m'],"main");
 	echo create_back_button($_GET['m'],"main");
 }
 }
-?>
+?>

+ 14 - 3
modules/administration/watch_logger.php

@@ -79,10 +79,21 @@ function exec_ogp_module() {
 	</thead> 
 	</thead> 
 	<tbody> 
 	<tbody> 
 	<?php
 	<?php
-	if( isset( $_POST['log_id'] ) )
+	if( isset( $_POST['log_id'] ) ){
 		$db->del_logger_log($_POST['log_id']);
 		$db->del_logger_log($_POST['log_id']);
-	if( isset( $_POST['empty_logger'] ) )
+		$newLogs = array();
+		foreach($logs as $log){
+			if($log['log_id'] != $_POST['log_id']){
+				$newLogs[] = $log;
+			}
+		}
+		$logs = $newLogs;
+	}
+		
+	if( isset( $_POST['empty_logger'] ) ){
 		$db->empty_logger();
 		$db->empty_logger();
+		$logs = false;
+	}
 	
 	
 	if($logs)
 	if($logs)
 	{
 	{
@@ -137,4 +148,4 @@ function exec_ogp_module() {
 	}
 	}
 	echo paginationPages($count_logs[0]['total'], $p, $l, $uri, 3, 'watchLogger');
 	echo paginationPages($count_logs[0]['total'], $p, $l, $uri, 3, 'watchLogger');
 }
 }
-?>
+?>

+ 24 - 1
modules/modulemanager/module_handling.php

@@ -33,7 +33,7 @@ function list_available_modules()
 /// \return 1 If module installation was successfull.
 /// \return 1 If module installation was successfull.
 /// \return 2 If module installation was optional and module was not installed.
 /// \return 2 If module installation was optional and module was not installed.
 function install_module($db, $module, $install_if_optional = TRUE)
 function install_module($db, $module, $install_if_optional = TRUE)
-{
+{	
     // each module must have module.php file which contains the required variables.
     // each module must have module.php file which contains the required variables.
     /// \todo We might want to turn this to XML file.
     /// \todo We might want to turn this to XML file.
     if ( !is_file("modules/".$module."/module.php") )
     if ( !is_file("modules/".$module."/module.php") )
@@ -52,6 +52,29 @@ function install_module($db, $module, $install_if_optional = TRUE)
 
 
     if ( $db->isModuleInstalled($module) )
     if ( $db->isModuleInstalled($module) )
         return 0;
         return 0;
+        
+    // Prerequisites checking
+    if(isset($module_prereqs) && is_array($module_prereqs) && count($module_prereqs)){
+		$prereqPass = true;
+		$missingPrereqs = "";
+		$i = 0;
+		foreach($module_prereqs as $prereq){
+			if(!preReqInstalled($prereq)){
+				if($i == 0){
+					$missingPrereqs .= $prereq["name"];
+				}else{
+					$missingPrereqs .= ", " . $prereq["name"];
+				}
+				$prereqPass = false;
+			}
+			$i++;
+		}
+		
+		if(!$prereqPass){
+			print_failure(get_lang_f("prereqs_missing", $missingPrereqs, $module_title));
+			return -2;
+		}
+	}
 
 
     // Check if the module should be installed or not.
     // Check if the module should be installed or not.
     if ( $install_if_optional == FALSE && $module_required == FALSE )
     if ( $install_if_optional == FALSE && $module_required == FALSE )