Ejemplo n.º 1
0
function plugin_certificates_install()
{
    global $DB;
    include_once GLPI_ROOT . "/plugins/certificates/inc/profile.class.php";
    $install = false;
    $update78 = false;
    $update80 = false;
    if (!TableExists("glpi_plugin_certificates") && !TableExists("glpi_plugin_certificates_certificatetypes")) {
        $install = true;
        $DB->runFile(GLPI_ROOT . "/plugins/certificates/sql/empty-1.8.0.sql");
    } else {
        if (TableExists("glpi_plugin_certificates_mailing") && !FieldExists("glpi_plugin_certificates", "recursive")) {
            $update78 = true;
            $update80 = true;
            $DB->runFile(GLPI_ROOT . "/plugins/certificates/sql/update-1.4.sql");
            $DB->runFile(GLPI_ROOT . "/plugins/certificates/sql/update-1.5.0.sql");
            $DB->runFile(GLPI_ROOT . "/plugins/certificates/sql/update-1.5.1.sql");
            $DB->runFile(GLPI_ROOT . "/plugins/certificates/sql/update-1.6.0.sql");
        } else {
            if (TableExists("glpi_plugin_certificates_profiles") && FieldExists("glpi_plugin_certificates_profiles", "interface")) {
                $update78 = true;
                $update80 = true;
                $DB->runFile(GLPI_ROOT . "/plugins/certificates/sql/update-1.5.0.sql");
                $DB->runFile(GLPI_ROOT . "/plugins/certificates/sql/update-1.5.1.sql");
                $DB->runFile(GLPI_ROOT . "/plugins/certificates/sql/update-1.6.0.sql");
            } else {
                if (TableExists("glpi_plugin_certificates") && !FieldExists("glpi_plugin_certificates", "date_mod")) {
                    $update78 = true;
                    $update80 = true;
                    $DB->runFile(GLPI_ROOT . "/plugins/certificates/sql/update-1.5.1.sql");
                    $DB->runFile(GLPI_ROOT . "/plugins/certificates/sql/update-1.6.0.sql");
                } else {
                    if (!TableExists("glpi_plugin_certificates_certificatetypes")) {
                        $update78 = true;
                        $update80 = true;
                        $DB->runFile(GLPI_ROOT . "/plugins/certificates/sql/update-1.6.0.sql");
                    }
                }
            }
        }
    }
    //from 1.6 version
    if (TableExists("glpi_plugin_certificates_certificates") && !FieldExists("glpi_plugin_certificates_certificates", "users_id_tech")) {
        $DB->runFile(GLPI_ROOT . "/plugins/certificates/sql/update-1.8.0.sql");
    }
    if ($install || $update78) {
        //Do One time on 0.78
        $query_id = "SELECT `id` FROM `glpi_notificationtemplates` WHERE `itemtype`='PluginCertificatesCertificate' AND `name` = 'Alert Certificates'";
        $result = $DB->query($query_id) or die($DB->error());
        $itemtype = $DB->result($result, 0, 'id');
        $query = "INSERT INTO `glpi_notificationtemplatetranslations`\n                                 VALUES(NULL, " . $itemtype . ", '','##certificate.action## : ##certificate.entity##',\n                        '##lang.certificate.entity## :##certificate.entity##\n   ##FOREACHcertificates##\n   ##lang.certificate.name## : ##certificate.name## - ##lang.certificate.dateexpiration## : ##certificate.dateexpiration##\n   ##ENDFOREACHcertificates##',\n                        '<p>##lang.certificate.entity## :##certificate.entity##<br /> <br />\n                        ##FOREACHcertificates##<br />\n                        ##lang.certificate.name##  : ##certificate.name## - ##lang.certificate.dateexpiration## :  ##certificate.dateexpiration##<br /> \n                        ##ENDFOREACHcertificates##</p>');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'Alert Expired Certificates', 0, 'PluginCertificatesCertificate', 'ExpiredCertificates',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-02-17 22:36:46');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'Alert Certificates Which Expire', 0, 'PluginCertificatesCertificate', 'CertificatesWhichExpire',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-02-17 22:36:46');";
        $result = $DB->query($query);
    }
    if ($update78) {
        $query_ = "SELECT *\n            FROM `glpi_plugin_certificates_profiles` ";
        $result_ = $DB->query($query_);
        if ($DB->numrows($result_) > 0) {
            while ($data = $DB->fetch_array($result_)) {
                $query = "UPDATE `glpi_plugin_certificates_profiles`\n                  SET `profiles_id` = '" . $data["id"] . "'\n                  WHERE `id` = '" . $data["id"] . "';";
                $result = $DB->query($query);
            }
        }
        $query = "ALTER TABLE `glpi_plugin_certificates_profiles`\n               DROP `name` ;";
        $result = $DB->query($query);
        Plugin::migrateItemType(array(1700 => 'PluginCertificatesCertificate'), array("glpi_bookmarks", "glpi_bookmarks_users", "glpi_displaypreferences", "glpi_documents_items", "glpi_infocoms", "glpi_logs", "glpi_tickets"), array("glpi_plugin_certificates_certificates_items"));
        Plugin::migrateItemType(array(1200 => "PluginAppliancesAppliance", 1300 => "PluginWebapplicationsWebapplication"), array("glpi_plugin_certificates_certificates_items"));
    }
    CronTask::Register('PluginCertificatesCertificate', 'CertificatesAlert', DAY_TIMESTAMP);
    PluginCertificatesProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']);
    return true;
}
Ejemplo n.º 2
0
function plugin_certificates_uninstall() {
   global $DB;
   
   include_once (GLPI_ROOT."/plugins/certificates/inc/profile.class.php");
   include_once (GLPI_ROOT."/plugins/certificates/inc/menu.class.php");
   
   $tables = array("glpi_plugin_certificates_certificates",
               "glpi_plugin_certificates_certificates_items",
               "glpi_plugin_certificates_certificatetypes",
               "glpi_plugin_certificates_certificatestates",
               "glpi_plugin_certificates_configs",
               "glpi_plugin_certificates_notificationstates");

   foreach($tables as $table)
      $DB->query("DROP TABLE IF EXISTS `$table`;");
   
   //old versions	
   $tables = array("glpi_plugin_certificates",
               "glpi_plugin_certificates_profiles",
               "glpi_plugin_certificates_device",
               "glpi_dropdown_plugin_certificates_type",
               "glpi_dropdown_plugin_certificates_status",
               "glpi_plugin_certificates_config",
               "glpi_plugin_certificates_mailing",
               "glpi_plugin_certificates_default");

   foreach($tables as $table)
      $DB->query("DROP TABLE IF EXISTS `$table`;");
   
   $notif = new Notification();
   $options = array('itemtype' => 'PluginCertificatesCertificate',
                    'event'    => 'ExpiredCertificates',
                    'FIELDS'   => 'id');
   foreach ($DB->request('glpi_notifications', $options) as $data) {
      $notif->delete($data);
   }
   $options = array('itemtype' => 'PluginCertificatesCertificate',
                    'event'    => 'CertificatesWhichExpire',
                    'FIELDS'   => 'id');
   foreach ($DB->request('glpi_notifications', $options) as $data) {
      $notif->delete($data);
   }
   
   //templates
   $template = new NotificationTemplate();
   $translation = new NotificationTemplateTranslation();
   $options = array('itemtype' => 'PluginCertificatesCertificate',
                    'FIELDS'   => 'id');
   foreach ($DB->request('glpi_notificationtemplates', $options) as $data) {
      $options_template = array('notificationtemplates_id' => $data['id'],
                    'FIELDS'   => 'id');
   
         foreach ($DB->request('glpi_notificationtemplatetranslations', $options_template) as $data_template) {
            $translation->delete($data_template);
         }
      $template->delete($data);
   }
   
   $tables_glpi = array("glpi_displaypreferences",
               "glpi_documents_items",
               "glpi_bookmarks",
               "glpi_logs",
               "glpi_tickets",
               "glpi_contracts_items",
               "glpi_notepads");

   foreach($tables_glpi as $table_glpi)
      $DB->query("DELETE FROM `$table_glpi` WHERE `itemtype` = 'PluginCertificatesCertificate';");
      
   //Delete rights associated with the plugin
   $profileRight = new ProfileRight();
   foreach (PluginCertificatesProfile::getAllRights() as $right) {
      $profileRight->deleteByCriteria(array('name' => $right['field']));
   }
   PluginCertificatesMenu::removeRightsFromSession();
   
   PluginCertificatesProfile::removeRightsFromSession();

   return true;
}
Ejemplo n.º 3
0
Copyright (C) 2003-2011 by the certificates Development Team.

https://forge.indepnet.net/projects/certificates
-------------------------------------------------------------------------

LICENSE
		
This file is part of certificates.

Certificates is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

Certificates is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Certificates. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
include '../../../inc/includes.php';
Session::checkRight("profile", "r");
$prof = new PluginCertificatesProfile();
//Save profile
if (isset($_POST['update'])) {
    $prof->update($_POST);
    Html::back();
}