Skip to content
Snippets Groups Projects
Select Git revision
  • 0180cf1553b437ab6fa982e0de0d6c61c01f2701
  • master default protected
  • Legacy_Php7
3 results

actionlog.class.php

Blame
    • hahn's avatar
      0180cf15
      - project overview page: · 0180cf15
      hahn authored
        - scrolling
        - no detail button
        - smaller folder image
      - Scroll to top of page
      - delete project: red button
      - removed builld and cleanup from menu
      - Action-Log with AJAX request and form class
      0180cf15
      History
      - project overview page:
      hahn authored
        - scrolling
        - no detail button
        - smaller folder image
      - Scroll to top of page
      - delete project: red button
      - removed builld and cleanup from menu
      - Action-Log with AJAX request and form class
    actionlog.class.php 12.99 KiB
    <?php
    
    /**
     * class to log all project actions, ie. build, deploy etc.
     *
     * @author hahn
     */
    class Actionlog {
    
        private $_aLoglevels = array("info", "warning", "error", "success"); // array of valid loglevels
        private $_sIP = false;
        private $_sUser = false;
        private $_sProject = false;
        private $_sCreate = '
            CREATE TABLE "logs" (
              `id` INTEGER PRIMARY KEY  AUTOINCREMENT  NOT NULL  UNIQUE ,
              `time` DATETIME,
              `loglevel` TEXT,
              `ip` TEXT,
              `user` TEXT,
              `project` TEXT,
              `action` TEXT,
              `message` TEXT
            )';
    
        /**
         * constructor - sets internal environment variables and checks existence 
         * of the database
         * @global array $aConfig    settings
         * @param  string $sProject  project ID
         */
        public function __construct($sProject = false) {
            global $aConfig;
            if (!is_array($aConfig) || !array_key_exists("appRootDir", $aConfig)) {
                die(__CLASS__ . "::".__FUNCTION__." ERROR: configuration with \$aConfig was not loaded.");
            }
            $this->_dbfile = $aConfig['appRootDir'] . '/database/logs.db';
            if (!file_exists($this->_dbfile)) {
                $this->_createDb();
                if (!file_exists($this->_dbfile)) {
                    die("ERROR: unable to create sqlite database " . $this->_dbfile);
                }
            }
    
            $this->_sProject = $sProject;
            if (isset($_SERVER) && is_array($_SERVER) && array_key_exists("PHP_AUTH_USER", $_SERVER) && $_SERVER["PHP_AUTH_USER"]
            ) {
                $this->_sIP = $_SERVER["REMOTE_ADDR"];
                $this->_sUser = $_SERVER["PHP_AUTH_USER"] . " (web)";
            } else {
                $this->_sIP = 'local';
                $this->_sUser = get_current_user() . " (system)";
            }
        }
    
        /**
         * create sqlite database - called in constructor if the file does not exist
         */
        private function _createDb() {
            return $this->_makeQuery($this->_sCreate);
        }
    
        /**
         * execute a sql statement
         * @param string $sSql sql statement
         * @return database object
         */
        private function _makeQuery($sSql) {
            // $this->_log(__FUNCTION__."($sSql)");
            // echo "<pre>$sSql</pre>";