Skip to content

Commit

Permalink
upadated error log
Browse files Browse the repository at this point in the history
  • Loading branch information
danielkerr committed Mar 21, 2022
1 parent 7856823 commit 23b9d53
Show file tree
Hide file tree
Showing 9 changed files with 170 additions and 75 deletions.
2 changes: 2 additions & 0 deletions upload/admin/controller/common/column_left.php
Expand Up @@ -749,6 +749,8 @@ public function index(): string {
}

return $this->load->view('common/column_left', $data);
} else {
return '';
}
}
}
7 changes: 4 additions & 3 deletions upload/admin/controller/common/forgotten.php
Expand Up @@ -22,6 +22,7 @@ public function index(): void {
'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');
Expand Down Expand Up @@ -53,7 +54,7 @@ public function confirm(): void {
$user_info = $this->model_user_user->getUserByEmail($this->request->post['email']);

if (!$user_info) {
$json['error'] = $this->language->get('error_not_found');
$json['error'] = $this->language->get('error_email');
}

if (!$json) {
Expand Down Expand Up @@ -115,7 +116,7 @@ public function reset(): void {

$this->session->data['reset_token'] = substr(bin2hex(openssl_random_pseudo_bytes(26)), 0, 26);

$data['reset'] = $this->url->link('account/forgotten|password', 'email=' . urlencode($email) . '&code=' . $code . '&reset_token=' . $this->session->data['reset_token']);
$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');
Expand All @@ -124,7 +125,7 @@ public function reset(): void {
$this->response->setOutput($this->load->view('common/forgotten_reset', $data));
}

public function password(): bool {
public function password(): void {
$this->load->language('common/forgotten');

$json = [];
Expand Down
35 changes: 34 additions & 1 deletion upload/admin/controller/mail/subscription.php
@@ -1,7 +1,35 @@
<?php
namespace Opencart\Admin\Controller\Mail;
class Customer extends \Opencart\System\Engine\Controller {
public function approve(string &$route, array &$args, mixed &$output): void {
public function index(string &$route, array &$args, mixed &$output): void {
if (isset($args[0])) {
$customer_id = $args[0];
} else {
$customer_id = 0;
}

if (isset($args[1])) {
$description = $args[1];
} else {
$description = '';
}

if (isset($args[2])) {
$amount = $args[2];
} else {
$amount = 0;
}

if (isset($args[3])) {
$order_id = $args[3];
} else {
$order_id = 0;
}





$this->load->model('customer/customer');

$customer_info = $this->model_customer_customer->getCustomer($args[0]);
Expand Down Expand Up @@ -77,4 +105,9 @@ public function approve(string &$route, array &$args, mixed &$output): void {
$mail->send();
}
}

public function cancel(string &$route, array &$args, mixed &$output): void {


}
}
5 changes: 1 addition & 4 deletions upload/admin/controller/sale/subscription.php
Expand Up @@ -440,11 +440,10 @@ public function info(): void {
$data['description'] = '';

if (!empty($subscription_info)) {

$trial_price = $this->currency->format($subscription_info['trial_price'], $this->config->get('config_currency'));
$trial_cycle = $subscription_info['trial_cycle'];
$trial_frequency = $this->language->get('text_' . $subscription_info['trial_frequency']);
$trial_duration = $subscription_info['trial_duration'];
$trial_price = $this->currency->format($subscription_info['trial_price'], $this->config->get('config_currency'));

if ($subscription_info['trial_status']) {
$data['description'] .= sprintf($this->language->get('text_subscription_trial'), $trial_price, $trial_cycle, $trial_frequency, $trial_duration);
Expand All @@ -460,8 +459,6 @@ public function info(): void {
} else {
$data['description'] .= sprintf($this->language->get('text_subscription_cancel'), $price, $cycle, $frequency);
}


}

if (!empty($product_info)) {
Expand Down
74 changes: 55 additions & 19 deletions upload/admin/controller/tool/log.php
Expand Up @@ -18,19 +18,26 @@ public function index(): void {
'href' => $this->url->link('tool/log', 'user_token=' . $this->session->data['user_token'])
];

//echo $this->session->data['error'];


if (isset($this->session->data['error'])) {
$data['error_warning'] = $this->session->data['error'];

unset($this->session->data['error']);
} else {
$data['error_warning'] = '';
}

$data['download'] = $this->url->link('tool/log|download', 'user_token=' . $this->session->data['user_token']);
$data['log'] = [];

$data['log'] = '';
$files = glob(DIR_LOGS . '*.log');

$file = DIR_LOGS . $this->config->get('config_error_filename');
foreach ($files as $file) {
$error = '';

$filename = basename($file);

if (is_file($file)) {
$size = filesize($file);

if ($size >= 3145728) {
Expand All @@ -53,12 +60,18 @@ public function index(): void {
$i++;
}

$data['error_warning'] = sprintf($this->language->get('error_warning'), basename($file), round(substr($size, 0, strpos($size, '.') + 4), 2) . $suffix[$i]);
$error = sprintf($this->language->get('error_size'), $filename, round(substr($size, 0, strpos($size, '.') + 4), 2) . $suffix[$i]);
}

$handle = fopen($file, 'r+');

$data['log'] = fread($handle, 3145728);
$data['logs'][] = [
'name' => $filename,
'output' => fread($handle, 3145728),
'download' => $this->url->link('tool/log|download', 'user_token=' . $this->session->data['user_token'] . '&filename=' . $filename),
'clear' => $this->url->link('tool/log|clear', 'user_token=' . $this->session->data['user_token'] . '&filename=' . $filename),
'error' => $error
];

fclose($handle);
}
Expand All @@ -75,36 +88,59 @@ public function index(): void {
public function download(): void {
$this->load->language('tool/log');

$file = DIR_LOGS . $this->config->get('config_error_filename');
if (isset($this->request->get['filename'])) {
$filename = (string)basename($this->request->get['filename']);
} else {
$filename = '';
}

$file = DIR_LOGS . $filename;

if (is_file($file) && filesize($file) > 0) {
$this->response->addheader('Pragma: public');
$this->response->addheader('Expires: 0');
$this->response->addheader('Content-Description: File Transfer');
$this->response->addheader('Content-Type: application/octet-stream');
$this->response->addheader('Content-Disposition: attachment; filename="' . $this->config->get('config_name') . '_' . date('Y-m-d_H-i-s', time()) . '_error.log"');
$this->response->addheader('Content-Transfer-Encoding: binary');
if (!is_file($file)) {
$this->session->data['error'] = sprintf($this->language->get('error_file'), $filename);

$this->response->setOutput(file_get_contents($file, FILE_USE_INCLUDE_PATH, null));
} else {
$this->session->data['error'] = sprintf($this->language->get('error_warning'), basename($file), '0B');
$this->response->redirect($this->url->link('tool/log', 'user_token=' . $this->session->data['user_token']));
}

if (!filesize($file)) {
$this->session->data['error'] = sprintf($this->language->get('error_empty'), $filename);
//echo sprintf($this->language->get('error_empty'), $filename);

$this->response->redirect($this->url->link('tool/log', 'user_token=' . $this->session->data['user_token']));
}

$this->response->addheader('Pragma: public');
$this->response->addheader('Expires: 0');
$this->response->addheader('Content-Description: File Transfer');
$this->response->addheader('Content-Type: application/octet-stream');
$this->response->addheader('Content-Disposition: attachment; filename="' . $this->config->get('config_name') . '_' . date('Y-m-d_H-i-s', time()) . '_error.log"');
$this->response->addheader('Content-Transfer-Encoding: binary');

//$this->response->setOutput(file_get_contents($file, FILE_USE_INCLUDE_PATH, null));
}

public function clear(): void {
$this->load->language('tool/log');

if (isset($this->request->get['filename'])) {
$filename = (string)$this->request->get['filename'];
} else {
$filename = '';
}

$json = [];

if (!$this->user->hasPermission('modify', 'tool/log')) {
$json['error'] = $this->language->get('error_permission');
}

if (!$json) {
$file = DIR_LOGS . $this->config->get('config_error_filename');
$file = DIR_LOGS . $filename;

if (!is_file($file)) {
$json['error'] = sprintf($this->language->get('error_file'), $filename);
}

if (!$json) {
$handle = fopen($file, 'w+');

fclose($handle);
Expand Down
6 changes: 4 additions & 2 deletions upload/admin/language/en-gb/tool/log.php
Expand Up @@ -7,5 +7,7 @@
$_['text_list'] = 'Errors List';

// Error
$_['error_warning'] = 'Warning: Your error log file %s is %s!';
$_['error_permission'] = 'Warning: You do not have permission to clear error log!';
$_['error_permission'] = 'Warning: You do not have permission to clear error log!';
$_['error_file'] = 'Warning: %s file could not be found!';
$_['error_size'] = 'Warning: Error log file %s is %s!';
$_['error_empty'] = 'Warning: Log file %s is empty!';
4 changes: 2 additions & 2 deletions upload/admin/view/template/common/forgotten_reset.twig
Expand Up @@ -8,7 +8,7 @@
<div class="card">
<div class="card-header"><i class="fas fa-redo"></i> {{ heading_title }}</div>
<div class="card-body">
<form id="form-forgotten" action="{{ save }}" method="post" data-oc-toggle="ajax">
<form id="form-forgotten" action="{{ reset }}" method="post" data-oc-toggle="ajax">
<p>{{ text_password }}</p>
<div class="mb-3">
<label for="input-password" class="form-label">{{ entry_password }}</label>
Expand All @@ -19,7 +19,7 @@
<input type="password" name="confirm" value="" id="input-confirm" class="form-control"/>
</div>
<div class="text-end">
<button type="button" class="btn btn-primary"><i class="fas fa-save"></i> {{ button_save }}</button>
<button type="submit" class="btn btn-primary"><i class="fas fa-save"></i> {{ button_save }}</button>
<a href="{{ back }}" data-bs-toggle="tooltip" title="{{ button_back }}" class="btn btn-light"><i class="fas fa-reply"></i></a>
</div>
</form>
Expand Down
18 changes: 1 addition & 17 deletions upload/admin/view/template/common/security.twig
@@ -1,20 +1,16 @@
<div id="modal-security" class="modal show">
<div class="modal-dialog">
<div class="modal-content">

<div class="modal-header">
<h5 class="modal-title text-danger"><i class="fas fa-exclamation-triangle"></i> {{ heading_title }}</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>

<div id="accordion" class="accordion">

{% if install %}
<div id="security-install" class="accordion-item">
<h5 class="accordion-header"><button type="button" data-bs-toggle="collapse" data-bs-target="#accordion-install" class="accordion-button collapsed"><span class="fas fa-folder"></span>&nbsp;&nbsp;{{ text_install }}</button></h5>
<div id="accordion-install" class="accordion-collapse collapse" data-bs-parent="#accordion">
<div class="modal-body">

<p>{{ text_install_description }}</p>
<div class="mb-3">
<div class="input-group">
Expand All @@ -25,12 +21,10 @@
<div class="text-end">
<button type="button" id="button-install" data-oc-loading-text="{{ text_loading }}" class="btn btn-danger"><i class="fas fa-trash-alt"></i> {{ button_delete }}</button>
</div>

</div>
</div>
</div>
{% endif %}

{% if storage %}
<div id="security-storage" class="accordion-item">
<h2 class="accordion-header"><button type="button" data-bs-toggle="collapse" data-bs-target="#accordion-storage" class="accordion-button collapsed"><i class="fas fa-arrow-alt-circle-right"></i>&nbsp;&nbsp;{{ text_storage }}</button></h2>
Expand All @@ -39,8 +33,7 @@
<form id="form-storage">
<p>{{ text_storage_description }}</p>
<div class="mb-3">
<label class="form-label">{{ entry_path_current }}</label>
<input type="text" value="{{ storage }}" class="form-control is-invalid bg-white" readonly/>
<label class="form-label">{{ entry_path_current }}</label> <input type="text" value="{{ storage }}" class="form-control is-invalid bg-white" readonly/>
</div>
<div class="mb-3">
<label class="form-label">{{ entry_path_new }}</label>
Expand All @@ -63,32 +56,23 @@
</div>
</div>
{% endif %}


{% if admin %}
<div id="security-admin" class="accordion-item">
<h2 class="accordion-header"><button type="button" data-bs-toggle="collapse" data-bs-target="#accordion-admin" class="accordion-button collapsed"><span class="fas fa-lock"></span>&nbsp;&nbsp;{{ text_admin }}</button></h2>
<div id="accordion-admin" class="accordion-collapse collapse" data-bs-parent="#accordion">

<div class="modal-body">

<form id="form-admin">

<p>{{ text_admin_description }}</p>

<div class="mb-3">
<div class="input-group">
<div class="input-group-text">{{ text_path }}</div>
<input type="text" name="name" value="admin" placeholder="{{ entry_name }}" class="form-control is-invalid"/>
</div>
</div>

<div class="text-end">
<button type="button" id="button-admin" data-oc-loading-text="{{ text_loading }}" class="btn btn-danger"><i class="fas fa-pencil-alt"></i> {{ button_rename }}</button>
</div>

</form>

</div>
</div>
</div>
Expand Down

0 comments on commit 23b9d53

Please sign in to comment.