Goobus
This commit is contained in:
parent
2f00221f17
commit
84561d469d
69
index.js
69
index.js
|
|
@ -3,6 +3,56 @@ const { exec } = require('child_process');
|
|||
|
||||
require('dotenv').config();
|
||||
|
||||
const contexts = {
|
||||
"A1": {
|
||||
context: 'custom-emergency.9001.1',
|
||||
timeout: 30000,
|
||||
cid: 'Live Page'
|
||||
},
|
||||
"E1": {
|
||||
context: 'custom-emergency.9002.1',
|
||||
timeout: 30000,
|
||||
cid: 'Emergency Live Page'
|
||||
},
|
||||
"A2": {
|
||||
context: 'custom-emergency.9003.1',
|
||||
timeout: 30000,
|
||||
cid: 'Announcement 2',
|
||||
number: '2000' // Direct to page group, no phone needed
|
||||
},
|
||||
"E2": {
|
||||
context: 'custom-emergency.9004.1',
|
||||
timeout: 30000,
|
||||
cid: 'Emergency 2',
|
||||
number: '2000' // Direct to page group, no phone needed
|
||||
},
|
||||
"A3": {
|
||||
context: 'custom-emergency.9005.1',
|
||||
timeout: 30000,
|
||||
cid: 'Announcement 3',
|
||||
number: '2000' // Direct to page group, no phone needed
|
||||
},
|
||||
"E3": {
|
||||
context: 'custom-emergency.9006.1',
|
||||
timeout: 30000,
|
||||
cid: 'Emergency 3',
|
||||
number: '2000' // Direct to page group, no phone needed
|
||||
}
|
||||
}
|
||||
|
||||
function trigCall(pageType, phone) {
|
||||
// If contexts[pageType] does not exist, return an error
|
||||
if (!contexts[pageType]) {
|
||||
throw new Error(`Invalid page type: ${pageType}`);
|
||||
}
|
||||
const { context, timeout, cid, number } = contexts[pageType];
|
||||
const targetNumber = number || phone;
|
||||
if (!targetNumber) {
|
||||
throw new Error(`Phone number is required for page type: ${pageType}`);
|
||||
}
|
||||
return originateCall(targetNumber, context, 0, timeout, cid);
|
||||
}
|
||||
|
||||
function originateCall(number, context, delay, timeout, cid, variables = {}) {
|
||||
// Build the base command
|
||||
let command = `/usr/bin/ast_originate ${number} ${context} ${delay} ${timeout} ${Buffer.from(cid).toString('base64')}`;
|
||||
|
|
@ -52,25 +102,12 @@ function auth(req, res, next) {
|
|||
next();
|
||||
}
|
||||
|
||||
app.get('/', auth, (req, res) => {
|
||||
app.get('/', (req, res) => {
|
||||
res.render('index', { session: req.session });
|
||||
});
|
||||
|
||||
app.get('/login', (req, res) => {
|
||||
if (req.session && req.session.authenticated) {
|
||||
return res.redirect('/');
|
||||
}
|
||||
res.render('login');
|
||||
});
|
||||
|
||||
app.post('/login', (req, res) => {
|
||||
const { username, password } = req.body;
|
||||
if (username === process.env.USER && password === process.env.PASS) {
|
||||
req.session.authenticated = true;
|
||||
req.session.username = username;
|
||||
return res.redirect('/');
|
||||
}
|
||||
res.redirect('/login');
|
||||
app.post('/trig', async (req, res) => {
|
||||
console.log('Triggering call with data:', req.body);
|
||||
});
|
||||
|
||||
app.listen(PORT, HOST, () => {
|
||||
|
|
|
|||
|
|
@ -7,11 +7,66 @@
|
|||
<title>Funny goofy test page!!!!!1!</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Welcome to the Funny Goofy Test Page <%= session.username %>!</h1>
|
||||
<p>This is a simple web page to demonstrate EJS templating with Bootstrap styling.</p>
|
||||
|
||||
<div class="position-absolute top-0 start-0 m-3">
|
||||
<select class="form-select" id="phoneSelect">
|
||||
<option value="1001">Front Desk</option>
|
||||
<option value="1000">Office</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="container-fluid d-flex justify-content-center align-items-center min-vh-100">
|
||||
<div>
|
||||
<table class="table table-borderless table-sm">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="text-left"><h3>Normal Announcements</h3></th>
|
||||
<th class="text-left"><h3>Emergency Announcements</h3></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td class="text-left">
|
||||
<button class="btn btn-primary mb-1 w-100" name="A1" onclick="triggerAnnouncement(this)" style="height: 76px;">Live Page</button>
|
||||
</td>
|
||||
<td class="text-left">
|
||||
<button class="btn btn-danger mb-1 w-100" name="E1" onclick="triggerAnnouncement(this)" style="height: 76px;">Emergency Live Page</button>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="text-left">
|
||||
<button class="btn btn-success mb-1" name="A2" onclick="triggerAnnouncement(this)">Announcement 2</button>
|
||||
</td>
|
||||
<td class="text-left">
|
||||
<button class="btn btn-warning mb-1" name="E2" onclick="triggerAnnouncement(this)">Emergency 2</button>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="text-left">
|
||||
<button class="btn btn-info mb-1" name="A3" onclick="triggerAnnouncement(this)">Announcement 3</button>
|
||||
</td>
|
||||
<td class="text-left">
|
||||
<button class="btn btn-dark mb-1" name="E3" onclick="triggerAnnouncement(this)">Emergency 3</button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<script src="/assets/js/bootstrap.min.js"></script>
|
||||
<script src="/assets/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="/assets/js/jquery.min.js"></script>
|
||||
<script>
|
||||
function triggerAnnouncement(button) {
|
||||
const ann = button.getAttribute('name');
|
||||
const phoneSelect = document.getElementById('phoneSelect');
|
||||
const phone = phoneSelect.value;
|
||||
console.log(name)
|
||||
fetch('/trig', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({ pageType: ann, phone: phone })
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Reference in a new issue