Beispiel #1
0
 /**
  * Try to get the root credentials from a variety of locations
  *
  * @return  mixed  Array of creds or false on failure
  **/
 private function getRootCredentials()
 {
     $secrets = DS . 'etc' . DS . 'hubzero.secrets';
     $conf_file = DS . 'root' . DS . '.my.cnf';
     $hub_maint = DS . 'etc' . DS . 'mysql' . DS . 'hubmaint.cnf';
     $deb_maint = DS . 'etc' . DS . 'mysql' . DS . 'debian.cnf';
     if (is_file($secrets) && is_readable($secrets)) {
         $conf = Processor::instance('ini')->parse($secrets);
         $user = isset($conf['DEFAULT']['MYSQL-ROOT-USER']) ? $conf['DEFAULT']['MYSQL-ROOT-USER'] : '******';
         $pw = isset($conf['DEFAULT']['MYSQL-ROOT']) ? $conf['DEFAULT']['MYSQL-ROOT'] : false;
         if ($user && $pw) {
             return array('user' => $user, 'password' => $pw);
         }
     }
     if (is_file($conf_file) && is_readable($conf_file)) {
         $conf = Processor::instance('ini')->parse($conf_file, true);
         $user = isset($conf['client']['user']) ? $conf['client']['user'] : false;
         $pw = isset($conf['client']['password']) ? $conf['client']['password'] : false;
         if ($user && $pw) {
             return array('user' => $user, 'password' => $pw);
         }
     }
     if (is_file($hub_maint) && is_readable($hub_maint)) {
         $conf = Processor::instance('ini')->parse($hub_maint, true);
         $user = isset($conf['client']['user']) ? $conf['client']['user'] : false;
         $pw = isset($conf['client']['password']) ? $conf['client']['password'] : false;
         if ($user && $pw) {
             return array('user' => $user, 'password' => $pw);
         }
     }
     if (is_file($deb_maint) && is_readable($deb_maint)) {
         $conf = Processor::instance('ini')->parse($deb_maint, true);
         $user = isset($conf['client']['user']) ? $conf['client']['user'] : false;
         $pw = isset($conf['client']['password']) ? $conf['client']['password'] : false;
         if ($user && $pw) {
             return array('user' => $user, 'password' => $pw);
         }
     }
     return false;
 }
Beispiel #2
0
 /**
  * Parse a JSON formatted string and convert it into an object.
  *
  * If the string is not in JSON format, this method will attempt to parse it as INI format.
  *
  * @param   string  $data     JSON formatted string to convert.
  * @param   array   $options  Options used by the formatter.
  * @return  object  Data object.
  */
 public function stringToObject($data, $options = array('processSections' => false))
 {
     if (is_object($data)) {
         return $data;
     }
     if (is_bool($options)) {
         $options = array('processSections' => $options);
     }
     $data = trim($data);
     $data = trim($data, '"');
     if (substr($data, 0, 1) != '{' && substr($data, -1, 1) != '}') {
         $obj = Base::instance('ini')->stringToObject($data, $options);
     } else {
         $obj = json_decode($data);
     }
     return $obj;
 }
Beispiel #3
0
 /**
  * Get the processor for a specific format
  *
  * @param   string  $format  Format to return the processor for
  * @return  object
  */
 public function processor($format = 'json')
 {
     return Processor::instance($format);
 }