Skip to content

Commit a7b5987

Browse files
Web SFTP for KVM :D!
1 parent bc5786d commit a7b5987

9 files changed

Lines changed: 1314 additions & 1118 deletions

File tree

backend/src/handlers/adminHandler.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import { Order } from '../models/order.entity';
3232
import { Plan } from '../models/plan.entity';
3333
import { getSlowQueries, clearSlowQueries } from '../utils/slowQueryCollector';
3434
import { executeDeletionRequest } from '../jobs/deletionExecutionJob';
35-
import { getGeoBlockRules, getGeoBlockLevelFromRules, getGeoBlockLevel } from '../utils/eu';
35+
import { getGeoBlockRules, getGeoBlockLevelFromRules, getGeoBlockLevel, getMinimumAgeForCountry } from '../utils/eu';
3636
import { getPanelFeatureToggles } from '../utils/featureToggles';
3737
import path from 'path';
3838
import fs from 'fs';
@@ -41,6 +41,20 @@ import * as tar from 'tar';
4141
import { promises as fsp } from 'fs';
4242
import { normalizeProcessConfig } from '../utils/startupDetection';
4343

44+
function getAgeFromDate(date?: Date | string | null): number | null {
45+
if (!date) return null;
46+
const dob = date instanceof Date ? date : new Date(String(date));
47+
if (isNaN(dob.getTime())) return null;
48+
const now = new Date();
49+
let age = now.getUTCFullYear() - dob.getUTCFullYear();
50+
const monthDiff = now.getUTCMonth() - dob.getUTCMonth();
51+
const dayDiff = now.getUTCDate() - dob.getUTCDate();
52+
if (monthDiff < 0 || (monthDiff === 0 && dayDiff < 0)) {
53+
age -= 1;
54+
}
55+
return age;
56+
}
57+
4458
function getSafeRelativeFilePath(base: string, relPath: string): string | null {
4559
const normalised = path.normalize(String(relPath || '')).replace(/^([/\\])+/, '').replace(/^(\.{2}(\/|\\|$))+/,'');
4660
const fullPath = path.join(base, normalised);
@@ -1131,10 +1145,11 @@ export async function adminRoutes(app: any, prefix = '') {
11311145
return { error: 'invalid_date_of_birth', message: 'dateOfBirth must be a valid date string in YYYY-MM-DD format.' };
11321146
}
11331147
const updatedAge = getAgeFromDate(dob);
1134-
if (updatedAge !== null && updatedAge < 14) {
1148+
const minimumAge = await getMinimumAgeForCountry(user.billingCountry);
1149+
if (updatedAge !== null && updatedAge < minimumAge) {
11351150
user.suspended = true;
11361151
user.fraudFlag = true;
1137-
user.fraudReason = 'Underage account (<14 years)';
1152+
user.fraudReason = `Underage account (<${minimumAge} years)`;
11381153
}
11391154
user.dateOfBirth = dob;
11401155
}

0 commit comments

Comments
 (0)