Add ability to manage computers and computer groups from web interface
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
718414d924
commit
d6e4ea2e56
@ -0,0 +1,92 @@
|
|||||||
|
import CRUDBase from '../CRUDBase.js'
|
||||||
|
|
||||||
|
class MachineResource extends CRUDBase {
|
||||||
|
constructor() {
|
||||||
|
super()
|
||||||
|
|
||||||
|
this.endpoint = '/api/v1/ldap/machines'
|
||||||
|
this.required_fields = ['name', 'description']
|
||||||
|
this.permission_base = 'v1:ldap:machines'
|
||||||
|
|
||||||
|
this.item = 'Computer'
|
||||||
|
this.plural = 'Computers'
|
||||||
|
|
||||||
|
this.listing_definition = {
|
||||||
|
columns: [
|
||||||
|
{
|
||||||
|
name: 'Machine Name',
|
||||||
|
field: 'name',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Host Name',
|
||||||
|
field: 'host_name',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Description',
|
||||||
|
field: 'description',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
actions: [
|
||||||
|
{
|
||||||
|
type: 'resource',
|
||||||
|
position: 'main',
|
||||||
|
action: 'insert',
|
||||||
|
text: 'Create New',
|
||||||
|
color: 'success',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'resource',
|
||||||
|
position: 'row',
|
||||||
|
action: 'update',
|
||||||
|
icon: 'fa fa-edit',
|
||||||
|
color: 'primary',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'resource',
|
||||||
|
position: 'row',
|
||||||
|
action: 'delete',
|
||||||
|
icon: 'fa fa-times',
|
||||||
|
color: 'danger',
|
||||||
|
confirm: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
this.form_definition = {
|
||||||
|
// back_action: {
|
||||||
|
// text: 'Back',
|
||||||
|
// action: 'back',
|
||||||
|
// },
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
name: 'Machine Name',
|
||||||
|
field: 'name',
|
||||||
|
placeholder: 'DNS01',
|
||||||
|
required: true,
|
||||||
|
type: 'text',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Description',
|
||||||
|
field: 'description',
|
||||||
|
required: true,
|
||||||
|
type: 'textarea',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Location',
|
||||||
|
field: 'location',
|
||||||
|
type: 'text',
|
||||||
|
placeholder: 'Server room 1',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Host Name (FQDN)',
|
||||||
|
field: 'host_name',
|
||||||
|
type: 'text',
|
||||||
|
placeholder: 'dns01.my.domain',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const ldap_machine = new MachineResource()
|
||||||
|
export { ldap_machine }
|
@ -0,0 +1,90 @@
|
|||||||
|
import CRUDBase from '../CRUDBase.js'
|
||||||
|
|
||||||
|
class MachineGroupResource extends CRUDBase {
|
||||||
|
constructor() {
|
||||||
|
super()
|
||||||
|
|
||||||
|
this.endpoint = '/api/v1/ldap/machine-groups'
|
||||||
|
this.required_fields = ['name']
|
||||||
|
this.permission_base = 'v1:ldap:machine_groups'
|
||||||
|
|
||||||
|
this.item = 'Computer Group'
|
||||||
|
this.plural = 'Computer Groups'
|
||||||
|
|
||||||
|
this.listing_definition = {
|
||||||
|
columns: [
|
||||||
|
{
|
||||||
|
name: 'Group Name',
|
||||||
|
field: 'name',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: '# Computers',
|
||||||
|
field: 'machine_ids',
|
||||||
|
renderer: machine_ids => Array.isArray(machine_ids) ? machine_ids.length : 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Description',
|
||||||
|
field: 'description',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
actions: [
|
||||||
|
{
|
||||||
|
type: 'resource',
|
||||||
|
position: 'main',
|
||||||
|
action: 'insert',
|
||||||
|
text: 'Create New',
|
||||||
|
color: 'success',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'resource',
|
||||||
|
position: 'row',
|
||||||
|
action: 'update',
|
||||||
|
icon: 'fa fa-edit',
|
||||||
|
color: 'primary',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'resource',
|
||||||
|
position: 'row',
|
||||||
|
action: 'delete',
|
||||||
|
icon: 'fa fa-times',
|
||||||
|
color: 'danger',
|
||||||
|
confirm: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
this.form_definition = {
|
||||||
|
// back_action: {
|
||||||
|
// text: 'Back',
|
||||||
|
// action: 'back',
|
||||||
|
// },
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
name: 'Group Name',
|
||||||
|
field: 'name',
|
||||||
|
placeholder: 'DNS Servers',
|
||||||
|
required: true,
|
||||||
|
type: 'text',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Description',
|
||||||
|
field: 'description',
|
||||||
|
type: 'textarea',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Computers',
|
||||||
|
field: 'machine_ids',
|
||||||
|
type: 'select.dynamic.multiple',
|
||||||
|
options: {
|
||||||
|
resource: 'ldap/Machine',
|
||||||
|
display: machine => `${machine.name}${machine.host_name ? ' (' + machine.host_name + ')' : ''}`,
|
||||||
|
value: 'id',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const ldap_machinegroup = new MachineGroupResource()
|
||||||
|
export { ldap_machinegroup }
|
@ -0,0 +1,64 @@
|
|||||||
|
const { Model } = require('flitter-orm')
|
||||||
|
const LDAP = require('ldapjs')
|
||||||
|
const bcrypt = require('bcrypt')
|
||||||
|
|
||||||
|
class MachineModel extends Model {
|
||||||
|
static get services() {
|
||||||
|
return [...super.services, 'models', 'ldap_server', 'configs']
|
||||||
|
}
|
||||||
|
|
||||||
|
static get schema() {
|
||||||
|
return {
|
||||||
|
name: String,
|
||||||
|
bind_password: String,
|
||||||
|
description: String,
|
||||||
|
host_name: String,
|
||||||
|
location: String,
|
||||||
|
active: { type: Boolean, default: true },
|
||||||
|
ldap_visible: { type: Boolean, default: true },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async to_api() {
|
||||||
|
return {
|
||||||
|
id: this.id,
|
||||||
|
name: this.name,
|
||||||
|
description: this.description,
|
||||||
|
host_name: this.host_name,
|
||||||
|
location: this.location,
|
||||||
|
ldap_visible: this.ldap_visible,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async set_bind_password(password) {
|
||||||
|
this.bind_password = await bcrypt.hash(password, 10)
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
async check_bind_password(password) {
|
||||||
|
return await bcrypt.compare(password, this.bind_password)
|
||||||
|
}
|
||||||
|
|
||||||
|
get dn() {
|
||||||
|
return LDAP.parseDN(`cn=${this.name},${this.ldap_server.machine_dn().format(this.configs.get('ldap:server.format'))}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
async to_ldap() {
|
||||||
|
const data = {
|
||||||
|
cn: this.name,
|
||||||
|
dn: this.dn.format(this.configs.get('ldap:server.format')),
|
||||||
|
name: this.name,
|
||||||
|
id: this.id,
|
||||||
|
objectClass: ['computer'],
|
||||||
|
description: this.description,
|
||||||
|
dNSHostName: this.host_name,
|
||||||
|
location: this.location,
|
||||||
|
primaryGroupID: 515, // compat with AD
|
||||||
|
sAMAccountType: 805306369, // compat with AD
|
||||||
|
}
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = exports = MachineModel
|
@ -0,0 +1,47 @@
|
|||||||
|
const { Model } = require('flitter-orm')
|
||||||
|
const uuid = require('uuid').v4
|
||||||
|
const LDAP = require('ldapjs')
|
||||||
|
|
||||||
|
class MachineGroupModel extends Model {
|
||||||
|
static get services() {
|
||||||
|
return [...super.services, 'models', 'ldap_server', 'configs']
|
||||||
|
}
|
||||||
|
|
||||||
|
static get schema() {
|
||||||
|
return {
|
||||||
|
name: String,
|
||||||
|
description: String,
|
||||||
|
UUID: { type: String, default: uuid },
|
||||||
|
active: { type: Boolean, default: true },
|
||||||
|
machine_ids: [String],
|
||||||
|
ldap_visible: { type: Boolean, default: true },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async to_api() {
|
||||||
|
return {
|
||||||
|
id: this.id,
|
||||||
|
name: this.name,
|
||||||
|
description: this.description || '',
|
||||||
|
UUID: this.UUID,
|
||||||
|
machine_ids: this.machine_ids,
|
||||||
|
ldap_visible: this.ldap_visible,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
get dn() {
|
||||||
|
return LDAP.parseDN(`cn=${this.name},${this.ldap_server.machine_group_dn().format(this.configs.get('ldap:server.format'))}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
async to_ldap() {
|
||||||
|
return {
|
||||||
|
cn: this.name,
|
||||||
|
dn: this.dn.format(this.configs.get('ldap:server.format')),
|
||||||
|
id: this.id,
|
||||||
|
uuid: this.UUID,
|
||||||
|
description: this.description,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = exports = MachineGroupModel
|
Loading…
Reference in new issue