48 lines
1.3 KiB
TypeScript
48 lines
1.3 KiB
TypeScript
// import ldap from "ldapjs";
|
|
import { Client } from "ldapts";
|
|
|
|
export async function getMembers(year: string, term: string) {
|
|
// LDAPJS
|
|
// const client = ldap.createClient({
|
|
// url: [
|
|
// "ldap://ldap1.csclub.uwaterloo.ca",
|
|
// "ldap://ldap2.csclub.uwaterloo.ca",
|
|
// ],
|
|
// });
|
|
// client.bind("cn=root", "", (err) => {
|
|
// throw err;
|
|
// });
|
|
// const opts = {
|
|
// filter: `(&(objectClass=member)(term=${term}${year}))`,
|
|
// // scope: "sub",
|
|
// // attributes: ["dn", "sn", "cn"],
|
|
// };
|
|
// client.search("ou=People,dc=csclub,dc=uwaterloo,dc=ca", opts, (err, res) => {
|
|
// console.log("h3");
|
|
// res.on("searchEntry", (entry) => {
|
|
// console.log("entry: " + JSON.stringify(entry.object));
|
|
// });
|
|
// });
|
|
// client.unbind();
|
|
|
|
// LDAPTS
|
|
const url = "ldap://ldap1.csclub.uwaterloo.ca";
|
|
const searchDN = "ou=People,dc=csclub,dc=uwaterloo,dc=ca";
|
|
const client = new Client({
|
|
url,
|
|
});
|
|
try {
|
|
await client.bind("cn=root", "secret");
|
|
const { searchEntries, searchReferences } = await client.search(searchDN, {
|
|
scope: "sub",
|
|
filter: `(&(objectClass=member)(term=${term}${year}))`,
|
|
});
|
|
} catch (ex) {
|
|
throw ex;
|
|
} finally {
|
|
await client.unbind();
|
|
}
|
|
}
|
|
|
|
void getMembers("2020", "winter");
|