Skip to content

Commit

Permalink
Write pfsense user <bcrypt-hash> and <md5-hash> fields to opnsene…
Browse files Browse the repository at this point in the history
… user `<password>` (#8)

* write pfsense user <bcrypt-hash> and <md5-hash> fields to opnsene user <password>

* remove log
  • Loading branch information
mwood77 authored Nov 8, 2023
1 parent c8abb69 commit 061ae6b
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 5 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pf2open",
"version": "0.1.2",
"version": "0.1.3",
"scripts": {
"ng": "ng",
"start": "ng serve",
Expand Down
17 changes: 17 additions & 0 deletions src/app/mappings/opnsense.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,23 @@ export interface System {
domain?: string;
timezone?: string;
language?: string;
user?: User;
}

export interface User {
[x: string]: any;
name?: string;
descr?: string;
scope?: string;
groupname?: string;
password?: string;
uid?: number;
priv?: string;
'md5-hash'?: string;
expires?: string;
authorizedkeys?: string;
ipsecpsk?: string;
'bcrypt-hash'?: string;
}

export interface Configapply {
Expand Down
1 change: 1 addition & 0 deletions src/app/mappings/pfsense-complex.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1050,6 +1050,7 @@ export interface User {
expires?: string;
authorizedkeys?: string;
ipsecpsk?: string;
'bcrypt-hash'?: string;
}

export interface Group {
Expand Down
23 changes: 21 additions & 2 deletions src/app/services/converter.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
Rule as opnRule,
Opnsense,
System as opnSystem,
User,
} from '../mappings/opnsense.interface';
import { v1 as uuidv1 } from 'uuid'
import { XMLParser, XMLBuilder } from 'fast-xml-parser';
Expand Down Expand Up @@ -126,16 +127,34 @@ export class ConverterService {
system.hostname = pfSystem.hostname;
system.domain = pfSystem.domain;
system.timezone = pfSystem.timezone;

system.user = {
...pfSystem.user
}

// Map bcrypt-hash or md5-hash to password
if (pfSystem.user?.['bcrypt-hash']) {
system.user.password = pfSystem.user['bcrypt-hash'];
delete system.user['bcrypt-hash'];

}
if (pfSystem.user?.['md5-hash']) {
system.user.password = pfSystem.user['md5-hash'];
delete system.user['md5-hash'];
}

// dedupe pfSense.system.user
delete input.pfsense.system?.user;
}

//@ts-ignore
// @ts-ignore
const opnsense: Opnsense = {
version: 1,
'config-apply': {
uuid: uuidv1(),
},
system,
...input.pfsense,
system,
}

const opnsenseJson: opnRoot = {
Expand Down

0 comments on commit 061ae6b

Please sign in to comment.