Skip to content
Snippets Groups Projects
Select Git revision
  • f93ecd2ca1262c91cee00eb611a9785ceb2e2d0b
  • master default protected
  • 7771-harden-postgres-backup
  • pgsql-dump-with-snapshots
  • update-colors
  • update-docs-css
  • usb-repair-stick
  • desktop-notification
  • 7000-corrections
  • db-detector
10 results

localdump.sh.banner

Blame
  • rollout_awx.php 4.90 KiB
    <?php
    
    /**
     * 
     * Rollout plugin - awx
     * 
     * Run an Https POST request to AWX
     *
     * @author axel
     */
    class rollout_awx extends rollout_base {
    
        /**
         * check requirements if the plugin could work
         */
        public function checkRequirements() {
            // no specific checks needed ... always true
            return true;
        }
    
        /**
         * make an http get request and return the response body
         * it is called by _makeRequest
         * $aRequest contains subkeys
         * - url
         * - method; one of GET|POST|PUT|DELETE
         * - postdata; for POST only
         * 
         * @param array   $aRequest   arrayurl for Foreman API
         * @return string
         */
        protected function _httpRequest($aRequest=false, $iTimeout = 5) {
    
            if (!function_exists("curl_init")) {
                die("ERROR: PHP CURL module is not installed.");
            }
            $aConfig=$this->getConfig();
            
            
            $ch = curl_init($aConfig['url'].$aRequest['url']);
    
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $aRequest['method']);
            if ($this->_aRequest['method']==='POST'){
                curl_setopt($ch, CURLOPT_POSTFIELDS, $aRequest['postdata']);
            }
    
            if ($aConfig['user']){
                curl_setopt($ch, CURLOPT_USERPWD, $aConfig['user'].':'.$aConfig['password']);
            }
    
            if (isset($aConfig['ignore-ssl-error']) && $aConfig['ignore-ssl-error']){
                curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
            }
            
            curl_setopt($ch, CURLOPT_TIMEOUT, $iTimeout);
            curl_setopt($ch, CURLOPT_USERAGENT, 'IML Deployment :: rollout plugin awx ' . __CLASS__);
            curl_setopt($ch, CURLOPT_HEADER,1);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    
            $res = curl_exec($ch);
            
            $aReturn=array('info'=>curl_getinfo($ch), 'error'=>curl_error($ch));
            curl_close($ch);
            
            $sHeader=substr($res, 0, $aReturn['info']['header_size']);
            $aReturn['header']=explode("\n", $sHeader);
            $aReturn['body']=str_replace($sHeader, "", $res);
    
            // print_r($aReturn);