Skip to content
Snippets Groups Projects
Select Git revision
  • cfa03133e23b8fef31e5f83ccebbba021f89e1d2
  • master default protected
  • simple-task/7248-eol-check-add-node-22
  • 6877_check_iml_deployment
4 results

check_haproxy_health

Blame
  • redirect.admin.class.php 6.80 KiB
    <?php
    require_once 'redirect.class.php';
    /**
     * ----------------------------------------------------------------------
     *   _____ __  __ _        _____          _ _               _   
     *  |_   _|  \/  | |      |  __ \        | (_)             | |  
     *    | | | \  / | |      | |__) |___  __| |_ _ __ ___  ___| |_ 
     *    | | | |\/| | |      |  _  // _ \/ _` | | '__/ _ \/ __| __|
     *   _| |_| |  | | |____  | | \ \  __/ (_| | | | |  __/ (__| |_ 
     *  |_____|_|  |_|______| |_|  \_\___|\__,_|_|_|  \___|\___|\__|
     *
     * ----------------------------------------------------------------------
     * Loads a config json from outside webroot and makes a 3xx redirect
     * if the definition exists
     * ----------------------------------------------------------------------
     * 2020-05-11  v1.4  ah  rewrite as class
     * 2022-02-03  v1.5  ah  add method isEnabled
     * 2022-05-23  v1.6  ah  add http head check+render output; 
     * 2022-05-31  v1.7  ah  optical changes
     */
    
    /**
     * Description of redirect
     *
     * @author axel
     */
    class redirectadmin extends redirect {
    
        protected function _getCurlOptions(){
            $aReturn=array(
                CURLOPT_HEADER => true,
                CURLOPT_FOLLOWLOCATION => true,
                CURLOPT_RETURNTRANSFER => true,
                CURLOPT_USERAGENT => strip_tags($this->sAbout),
                CURLOPT_VERBOSE => false,
                CURLOPT_ENCODING => 'gzip, deflate',  // to fetch encoding
                CURLOPT_HTTPHEADER => array(
                    'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
                    'Accept-Language: en',
                    'DNT: 1',
                ),
    
                // TODO: this is unsafe .. better: let the user configure it
                CURLOPT_SSL_VERIFYHOST => false,
                CURLOPT_SSL_VERIFYPEER => false,
                CURLOPT_TIMEOUT => 5,
            );
            return $aReturn;
        }
    
        /**
         * make a single http(s) get request and return the response body
         * @param string   $url          url to fetch
         * @param boolean  $bHeaderOnly  optional: true=make HEAD request; default: false (=GET)
         * @return string
         */
        public function httpGet($url, $bHeaderOnly = false) {
            $ch = curl_init($url);
            foreach ($this->_getCurlOptions() as $sCurlOption=>$sCurlValue){
                curl_setopt($ch, $sCurlOption, $sCurlValue);
            }
            if ($bHeaderOnly) {
                curl_setopt($ch, CURLOPT_HEADER, 1);
                curl_setopt($ch, CURLOPT_NOBODY, 1);
            }
            $res = curl_exec($ch);
            curl_close($ch);
            return ($res);
        }