Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var fs = require('fs');
  2. var http = require('http');
  3. var https = require('https');
  4. var express = require('express');
  5. var app = express();
  6. var bodyParser = require('body-parser');
  7. const hex2ascii = require('hex2ascii');
  8. const { exec } = require('child_process');
  9.  
  10. var urlencodedParser = bodyParser.urlencoded({ extended: true });
  11.  
  12.    https.createServer({
  13.      key: fs.readFileSync('encryption/key.pem'),
  14.      cert: fs.readFileSync('encryption/cert.pem')
  15.    }, app).listen(8083, function () {
  16.      var port1 = server.address().port;
  17.     require('dns').lookup(require('os').hostname(), function (err, add, fam) {
  18.       console.log('HTTPS running on http://%s:8083', add);
  19.   })
  20.    });
  21.  
  22.    var server = app.listen(8082, function () {
  23.    var port = server.address().port;
  24.   require('dns').lookup(require('os').hostname(), function (err, add, fam) {
  25.   console.log('HTTP running on http://%s:8082', add);
  26.   })
  27.    });
  28.  
  29. app.get('/', function (req, res) {
  30.   var html='';
  31.   html +="<!DOCTYPE html>";
  32.   html +="  <html>";
  33.   html +="    <head>";
  34.   html +="      <link rel='stylesheet' type='text/css' href='./public/style.css'>";
  35.   html +="    </head>";
  36.   html +="        <body>";
  37.   html += "<form action='/thank'  method='post' name='form1'>";
  38.   html += "<center>Transaction ID:<br>";
  39.   html += "<input type= 'text' name='txid' style='background-color: #3CBC8D; color: white; size: 150px;'> <br>";
  40.   html += "<input type='submit' value='submit' style='background-color: #3CBC8D; color: white;'></center>";
  41.   html += "</form>";
  42.   html += "</body>";
  43.   res.send(html);
  44. });
  45.  
  46. app.get('/:id', function(req, res) {
  47.   exec(`pandacoind gettransaction ${req.params.id.replace(';', 'X')}`, (err, stdout, stderr) => {
  48.     if (err) {
  49.       return;
  50.     }
  51.     var reply='';
  52.     var obj = JSON.parse(stdout);
  53.     reply +="<!DOCTYPE html>";
  54.     reply +="  <html>";
  55.     reply +="    <head>";
  56.     reply +="      <link rel='stylesheet' type='text/css' href='./public/style.css'>";
  57.     reply +="    </head>"
  58.     reply +="        <body>";
  59.     reply += "<b>Transaction Information</b> <br>" + stdout;
  60.     reply += "<br><br><br><b>Message on Blockchain</b><br>";
  61.   if (obj.vout.length > 1) {
  62.     reply += hex2ascii(JSON.stringify(obj.vout[1].scriptPubKey.asm));
  63.   }
  64.   else {
  65.     reply += "No Message on the Blockchain"
  66.   }
  67.     res.send(reply);
  68. }) });
  69.  
  70. app.post('/thank', urlencodedParser, function (req, res){
  71.   exec(`pandacoind gettransaction ${req.body.txid.replace(';', 'X')}`, (err, stdout, stderr) => {
  72.  
  73.     if (err) {
  74.       return;
  75.     }
  76.     var reply='';
  77.     var obj = JSON.parse(stdout);
  78.     reply +="<!DOCTYPE html>";
  79.     reply +="  <html>";
  80.     reply +="    <head>";
  81.     reply +="      <link rel='stylesheet' type='text/css' href='./public/style.css'>";
  82.     reply +="    </head>"
  83.     reply +="        <body>";
  84.     reply += "<b>Transaction Information</b> <br>" + stdout;
  85.     reply += "<br><br><br><b>Message on Blockchain</b><br>";
  86.     if (obj.vout.length > 1) {
  87.       reply += hex2ascii(JSON.stringify(obj.vout[1].scriptPubKey.asm));
  88.     }
  89.     else {
  90.       reply += "No Message on the Blockchain"
  91.     }
  92.     res.send(reply);
  93.  
  94. }) });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement