Compare commits
12 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0afd3e460a | ||
|
|
730508a60a | ||
|
|
66be141aad | ||
|
|
bf6ed36211 | ||
|
|
9e4f8f6f73 | ||
|
|
f373da8428 | ||
|
|
7d9d26c14d | ||
|
|
7cb2bcad3a | ||
|
|
a02234305c | ||
|
|
c677392f6d | ||
|
|
de9817e576 | ||
|
|
1a19ca954d |
15
freepbx.js
15
freepbx.js
|
|
@ -221,15 +221,28 @@ class FreepbxManager {
|
||||||
const startExt = process.env.START_EXT ? parseInt(process.env.START_EXT, 10) : 1000;
|
const startExt = process.env.START_EXT ? parseInt(process.env.START_EXT, 10) : 1000;
|
||||||
// Remove duplicates by using a Set
|
// Remove duplicates by using a Set
|
||||||
const existingExtsSet = new Set(exts.map(ext => parseInt(ext.user.extension, 10)));
|
const existingExtsSet = new Set(exts.map(ext => parseInt(ext.user.extension, 10)));
|
||||||
const existingExts = Array.from(existingExtsSet).sort((a, b) => a - b);
|
var existingExts = Array.from(existingExtsSet).sort((a, b) => a - b);
|
||||||
|
|
||||||
|
// Filter out extensions that are less than the starting extension
|
||||||
|
existingExts = existingExts.filter(ext => ext >= startExt);
|
||||||
|
|
||||||
|
if (process.env.DEBUG == 'true') {
|
||||||
|
console.log(`Existing extensions: ${existingExts.join(', ')}`);
|
||||||
|
console.log(`Starting extension: ${startExt}`);
|
||||||
|
// console.log(`Next available extension: ${this.findNextAvailableExtension(existingExts, startExt)}`);
|
||||||
|
}
|
||||||
|
|
||||||
let nextExt = startExt;
|
let nextExt = startExt;
|
||||||
for (let i = 0; i < existingExts.length; i++) {
|
for (let i = 0; i < existingExts.length; i++) {
|
||||||
|
if (process.env.DEBUG == 'true') console.log(`Finding next, cur is ${nextExt}`)
|
||||||
if (existingExts[i] !== nextExt) {
|
if (existingExts[i] !== nextExt) {
|
||||||
|
if (process.env.DEBUG == 'true') console.log(`Found gap at ${nextExt}`)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (process.env.DEBUG == 'true') console.log(`No gap, incrementing nextExt`)
|
||||||
nextExt++;
|
nextExt++;
|
||||||
}
|
}
|
||||||
|
if (process.env.DEBUG == 'true') console.log(`Next available extension is ${nextExt}`)
|
||||||
return nextExt;
|
return nextExt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,13 @@ module.exports.execute = async (interaction) => {
|
||||||
emoji: "🔄",
|
emoji: "🔄",
|
||||||
style: Discord.ButtonStyle.Danger,
|
style: Discord.ButtonStyle.Danger,
|
||||||
custom_id: "resetPassword"
|
custom_id: "resetPassword"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: Discord.ComponentType.Button,
|
||||||
|
label: "LiteNet Dashboard",
|
||||||
|
emoji: "💻",
|
||||||
|
style: Discord.ButtonStyle.Link,
|
||||||
|
url: "https://litenet.tel/dashboard"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,20 +30,20 @@ module.exports.execute = async (interaction) => {
|
||||||
description: `**PBX Address:** \`${process.env.PBX_HOSTNAME}\`\n**Extension:** \`${extInfo.fetchExtension.user.extension}\`\n**Name:** \`${extInfo.fetchExtension.user.name}\`\n**Password:** ||\`${extInfo.fetchExtension.user.extPassword}\`||`,
|
description: `**PBX Address:** \`${process.env.PBX_HOSTNAME}\`\n**Extension:** \`${extInfo.fetchExtension.user.extension}\`\n**Name:** \`${extInfo.fetchExtension.user.name}\`\n**Password:** ||\`${extInfo.fetchExtension.user.extPassword}\`||`,
|
||||||
color: 0x00ff00
|
color: 0x00ff00
|
||||||
}],
|
}],
|
||||||
components: [
|
// components: [
|
||||||
{
|
// {
|
||||||
type: 1,
|
// type: 1,
|
||||||
components: [
|
// components: [
|
||||||
{
|
// {
|
||||||
type: Discord.ComponentType.Button,
|
// type: Discord.ComponentType.Button,
|
||||||
label: "Reset Password",
|
// label: "Reset Password",
|
||||||
emoji: "🔄",
|
// emoji: "🔄",
|
||||||
style: Discord.ButtonStyle.Danger,
|
// style: Discord.ButtonStyle.Danger,
|
||||||
custom_id: "resetPassword"
|
// custom_id: "resetPassword"
|
||||||
}
|
// }
|
||||||
]
|
// ]
|
||||||
}
|
// }
|
||||||
],
|
// ],
|
||||||
ephemeral: true
|
ephemeral: true
|
||||||
})
|
})
|
||||||
if (process.env.EXTENSION_ROLE_ID) await interaction.member.roles.add(process.env.EXTENSION_ROLE_ID);
|
if (process.env.EXTENSION_ROLE_ID) await interaction.member.roles.add(process.env.EXTENSION_ROLE_ID);
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ module.exports.execute = async (interaction) => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const extData = await fpbx.getExtension(lookup.extension); // Verify extension exists
|
const extData = await fpbx.getExtension(lookup.extension); // Verify extension exists
|
||||||
console.log(extData)
|
|
||||||
await interaction.deferReply({ ephemeral: true });
|
await interaction.deferReply({ ephemeral: true });
|
||||||
// console.log(JSON.stringify(interaction, null, 2));
|
// console.log(JSON.stringify(interaction, null, 2));
|
||||||
const newPassword = interaction.fields.getTextInputValue('newPassword');
|
const newPassword = interaction.fields.getTextInputValue('newPassword');
|
||||||
|
|
@ -26,7 +26,7 @@ module.exports.execute = async (interaction) => {
|
||||||
try {
|
try {
|
||||||
const updated = await fpbx.updateExtPassword(lookup.extension, oldName, passwordToSet);
|
const updated = await fpbx.updateExtPassword(lookup.extension, oldName, passwordToSet);
|
||||||
//const updated = await fpbx.updateExtName(lookup.extension, passwordToSet);
|
//const updated = await fpbx.updateExtName(lookup.extension, passwordToSet);
|
||||||
console.log(updated)
|
await fpbx.reload();
|
||||||
await interaction.editReply({ content: `Your extension password has been reset successfully! Your new password is: ||\`${passwordToSet}\`||`, ephemeral: true });
|
await interaction.editReply({ content: `Your extension password has been reset successfully! Your new password is: ||\`${passwordToSet}\`||`, ephemeral: true });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log.error(error);
|
log.error(error);
|
||||||
|
|
|
||||||
28
moduletest.js
Normal file
28
moduletest.js
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
require("dotenv").config();
|
||||||
|
const cron = require("node-cron")
|
||||||
|
const fs = require('fs');
|
||||||
|
const mariadb = require("mariadb");
|
||||||
|
const pool = mariadb.createPool({
|
||||||
|
host: process.env.DB_HOST,
|
||||||
|
port: process.env.DB_PORT || 3306,
|
||||||
|
user: process.env.DB_USER,
|
||||||
|
password: process.env.DB_PASS,
|
||||||
|
database: "asterisk",
|
||||||
|
connectionLimit: 5,
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(process.env)
|
||||||
|
|
||||||
|
const FreepbxManager = require("./freepbx");
|
||||||
|
const fpbx = new FreepbxManager({
|
||||||
|
url: process.env.FREEPBX_URL,
|
||||||
|
clientId: process.env.FREEPBX_CLIENT_ID,
|
||||||
|
clientSecret: process.env.FREEPBX_CLIENT_SECRET,
|
||||||
|
dbPool: pool,
|
||||||
|
});
|
||||||
|
|
||||||
|
fpbx.getNextAvailableExtension().then((ext) => {
|
||||||
|
console.log(`Next available extension: ${ext}`);
|
||||||
|
}).catch((err) => {
|
||||||
|
console.error(`Error getting next available extension: ${err}`);
|
||||||
|
});
|
||||||
Loading…
Reference in a new issue