plugin installer functionality
--HG-- branch : Gsoc14-ryzomAppImprovementshg/feature/cdb-packed
parent
c558b92bf5
commit
a15462c863
@ -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 );
|
||||||
|
@ -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}
|
Loading…
Reference in New Issue