<?php
/* Smarty version 4.5.6, created on 2025-12-20 23:19:28
  from '/var/www/html/tivi/panel/templates/security/ip_rules.tpl' */

/* @var Smarty_Internal_Template $_smarty_tpl */
if ($_smarty_tpl->_decodeProperties($_smarty_tpl, array (
  'version' => '4.5.6',
  'unifunc' => 'content_694720f0a090a1_24525748',
  'has_nocache_code' => false,
  'file_dependency' => 
  array (
    '4adcca8cf7bafd18142aaf1fc6f82bf7dc6ba897' => 
    array (
      0 => '/var/www/html/tivi/panel/templates/security/ip_rules.tpl',
      1 => 1766254344,
      2 => 'file',
    ),
  ),
  'includes' => 
  array (
  ),
),false)) {
function content_694720f0a090a1_24525748 (Smarty_Internal_Template $_smarty_tpl) {
$_smarty_tpl->_loadInheritance();
$_smarty_tpl->inheritance->init($_smarty_tpl, true);
?>


<?php 
$_smarty_tpl->inheritance->instanceBlock($_smarty_tpl, 'Block_8542548694720f09fdbe9_35804550', "content");
?>

<?php $_smarty_tpl->inheritance->endChild($_smarty_tpl, "layout.tpl");
}
/* {block "content"} */
class Block_8542548694720f09fdbe9_35804550 extends Smarty_Internal_Block
{
public $subBlocks = array (
  'content' => 
  array (
    0 => 'Block_8542548694720f09fdbe9_35804550',
  ),
);
public function callBlock(Smarty_Internal_Template $_smarty_tpl) {
$_smarty_tpl->_checkPlugins(array(0=>array('file'=>'/var/www/html/tivi/vendor/smarty/smarty/libs/plugins/modifier.count.php','function'=>'smarty_modifier_count',),1=>array('file'=>'/var/www/html/tivi/vendor/smarty/smarty/libs/plugins/modifier.date_format.php','function'=>'smarty_modifier_date_format',),2=>array('file'=>'/var/www/html/tivi/vendor/smarty/smarty/libs/plugins/modifier.truncate.php','function'=>'smarty_modifier_truncate',),));
?>

<div class="container-fluid">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <div>
            <h4 class="mb-1">Reguły IP</h4>
            <p class="text-muted mb-0">Zarządzaj whitelist i blacklist adresów IP</p>
        </div>
        <button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addRuleModal">
            <i class="bi bi-plus-lg me-1"></i>Dodaj regułę
        </button>
    </div>

    <!-- Statystyki -->
    <div class="row g-4 mb-4">
        <div class="col-md-4">
            <div class="card bg-danger bg-opacity-10 border-danger">
                <div class="card-body">
                    <h6 class="text-danger">Zablokowane IP (automatycznie)</h6>
                    <h2 class="mb-0"><?php echo smarty_modifier_count($_smarty_tpl->tpl_vars['blockedIps']->value);?>
</h2>
                </div>
            </div>
        </div>
        <div class="col-md-4">
            <div class="card bg-dark bg-opacity-10">
                <div class="card-body">
                    <h6>Blacklist</h6>
                    <h2 class="mb-0"><?php echo (($tmp = $_smarty_tpl->tpl_vars['stats']->value['ip_rules']['blacklist'] ?? null)===null||$tmp==='' ? 0 ?? null : $tmp);?>
</h2>
                </div>
            </div>
        </div>
        <div class="col-md-4">
            <div class="card bg-success bg-opacity-10 border-success">
                <div class="card-body">
                    <h6 class="text-success">Whitelist</h6>
                    <h2 class="mb-0"><?php echo (($tmp = $_smarty_tpl->tpl_vars['stats']->value['ip_rules']['whitelist'] ?? null)===null||$tmp==='' ? 0 ?? null : $tmp);?>
</h2>
                </div>
            </div>
        </div>
    </div>

    <?php if (smarty_modifier_count($_smarty_tpl->tpl_vars['blockedIps']->value) > 0) {?>
    <div class="card mb-4">
        <div class="card-header bg-danger bg-opacity-10">
            <h5 class="card-title mb-0 text-danger"><i class="bi bi-shield-x me-2"></i>Automatycznie zablokowane IP</h5>
        </div>
        <div class="card-body p-0">
            <div class="table-responsive">
                <table class="table table-hover mb-0">
                    <thead>
                        <tr>
                            <th>IP</th>
                            <th>Próba użytkownika</th>
                            <th>Próby</th>
                            <th>Zablokowane do</th>
                            <th>Akcje</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
$_from = $_smarty_tpl->smarty->ext->_foreach->init($_smarty_tpl, $_smarty_tpl->tpl_vars['blockedIps']->value, 'blocked');
$_smarty_tpl->tpl_vars['blocked']->do_else = true;
if ($_from !== null) foreach ($_from as $_smarty_tpl->tpl_vars['blocked']->value) {
$_smarty_tpl->tpl_vars['blocked']->do_else = false;
?>
                        <tr>
                            <td><code><?php echo $_smarty_tpl->tpl_vars['blocked']->value['ip_address'];?>
</code></td>
                            <td><?php echo (($tmp = $_smarty_tpl->tpl_vars['blocked']->value['username'] ?? null)===null||$tmp==='' ? '-' ?? null : $tmp);?>
</td>
                            <td><span class="badge bg-danger"><?php echo $_smarty_tpl->tpl_vars['blocked']->value['attempts'];?>
</span></td>
                            <td><?php echo smarty_modifier_date_format($_smarty_tpl->tpl_vars['blocked']->value['blocked_until'],"%d.%m.%Y %H:%M");?>
</td>
                            <td>
                                <form method="post" action="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/security/unblock-ip" style="display:inline;">
                                    <input type="hidden" name="csrf_token" value="<?php echo $_smarty_tpl->tpl_vars['csrfToken']->value;?>
">
                                    <input type="hidden" name="ip" value="<?php echo $_smarty_tpl->tpl_vars['blocked']->value['ip_address'];?>
">
                                    <button type="submit" class="btn btn-sm btn-outline-success" onclick="return confirm('Odblokować to IP?')">
                                        <i class="bi bi-unlock"></i> Odblokuj
                                    </button>
                                </form>
                            </td>
                        </tr>
                        <?php
}
$_smarty_tpl->smarty->ext->_foreach->restore($_smarty_tpl, 1);?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
    <?php }?>

    <div class="card">
        <div class="card-header d-flex justify-content-between align-items-center">
            <h5 class="card-title mb-0"><i class="bi bi-shield-lock me-2"></i>Reguły IP</h5>
            <div class="btn-group btn-group-sm">
                <a href="?type=" class="btn btn-outline-secondary <?php if (!$_smarty_tpl->tpl_vars['filterType']->value) {?>active<?php }?>">Wszystkie</a>
                <a href="?type=blacklist" class="btn btn-outline-secondary <?php if ($_smarty_tpl->tpl_vars['filterType']->value == 'blacklist') {?>active<?php }?>">Blacklist</a>
                <a href="?type=whitelist" class="btn btn-outline-secondary <?php if ($_smarty_tpl->tpl_vars['filterType']->value == 'whitelist') {?>active<?php }?>">Whitelist</a>
            </div>
        </div>
        <div class="card-body p-0">
            <div class="table-responsive">
                <table class="table table-hover mb-0">
                    <thead>
                        <tr>
                            <th>IP</th>
                            <th>Typ</th>
                            <th>Powód</th>
                            <th>Wygasa</th>
                            <th>Dodał</th>
                            <th>Data</th>
                            <th>Akcje</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
$_from = $_smarty_tpl->smarty->ext->_foreach->init($_smarty_tpl, $_smarty_tpl->tpl_vars['rules']->value, 'rule');
$_smarty_tpl->tpl_vars['rule']->do_else = true;
if ($_from !== null) foreach ($_from as $_smarty_tpl->tpl_vars['rule']->value) {
$_smarty_tpl->tpl_vars['rule']->do_else = false;
?>
                        <tr>
                            <td><code><?php echo $_smarty_tpl->tpl_vars['rule']->value['ip_address'];?>
</code></td>
                            <td>
                                <?php if ($_smarty_tpl->tpl_vars['rule']->value['rule_type'] == 'blacklist') {?>
                                <span class="badge bg-danger">Blacklist</span>
                                <?php } else { ?>
                                <span class="badge bg-success">Whitelist</span>
                                <?php }?>
                            </td>
                            <td><?php echo smarty_modifier_truncate((($tmp = $_smarty_tpl->tpl_vars['rule']->value['reason'] ?? null)===null||$tmp==='' ? '-' ?? null : $tmp),30);?>
</td>
                            <td>
                                <?php if ($_smarty_tpl->tpl_vars['rule']->value['expires_at']) {?>
                                <?php echo smarty_modifier_date_format($_smarty_tpl->tpl_vars['rule']->value['expires_at'],"%d.%m.%Y");?>

                                <?php } else { ?>
                                <span class="text-muted">Nigdy</span>
                                <?php }?>
                            </td>
                            <td><?php echo (($tmp = $_smarty_tpl->tpl_vars['rule']->value['created_by_username'] ?? null)===null||$tmp==='' ? 'System' ?? null : $tmp);?>
</td>
                            <td><?php echo smarty_modifier_date_format($_smarty_tpl->tpl_vars['rule']->value['created_at'],"%d.%m.%Y");?>
</td>
                            <td>
                                <form method="post" action="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/security/ip-rules/delete" style="display:inline;">
                                    <input type="hidden" name="csrf_token" value="<?php echo $_smarty_tpl->tpl_vars['csrfToken']->value;?>
">
                                    <input type="hidden" name="id" value="<?php echo $_smarty_tpl->tpl_vars['rule']->value['id'];?>
">
                                    <button type="submit" class="btn btn-sm btn-outline-danger" onclick="return confirm('Usunąć tę regułę?')">
                                        <i class="bi bi-trash"></i>
                                    </button>
                                </form>
                            </td>
                        </tr>
                        <?php
}
if ($_smarty_tpl->tpl_vars['rule']->do_else) {
?>
                        <tr>
                            <td colspan="7" class="text-center py-4 text-muted">Brak reguł IP</td>
                        </tr>
                        <?php
}
$_smarty_tpl->smarty->ext->_foreach->restore($_smarty_tpl, 1);?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>

<!-- Modal dodawania reguły -->
<div class="modal fade" id="addRuleModal" tabindex="-1">
    <div class="modal-dialog">
        <div class="modal-content">
            <form method="post" action="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/security/ip-rules/add">
                <input type="hidden" name="csrf_token" value="<?php echo $_smarty_tpl->tpl_vars['csrfToken']->value;?>
">
                <div class="modal-header">
                    <h5 class="modal-title">Dodaj regułę IP</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
                </div>
                <div class="modal-body">
                    <div class="mb-3">
                        <label class="form-label">Adres IP <span class="text-danger">*</span></label>
                        <input type="text" name="ip_address" class="form-control" required placeholder="np. 192.168.1.100">
                    </div>
                    <div class="mb-3">
                        <label class="form-label">Typ reguły</label>
                        <select name="rule_type" class="form-select">
                            <option value="blacklist">Blacklist (blokuj)</option>
                            <option value="whitelist">Whitelist (zezwól)</option>
                        </select>
                    </div>
                    <div class="mb-3">
                        <label class="form-label">Powód</label>
                        <input type="text" name="reason" class="form-control" placeholder="Opcjonalny powód">
                    </div>
                    <div class="mb-3">
                        <label class="form-label">Wygasa</label>
                        <input type="datetime-local" name="expires_at" class="form-control">
                        <small class="text-muted">Pozostaw puste dla reguły permanentnej</small>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Anuluj</button>
                    <button type="submit" class="btn btn-primary">Dodaj regułę</button>
                </div>
            </form>
        </div>
    </div>
</div>
<?php
}
}
/* {/block "content"} */
}
