mirror of
https://github.com/freedbygrace/ActiveDirectoryManager.git
synced 2026-08-20 15:23:15 +00:00
Add user authentication and Active Directory management features. Includes a new admin UI and Swagger API documentation.
Replit-Commit-Author: Agent Replit-Commit-Session-Id: 705f2157-ef97-4fbd-89e4-8c7f2ecaea90 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/7ed01c5f-a82d-405a-b728-b2e3d127c60c/e9f0a10f-e323-455c-82c9-1da4a687f20e.jpg
This commit is contained in:
+107
-59
@@ -2,98 +2,146 @@ import { pgTable, text, serial, integer, boolean, timestamp, jsonb } from "drizz
|
||||
import { createInsertSchema } from "drizzle-zod";
|
||||
import { z } from "zod";
|
||||
|
||||
// User schema for authentication
|
||||
// User schema for local authentication
|
||||
export const users = pgTable("users", {
|
||||
id: serial("id").primaryKey(),
|
||||
username: text("username").notNull().unique(),
|
||||
password: text("password").notNull(),
|
||||
email: text("email"),
|
||||
isAdmin: boolean("is_admin").default(false).notNull(),
|
||||
createdAt: timestamp("created_at").defaultNow().notNull(),
|
||||
fullName: text("full_name"),
|
||||
role: text("role").default("user"),
|
||||
createdAt: timestamp("created_at").defaultNow(),
|
||||
});
|
||||
|
||||
export const insertUserSchema = createInsertSchema(users).pick({
|
||||
username: true,
|
||||
password: true,
|
||||
email: true,
|
||||
isAdmin: true,
|
||||
});
|
||||
|
||||
// API Tokens
|
||||
// API Token schema
|
||||
export const apiTokens = pgTable("api_tokens", {
|
||||
id: serial("id").primaryKey(),
|
||||
name: text("name").notNull(),
|
||||
token: text("token").notNull().unique(),
|
||||
userId: integer("user_id").notNull(),
|
||||
createdAt: timestamp("created_at").defaultNow().notNull(),
|
||||
lastUsedAt: timestamp("last_used_at"),
|
||||
permissions: jsonb("permissions").notNull(),
|
||||
expiresAt: timestamp("expires_at"),
|
||||
createdAt: timestamp("created_at").defaultNow(),
|
||||
});
|
||||
|
||||
export const insertApiTokenSchema = createInsertSchema(apiTokens).pick({
|
||||
name: true,
|
||||
userId: true,
|
||||
expiresAt: true,
|
||||
});
|
||||
|
||||
// LDAP Connections
|
||||
// LDAP Connection schema
|
||||
export const ldapConnections = pgTable("ldap_connections", {
|
||||
id: serial("id").primaryKey(),
|
||||
name: text("name").notNull(),
|
||||
server: text("server").notNull(),
|
||||
port: integer("port").notNull(),
|
||||
authType: text("auth_type").notNull(),
|
||||
domain: text("domain").notNull(),
|
||||
port: integer("port").default(389),
|
||||
useSSL: boolean("use_ssl").default(true),
|
||||
username: text("username").notNull(),
|
||||
password: text("password").notNull(),
|
||||
baseDN: text("base_dn"),
|
||||
useTLS: boolean("use_tls").default(false),
|
||||
status: text("status").default("disconnected"),
|
||||
lastConnected: timestamp("last_connected"),
|
||||
createdAt: timestamp("created_at").defaultNow(),
|
||||
});
|
||||
|
||||
export const insertLdapConnectionSchema = createInsertSchema(ldapConnections).pick({
|
||||
name: true,
|
||||
server: true,
|
||||
port: true,
|
||||
authType: true,
|
||||
username: true,
|
||||
password: true,
|
||||
baseDN: true,
|
||||
useTLS: true,
|
||||
});
|
||||
|
||||
// Activity Log
|
||||
export const activityLogs = pgTable("activity_logs", {
|
||||
// Active Directory schemas
|
||||
export const adUsers = pgTable("ad_users", {
|
||||
id: serial("id").primaryKey(),
|
||||
action: text("action").notNull(),
|
||||
resource: text("resource").notNull(),
|
||||
resourceType: text("resource_type").notNull(),
|
||||
userId: integer("user_id"),
|
||||
username: text("username"),
|
||||
status: text("status").notNull(),
|
||||
details: jsonb("details"),
|
||||
timestamp: timestamp("timestamp").defaultNow().notNull(),
|
||||
connectionId: integer("connection_id").notNull(),
|
||||
distinguishedName: text("distinguished_name").notNull(),
|
||||
sAMAccountName: text("sam_account_name").notNull(),
|
||||
userPrincipalName: text("user_principal_name"),
|
||||
givenName: text("given_name"),
|
||||
surname: text("surname"),
|
||||
displayName: text("display_name"),
|
||||
email: text("email"),
|
||||
enabled: boolean("enabled").default(true),
|
||||
lastLogon: timestamp("last_logon"),
|
||||
memberOf: jsonb("member_of"),
|
||||
adProperties: jsonb("ad_properties"),
|
||||
});
|
||||
|
||||
export const insertActivityLogSchema = createInsertSchema(activityLogs).pick({
|
||||
action: true,
|
||||
resource: true,
|
||||
resourceType: true,
|
||||
userId: true,
|
||||
username: true,
|
||||
status: true,
|
||||
details: true,
|
||||
export const adGroups = pgTable("ad_groups", {
|
||||
id: serial("id").primaryKey(),
|
||||
connectionId: integer("connection_id").notNull(),
|
||||
distinguishedName: text("distinguished_name").notNull(),
|
||||
sAMAccountName: text("sam_account_name").notNull(),
|
||||
groupType: text("group_type"),
|
||||
description: text("description"),
|
||||
members: jsonb("members"),
|
||||
adProperties: jsonb("ad_properties"),
|
||||
});
|
||||
|
||||
// Types
|
||||
export const adOrgUnits = pgTable("ad_org_units", {
|
||||
id: serial("id").primaryKey(),
|
||||
connectionId: integer("connection_id").notNull(),
|
||||
distinguishedName: text("distinguished_name").notNull(),
|
||||
name: text("name").notNull(),
|
||||
description: text("description"),
|
||||
adProperties: jsonb("ad_properties"),
|
||||
});
|
||||
|
||||
export const adComputers = pgTable("ad_computers", {
|
||||
id: serial("id").primaryKey(),
|
||||
connectionId: integer("connection_id").notNull(),
|
||||
distinguishedName: text("distinguished_name").notNull(),
|
||||
name: text("name").notNull(),
|
||||
dnsHostName: text("dns_host_name"),
|
||||
operatingSystem: text("operating_system"),
|
||||
operatingSystemVersion: text("operating_system_version"),
|
||||
lastLogon: timestamp("last_logon"),
|
||||
enabled: boolean("enabled").default(true),
|
||||
adProperties: jsonb("ad_properties"),
|
||||
});
|
||||
|
||||
export const adDomains = pgTable("ad_domains", {
|
||||
id: serial("id").primaryKey(),
|
||||
connectionId: integer("connection_id").notNull(),
|
||||
distinguishedName: text("distinguished_name").notNull(),
|
||||
name: text("name").notNull(),
|
||||
netBIOSName: text("net_bios_name"),
|
||||
forestName: text("forest_name"),
|
||||
domainFunctionality: text("domain_functionality"),
|
||||
adProperties: jsonb("ad_properties"),
|
||||
});
|
||||
|
||||
// Generate insertion schemas
|
||||
export const insertUserSchema = createInsertSchema(users).omit({ id: true, createdAt: true });
|
||||
export const insertApiTokenSchema = createInsertSchema(apiTokens).omit({ id: true, createdAt: true });
|
||||
export const insertLdapConnectionSchema = createInsertSchema(ldapConnections).omit({ id: true, createdAt: true, lastConnected: true });
|
||||
export const insertAdUserSchema = createInsertSchema(adUsers).omit({ id: true });
|
||||
export const insertAdGroupSchema = createInsertSchema(adGroups).omit({ id: true });
|
||||
export const insertAdOrgUnitSchema = createInsertSchema(adOrgUnits).omit({ id: true });
|
||||
export const insertAdComputerSchema = createInsertSchema(adComputers).omit({ id: true });
|
||||
export const insertAdDomainSchema = createInsertSchema(adDomains).omit({ id: true });
|
||||
|
||||
// Login schema
|
||||
export const loginSchema = z.object({
|
||||
username: z.string().min(1, "Username is required"),
|
||||
password: z.string().min(1, "Password is required"),
|
||||
});
|
||||
|
||||
// API query parameters schema
|
||||
export const apiQuerySchema = z.object({
|
||||
filter: z.string().optional(),
|
||||
select: z.string().optional(),
|
||||
expand: z.string().optional(),
|
||||
orderBy: z.string().optional(),
|
||||
top: z.string().optional(),
|
||||
skip: z.string().optional(),
|
||||
});
|
||||
|
||||
// Export types
|
||||
export type User = typeof users.$inferSelect;
|
||||
export type InsertUser = z.infer<typeof insertUserSchema>;
|
||||
|
||||
export type ApiToken = typeof apiTokens.$inferSelect;
|
||||
export type InsertApiToken = z.infer<typeof insertApiTokenSchema>;
|
||||
|
||||
export type LdapConnection = typeof ldapConnections.$inferSelect;
|
||||
export type InsertLdapConnection = z.infer<typeof insertLdapConnectionSchema>;
|
||||
|
||||
export type ActivityLog = typeof activityLogs.$inferSelect;
|
||||
export type InsertActivityLog = z.infer<typeof insertActivityLogSchema>;
|
||||
export type AdUser = typeof adUsers.$inferSelect;
|
||||
export type InsertAdUser = z.infer<typeof insertAdUserSchema>;
|
||||
export type AdGroup = typeof adGroups.$inferSelect;
|
||||
export type InsertAdGroup = z.infer<typeof insertAdGroupSchema>;
|
||||
export type AdOrgUnit = typeof adOrgUnits.$inferSelect;
|
||||
export type InsertAdOrgUnit = z.infer<typeof insertAdOrgUnitSchema>;
|
||||
export type AdComputer = typeof adComputers.$inferSelect;
|
||||
export type InsertAdComputer = z.infer<typeof insertAdComputerSchema>;
|
||||
export type AdDomain = typeof adDomains.$inferSelect;
|
||||
export type InsertAdDomain = z.infer<typeof insertAdDomainSchema>;
|
||||
export type Login = z.infer<typeof loginSchema>;
|
||||
export type ApiQuery = z.infer<typeof apiQuerySchema>;
|
||||
|
||||
Reference in New Issue
Block a user