diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/translations/en.ini b/code/ryzom/tools/server/ryzom_ams/ams_lib/translations/en.ini index 0164abbee..4c8b545ec 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/translations/en.ini +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/translations/en.ini @@ -61,16 +61,23 @@ plugin_name = "Name" plugin_version = "Version" plugin_description = "Description" plugin_type = "Type" -plugin_permission = "Access Permission" +plugin_permission = "Access
Permission" plugin_status = "Status" -ip_success = "Plugin added succesfully." +ip_success = "Plugin added succesfuly." +plugin_actions = "Actions" +dp_success = "Plugin deleted successfuly" +dp_error = "Error in deleting plugin.Please try again later" +ac_success = "Plugin Activated successfuly" +ac_error = "Plugin facing some error in activating. Please try again later" +dc_success = "Plugin de-Activated successfuly" +dc_error = "Plugin facing some error in de-activating. Please try again later" [install_plugin] ip_title = "Install a new Plugin" ip_message = "For example: name.zip from your local computer" ip_support = "Upload the plugin archieve to install.
The following file extension is supported: zip." -ip_error = "Please select the format with zip extension" ip_info_nfound = "Info file not found in the Plugin.Please recheck" +ip_file_nfnd="Please upload a plugin before clicking on install button" [show_ticket] t_title = "Ticket" diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/func/install_plugin.php b/code/ryzom/tools/server/ryzom_ams/www/html/func/install_plugin.php index 64cb66a30..5376dfd02 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/func/install_plugin.php +++ b/code/ryzom/tools/server/ryzom_ams/www/html/func/install_plugin.php @@ -11,7 +11,18 @@ function install_plugin() { // if logged in if ( WebUsers :: isLoggedIn() ) { - if ( ( isset( $_FILES["file"] ) ) && ( $_FILES["file"]["size"] > 0 ) && ( $_FILES["file"]["type"] == 'application/zip' ) ) + // path of temporary folder for storing files + $temp_path = "../../ams_lib/temp"; + + // create a temp directory if not exist + // temp folder where we first store all uploaded plugins before install + if ( !file_exists( "$temp_path" ) ) + { + mkdir( $temp_path ); + } + + // checking the server if file is uploaded or not + if ( ( isset( $_FILES["file"] ) ) && ( $_FILES["file"]["size"] > 0 ) ) { $fileName = $_FILES["file"]["name"]; //the files name takes from the HTML form $fileTmpLoc = $_FILES["file"]["tmp_name"]; //file in the PHP tmp folder @@ -19,40 +30,44 @@ function install_plugin() { $target_path = "../../ams_lib/plugins/$dir"; //path in which the zip extraction is to be done $destination = "../../ams_lib/plugins/"; - if ( move_uploaded_file( $fileTmpLoc, $destination . $fileName ) ) { - // zip object to handle zip archieves - $zip = new ZipArchive(); - $x = $zip -> open( $destination . $fileName ); - if ( $x === true ) { - $zip -> extractTo( $destination ); // change this to the correct site path - $zip -> close(); - - // removing the uploaded zip file - unlink( $destination . $fileName ); - - // check for the info file + // checking for the command to install plugin is given or not + if ( !isset( $_POST['install_plugin'] ) ) + { + if ( ( $_FILES["file"]["type"] == 'application/zip' ) ) + { + if ( move_uploaded_file( $fileTmpLoc, $temp_path . "/" . $fileName ) ) { + echo "$fileName upload is complete."; + exit(); + } + else + { + echo "Error in uploading file."; + exit(); + } + } + else + { + echo "Please select a file with .zip extension to upload."; + exit(); + } + } + else + { + + // calling function to unzip archives + if ( zipExtraction( $temp_path . "/" . $fileName , $destination ) ) + { if ( file_exists( $target_path . "/.info" ) ) { - // read the details of the plugin through the info file - $file_handle = fopen( $target_path . "/.info", "r" ); - $result = array(); - while ( !feof( $file_handle ) ) { - - $line_of_text = fgets( $file_handle ); - $parts = array_map( 'trim', explode( '=', $line_of_text, 2 ) ); - @$result[$parts[0]] = $parts[1]; - - } - - fclose( $file_handle ); + $result = array(); + $result = readPluginFile( ".info", $target_path ); // sending all info to the database $install_result = array(); $install_result['FileName'] = $target_path; $install_result['Name'] = $result['PluginName']; - $install_result['Type'] = $result['type']; - - if ( Ticket_User :: isMod( unserialize( $_SESSION['ticket_user'] ) ) ) + // $install_result['Type'] = $result['type']; + if ( Ticket_User :: isMod( unserialize( $_SESSION['ticket_user'] ) ) ) { $install_result['Permission'] = 'admin'; } @@ -67,28 +82,87 @@ function install_plugin() { $dbr = new DBLayer( "lib" ); $dbr -> insert( "plugins", $install_result ); - header( "Location: index.php?page=plugins&result=1" ); + // if everything is successfull redirecting to the plugin template + header( "Location: index.php?page=plugins&result=1" ); exit; - } else { + // file .info not exists rmdir( $target_path ); header( "Location: index.php?page=install_plugin&result=2" ); exit; - } - } + } else + { + // extraction failed + header( "Location: index.php?page=install_plugin&result=0" ); + exit; + } } - - header( "Location: index.php?page=plugins" ); - exit; + } + else + { + echo "Please Browse for a file before clicking the upload button"; + exit(); + } + } + } + +/** + * function to unzip the zipped files + * + * @param $target_path path to the target zipped file + * @param $destination path to the destination + * @return boolean + */ +function zipExtraction( $target_path, $destination ) + { + $zip = new ZipArchive(); + $x = $zip -> open( $target_path ); + if ( $x === true ) { + if ( $zip -> extractTo( $destination ) ) + { + $zip -> close(); + return true; } else { - header( "Location: index.php?page=install_plugin&result=1" ); - exit; + $zip -> close(); + return false; } } - } + } + +/** + * function to read text files and extract + * the information into an array + * + * ----------------------------------------------------------- + * format: + * ----------------------------------------------------------- + * PluginName = Name of the plugin + * Version = version of the plugin + * Type = type of the plugin + * Description = Description of the plugin ,it's functionality + * ----------------------------------------------------------- + * + * reads only files with name .info + * + * @param $fileName file to read + * @param $targetPath path to the folder containing .info file + * @return array containing above information in array(value => key) + */ +function readPluginFile( $fileName, $target_path ) + { + $file_handle = fopen( $target_path . "/" . $fileName, "r" ); + $result = array(); + while ( !feof( $file_handle ) ) { + $line_of_text = fgets( $file_handle ); + $parts = array_map( 'trim', explode( '=', $line_of_text, 2 ) ); + @$result[$parts[0]] = $parts[1]; + } + fclose( $file_handle ); + return $result; + } diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/templates/install_plugin.tpl b/code/ryzom/tools/server/ryzom_ams/www/html/templates/install_plugin.tpl index 52fdb3820..27a4cec49 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/templates/install_plugin.tpl +++ b/code/ryzom/tools/server/ryzom_ams/www/html/templates/install_plugin.tpl @@ -15,12 +15,15 @@

{$ip_support}

-
+   
- {if isset($smarty.get.result) and $smarty.get.result eq "1"}

{$ip_error}

{/if} +
+
+

+ {if isset($smarty.get.result) and $smarty.get.result eq "0"}

{$ip_file_nfnd}

{/if} {if isset($smarty.get.result) and $smarty.get.result eq "2"}

{$ip_info_nfound}

{/if} -
+
{$ip_message}
diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout.tpl b/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout.tpl index fa97211d7..e66d952b8 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout.tpl +++ b/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout.tpl @@ -192,6 +192,50 @@ } + + + diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/templates/plugins.tpl b/code/ryzom/tools/server/ryzom_ams/www/html/templates/plugins.tpl index 99f382c5c..cac67147a 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/templates/plugins.tpl +++ b/code/ryzom/tools/server/ryzom_ams/www/html/templates/plugins.tpl @@ -10,23 +10,28 @@ {if isset($smarty.get.result) and $smarty.get.result eq "1"}

{$ip_success}

{/if} + {if isset($smarty.get.result) and $smarty.get.result eq "0"}

{$dp_error}

{/if} + {if isset($smarty.get.result) and $smarty.get.result eq "2"}

{$dp_success}

{/if} + {if isset($smarty.get.result) and $smarty.get.result eq "3"}

{$ac_success}

{/if} + {if isset($smarty.get.result) and $smarty.get.result eq "4"}

{$ac_error}

{/if} + {if isset($smarty.get.result) and $smarty.get.result eq "5"}

{$dc_success}

{/if} + {if isset($smarty.get.result) and $smarty.get.result eq "6"}

{$dc_error}

{/if}

{$plugin_info}

-
- - - - -
+
+ + +
- + - - + + + @@ -38,6 +43,9 @@ + {/foreach}
{$plugin_status}{$plugin_name}{$plugin_name} {$plugin_version}{$plugin_description}{$plugin_type}{$plugin_description}{$plugin_type} {$plugin_permission}{$plugin_actions}
{$element.plugin_info->Description} {$element.plugin_type} {$element.plugin_permission} + {if ($element.plugin_status) eq "0"}{/if} + {if ($element.plugin_status) eq "1"}{/if}