Skip to content

Commit

Permalink
fixing issue from disable secret
Browse files Browse the repository at this point in the history
  • Loading branch information
arn-ob committed Mar 19, 2021
1 parent a769a45 commit a617cda
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 17 deletions.
8 changes: 4 additions & 4 deletions routes/v1/ppp/ppp_interface_remove/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ const {
router.post('/interface_remove', (req, res) => {

let host_params = {
host: req.body.host_string.host,
user: req.body.host_string.user,
password: req.body.host_string.password,
port: req.body.host_string.port || 8728
host: req.body?.host_string?.host,
user: req.body?.host_string?.user,
password: req.body?.host_string?.password,
port: req.body?.host_string?.port || 8728
}
const name = req.body.name

Expand Down
28 changes: 23 additions & 5 deletions routes/v1/ppp/ppp_secret_disable/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,43 @@ const {
router.post('/secret_disable', (req, res) => {

let host_params = {
host: req.body.host_string.host,
user: req.body.host_string.user,
password: req.body.host_string.password,
port: req.body.host_string.port || 8728
host: req?.body?.host_string?.host,
user: req?.body?.host_string?.user,
password: req?.body?.host_string?.password,
port: req?.body?.host_string.port || 8728
}
const name = req.body.name

try {
const script = '/ppp/secret/disable';
const remove = `=numbers=${name}`;
const peramitter = [remove]

// Interface Removed
const script_interface = '/interface/pppoe-server/remove';
const remove_interface = `=numbers=<pppoe-${name}>`;
const peramitter_interface = [remove_interface]

with_params({
script,
peramitter,
host_params
}).then(retn => {
}).then(async retn => {
console.log("log: ppp secret disable")
retn = Array.isArray(retn) ? retn : [retn]

// Remove Interface
try {
await with_params({
script: script_interface,
peramitter: peramitter_interface,
host_params
})
console.log("log: ppp interface remove")
} catch (error) {
console.log("failed: Interface Not Removed")
}

res.json({
success: true,
message: "done",
Expand Down
16 changes: 8 additions & 8 deletions utils/mikrotik_cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const connection = require('../function/connection');
*/


const with_params = ({
const with_params = async ({
script,
peramitter = [],
host_params =
Expand Down Expand Up @@ -40,24 +40,24 @@ const with_params = ({
resolve(data)
}).catch((err) => {
conn.close();
console.log("with_params -> Server Error")
console.log("with_params -> Server Exec Error")
resolve([])
});
})
.catch(err => {
conn.close();
console.log("with_params -> Server Error")
console.log("with_params -> Server Connect Error")
resolve([])
})
} catch (e) {
console.log("with_params -> catch -> Server Error")
console.log("with_params -> catch -> Server Catch Error")
resolve([])
}
})
}


const without_params = ({
const without_params = async ({
script,
host_params =
{
Expand All @@ -84,16 +84,16 @@ const without_params = ({
resolver(get)
}).catch((err) => {
conn.close();
console.log("without_params -> Server Error")
console.log("without_params -> Server Exec Error")
resolver([])
});
}).catch(err => {
conn.close();
console.log("without_params -> Server Error")
console.log("without_params -> Server Connect Error")
resolver([])
})
} catch (e) {
console.log("without_params -> catch -> Server Error")
console.log("without_params -> catch -> Server Catch Error")
resolver([])
}
})
Expand Down

0 comments on commit a617cda

Please sign in to comment.