first commit
This commit is contained in:
243
admininistrator/controller/common/authorize.php
Normal file
243
admininistrator/controller/common/authorize.php
Normal file
@ -0,0 +1,243 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Common;
|
||||
/**
|
||||
* Class Authorize
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Common
|
||||
*/
|
||||
class Authorize extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('common/authorize');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
if (isset($this->request->cookie['authorize'])) {
|
||||
$token = $this->request->cookie['authorize'];
|
||||
} else {
|
||||
$token = '';
|
||||
}
|
||||
|
||||
// Check to see if user is using incorrect token
|
||||
if (isset($this->session->data['error'])) {
|
||||
$data['error_warning'] = $this->session->data['error'];
|
||||
|
||||
unset($this->session->data['error']);
|
||||
} else {
|
||||
$data['error_warning'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->session->data['success'])) {
|
||||
$data['success'] = $this->session->data['success'];
|
||||
|
||||
unset($this->session->data['success']);
|
||||
} else {
|
||||
$data['success'] = '';
|
||||
}
|
||||
|
||||
$this->load->model('user/user');
|
||||
|
||||
$login_info = $this->model_user_user->getAuthorizeByToken($this->user->getId(), $token);
|
||||
|
||||
if (!$login_info) {
|
||||
// Create a token that can be stored as a cookie and will be used to identify device is safe.
|
||||
$token = oc_token(32);
|
||||
|
||||
$authorize_data = [
|
||||
'token' => $token,
|
||||
'ip' => $this->request->server['REMOTE_ADDR'],
|
||||
'user_agent' => $this->request->server['HTTP_USER_AGENT']
|
||||
];
|
||||
|
||||
$this->load->model('user/user');
|
||||
|
||||
$this->model_user_user->addAuthorize($this->user->getId(), $authorize_data);
|
||||
|
||||
setcookie('authorize', $token, time() + 60 * 60 * 24 * 365 * 10);
|
||||
}
|
||||
|
||||
$data['action'] = $this->url->link('common/authorize.validate', 'user_token=' . $this->session->data['user_token']);
|
||||
|
||||
// Set the code to be emailed
|
||||
$this->session->data['code'] = oc_token(4);
|
||||
|
||||
if (isset($this->request->get['route']) && $this->request->get['route'] != 'common/login' && $this->request->get['route'] != 'common/authorize') {
|
||||
$args = $this->request->get;
|
||||
|
||||
$route = $args['route'];
|
||||
|
||||
unset($args['route']);
|
||||
unset($args['user_token']);
|
||||
|
||||
$url = '';
|
||||
|
||||
if ($args) {
|
||||
$url .= http_build_query($args);
|
||||
}
|
||||
|
||||
$data['redirect'] = $this->url->link($route, $url);
|
||||
} else {
|
||||
$data['redirect'] = $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true);
|
||||
}
|
||||
|
||||
$data['user_token'] = $this->session->data['user_token'];
|
||||
|
||||
$data['header'] = $this->load->controller('common/header');
|
||||
$data['footer'] = $this->load->controller('common/footer');
|
||||
|
||||
$this->response->setOutput($this->load->view('common/authorize', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function send() {
|
||||
$this->load->language('common/authorize');
|
||||
|
||||
$json = [];
|
||||
|
||||
$json['success'] = $this->language->get('text_resend');
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function validate(): void {
|
||||
$this->load->language('common/authorize');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->cookie['authorize'])) {
|
||||
$token = $this->request->cookie['authorize'];
|
||||
} else {
|
||||
$token = '';
|
||||
}
|
||||
|
||||
$this->load->model('user/user');
|
||||
|
||||
$authorize_info = $this->model_user_user->getAuthorizeByToken($this->user->getId(), $token);
|
||||
|
||||
if ($authorize_info) {
|
||||
if (($authorize_info['attempts'] <= 2) && (!isset($this->request->post['code']) || !isset($this->session->data['code']) || ($this->request->post['code'] != $this->session->data['code']))) {
|
||||
$json['error'] = $this->language->get('error_code');
|
||||
|
||||
$this->model_user_user->editAuthorizeTotal($authorize_info['user_authorize_id'], $authorize_info['total'] + 1);
|
||||
}
|
||||
|
||||
if ($authorize_info['attempts'] >= 2) {
|
||||
$json['redirect'] = $this->url->link('common/authorize.unlock', 'user_token=' . $this->session->data['user_token'], true);
|
||||
}
|
||||
} else {
|
||||
$json['error'] = $this->language->get('error_code');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->model_user_user->editAuthorizeStatus($authorize_info['user_authorize_id'], 1);
|
||||
$this->model_user_user->editAuthorizeTotal($authorize_info['user_authorize_id'], 0);
|
||||
|
||||
// Register the cookie for security.
|
||||
if (isset($this->request->post['redirect']) && (strpos($this->request->post['redirect'], HTTP_SERVER) === 0)) {
|
||||
$json['redirect'] = str_replace('&', '&', $this->request->post['redirect'] . '&user_token=' . $this->session->data['user_token']);
|
||||
} else {
|
||||
$json['redirect'] = $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true);
|
||||
}
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function unlock() {
|
||||
$this->load->language('common/authorize');
|
||||
|
||||
if (isset($this->request->cookie['authorize'])) {
|
||||
$token = $this->request->cookie['authorize'];
|
||||
} else {
|
||||
$token = '';
|
||||
}
|
||||
|
||||
$this->load->model('user/user');
|
||||
|
||||
$authorize_info = $this->model_user_user->getAuthorizeByToken($this->user->getId(), $token);
|
||||
|
||||
if ($authorize_info && $authorize_info['status']) {
|
||||
// Redirect if already have a valid token.
|
||||
$this->response->redirect($this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true));
|
||||
}
|
||||
|
||||
$data['user_token'] = $this->session->data['user_token'];
|
||||
|
||||
$data['header'] = $this->load->controller('common/header');
|
||||
$data['footer'] = $this->load->controller('common/footer');
|
||||
|
||||
$this->response->setOutput($this->load->view('common/authorize_unlock', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function confirm() {
|
||||
$this->load->language('common/authorize');
|
||||
|
||||
$json = [];
|
||||
|
||||
$json['success'] = $this->language->get('text_link');
|
||||
|
||||
// Create reset code
|
||||
$this->load->model('user/user');
|
||||
|
||||
$this->model_user_user->editCode($this->user->getEmail(), oc_token(32));
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function reset() {
|
||||
$this->load->language('common/authorize');
|
||||
|
||||
if (isset($this->request->get['email'])) {
|
||||
$email = (string)$this->request->get['email'];
|
||||
} else {
|
||||
$email = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['code'])) {
|
||||
$code = (string)$this->request->get['code'];
|
||||
} else {
|
||||
$code = '';
|
||||
}
|
||||
|
||||
$this->load->model('user/user');
|
||||
|
||||
$user_info = $this->model_user_user->getUserByEmail($email);
|
||||
|
||||
if ($user_info && $user_info['code'] && $code && $user_info['code'] === $code) {
|
||||
$this->model_user_user->resetAuthorizes($user_info['user_id']);
|
||||
|
||||
$this->model_user_user->editCode($email, '');
|
||||
|
||||
$this->session->data['success'] = $this->language->get('text_unlocked');
|
||||
|
||||
$this->response->redirect($this->url->link('common/authorize', 'user_token=' . $this->session->data['user_token'], true));
|
||||
} else {
|
||||
$this->user->logout();
|
||||
|
||||
$this->model_user_user->editCode($email, '');
|
||||
|
||||
$this->session->data['error'] = $this->language->get('error_reset');
|
||||
|
||||
$this->response->redirect($this->url->link('common/login', '', true));
|
||||
}
|
||||
}
|
||||
}
|
808
admininistrator/controller/common/column_left.php
Normal file
808
admininistrator/controller/common/column_left.php
Normal file
@ -0,0 +1,808 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Common;
|
||||
/**
|
||||
* Class Column Left
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Common
|
||||
*/
|
||||
class ColumnLeft extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function index(): string {
|
||||
if (isset($this->request->get['user_token']) && isset($this->session->data['user_token']) && ((string)$this->request->get['user_token'] == $this->session->data['user_token'])) {
|
||||
$this->load->language('common/column_left');
|
||||
|
||||
// Create a 3 level menu array
|
||||
// Level 2 cannot have children
|
||||
|
||||
// Menu
|
||||
$data['menus'][] = [
|
||||
'id' => 'menu-dashboard',
|
||||
'icon' => 'fas fa-home',
|
||||
'name' => $this->language->get('text_dashboard'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
|
||||
// Catalog
|
||||
$catalog = [];
|
||||
|
||||
if ($this->user->hasPermission('access', 'catalog/category')) {
|
||||
$catalog[] = [
|
||||
'name' => $this->language->get('text_category'),
|
||||
'href' => $this->url->link('catalog/category', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'catalog/product')) {
|
||||
$catalog[] = [
|
||||
'name' => $this->language->get('text_product'),
|
||||
'href' => $this->url->link('catalog/product', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'catalog/subscription_plan')) {
|
||||
$catalog[] = [
|
||||
'name' => $this->language->get('text_subscription_plan'),
|
||||
'href' => $this->url->link('catalog/subscription_plan', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'catalog/filter')) {
|
||||
$catalog[] = [
|
||||
'name' => $this->language->get('text_filter'),
|
||||
'href' => $this->url->link('catalog/filter', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
// Attributes
|
||||
$attribute = [];
|
||||
|
||||
if ($this->user->hasPermission('access', 'catalog/attribute')) {
|
||||
$attribute[] = [
|
||||
'name' => $this->language->get('text_attribute'),
|
||||
'href' => $this->url->link('catalog/attribute', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'catalog/attribute_group')) {
|
||||
$attribute[] = [
|
||||
'name' => $this->language->get('text_attribute_group'),
|
||||
'href' => $this->url->link('catalog/attribute_group', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($attribute) {
|
||||
$catalog[] = [
|
||||
'name' => $this->language->get('text_attribute'),
|
||||
'href' => '',
|
||||
'children' => $attribute
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'catalog/option')) {
|
||||
$catalog[] = [
|
||||
'name' => $this->language->get('text_option'),
|
||||
'href' => $this->url->link('catalog/option', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'catalog/manufacturer')) {
|
||||
$catalog[] = [
|
||||
'name' => $this->language->get('text_manufacturer'),
|
||||
'href' => $this->url->link('catalog/manufacturer', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'catalog/download')) {
|
||||
$catalog[] = [
|
||||
'name' => $this->language->get('text_download'),
|
||||
'href' => $this->url->link('catalog/download', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'catalog/review')) {
|
||||
$catalog[] = [
|
||||
'name' => $this->language->get('text_review'),
|
||||
'href' => $this->url->link('catalog/review', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'catalog/information')) {
|
||||
$catalog[] = [
|
||||
'name' => $this->language->get('text_information'),
|
||||
'href' => $this->url->link('catalog/information', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($catalog) {
|
||||
$data['menus'][] = [
|
||||
'id' => 'menu-catalog',
|
||||
'icon' => 'fa-solid fa-tag',
|
||||
'name' => $this->language->get('text_catalog'),
|
||||
'href' => '',
|
||||
'children' => $catalog
|
||||
];
|
||||
}
|
||||
|
||||
$cms = [];
|
||||
|
||||
if ($this->user->hasPermission('access', 'cms/topic')) {
|
||||
$cms[] = [
|
||||
'name' => $this->language->get('text_topic'),
|
||||
'href' => $this->url->link('cms/topic', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'cms/article')) {
|
||||
$cms[] = [
|
||||
'name' => $this->language->get('text_article'),
|
||||
'href' => $this->url->link('cms/article', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'cms/comment')) {
|
||||
$cms[] = [
|
||||
'name' => $this->language->get('text_comment'),
|
||||
'href' => $this->url->link('cms/comment', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'cms/antispam')) {
|
||||
$cms[] = [
|
||||
'name' => $this->language->get('text_antispam'),
|
||||
'href' => $this->url->link('cms/antispam', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
// Still in development
|
||||
//if ($cms) {
|
||||
// $data['menus'][] = [
|
||||
// 'id' => 'menu-cms',
|
||||
// 'icon' => 'fa-regular fa-newspaper',
|
||||
// 'name' => $this->language->get('text_cms'),
|
||||
// 'href' => '',
|
||||
// 'children' => $cms
|
||||
// ];
|
||||
//}
|
||||
|
||||
// Extension
|
||||
$marketplace = [];
|
||||
|
||||
if ($this->user->hasPermission('access', 'marketplace/marketplace')) {
|
||||
$marketplace[] = [
|
||||
'name' => $this->language->get('text_marketplace'),
|
||||
'href' => $this->url->link('marketplace/marketplace', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'marketplace/installer')) {
|
||||
$marketplace[] = [
|
||||
'name' => $this->language->get('text_installer'),
|
||||
'href' => $this->url->link('marketplace/installer', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'marketplace/extension')) {
|
||||
$marketplace[] = [
|
||||
'name' => $this->language->get('text_extension'),
|
||||
'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'marketplace/startup')) {
|
||||
$marketplace[] = [
|
||||
'name' => $this->language->get('text_startup'),
|
||||
'href' => $this->url->link('marketplace/startup', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'marketplace/event')) {
|
||||
$marketplace[] = [
|
||||
'name' => $this->language->get('text_event'),
|
||||
'href' => $this->url->link('marketplace/event', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'marketplace/cron')) {
|
||||
$marketplace[] = [
|
||||
'name' => $this->language->get('text_cron'),
|
||||
'href' => $this->url->link('marketplace/cron', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($marketplace) {
|
||||
$data['menus'][] = [
|
||||
'id' => 'menu-extension',
|
||||
'icon' => 'fas fa-puzzle-piece',
|
||||
'name' => $this->language->get('text_extension'),
|
||||
'href' => '',
|
||||
'children' => $marketplace
|
||||
];
|
||||
}
|
||||
|
||||
// Design
|
||||
$design = [];
|
||||
|
||||
if ($this->user->hasPermission('access', 'design/layout')) {
|
||||
$design[] = [
|
||||
'name' => $this->language->get('text_layout'),
|
||||
'href' => $this->url->link('design/layout', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'design/theme')) {
|
||||
$design[] = [
|
||||
'name' => $this->language->get('text_theme'),
|
||||
'href' => $this->url->link('design/theme', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'design/translation')) {
|
||||
$design[] = [
|
||||
'name' => $this->language->get('text_language_editor'),
|
||||
'href' => $this->url->link('design/translation', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'design/banner')) {
|
||||
$design[] = [
|
||||
'name' => $this->language->get('text_banner'),
|
||||
'href' => $this->url->link('design/banner', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
$seo = [];
|
||||
|
||||
if ($this->user->hasPermission('access', 'design/seo_url')) {
|
||||
$design[] = [
|
||||
'name' => $this->language->get('text_seo_url'),
|
||||
'href' => $this->url->link('design/seo_url', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($design) {
|
||||
$data['menus'][] = [
|
||||
'id' => 'menu-design',
|
||||
'icon' => 'fas fa-desktop',
|
||||
'name' => $this->language->get('text_design'),
|
||||
'href' => '',
|
||||
'children' => $design
|
||||
];
|
||||
}
|
||||
|
||||
// Sales
|
||||
$sale = [];
|
||||
|
||||
if ($this->user->hasPermission('access', 'sale/order')) {
|
||||
$sale[] = [
|
||||
'name' => $this->language->get('text_order'),
|
||||
'href' => $this->url->link('sale/order', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'sale/subscription')) {
|
||||
$sale[] = [
|
||||
'name' => $this->language->get('text_subscription'),
|
||||
'href' => $this->url->link('sale/subscription', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'sale/returns')) {
|
||||
$sale[] = [
|
||||
'name' => $this->language->get('text_return'),
|
||||
'href' => $this->url->link('sale/returns', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
// Voucher
|
||||
$voucher = [];
|
||||
|
||||
if ($this->user->hasPermission('access', 'sale/voucher')) {
|
||||
$voucher[] = [
|
||||
'name' => $this->language->get('text_voucher'),
|
||||
'href' => $this->url->link('sale/voucher', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'sale/voucher_theme')) {
|
||||
$voucher[] = [
|
||||
'name' => $this->language->get('text_voucher_theme'),
|
||||
'href' => $this->url->link('sale/voucher_theme', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($voucher) {
|
||||
$sale[] = [
|
||||
'name' => $this->language->get('text_voucher'),
|
||||
'href' => '',
|
||||
'children' => $voucher
|
||||
];
|
||||
}
|
||||
|
||||
if ($sale) {
|
||||
$data['menus'][] = [
|
||||
'id' => 'menu-sale',
|
||||
'icon' => 'fas fa-shopping-cart',
|
||||
'name' => $this->language->get('text_sale'),
|
||||
'href' => '',
|
||||
'children' => $sale
|
||||
];
|
||||
}
|
||||
|
||||
// Customer
|
||||
$customer = [];
|
||||
|
||||
if ($this->user->hasPermission('access', 'customer/customer')) {
|
||||
$customer[] = [
|
||||
'name' => $this->language->get('text_customer'),
|
||||
'href' => $this->url->link('customer/customer', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'customer/customer_group')) {
|
||||
$customer[] = [
|
||||
'name' => $this->language->get('text_customer_group'),
|
||||
'href' => $this->url->link('customer/customer_group', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'customer/customer_approval')) {
|
||||
$customer[] = [
|
||||
'name' => $this->language->get('text_customer_approval'),
|
||||
'href' => $this->url->link('customer/customer_approval', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'customer/gdpr')) {
|
||||
$customer[] = [
|
||||
'name' => $this->language->get('text_gdpr'),
|
||||
'href' => $this->url->link('customer/gdpr', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'customer/custom_field')) {
|
||||
$customer[] = [
|
||||
'name' => $this->language->get('text_custom_field'),
|
||||
'href' => $this->url->link('customer/custom_field', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($customer) {
|
||||
$data['menus'][] = [
|
||||
'id' => 'menu-customer',
|
||||
'icon' => 'fas fa-user',
|
||||
'name' => $this->language->get('text_customer'),
|
||||
'href' => '',
|
||||
'children' => $customer
|
||||
];
|
||||
}
|
||||
|
||||
// Marketing
|
||||
$marketing = [];
|
||||
|
||||
if ($this->user->hasPermission('access', 'marketing/affiliate')) {
|
||||
$marketing[] = [
|
||||
'name' => $this->language->get('text_affiliate'),
|
||||
'href' => $this->url->link('marketing/affiliate', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'marketing/marketing')) {
|
||||
$marketing[] = [
|
||||
'name' => $this->language->get('text_marketing'),
|
||||
'href' => $this->url->link('marketing/marketing', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'marketing/coupon')) {
|
||||
$marketing[] = [
|
||||
'name' => $this->language->get('text_coupon'),
|
||||
'href' => $this->url->link('marketing/coupon', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'marketing/contact')) {
|
||||
$marketing[] = [
|
||||
'name' => $this->language->get('text_contact'),
|
||||
'href' => $this->url->link('marketing/contact', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($marketing) {
|
||||
$data['menus'][] = [
|
||||
'id' => 'menu-marketing',
|
||||
'icon' => 'fas fa-share-alt',
|
||||
'name' => $this->language->get('text_marketing'),
|
||||
'href' => '',
|
||||
'children' => $marketing
|
||||
];
|
||||
}
|
||||
|
||||
// System
|
||||
$system = [];
|
||||
|
||||
if ($this->user->hasPermission('access', 'setting/setting')) {
|
||||
$system[] = [
|
||||
'name' => $this->language->get('text_setting'),
|
||||
'href' => $this->url->link('setting/store', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
// Users
|
||||
$user = [];
|
||||
|
||||
if ($this->user->hasPermission('access', 'user/user')) {
|
||||
$user[] = [
|
||||
'name' => $this->language->get('text_users'),
|
||||
'href' => $this->url->link('user/user', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'user/user_permission')) {
|
||||
$user[] = [
|
||||
'name' => $this->language->get('text_user_group'),
|
||||
'href' => $this->url->link('user/user_permission', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'user/api')) {
|
||||
$user[] = [
|
||||
'name' => $this->language->get('text_api'),
|
||||
'href' => $this->url->link('user/api', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($user) {
|
||||
$system[] = [
|
||||
'name' => $this->language->get('text_users'),
|
||||
'href' => '',
|
||||
'children' => $user
|
||||
];
|
||||
}
|
||||
|
||||
// Localisation
|
||||
$localisation = [];
|
||||
|
||||
if ($this->user->hasPermission('access', 'localisation/location')) {
|
||||
$localisation[] = [
|
||||
'name' => $this->language->get('text_location'),
|
||||
'href' => $this->url->link('localisation/location', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'localisation/language')) {
|
||||
$localisation[] = [
|
||||
'name' => $this->language->get('text_language'),
|
||||
'href' => $this->url->link('localisation/language', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'localisation/currency')) {
|
||||
$localisation[] = [
|
||||
'name' => $this->language->get('text_currency'),
|
||||
'href' => $this->url->link('localisation/currency', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'localisation/stock_status')) {
|
||||
$localisation[] = [
|
||||
'name' => $this->language->get('text_stock_status'),
|
||||
'href' => $this->url->link('localisation/stock_status', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'localisation/order_status')) {
|
||||
$localisation[] = [
|
||||
'name' => $this->language->get('text_order_status'),
|
||||
'href' => $this->url->link('localisation/order_status', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'localisation/subscription_status')) {
|
||||
$localisation[] = [
|
||||
'name' => $this->language->get('text_subscription_status'),
|
||||
'href' => $this->url->link('localisation/subscription_status', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
// Returns
|
||||
$returns = [];
|
||||
|
||||
if ($this->user->hasPermission('access', 'localisation/return_status')) {
|
||||
$returns[] = [
|
||||
'name' => $this->language->get('text_return_status'),
|
||||
'href' => $this->url->link('localisation/return_status', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'localisation/return_action')) {
|
||||
$returns[] = [
|
||||
'name' => $this->language->get('text_return_action'),
|
||||
'href' => $this->url->link('localisation/return_action', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'localisation/return_reason')) {
|
||||
$returns[] = [
|
||||
'name' => $this->language->get('text_return_reason'),
|
||||
'href' => $this->url->link('localisation/return_reason', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($returns) {
|
||||
$localisation[] = [
|
||||
'name' => $this->language->get('text_return'),
|
||||
'href' => '',
|
||||
'children' => $returns
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'localisation/country')) {
|
||||
$localisation[] = [
|
||||
'name' => $this->language->get('text_country'),
|
||||
'href' => $this->url->link('localisation/country', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'localisation/zone')) {
|
||||
$localisation[] = [
|
||||
'name' => $this->language->get('text_zone'),
|
||||
'href' => $this->url->link('localisation/zone', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'localisation/geo_zone')) {
|
||||
$localisation[] = [
|
||||
'name' => $this->language->get('text_geo_zone'),
|
||||
'href' => $this->url->link('localisation/geo_zone', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
// Tax
|
||||
$tax = [];
|
||||
|
||||
if ($this->user->hasPermission('access', 'localisation/tax_class')) {
|
||||
$tax[] = [
|
||||
'name' => $this->language->get('text_tax_class'),
|
||||
'href' => $this->url->link('localisation/tax_class', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'localisation/tax_rate')) {
|
||||
$tax[] = [
|
||||
'name' => $this->language->get('text_tax_rate'),
|
||||
'href' => $this->url->link('localisation/tax_rate', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($tax) {
|
||||
$localisation[] = [
|
||||
'name' => $this->language->get('text_tax'),
|
||||
'href' => '',
|
||||
'children' => $tax
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'localisation/length_class')) {
|
||||
$localisation[] = [
|
||||
'name' => $this->language->get('text_length_class'),
|
||||
'href' => $this->url->link('localisation/length_class', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'localisation/weight_class')) {
|
||||
$localisation[] = [
|
||||
'name' => $this->language->get('text_weight_class'),
|
||||
'href' => $this->url->link('localisation/weight_class', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'localisation/address_format')) {
|
||||
$localisation[] = [
|
||||
'name' => $this->language->get('text_address_format'),
|
||||
'href' => $this->url->link('localisation/address_format', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($localisation) {
|
||||
$system[] = [
|
||||
'name' => $this->language->get('text_localisation'),
|
||||
'href' => '',
|
||||
'children' => $localisation
|
||||
];
|
||||
}
|
||||
|
||||
// Tools
|
||||
$maintenance = [];
|
||||
|
||||
if ($this->user->hasPermission('access', 'tool/upgrade')) {
|
||||
$maintenance[] = [
|
||||
'name' => $this->language->get('text_upgrade'),
|
||||
'href' => $this->url->link('tool/upgrade', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'tool/backup')) {
|
||||
$maintenance[] = [
|
||||
'name' => $this->language->get('text_backup'),
|
||||
'href' => $this->url->link('tool/backup', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'tool/upload')) {
|
||||
$maintenance[] = [
|
||||
'name' => $this->language->get('text_upload'),
|
||||
'href' => $this->url->link('tool/upload', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'tool/log')) {
|
||||
$maintenance[] = [
|
||||
'name' => $this->language->get('text_log'),
|
||||
'href' => $this->url->link('tool/log', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($maintenance) {
|
||||
$system[] = [
|
||||
'name' => $this->language->get('text_maintenance'),
|
||||
'href' => '',
|
||||
'children' => $maintenance
|
||||
];
|
||||
}
|
||||
|
||||
if ($system) {
|
||||
$data['menus'][] = [
|
||||
'id' => 'menu-system',
|
||||
'icon' => 'fas fa-cog',
|
||||
'name' => $this->language->get('text_system'),
|
||||
'href' => '',
|
||||
'children' => $system
|
||||
];
|
||||
}
|
||||
|
||||
$report = [];
|
||||
|
||||
if ($this->user->hasPermission('access', 'report/report')) {
|
||||
$report[] = [
|
||||
'name' => $this->language->get('text_reports'),
|
||||
'href' => $this->url->link('report/report', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'report/online')) {
|
||||
$report[] = [
|
||||
'name' => $this->language->get('text_online'),
|
||||
'href' => $this->url->link('report/online', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'report/statistics')) {
|
||||
$report[] = [
|
||||
'name' => $this->language->get('text_statistics'),
|
||||
'href' => $this->url->link('report/statistics', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($report) {
|
||||
$data['menus'][] = [
|
||||
'id' => 'menu-report',
|
||||
'icon' => 'fas fa-chart-bar',
|
||||
'name' => $this->language->get('text_reports'),
|
||||
'href' => '',
|
||||
'children' => $report
|
||||
];
|
||||
}
|
||||
|
||||
// Stats
|
||||
if ($this->user->hasPermission('access', 'report/statistics')) {
|
||||
$this->load->model('sale/order');
|
||||
|
||||
$order_total = (float)$this->model_sale_order->getTotalOrders();
|
||||
|
||||
$this->load->model('report/statistics');
|
||||
|
||||
$complete_total = (float)$this->model_report_statistics->getValue('order_complete');
|
||||
|
||||
if ($complete_total && $order_total) {
|
||||
$data['complete_status'] = round(($complete_total / $order_total) * 100);
|
||||
} else {
|
||||
$data['complete_status'] = 0;
|
||||
}
|
||||
|
||||
$processing_total = (float)$this->model_report_statistics->getValue('order_processing');
|
||||
|
||||
if ($processing_total && $order_total) {
|
||||
$data['processing_status'] = round(($processing_total / $order_total) * 100);
|
||||
} else {
|
||||
$data['processing_status'] = 0;
|
||||
}
|
||||
|
||||
$other_total = (float)$this->model_report_statistics->getValue('order_other');
|
||||
|
||||
if ($other_total && $order_total) {
|
||||
$data['other_status'] = round(($other_total / $order_total) * 100);
|
||||
} else {
|
||||
$data['other_status'] = 0;
|
||||
}
|
||||
|
||||
$data['statistics_status'] = true;
|
||||
} else {
|
||||
$data['statistics_status'] = false;
|
||||
}
|
||||
|
||||
return $this->load->view('common/column_left', $data);
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
100
admininistrator/controller/common/dashboard.php
Normal file
100
admininistrator/controller/common/dashboard.php
Normal file
@ -0,0 +1,100 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Common;
|
||||
/**
|
||||
* Class Dashboard
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Common
|
||||
*/
|
||||
class Dashboard extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('common/dashboard');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
// Dashboard Extensions
|
||||
$dashboards = [];
|
||||
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
// Get a list of installed modules
|
||||
$extensions = $this->model_setting_extension->getExtensionsByType('dashboard');
|
||||
|
||||
// Add all the modules which have multiple settings for each module
|
||||
foreach ($extensions as $extension) {
|
||||
if ($this->config->get('dashboard_' . $extension['code'] . '_status') && $this->user->hasPermission('access', 'extension/' . $extension['extension'] . '/dashboard/' . $extension['code'])) {
|
||||
$output = $this->load->controller('extension/' . $extension['extension'] . '/dashboard/' . $extension['code'] . '.dashboard');
|
||||
|
||||
//if (!$output instanceof \Exception) {
|
||||
if ($output) {
|
||||
$dashboards[] = [
|
||||
'code' => $extension['code'],
|
||||
'width' => $this->config->get('dashboard_' . $extension['code'] . '_width'),
|
||||
'sort_order' => $this->config->get('dashboard_' . $extension['code'] . '_sort_order'),
|
||||
'output' => $output
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$sort_order = [];
|
||||
|
||||
foreach ($dashboards as $key => $value) {
|
||||
$sort_order[$key] = $value['sort_order'];
|
||||
}
|
||||
|
||||
array_multisort($sort_order, SORT_ASC, $dashboards);
|
||||
|
||||
// Split the array so the columns width is not more than 12 on each row.
|
||||
$width = 0;
|
||||
$column = [];
|
||||
$data['rows'] = [];
|
||||
|
||||
foreach ($dashboards as $dashboard) {
|
||||
$column[] = $dashboard;
|
||||
|
||||
$width = ($width + $dashboard['width']);
|
||||
|
||||
if ($width >= 12) {
|
||||
$data['rows'][] = $column;
|
||||
|
||||
$width = 0;
|
||||
$column = [];
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($column)) {
|
||||
$data['rows'][] = $column;
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'common/developer')) {
|
||||
$data['developer_status'] = true;
|
||||
} else {
|
||||
$data['developer_status'] = false;
|
||||
}
|
||||
|
||||
$data['security'] = $this->load->controller('common/security');
|
||||
|
||||
$data['user_token'] = $this->session->data['user_token'];
|
||||
|
||||
$data['header'] = $this->load->controller('common/header');
|
||||
$data['column_left'] = $this->load->controller('common/column_left');
|
||||
$data['footer'] = $this->load->controller('common/footer');
|
||||
|
||||
$this->response->setOutput($this->load->view('common/dashboard', $data));
|
||||
}
|
||||
}
|
130
admininistrator/controller/common/developer.php
Normal file
130
admininistrator/controller/common/developer.php
Normal file
@ -0,0 +1,130 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Common;
|
||||
/**
|
||||
* Class Developer
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Common
|
||||
*/
|
||||
class Developer extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('common/developer');
|
||||
|
||||
$data['developer_sass'] = $this->config->get('developer_sass');
|
||||
|
||||
$data['user_token'] = $this->session->data['user_token'];
|
||||
|
||||
$this->response->setOutput($this->load->view('common/developer', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function edit(): void {
|
||||
$this->load->language('common/developer');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'common/developer')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('setting/setting');
|
||||
|
||||
$this->model_setting_setting->editSetting('developer', $this->request->post, 0);
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function theme(): void {
|
||||
$this->load->language('common/developer');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'common/developer')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$directories = glob(DIR_CACHE . 'template/*', GLOB_ONLYDIR);
|
||||
|
||||
if ($directories) {
|
||||
foreach ($directories as $directory) {
|
||||
$files = glob($directory . '/*');
|
||||
|
||||
foreach ($files as $file) {
|
||||
if (is_file($file)) {
|
||||
unlink($file);
|
||||
}
|
||||
}
|
||||
|
||||
if (is_dir($directory)) {
|
||||
rmdir($directory);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$json['success'] = sprintf($this->language->get('text_cache'), $this->language->get('text_theme'));
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function sass(): void {
|
||||
$this->load->language('common/developer');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'common/developer')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
// Before we delete we need to make sure there is a sass file to regenerate the css
|
||||
$file = DIR_APPLICATION . 'view/stylesheet/bootstrap.css';
|
||||
|
||||
if (is_file($file) && is_file(DIR_APPLICATION . 'view/stylesheet/scss/bootstrap.scss')) {
|
||||
unlink($file);
|
||||
}
|
||||
|
||||
$files = glob(DIR_CATALOG . 'view/theme/*/stylesheet/scss/bootstrap.scss');
|
||||
|
||||
foreach ($files as $file) {
|
||||
$file = substr($file, 0, -20) . '/bootstrap.css';
|
||||
|
||||
if (is_file($file)) {
|
||||
unlink($file);
|
||||
}
|
||||
}
|
||||
|
||||
$files = glob(DIR_CATALOG . 'view/theme/*/stylesheet/stylesheet.scss');
|
||||
|
||||
foreach ($files as $file) {
|
||||
$file = substr($file, 0, -16) . '/stylesheet.css';
|
||||
|
||||
if (is_file($file)) {
|
||||
unlink($file);
|
||||
}
|
||||
}
|
||||
|
||||
$json['success'] = sprintf($this->language->get('text_cache'), $this->language->get('text_sass'));
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
485
admininistrator/controller/common/filemanager.php
Normal file
485
admininistrator/controller/common/filemanager.php
Normal file
@ -0,0 +1,485 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Common;
|
||||
/**
|
||||
* Class File Manager
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Common
|
||||
*/
|
||||
class FileManager extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('common/filemanager');
|
||||
|
||||
$data['error_upload_size'] = sprintf($this->language->get('error_upload_size'), $this->config->get('config_file_max_size'));
|
||||
|
||||
$data['config_file_max_size'] = ((int)$this->config->get('config_file_max_size') * 1024 * 1024);
|
||||
|
||||
// Return the target ID for the file manager to set the value
|
||||
if (isset($this->request->get['target'])) {
|
||||
$data['target'] = $this->request->get['target'];
|
||||
} else {
|
||||
$data['target'] = '';
|
||||
}
|
||||
|
||||
// Return the thumbnail for the file manager to show a thumbnail
|
||||
if (isset($this->request->get['thumb'])) {
|
||||
$data['thumb'] = $this->request->get['thumb'];
|
||||
} else {
|
||||
$data['thumb'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['ckeditor'])) {
|
||||
$data['ckeditor'] = $this->request->get['ckeditor'];
|
||||
} else {
|
||||
$data['ckeditor'] = '';
|
||||
}
|
||||
|
||||
$data['user_token'] = $this->session->data['user_token'];
|
||||
|
||||
$this->response->setOutput($this->load->view('common/filemanager', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function list(): void {
|
||||
$this->load->language('common/filemanager');
|
||||
|
||||
$base = DIR_IMAGE . 'catalog/';
|
||||
|
||||
// Make sure we have the correct directory
|
||||
if (isset($this->request->get['directory'])) {
|
||||
$directory = $base . html_entity_decode($this->request->get['directory'], ENT_QUOTES, 'UTF-8') . '/';
|
||||
} else {
|
||||
$directory = $base;
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_name'])) {
|
||||
$filter_name = basename(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8'));
|
||||
} else {
|
||||
$filter_name = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$allowed = [
|
||||
'.ico',
|
||||
'.jpg',
|
||||
'.jpeg',
|
||||
'.png',
|
||||
'.gif',
|
||||
'.webp',
|
||||
'.JPG',
|
||||
'.JPEG',
|
||||
'.PNG',
|
||||
'.GIF'
|
||||
];
|
||||
|
||||
$data['directories'] = [];
|
||||
$data['images'] = [];
|
||||
|
||||
$this->load->model('tool/image');
|
||||
|
||||
// Get directories and files
|
||||
$paths = array_merge(
|
||||
glob($directory . $filter_name . '*', GLOB_ONLYDIR),
|
||||
glob($directory . $filter_name . '*{' . implode(',', $allowed) . '}', GLOB_BRACE)
|
||||
);
|
||||
|
||||
$total = count($paths);
|
||||
$limit = 16;
|
||||
$start = ($page - 1) * $limit;
|
||||
|
||||
if ($paths) {
|
||||
// Split the array based on current page number and max number of items per page of 10
|
||||
foreach (array_slice($paths, $start, $limit) as $path) {
|
||||
$path = str_replace('\\', '/', realpath($path));
|
||||
|
||||
if (substr($path, 0, strlen($path)) == $path) {
|
||||
$name = basename($path);
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['target'])) {
|
||||
$url .= '&target=' . $this->request->get['target'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['thumb'])) {
|
||||
$url .= '&thumb=' . $this->request->get['thumb'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['ckeditor'])) {
|
||||
$url .= '&ckeditor=' . $this->request->get['ckeditor'];
|
||||
}
|
||||
|
||||
if (is_dir($path)) {
|
||||
$data['directories'][] = [
|
||||
'name' => $name,
|
||||
'path' => oc_substr($path, oc_strlen($base)) . '/',
|
||||
'href' => $this->url->link('common/filemanager.list', 'user_token=' . $this->session->data['user_token'] . '&directory=' . urlencode(oc_substr($path, oc_strlen($base))) . $url)
|
||||
];
|
||||
}
|
||||
|
||||
if (is_file($path) && in_array(substr($path, strrpos($path, '.')), $allowed)) {
|
||||
$data['images'][] = [
|
||||
'name' => $name,
|
||||
'path' => oc_substr($path, oc_strlen($base)),
|
||||
'href' => HTTP_CATALOG . 'image/catalog/' . oc_substr($path, oc_strlen($base)),
|
||||
'thumb' => $this->model_tool_image->resize(oc_substr($path, oc_strlen(DIR_IMAGE)), 136, 136)
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($this->request->get['directory'])) {
|
||||
$data['directory'] = urldecode($this->request->get['directory']);
|
||||
} else {
|
||||
$data['directory'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_name'])) {
|
||||
$data['filter_name'] = $this->request->get['filter_name'];
|
||||
} else {
|
||||
$data['filter_name'] = '';
|
||||
}
|
||||
|
||||
// Parent
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['directory'])) {
|
||||
$pos = strrpos($this->request->get['directory'], '/');
|
||||
|
||||
if ($pos) {
|
||||
$url .= '&directory=' . urlencode(substr($this->request->get['directory'], 0, $pos));
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($this->request->get['target'])) {
|
||||
$url .= '&target=' . $this->request->get['target'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['thumb'])) {
|
||||
$url .= '&thumb=' . $this->request->get['thumb'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['ckeditor'])) {
|
||||
$url .= '&ckeditor=' . $this->request->get['ckeditor'];
|
||||
}
|
||||
|
||||
$data['parent'] = $this->url->link('common/filemanager.list', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
// Refresh
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['directory'])) {
|
||||
$url .= '&directory=' . urlencode(html_entity_decode($this->request->get['directory'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_name'])) {
|
||||
$url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['target'])) {
|
||||
$url .= '&target=' . $this->request->get['target'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['thumb'])) {
|
||||
$url .= '&thumb=' . $this->request->get['thumb'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['ckeditor'])) {
|
||||
$url .= '&ckeditor=' . $this->request->get['ckeditor'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['refresh'] = $this->url->link('common/filemanager.list', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['directory'])) {
|
||||
$url .= '&directory=' . urlencode(html_entity_decode($this->request->get['directory'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_name'])) {
|
||||
$url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['target'])) {
|
||||
$url .= '&target=' . $this->request->get['target'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['thumb'])) {
|
||||
$url .= '&thumb=' . $this->request->get['thumb'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['ckeditor'])) {
|
||||
$url .= '&ckeditor=' . $this->request->get['ckeditor'];
|
||||
}
|
||||
|
||||
// Get total number of files and directories
|
||||
$data['pagination'] = $this->load->controller('common/pagination', [
|
||||
'total' => $total,
|
||||
'page' => $page,
|
||||
'limit' => $limit,
|
||||
'url' => $this->url->link('common/filemanager.list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}')
|
||||
]);
|
||||
|
||||
$this->response->setOutput($this->load->view('common/filemanager_list', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function upload(): void {
|
||||
$this->load->language('common/filemanager');
|
||||
|
||||
$json = [];
|
||||
|
||||
$base = DIR_IMAGE . 'catalog/';
|
||||
|
||||
// Check user has permission
|
||||
if (!$this->user->hasPermission('modify', 'common/filemanager')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
// Make sure we have the correct directory
|
||||
if (isset($this->request->get['directory'])) {
|
||||
$directory = $base . html_entity_decode($this->request->get['directory'], ENT_QUOTES, 'UTF-8') . '/';
|
||||
} else {
|
||||
$directory = $base;
|
||||
}
|
||||
|
||||
// Check it's a directory
|
||||
if (!is_dir($directory) || substr(str_replace('\\', '/', realpath($directory)) . '/', 0, strlen($base)) != $base) {
|
||||
$json['error'] = $this->language->get('error_directory');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
// Check if multiple files are uploaded or just one
|
||||
$files = [];
|
||||
|
||||
if (!empty($this->request->files['file']['name']) && is_array($this->request->files['file']['name'])) {
|
||||
foreach (array_keys($this->request->files['file']['name']) as $key) {
|
||||
$files[] = [
|
||||
'name' => $this->request->files['file']['name'][$key],
|
||||
'type' => $this->request->files['file']['type'][$key],
|
||||
'tmp_name' => $this->request->files['file']['tmp_name'][$key],
|
||||
'error' => $this->request->files['file']['error'][$key],
|
||||
'size' => $this->request->files['file']['size'][$key]
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($files as $file) {
|
||||
if (is_file($file['tmp_name'])) {
|
||||
// Sanitize the filename
|
||||
$filename = preg_replace('[/\\?%*:|"<>]', '', basename(html_entity_decode($file['name'], ENT_QUOTES, 'UTF-8')));
|
||||
|
||||
// Validate the filename length
|
||||
if ((oc_strlen($filename) < 4) || (oc_strlen($filename) > 255)) {
|
||||
$json['error'] = $this->language->get('error_filename');
|
||||
}
|
||||
|
||||
// Allowed file extension types
|
||||
$allowed = [
|
||||
'ico',
|
||||
'jpg',
|
||||
'jpeg',
|
||||
'png',
|
||||
'gif',
|
||||
'webp',
|
||||
'JPG',
|
||||
'JPEG',
|
||||
'PNG',
|
||||
'GIF'
|
||||
];
|
||||
|
||||
if (!in_array(substr($filename, strrpos($filename, '.') + 1), $allowed)) {
|
||||
$json['error'] = $this->language->get('error_file_type');
|
||||
}
|
||||
|
||||
// Allowed file mime types
|
||||
$allowed = [
|
||||
'image/x-icon',
|
||||
'image/jpeg',
|
||||
'image/pjpeg',
|
||||
'image/png',
|
||||
'image/x-png',
|
||||
'image/gif',
|
||||
'image/webp'
|
||||
];
|
||||
|
||||
if (!in_array($file['type'], $allowed)) {
|
||||
$json['error'] = $this->language->get('error_file_type');
|
||||
}
|
||||
|
||||
// Return any upload error
|
||||
if ($file['error'] != UPLOAD_ERR_OK) {
|
||||
$json['error'] = $this->language->get('error_upload_' . $file['error']);
|
||||
}
|
||||
} else {
|
||||
$json['error'] = $this->language->get('error_upload');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
move_uploaded_file($file['tmp_name'], $directory . $filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$json['success'] = $this->language->get('text_uploaded');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function folder(): void {
|
||||
$this->load->language('common/filemanager');
|
||||
|
||||
$json = [];
|
||||
|
||||
$base = DIR_IMAGE . 'catalog/';
|
||||
|
||||
// Check user has permission
|
||||
if (!$this->user->hasPermission('modify', 'common/filemanager')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
// Make sure we have the correct directory
|
||||
if (isset($this->request->get['directory'])) {
|
||||
$directory = $base . html_entity_decode($this->request->get['directory'], ENT_QUOTES, 'UTF-8') . '/';
|
||||
} else {
|
||||
$directory = $base;
|
||||
}
|
||||
|
||||
// Check its a directory
|
||||
if (!is_dir($directory) || substr(str_replace('\\', '/', realpath($directory)) . '/', 0, strlen($base)) != $base) {
|
||||
$json['error'] = $this->language->get('error_directory');
|
||||
}
|
||||
|
||||
if ($this->request->server['REQUEST_METHOD'] == 'POST') {
|
||||
// Sanitize the folder name
|
||||
$folder = preg_replace('[/\\?%*&:|"<>]', '', basename(html_entity_decode($this->request->post['folder'], ENT_QUOTES, 'UTF-8')));
|
||||
|
||||
// Validate the filename length
|
||||
if ((oc_strlen($folder) < 3) || (oc_strlen($folder) > 128)) {
|
||||
$json['error'] = $this->language->get('error_folder');
|
||||
}
|
||||
|
||||
// Check if directory already exists or not
|
||||
if (is_dir($directory . $folder)) {
|
||||
$json['error'] = $this->language->get('error_exists');
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
mkdir($directory . '/' . $folder, 0777);
|
||||
|
||||
chmod($directory . '/' . $folder, 0777);
|
||||
|
||||
@touch($directory . '/' . $folder . '/' . 'index.html');
|
||||
|
||||
$json['success'] = $this->language->get('text_directory');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function delete(): void {
|
||||
$this->load->language('common/filemanager');
|
||||
|
||||
$json = [];
|
||||
|
||||
$base = DIR_IMAGE . 'catalog/';
|
||||
|
||||
// Check user has permission
|
||||
if (!$this->user->hasPermission('modify', 'common/filemanager')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (isset($this->request->post['path'])) {
|
||||
$paths = $this->request->post['path'];
|
||||
} else {
|
||||
$paths = [];
|
||||
}
|
||||
|
||||
// Loop through each path to run validations
|
||||
foreach ($paths as $path) {
|
||||
// Convert any html encoded characters.
|
||||
$path = html_entity_decode($path, ENT_QUOTES, 'UTF-8');
|
||||
|
||||
// Check path exists
|
||||
if (($path == $base) || (substr(str_replace('\\', '/', realpath($base . $path)) . '/', 0, strlen($base)) != $base)) {
|
||||
$json['error'] = $this->language->get('error_delete');
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
// Loop through each path
|
||||
foreach ($paths as $path) {
|
||||
$path = rtrim($base . html_entity_decode($path, ENT_QUOTES, 'UTF-8'), '/');
|
||||
|
||||
$files = [];
|
||||
|
||||
// Make path into an array
|
||||
$directory = [$path];
|
||||
|
||||
// While the path array is still populated keep looping through
|
||||
while (count($directory) != 0) {
|
||||
$next = array_shift($directory);
|
||||
|
||||
if (is_dir($next)) {
|
||||
foreach (glob(trim($next, '/') . '/{*,.[!.]*,..?*}', GLOB_BRACE) as $file) {
|
||||
// If directory add to path array
|
||||
$directory[] = $file;
|
||||
}
|
||||
}
|
||||
|
||||
// Add the file to the files to be deleted array
|
||||
$files[] = $next;
|
||||
}
|
||||
|
||||
// Reverse sort the file array
|
||||
rsort($files);
|
||||
|
||||
foreach ($files as $file) {
|
||||
// If file just delete
|
||||
if (is_file($file)) {
|
||||
unlink($file);
|
||||
}
|
||||
|
||||
// If directory use the remove directory function
|
||||
if (is_dir($file)) {
|
||||
rmdir($file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_delete');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
25
admininistrator/controller/common/footer.php
Normal file
25
admininistrator/controller/common/footer.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Common;
|
||||
/**
|
||||
* Class Footer
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Common
|
||||
*/
|
||||
class Footer extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function index(): string {
|
||||
$this->load->language('common/footer');
|
||||
|
||||
if ($this->user->isLogged() && isset($this->request->get['user_token']) && ($this->request->get['user_token'] == $this->session->data['user_token'])) {
|
||||
$data['text_version'] = sprintf($this->language->get('text_version'), VERSION);
|
||||
} else {
|
||||
$data['text_version'] = '';
|
||||
}
|
||||
|
||||
$data['bootstrap'] = 'view/javascript/bootstrap/js/bootstrap.bundle.min.js';
|
||||
|
||||
return $this->load->view('common/footer', $data);
|
||||
}
|
||||
}
|
214
admininistrator/controller/common/forgotten.php
Normal file
214
admininistrator/controller/common/forgotten.php
Normal file
@ -0,0 +1,214 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Common;
|
||||
/**
|
||||
* Class Forgotten
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Common
|
||||
*/
|
||||
class Forgotten extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('common/forgotten');
|
||||
|
||||
if ($this->user->isLogged() || !$this->config->get('config_mail_engine')) {
|
||||
$this->response->redirect($this->url->link('common/login', '', true));
|
||||
}
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard')
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('common/forgotten')
|
||||
];
|
||||
|
||||
$data['confirm'] = $this->url->link('common/forgotten.confirm');
|
||||
$data['back'] = $this->url->link('common/login');
|
||||
|
||||
$data['header'] = $this->load->controller('common/header');
|
||||
$data['footer'] = $this->load->controller('common/footer');
|
||||
|
||||
$this->response->setOutput($this->load->view('common/forgotten', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function confirm(): void {
|
||||
$this->load->language('common/forgotten');
|
||||
|
||||
$json = [];
|
||||
|
||||
// Stop any undefined index messages.
|
||||
if ($this->user->isLogged() || !$this->config->get('config_mail_engine')) {
|
||||
$json['redirect'] = $this->url->link('common/login', '', true);
|
||||
}
|
||||
|
||||
$keys = ['email'];
|
||||
|
||||
foreach ($keys as $key) {
|
||||
if (!isset($this->request->post[$key])) {
|
||||
$this->request->post[$key] = '';
|
||||
}
|
||||
}
|
||||
|
||||
$this->load->model('user/user');
|
||||
|
||||
$user_info = $this->model_user_user->getUserByEmail($this->request->post['email']);
|
||||
|
||||
if (!$user_info) {
|
||||
$json['error'] = $this->language->get('error_email');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->model_user_user->editCode($this->request->post['email'], oc_token(40));
|
||||
|
||||
$this->session->data['success'] = $this->language->get('text_success');
|
||||
|
||||
$json['redirect'] = $this->url->link('common/login', '', true);
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function reset(): void {
|
||||
$this->load->language('common/forgotten');
|
||||
|
||||
if (isset($this->request->get['email'])) {
|
||||
$email = (string)$this->request->get['email'];
|
||||
} else {
|
||||
$email = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['code'])) {
|
||||
$code = (string)$this->request->get['code'];
|
||||
} else {
|
||||
$code = '';
|
||||
}
|
||||
|
||||
if ($this->user->isLogged() || !$this->config->get('config_mail_engine')) {
|
||||
$this->response->redirect($this->url->link('common/login', '', true));
|
||||
}
|
||||
|
||||
$this->load->model('user/user');
|
||||
|
||||
$user_info = $this->model_user_user->getUserByEmail($email);
|
||||
|
||||
if (!$user_info || !$user_info['code'] || $user_info['code'] !== $code) {
|
||||
$this->model_user_user->editCode($email, '');
|
||||
|
||||
$this->session->data['error'] = $this->language->get('error_code');
|
||||
|
||||
$this->response->redirect($this->url->link('common/login', '', true));
|
||||
}
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_reset'));
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard')
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('common/forgotten.reset')
|
||||
];
|
||||
|
||||
$this->session->data['reset_token'] = substr(bin2hex(openssl_random_pseudo_bytes(26)), 0, 26);
|
||||
|
||||
$data['reset'] = $this->url->link('common/forgotten.password', 'email=' . urlencode($email) . '&code=' . $code . '&reset_token=' . $this->session->data['reset_token']);
|
||||
$data['back'] = $this->url->link('common/login');
|
||||
|
||||
$data['header'] = $this->load->controller('common/header');
|
||||
$data['footer'] = $this->load->controller('common/footer');
|
||||
|
||||
$this->response->setOutput($this->load->view('common/forgotten_reset', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function password(): void {
|
||||
$this->load->language('common/forgotten');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->get['email'])) {
|
||||
$email = (string)$this->request->get['email'];
|
||||
} else {
|
||||
$email = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['code'])) {
|
||||
$code = (string)$this->request->get['code'];
|
||||
} else {
|
||||
$code = '';
|
||||
}
|
||||
|
||||
$keys = [
|
||||
'password',
|
||||
'confirm'
|
||||
];
|
||||
|
||||
foreach ($keys as $key) {
|
||||
if (!isset($this->request->post[$key])) {
|
||||
$this->request->post[$key] = '';
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($this->request->get['reset_token']) || !isset($this->session->data['reset_token']) || ($this->session->data['reset_token'] != $this->request->get['reset_token'])) {
|
||||
$this->session->data['error'] = $this->language->get('error_session');
|
||||
|
||||
$json['redirect'] = $this->url->link('account/forgotten', true);
|
||||
}
|
||||
|
||||
$this->load->model('user/user');
|
||||
|
||||
$user_info = $this->model_user_user->getUserByEmail($email);
|
||||
|
||||
if (!$user_info || !$user_info['code'] || $user_info['code'] !== $code) {
|
||||
$this->model_user_user->editCode($email, '');
|
||||
|
||||
$this->session->data['error'] = $this->language->get('error_code');
|
||||
|
||||
$json['redirect'] = $this->url->link('common/login', '', true);
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
if ((oc_strlen(html_entity_decode($this->request->post['password'], ENT_QUOTES, 'UTF-8')) < 4) || (oc_strlen(html_entity_decode($this->request->post['password'], ENT_QUOTES, 'UTF-8')) > 40)) {
|
||||
$json['error']['password'] = $this->language->get('error_password');
|
||||
}
|
||||
|
||||
if ($this->request->post['confirm'] != $this->request->post['password']) {
|
||||
$json['error']['confirm'] = $this->language->get('error_confirm');
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->model_user_user->editPassword($user_info['user_id'], $this->request->post['password']);
|
||||
|
||||
$this->session->data['success'] = $this->language->get('text_reset');
|
||||
|
||||
unset($this->session->data['reset_token']);
|
||||
|
||||
$json['redirect'] = $this->url->link('common/login', '', true);
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
117
admininistrator/controller/common/header.php
Normal file
117
admininistrator/controller/common/header.php
Normal file
@ -0,0 +1,117 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Common;
|
||||
/**
|
||||
* Class Header
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Common
|
||||
*/
|
||||
class Header extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function index(): string {
|
||||
$data['lang'] = $this->language->get('code');
|
||||
$data['direction'] = $this->language->get('direction');
|
||||
|
||||
$data['title'] = $this->document->getTitle();
|
||||
$data['base'] = HTTP_SERVER;
|
||||
$data['description'] = $this->document->getDescription();
|
||||
$data['keywords'] = $this->document->getKeywords();
|
||||
|
||||
// Hard coding css so they can be replaced via the event's system.
|
||||
$data['bootstrap'] = 'view/stylesheet/bootstrap.css';
|
||||
$data['icons'] = 'view/stylesheet/fonts/fontawesome/css/all.min.css';
|
||||
$data['stylesheet'] = 'view/stylesheet/stylesheet.css';
|
||||
|
||||
// Hard coding scripts so they can be replaced via the event's system.
|
||||
$data['jquery'] = 'view/javascript/jquery/jquery-3.7.1.min.js';
|
||||
|
||||
$data['links'] = $this->document->getLinks();
|
||||
$data['styles'] = $this->document->getStyles();
|
||||
$data['scripts'] = $this->document->getScripts();
|
||||
|
||||
$this->load->language('common/header');
|
||||
|
||||
if (!isset($this->request->get['user_token']) || !isset($this->session->data['user_token']) || ($this->request->get['user_token'] != $this->session->data['user_token'])) {
|
||||
$data['logged'] = false;
|
||||
|
||||
$data['home'] = $this->url->link('common/login');
|
||||
} else {
|
||||
$data['logged'] = true;
|
||||
|
||||
$data['home'] = $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token']);
|
||||
|
||||
$data['language'] = $this->load->controller('common/language');
|
||||
|
||||
// Notifications
|
||||
$filter_data = [
|
||||
'start' => 0,
|
||||
'limit' => 5
|
||||
];
|
||||
|
||||
$data['notifications'] = [];
|
||||
|
||||
$this->load->model('tool/notification');
|
||||
|
||||
$results = $this->model_tool_notification->getNotifications($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$data['notifications'][] = [
|
||||
'title' => $result['title'],
|
||||
'href' => $this->url->link('tool/notification.info', 'user_token=' . $this->session->data['user_token'] . '¬ification_id=' . $result['notification_id'])
|
||||
];
|
||||
}
|
||||
|
||||
$data['notification_all'] = $this->url->link('tool/notification', 'user_token=' . $this->session->data['user_token']);
|
||||
$data['notification_total'] = $this->model_tool_notification->getTotalNotifications(['filter_status' => 0]);
|
||||
|
||||
$data['profile'] = $this->url->link('user/profile', 'user_token=' . $this->session->data['user_token']);
|
||||
|
||||
$this->load->model('tool/image');
|
||||
|
||||
$data['image'] = $this->model_tool_image->resize('profile.png', 45, 45);
|
||||
|
||||
$this->load->model('user/user');
|
||||
|
||||
$user_info = $this->model_user_user->getUser($this->user->getId());
|
||||
|
||||
if ($user_info) {
|
||||
$data['firstname'] = $user_info['firstname'];
|
||||
$data['lastname'] = $user_info['lastname'];
|
||||
$data['username'] = $user_info['username'];
|
||||
$data['user_group'] = $user_info['user_group'];
|
||||
|
||||
if (is_file(DIR_IMAGE . html_entity_decode($user_info['image'], ENT_QUOTES, 'UTF-8'))) {
|
||||
$data['image'] = $this->model_tool_image->resize(html_entity_decode($user_info['image'], ENT_QUOTES, 'UTF-8'), 45, 45);
|
||||
}
|
||||
} else {
|
||||
$data['firstname'] = '';
|
||||
$data['lastname'] = '';
|
||||
$data['user_group'] = '';
|
||||
}
|
||||
|
||||
// Stores
|
||||
$data['stores'] = [];
|
||||
|
||||
$data['stores'][] = [
|
||||
'name' => $this->config->get('config_name'),
|
||||
'href' => HTTP_CATALOG
|
||||
];
|
||||
|
||||
$this->load->model('setting/store');
|
||||
|
||||
$results = $this->model_setting_store->getStores();
|
||||
|
||||
foreach ($results as $result) {
|
||||
$data['stores'][] = [
|
||||
'name' => $result['name'],
|
||||
'href' => $result['url']
|
||||
];
|
||||
}
|
||||
|
||||
$data['logout'] = $this->url->link('common/logout', 'user_token=' . $this->session->data['user_token']);
|
||||
}
|
||||
|
||||
return $this->load->view('common/header', $data);
|
||||
}
|
||||
}
|
98
admininistrator/controller/common/language.php
Normal file
98
admininistrator/controller/common/language.php
Normal file
@ -0,0 +1,98 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Common;
|
||||
/**
|
||||
* Class Language
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Common
|
||||
*/
|
||||
class Language extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function index(): string {
|
||||
$data['languages'] = [];
|
||||
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
$results = $this->model_localisation_language->getLanguages();
|
||||
|
||||
foreach ($results as $result) {
|
||||
$data['languages'][] = [
|
||||
'name' => $result['name'],
|
||||
'code' => $result['code'],
|
||||
'image' => $result['image']
|
||||
];
|
||||
}
|
||||
|
||||
if (isset($this->request->cookie['language'])) {
|
||||
$data['code'] = $this->request->cookie['language'];
|
||||
} else {
|
||||
$data['code'] = $this->config->get('config_language');
|
||||
}
|
||||
|
||||
// Redirect
|
||||
$url_data = $this->request->get;
|
||||
|
||||
if (isset($url_data['route'])) {
|
||||
$route = $url_data['route'];
|
||||
} else {
|
||||
$route = 'common/dashboard';
|
||||
}
|
||||
|
||||
unset($url_data['route']);
|
||||
|
||||
$url = '';
|
||||
|
||||
if ($url_data) {
|
||||
$url .= '&' . urldecode(http_build_query($url_data));
|
||||
}
|
||||
|
||||
$data['redirect'] = $this->url->link($route, $url);
|
||||
|
||||
$data['user_token'] = $this->session->data['user_token'];
|
||||
|
||||
return $this->load->view('common/language', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function save(): void {
|
||||
$this->load->language('common/language');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->post['code'])) {
|
||||
$code = $this->request->post['code'];
|
||||
} else {
|
||||
$code = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->post['redirect'])) {
|
||||
$redirect = htmlspecialchars_decode($this->request->post['redirect'], ENT_COMPAT);
|
||||
} else {
|
||||
$redirect = '';
|
||||
}
|
||||
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
$language_info = $this->model_localisation_language->getLanguageByCode($code);
|
||||
|
||||
if (!$language_info) {
|
||||
$json['error'] = $this->language->get('error_language');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
setcookie('language', $code, time() + 60 * 60 * 24 * 365 * 10);
|
||||
|
||||
if ($redirect && substr($redirect, 0, strlen($this->config->get('config_url'))) == $this->config->get('config_url')) {
|
||||
$json['redirect'] = $redirect;
|
||||
} else {
|
||||
$json['redirect'] = $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true);
|
||||
}
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
137
admininistrator/controller/common/login.php
Normal file
137
admininistrator/controller/common/login.php
Normal file
@ -0,0 +1,137 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Common;
|
||||
/**
|
||||
* Class Login
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Common
|
||||
*/
|
||||
class Login extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('common/login');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
// Check to see if user is already logged
|
||||
if ($this->user->isLogged() && isset($this->request->get['user_token']) && isset($this->session->data['user_token']) && ($this->request->get['user_token'] == $this->session->data['user_token'])) {
|
||||
$this->response->redirect($this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true));
|
||||
}
|
||||
|
||||
// Check to see if user is using incorrect token
|
||||
if (isset($this->request->get['user_token']) && (!isset($this->session->data['user_token']) || ($this->request->get['user_token'] != $this->session->data['user_token']))) {
|
||||
$data['error_warning'] = $this->language->get('error_token');
|
||||
} elseif (isset($this->session->data['error'])) {
|
||||
$data['error_warning'] = $this->session->data['error'];
|
||||
|
||||
unset($this->session->data['error']);
|
||||
} else {
|
||||
$data['error_warning'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->session->data['success'])) {
|
||||
$data['success'] = $this->session->data['success'];
|
||||
|
||||
unset($this->session->data['success']);
|
||||
} else {
|
||||
$data['success'] = '';
|
||||
}
|
||||
|
||||
// Create a login token to prevent brute force attacks
|
||||
$this->session->data['login_token'] = oc_token(32);
|
||||
|
||||
$data['login'] = $this->url->link('common/login.login', 'login_token=' . $this->session->data['login_token'], true);
|
||||
|
||||
if ($this->config->get('config_mail_engine')) {
|
||||
$data['forgotten'] = $this->url->link('common/forgotten');
|
||||
} else {
|
||||
$data['forgotten'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['route']) && $this->request->get['route'] != 'common/login') {
|
||||
$args = $this->request->get;
|
||||
|
||||
$route = $args['route'];
|
||||
|
||||
unset($args['route']);
|
||||
unset($args['user_token']);
|
||||
|
||||
$url = '';
|
||||
|
||||
if ($this->request->get) {
|
||||
$url .= http_build_query($args);
|
||||
}
|
||||
|
||||
$data['redirect'] = $this->url->link($route, $url);
|
||||
} else {
|
||||
$data['redirect'] = '';
|
||||
}
|
||||
|
||||
$data['header'] = $this->load->controller('common/header');
|
||||
$data['footer'] = $this->load->controller('common/footer');
|
||||
|
||||
$this->response->setOutput($this->load->view('common/login', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function login(): void {
|
||||
$this->load->language('common/login');
|
||||
|
||||
$json = [];
|
||||
|
||||
// Stop any undefined index messages.
|
||||
$keys = [
|
||||
'username',
|
||||
'password',
|
||||
'redirect'
|
||||
];
|
||||
|
||||
foreach ($keys as $key) {
|
||||
if (!isset($this->request->post[$key])) {
|
||||
$this->request->post[$key] = '';
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->user->isLogged() && isset($this->request->get['user_token']) && isset($this->session->data['user_token']) && ($this->request->get['user_token'] == $this->session->data['user_token'])) {
|
||||
$json['redirect'] = $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true);
|
||||
}
|
||||
|
||||
if (!isset($this->request->get['login_token']) || !isset($this->session->data['login_token']) || $this->request->get['login_token'] != $this->session->data['login_token']) {
|
||||
$this->session->data['error'] = $this->language->get('error_login');
|
||||
|
||||
$json['redirect'] = $this->url->link('common/login', '', true);
|
||||
}
|
||||
|
||||
if (!$json && !$this->user->login($this->request->post['username'], html_entity_decode($this->request->post['password'], ENT_QUOTES, 'UTF-8'))) {
|
||||
$json['error'] = $this->language->get('error_login');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->session->data['user_token'] = oc_token(32);
|
||||
|
||||
// Remove login token so it cannot be used again.
|
||||
unset($this->session->data['login_token']);
|
||||
|
||||
$login_data = [
|
||||
'ip' => $this->request->server['REMOTE_ADDR'],
|
||||
'user_agent' => $this->request->server['HTTP_USER_AGENT']
|
||||
];
|
||||
|
||||
$this->load->model('user/user');
|
||||
|
||||
$this->model_user_user->addLogin($this->user->getId(), $login_data);
|
||||
|
||||
if ($this->request->post['redirect'] && (strpos($this->request->post['redirect'], HTTP_SERVER) === 0)) {
|
||||
$json['redirect'] = str_replace('&', '&', $this->request->post['redirect'] . '&user_token=' . $this->session->data['user_token']);
|
||||
} else {
|
||||
$json['redirect'] = $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true);
|
||||
}
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
19
admininistrator/controller/common/logout.php
Normal file
19
admininistrator/controller/common/logout.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Common;
|
||||
/**
|
||||
* Class Logout
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Common
|
||||
*/
|
||||
class Logout extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->user->logout();
|
||||
|
||||
unset($this->session->data['user_token']);
|
||||
|
||||
$this->response->redirect($this->url->link('common/login', '', true));
|
||||
}
|
||||
}
|
106
admininistrator/controller/common/pagination.php
Normal file
106
admininistrator/controller/common/pagination.php
Normal file
@ -0,0 +1,106 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Common;
|
||||
/**
|
||||
* Class Pagination
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Common
|
||||
*/
|
||||
class Pagination extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @param array $setting
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function index(array $setting): string {
|
||||
if (isset($setting['total'])) {
|
||||
$total = $setting['total'];
|
||||
} else {
|
||||
$total = 0;
|
||||
}
|
||||
|
||||
if (isset($setting['page']) && $setting['page'] > 0) {
|
||||
$page = (int)$setting['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
if (isset($setting['limit']) && (int)$setting['limit']) {
|
||||
$limit = (int)$setting['limit'];
|
||||
} else {
|
||||
$limit = 10;
|
||||
}
|
||||
|
||||
if (isset($setting['url'])) {
|
||||
$url = str_replace('%7Bpage%7D', '{page}', (string)$setting['url']);
|
||||
} else {
|
||||
$url = '';
|
||||
}
|
||||
|
||||
$num_links = 8;
|
||||
$num_pages = ceil($total / $limit);
|
||||
|
||||
if ($url && $page > 1 && $num_pages < $page) {
|
||||
$back = true;
|
||||
} else {
|
||||
$back = false;
|
||||
}
|
||||
|
||||
$data['page'] = $page;
|
||||
|
||||
if ($page > 1) {
|
||||
$data['first'] = str_replace(['&page={page}', '?page={page}', '&page={page}'], '', $url);
|
||||
|
||||
if ($page - 1 === 1) {
|
||||
$data['prev'] = str_replace(['&page={page}', '?page={page}', '&page={page}'], '', $url);
|
||||
} else {
|
||||
$data['prev'] = str_replace('{page}', $page - 1, $url);
|
||||
}
|
||||
} else {
|
||||
$data['first'] = '';
|
||||
$data['prev'] = '';
|
||||
}
|
||||
|
||||
$data['links'] = [];
|
||||
|
||||
if ($num_pages > 1) {
|
||||
if ($num_pages <= $num_links) {
|
||||
$start = 1;
|
||||
$end = $num_pages;
|
||||
} else {
|
||||
$start = $page - floor($num_links / 2);
|
||||
$end = $page + floor($num_links / 2);
|
||||
|
||||
if ($start < 1) {
|
||||
$end += abs($start) + 1;
|
||||
$start = 1;
|
||||
}
|
||||
|
||||
if ($end > $num_pages) {
|
||||
$start -= ($end - $num_pages);
|
||||
$end = $num_pages;
|
||||
}
|
||||
}
|
||||
|
||||
for ($i = $start; $i <= $end; $i++) {
|
||||
$data['links'][] = [
|
||||
'page' => $i,
|
||||
'href' => str_replace('{page}', $i, $url)
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
if ($num_pages > $page) {
|
||||
$data['next'] = str_replace('{page}', $page + 1, $url);
|
||||
$data['last'] = str_replace('{page}', $num_pages, $url);
|
||||
} else {
|
||||
$data['next'] = '';
|
||||
$data['last'] = '';
|
||||
}
|
||||
|
||||
if ($num_pages > 1 || $back) {
|
||||
return $this->load->view('common/pagination', $data);
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
455
admininistrator/controller/common/security.php
Normal file
455
admininistrator/controller/common/security.php
Normal file
@ -0,0 +1,455 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Common;
|
||||
/**
|
||||
* Class Security
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Common
|
||||
*/
|
||||
class Security extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function index(): string {
|
||||
$this->load->language('common/security');
|
||||
|
||||
// Check install directory exists
|
||||
if (is_dir(DIR_OPENCART . 'install/')) {
|
||||
$data['install'] = DIR_OPENCART . 'install/';
|
||||
} else {
|
||||
$data['install'] = '';
|
||||
}
|
||||
|
||||
// Check storage directory exists
|
||||
if (DIR_STORAGE == DIR_SYSTEM . 'storage/') {
|
||||
// Check install directory exists
|
||||
$data['storage'] = DIR_STORAGE;
|
||||
|
||||
$data['document_root'] = str_replace('\\', '/', realpath($this->request->server['DOCUMENT_ROOT'] . '/../')) . '/';
|
||||
|
||||
$path = '';
|
||||
|
||||
$data['paths'] = [];
|
||||
|
||||
$parts = explode('/', rtrim($data['document_root'], '/'));
|
||||
|
||||
foreach ($parts as $part) {
|
||||
$path .= $part . '/';
|
||||
|
||||
$data['paths'][] = $path;
|
||||
}
|
||||
|
||||
rsort($data['paths']);
|
||||
} else {
|
||||
$data['storage'] = '';
|
||||
}
|
||||
|
||||
// Check admin directory ia renamed
|
||||
if (DIR_APPLICATION == DIR_OPENCART . 'admin/') {
|
||||
$data['admin'] = 'admin';
|
||||
} else {
|
||||
$data['admin'] = '';
|
||||
}
|
||||
|
||||
$data['user_token'] = $this->session->data['user_token'];
|
||||
|
||||
if ($data['install'] || $data['storage'] || $data['admin']) {
|
||||
return $this->load->view('common/security', $data);
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function install(): void {
|
||||
$this->load->language('common/security');
|
||||
|
||||
$json = [];
|
||||
|
||||
if ($this->user->hasPermission('modify', 'common/security')) {
|
||||
if (!is_dir(DIR_OPENCART . 'install/')) {
|
||||
$json['error'] = $this->language->get('error_install');
|
||||
}
|
||||
} else {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$files = [];
|
||||
|
||||
$path = DIR_OPENCART . 'install/';
|
||||
|
||||
// Make path into an array
|
||||
$directory = [$path];
|
||||
|
||||
// While the path array is still populated keep looping through
|
||||
while (count($directory) != 0) {
|
||||
$next = array_shift($directory);
|
||||
|
||||
if (is_dir($next)) {
|
||||
foreach (glob(rtrim($next, '/') . '/{*,.[!.]*,..?*}', GLOB_BRACE) as $file) {
|
||||
// If directory add to path array
|
||||
if (is_dir($file)) {
|
||||
$directory[] = $file;
|
||||
}
|
||||
|
||||
// Add the file to the files to be deleted array
|
||||
$files[] = $file;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rsort($files);
|
||||
|
||||
foreach ($files as $file) {
|
||||
if (is_file($file)) {
|
||||
unlink($file);
|
||||
} elseif (is_dir($file)) {
|
||||
rmdir($file);
|
||||
}
|
||||
}
|
||||
|
||||
rmdir($path);
|
||||
|
||||
$json['success'] = $this->language->get('text_install_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function storage(): void {
|
||||
$this->load->language('common/security');
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
if (isset($this->request->get['name'])) {
|
||||
$name = preg_replace('[^a-zA-z0-9_]', '', basename(html_entity_decode(trim($this->request->get['name']), ENT_QUOTES, 'UTF-8')));
|
||||
} else {
|
||||
$name = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['path'])) {
|
||||
$path = preg_replace('[^a-zA-z0-9_\:\/]', '', html_entity_decode(trim($this->request->get['path']), ENT_QUOTES, 'UTF-8'));
|
||||
} else {
|
||||
$path = '';
|
||||
}
|
||||
|
||||
$json = [];
|
||||
|
||||
if ($this->user->hasPermission('modify', 'common/security')) {
|
||||
$base_old = DIR_STORAGE;
|
||||
$base_new = $path . $name . '/';
|
||||
|
||||
if (!is_dir($base_old)) {
|
||||
$json['error'] = $this->language->get('error_storage');
|
||||
}
|
||||
|
||||
$root = str_replace('\\', '/', realpath($this->request->server['DOCUMENT_ROOT'] . '/../'));
|
||||
|
||||
if ((substr($base_new, 0, strlen($root)) != $root) || ($root == $base_new)) {
|
||||
$json['error'] = $this->language->get('error_storage');
|
||||
}
|
||||
|
||||
if (is_dir($base_new) && $page < 2) {
|
||||
$json['error'] = $this->language->get('error_storage_exists');
|
||||
}
|
||||
|
||||
if (!is_writable(DIR_OPENCART . 'config.php') || !is_writable(DIR_APPLICATION . 'config.php')) {
|
||||
$json['error'] = $this->language->get('error_writable');
|
||||
}
|
||||
} else {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$files = [];
|
||||
|
||||
// Make path into an array
|
||||
$directory = [$base_old];
|
||||
|
||||
// While the path array is still populated keep looping through
|
||||
while (count($directory) != 0) {
|
||||
$next = array_shift($directory);
|
||||
|
||||
foreach (glob(rtrim($next, '/') . '/{*,.[!.]*,..?*}', GLOB_BRACE) as $file) {
|
||||
// If directory add to path array
|
||||
if (is_dir($file)) {
|
||||
$directory[] = $file;
|
||||
}
|
||||
|
||||
// Add the file to the files to be deleted array
|
||||
$files[] = $file;
|
||||
}
|
||||
}
|
||||
|
||||
// Create the new storage folder
|
||||
if (!is_dir($base_new)) {
|
||||
mkdir($base_new, 0777);
|
||||
}
|
||||
|
||||
// Copy the
|
||||
$total = count($files);
|
||||
$limit = 200;
|
||||
|
||||
$start = ($page - 1) * $limit;
|
||||
$end = $start > ($total - $limit) ? $total : ($start + $limit);
|
||||
|
||||
for ($i = $start; $i < $end; $i++) {
|
||||
$destination = substr($files[$i], strlen($base_old));
|
||||
|
||||
if (is_dir($base_old . $destination) && !is_dir($base_new . $destination)) {
|
||||
mkdir($base_new . $destination, 0777);
|
||||
}
|
||||
|
||||
if (is_file($base_old . $destination) && !is_file($base_new . $destination)) {
|
||||
copy($base_old . $destination, $base_new . $destination);
|
||||
}
|
||||
}
|
||||
|
||||
if ($end < $total) {
|
||||
$json['next'] = $this->url->link('common/security.storage', '&user_token=' . $this->session->data['user_token'] . '&name=' . $name . '&path=' . $path . '&page=' . ($page + 1), true);
|
||||
} else {
|
||||
// Start deleting old storage location files.
|
||||
rsort($files);
|
||||
|
||||
foreach ($files as $file) {
|
||||
// If file just delete
|
||||
if (is_file($file)) {
|
||||
unlink($file);
|
||||
}
|
||||
|
||||
// If directory use the remove directory function
|
||||
if (is_dir($file)) {
|
||||
rmdir($file);
|
||||
}
|
||||
}
|
||||
|
||||
rmdir($base_old);
|
||||
|
||||
// Modify the config files
|
||||
$files = [
|
||||
DIR_APPLICATION . 'config.php',
|
||||
DIR_OPENCART . 'config.php'
|
||||
];
|
||||
|
||||
foreach ($files as $file) {
|
||||
$output = '';
|
||||
|
||||
$lines = file($file);
|
||||
|
||||
foreach ($lines as $line_id => $line) {
|
||||
if (strpos($line, 'define(\'DIR_STORAGE') !== false) {
|
||||
$output .= 'define(\'DIR_STORAGE\', \'' . $base_new . '\');' . "\n";
|
||||
} else {
|
||||
$output .= $line;
|
||||
}
|
||||
}
|
||||
|
||||
$file = fopen($file, 'w');
|
||||
|
||||
fwrite($file, $output);
|
||||
|
||||
fclose($file);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_storage_success');
|
||||
}
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function admin(): void {
|
||||
$this->load->language('common/security');
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
if (isset($this->request->get['name'])) {
|
||||
$name = preg_replace('[^a-zA-z0-9]', '', basename(html_entity_decode(trim((string)$this->request->get['name']), ENT_QUOTES, 'UTF-8')));
|
||||
} else {
|
||||
$name = 'admin';
|
||||
}
|
||||
|
||||
$json = [];
|
||||
|
||||
if ($this->user->hasPermission('modify', 'common/security')) {
|
||||
$base_old = DIR_OPENCART . 'admin/';
|
||||
$base_new = DIR_OPENCART . $name . '/';
|
||||
|
||||
if (!is_dir($base_old)) {
|
||||
$json['error'] = $this->language->get('error_admin');
|
||||
}
|
||||
|
||||
if (is_dir($base_new) && $page < 2) {
|
||||
$json['error'] = $this->language->get('error_admin_exists');
|
||||
}
|
||||
|
||||
if ($name == 'admin') {
|
||||
$json['error'] = $this->language->get('error_admin_name');
|
||||
}
|
||||
|
||||
if (!is_writable(DIR_OPENCART . 'config.php') || !is_writable(DIR_APPLICATION . 'config.php')) {
|
||||
$json['error'] = $this->language->get('error_writable');
|
||||
}
|
||||
} else {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
// 1. // 1. We need to copy the files, as rename cannot be used on any directory, the executing script is running under
|
||||
$files = [];
|
||||
|
||||
// Make path into an array
|
||||
$directory = [$base_old];
|
||||
|
||||
// While the path array is still populated keep looping through
|
||||
while (count($directory) != 0) {
|
||||
$next = array_shift($directory);
|
||||
|
||||
foreach (glob(rtrim($next, '/') . '/{*,.[!.]*,..?*}', GLOB_BRACE) as $file) {
|
||||
// If directory add to path array
|
||||
if (is_dir($file)) {
|
||||
$directory[] = $file;
|
||||
}
|
||||
|
||||
// Add the file to the files to be deleted array
|
||||
$files[] = $file;
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Create the new admin folder name
|
||||
if (!is_dir($base_new)) {
|
||||
mkdir($base_new, 0777);
|
||||
}
|
||||
|
||||
// 3. split the file copies into chunks.
|
||||
$total = count($files);
|
||||
$limit = 200;
|
||||
|
||||
$start = ($page - 1) * $limit;
|
||||
$end = $start > ($total - $limit) ? $total : ($start + $limit);
|
||||
|
||||
// 4. Copy the files across
|
||||
foreach (array_slice($files, $start, $end) as $file) {
|
||||
$destination = substr($file, strlen($base_old));
|
||||
|
||||
if (is_dir($base_old . $destination) && !is_dir($base_new . $destination)) {
|
||||
mkdir($base_new . $destination, 0777);
|
||||
}
|
||||
|
||||
if (is_file($base_old . $destination) && !is_file($base_new . $destination)) {
|
||||
copy($base_old . $destination, $base_new . $destination);
|
||||
}
|
||||
}
|
||||
|
||||
if (($page * $limit) <= $total) {
|
||||
$json['next'] = $this->url->link('common/security.admin', '&user_token=' . $this->session->data['user_token'] . '&name=' . $name . '&page=' . ($page + 1), true);
|
||||
} else {
|
||||
// Update the old config files
|
||||
$file = $base_new . 'config.php';
|
||||
|
||||
$output = '';
|
||||
|
||||
$lines = file($file);
|
||||
|
||||
foreach ($lines as $line_id => $line) {
|
||||
$status = true;
|
||||
|
||||
if (strpos($line, 'define(\'HTTP_SERVER') !== false) {
|
||||
$output .= 'define(\'HTTP_SERVER\', \'' . substr(HTTP_SERVER, 0, strrpos(HTTP_SERVER, '/admin/')) . '/' . $name . '/\');' . "\n";
|
||||
|
||||
$status = false;
|
||||
}
|
||||
|
||||
if (strpos($line, 'define(\'DIR_APPLICATION') !== false) {
|
||||
$output .= 'define(\'DIR_APPLICATION\', DIR_OPENCART . \'' . $name . '/\');' . "\n";
|
||||
|
||||
$status = false;
|
||||
}
|
||||
|
||||
if ($status) {
|
||||
$output .= $line;
|
||||
}
|
||||
}
|
||||
|
||||
$file = fopen($file, 'w');
|
||||
|
||||
fwrite($file, $output);
|
||||
|
||||
fclose($file);
|
||||
|
||||
// 6. redirect to the new admin
|
||||
$json['redirect'] = str_replace('&', '&', substr(HTTP_SERVER, 0, -6) . $name . '/index.php?route=common/login');
|
||||
}
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function __destruct() {
|
||||
// Remove old admin if exists
|
||||
$path = DIR_OPENCART . 'admin/';
|
||||
|
||||
if (is_dir($path) && DIR_APPLICATION != $path) {
|
||||
// 1. We need to copy the files, as rename cannot be used on any directory, the executing script is running under
|
||||
$files = [];
|
||||
|
||||
// Make path into an array
|
||||
$directory = [$path];
|
||||
|
||||
// While the path array is still populated keep looping through
|
||||
while (count($directory) != 0) {
|
||||
$next = array_shift($directory);
|
||||
|
||||
foreach (glob(rtrim($next, '/') . '/{*,.[!.]*,..?*}', GLOB_BRACE) as $file) {
|
||||
// If directory add to path array
|
||||
if (is_dir($file)) {
|
||||
$directory[] = $file;
|
||||
}
|
||||
|
||||
// Add the file to the files to be deleted array
|
||||
$files[] = $file;
|
||||
}
|
||||
}
|
||||
|
||||
// 4. reverse file order
|
||||
rsort($files);
|
||||
|
||||
// 5. Delete the old admin directory
|
||||
foreach ($files as $file) {
|
||||
// If file just delete
|
||||
if (is_file($file)) {
|
||||
unlink($file);
|
||||
}
|
||||
|
||||
// If directory use the remove directory function
|
||||
if (is_dir($file)) {
|
||||
rmdir($file);
|
||||
}
|
||||
}
|
||||
|
||||
rmdir($path);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user