Guest User

Untitled

a guest
Oct 19th, 2017
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.89 KB | None | 0 0
  1. parser.parseString(soapreplyx, function (err, result) {
  2. ^
  3. ReferenceError: parser is not defined
  4.  
  5. // APP - INCLUDE
  6. const express = require('express')
  7. const path = require("path")
  8. const bodyParser = require("body-parser")
  9. const hbs = require('hbs')
  10. var xml2js = require('xml2js');
  11. var parser = new xml2js.Parser();
  12.  
  13. // APP - DEFINITION
  14. const app = express()
  15.  
  16. // APP - BUILD
  17. app.use(express.static(path.join(__dirname, 'public')));
  18. app.use(bodyParser.json());
  19. app.use(bodyParser.urlencoded({extended: true}));
  20. app.engine('html', require('hbs').__express);
  21. app.set('view engine', 'html');
  22.  
  23. // EXPRESS ROUTE - INDEX
  24. app.get('/', function (req, res) {
  25. res.render(path.join(__dirname+ '/views/index.html'), {
  26. 'title': 'CUCM 2.0'
  27. });
  28. })
  29.  
  30. // EXPRESS ROUTING - INCLUDE - CUCM MAPPER
  31. var routingextensions = require(__dirname+ '/routes/cucmmapper.js')(app);
  32.  
  33. // APP - START
  34. app.listen(3000, function () {
  35. console.log('CUCM 2.0 listening on port 3000!')
  36. })
  37.  
  38. module.exports = function (app) {
  39. // FORM - SUBMIT - CUCMMAPPER
  40. app.post('/cucmmapper/submit', function (req, res) {
  41.  
  42. // FORM - DATA COLLECTION
  43. var cucmpub = req.body.cucmpub;
  44. var cucmversion = req.body.cucmversion;
  45. var username = req.body.username;
  46. var password = req.body.password;
  47.  
  48. // JS - VARIABLE DEFINITION
  49. var authentication = username + ":" + password;
  50. var soapreplyx = '';
  51. var cssx = '';
  52. //var parser = new xml2js.parser();
  53.  
  54. // HTTP.REQUEST - BUILD CALL
  55. var https = require("https");
  56. var headers = {
  57. 'SoapAction': 'CUCM:DB ver=' + cucmversion + ' listCss',
  58. 'Authorization': 'Basic ' + new Buffer(authentication).toString('base64'),
  59. 'Content-Type': 'text/xml; charset=utf-8'
  60. };
  61.  
  62. // SOAP - AXL CALL
  63. var soapBody = new Buffer('<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://www.cisco.com/AXL/API/11.5">' +
  64. '<soapenv:Header/>' +
  65. '<soapenv:Body>' +
  66. '<ns:listCss sequence="?">' +
  67. '<searchCriteria>' +
  68. '<name>%</name>' +
  69. '</searchCriteria>' +
  70. '<returnedTags uuid="?">' +
  71. '<name>?</name>' +
  72. '<description>?</description>' +
  73. '<clause>?</clause>' +
  74. '</returnedTags>' +
  75. '</ns:listCss>' +
  76. '</soapenv:Body>' +
  77. '</soapenv:Envelope>');
  78.  
  79. // HTTP.REQUEST - OPTIONS
  80. var options = {
  81. host: cucmpub, // IP ADDRESS OF CUCM PUBLISHER
  82. port: 8443, // DEFAULT CISCO SSL PORT
  83. path: '/axl/', // AXL URL
  84. method: 'POST', // AXL REQUIREMENT OF POST
  85. headers: headers, // HEADER VAR
  86. rejectUnauthorized: false // REQUIRED TO ACCEPT SELF-SIGNED CERTS
  87. };
  88.  
  89. // HTTP.REQUEST - Doesn't seem to need this line, but it might be useful anyway for pooling?
  90. options.agent = new https.Agent(options);
  91.  
  92. // HTTP.REQUEST - OPEN SESSION
  93. let soapRequest = https.request(options, soapResponse => {
  94. soapResponse.setEncoding('utf8');
  95. soapResponse.on('data', chunk => {
  96. soapreplyx += chunk
  97. });
  98. // HTTP.REQUEST - RESULTS + RENDER
  99. soapResponse.on('end', () => {
  100. parser.parseString(soapreplyx, function (err, result) {
  101. var cssx = result['return']['css'];
  102. res.render('cucmmapper-results.html', {
  103. title: 'CUCM 2.1',
  104. soapreply: soapreplyx,
  105. css: cssx,
  106. })
  107. });
  108. });
  109. });
  110.  
  111. // SOAP - SEND AXL CALL
  112. soapRequest.write(soapBody);
  113. soapRequest.end();
  114. });
  115. }
  116.  
  117. <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
  118. <soapenv:Body>
  119. <ns:listCssResponse xmlns:ns="http://www.cisco.com/AXL/API/11.0">
  120. <return>
  121. <css uuid="{E85C54E1-5737-7516-FFFC-14E97B1D0504}">
  122. <description>description</description>
  123. <clause>blablabla</clause>
  124. <name>name</name>
  125. </css>
  126. <css uuid="{AFFC55A7-CD16-E250-09E8-9A12ABBE0C9E}">
  127. <description>description</description>
  128. <clause>blablabla</clause>
  129. <name>name</name>
  130. </css>
Add Comment
Please, Sign In to add comment