Exemplo n.º 1
0
/**
 * This function is used in deleting plugins.
 * It removes the plugin from the codebase as well as
 * from the Database. When user request to delete a plugin
 * id of that plugin is sent in $_GET global variable.
 *
 * @author Shubham Meena, mentored by Matthew Lagoe
 */
function delete_plugin()
{
    // if logged in
    if (WebUsers::isLoggedIn()) {
        if (isset($_GET['id'])) {
            // id of plugin to delete after filtering
            $id = filter_var($_GET['id'], FILTER_SANITIZE_FULL_SPECIAL_CHARS);
            $db = new DBLayer('lib');
            $sth = $db->selectWithParameter("FileName", "plugins", array('id' => $id), "Id=:id");
            $name = $sth->fetch();
            if (is_dir("{$name['FileName']}")) {
                // removing plugin directory from the code base
                if (Plugincache::rrmdir("{$name['FileName']}")) {
                    $db->delete('plugins', array('id' => $id), "Id=:id");
                    //if result	successfull redirect and show success message
                    header("Cache-Control: max-age=1");
                    header("Location: index.php?page=plugins&result=2");
                    throw new SystemExit();
                } else {
                    // if result unsuccessfull redirect and show error message
                    header("Cache-Control: max-age=1");
                    header("Location: index.php?page=plugins&result=0");
                    throw new SystemExit();
                }
            }
        } else {
            // if result unsuccessfull redirect and show error message
            header("Cache-Control: max-age=1");
            header("Location: index.php?page=plugins&result=0");
            throw new SystemExit();
        }
    }
}
Exemplo n.º 2
0
/**
 * This function is used in installing updates for plugins.
 * It takes id of the plugin whose update is available using
 * $_GET global variable and then extract the update details
 * from db and then install it in the plugin.
 *
 * @author Shubham Meena, mentored by Matthew Lagoe
 */
function update_plugin()
{
    // if logged in
    if (WebUsers::isLoggedIn()) {
        if (isset($_GET['id'])) {
            // id of plugin to update
            $id = filter_var($_GET['id'], FILTER_SANITIZE_FULL_SPECIAL_CHARS);
            $db = new DBLayer('lib');
            $sth = $db->executeWithoutParams("SELECT * FROM plugins INNER JOIN updates ON plugins.Id=updates.PluginId Where plugins.Id={$id}");
            $row = $sth->fetch();
            // replacing update in the  database
            Plugincache::rrmdir($row['FileName']);
            Plugincache::zipExtraction($row['UpdatePath'], rtrim($row['FileName'], strtolower($row['Name'])));
            $db->update("plugins", array('Info' => $row['UpdateInfo']), "Id={$row['Id']}");
            // deleting the previous update
            $db->delete("updates", array('id' => $row['s.no']), "s.no=:id");
            // if update is installed succesffully redirect to show success message
            header("Cache-Control: max-age=1");
            header("Location: index.php?page=plugins&result=8");
            throw new SystemExit();
        }
    }
}
Exemplo n.º 3
0
/**
 * function to check for updates or
 * if the same plugin already exists
 * also, if the update founds ,check for the UpdateInfo in the .info file.
 * Update is saved in the temp directory with pluginName_version.zip
 *
 * @param  $fileName file which is uploaded in .zip extension
 * @param  $findPath where we have to look for the installed plugins
 * @param  $tempFile path for the temporary file
 * @param  $tempPath path where we have to store the update
 * @return 2 if plugin already exists and update not found
 * @return 3 if update info tag not found in .info file
 */
function checkForUpdate($fileName, $findPath, $tempFile, $tempPath)
{
    // check for plugin if exists
    $file = scandir($findPath);
    foreach ($file as $key => $value) {
        if (strcmp($value, $fileName) == 0) {
            if (!file_exists($tempPath . "/test")) {
                mkdir($tempPath . "/test");
            }
            // extracting the update
            if (zipExtraction($tempFile, $tempPath . "/test/")) {
                $result = readPluginFile(".info", $tempPath . "/test/" . $fileName);
                // check for the version for the plugin
                $db = new DBLayer("lib");
                $sth = $db->select("plugins", array('Name' => $result['PluginName']), "Name = :Name");
                $info = $sth->fetch();
                $info['Info'] = json_decode($info['Info']);
                // the two versions from main plugin and the updated part
                $new_version = explode('.', $result['Version']);
                $pre_version = explode('.', $info['Info']->Version);
                // For all plugins we have used semantic versioning
                // Format: X.Y.Z ,X->Major, Y->Minor, Z->Patch
                // change in the X Y & Z values refer the type of change in the plugin.
                // for initial development only Minor an Patch MUST be 0.
                // if there is bug fix then there MUST be an increment in the Z value.
                // if there is change in the functionality or addition of new functionality
                // then there MUST be an increment in the Y value.
                // When there is increment in the X value , Y and Z MUST be 0.
                // comparing if there is some change
                if (!array_diff($new_version, $pre_version)) {
                    // removing the uploaded file
                    Plugincache::rrmdir($tempPath . "/test/" . $fileName);
                    return '2';
                    //plugin already exists
                } else {
                    // check for update info if exists
                    if (!array_key_exists('UpdateInfo', $result)) {
                        return '3';
                        //update info tag not found
                    } else {
                        // check if update already exists
                        if (pluginUpdateExists($info['Id'], $tempPath . "/" . trim($fileName, ".zip") . "_" . $result['Version'] . ".zip")) {
                            echo "Update already exists";
                            throw new SystemExit();
                        } else {
                            // removing the preivous update
                            $dbr = new DBLayer("lib");
                            $dbr->delete("updates", array('id' => $info['Id']), "PluginId=:id");
                            // storing update in the temp directory
                            // format of update save
                            if (move_uploaded_file($tempFile, $tempPath . "/" . trim($fileName, ".zip") . "_" . $result['Version'] . ".zip")) {
                                // setting update information in the database
                                $update['PluginId'] = $info['Id'];
                                $update['UpdatePath'] = $tempPath . "/" . trim($fileName, ".zip") . "_" . $result['Version'] . ".zip";
                                $update['UpdateInfo'] = json_encode($result);
                                $dbr->insert("updates", $update);
                                header("Cache-Control: max-age=1");
                                header("Location: index.php?page=plugins&result=7");
                                throw new SystemExit();
                            }
                        }
                    }
                }
            }
        }
    }
}
Exemplo n.º 4
0
 /**
  * function to load hooks for the active plugins
  * and return the contents get from them.
  *
  * -->Get the list of active plugins then call the global
  *    hooks exists in the plugins hook file ($pluginName.php).
  * -->Collect the contents from the hooks and associate within
  *    array with key referenced plugin name.
  * -->return the content to use with smarty template loader
  *
  * @return $content content get from hooks
  */
 public static function loadHooks()
 {
     $content = array();
     $ac_arr = Plugincache::activePlugins();
     foreach ($ac_arr as $key => $value) {
         $plugin_path = Plugincache::pluginInfoUsingId($value['Id'], 'FileName');
         $template_path = json_decode(Plugincache::pluginInfoUsingId($value['Id'], 'Info'))->TemplatePath;
         $plugin_name = $plugin_path;
         // calling hooks in the $pluginName.php
         global $AMS_PLUGINS;
         include $AMS_PLUGINS . '/' . $plugin_name . '/' . $plugin_name . '.php';
         $arr = get_defined_functions();
         foreach ($arr['user'] as $key => $value) {
             switch (strtolower($value)) {
                 case strtolower($plugin_name) . '_hook_display':
                 case strtolower($plugin_name) . '_hook_call_rest':
                 case strtolower($plugin_name) . '_hook_get_db':
                 case strtolower($plugin_name) . '_hook_return_global':
                 case strtolower($plugin_name) . '_hook_activate':
                     $content['hook_info'][$plugin_name] = call_user_func($value);
                     break;
             }
         }
         // path for the template
         $content['hook_info'][$plugin_name]['TemplatePath'] = $template_path;
     }
     return $content;
 }
Exemplo n.º 5
0
    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;
    }
    // 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';
    }
    // call to load hooks for the active plugins
    $hook_content = Plugincache::loadHooks();
    foreach ($hook_content as $key => $value) {
        $return[$key] = $value;
    }
    // load the template with the variables in the $return array
    helpers::loadTemplate($page, $return);
} catch (SystemExit $e) {
    /* do nothing */
}