コード例 #1
0
ファイル: Agent.controller.php プロジェクト: glial/pmacontrol
 function stop($param)
 {
     $id_daemon = $param[0];
     $id_daemon = 1;
     $db = $this->di['db']->sql(DB_DEFAULT);
     $this->view = false;
     $this->layout_name = false;
     $sql = "SELECT * FROM daemon_main where id ='" . $id_daemon . "'";
     $res = $db->sql_query($sql);
     if ($db->sql_num_rows($res) !== 1) {
         $msg = I18n::getTranslation(__("Impossible to find the daemon with the id : ") . "'" . $id_daemon . "'");
         $title = I18n::getTranslation(__("Error"));
         set_flash("error", $title, $msg);
         header("location: " . LINK . $this->url);
         exit;
     }
     $ob = $db->sql_fetch_object($res);
     if ($this->isRunning($ob->pid)) {
         $msg = I18n::getTranslation(__("The daemon with pid : '" . $ob->pid . "' successfully stopped "));
         $title = I18n::getTranslation(__("Success"));
         set_flash("success", $title, $msg);
         $cmd = "kill " . $ob->pid;
         shell_exec($cmd);
         //shell_exec("echo '[" . date("Y-m-d H:i:s") . "] DAEMON STOPPED !' >> " . $ob->log_file);
         $this->logger->info(Color::getColoredString('Stopped daemon with the pid : ' . $ob->pid, "white", "red"));
     } else {
         if (!empty($pid)) {
             $this->logger->info(Color::getColoredString('Impossible to find the daemon with the pid : ' . $pid, "yellow"));
         }
         $msg = I18n::getTranslation(__("Impossible to find the daemon with the pid : ") . "'" . $ob->pid . "'");
         $title = I18n::getTranslation(__("Daemon was already stopped or in error"));
         set_flash("caution", $title, $msg);
     }
     sleep(1);
     if (!$this->isRunning($ob->pid)) {
         $sql = "UPDATE daemon_main SET pid ='0' WHERE id = '" . $id_daemon . "'";
         $db->sql_query($sql);
     } else {
         $this->logger->info(Color::getColoredString('Impossible to stop daemon with pid : ' . $pid, "white", "red"));
         throw new Exception('PMACTRL-876 : Impossible to stop daemon with pid : "' . $ob->pid . '"');
     }
     header("location: " . LINK . $this->url);
 }
コード例 #2
0
 function stop($param)
 {
     $id_cleaner = $param[0];
     $db = $this->di['db']->sql(DB_DEFAULT);
     $this->view = false;
     $this->layout_name = false;
     $sql = "SELECT * FROM cleaner_main where id ='" . $id_cleaner . "'";
     $res = $db->sql_query($sql);
     if ($db->sql_num_rows($res) !== 1) {
         $msg = I18n::getTranslation(__("Impossible to find the cleaner with the id : ") . "'" . $id_cleaner . "'");
         $title = I18n::getTranslation(__("Error"));
         set_flash("error", $title, $msg);
         header("location: " . LINK . "cleaner/index");
         exit;
     }
     $ob = $db->sql_fetch_object($res);
     if ($this->isRunning($ob->pid)) {
         $msg = I18n::getTranslation(__("The cleaner with pid : '" . $ob->pid . "' successfully stopped "));
         $title = I18n::getTranslation(__("Success"));
         set_flash("success", $title, $msg);
         $cmd = "kill " . $ob->pid;
         shell_exec($cmd);
         shell_exec("echo '[" . date("Y-m-d H:i:s") . "] CLEANER STOPED !' >> " . $ob->log_file);
     } else {
         $msg = I18n::getTranslation(__("Impossible to find the cleaner with the pid : ") . "'" . $ob->pid . "'");
         $title = I18n::getTranslation(__("Cleaner was already stopped or in error"));
         set_flash("caution", $title, $msg);
     }
     sleep(1);
     if (!$this->isRunning($ob->pid)) {
         $sql = "UPDATE cleaner_main SET pid ='0' WHERE id = '" . $id_cleaner . "'";
         $db->sql_query($sql);
     } else {
         throw new Exception('PMACTRL-875 : Impossible to stop cleaner with pid : "' . $ob->pid . '"');
     }
     header("location: " . LINK . "cleaner/index");
 }
コード例 #3
0
ファイル: Auth.php プロジェクト: glial/glial
 public function authenticate($check_post = true)
 {
     if ($_SERVER['REQUEST_METHOD'] == "POST" && $check_post) {
         if (empty($_POST[self::$_tableName][self::$_login])) {
             return false;
         }
         if (empty($_POST[self::$_tableName][self::$_passwd])) {
             return false;
         }
         if (empty($_POST[self::$_tableName][self::$_login]) || empty($_POST[self::$_tableName][self::$_passwd])) {
             return true;
         }
         $Identity = self::$_dbLink->sql_real_escape_string($_POST[self::$_tableName][self::$_login]);
         $Credential = self::$_dbLink->sql_real_escape_string($_POST[self::$_tableName][self::$_passwd]);
         $hash_password = $this->hash_password($Identity, $Credential);
         if (LDAP_CHECK) {
             if ($ldap = $this->checkLdap($Identity, $Credential)) {
                 $sql = "select * from " . self::$_tableName . " where " . self::$_login . " = '" . $Identity . "'";
                 $res = self::$_dbLink->sql_query($sql);
                 $data = array();
                 if (self::$_dbLink->sql_num_rows($res) === 1) {
                     $ob = self::$_dbLink->sql_fetch_object($res);
                     $this->_user = $ob;
                     $data[self::$_tableName]['id'] = $ob->id;
                     $data[self::$_tableName][self::$_passwd] = $hash_password;
                     $data[self::$_tableName]['date_last_login'] = date('Y-m-d H:i:s');
                     $data[self::$_tableName]['date_last_connected'] = date('Y-m-d H:i:s');
                 } elseif (self::$_dbLink->sql_num_rows($res) === 0) {
                     $data[self::$_tableName]['date_last_login'] = date('Y-m-d H:i:s');
                     $data[self::$_tableName]['date_last_connected'] = date('Y-m-d H:i:s');
                     $data[self::$_tableName][self::$_passwd] = $hash_password;
                     $data[self::$_tableName][self::$_login] = $ldap['samaccountname'][0];
                     $data[self::$_tableName]['email'] = $ldap['mail'][0];
                     $data[self::$_tableName]['name'] = strtoupper($ldap['sn'][0]);
                     $data[self::$_tableName]['firstname'] = $ldap['givenname'][0];
                     $data[self::$_tableName]['ip'] = $_SERVER["REMOTE_ADDR"];
                     $data[self::$_tableName]['date_created'] = substr($ldap['whencreated'][0], 0, 4) . "-" . substr($ldap['whencreated'][0], 4, 2) . "-" . substr($ldap['whencreated'][0], 6, 2) . " " . substr($ldap['whencreated'][0], 8, 2) . ":" . substr($ldap['whencreated'][0], 10, 2) . ":" . substr($ldap['whencreated'][0], 12, 2);
                     $data[self::$_tableName]['id_group'] = 2;
                     $data[self::$_tableName]['is_valid'] = 0;
                 } else {
                     throw new \Exception('GLI-999 : Whilte list failed');
                 }
                 if (!self::$_dbLink->sql_save($data)) {
                     debug($data);
                     debug(self::$_dbLink->sql_error());
                     die;
                 }
                 $sql = "select * from " . self::$_tableName . " where " . self::$_login . " = '" . self::$_dbLink->sql_real_escape_string($ldap['samaccountname'][0]) . "'";
                 $res = self::$_dbLink->sql_query($sql);
                 $ob = self::$_dbLink->sql_fetch_object($res);
                 $this->_user = $ob;
                 $this->id_user = $ob->id;
                 setcookie(self::$_name_cookie_login, $ob->{self::$_login}, time() + AUTH_SESSION_TIME, '/', $_SERVER['SERVER_NAME'], false, true);
                 setcookie(self::$_name_cookie_passwd, $hash_password, time() + AUTH_SESSION_TIME, '/', $_SERVER['SERVER_NAME'], false, true);
                 return true;
             }
             return false;
         } else {
             $sql = "select * from " . self::$_tableName . " where " . self::$_login . " = '" . $Identity . "'";
             $res = self::$_dbLink->sql_query($sql);
             if (self::$_dbLink->sql_num_rows($res) === 1) {
                 $ob = self::$_dbLink->sql_fetch_object($res);
                 $this->id_user = $ob->id;
                 if ($hash_password === $ob->{self::$_passwd}) {
                     $this->_user = $ob;
                     setcookie(self::$_name_cookie_login, $ob->{self::$_login}, time() + AUTH_SESSION_TIME, '/', $_SERVER['SERVER_NAME'], false, true);
                     setcookie(self::$_name_cookie_passwd, $hash_password, time() + AUTH_SESSION_TIME, '/', $_SERVER['SERVER_NAME'], false, true);
                     return true;
                 }
             }
         }
     }
     if (empty($_POST[self::$_tableName][self::$_login])) {
         if (!empty($_COOKIE[self::$_name_cookie_login]) && !empty($_COOKIE[self::$_name_cookie_passwd])) {
             $sql = "select * from " . self::$_tableName . " where " . self::$_login . " = '" . self::$_dbLink->sql_real_escape_string($_COOKIE[self::$_name_cookie_login]) . "'";
             $res = self::$_dbLink->sql_query($sql);
             if (self::$_dbLink->sql_num_rows($res) === 1) {
                 $ob = self::$_dbLink->sql_fetch_object($res);
                 if ($_COOKIE[self::$_name_cookie_passwd] === $ob->{self::$_passwd}) {
                     //if (password_verify($ob->{self::$_passwd}, $_COOKIE[self::$_name_cookie_passwd]) ) {
                     $this->_user = $ob;
                     if ($ob->is_valid == 0) {
                         if ($_SERVER['REQUEST_METHOD'] === "GET") {
                             $msg = I18n::getTranslation(__("Hello,") . "<br />" . __("Thank you for registering.") . "<br />" . __("To finalise your registration, an administrator have to give you a role."));
                             $title = I18n::getTranslation(__("Restricted access"));
                             set_flash("caution", $title, $msg);
                         }
                     }
                     return true;
                 }
             }
         }
     }
     return false;
 }
コード例 #4
0
 function index($params)
 {
     /*
      * SHOW TABLES
      * SHOW COLUMNS FROM table_name
      *
      */
     $this->layout_name = 'pmacontrol';
     $db = $this->di['db']->sql(DB_DEFAULT);
     $this->db_default = $db;
     $this->title = __("Compare");
     $this->ariane = "> " . '<a href="' . LINK . 'Plugins/index/">' . __('Plugins') . "</a> > " . $this->title;
     $redirect = false;
     if ($_SERVER['REQUEST_METHOD'] == "POST") {
         $id_server1 = empty($_POST['compare_main']['id_mysql_server__original']) ? "" : $_POST['compare_main']['id_mysql_server__original'];
         $id_server2 = empty($_POST['compare_main']['id_mysql_server__compare']) ? "" : $_POST['compare_main']['id_mysql_server__compare'];
         $db1 = empty($_POST['compare_main']['database__original']) ? "" : $_POST['compare_main']['database__original'];
         $db2 = empty($_POST['compare_main']['database__compare']) ? "" : $_POST['compare_main']['database__compare'];
         $out = $this->checkConfig($id_server1, $db1, $id_server2, $db2);
         if ($out !== true) {
             $extra = "";
             foreach ($out as $msg) {
                 $extra .= "<br />" . __($msg);
             }
             $msg = I18n::getTranslation(__("Please correct your paramaters !") . $extra);
             $title = I18n::getTranslation(__("Error"));
             set_flash("error", $title, $msg);
             $redirect = true;
         }
         header('location: ' . LINK . 'compare/index/compare_main:id_mysql_server__original:' . $id_server1 . '/compare_main:' . 'id_mysql_server__compare:' . $id_server2 . '/compare_main:' . 'database__original:' . $db1 . '/compare_main:' . 'database__compare:' . $db2);
     }
     $this->di['js']->addJavascript(array("jquery-latest.min.js", "jquery.browser.min.js", "jquery.autocomplete.min.js", "compare/index.js"));
     $sql = "SELECT * FROM mysql_server WHERE `error` = '' order by `name`";
     $servers = $db->sql_fetch_yield($sql);
     $data['server'] = [];
     foreach ($servers as $server) {
         $tmp = [];
         $tmp['id'] = $server['id'];
         $tmp['libelle'] = str_replace('_', '-', $server['name']) . " (" . $server['ip'] . ")";
         $data['server'][] = $tmp;
     }
     $data['listdb1'] = array();
     if (!empty($_GET['compare_main']['id_mysql_server__original'])) {
         $select1 = $this->getDatabaseByServer(array($_GET['compare_main']['id_mysql_server__original']));
         $data['listdb1'] = $select1['databases'];
     }
     $data['listdb2'] = array();
     if (!empty($_GET['compare_main']['id_mysql_server__compare'])) {
         $select1 = $this->getDatabaseByServer(array($_GET['compare_main']['id_mysql_server__compare']));
         $data['listdb2'] = $select1['databases'];
     }
     $data['display'] = false;
     if (count($data['listdb2']) != 0 && count($data['listdb1']) != 0) {
         if (!empty($_GET['compare_main']['database__original']) && !empty($_GET['compare_main']['database__compare'])) {
             $data['resultat'] = $this->analyse($_GET['compare_main']['id_mysql_server__original'], $_GET['compare_main']['database__original'], $_GET['compare_main']['id_mysql_server__compare'], $_GET['compare_main']['database__compare']);
             $data['display'] = true;
             //log
             $this->di['log']->warning('[Compare] ' . $_GET['compare_main']['id_mysql_server__original'] . ":" . $_GET['compare_main']['database__original'] . " vs " . $_GET['compare_main']['id_mysql_server__compare'] . ":" . $_GET['compare_main']['database__compare'] . "(" . $_SERVER["REMOTE_ADDR"] . ")");
         }
     }
     $this->set('data', $data);
 }
コード例 #5
0
ファイル: Controller.php プロジェクト: glial/glial
 final function setLayout()
 {
     Variable::$_open = false;
     if (!IS_CLI) {
         global $_SITE;
         $GLIALE_CONTENT = $this->html;
         $GLIALE_TITLE = $this->title;
         $GLIALE_ARIANE = $this->ariane;
         ob_implicit_flush(false);
         ob_start();
         Variable::$_open = true;
         include APP_DIR . DS . "layout" . DS . $this->layout_name . ".layout.php";
         if (!$this->ajax) {
             //echo $this->js;
             echo $this->di['js']->getJavascript();
             //echo $this->js;
         }
         echo "</html>\n";
         //TODO a mettre ailleurs
         Variable::$_html = ob_get_clean();
         Variable::$_html = I18n::getTranslation(Variable::$_html);
         echo Variable::$_html;
     }
 }
コード例 #6
0
    public function add()
    {
        //df -Ph . | tail -1 | awk '{print $2}' => to know space
        $db = $this->di['db']->sql(DB_DEFAULT);
        if ($_SERVER['REQUEST_METHOD'] == "POST") {
            Crypt::$key = CRYPT_KEY;
            $storage_area['backup_storage_area'] = $_POST['backup_storage_area'];
            if (!Ssh::testAccount($storage_area['backup_storage_area']['ip'], $storage_area['backup_storage_area']['port'], $storage_area['backup_storage_area']['ssh_login'], $storage_area['backup_storage_area']['ssh_password'])) {
                foreach ($_POST['backup_storage_area'] as $var => $val) {
                    $ret[] = "backup_storage_area:" . $var . ":" . urlencode(html_entity_decode($val));
                }
                $param = implode("/", $ret);
                $title = I18n::getTranslation(__("Failed to connect on ssh/scp/sFtp"));
                $msg = I18n::getTranslation(__("Please check your hostname and you credentials !"));
                set_flash("error", $title, $msg);
                header("location: " . LINK . "backup/storageArea/add/" . $param);
                exit;
            }
            $storage_area['backup_storage_area']['ssh_login'] = Crypt::encrypt($storage_area['backup_storage_area']['ssh_login']);
            $storage_area['backup_storage_area']['ssh_password'] = Crypt::encrypt($storage_area['backup_storage_area']['ssh_password']);
            if (!($id_storage_area = $db->sql_save($storage_area))) {
                $error = $db->sql_error();
                $_SESSION['ERROR'] = $error;
                $title = I18n::getTranslation(__("Fail to add this storage area"));
                $msg = I18n::getTranslation(__("One or more problem came when you try to add this storage, please verify your informations"));
                set_flash("error", $title, $msg);
                foreach ($_POST['backup_storage_area'] as $var => $val) {
                    $ret[] = "backup_storage_area:" . $var . ":" . urlencode(html_entity_decode($val));
                }
                $param = implode("/", $ret);
                header("location: " . LINK . "backup/storageArea/add/" . $param);
                exit;
            } else {
                $this->getStorageSpace(array($id_storage_area));
                $title = I18n::getTranslation(__("Successfull"));
                $msg = I18n::getTranslation(__("You storage area has been successfull added !"));
                set_flash("success", $title, $msg);
            }
        }
        $this->di['js']->addJavascript(array("http://www.estrildidae.net/js/jquery.1.3.2.js", "jquery.autocomplete.min.js"));
        //$this->di['js']->addJavascript(array("jquery-latest.min.js", "jquery.autocomplete.min.js"));
        $this->di['js']->code_javascript('$("#backup_storage_area-id_geolocalisation_city-auto").autocomplete("' . LINK . 'user/city/ajax>yes", {
		extraParams: {
			country: function() {return $("#backup_storage_area-id_geolocalisation_country").val();}
		},
        mustMatch: true,
        autoFill: true,
        max: 100,
        scrollHeight: 302,
        delay:0
		});
		$("#backup_storage_area-id_geolocalisation_city-auto").result(function(event, data, formatted) {
			if (data)
				$("#backup_storage_area-id_geolocalisation_city").val(data[1]);
		});
		$("#backup_storage_area-id_geolocalisation_country").change( function() 
		{
			$("#backup_storage_area-id_geolocalisation_city-auto").val("");
			$("#backup_storage_area-id_geolocalisation_city").val("");
		} );

		');
        $sql = "SELECT id, libelle from geolocalisation_country where libelle != '' order by libelle asc";
        $res = $db->sql_query($sql);
        $this->data['geolocalisation_country'] = $db->sql_to_array($res);
        $this->set('data', $this->data);
    }