|
@@ -8,9 +8,9 @@ import { ILDAPManager } from '../src/ldapInterface';
|
|
|
import LDAPEntry from '../src/LDAPEntry';
|
|
import LDAPEntry from '../src/LDAPEntry';
|
|
|
import ConfigManager, { LDAPAttribute, LDAPCategory } from '../src/ConfigLoader';
|
|
import ConfigManager, { LDAPAttribute, LDAPCategory } from '../src/ConfigLoader';
|
|
|
|
|
|
|
|
-function GetCurrentCategory(req: express.Request, defaultResult: LDAPCategory): LDAPCategory {
|
|
|
|
|
|
|
+function GetCurrentCategory(req: express.Request, defaultResult: LDAPCategory): LDAPCategory|null {
|
|
|
if (!req.query["category"])
|
|
if (!req.query["category"])
|
|
|
- return defaultResult;
|
|
|
|
|
|
|
+ return null;
|
|
|
let query = Array.isArray(req.query["category"]) ? req.query["category"][0] : req.query["category"];
|
|
let query = Array.isArray(req.query["category"]) ? req.query["category"][0] : req.query["category"];
|
|
|
return LinkToCategory(query.toString()) || defaultResult;
|
|
return LinkToCategory(query.toString()) || defaultResult;
|
|
|
}
|
|
}
|
|
@@ -31,27 +31,40 @@ router.get('/', (req: express.Request, res: express.Response) => {
|
|
|
if (!Security.requireLoggedUser(req, res))
|
|
if (!Security.requireLoggedUser(req, res))
|
|
|
return;
|
|
return;
|
|
|
req.ldapManager.GetInstance().then((ldap: ILDAPManager): void => {
|
|
req.ldapManager.GetInstance().then((ldap: ILDAPManager): void => {
|
|
|
- let categories = ConfigManager.GetInstance().GetCategories();
|
|
|
|
|
- let category = GetCurrentCategory(req, categories[0]);
|
|
|
|
|
- ldap.ListEntries(category).then(items => {
|
|
|
|
|
- res.render("category", {
|
|
|
|
|
- categoryName: category.GetName(),
|
|
|
|
|
- allCategories: categories.map((i) => { return { name: i.GetName(), lnk: "?category="+CategoryToLink(i) }}),
|
|
|
|
|
- items: items,
|
|
|
|
|
- attributes: category.GetAttributes(),
|
|
|
|
|
- DnToLnk: DnToLink,
|
|
|
|
|
- GetAttributeLink: function (attr: LDAPAttribute, entityDn: string) {
|
|
|
|
|
- if (attr.type.startsWith("entry")) {
|
|
|
|
|
- let link = attr.type.split("#", 2)[1];
|
|
|
|
|
- if (link)
|
|
|
|
|
- return "?category=" + link + "#" + DnToLink(entityDn);
|
|
|
|
|
- }
|
|
|
|
|
- return null;
|
|
|
|
|
- },
|
|
|
|
|
- GetAttributeValue: function (user: LDAPEntry, attribute: LDAPAttribute) {
|
|
|
|
|
- return user.GetAttributeByName(attribute.name);
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ ldap.GetTree().then(root => {
|
|
|
|
|
+ let categories = ConfigManager.GetInstance().GetCategories();
|
|
|
|
|
+ let category = GetCurrentCategory(req, categories[0]);
|
|
|
|
|
+
|
|
|
|
|
+ if (category == null) {
|
|
|
|
|
+ res.render("index", {
|
|
|
|
|
+ tree: root.GetChildren()[0],
|
|
|
|
|
+ rootSrc: "?category=" + CategoryToLink(categories[0])
|
|
|
|
|
+ });
|
|
|
|
|
+ } else {
|
|
|
|
|
+ let session = Security.GetSession(req);
|
|
|
|
|
+
|
|
|
|
|
+ ldap.ListEntries(category).then(items => {
|
|
|
|
|
+ res.render("category", {
|
|
|
|
|
+ csrf: session ? session.GetCSRFToken() : "",
|
|
|
|
|
+ categoryName: category?.GetName(),
|
|
|
|
|
+ allCategories: categories.map((i) => { return { name: i.GetName(), lnk: "?category=" + CategoryToLink(i) } }),
|
|
|
|
|
+ items: items,
|
|
|
|
|
+ attributes: category?.GetAttributes(),
|
|
|
|
|
+ DnToLnk: DnToLink,
|
|
|
|
|
+ GetAttributeLink: function (attr: LDAPAttribute, entityDn: string) {
|
|
|
|
|
+ if (attr.type.startsWith("entry")) {
|
|
|
|
|
+ let link = attr.type.split("#", 2)[1];
|
|
|
|
|
+ if (link)
|
|
|
|
|
+ return "?category=" + link + "#" + DnToLink(entityDn);
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
|
|
+ },
|
|
|
|
|
+ GetAttributeValue: function (user: LDAPEntry, attribute: LDAPAttribute) {
|
|
|
|
|
+ return user.GetAttributeByName(attribute.name);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|