plugin installer functionality

This commit is contained in:
shubham_meena 2014-06-11 15:57:07 +05:30
parent 10afd1a3e8
commit 60d9b16a4a
7 changed files with 275 additions and 170 deletions

View file

@ -2,7 +2,7 @@
/**
* API for loading and interacting with plugins
* contains getters and setters
* contains getters and setters
*
* @author shubham meena mentored by Matthew Lagoe
*/
@ -29,7 +29,7 @@ class Plugincache {
$this -> setPluginType( $values['Type'] );
$this -> setPluginPermission( $values['Permission'] );
$this -> setPluginStatus( $values['Status'] );
$this -> setPluginInfo( $values['Info'] );
$this -> setPluginInfo( json_decode( $values['Info'] ) );
}
/**
@ -122,13 +122,6 @@ class Plugincache {
$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.
*

View file

@ -56,12 +56,21 @@ action = "Action"
[plugins]
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"
plugins= "Plugins"
plugin_id = "ID"
plugins = "Plugins"
plugin_name = "Name"
plugin_version= "Version"
plugin_permission= "Owner/Access Permission"
plugin_is_active= "On/Off"
plugin_version = "Version"
plugin_description = "Description"
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]
t_title = "Ticket"

View file

@ -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;
}
}
}

View file

@ -1,126 +1,130 @@
<?php
/**
* Core that runs the entire system.
* The index.php page handles:
* -# 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.
* -# else load the inc's folder matching function related to the page
* -# set the permission and other smarty related settings
* -# call the helper function to load the page.
* @author Daan Janssens, mentored by Matthew Lagoe
*/
* Core that runs the entire system.
* The index.php page handles:
* -# 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.
* -# else load the inc's folder matching function related to the page
* -# set the permission and other smarty related settings
* -# call the helper function to load the page.
*
* @author Daan Janssens, mentored by Matthew Lagoe
*/
//load required pages and turn error reporting on/off
error_reporting(E_ALL);
ini_set('display_errors', 'on');
// load required pages and turn error reporting on/off
error_reporting( E_ALL );
ini_set( 'display_errors', 'on' );
require_once( '../../ams_lib/libinclude.php' );
if (!file_exists('../is_installed')) {
//if is_installed doesnt exist run setup
if ( !file_exists( '../is_installed' ) ) {
// if is_installed doesnt exist run setup
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";
exit;
} else {
//if config exists then include it
exit;
} else {
// if config exists then include it
require( '../config.php' );
}
}
session_start();
//Running Cron?
if ( isset( $_GET["cron"]) ){
if ($_GET["cron"] == "true"){
Sync::syncdata(false);
}
}
// Running Cron?
if ( isset( $_GET["cron"] ) ) {
if ( $_GET["cron"] == "true" ) {
Sync :: syncdata( false );
}
}
//Always try to sync on page load, ie "lazy" cron
Sync::syncdata(false);
// Always try to sync on page load, ie "lazy" cron
Sync :: syncdata( false );
//Decide what page to load
if ( ! isset( $_GET["page"]) ){
if(isset($_SESSION['user'])){
if(Ticket_User::isMod(unserialize($_SESSION['ticket_user']))){
$page = 'dashboard';
}else{
$page = 'show_user';
}
}else{
//default page
$page = 'login';
}
}else{
if(isset($_SESSION['user'])){
$page = $_GET["page"];
}else{
switch($_GET["page"]){
case 'register':
$page = 'register';
break;
case 'forgot_password':
$page = 'forgot_password';
break;
case 'reset_password':
$page = 'reset_password';
break;
case 'error':
$page = 'error';
break;
default:
$page = 'login';
break;
}
}
}
// Decide what page to load
if ( ! isset( $_GET["page"] ) ) {
if ( isset( $_SESSION['user'] ) ) {
if ( Ticket_User :: isMod( unserialize( $_SESSION['ticket_user'] ) ) ) {
$page = 'dashboard';
} else {
$page = 'show_user';
}
} else {
// default page
$page = 'login';
}
} else {
if ( isset( $_SESSION['user'] ) ) {
$page = $_GET["page"];
} else {
switch ( $_GET["page"] ) {
case 'register':
$page = 'register';
break;
case 'forgot_password':
$page = 'forgot_password';
break;
case 'reset_password':
$page = 'reset_password';
break;
case 'error':
$page = 'error';
break;
default:
$page = 'login';
break;
}
}
}
//check if ingame & page= register
//this is needed because the ingame register can't send a hidden $_POST["function"]
if ( Helpers::check_if_game_client() && ($page == "register")){
require( "func/add_user.php" );
// check if ingame & page= register
// this is needed because the ingame register can't send a hidden $_POST["function"]
if ( Helpers :: check_if_game_client() && ( $page == "register" ) ) {
require( "func/add_user.php" );
$return = add_user();
}
}
//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
if ( isset( $_POST["function"] ) ){
require( "func/" . $_POST["function"] . ".php" );
// 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
if ( isset( $_POST["function"] ) ) {
require( "func/" . $_POST["function"] . ".php" );
$return = $_POST["function"]();
}else{
$filename = 'inc/' . $page . '.php';
if(is_file($filename)){
require_once($filename);
$return = $page();
}
}
} else if ( isset( $_GET["action"] ) ) {
require( "func/" . $_GET["action"] . ".php" );
$return = $_GET["action"]();
} else {
$filename = 'inc/' . $page . '.php';
if ( is_file( $filename ) ) {
require_once( $filename );
$return = $page();
}
}
//add username to the return array in case logged in.
if(isset($_SESSION['user'])){
$return['username'] = $_SESSION['user'];
}
// add username to the return array in case logged in.
if ( isset( $_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;
}
// 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
if($page == 'login' || $page == 'register' || $page == 'logout' || $page == 'forgot_password' || $page == 'reset_password'){
$return['no_visible_elements'] = 'TRUE';
}else{
// 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
if ( $page == 'error' ) {
$return['permission'] = 0;
$return['no_visible_elements'] = 'FALSE';
}
}
//handle error page
if($page == 'error'){
$return['permission'] = 0;
$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 );

View file

@ -160,15 +160,15 @@
DROP TABLE IF EXISTS `" . $cfg['db']['lib']['name'] ."`.`plugins` ;
CREATE TABLE IF NOT EXISTS `" . $cfg['db']['lib']['name'] ."`.`plugins` (
`Id` INT(10) NOT NULL AUTO_INCREMENT,
`FileName VARCHAR(255) NOT NULL,
`Id` INT(10) NOT NULL AUTO_INCREMENT,
`FileName VARCHAR(255) NOT NULL,
`Name` VARCHAR(11) NOT NULL,
`Type` VARCHAR(12) NOT NULL,
`Owner` VARCHAR(25) NOT NULL,
`Permission` VARCHAR(5) NOT NULL,
`Status` 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`) )
ENGINE = InnoDB;

View file

@ -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}

View file

@ -1,4 +1,3 @@
{block name=content}
<div class="row-fluid">
<div class="box span12">
@ -10,27 +9,35 @@
<a href="#" class="btn btn-close btn-round"><i class="icon-remove"></i></a>
</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">
<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">
<thead>
<tr>
<th>{$plugin_id}</th>
<th>{$plugin_permission}</th>
<th>{$plugin_name}</th>
<th>{$plugin_status}</th>
<th width="150">{$plugin_name}</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>
</thead>
<tbody>
{foreach from=$plug item=element}
<tr>
<td>{$element.id}</td>
<td class="center">{$element.plugin_permission}</td>
<td><input type="checkbox" name ="{$element.id}"{if ($element.plugin_status) eq "1"}checked{/if}/></td>
<td class="center">{$element.plugin_name}</td>
<td class="center">{$element.plugin_version}</td>
<td class="center">{$element.plugin_isactive}</td>
<td class="center">{$element.plugin_info->Version}</td>
<td class="center">{$element.plugin_info->Description}</td>
<td class="center">{$element.plugin_type}</td>
<td class="center">{$element.plugin_permission}</td>
</tr>
{/foreach}
@ -48,42 +55,6 @@
</div>
</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-->
{/block}