client: 2367 Show SSL Certificate Expire Banner in 5 Days
Squashed commit of the following:
commit 290b3fbc5e18a2cc8694fb2d5f777952d971dfd6
Merge: fe5c67e62 2313eda12
Author: Artem Baskal <a.baskal@adguard.com>
Date: Tue Dec 8 13:57:38 2020 +0300
Merge branch 'master' into fix/2367
commit fe5c67e624280d7fc08192ed3e953a09ca10a9ee
Author: Artem Baskal <a.baskal@adguard.com>
Date: Mon Dec 7 16:44:41 2020 +0300
- client: 2367 Show SSL Certificate Expire Banner in 5 Days
This commit is contained in:
parent
2313eda123
commit
88d44b4370
|
@ -6,6 +6,50 @@ import { useSelector } from 'react-redux';
|
|||
import Topline from './Topline';
|
||||
import { EMPTY_DATE } from '../../helpers/constants';
|
||||
|
||||
const EXPIRATION_ENUM = {
|
||||
VALID: 'VALID',
|
||||
EXPIRED: 'EXPIRED',
|
||||
EXPIRING: 'EXPIRING',
|
||||
};
|
||||
|
||||
const EXPIRATION_STATE = {
|
||||
[EXPIRATION_ENUM.EXPIRED]: {
|
||||
toplineType: 'danger',
|
||||
i18nKey: 'topline_expired_certificate',
|
||||
},
|
||||
[EXPIRATION_ENUM.EXPIRING]: {
|
||||
toplineType: 'warning',
|
||||
i18nKey: 'topline_expiring_certificate',
|
||||
},
|
||||
};
|
||||
|
||||
const getExpirationFlags = (not_after) => {
|
||||
const DAYS_BEFORE_EXPIRATION = 5;
|
||||
|
||||
const now = Date.now();
|
||||
const isExpiring = isAfter(addDays(now, DAYS_BEFORE_EXPIRATION), not_after);
|
||||
const isExpired = isAfter(now, not_after);
|
||||
|
||||
return {
|
||||
isExpiring,
|
||||
isExpired,
|
||||
};
|
||||
};
|
||||
|
||||
const getExpirationEnumKey = (not_after) => {
|
||||
const { isExpiring, isExpired } = getExpirationFlags(not_after);
|
||||
|
||||
if (isExpired) {
|
||||
return EXPIRATION_ENUM.EXPIRED;
|
||||
}
|
||||
|
||||
if (isExpiring) {
|
||||
return EXPIRATION_ENUM.EXPIRING;
|
||||
}
|
||||
|
||||
return EXPIRATION_ENUM.VALID;
|
||||
};
|
||||
|
||||
const EncryptionTopline = () => {
|
||||
const not_after = useSelector((state) => state.encryption.not_after);
|
||||
|
||||
|
@ -13,30 +57,21 @@ const EncryptionTopline = () => {
|
|||
return null;
|
||||
}
|
||||
|
||||
const isAboutExpire = isAfter(addDays(Date.now(), 30), not_after);
|
||||
const isExpired = isAfter(Date.now(), not_after);
|
||||
const expirationStateKey = getExpirationEnumKey(not_after);
|
||||
|
||||
if (expirationStateKey === EXPIRATION_ENUM.VALID) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const { toplineType, i18nKey } = EXPIRATION_STATE[expirationStateKey];
|
||||
|
||||
if (isExpired) {
|
||||
return (
|
||||
<Topline type="danger">
|
||||
<Topline type={toplineType}>
|
||||
<Trans components={[<a href="#encryption" key="0">link</a>]}>
|
||||
topline_expired_certificate
|
||||
{i18nKey}
|
||||
</Trans>
|
||||
</Topline>
|
||||
);
|
||||
}
|
||||
|
||||
if (isAboutExpire) {
|
||||
return (
|
||||
<Topline type="warning">
|
||||
<Trans components={[<a href="#encryption" key="0">link</a>]}>
|
||||
topline_expiring_certificate
|
||||
</Trans>
|
||||
</Topline>
|
||||
);
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
export default EncryptionTopline;
|
||||
|
|
Loading…
Reference in New Issue