mirror of
https://github.com/i701/sarlink-portal.git
synced 2025-06-29 13:43:58 +00:00
Implement parental control features and enhance device management
- Added a new Parental Control page for managing device access and notifications. - Introduced blockDevice function to handle blocking and unblocking devices based on payment status. - Enhanced omada-actions.ts to include device blocking logic and improved error handling. - Updated DevicesTable component to integrate BlockDeviceButton for managing device states. - Implemented API route for checking device statuses and sending notifications for expiring devices. - Refactored payment processing to update device statuses upon successful payment verification. - Added new utility functions for API key validation and SMS notifications. These changes improve user control over device management and enhance the overall functionality of the application.
This commit is contained in:
37
lib/types.ts
37
lib/types.ts
@ -5,3 +5,40 @@ export type PaymentType = {
|
||||
amount: number;
|
||||
paid: boolean;
|
||||
};
|
||||
|
||||
interface IpAddress {
|
||||
ip: string;
|
||||
mask: number;
|
||||
}
|
||||
|
||||
interface Ipv6Address {
|
||||
ip: string;
|
||||
prefix: number;
|
||||
}
|
||||
|
||||
export interface MacAddress {
|
||||
ruleId?: number;
|
||||
name: string;
|
||||
macAddress: string;
|
||||
}
|
||||
|
||||
export interface GroupProfile {
|
||||
groupId: string;
|
||||
site?: string;
|
||||
name: string;
|
||||
buildIn?: boolean;
|
||||
ipList?: IpAddress[];
|
||||
ipv6List?: Ipv6Address[];
|
||||
macAddressList?: MacAddress[];
|
||||
count: number;
|
||||
type: number;
|
||||
resource: number;
|
||||
}
|
||||
|
||||
export interface OmadaResponse {
|
||||
errorCode: number;
|
||||
msg: string;
|
||||
result: {
|
||||
data: GroupProfile[];
|
||||
};
|
||||
}
|
||||
|
20
lib/utils.ts
20
lib/utils.ts
@ -26,3 +26,23 @@ export const formatMacAddress = (mac: string): string => {
|
||||
// Provide a fallback if formatted is null
|
||||
return formatted ? formatted.join("-") : "";
|
||||
};
|
||||
|
||||
export function validateApiKey(request: Request) {
|
||||
// Get API key from environment variable
|
||||
const validApiKey = process.env.CRON_API_KEY;
|
||||
|
||||
if (!validApiKey) {
|
||||
throw new Error("CRON_API_KEY is not configured");
|
||||
}
|
||||
|
||||
// Get API key from request header
|
||||
const apiKey = request.headers.get("x-api-key");
|
||||
|
||||
if (!apiKey) {
|
||||
throw new Error("API key is missing");
|
||||
}
|
||||
|
||||
if (apiKey !== validApiKey) {
|
||||
throw new Error("Invalid API key");
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user