mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-12-23 01:18:46 +00:00
plugin installer functionality
This commit is contained in:
parent
8517a59a1d
commit
32db353677
7 changed files with 275 additions and 170 deletions
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -57,11 +57,20 @@ action = "Action"
|
|||
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"
|
||||
plugin_name = "Name"
|
||||
plugin_version = "Version"
|
||||
plugin_permission= "Owner/Access Permission"
|
||||
plugin_is_active= "On/Off"
|
||||
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"
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -7,6 +7,7 @@
|
|||
* -# 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
|
||||
*/
|
||||
|
||||
|
@ -84,6 +85,9 @@ if ( Helpers::check_if_game_client() && ($page == "register")){
|
|||
if ( isset( $_POST["function"] ) ) {
|
||||
require( "func/" . $_POST["function"] . ".php" );
|
||||
$return = $_POST["function"]();
|
||||
} else if ( isset( $_GET["action"] ) ) {
|
||||
require( "func/" . $_GET["action"] . ".php" );
|
||||
$return = $_GET["action"]();
|
||||
} else {
|
||||
$filename = 'inc/' . $page . '.php';
|
||||
if ( is_file( $filename ) ) {
|
||||
|
|
|
@ -168,7 +168,7 @@
|
|||
`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;
|
||||
|
||||
|
|
|
@ -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>
|
||||
<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}
|
||||
<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}
|
||||
|
||||
|
|
Loading…
Reference in a new issue