Skip to content

Commit

Permalink
Adicionado opção de alterar configurações da API na menu configurações (
Browse files Browse the repository at this point in the history
  • Loading branch information
juliolobo authored May 3, 2024
1 parent 7b58a6a commit ba05dda
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
9 changes: 9 additions & 0 deletions application/controllers/Mapos.php
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,15 @@ public function configurar()
if ($this->form_validation->run() == false) {
$this->data['custom_error'] = (validation_errors() ? '<div class="alert">' . validation_errors() . '</div>' : false);
} else {
$env_file_path = dirname(__FILE__,2) . DIRECTORY_SEPARATOR . '.env';
$env_file = file_get_contents($env_file_path);
$env_file = str_replace("API_ENABLED={$_ENV['API_ENABLED']}", "API_ENABLED={$this->input->post('apiEnabled')}", $env_file);
$env_file = str_replace("API_TOKEN_EXPIRE_TIME={$_ENV['API_TOKEN_EXPIRE_TIME']}", "API_TOKEN_EXPIRE_TIME={$this->input->post('apiExpireTime')}", $env_file);
if ($this->input->post('resetJwtToken') == 'sim') {
$env_file = str_replace('API_JWT_KEY="'.$_ENV['API_JWT_KEY'].'"', 'API_JWT_KEY="'.base64_encode(openssl_random_pseudo_bytes(32)).'"', $env_file);
}
file_put_contents($env_file_path, $env_file);

$data = [
'app_name' => $this->input->post('app_name'),
'per_page' => $this->input->post('per_page'),
Expand Down
51 changes: 51 additions & 0 deletions application/views/mapos/configurar.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<li><a data-toggle="tab" href="#menu3">Notificações</a></li>
<li><a data-toggle="tab" href="#menu4">Atualizações</a></li>
<li><a data-toggle="tab" href="#menu5">OS</a></li>
<li><a data-toggle="tab" href="#menu6">API</a></li>
</ul>
<form action="<?php echo current_url(); ?>" id="formConfigurar" method="post" class="form-horizontal">
<div class="widget-content nopadding tab-content">
Expand Down Expand Up @@ -256,6 +257,56 @@
</div>
</div>
</div>
<!-- Menu API -->
<div id="menu6" class="tab-pane fade">
<div class="control-group">
<label for="apiEnabled" class="control-label">Ativar acesso à API</label>
<div class="controls">
<select name="apiEnabled" id="apiEnabled">
<option value="true">Ativar</option>
<option value="false" <?= !filter_var($_ENV['API_ENABLED'] ?? false, FILTER_VALIDATE_BOOLEAN) ? 'selected' : ''; ?>>Desativar</option>
</select>
<span class="help-inline">Ativar ou desativar acesso à API.</span>
</div>
</div>
<div class="control-group">
<label for="apiEnabled" class="control-label">URL API</label>
<div class="controls">
<span class="span10" id="urlApi" style="margin-top:7px;"><?= $_ENV['APP_BASEURL'] ?>index.php/api/v1</span>
</div>
</div>
<div class="control-group">
<label for="apiExpireTime" class="control-label">Tempo de expiração</label>
<div class="controls">
<select name="apiExpireTime" id="apiExpireTime">
<option value="60" <?= $_ENV['API_TOKEN_EXPIRE_TIME'] == 60 ? 'selected' : '' ?>>1 minuto</option>
<option value="3600" <?= $_ENV['API_TOKEN_EXPIRE_TIME'] == 3600 ? 'selected' : '' ?>>1 hora</option>
<option value="86400" <?= $_ENV['API_TOKEN_EXPIRE_TIME'] == 86400 ? 'selected' : '' ?>>1 dia</option>
<option value="604800" <?= $_ENV['API_TOKEN_EXPIRE_TIME'] == 604800 ? 'selected' : '' ?>>1 semana</option>
<option value="2592000" <?= $_ENV['API_TOKEN_EXPIRE_TIME'] == 2592000 ? 'selected' : '' ?>>1 mês</option>
</select>
<span class="help-inline">Tempo de duração da sessão na API.</span>
</div>
</div>
<div class="control-group">
<label for="resetJwtToken" class="control-label">Resetar token JWT</label>
<div class="controls">
<select name="resetJwtToken" id="resetJwtToken">
<option value="nao" selected>Não</option>
<option value="sim">Sim</option>
</select>
<span class="help-inline">Gerar um novo token JWT.</span>
</div>
</div>
<div class="form-actions">
<div class="span8">
<div class="span9">
<button type="submit" class="button btn btn-primary">
<span class="button__icon"><i class='bx bx-save'></i></span><span class="button__text2">Salvar Alterações</span></button>
</div>
</div>
</div>
</div>
</div>
</form>
</div>
Expand Down

0 comments on commit ba05dda

Please sign in to comment.