public function getCoords($str) { if (!is_array($str)) { $_address = preg_replace('/\\s+/', '+', $str); $_address = urlencode($_address); } else { $address = array(); $address[] = $str['d_zip']; $address[] = $str['d_address_1']; $address[] = $str['d_city']; $address[] = $str['d_state']; foreach ($address as $k => $v) { $tmp = preg_replace('/\\s+/', '+', $v); $address[$k] = $tmp; } $_address = join(",+", $address); } $api = sprintf("https://maps.googleapis.com/maps/api/geocode/json?address=%s&sensor=false", $_address); $pjHttp = new pjHttp(); $pjHttp->request($api); $response = $pjHttp->getResponse(); $geoObj = pjAppController::jsonDecode($response); $data = array(); if ($geoObj->status == 'OK') { $data['lat'] = $geoObj->results[0]->geometry->location->lat; $data['lng'] = $geoObj->results[0]->geometry->location->lng; } else { $data['lat'] = array('NULL'); $data['lng'] = array('NULL'); } return $data; }
public function pjActionSetConfig() { $this->setAjax(true); if ($this->isXHR()) { if (!self::pjActionCheckConfig(false)) { pjAppController::jsonResponse(array('code' => 107, 'text' => 'Product is already installed. If you need to re-install it empty app/config/config.inc.php file.')); } $resp = array(); $sample = 'app/config/config.sample.php'; $filename = 'app/config/config.inc.php'; ob_start(); readfile($sample); $string = ob_get_contents(); ob_end_clean(); if ($string === FALSE) { $resp['code'] = 100; $resp['text'] = "An error occurs while reading 'app/config/config.sample.php'"; } else { if (!self::pjActionCheckVars()) { pjAppController::jsonResponse(array('status' => 'ERR', 'code' => 108, 'text' => 'Missing, empty or invalid parameters.')); } $string = str_replace('[hostname]', $_SESSION[$this->defaultInstaller]['hostname'], $string); $string = str_replace('[username]', $_SESSION[$this->defaultInstaller]['username'], $string); $string = str_replace('[password]', str_replace(array('$'), array('\\$'), $_SESSION[$this->defaultInstaller]['password']), $string); $string = str_replace('[database]', $_SESSION[$this->defaultInstaller]['database'], $string); $string = str_replace('[prefix]', $_SESSION[$this->defaultInstaller]['prefix'], $string); $string = str_replace('[install_folder]', $_SESSION[$this->defaultInstaller]['install_folder'], $string); $string = str_replace('[install_path]', $_SESSION[$this->defaultInstaller]['install_path'], $string); $string = str_replace('[install_url]', $_SESSION[$this->defaultInstaller]['install_url'], $string); $string = str_replace('[salt]', pjUtil::getRandomPassword(8), $string); $Http = new pjHttp(); $Http->request(base64_decode("aHR0cDovL3N1cHBvcnQuc3RpdmFzb2Z0LmNvbS8=") . 'index.php?controller=Api&action=getInstall' . "&key=" . urlencode($_SESSION[$this->defaultInstaller]['license_key']) . "&modulo=" . urlencode(PJ_RSA_MODULO) . "&private=" . urlencode(PJ_RSA_PRIVATE) . "&server_name=" . urlencode($_SERVER['SERVER_NAME'])); $response = $Http->getResponse(); $output = unserialize($response); if (isset($output['hash']) && isset($output['code']) && $output['code'] == 200) { $string = str_replace('[pj_installation]', $output['hash'], $string); if (is_writable($filename)) { if (!($handle = @fopen($filename, 'wb'))) { $resp['code'] = 103; $resp['text'] = "'app/config/config.inc.php' open fails"; } else { if (fwrite($handle, $string) === FALSE) { $resp['code'] = 102; $resp['text'] = "An error occurs while writing to 'app/config/config.inc.php'"; } else { fclose($handle); $resp['code'] = 200; } } } else { $resp['code'] = 101; $resp['text'] = "'app/config/config.inc.php' do not exists or not writable"; } } else { $resp['code'] = 104; $resp['text'] = "Security vulnerability detected"; } } pjAppController::jsonResponse($resp); } exit; }