}
$errortext = array();
if (is_object($session) && !empty($current_user->id) && $current_user->is_admin === 'y') {
    $xmlwriter->setHeaderMessage('OK');
    $xmlwriter->setHeaderStatus(0);
    $mask = trim($mask);
    $description = trim($description);
    $action = trim($action);
    // Validate expiration date
    if (empty($expires_never) && (!@checkdate($expires_month, $expires_day, $expires_year) || !pcpin_ctype_digit($expires_hour) || $expires_hour > 60 || $expires_hour < 0 || !pcpin_ctype_digit($expires_minute) || $expires_minute > 60 || $expires_minute < 0)) {
        $errortext[] = $l->g('expiration_date_invalid');
    }
    // Check mask
    if ($type !== 'IPv4' && $type !== 'IPv6') {
        $errortext[] = $l->g('ip_address_type_invalid');
    } elseif (!$ipfilter->checkIPMask($type, $mask)) {
        $errortext[] = $l->g('ip_mask_invalid');
    }
    if (empty($errortext)) {
        if ($ipfilter->addAddress($type, $mask, empty($expires_never) ? "{$expires_year}-{$expires_month}-{$expires_day} {$expires_hour}:{$expires_minute}:00" : '', $description, $action)) {
            $xmlwriter->setHeaderMessage($l->g('ip_address_added'));
            // Ensure, that current user can access the software with new record
            if ($ipfilter->isBlocked(PCPIN_CLIENT_IP)) {
                // Not good
                $ipfilter->deleteAddress($ipfilter->id);
                $errortext[] = str_replace('[ADDRESS]', $mask, $l->g('own_ip_cant_be_banned'));
            }
        } else {
            $errortext[] = $l->g('error');
        }
    }