diff options
author | Jesús <heckyel@hyperbola.info> | 2019-08-18 21:14:58 -0500 |
---|---|---|
committer | Jesús <heckyel@hyperbola.info> | 2019-08-18 21:14:58 -0500 |
commit | 2eed7b082f83630301e51f57ca8394de228a8605 (patch) | |
tree | 1d19962d22d30f99317d9276e4bae7744fc93fc2 /public/install/controller | |
download | librecart-2eed7b082f83630301e51f57ca8394de228a8605.tar.lz librecart-2eed7b082f83630301e51f57ca8394de228a8605.tar.xz librecart-2eed7b082f83630301e51f57ca8394de228a8605.zip |
first commit
Diffstat (limited to 'public/install/controller')
-rw-r--r-- | public/install/controller/3rd_party/extension.php | 25 | ||||
-rw-r--r-- | public/install/controller/3rd_party/openbay.php | 26 | ||||
-rw-r--r-- | public/install/controller/common/column_left.php | 69 | ||||
-rw-r--r-- | public/install/controller/common/footer.php | 12 | ||||
-rw-r--r-- | public/install/controller/common/header.php | 16 | ||||
-rw-r--r-- | public/install/controller/error/not_found.php | 25 | ||||
-rw-r--r-- | public/install/controller/event/theme.php | 10 | ||||
-rw-r--r-- | public/install/controller/install/step_1.php | 27 | ||||
-rw-r--r-- | public/install/controller/install/step_2.php | 266 | ||||
-rw-r--r-- | public/install/controller/install/step_3.php | 316 | ||||
-rw-r--r-- | public/install/controller/install/step_4.php | 55 | ||||
-rw-r--r-- | public/install/controller/startup/database.php | 22 | ||||
-rw-r--r-- | public/install/controller/startup/language.php | 33 | ||||
-rw-r--r-- | public/install/controller/startup/router.php | 10 | ||||
-rw-r--r-- | public/install/controller/startup/upgrade.php | 20 | ||||
-rw-r--r-- | public/install/controller/upgrade/upgrade.php | 69 |
16 files changed, 1001 insertions, 0 deletions
diff --git a/public/install/controller/3rd_party/extension.php b/public/install/controller/3rd_party/extension.php new file mode 100644 index 0000000..3051971 --- /dev/null +++ b/public/install/controller/3rd_party/extension.php @@ -0,0 +1,25 @@ +<?php +class Controller3rdPartyExtension extends Controller { + public function index() { + $curl = curl_init(); + + curl_setopt($curl, CURLOPT_POST, true); + curl_setopt($curl, CURLOPT_HEADER, false); + curl_setopt($curl, CURLOPT_URL, 'https://www.opencart.com/index.php?route=extension/json/extensions'); + curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1'); + curl_setopt($curl, CURLOPT_FRESH_CONNECT, true); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); + curl_setopt($curl, CURLOPT_FORBID_REUSE, true); + curl_setopt($curl, CURLOPT_TIMEOUT, 30); + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); + curl_setopt($curl, CURLOPT_POSTFIELDS, array()); + + $response = curl_exec($curl); + + curl_close($curl); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput($response); + } +}
\ No newline at end of file diff --git a/public/install/controller/3rd_party/openbay.php b/public/install/controller/3rd_party/openbay.php new file mode 100644 index 0000000..9f3af7c --- /dev/null +++ b/public/install/controller/3rd_party/openbay.php @@ -0,0 +1,26 @@ +<?php +class Controller3rdPartyOpenbay extends Controller { + public function index() { + $this->load->language('3rd_party/openbay'); + + $this->document->setTitle($this->language->get('heading_title')); + + $data['heading_title'] = $this->language->get('heading_title'); + + $data['text_openbay'] = $this->language->get('text_openbay'); + $data['text_ebay'] = $this->language->get('text_ebay'); + $data['text_amazon'] = $this->language->get('text_amazon'); + + $data['button_register'] = $this->language->get('button_register'); + $data['button_register_eu'] = $this->language->get('button_register_eu'); + $data['button_register_us'] = $this->language->get('button_register_us'); + $data['button_back'] = $this->language->get('button_back'); + + $data['back'] = $this->url->link('install/step_4'); + + $data['footer'] = $this->load->controller('common/footer'); + $data['header'] = $this->load->controller('common/header'); + + $this->response->setOutput($this->load->view('3rd_party/openbay', $data)); + } +}
\ No newline at end of file diff --git a/public/install/controller/common/column_left.php b/public/install/controller/common/column_left.php new file mode 100644 index 0000000..21c662d --- /dev/null +++ b/public/install/controller/common/column_left.php @@ -0,0 +1,69 @@ +<?php +class ControllerCommonColumnLeft extends Controller { + public function index() { + $this->load->language('common/column_left'); + + // Step + $data['text_license'] = $this->language->get('text_license'); + $data['text_installation'] = $this->language->get('text_installation'); + $data['text_configuration'] = $this->language->get('text_configuration'); + $data['text_upgrade'] = $this->language->get('text_upgrade'); + $data['text_finished'] = $this->language->get('text_finished'); + $data['text_language'] = $this->language->get('text_language'); + + if (isset($this->request->get['route'])) { + $data['route'] = $this->request->get['route']; + } else { + $data['route'] = 'install/step_1'; + } + + // Language + $data['action'] = $this->url->link('common/column_left/language', '', $this->request->server['HTTPS']); + + if (isset($this->session->data['language'])) { + $data['code'] = $this->session->data['language']; + } else { + $data['code'] = $this->config->get('language.default'); + } + + $data['languages'] = array(); + + $languages = glob(DIR_LANGUAGE . '*', GLOB_ONLYDIR); + + foreach ($languages as $language) { + $data['languages'][] = basename($language); + } + + if (!isset($this->request->get['route'])) { + $data['redirect'] = $this->url->link('install/step_1'); + } else { + $url_data = $this->request->get; + + $route = $url_data['route']; + + unset($url_data['route']); + + $url = ''; + + if ($url_data) { + $url = '&' . urldecode(http_build_query($url_data, '', '&')); + } + + $data['redirect'] = $this->url->link($route, $url, $this->request->server['HTTPS']); + } + + return $this->load->view('common/column_left', $data); + } + + public function language() { + if (isset($this->request->post['code']) && is_dir(DIR_LANGUAGE . basename($this->request->post['code']))) { + $this->session->data['language'] = $this->request->post['code']; + } + + if (isset($this->request->post['redirect'])) { + $this->response->redirect($this->request->post['redirect']); + } else { + $this->response->redirect($this->url->link('install/step_1')); + } + } +} diff --git a/public/install/controller/common/footer.php b/public/install/controller/common/footer.php new file mode 100644 index 0000000..5364afc --- /dev/null +++ b/public/install/controller/common/footer.php @@ -0,0 +1,12 @@ +<?php +class ControllerCommonFooter extends Controller { + public function index() { + $this->load->language('common/footer'); + + $data['text_project'] = $this->language->get('text_project'); + $data['text_documentation'] = $this->language->get('text_documentation'); + $data['text_support'] = $this->language->get('text_support'); + + return $this->load->view('common/footer', $data); + } +} diff --git a/public/install/controller/common/header.php b/public/install/controller/common/header.php new file mode 100644 index 0000000..1768edb --- /dev/null +++ b/public/install/controller/common/header.php @@ -0,0 +1,16 @@ +<?php +class ControllerCommonHeader extends Controller { + public function index() { + $this->load->language('common/header'); + + $data['title'] = $this->document->getTitle(); + $data['description'] = $this->document->getDescription(); + $data['links'] = $this->document->getLinks(); + $data['styles'] = $this->document->getStyles(); + $data['scripts'] = $this->document->getScripts(); + + $data['base'] = HTTP_SERVER; + + return $this->load->view('common/header', $data); + } +}
\ No newline at end of file diff --git a/public/install/controller/error/not_found.php b/public/install/controller/error/not_found.php new file mode 100644 index 0000000..115ef69 --- /dev/null +++ b/public/install/controller/error/not_found.php @@ -0,0 +1,25 @@ +<?php +class ControllerErrorNotFound extends Controller { + public function index() { + /* + $this->load->language('error/not_found'); + + $this->document->setTitle($this->language->get('heading_title')); + + $data['heading_title'] = $this->language->get('heading_title'); + + $data['text_error'] = $this->language->get('text_error'); + + $data['button_continue'] = $this->language->get('button_continue'); + + $data['continue'] = $this->url->link('common/home'); + + $data['footer'] = $this->load->controller('common/footer'); + $data['header'] = $this->load->controller('common/header'); + + $this->response->addHeader($this->request->server['SERVER_PROTOCOL'] . ' 404 Not Found'); + + $this->response->setOutput($this->load->view('error/not_found', $data)); + */ + } +}
\ No newline at end of file diff --git a/public/install/controller/event/theme.php b/public/install/controller/event/theme.php new file mode 100644 index 0000000..62e31ac --- /dev/null +++ b/public/install/controller/event/theme.php @@ -0,0 +1,10 @@ +<?php +class ControllerEventTheme extends Controller { + public function index(&$view, &$data) { + if (is_file(DIR_TEMPLATE . $view . '.tpl')) { + $this->config->set('template_engine', 'php'); + } elseif (is_file(DIR_TEMPLATE . $view . '.twig')) { + $this->config->set('template_engine', 'twig'); + } + } +} diff --git a/public/install/controller/install/step_1.php b/public/install/controller/install/step_1.php new file mode 100644 index 0000000..ddf64d0 --- /dev/null +++ b/public/install/controller/install/step_1.php @@ -0,0 +1,27 @@ +<?php +class ControllerInstallStep1 extends Controller { + public function index() { + $this->load->language('install/step_1'); + + if ($this->request->server['REQUEST_METHOD'] == 'POST') { + $this->response->redirect($this->url->link('install/step_2')); + } + + $this->document->setTitle($this->language->get('heading_title')); + + $data['heading_title'] = $this->language->get('heading_title'); + + $data['text_step_1'] = $this->language->get('text_step_1'); + $data['text_terms'] = $this->language->get('text_terms'); + + $data['button_continue'] = $this->language->get('button_continue'); + + $data['action'] = $this->url->link('install/step_1'); + + $data['footer'] = $this->load->controller('common/footer'); + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + + $this->response->setOutput($this->load->view('install/step_1', $data)); + } +}
\ No newline at end of file diff --git a/public/install/controller/install/step_2.php b/public/install/controller/install/step_2.php new file mode 100644 index 0000000..0083ce4 --- /dev/null +++ b/public/install/controller/install/step_2.php @@ -0,0 +1,266 @@ +<?php +class ControllerInstallStep2 extends Controller { + private $error = array(); + + public function index() { + $this->load->language('install/step_2'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->response->redirect($this->url->link('install/step_3')); + } + + $this->document->setTitle($this->language->get('heading_title')); + + $data['heading_title'] = $this->language->get('heading_title'); + + $data['text_step_2'] = $this->language->get('text_step_2'); + $data['text_install_php'] = $this->language->get('text_install_php'); + $data['text_install_extension'] = $this->language->get('text_install_extension'); + $data['text_install_file'] = $this->language->get('text_install_file'); + $data['text_install_directory'] = $this->language->get('text_install_directory'); + $data['text_setting'] = $this->language->get('text_setting'); + $data['text_current'] = $this->language->get('text_current'); + $data['text_required'] = $this->language->get('text_required'); + $data['text_extension'] = $this->language->get('text_extension'); + $data['text_file'] = $this->language->get('text_file'); + $data['text_directory'] = $this->language->get('text_directory'); + $data['text_status'] = $this->language->get('text_status'); + $data['text_on'] = $this->language->get('text_on'); + $data['text_off'] = $this->language->get('text_off'); + $data['text_missing'] = $this->language->get('text_missing'); + $data['text_writable'] = $this->language->get('text_writable'); + $data['text_unwritable'] = $this->language->get('text_unwritable'); + $data['text_version'] = $this->language->get('text_version'); + $data['text_global'] = $this->language->get('text_global'); + $data['text_magic'] = $this->language->get('text_magic'); + $data['text_file_upload'] = $this->language->get('text_file_upload'); + $data['text_session'] = $this->language->get('text_session'); + $data['text_db'] = $this->language->get('text_db'); + $data['text_gd'] = $this->language->get('text_gd'); + $data['text_curl'] = $this->language->get('text_curl'); + $data['text_openssl'] = $this->language->get('text_openssl'); + $data['text_zlib'] = $this->language->get('text_zlib'); + $data['text_zip'] = $this->language->get('text_zip'); + $data['text_mbstring'] = $this->language->get('text_mbstring'); + + $data['button_continue'] = $this->language->get('button_continue'); + $data['button_back'] = $this->language->get('button_back'); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['action'] = $this->url->link('install/step_2'); + + // catalog config + if (!is_file(DIR_OPENCART . 'config.php')) { + $data['error_catalog_config'] = $this->language->get('error_missing'); + } else { + $data['error_catalog_config'] = ''; + } + + if (!is_writable(DIR_OPENCART . 'config.php')) { + $data['error_catalog'] = $this->language->get('error_unwritable'); + } else { + $data['error_catalog'] = ''; + } + + // admin configs + if (!is_file(DIR_OPENCART . 'admin/config.php')) { + $data['error_admin_config'] = $this->language->get('error_missing'); + } else { + $data['error_admin_config_admin'] = ''; + } + + if (!is_writable(DIR_OPENCART . 'admin/config.php')) { + $data['error_admin_config'] = $this->language->get('error_unwritable'); + } else { + $data['error_admin_config'] = ''; + } + + if (!is_writable(DIR_OPENCART . 'image/')) { + $data['error_image'] = $this->language->get('error_unwritable'); + } else { + $data['error_image'] = ''; + } + + if (!is_writable(DIR_OPENCART . 'image/cache/')) { + $data['error_image_cache'] = $this->language->get('error_unwritable'); + } else { + $data['error_image_cache'] = ''; + } + + if (!is_writable(DIR_OPENCART . 'image/catalog/')) { + $data['error_image_catalog'] = $this->language->get('error_unwritable'); + } else { + $data['error_image_catalog'] = ''; + } + + if (!is_writable(DIR_SYSTEM . 'storage/logs/')) { + $data['error_log'] = $this->language->get('error_unwritable'); + } else { + $data['error_log'] = ''; + } + + if (!is_writable(DIR_SYSTEM . 'storage/download/')) { + $data['error_download'] = $this->language->get('error_unwritable'); + } else { + $data['error_download'] = ''; + } + + if (!is_writable(DIR_SYSTEM . 'storage/upload/')) { + $data['error_upload'] = $this->language->get('error_unwritable'); + } else { + $data['error_upload'] = ''; + } + + if (!is_writable(DIR_SYSTEM . 'storage/modification/')) { + $data['error_modification'] = $this->language->get('error_unwritable'); + } else { + $data['error_modification'] = ''; + } + + $data['php_version'] = phpversion(); + $data['register_globals'] = ini_get('register_globals'); + $data['magic_quotes_gpc'] = ini_get('magic_quotes_gpc'); + $data['file_uploads'] = ini_get('file_uploads'); + $data['session_auto_start'] = ini_get('session_auto_start'); + + $db = array( + 'mysql', + 'mysqli', + 'pgsql', + 'pdo' + ); + + if (!array_filter($db, 'extension_loaded')) { + $data['db'] = false; + } else { + $data['db'] = true; + } + + $data['gd'] = extension_loaded('gd'); + $data['curl'] = extension_loaded('curl'); + $data['openssl'] = function_exists('openssl_encrypt'); + $data['zlib'] = extension_loaded('zlib'); + $data['zip'] = extension_loaded('zip'); + $data['iconv'] = function_exists('iconv'); + $data['mbstring'] = extension_loaded('mbstring'); + + $data['catalog_config'] = DIR_OPENCART . 'config.php'; + $data['admin_config'] = DIR_OPENCART . 'admin/config.php'; + $data['image'] = DIR_OPENCART . 'image'; + $data['image_cache'] = DIR_OPENCART . 'image/cache'; + $data['image_catalog'] = DIR_OPENCART . 'image/catalog'; + $data['cache'] = DIR_SYSTEM . 'storage/cache'; + $data['logs'] = DIR_SYSTEM . 'storage/logs'; + $data['download'] = DIR_SYSTEM . 'storage/download'; + $data['upload'] = DIR_SYSTEM . 'storage/upload'; + $data['modification'] = DIR_SYSTEM . 'storage/modification'; + + $data['back'] = $this->url->link('install/step_1'); + + $data['footer'] = $this->load->controller('common/footer'); + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + + $this->response->setOutput($this->load->view('install/step_2', $data)); + } + + private function validate() { + if (phpversion() < '5.4') { + $this->error['warning'] = $this->language->get('error_version'); + } + + if (!ini_get('file_uploads')) { + $this->error['warning'] = $this->language->get('error_file_upload'); + } + + if (ini_get('session.auto_start')) { + $this->error['warning'] = $this->language->get('error_session'); + } + + $db = array( + 'mysql', + 'mysqli', + 'pdo', + 'pgsql' + ); + + if (!array_filter($db, 'extension_loaded')) { + $this->error['warning'] = $this->language->get('error_db'); + } + + if (!extension_loaded('gd')) { + $this->error['warning'] = $this->language->get('error_gd'); + } + + if (!extension_loaded('curl')) { + $this->error['warning'] = $this->language->get('error_curl'); + } + + if (!function_exists('openssl_encrypt')) { + $this->error['warning'] = $this->language->get('error_openssl'); + } + + if (!extension_loaded('zlib')) { + $this->error['warning'] = $this->language->get('error_zlib'); + } + + if (!extension_loaded('zip')) { + $this->error['warning'] = $this->language->get('error_zip'); + } + + if (!function_exists('iconv') && !extension_loaded('mbstring')) { + $this->error['warning'] = $this->language->get('error_mbstring'); + } + + if (!file_exists(DIR_OPENCART . 'config.php')) { + $this->error['warning'] = $this->language->get('error_catalog_exist'); + } elseif (!is_writable(DIR_OPENCART . 'config.php')) { + $this->error['warning'] = $this->language->get('error_catalog_writable'); + } + + if (!file_exists(DIR_OPENCART . 'admin/config.php')) { + $this->error['warning'] = $this->language->get('error_admin_exist'); + } elseif (!is_writable(DIR_OPENCART . 'admin/config.php')) { + $this->error['warning'] = $this->language->get('error_admin_writable'); + } + + if (!is_writable(DIR_OPENCART . 'image')) { + $this->error['warning'] = $this->language->get('error_image'); + } + + if (!is_writable(DIR_OPENCART . 'image/cache')) { + $this->error['warning'] = $this->language->get('error_image_cache'); + } + + if (!is_writable(DIR_OPENCART . 'image/catalog')) { + $this->error['warning'] = $this->language->get('error_image_catalog'); + } + + if (!is_writable(DIR_SYSTEM . 'storage/cache')) { + $this->error['warning'] = $this->language->get('error_cache'); + } + + if (!is_writable(DIR_SYSTEM . 'storage/logs')) { + $this->error['warning'] = $this->language->get('error_log'); + } + + if (!is_writable(DIR_SYSTEM . 'storage/download')) { + $this->error['warning'] = $this->language->get('error_download'); + } + + if (!is_writable(DIR_SYSTEM . 'storage/upload')) { + $this->error['warning'] = $this->language->get('error_upload'); + } + + if (!is_writable(DIR_SYSTEM . 'storage/modification')) { + $this->error['warning'] = $this->language->get('error_modification'); + } + + return !$this->error; + } +} diff --git a/public/install/controller/install/step_3.php b/public/install/controller/install/step_3.php new file mode 100644 index 0000000..eb7cccd --- /dev/null +++ b/public/install/controller/install/step_3.php @@ -0,0 +1,316 @@ +<?php +class ControllerInstallStep3 extends Controller { + private $error = array(); + + public function index() { + $this->load->language('install/step_3'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->load->model('install/install'); + + $this->model_install_install->database($this->request->post); + + $output = '<?php' . "\n"; + $output .= '// HTTP' . "\n"; + $output .= 'define(\'HTTP_SERVER\', \'' . HTTP_OPENCART . '\');' . "\n\n"; + + $output .= '// HTTPS' . "\n"; + $output .= 'define(\'HTTPS_SERVER\', \'' . HTTP_OPENCART . '\');' . "\n\n"; + + $output .= '// DIR' . "\n"; + $output .= 'define(\'DIR_APPLICATION\', \'' . addslashes(DIR_OPENCART) . 'catalog/\');' . "\n"; + $output .= 'define(\'DIR_SYSTEM\', \'' . addslashes(DIR_OPENCART) . 'system/\');' . "\n"; + $output .= 'define(\'DIR_IMAGE\', \'' . addslashes(DIR_OPENCART) . 'image/\');' . "\n"; + $output .= 'define(\'DIR_STORAGE\', DIR_SYSTEM . \'storage/\');' . "\n"; + $output .= 'define(\'DIR_LANGUAGE\', DIR_APPLICATION . \'language/\');' . "\n"; + $output .= 'define(\'DIR_TEMPLATE\', DIR_APPLICATION . \'view/theme/\');' . "\n"; + $output .= 'define(\'DIR_CONFIG\', DIR_SYSTEM . \'config/\');' . "\n"; + $output .= 'define(\'DIR_CACHE\', DIR_STORAGE . \'cache/\');' . "\n"; + $output .= 'define(\'DIR_DOWNLOAD\', DIR_STORAGE . \'download/\');' . "\n"; + $output .= 'define(\'DIR_LOGS\', DIR_STORAGE . \'logs/\');' . "\n"; + $output .= 'define(\'DIR_MODIFICATION\', DIR_STORAGE . \'modification/\');' . "\n"; + $output .= 'define(\'DIR_SESSION\', DIR_STORAGE . \'session/\');' . "\n"; + $output .= 'define(\'DIR_UPLOAD\', DIR_STORAGE . \'upload/\');' . "\n\n"; + + $output .= '// DB' . "\n"; + $output .= 'define(\'DB_DRIVER\', \'' . addslashes($this->request->post['db_driver']) . '\');' . "\n"; + $output .= 'define(\'DB_HOSTNAME\', \'' . addslashes($this->request->post['db_hostname']) . '\');' . "\n"; + $output .= 'define(\'DB_USERNAME\', \'' . addslashes($this->request->post['db_username']) . '\');' . "\n"; + $output .= 'define(\'DB_PASSWORD\', \'' . addslashes(html_entity_decode($this->request->post['db_password'], ENT_QUOTES, 'UTF-8')) . '\');' . "\n"; + $output .= 'define(\'DB_DATABASE\', \'' . addslashes($this->request->post['db_database']) . '\');' . "\n"; + $output .= 'define(\'DB_PORT\', \'' . addslashes($this->request->post['db_port']) . '\');' . "\n"; + $output .= 'define(\'DB_PREFIX\', \'' . addslashes($this->request->post['db_prefix']) . '\');'; + + $file = fopen(DIR_OPENCART . 'config.php', 'w'); + + fwrite($file, $output); + + fclose($file); + + $output = '<?php' . "\n"; + $output .= '// HTTP' . "\n"; + $output .= 'define(\'HTTP_SERVER\', \'' . HTTP_OPENCART . 'admin/\');' . "\n"; + $output .= 'define(\'HTTP_CATALOG\', \'' . HTTP_OPENCART . '\');' . "\n\n"; + + $output .= '// HTTPS' . "\n"; + $output .= 'define(\'HTTPS_SERVER\', \'' . HTTP_OPENCART . 'admin/\');' . "\n"; + $output .= 'define(\'HTTPS_CATALOG\', \'' . HTTP_OPENCART . '\');' . "\n\n"; + + $output .= '// DIR' . "\n"; + $output .= 'define(\'DIR_APPLICATION\', \'' . addslashes(DIR_OPENCART) . 'admin/\');' . "\n"; + $output .= 'define(\'DIR_SYSTEM\', \'' . addslashes(DIR_OPENCART) . 'system/\');' . "\n"; + $output .= 'define(\'DIR_IMAGE\', \'' . addslashes(DIR_OPENCART) . 'image/\');' . "\n"; + $output .= 'define(\'DIR_STORAGE\', DIR_SYSTEM . \'storage/\');' . "\n"; + $output .= 'define(\'DIR_CATALOG\', \'' . addslashes(DIR_OPENCART) . 'catalog/\');' . "\n"; + $output .= 'define(\'DIR_LANGUAGE\', DIR_APPLICATION . \'language/\');' . "\n"; + $output .= 'define(\'DIR_TEMPLATE\', DIR_APPLICATION . \'view/template/\');' . "\n"; + $output .= 'define(\'DIR_CONFIG\', DIR_SYSTEM . \'config/\');' . "\n"; + $output .= 'define(\'DIR_CACHE\', DIR_STORAGE . \'cache/\');' . "\n"; + $output .= 'define(\'DIR_DOWNLOAD\', DIR_STORAGE . \'download/\');' . "\n"; + $output .= 'define(\'DIR_LOGS\', DIR_STORAGE . \'logs/\');' . "\n"; + $output .= 'define(\'DIR_MODIFICATION\', DIR_STORAGE . \'modification/\');' . "\n"; + $output .= 'define(\'DIR_SESSION\', DIR_STORAGE . \'session/\');' . "\n"; + $output .= 'define(\'DIR_UPLOAD\', DIR_STORAGE . \'upload/\');' . "\n\n"; + + $output .= '// DB' . "\n"; + $output .= 'define(\'DB_DRIVER\', \'' . addslashes($this->request->post['db_driver']) . '\');' . "\n"; + $output .= 'define(\'DB_HOSTNAME\', \'' . addslashes($this->request->post['db_hostname']) . '\');' . "\n"; + $output .= 'define(\'DB_USERNAME\', \'' . addslashes($this->request->post['db_username']) . '\');' . "\n"; + $output .= 'define(\'DB_PASSWORD\', \'' . addslashes(html_entity_decode($this->request->post['db_password'], ENT_QUOTES, 'UTF-8')) . '\');' . "\n"; + $output .= 'define(\'DB_DATABASE\', \'' . addslashes($this->request->post['db_database']) . '\');' . "\n"; + $output .= 'define(\'DB_PORT\', \'' . addslashes($this->request->post['db_port']) . '\');' . "\n"; + $output .= 'define(\'DB_PREFIX\', \'' . addslashes($this->request->post['db_prefix']) . '\');' . "\n\n"; + + $output .= '// OpenCart API' . "\n"; + $output .= 'define(\'OPENCART_SERVER\', \'https://www.opencart.com/\');' . "\n"; + + $file = fopen(DIR_OPENCART . 'admin/config.php', 'w'); + + fwrite($file, $output); + + fclose($file); + + $this->response->redirect($this->url->link('install/step_4')); + } + + $this->document->setTitle($this->language->get('heading_title')); + + $data['heading_title'] = $this->language->get('heading_title'); + + $data['text_step_3'] = $this->language->get('text_step_3'); + $data['text_db_connection'] = $this->language->get('text_db_connection'); + $data['text_db_administration'] = $this->language->get('text_db_administration'); + $data['text_mysqli'] = $this->language->get('text_mysqli'); + $data['text_mpdo'] = $this->language->get('text_mpdo'); + $data['text_pgsql'] = $this->language->get('text_pgsql'); + + $data['entry_db_driver'] = $this->language->get('entry_db_driver'); + $data['entry_db_hostname'] = $this->language->get('entry_db_hostname'); + $data['entry_db_username'] = $this->language->get('entry_db_username'); + $data['entry_db_password'] = $this->language->get('entry_db_password'); + $data['entry_db_database'] = $this->language->get('entry_db_database'); + $data['entry_db_port'] = $this->language->get('entry_db_port'); + $data['entry_db_prefix'] = $this->language->get('entry_db_prefix'); + $data['entry_username'] = $this->language->get('entry_username'); + $data['entry_password'] = $this->language->get('entry_password'); + $data['entry_email'] = $this->language->get('entry_email'); + + $data['button_continue'] = $this->language->get('button_continue'); + $data['button_back'] = $this->language->get('button_back'); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['db_hostname'])) { + $data['error_db_hostname'] = $this->error['db_hostname']; + } else { + $data['error_db_hostname'] = ''; + } + + if (isset($this->error['db_username'])) { + $data['error_db_username'] = $this->error['db_username']; + } else { + $data['error_db_username'] = ''; + } + + if (isset($this->error['db_database'])) { + $data['error_db_database'] = $this->error['db_database']; + } else { + $data['error_db_database'] = ''; + } + + if (isset($this->error['db_port'])) { + $data['error_db_port'] = $this->error['db_port']; + } else { + $data['error_db_port'] = ''; + } + + if (isset($this->error['db_prefix'])) { + $data['error_db_prefix'] = $this->error['db_prefix']; + } else { + $data['error_db_prefix'] = ''; + } + + if (isset($this->error['username'])) { + $data['error_username'] = $this->error['username']; + } else { + $data['error_username'] = ''; + } + + if (isset($this->error['password'])) { + $data['error_password'] = $this->error['password']; + } else { + $data['error_password'] = ''; + } + + if (isset($this->error['email'])) { + $data['error_email'] = $this->error['email']; + } else { + $data['error_email'] = ''; + } + + $data['action'] = $this->url->link('install/step_3'); + + if (isset($this->request->post['db_driver'])) { + $data['db_driver'] = $this->request->post['db_driver']; + } else { + $data['db_driver'] = ''; + } + + if (isset($this->request->post['db_hostname'])) { + $data['db_hostname'] = $this->request->post['db_hostname']; + } else { + $data['db_hostname'] = 'localhost'; + } + + if (isset($this->request->post['db_username'])) { + $data['db_username'] = $this->request->post['db_username']; + } else { + $data['db_username'] = 'root'; + } + + if (isset($this->request->post['db_password'])) { + $data['db_password'] = $this->request->post['db_password']; + } else { + $data['db_password'] = ''; + } + + if (isset($this->request->post['db_database'])) { + $data['db_database'] = $this->request->post['db_database']; + } else { + $data['db_database'] = ''; + } + + if (isset($this->request->post['db_port'])) { + $data['db_port'] = $this->request->post['db_port']; + } else { + $data['db_port'] = 3306; + } + + if (isset($this->request->post['db_prefix'])) { + $data['db_prefix'] = $this->request->post['db_prefix']; + } else { + $data['db_prefix'] = 'oc_'; + } + + if (isset($this->request->post['username'])) { + $data['username'] = $this->request->post['username']; + } else { + $data['username'] = 'admin'; + } + + if (isset($this->request->post['password'])) { + $data['password'] = $this->request->post['password']; + } else { + $data['password'] = ''; + } + + if (isset($this->request->post['email'])) { + $data['email'] = $this->request->post['email']; + } else { + $data['email'] = ''; + } + + $data['mysqli'] = extension_loaded('mysqli'); + $data['mysql'] = extension_loaded('mysql'); + $data['pdo'] = extension_loaded('pdo'); + $data['pgsql'] = extension_loaded('pgsql'); + + $data['back'] = $this->url->link('install/step_2'); + + $data['footer'] = $this->load->controller('common/footer'); + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + + $this->response->setOutput($this->load->view('install/step_3', $data)); + } + + private function validate() { + if (!$this->request->post['db_hostname']) { + $this->error['db_hostname'] = $this->language->get('error_db_hostname'); + } + + if (!$this->request->post['db_username']) { + $this->error['db_username'] = $this->language->get('error_db_username'); + } + + if (!$this->request->post['db_database']) { + $this->error['db_database'] = $this->language->get('error_db_database'); + } + + if (!$this->request->post['db_port']) { + $this->error['db_port'] = $this->language->get('error_db_port'); + } + + if ($this->request->post['db_prefix'] && preg_match('/[^a-z0-9_]/', $this->request->post['db_prefix'])) { + $this->error['db_prefix'] = $this->language->get('error_db_prefix'); + } + + if ($this->request->post['db_driver'] == 'mysqli') { + try { + $db = new \DB\MySQLi($this->request->post['db_hostname'], $this->request->post['db_username'], html_entity_decode($this->request->post['db_password'], ENT_QUOTES, 'UTF-8'), $this->request->post['db_database'], $this->request->post['db_port']); + + if (is_resource($db)) { + $db->close(); + } + } catch(Exception $e) { + $this->error['warning'] = $mysql->connect_error; + } + } elseif ($this->request->post['db_driver'] == 'mpdo') { + try { + $db = new \DB\mPDO($this->request->post['db_hostname'], $this->request->post['db_username'], html_entity_decode($this->request->post['db_password'], ENT_QUOTES, 'UTF-8'), $this->request->post['db_database'], $this->request->post['db_port']); + + if (is_resource($db)) { + $db->close(); + } + } catch(Exception $e) { + $this->error['warning'] = $e->getMessage(); + } + } + + if (!$this->request->post['username']) { + $this->error['username'] = $this->language->get('error_username'); + } + + if (!$this->request->post['password']) { + $this->error['password'] = $this->language->get('error_password'); + } + + if ((utf8_strlen($this->request->post['email']) > 96) || !filter_var($this->request->post['email'], FILTER_VALIDATE_EMAIL)) { + $this->error['email'] = $this->language->get('error_email'); + } + + if (!is_writable(DIR_OPENCART . 'config.php')) { + $this->error['warning'] = $this->language->get('error_config') . DIR_OPENCART . 'config.php!'; + } + + if (!is_writable(DIR_OPENCART . 'admin/config.php')) { + $this->error['warning'] = $this->language->get('error_config') . DIR_OPENCART . 'admin/config.php!'; + } + + return !$this->error; + } +} diff --git a/public/install/controller/install/step_4.php b/public/install/controller/install/step_4.php new file mode 100644 index 0000000..a01dc49 --- /dev/null +++ b/public/install/controller/install/step_4.php @@ -0,0 +1,55 @@ +<?php +class ControllerInstallStep4 extends Controller { + public function index() { + $this->load->language('install/step_4'); + + $this->document->setTitle($this->language->get('heading_title')); + + $data['heading_title'] = $this->language->get('heading_title'); + + $data['text_step_4'] = $this->language->get('text_step_4'); + $data['text_catalog'] = $this->language->get('text_catalog'); + $data['text_admin'] = $this->language->get('text_admin'); + $data['text_loading'] = $this->language->get('text_loading'); + $data['text_extension'] = $this->language->get('text_extension'); + $data['text_mail'] = $this->language->get('text_mail'); + $data['text_mail_description'] = $this->language->get('text_mail_description'); + $data['text_openbay'] = $this->language->get('text_openbay'); + $data['text_amazon_pay'] = $this->language->get('text_amazon_pay'); + $data['text_facebook'] = $this->language->get('text_facebook'); + $data['text_facebook_description'] = $this->language->get('text_facebook_description'); + $data['text_facebook_visit'] = $this->language->get('text_facebook_visit'); + $data['text_forum'] = $this->language->get('text_forum'); + $data['text_forum_description'] = $this->language->get('text_forum_description'); + $data['text_forum_visit'] = $this->language->get('text_forum_visit'); + $data['text_commercial'] = $this->language->get('text_commercial'); + $data['text_commercial_description'] = $this->language->get('text_commercial_description'); + $data['text_commercial_visit'] = $this->language->get('text_commercial_visit'); + $data['text_view'] = $this->language->get('text_view'); + $data['text_download'] = $this->language->get('text_download'); + $data['text_downloads'] = $this->language->get('text_downloads'); + $data['text_price'] = $this->language->get('text_price'); + $data['text_view'] = $this->language->get('text_view'); + + $data['button_mail'] = $this->language->get('button_mail'); + $data['button_setup'] = $this->language->get('button_setup'); + + $data['error_warning'] = $this->language->get('error_warning'); + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + + unset($this->session->data['success']); + } else { + $data['success'] = ''; + } + + $data['openbay'] = $this->url->link('3rd_party/openbay'); + $data['extension'] = $this->url->link('3rd_party/extension'); + + $data['footer'] = $this->load->controller('common/footer'); + $data['header'] = $this->load->controller('common/header'); + + $this->response->setOutput($this->load->view('install/step_4', $data)); + } +} diff --git a/public/install/controller/startup/database.php b/public/install/controller/startup/database.php new file mode 100644 index 0000000..a4cf4cf --- /dev/null +++ b/public/install/controller/startup/database.php @@ -0,0 +1,22 @@ +<?php +class ControllerStartupDatabase extends Controller { + public function index() { + if (is_file(DIR_OPENCART . 'config.php') && filesize(DIR_OPENCART . 'config.php') > 0) { + $lines = file(DIR_OPENCART . 'config.php'); + + foreach ($lines as $line) { + if (strpos(strtoupper($line), 'DB_') !== false) { + eval($line); + } + } + + if (defined('DB_PORT')) { + $port = DB_PORT; + } else { + $port = ini_get('mysqli.default_port'); + } + + $this->registry->set('db', new DB(DB_DRIVER, DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE, $port)); + } + } +}
\ No newline at end of file diff --git a/public/install/controller/startup/language.php b/public/install/controller/startup/language.php new file mode 100644 index 0000000..3055f60 --- /dev/null +++ b/public/install/controller/startup/language.php @@ -0,0 +1,33 @@ +<?php +class ControllerStartupLanguage extends Controller { + public function index() { + // Default language code + $code = $this->config->get('language_default'); + + $languages = glob(DIR_LANGUAGE . '*', GLOB_ONLYDIR); + + foreach ($languages as $language) { + $languages[] = basename($language); + } + + if (isset($this->request->server['HTTP_ACCEPT_LANGUAGE'])) { + $browser_languages = explode(',', $this->request->server['HTTP_ACCEPT_LANGUAGE']); + + foreach ($browser_languages as $browser_language) { + if (in_array($browser_language, $languages)) { + $code = $browser_language; + break; + } + } + } + + if (!isset($this->session->data['language']) || !is_dir(DIR_LANGUAGE . basename($this->session->data['language']))) { + $this->session->data['language'] = $code; + } + + // Language + $language = new Language($this->session->data['language']); + $language->load($this->session->data['language']); + $this->registry->set('language', $language); + } +} diff --git a/public/install/controller/startup/router.php b/public/install/controller/startup/router.php new file mode 100644 index 0000000..13cd146 --- /dev/null +++ b/public/install/controller/startup/router.php @@ -0,0 +1,10 @@ +<?php +class ControllerStartupRouter extends Controller { + public function index() { + if (isset($this->request->get['route']) && $this->request->get['route'] != 'action/route') { + return new Action($this->request->get['route']); + } else { + return new Action($this->config->get('action_default')); + } + } +}
\ No newline at end of file diff --git a/public/install/controller/startup/upgrade.php b/public/install/controller/startup/upgrade.php new file mode 100644 index 0000000..abc9ddd --- /dev/null +++ b/public/install/controller/startup/upgrade.php @@ -0,0 +1,20 @@ +<?php +class ControllerStartupUpgrade extends Controller { + public function index() { + $upgrade = false; + + if (is_file(DIR_OPENCART . 'config.php') && filesize(DIR_OPENCART . 'config.php') > 0) { + $upgrade = true; + } + + if (isset($this->request->get['route'])) { + if (($this->request->get['route'] == 'install/step_4') || (substr($this->request->get['route'], 0, 8) == 'upgrade/') || (substr($this->request->get['route'], 0, 10) == '3rd_party/')) { + $upgrade = false; + } + } + + if ($upgrade) { + $this->response->redirect($this->url->link('upgrade/upgrade')); + } + } +}
\ No newline at end of file diff --git a/public/install/controller/upgrade/upgrade.php b/public/install/controller/upgrade/upgrade.php new file mode 100644 index 0000000..f283c25 --- /dev/null +++ b/public/install/controller/upgrade/upgrade.php @@ -0,0 +1,69 @@ +<?php +class ControllerUpgradeUpgrade extends Controller { + public function index() { + $this->load->language('upgrade/upgrade'); + + $this->document->setTitle($this->language->get('heading_title')); + + $data['heading_title'] = $this->language->get('heading_title'); + + $data['text_upgrade'] = $this->language->get('text_upgrade'); + $data['text_server'] = $this->language->get('text_server'); + $data['text_steps'] = $this->language->get('text_steps'); + $data['text_error'] = $this->language->get('text_error'); + $data['text_clear'] = $this->language->get('text_clear'); + $data['text_admin'] = $this->language->get('text_admin'); + $data['text_user'] = $this->language->get('text_user'); + $data['text_setting'] = $this->language->get('text_setting'); + $data['text_store'] = $this->language->get('text_store'); + + $data['entry_progress'] = $this->language->get('entry_progress'); + + $data['button_continue'] = $this->language->get('button_continue'); + + $data['store'] = HTTP_OPENCART; + + $data['total'] = count(glob(DIR_APPLICATION . 'model/upgrade/*.php')); + + $data['header'] = $this->load->controller('common/header'); + $data['footer'] = $this->load->controller('common/footer'); + $data['column_left'] = $this->load->controller('common/column_left'); + + $this->response->setOutput($this->load->view('upgrade/upgrade', $data)); + } + + public function next() { + $this->load->language('upgrade/upgrade'); + + $json = array(); + + if (isset($this->request->get['step'])) { + $step = $this->request->get['step']; + } else { + $step = 1; + } + + $files = glob(DIR_APPLICATION . 'model/upgrade/*.php'); + + if (isset($files[$step - 1])) { + // Get the upgrade file + try { + $this->load->model('upgrade/' . basename($files[$step - 1], '.php')); + + // All upgrade methods require a upgrade method + $this->{'model_upgrade_' . str_replace('.', '', basename($files[$step - 1], '.php'))}->upgrade(); + + $json['success'] = sprintf($this->language->get('text_progress'), basename($files[$step - 1], '.php'), $step, count($files)); + + $json['next'] = str_replace('&', '&', $this->url->link('upgrade/upgrade/next', 'step=' . ($step + 1))); + } catch(Exception $exception) { + $json['error'] = sprintf($this->language->get('error_exception'), $exception->getCode(), $exception->getMessage(), $exception->getFile(), $exception->getLine()); + } + } else { + $json['success'] = $this->language->get('text_success'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } +}
\ No newline at end of file |