Compare commits
No commits in common. "main" and "dev" have entirely different histories.
15
freepbx.js
15
freepbx.js
|
|
@ -221,28 +221,15 @@ class FreepbxManager {
|
|||
const startExt = process.env.START_EXT ? parseInt(process.env.START_EXT, 10) : 1000;
|
||||
// Remove duplicates by using a Set
|
||||
const existingExtsSet = new Set(exts.map(ext => parseInt(ext.user.extension, 10)));
|
||||
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)}`);
|
||||
}
|
||||
const existingExts = Array.from(existingExtsSet).sort((a, b) => a - b);
|
||||
|
||||
let nextExt = startExt;
|
||||
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 (process.env.DEBUG == 'true') console.log(`Found gap at ${nextExt}`)
|
||||
break;
|
||||
}
|
||||
if (process.env.DEBUG == 'true') console.log(`No gap, incrementing nextExt`)
|
||||
nextExt++;
|
||||
}
|
||||
if (process.env.DEBUG == 'true') console.log(`Next available extension is ${nextExt}`)
|
||||
return nextExt;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,13 +33,6 @@ module.exports.execute = async (interaction) => {
|
|||
emoji: "🔄",
|
||||
style: Discord.ButtonStyle.Danger,
|
||||
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}\`||`,
|
||||
color: 0x00ff00
|
||||
}],
|
||||
// components: [
|
||||
// {
|
||||
// type: 1,
|
||||
// components: [
|
||||
// {
|
||||
// type: Discord.ComponentType.Button,
|
||||
// label: "Reset Password",
|
||||
// emoji: "🔄",
|
||||
// style: Discord.ButtonStyle.Danger,
|
||||
// custom_id: "resetPassword"
|
||||
// }
|
||||
// ]
|
||||
// }
|
||||
// ],
|
||||
components: [
|
||||
{
|
||||
type: 1,
|
||||
components: [
|
||||
{
|
||||
type: Discord.ComponentType.Button,
|
||||
label: "Reset Password",
|
||||
emoji: "🔄",
|
||||
style: Discord.ButtonStyle.Danger,
|
||||
custom_id: "resetPassword"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
ephemeral: true
|
||||
})
|
||||
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;
|
||||
}
|
||||
const extData = await fpbx.getExtension(lookup.extension); // Verify extension exists
|
||||
|
||||
console.log(extData)
|
||||
await interaction.deferReply({ ephemeral: true });
|
||||
// console.log(JSON.stringify(interaction, null, 2));
|
||||
const newPassword = interaction.fields.getTextInputValue('newPassword');
|
||||
|
|
@ -26,7 +26,7 @@ module.exports.execute = async (interaction) => {
|
|||
try {
|
||||
const updated = await fpbx.updateExtPassword(lookup.extension, oldName, passwordToSet);
|
||||
//const updated = await fpbx.updateExtName(lookup.extension, passwordToSet);
|
||||
await fpbx.reload();
|
||||
console.log(updated)
|
||||
await interaction.editReply({ content: `Your extension password has been reset successfully! Your new password is: ||\`${passwordToSet}\`||`, ephemeral: true });
|
||||
} catch (error) {
|
||||
log.error(error);
|
||||
|
|
|
|||
|
|
@ -1,28 +0,0 @@
|
|||
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