more fixes

This commit is contained in:
HF 2022-08-05 23:38:49 +02:00
parent 2b82971ceb
commit a5d25a8217
6 changed files with 42 additions and 32 deletions

View File

@ -50,7 +50,7 @@ function ModIIDtools() {
selectIIDAction(sel.options[sel.selectedIndex].value); selectIIDAction(sel.options[sel.selectedIndex].value);
}} }}
> >
{['givecaptcha', 'ban', 'unban', 'whitelist', 'unwhitelist'] {['status', 'givecaptcha', 'ban', 'unban', 'whitelist', 'unwhitelist']
.map((opt) => ( .map((opt) => (
<option <option
key={opt} key={opt}

View File

@ -13,15 +13,7 @@ import Palette from './Palette';
import Alert from './Alert'; import Alert from './Alert';
import HistorySelect from './HistorySelect'; import HistorySelect from './HistorySelect';
import Mobile3DControls from './Mobile3DControls'; import Mobile3DControls from './Mobile3DControls';
import UserContextMenu from './contextmenus/UserContextMenu'; import ContextMenues from './contextmenus';
import ChannelContextMenu from './contextmenus/ChannelContextMenu';
const CONTEXT_MENUS = {
USER: UserContextMenu,
CHANNEL: ChannelContextMenu,
/* other context menus */
};
const UI = () => { const UI = () => {
const [ const [
@ -38,7 +30,7 @@ const UI = () => {
state.contextMenu.menuType, state.contextMenu.menuType,
], shallowEqual); ], shallowEqual);
const ContextMenu = menuOpen && menuType && CONTEXT_MENUS[menuType]; const ContextMenu = menuOpen && menuType && ContextMenues[menuType];
return ( return (
<> <>

View File

@ -0,0 +1,7 @@
import UserContextMenu from './UserContextMenu';
import ChannelContextMenu from './ChannelContextMenu';
export default {
USER: UserContextMenu,
CHANNEL: ChannelContextMenu,
};

View File

@ -94,10 +94,12 @@ async function dummy() {
return [false, 'dummy']; return [false, 'dummy'];
} }
async function saveIPInfo(ip, isProxy, info) { async function saveIPInfo(ip, whoisRet, isProxy, info) {
const whoisData = whoisRet || {};
try { try {
const whoisData = await whois(ip);
IPInfo.upsert({ IPInfo.upsert({
ip,
...whoisData, ...whoisData,
isProxy, isProxy,
pcheck: info, pcheck: info,
@ -113,24 +115,32 @@ async function saveIPInfo(ip, isProxy, info) {
* @param ip IP to check * @param ip IP to check
* @return true if proxy or blacklisted, false if not or whitelisted * @return true if proxy or blacklisted, false if not or whitelisted
*/ */
async function withoutCache(f, ip) { export async function withoutCache(f, ip) {
const ipKey = getIPv6Subnet(ip); const ipKey = getIPv6Subnet(ip);
let allowed; let allowed = true;
let status; let status = -2;
let pcInfo; let pcInfo = null;
if (await isWhitelisted(ipKey)) { let whoisRet = null;
allowed = false;
pcInfo = 'wl'; try {
status = -1; if (await isWhitelisted(ipKey)) {
} else if (await isIPBanned(ipKey)) { allowed = true;
allowed = true; pcInfo = 'wl';
pcInfo = 'bl'; status = -1;
status = 2; } else if (await isIPBanned(ipKey)) {
} else { allowed = false;
[allowed, pcInfo] = await f(ip); pcInfo = 'bl';
status = (allowed) ? 1 : 0; status = 2;
} else {
[allowed, pcInfo] = await f(ip);
allowed = !allowed;
status = (allowed) ? 0 : 1;
}
whoisRet = await whois(ip);
} finally {
await saveIPInfo(ipKey, whoisRet, allowed, pcInfo);
} }
saveIPInfo(ipKey, allowed, pcInfo);
return { return {
allowed, allowed,
status, status,

View File

@ -272,9 +272,9 @@ export async function getSummaryFromArea(
} }
} }
row.push( row.push(
ipInfo.uuid || 'N/A', ipInfo.uuid,
ipInfo.country || 'xx', ipInfo.country,
ipInfo.cidr || 'N/A', ipInfo.cidr,
ipInfo.org || 'N/A', ipInfo.org || 'N/A',
pcheck || 'N/A', pcheck || 'N/A',
); );

View File

@ -23,6 +23,7 @@ const IPInfo = sequelize.define('IPInfo', {
cidr: { cidr: {
type: DataTypes.CHAR(43), type: DataTypes.CHAR(43),
defaultValue: 'N/A',
allowNull: false, allowNull: false,
}, },