plugin installer functionality

--HG--
branch : Gsoc14-ryzomAppImprovements
hg/feature/cdb-packed
shubham_meena 11 years ago
parent c558b92bf5
commit a15462c863

@ -2,7 +2,7 @@
/** /**
* API for loading and interacting with plugins * API for loading and interacting with plugins
* contains getters and setters * contains getters and setters
* *
* @author shubham meena mentored by Matthew Lagoe * @author shubham meena mentored by Matthew Lagoe
*/ */
@ -29,7 +29,7 @@ class Plugincache {
$this -> setPluginType( $values['Type'] ); $this -> setPluginType( $values['Type'] );
$this -> setPluginPermission( $values['Permission'] ); $this -> setPluginPermission( $values['Permission'] );
$this -> setPluginStatus( $values['Status'] ); $this -> setPluginStatus( $values['Status'] );
$this -> setPluginInfo( $values['Info'] ); $this -> setPluginInfo( json_decode( $values['Info'] ) );
} }
/** /**
@ -122,13 +122,6 @@ class Plugincache {
$this -> plugin_status = $d; $this -> plugin_status = $d;
} }
/**
* get plugin name attribute of the object.
*/
public function getPluginName() {
return $this -> plugin_name;
}
/** /**
* set plugin name attribute of the object. * set plugin name attribute of the object.
* *
@ -147,4 +140,4 @@ class Plugincache {
$this -> plugin_info = $p_n; $this -> plugin_info = $p_n;
} }
} }

@ -56,12 +56,21 @@ action = "Action"
[plugins] [plugins]
plugin_title = "Plugin List" plugin_title = "Plugin List"
plugin_info = "Here you can see the entire list of plugins . You can easily remove plugins ,activate them and add permissions" plugin_info = "Here you can see the entire list of plugins . You can easily remove plugins ,activate them and add permissions"
plugins= "Plugins" plugins = "Plugins"
plugin_id = "ID"
plugin_name = "Name" plugin_name = "Name"
plugin_version= "Version" plugin_version = "Version"
plugin_permission= "Owner/Access Permission" plugin_description = "Description"
plugin_is_active= "On/Off" plugin_type = "Type"
plugin_permission = "Access Permission"
plugin_status = "Status"
ip_success = "Plugin added succesfully."
[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.</br>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"
[show_ticket] [show_ticket]
t_title = "Ticket" t_title = "Ticket"
@ -252,4 +261,4 @@ email_body_forgot_password_header = "A request to reset your account's password
email_body_forgot_password_footer = " email_body_forgot_password_footer = "
---------- ----------
If you didn't make this request, please ignore this message." If you didn't make this request, please ignore this message."
;=========================================================================== ;===========================================================================

@ -0,0 +1,94 @@
<?php
/**
* This function is used in installing plugins
* It performs validation check for the compressed plugin
* then extract in plugin folder to get the info
*
* @author Shubham Meena, mentored by Matthew Lagoe
*/
function install_plugin() {
// if logged in
if ( WebUsers :: isLoggedIn() ) {
if ( ( isset( $_FILES["file"] ) ) && ( $_FILES["file"]["size"] > 0 ) && ( $_FILES["file"]["type"] == 'application/zip' ) )
{
$fileName = $_FILES["file"]["name"]; //the files name takes from the HTML form
$fileTmpLoc = $_FILES["file"]["tmp_name"]; //file in the PHP tmp folder
$dir = trim( $_FILES["file"]["name"], ".zip" );
$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
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 );
// 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['Permission'] = 'admin';
}
else
{
$install_result['Permission'] = 'user';
}
$install_result['Info'] = json_encode( $result );
// connection with the database
$dbr = new DBLayer( "lib" );
$dbr -> insert( "plugins", $install_result );
header( "Location: index.php?page=plugins&result=1" );
exit;
}
else
{
rmdir( $target_path );
header( "Location: index.php?page=install_plugin&result=2" );
exit;
}
}
}
header( "Location: index.php?page=plugins" );
exit;
}
else
{
header( "Location: index.php?page=install_plugin&result=1" );
exit;
}
}
}

@ -1,126 +1,130 @@
<?php <?php
/** /**
* Core that runs the entire system. * Core that runs the entire system.
* The index.php page handles: * The index.php page handles:
* -# checks what page to load * -# checks what page to load
* -# if a $_POST['function'] is set try to execute that function in the matching php file located in the func folder. * -# if a $_POST['function'] is set try to execute that function in the matching php file located in the func folder.
* -# else load the inc's folder matching function related to the page * -# else load the inc's folder matching function related to the page
* -# set the permission and other smarty related settings * -# set the permission and other smarty related settings
* -# call the helper function to load the page. * -# call the helper function to load the page.
* @author Daan Janssens, mentored by Matthew Lagoe *
*/ * @author Daan Janssens, mentored by Matthew Lagoe
*/
//load required pages and turn error reporting on/off // load required pages and turn error reporting on/off
error_reporting(E_ALL); error_reporting( E_ALL );
ini_set('display_errors', 'on'); ini_set( 'display_errors', 'on' );
require_once( '../../ams_lib/libinclude.php' ); require_once( '../../ams_lib/libinclude.php' );
if (!file_exists('../is_installed')) { if ( !file_exists( '../is_installed' ) ) {
//if is_installed doesnt exist run setup // if is_installed doesnt exist run setup
require( 'installer/libsetup.php' ); require( 'installer/libsetup.php' );
} elseif (isset($_POST["function"]) && $_POST["function"] == "do_install") { } elseif ( isset( $_POST["function"] ) && $_POST["function"] == "do_install" ) {
echo "Can't run setup while file '../is_installed' exists, please remove that file if you wish to run the install"; echo "Can't run setup while file '../is_installed' exists, please remove that file if you wish to run the install";
exit; exit;
} else { } else {
//if config exists then include it // if config exists then include it
require( '../config.php' ); require( '../config.php' );
} }
session_start(); session_start();
//Running Cron? // Running Cron?
if ( isset( $_GET["cron"]) ){ if ( isset( $_GET["cron"] ) ) {
if ($_GET["cron"] == "true"){ if ( $_GET["cron"] == "true" ) {
Sync::syncdata(false); Sync :: syncdata( false );
} }
} }
//Always try to sync on page load, ie "lazy" cron // Always try to sync on page load, ie "lazy" cron
Sync::syncdata(false); Sync :: syncdata( false );
//Decide what page to load // Decide what page to load
if ( ! isset( $_GET["page"]) ){ if ( ! isset( $_GET["page"] ) ) {
if(isset($_SESSION['user'])){ if ( isset( $_SESSION['user'] ) ) {
if(Ticket_User::isMod(unserialize($_SESSION['ticket_user']))){ if ( Ticket_User :: isMod( unserialize( $_SESSION['ticket_user'] ) ) ) {
$page = 'dashboard'; $page = 'dashboard';
}else{ } else {
$page = 'show_user'; $page = 'show_user';
} }
}else{ } else {
//default page // default page
$page = 'login'; $page = 'login';
} }
}else{ } else {
if(isset($_SESSION['user'])){ if ( isset( $_SESSION['user'] ) ) {
$page = $_GET["page"]; $page = $_GET["page"];
}else{ } else {
switch($_GET["page"]){ switch ( $_GET["page"] ) {
case 'register': case 'register':
$page = 'register'; $page = 'register';
break; break;
case 'forgot_password': case 'forgot_password':
$page = 'forgot_password'; $page = 'forgot_password';
break; break;
case 'reset_password': case 'reset_password':
$page = 'reset_password'; $page = 'reset_password';
break; break;
case 'error': case 'error':
$page = 'error'; $page = 'error';
break; break;
default: default:
$page = 'login'; $page = 'login';
break; break;
} }
} }
} }
//check if ingame & page= register // check if ingame & page= register
//this is needed because the ingame register can't send a hidden $_POST["function"] // this is needed because the ingame register can't send a hidden $_POST["function"]
if ( Helpers::check_if_game_client() && ($page == "register")){ if ( Helpers :: check_if_game_client() && ( $page == "register" ) ) {
require( "func/add_user.php" ); require( "func/add_user.php" );
$return = add_user(); $return = add_user();
} }
//perform an action in case one is specified // perform an action in case one is specified
//else check if a php page is included in the inc folder, else just set page to the get param // else check if a php page is included in the inc folder, else just set page to the get param
if ( isset( $_POST["function"] ) ){ if ( isset( $_POST["function"] ) ) {
require( "func/" . $_POST["function"] . ".php" ); require( "func/" . $_POST["function"] . ".php" );
$return = $_POST["function"](); $return = $_POST["function"]();
}else{ } else if ( isset( $_GET["action"] ) ) {
$filename = 'inc/' . $page . '.php'; require( "func/" . $_GET["action"] . ".php" );
if(is_file($filename)){ $return = $_GET["action"]();
require_once($filename); } else {
$return = $page(); $filename = 'inc/' . $page . '.php';
} if ( is_file( $filename ) ) {
} require_once( $filename );
$return = $page();
}
}
//add username to the return array in case logged in. // add username to the return array in case logged in.
if(isset($_SESSION['user'])){ if ( isset( $_SESSION['user'] ) ) {
$return['username'] = $_SESSION['user']; $return['username'] = $_SESSION['user'];
} }
//Set permission
if(isset($_SESSION['ticket_user'])){
$return['permission'] = unserialize($_SESSION['ticket_user'])->getPermission();
}else{
//default permission
$return['permission'] = 0;
}
//hide sidebar + topbar in case of login/register // Set permission
if($page == 'login' || $page == 'register' || $page == 'logout' || $page == 'forgot_password' || $page == 'reset_password'){ if ( isset( $_SESSION['ticket_user'] ) ) {
$return['no_visible_elements'] = 'TRUE'; $return['permission'] = unserialize( $_SESSION['ticket_user'] ) -> getPermission();
}else{ } else {
$return['no_visible_elements'] = 'FALSE'; // default permission
} $return['permission'] = 0;
}
// hide sidebar + topbar in case of login/register
if ( $page == 'login' || $page == 'register' || $page == 'logout' || $page == 'forgot_password' || $page == 'reset_password' ) {
$return['no_visible_elements'] = 'TRUE';
} else {
$return['no_visible_elements'] = 'FALSE';
}
//handle error page // handle error page
if($page == 'error'){ if ( $page == 'error' ) {
$return['permission'] = 0; $return['permission'] = 0;
$return['no_visible_elements'] = 'FALSE'; $return['no_visible_elements'] = 'FALSE';
} }
//load the template with the variables in the $return array // load the template with the variables in the $return array
helpers :: loadTemplate( $page , $return ); helpers :: loadTemplate( $page , $return );

@ -160,15 +160,15 @@
DROP TABLE IF EXISTS `" . $cfg['db']['lib']['name'] ."`.`plugins` ; DROP TABLE IF EXISTS `" . $cfg['db']['lib']['name'] ."`.`plugins` ;
CREATE TABLE IF NOT EXISTS `" . $cfg['db']['lib']['name'] ."`.`plugins` ( CREATE TABLE IF NOT EXISTS `" . $cfg['db']['lib']['name'] ."`.`plugins` (
`Id` INT(10) NOT NULL AUTO_INCREMENT, `Id` INT(10) NOT NULL AUTO_INCREMENT,
`FileName VARCHAR(255) NOT NULL, `FileName VARCHAR(255) NOT NULL,
`Name` VARCHAR(11) NOT NULL, `Name` VARCHAR(11) NOT NULL,
`Type` VARCHAR(12) NOT NULL, `Type` VARCHAR(12) NOT NULL,
`Owner` VARCHAR(25) NOT NULL, `Owner` VARCHAR(25) NOT NULL,
`Permission` VARCHAR(5) NOT NULL, `Permission` VARCHAR(5) NOT NULL,
`Status` INT(11) NOT NULL DEFAULT 0, `Status` INT(11) NOT NULL DEFAULT 0,
`Weight` INT(11) NOT NULL DEFAULT 0, `Weight` INT(11) NOT NULL DEFAULT 0,
`Info` BLOB NULL DEFAULT NULL, `Info` TEXT NULL DEFAULT NULL,
PRIMARY KEY (`Id`) ) PRIMARY KEY (`Id`) )
ENGINE = InnoDB; ENGINE = InnoDB;

@ -0,0 +1,34 @@
{block name=content}
<div class="row-fluid">
<div class="box span12">
<div class="box-header well">
<h2><i class="icon-info-sign"></i>{$ip_title}</h2>
<div class="box-icon">
<a href="#" class="btn btn-round" onclick="javascript:show_help('intro');return false;"><i class="icon-info-sign"></i></a>
<a href="#" class="btn btn-setting btn-round"><i class="icon-cog"></i></a>
<a href="#" class="btn btn-minimize btn-round"><i class="icon-chevron-up"></i></a>
<a href="#" class="btn btn-close btn-round"><i class="icon-remove"></i></a>
</div>
</div>
<div class="box-content">
<center>
<p>{$ip_support}</p>
<div class="alert alert-error">
<form enctype="multipart/form-data" method="post" action="index.php?page=plugin&action=install_plugin" >
<label for="file">Filename:</label>&nbsp;&nbsp;
<input type="file" name="file" id="file"></br>
{if isset($smarty.get.result) and $smarty.get.result eq "1"}<p>{$ip_error}</p>{/if}
{if isset($smarty.get.result) and $smarty.get.result eq "2"}<p>{$ip_info_nfound}</p>{/if}
<button type="submit" class="btn btn-primary" style="margin-left:5px; margin-top:10px;">Install Plugin</button></br>
</div>
{$ip_message}
</center>
<div class="clearfix"></div>
</div>
</div>
</div>
</div><!--/span-->
</div><!--/row-->
{/block}

@ -1,4 +1,3 @@
{block name=content} {block name=content}
<div class="row-fluid"> <div class="row-fluid">
<div class="box span12"> <div class="box span12">
@ -10,27 +9,35 @@
<a href="#" class="btn btn-close btn-round"><i class="icon-remove"></i></a> <a href="#" class="btn btn-close btn-round"><i class="icon-remove"></i></a>
</div> </div>
</div> </div>
{if isset($smarty.get.result) and $smarty.get.result eq "1"}<div class="alert alert-error"><p>{$ip_success}</p></div>{/if}
<div class="box-content"> <div class="box-content">
<center><p>{$plugin_info}</p></center> <center><p>{$plugin_info}</p></center>
<center><a href="index.php?page=plugins&action=deletePlugins"><button class="btn btn-primary btn-large">Delete</button></a>
<a href="index.php?page=plugins&action=activatePlugins"><button class="btn btn-primary btn-large dropdown-toggle">Activate</button></a>
<a href="index.php?page=plugins&action=deactivatePlugins"><button class="btn btn-primary btn-large dropdown-toggle">Deactivate</button></a>
<a href="index.php?page=install_plugin"><button class="btn btn-primary btn-large dropdown-toggle">Add</button></a>
<a href="index.php?page=plugins&action=updatePlugins"><button class="btn btn-primary btn-large dropdown-toggle">Check for updates</button></a>
</center>
<table class="table table-striped table-bordered"> <table class="table table-striped table-bordered">
<thead> <thead>
<tr> <tr>
<th>{$plugin_id}</th> <th>{$plugin_status}</th>
<th>{$plugin_permission}</th> <th width="150">{$plugin_name}</th>
<th>{$plugin_name}</th>
<th>{$plugin_version}</th> <th>{$plugin_version}</th>
<th>{$plugin_is_active}</th> <th width="400">{$plugin_description}</th>
<th>{$plugin_type}</th>
<th>{$plugin_permission}</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{foreach from=$plug item=element} {foreach from=$plug item=element}
<tr> <tr>
<td>{$element.id}</td> <td><input type="checkbox" name ="{$element.id}"{if ($element.plugin_status) eq "1"}checked{/if}/></td>
<td class="center">{$element.plugin_permission}</td>
<td class="center">{$element.plugin_name}</td> <td class="center">{$element.plugin_name}</td>
<td class="center">{$element.plugin_version}</td> <td class="center">{$element.plugin_info->Version}</td>
<td class="center">{$element.plugin_isactive}</td> <td class="center">{$element.plugin_info->Description}</td>
<td class="center">{$element.plugin_type}</td>
<td class="center">{$element.plugin_permission}</td>
</tr> </tr>
{/foreach} {/foreach}
@ -48,42 +55,6 @@
</div> </div>
</div><!--/span--> </div><!--/span-->
<div class="box span3">
<div class="box-header well" data-original-title="">
<h2><i class="icon-th"></i>Actions</h2>
<div class="box-icon">
<a href="#" class="btn btn-minimize btn-round"><i class="icon-chevron-up"></i></a>
<a href="#" class="btn btn-close btn-round"><i class="icon-remove"></i></a>
</div>
</div>
<div class="box-content">
<div class="row-fluid">
<div class="btn-group">
<button class="btn btn-primary btn-large dropdown-toggle" data-toggle="dropdown">Actions<span class="caret"></span></button>
<ul class="dropdown-menu">
<li class="divider"></li>
<li><a href="">Edit Plugins</a></li>
<li><a href="">Add Plugin</a></li>
<li class="divider"></li>
{if isset($isAdmin) and $isAdmin eq 'TRUE' and $target_id neq 1}
{if $userPermission eq 1}
<li><a href="index.php?page=change_permission&user_id={$target_id}&value=2">Make Moderator</a></li>
<li><a href="index.php?page=change_permission&user_id={$target_id}&value=3">Make Admin</a></li>
{else if $userPermission eq 2 }
<li><a href="index.php?page=change_permission&user_id={$target_id}&value=1">Demote to User</a></li>
<li><a href="index.php?page=change_permission&user_id={$target_id}&value=3">Make Admin</a></li>
{else if $userPermission eq 3 }
<li><a href="index.php?page=change_permission&user_id={$target_id}&value=1">Demote to User</a></li>
<li><a href="index.php?page=change_permission&user_id={$target_id}&value=2">Demote to Moderator</a></li>
{/if}
<li class="divider"></li>
{/if}
</ul>
</div>
</div>
</div>
</div><!--/span-->
</div><!--/row--> </div><!--/row-->
{/block} {/block}

Loading…
Cancel
Save