SHARE
TWEET

Untitled

a guest Mar 23rd, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var http = require('http');
  2. var XelkReq = require('/homes/paul/HTML/CS316/P3_Req.js');
  3.  
  4.  
  5. function serveFile() {
  6.  
  7. }
  8.  
  9. function serveCGI() {
  10.  
  11. }
  12.  
  13. function pullandsendFile() {
  14.  
  15. }
  16.  
  17. function pullandsendOutput() {
  18.  
  19. }
  20.  
  21. function getURL(req, res) {
  22.     console.log("inside geturl");
  23.     console.log(req.url);
  24.     var localF = "LOCALFILE";
  25.     var remoteF = "REMOTEFILE";
  26.     var localE = "LOCALEXEC";
  27.     var remoteE = "REMOTEEXEC";
  28.     var validExtArray = XelkReq.extAllowed();
  29.     var validExtensions;
  30.     for (var i = 0; i < validExtArray; i++){
  31.         validExtensions = validExtensions + "\." + validExtArray[i][0];
  32.         if (i < validExtArray.length - 1){
  33.             validExtensions = validExtensions + "|";
  34.         }
  35.     }
  36.     var urlRegEx = new RegExp("^\/[a-zA-Z0-9\.]+$");
  37.     var regExLocalF = new RegExp("\\/" + localF + "\\/[a-zA-Z0-9~\\/]+" + validExtensions);
  38.     var regExRemoteF = new RegExp("\\/" + remoteF + urlRegEx + "\\/[a-zA-Z0-9~\\/]" + validExtensions);
  39.     var regExLocalE = new RegExp("\\/" + localE + "[a-zA-Z0-9\\/]+\.cgi");
  40.     var regExRemoteE = new RegExp("\\/" + remoteE + urlRegEx + "[a-zA-Z0-9\\/]+\.cgi");
  41.     var finalRegEx = new RegExp(regExLocalF + "|" + regExRemoteF + "|" + regExLocalE + "|" + regExRemoteE);
  42.  
  43.  
  44.  
  45.     // default response
  46.     var response = "not good\n";
  47.     // response if request valid
  48.     if(urlRegEx.test(req.url)){
  49.         console.log("smd");
  50.         response = "this is good\n";
  51.     }
  52.     //actual response
  53.     res.writeHead(200, {"Context-Type": "text/plain"});
  54.     res.write(response);
  55.     res.end();
  56. }
  57.  
  58.  
  59.  
  60. console.log("hello");
  61.  
  62. const server = http.createServer(getURL).listen(8080);
  63. console.log("hellopart2");
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top