Added Twig templating engine for handling views; Removed some unneeded CoffeeScript files

This commit is contained in:
Gregory Ballantine 2022-05-24 18:41:43 -04:00
parent 15585bac29
commit cb622ebea0
11 changed files with 194 additions and 113 deletions

19
archon.js Normal file
View File

@ -0,0 +1,19 @@
const express = require('express');
const app = express();
const port = 3000;
// Initialize the Twig template engine - this might get swapped for Twing later.
app.set('view engine', 'twig');
// Service static files from public/
app.use(express.static('public'));
// Load in route handlers
indexRoutes = require('./routes/index');
// Assign routes to handlers
app.get('/', indexRoutes.home);
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
});

View File

@ -1,2 +1,2 @@
@loadPage = (pagePath) ->
window.location.href = pagePath + '.html'
window.onload = () ->
console.log('Test.')

View File

@ -1,44 +0,0 @@
ldap = require('ldapjs')
userTable = {}
window.onload = ->
document.getElementById('ldapHost').textContent = localStorage.getItem('ldap_hostname')
userTable = document.getElementById('ldapUserList')
ldapGetUserList()
return
searchOpts =
filter: '(objectClass=posixAccount)'
scope: 'sub'
attributes: ['uid', 'displayName', 'mail']
ldapGetUserList = () ->
client = ldap.createClient(url: 'ldap://' + localStorage.getItem('ldap_hostname') + '/')
client.bind(localStorage.getItem('ldap_bind_dn'), localStorage.getItem('ldap_bind_pw'), (err) ->
if err
document.querySelector('h1').textContent = 'error'
return
else
client.search('ou=People,' + localStorage.getItem('ldap_base_dn'), searchOpts, (err, res) ->
if err
console.log(err)
return
else
res.on('searchEntry', (entry) ->
userEntry = document.createElement('tr')
userUid = document.createElement('td')
userUid.innerText = entry.object.uid
userEntry.appendChild(userUid)
userName = document.createElement('td')
userName.innerText = entry.object.displayName
userEntry.appendChild(userName)
userMail = document.createElement('td')
userMail.innerText = entry.object.mail
userEntry.appendChild(userMail)
userTable.appendChild(userEntry)
)
)
)

View File

@ -1,30 +0,0 @@
ldap = require('ldapjs')
loginForm = (event) ->
event.preventDefault()
bindHost = document.forms.loginForm.ldap_host.value
bindDn = document.forms.loginForm.bind_dn.value
bindPw = document.forms.loginForm.bind_pw.value
client = ldap.createClient(url: 'ldap://' + bindHost + '/')
client.bind bindDn, bindPw, (err) ->
if err
document.querySelector('h1').textContent = 'error'
else
document.querySelector('h1').textContent = 'Logged in!'
bindDn = document.forms.loginForm.bind_dn.value
baseDnBits = bindDn.split(',')
baseDnBits.shift()
baseDn = baseDnBits.join(',')
localStorage.setItem('ldap_hostname', document.forms.loginForm.ldap_host.value)
localStorage.setItem('ldap_bind_dn', bindDn)
localStorage.setItem('ldap_bind_pw', document.forms.loginForm.bind_pw.value)
localStorage.setItem('ldap_base_dn', baseDn)
loadPage('index')
return
return
window.onload = ->
document.getElementById('loginForm').addEventListener('submit', loginForm)
return

View File

@ -1,9 +0,0 @@
userCreateFormSubmit = (e) ->
e.preventDefault()
user_uid = document.forms.createUserForm.user_username.value
console.log(user_uid)
window.onload = ->
document.getElementById('createUserForm').addEventListener('submit', userCreateFormSubmit)
return

View File

@ -1,11 +0,0 @@
const express = require('express');
const app = express();
const port = 3000;
indexRoutes = require('./routes/index');
app.get('/', indexRoutes.home);
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
});

115
package-lock.json generated
View File

@ -10,7 +10,8 @@
"license": "BSD-2-Clause",
"dependencies": {
"express": "^4.18.1",
"grunt-dart-sass": "^2.0.1"
"grunt-dart-sass": "^2.0.1",
"twig": "^1.15.4"
},
"devDependencies": {
"grunt": "^1.5.3",
@ -18,6 +19,17 @@
"grunt-contrib-watch": "^1.1.0"
}
},
"node_modules/@babel/runtime": {
"version": "7.18.0",
"resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.18.0.tgz",
"integrity": "sha512-YMQvx/6nKEaucl0MY56mwIG483xk8SDNdlUwb2Ts6FUpr7fm85DxEmsY18LXBNhcTz6tO6JwZV8w1W06v8UKeg==",
"dependencies": {
"regenerator-runtime": "^0.13.4"
},
"engines": {
"node": ">=6.9.0"
}
},
"node_modules/abbrev": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz",
@ -104,8 +116,7 @@
"node_modules/balanced-match": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
"integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==",
"dev": true
"integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw=="
},
"node_modules/binary-extensions": {
"version": "2.2.0",
@ -174,7 +185,6 @@
"version": "1.1.11",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
"integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
"dev": true,
"dependencies": {
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
@ -289,8 +299,7 @@
"node_modules/concat-map": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
"integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=",
"dev": true
"integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s="
},
"node_modules/content-disposition": {
"version": "0.5.4",
@ -617,6 +626,11 @@
"node": ">=0.10.0"
}
},
"node_modules/foreachasync": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/foreachasync/-/foreachasync-3.0.0.tgz",
"integrity": "sha1-VQKYfchxS+M5IJfzLgBxyd7gfPY="
},
"node_modules/forwarded": {
"version": "0.2.0",
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz",
@ -1339,6 +1353,14 @@
"integrity": "sha512-XPQH8Z2GDP/Hwz2PCDrh2mth4yFejwA1OZ/81Ti3LgKyhDcEjsSsqFWZojHG0va/duGd+WyosY7eXLDoOyqcPw==",
"dev": true
},
"node_modules/locutus": {
"version": "2.0.16",
"resolved": "https://registry.npmjs.org/locutus/-/locutus-2.0.16.tgz",
"integrity": "sha512-pGfl6Hb/1mXLzrX5kl5lH7gz25ey0vwQssZp8Qo2CEF59di6KrAgdFm+0pW8ghLnvNzzJGj5tlWhhv2QbK3jeQ==",
"engines": {
"node": ">= 10"
}
},
"node_modules/lodash": {
"version": "4.17.21",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
@ -1479,7 +1501,6 @@
"version": "3.0.8",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.8.tgz",
"integrity": "sha512-6FsRAQsxQ61mw+qP1ZzbL9Bc78x2p5OqNgNpnoAFLTrX8n5Kxph0CsnhmKKNXTWjXqU5L0pGPR7hYk+XWZr60Q==",
"dev": true,
"dependencies": {
"brace-expansion": "^1.1.7"
},
@ -1810,6 +1831,11 @@
"node": ">= 0.10"
}
},
"node_modules/regenerator-runtime": {
"version": "0.13.9",
"resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.9.tgz",
"integrity": "sha512-p3VT+cOEgxFsRRA9X4lkI1E+k2/CtnKtU4gcxyaCUreilL/vqI6CdZ3wxVUx3UOUg+gnUOQQcRI7BmSI656MYA=="
},
"node_modules/resolve": {
"version": "1.22.0",
"resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.0.tgz",
@ -2068,6 +2094,23 @@
"node": ">=0.6"
}
},
"node_modules/twig": {
"version": "1.15.4",
"resolved": "https://registry.npmjs.org/twig/-/twig-1.15.4.tgz",
"integrity": "sha512-gRpGrpdf+MswqF6eSjEdYZTa/jt3ZWHK/NU59IbTYJMBQXJ1W+7IxaGEwLkQjd+mNT15j9sQTzQumxUBkuQueQ==",
"dependencies": {
"@babel/runtime": "^7.8.4",
"locutus": "^2.0.11",
"minimatch": "3.0.x",
"walk": "2.3.x"
},
"bin": {
"twigjs": "bin/twigjs"
},
"engines": {
"node": ">=8.16"
}
},
"node_modules/type-is": {
"version": "1.6.18",
"resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz",
@ -2172,6 +2215,14 @@
"node": ">= 0.8"
}
},
"node_modules/walk": {
"version": "2.3.15",
"resolved": "https://registry.npmjs.org/walk/-/walk-2.3.15.tgz",
"integrity": "sha512-4eRTBZljBfIISK1Vnt69Gvr2w/wc3U6Vtrw7qiN5iqYJPH7LElcYh/iU4XWhdCy2dZqv1ToMyYlybDylfG/5Vg==",
"dependencies": {
"foreachasync": "^3.0.0"
}
},
"node_modules/websocket-driver": {
"version": "0.7.4",
"resolved": "https://registry.npmjs.org/websocket-driver/-/websocket-driver-0.7.4.tgz",
@ -2215,6 +2266,14 @@
}
},
"dependencies": {
"@babel/runtime": {
"version": "7.18.0",
"resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.18.0.tgz",
"integrity": "sha512-YMQvx/6nKEaucl0MY56mwIG483xk8SDNdlUwb2Ts6FUpr7fm85DxEmsY18LXBNhcTz6tO6JwZV8w1W06v8UKeg==",
"requires": {
"regenerator-runtime": "^0.13.4"
}
},
"abbrev": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz",
@ -2286,8 +2345,7 @@
"balanced-match": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
"integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==",
"dev": true
"integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw=="
},
"binary-extensions": {
"version": "2.2.0",
@ -2348,7 +2406,6 @@
"version": "1.1.11",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
"integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
"dev": true,
"requires": {
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
@ -2430,8 +2487,7 @@
"concat-map": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
"integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=",
"dev": true
"integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s="
},
"content-disposition": {
"version": "0.5.4",
@ -2686,6 +2742,11 @@
"for-in": "^1.0.1"
}
},
"foreachasync": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/foreachasync/-/foreachasync-3.0.0.tgz",
"integrity": "sha1-VQKYfchxS+M5IJfzLgBxyd7gfPY="
},
"forwarded": {
"version": "0.2.0",
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz",
@ -3238,6 +3299,11 @@
"integrity": "sha512-XPQH8Z2GDP/Hwz2PCDrh2mth4yFejwA1OZ/81Ti3LgKyhDcEjsSsqFWZojHG0va/duGd+WyosY7eXLDoOyqcPw==",
"dev": true
},
"locutus": {
"version": "2.0.16",
"resolved": "https://registry.npmjs.org/locutus/-/locutus-2.0.16.tgz",
"integrity": "sha512-pGfl6Hb/1mXLzrX5kl5lH7gz25ey0vwQssZp8Qo2CEF59di6KrAgdFm+0pW8ghLnvNzzJGj5tlWhhv2QbK3jeQ=="
},
"lodash": {
"version": "4.17.21",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
@ -3351,7 +3417,6 @@
"version": "3.0.8",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.8.tgz",
"integrity": "sha512-6FsRAQsxQ61mw+qP1ZzbL9Bc78x2p5OqNgNpnoAFLTrX8n5Kxph0CsnhmKKNXTWjXqU5L0pGPR7hYk+XWZr60Q==",
"dev": true,
"requires": {
"brace-expansion": "^1.1.7"
}
@ -3592,6 +3657,11 @@
"resolve": "^1.9.0"
}
},
"regenerator-runtime": {
"version": "0.13.9",
"resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.9.tgz",
"integrity": "sha512-p3VT+cOEgxFsRRA9X4lkI1E+k2/CtnKtU4gcxyaCUreilL/vqI6CdZ3wxVUx3UOUg+gnUOQQcRI7BmSI656MYA=="
},
"resolve": {
"version": "1.22.0",
"resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.0.tgz",
@ -3789,6 +3859,17 @@
"resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz",
"integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA=="
},
"twig": {
"version": "1.15.4",
"resolved": "https://registry.npmjs.org/twig/-/twig-1.15.4.tgz",
"integrity": "sha512-gRpGrpdf+MswqF6eSjEdYZTa/jt3ZWHK/NU59IbTYJMBQXJ1W+7IxaGEwLkQjd+mNT15j9sQTzQumxUBkuQueQ==",
"requires": {
"@babel/runtime": "^7.8.4",
"locutus": "^2.0.11",
"minimatch": "3.0.x",
"walk": "2.3.x"
}
},
"type-is": {
"version": "1.6.18",
"resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz",
@ -3873,6 +3954,14 @@
"resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",
"integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw="
},
"walk": {
"version": "2.3.15",
"resolved": "https://registry.npmjs.org/walk/-/walk-2.3.15.tgz",
"integrity": "sha512-4eRTBZljBfIISK1Vnt69Gvr2w/wc3U6Vtrw7qiN5iqYJPH7LElcYh/iU4XWhdCy2dZqv1ToMyYlybDylfG/5Vg==",
"requires": {
"foreachasync": "^3.0.0"
}
},
"websocket-driver": {
"version": "0.7.4",
"resolved": "https://registry.npmjs.org/websocket-driver/-/websocket-driver-0.7.4.tgz",

View File

@ -2,9 +2,9 @@
"name": "archon",
"version": "0.1.0",
"description": "A web-based LDAP user and group manager",
"main": "index.js",
"main": "archon.js",
"scripts": {
"start": "node index.js",
"start": "node archon.js",
"test": "echo \"Error: no test specified\" && exit 1",
"grunt": "grunt"
},
@ -16,7 +16,8 @@
"license": "BSD-2-Clause",
"dependencies": {
"express": "^4.18.1",
"grunt-dart-sass": "^2.0.1"
"grunt-dart-sass": "^2.0.1",
"twig": "^1.15.4"
},
"devDependencies": {
"grunt": "^1.5.3",

View File

@ -1,3 +1,3 @@
exports.home = function(req, res, next) {
res.send('Hello World!');
res.render('index');
};

34
views/index.twig Normal file
View File

@ -0,0 +1,34 @@
{% extends 'layout.twig' %}
{% block content %}
<header class="row">
<div class="columns twelve u-text-center">
<h1>Archon LDAP Manager</h1>
</div>
</header>
<section id="connectionInfo" class="row">
<div class="columns twelve u-text-center">
<p>Connected to: <span id="ldapHost"></span></p>
</div>
</section>
<section id="userActions" class="row">
<div class="columns twelve">
<p><a href="user/create.html">Create new user</a></p>
</div>
</section>
<section id="ldapObjectTable" class="row">
<table>
<thead>
<tr>
<th>User ID</th>
<th>Display Name</th>
<th>Email Address</th>
</tr>
</thead>
<tbody id="ldapUserList"></tbody>
</table>
</section>
{% endblock %}

32
views/layout.twig Normal file
View File

@ -0,0 +1,32 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/skeleton/2.0.4/skeleton.min.css">
<link rel="stylesheet" href="/styles/archon.css">
<title>Archon LDAP Manager</title>
<script src="/js/archon.js" charset="utf-8"></script>
{% block scripts %}{% endblock %}
</head>
<body>
<div class="container">
{% block content %}{% endblock %}
</div>
<footer id="footer">
<div class="container fluid">
<div class="row">
<div class="columns three"><p></p></div>
<div class="columns six">
<p class="no-margin">This app was built using:</p>
<p class="no-margin">
Node.js <span id="node-version"></span>,
Chromium <span id="chrome-version"></span>,
and Electron <span id="electron-version"></span>.
</p>
</div>
</div>
</div>
</footer>
</body>
</html>