Skip to content

Instantly share code, notes, and snippets.

@butlerx
Created May 29, 2017 16:17
Show Gist options
  • Save butlerx/6b30910513e59747fc931267c2b20d80 to your computer and use it in GitHub Desktop.
Save butlerx/6b30910513e59747fc931267c2b20d80 to your computer and use it in GitHub Desktop.
original script to generate vhost
#!/bin/node
//ldapsearch -D cn=root,ou=ldap,o=redbrick -xLLL -y /etc/ldap.secret objectClass uid gidNumber > entry.ldif
const fs = require('fs');
const _ = require('lodash');
const ldif = require('ldif');
const file = ldif.parseFile('./entry.ldif');
const users = [];
for (const record of file.entries) {
if (record.attributes) {
const user = {};
let reserved = false;
for (const atrib of record.attributes) {
if (atrib.attribute.attribute === 'uid') {
user.username = atrib.value.value;
}
if (atrib.attribute.attribute === 'gidNumber') {
user.gid = atrib.value.value;
}
if (atrib.value.value === 'club' || atrib.value.value === 'committe' || atrib.value.value === 'society' || atrib.value.value === 'associate' || atrib.value.value === 'member') {
user.group = atrib.value.value;
} else if (atrib.value.value === 'redbrick' || atrib.value.value === 'reserved') {
reserved = true;
}
}
if (!_.isEmpty(user) && !reserved) {
users.push(user);
}
}
}
for (const user of users) {
if (_.isEmpty(user.group)) {
switch (user.gid) {
case 100:
user.group = 'committe';
break;
case 101:
user.group = 'society';
break;
case 102:
user.group = 'club';
break;
case 103:
user.group = 'member';
break;
case 105:
user.group = 'founder';
break;
case 107:
user.group = 'associat';
break;
case 31382:
user.group = 'dcu';
break;
case 109:
user.group = 'staff';
break;
case 1014:
user.group = 'projects';
break;
case 1017:
user.group = 'redbrick';
break;
case 1016:
user.group = 'intersoc';
}
}
if (!_.isEmpty(user.username) && !_.isEmpty(user.group)) {
fs.appendFileSync('user_vhost_list.conf', `use VHost /storage/webtree/${user.username.charAt(0)}/${user.username} ${user.username} ${user.group} ${user.username}\n`);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment