| 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'; |
|---|
| | 110 | // We have to dig up the init file to read the MidgardUsername and MidgardPassword properties |
|---|
| | 111 | switch ($_MIDGARD['config']['prefix']) |
|---|
| | 112 | { |
|---|
| | 113 | case '/usr': |
|---|
| | 114 | case '/usr/local': |
|---|
| | 115 | $midgard_path = '/etc/midgard'; |
|---|
| | 116 | break; |
|---|
| | 117 | |
|---|
| | 118 | default: |
|---|
| | 119 | $midgard_path = "{$_MIDGARD['config']['prefix']}/etc/midgard"; |
|---|
| | 120 | break; |
|---|
| | 121 | } |
|---|
| | 122 | |
|---|
| | 123 | $init_file_path = "{$midgard_path}/conf.d/{$init_file}"; |
|---|
| | 124 | if (!file_exists($init_file_path)) |
|---|
| | 125 | { |
|---|
| | 126 | PEAR::raiseError("Midgard configuration file \"{$init_file_path}\" not found.", mgd_errno(), PEAR_ERROR_DIE); |
|---|
| | 127 | return false; |
|---|
| | 128 | } |
|---|
| | 129 | $midgard_username = null; |
|---|
| | 130 | $midgard_password = null; |
|---|
| | 131 | |
|---|
| | 132 | $lines = explode("\n", file_get_contents($init_file_path)); |
|---|
| | 133 | foreach ($lines as $line) |
|---|
| | 134 | { |
|---|
| | 135 | if (substr($line, 0, 1) == '#') |
|---|
| | 136 | { |
|---|
| | 137 | // This is a comment line, skip |
|---|
| | 138 | continue; |
|---|
| | 139 | } |
|---|
| | 140 | |
|---|
| | 141 | $parts = explode('=', $line); |
|---|
| | 142 | if (count($parts) != 2) |
|---|
| | 143 | { |
|---|
| | 144 | // This is not valid config field, skip |
|---|
| | 145 | continue; |
|---|
| | 146 | } |
|---|
| | 147 | |
|---|
| | 148 | switch ($parts[0]) |
|---|
| | 149 | { |
|---|
| | 150 | case 'MidgardUsername': |
|---|
| | 151 | $midgard_username = $parts[1]; |
|---|
| 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 | | } |
|---|
| | 158 | } |
|---|
| | 159 | |
|---|
| | 160 | if ( is_null($midgard_username) |
|---|
| | 161 | || is_null($midgard_password)) |
|---|
| | 162 | { |
|---|
| | 163 | PEAR::raiseError("Midgard configuration file \"{$init_file}\" did not contain MidgardUsername and MidgardPassword directives.", mgd_errno(), PEAR_ERROR_DIE); |
|---|
| | 164 | return false; |
|---|
| | 165 | } |
|---|
| | 166 | |
|---|
| | 167 | if (!mgd_auth_midgard($midgard_username, $midgard_password)) |
|---|
| | 168 | { |
|---|
| | 169 | PEAR::raiseError("Failed to authenticate as Midgard user \"{$midgard_username}\" using credentials from configuration file \"{$init_file}\".", mgd_errno(), PEAR_ERROR_DIE); |
|---|
| | 170 | return false; |
|---|
| | 171 | } |
|---|
| | 172 | |
|---|
| | 173 | return true; |
|---|