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

check-config.php

Blame
  • check-config.php 7.36 KiB
    <?php
    /* ######################################################################
    
      IML DEPLOYMENT
    
      CONFIG CHECKER for new setups
    
      ---------------------------------------------------------------------
      2017-12-01  Axel <axel.hahn@iml.unibe.ch>
      ###################################################################### */
    
    
    
    // ----------------------------------------------------------------------
    // functions
    // ----------------------------------------------------------------------
    
    /**
     * get html code to draw a colored box
     * @param string  $s       message
     * @param string  $sClass  css class; one of ok|info|error
     * @return string
     */
    function drawbox($s, $sClass) {
        return '<div class="box ' . $sClass . '">' . $s . '</div>';
    }
    
    /**
     * show an alert box with error message
     * @param type $s
     * @return type
     */
    function showerror($s) {
        return drawbox($s, 'error');
    }
    
    /**
     * show green box with ok message
     * @param type $s
     * @return type
     */
    function showok($s) {
        return drawbox($s, 'ok');
    }
    
    /**
     * check a directory if it exists and is writtable
     * @global array  $aErrors  found errors
     * @param string  $sDir     directory to check
     * @param string  $sKey     key in config (for output only)
     * @return boolean
     */
    function checkdir($sDir, $sKey = false) {
        global $aErrors;
    
        echo 'check directory [' . $sDir . '] ';
        if (!is_dir($sDir)) {
            echo '<span class="error">does not exist</span><br>';
            $aErrors[] = "* \$aConfig['$sKey'] points to a non existing directory (" . $sDir . ").\n";
            return false;
        } else {
            if (!is_writable($sDir)) {
                echo '<span class="error">not writable</span><br>';
                $aErrors[] = "* \$aConfig['$sKey'] = " . $sDir . " is NOT writable.\n";
                return false;
            } else {
                echo '<span class="ok">OK</span> exists and is writable<br>';
                return true;
            }
        }