Changeset 4178

Show
Ignore:
Timestamp:
09/22/06 15:01:31 (2 years ago)
Author:
bergie
Message:

Now uploading to different SGs works properly, but requires you to set "MidgardUsername?" and "MidgardPassword?" in conf.d file

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/support/Role_Midgardelement/Midgardelement.php

    r4164 r4178  
    6666            } 
    6767             
     68            if (method_exists($new_style, 'setsitegroup')) 
     69            { 
     70                $new_style->setsitegroup($this->sitegroup); 
     71            } 
     72             
    6873            return $new_style; 
    6974        } 
     
    9297        PEAR::raiseError("Failed to load Midgard sitegroup \"{$sitegroup_config}\". Error: " . mgd_errstr(), mgd_errno(), PEAR_ERROR_DIE); 
    9398        return false; 
     99    } 
     100     
     101    function initializeMidgard($init_file) 
     102    { 
     103        mgd_config_init($init_file); 
     104        if (!isset($_MIDGARD)) 
     105        { 
     106            PEAR::raiseError("Failed to initialize Midgard using configuration file \"{$init_file}\".", mgd_errno(), PEAR_ERROR_DIE); 
     107            return false; 
     108        } 
     109         
     110        if ($this->config->get('midgard_sitegroup') != 'root') 
     111        { 
     112            // We have to dig up the init file to read the MidgardUsername and MidgardPassword properties 
     113            switch ($_MIDGARD['config']['prefix']) 
     114            { 
     115                case '/usr': 
     116                case '/usr/local': 
     117                    $midgard_path = '/etc/midgard'; 
     118                    break; 
     119                 
     120                default: 
     121                    $midgard_path = "{$_MIDGARD['config']['prefix']}/etc/midgard"; 
     122                    break; 
     123            } 
     124             
     125            $init_file_path =  "{$midgard_path}/conf.d/{$init_file}"; 
     126            if (!file_exists($init_file_path)) 
     127            { 
     128                PEAR::raiseError("Midgard configuration file \"{$init_file_path}\" not found.", mgd_errno(), PEAR_ERROR_DIE); 
     129                return false; 
     130            } 
     131            $midgard_username = null; 
     132            $midgard_password = null; 
     133             
     134            $lines = explode("\n", file_get_contents($init_file_path)); 
     135            foreach ($lines as $line) 
     136            { 
     137                if (substr($line, 0, 1) == '#') 
     138                { 
     139                    // This is a comment line, skip 
     140                    continue; 
     141                } 
     142             
     143                $parts = explode('=', $line); 
     144                if (count($parts) != 2) 
     145                { 
     146                    // This is not valid config field, skip 
     147                    continue; 
     148                } 
     149                 
     150                switch ($parts[0]) 
     151                { 
     152                    case 'MidgardUsername': 
     153                        $midgard_username = $parts[1]; 
     154                        break; 
     155 
     156                    case 'MidgardPassword': 
     157                        $midgard_password = $parts[1]; 
     158                        break; 
     159                } 
     160            } 
     161             
     162            if (   is_null($midgard_username) 
     163                || is_null($midgard_password)) 
     164            { 
     165                PEAR::raiseError("Midgard configuration file \"{$init_file}\" did not contain MidgardUsername and MidgardPassword directives.", mgd_errno(), PEAR_ERROR_DIE); 
     166                return false; 
     167            } 
     168             
     169            if (!mgd_auth_midgard($midgard_username, $midgard_password)) 
     170            { 
     171                PEAR::raiseError("Failed to authenticate as Midgard user \"{$midgard_username}\" using credentials from configuration file \"{$init_file}\".", mgd_errno(), PEAR_ERROR_DIE); 
     172                return false; 
     173            } 
     174             
     175            return true; 
     176        } 
    94177    } 
    95178 
     
    114197        // $style_name = $pkg->getPackage(); 
    115198        $init_file = basename($installing_paths[0]); 
    116         mgd_config_init($init_file); 
    117         if (!isset($_MIDGARD)) 
    118         { 
    119             PEAR::raiseError("Failed to initialize Midgard using configuration file \"{$init_file}\".", mgd_errno(), PEAR_ERROR_DIE); 
    120         } 
     199        $this->initializeMidgard($init_file); 
    121200         
    122201        $element_name = str_replace('.php', '', basename($file)); 
     
    173252                $element = new midgard_element(); 
    174253                $element->get_by_id($new_element->id); 
     254                 
     255                if (method_exists($element, 'setsitegroup')) 
     256                { 
     257                    $element->setsitegroup($this->sitegroup); 
     258                } 
    175259            } 
    176260            else 
  • trunk/support/Role_Midgardelement/package.xml

    r4164 r4178  
    1919        <active>yes</active> 
    2020    </developer> 
    21     <date>2006-09-21</date> 
     21    <date>2006-09-22</date> 
    2222    <time>20:55:14</time> 
    2323    <version> 
    24         <release>1.1.0</release> 
     24        <release>1.1.1</release> 
    2525        <api>1.0.0</api> 
    2626    </version> 
     
    3030    </stability> 
    3131    <license uri="http://www.php.net/license/3_01.txt">PHP License</license> 
    32     <notes>Added support for substyles and uploading styles to specific sitegroups</notes> 
     32    <notes> 
     33        Fixes to authentication when uploading to sitegroups. 
     34    </notes> 
    3335    <contents> 
    3436        <dir name="/">