m0603va 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. package/Laba6/file1.js +23 -0
  2. package/Laba6/file2.js +23 -0
  3. package/Laba6/index.html +63 -0
  4. package/Laba6/m0603.js +29 -0
  5. package/Laba6/node_modules/.package-lock.json +83 -0
  6. package/Laba6/node_modules/httpntlm/.jshintrc +4 -0
  7. package/Laba6/node_modules/httpntlm/LICENSE +20 -0
  8. package/Laba6/node_modules/httpntlm/README.md +148 -0
  9. package/Laba6/node_modules/httpntlm/httpntlm.js +104 -0
  10. package/Laba6/node_modules/httpntlm/ntlm.js +390 -0
  11. package/Laba6/node_modules/httpntlm/package.json +33 -0
  12. package/Laba6/node_modules/httpreq/LICENSE +19 -0
  13. package/Laba6/node_modules/httpreq/README.md +383 -0
  14. package/Laba6/node_modules/httpreq/contributors.md +26 -0
  15. package/Laba6/node_modules/httpreq/lib/httpreq.js +681 -0
  16. package/Laba6/node_modules/httpreq/package.json +102 -0
  17. package/Laba6/node_modules/m0603sol/m0603.js +29 -0
  18. package/Laba6/node_modules/m0603sol/package.json +12 -0
  19. package/Laba6/node_modules/nodemailer/.gitattributes +6 -0
  20. package/Laba6/node_modules/nodemailer/.prettierrc.js +8 -0
  21. package/Laba6/node_modules/nodemailer/CHANGELOG.md +725 -0
  22. package/Laba6/node_modules/nodemailer/CODE_OF_CONDUCT.md +76 -0
  23. package/Laba6/node_modules/nodemailer/CONTRIBUTING.md +67 -0
  24. package/Laba6/node_modules/nodemailer/LICENSE +16 -0
  25. package/Laba6/node_modules/nodemailer/README.md +97 -0
  26. package/Laba6/node_modules/nodemailer/SECURITY.txt +22 -0
  27. package/Laba6/node_modules/nodemailer/lib/addressparser/index.js +313 -0
  28. package/Laba6/node_modules/nodemailer/lib/base64/index.js +142 -0
  29. package/Laba6/node_modules/nodemailer/lib/dkim/index.js +251 -0
  30. package/Laba6/node_modules/nodemailer/lib/dkim/message-parser.js +155 -0
  31. package/Laba6/node_modules/nodemailer/lib/dkim/relaxed-body.js +154 -0
  32. package/Laba6/node_modules/nodemailer/lib/dkim/sign.js +117 -0
  33. package/Laba6/node_modules/nodemailer/lib/fetch/cookies.js +281 -0
  34. package/Laba6/node_modules/nodemailer/lib/fetch/index.js +274 -0
  35. package/Laba6/node_modules/nodemailer/lib/json-transport/index.js +82 -0
  36. package/Laba6/node_modules/nodemailer/lib/mail-composer/index.js +558 -0
  37. package/Laba6/node_modules/nodemailer/lib/mailer/index.js +427 -0
  38. package/Laba6/node_modules/nodemailer/lib/mailer/mail-message.js +315 -0
  39. package/Laba6/node_modules/nodemailer/lib/mime-funcs/index.js +625 -0
  40. package/Laba6/node_modules/nodemailer/lib/mime-funcs/mime-types.js +2102 -0
  41. package/Laba6/node_modules/nodemailer/lib/mime-node/index.js +1290 -0
  42. package/Laba6/node_modules/nodemailer/lib/mime-node/last-newline.js +33 -0
  43. package/Laba6/node_modules/nodemailer/lib/mime-node/le-unix.js +43 -0
  44. package/Laba6/node_modules/nodemailer/lib/mime-node/le-windows.js +52 -0
  45. package/Laba6/node_modules/nodemailer/lib/nodemailer.js +143 -0
  46. package/Laba6/node_modules/nodemailer/lib/qp/index.js +219 -0
  47. package/Laba6/node_modules/nodemailer/lib/sendmail-transport/index.js +210 -0
  48. package/Laba6/node_modules/nodemailer/lib/ses-transport/index.js +349 -0
  49. package/Laba6/node_modules/nodemailer/lib/shared/index.js +638 -0
  50. package/Laba6/node_modules/nodemailer/lib/smtp-connection/data-stream.js +108 -0
  51. package/Laba6/node_modules/nodemailer/lib/smtp-connection/http-proxy-client.js +143 -0
  52. package/Laba6/node_modules/nodemailer/lib/smtp-connection/index.js +1796 -0
  53. package/Laba6/node_modules/nodemailer/lib/smtp-pool/index.js +648 -0
  54. package/Laba6/node_modules/nodemailer/lib/smtp-pool/pool-resource.js +253 -0
  55. package/Laba6/node_modules/nodemailer/lib/smtp-transport/index.js +416 -0
  56. package/Laba6/node_modules/nodemailer/lib/stream-transport/index.js +135 -0
  57. package/Laba6/node_modules/nodemailer/lib/well-known/index.js +47 -0
  58. package/Laba6/node_modules/nodemailer/lib/well-known/services.json +286 -0
  59. package/Laba6/node_modules/nodemailer/lib/xoauth2/index.js +376 -0
  60. package/Laba6/node_modules/nodemailer/package.json +46 -0
  61. package/Laba6/node_modules/nodemailer/postinstall.js +101 -0
  62. package/Laba6/node_modules/nodemailer-fetch/.eslintrc.js +56 -0
  63. package/Laba6/node_modules/nodemailer-fetch/.travis.yml +19 -0
  64. package/Laba6/node_modules/nodemailer-fetch/CHANGELOG.md +30 -0
  65. package/Laba6/node_modules/nodemailer-fetch/Gruntfile.js +27 -0
  66. package/Laba6/node_modules/nodemailer-fetch/LICENSE +16 -0
  67. package/Laba6/node_modules/nodemailer-fetch/README.md +55 -0
  68. package/Laba6/node_modules/nodemailer-fetch/lib/cookies.js +275 -0
  69. package/Laba6/node_modules/nodemailer-fetch/lib/fetch.js +224 -0
  70. package/Laba6/node_modules/nodemailer-fetch/package.json +30 -0
  71. package/Laba6/node_modules/nodemailer-fetch/test/cookies-test.js +391 -0
  72. package/Laba6/node_modules/nodemailer-fetch/test/fetch-test.js +486 -0
  73. package/Laba6/node_modules/nodemailer-shared/.eslintrc.js +59 -0
  74. package/Laba6/node_modules/nodemailer-shared/.travis.yml +18 -0
  75. package/Laba6/node_modules/nodemailer-shared/Gruntfile.js +27 -0
  76. package/Laba6/node_modules/nodemailer-shared/LICENSE +16 -0
  77. package/Laba6/node_modules/nodemailer-shared/README.md +14 -0
  78. package/Laba6/node_modules/nodemailer-shared/lib/shared.js +282 -0
  79. package/Laba6/node_modules/nodemailer-shared/package.json +36 -0
  80. package/Laba6/node_modules/nodemailer-shared/test/fixtures/message.html +1 -0
  81. package/Laba6/node_modules/nodemailer-shared/test/shared-test.js +291 -0
  82. package/Laba6/node_modules/nodemailer-smtp-transport/.eslintrc.js +59 -0
  83. package/Laba6/node_modules/nodemailer-smtp-transport/Gruntfile.js +27 -0
  84. package/Laba6/node_modules/nodemailer-smtp-transport/LICENSE +19 -0
  85. package/Laba6/node_modules/nodemailer-smtp-transport/README.md +7 -0
  86. package/Laba6/node_modules/nodemailer-smtp-transport/lib/smtp-transport.js +281 -0
  87. package/Laba6/node_modules/nodemailer-smtp-transport/package.json +37 -0
  88. package/Laba6/node_modules/nodemailer-wellknown/.travis.yml +17 -0
  89. package/Laba6/node_modules/nodemailer-wellknown/LICENSE +19 -0
  90. package/Laba6/node_modules/nodemailer-wellknown/README.md +80 -0
  91. package/Laba6/node_modules/nodemailer-wellknown/index.js +47 -0
  92. package/Laba6/node_modules/nodemailer-wellknown/package.json +26 -0
  93. package/Laba6/node_modules/nodemailer-wellknown/services.json +255 -0
  94. package/Laba6/node_modules/nodemailer-wellknown/test.js +23 -0
  95. package/Laba6/node_modules/smtp-connection/.eslintrc.js +56 -0
  96. package/Laba6/node_modules/smtp-connection/CHANGELOG.md +164 -0
  97. package/Laba6/node_modules/smtp-connection/Gruntfile.js +27 -0
  98. package/Laba6/node_modules/smtp-connection/LICENSE +19 -0
  99. package/Laba6/node_modules/smtp-connection/README.md +200 -0
  100. package/Laba6/node_modules/smtp-connection/lib/data-stream.js +111 -0
  101. package/Laba6/node_modules/smtp-connection/lib/smtp-connection.js +1443 -0
  102. package/Laba6/node_modules/smtp-connection/package.json +41 -0
  103. package/Laba6/node_modules/underscore/LICENSE +23 -0
  104. package/Laba6/node_modules/underscore/README.md +22 -0
  105. package/Laba6/node_modules/underscore/package.json +41 -0
  106. package/Laba6/node_modules/underscore/underscore-min.js +6 -0
  107. package/Laba6/node_modules/underscore/underscore.js +1415 -0
  108. package/Laba6/package-lock.json +94 -0
  109. package/Laba6/package.json +17 -0
  110. package/Laba6.txt +31 -0
  111. package/file1.js +23 -0
  112. package/file2.js +23 -0
  113. package/index.html +63 -0
  114. package/m0603.js +29 -0
  115. package/m0603Sol/m0603.js +29 -0
  116. package/m0603Sol/package.json +12 -0
  117. package/package.json +17 -0
package/Laba6/file1.js ADDED
@@ -0,0 +1,23 @@
1
+ var http = require("http");
2
+ var url = require("url");
3
+ const fs = require("fs");
4
+ let send=require("./m0603");
5
+ const { request } = require("https");
6
+
7
+
8
+
9
+ http.createServer(function (request, response) {
10
+ console.log(`Запрошенный адрес: ${request.url}`);
11
+ var path=url.parse(request.url).pathname
12
+ if ( path === '/send') {
13
+ request.on('data',data =>{
14
+ let r=JSON.parse(data);
15
+ send(r.sender,r.receiver,r.message); })
16
+ }
17
+ if ( path === '/') {
18
+ let page = fs.readFileSync('./index.html');
19
+ response.writeHead(200, {'Content-Type' : 'text/html; charset=utf-8'});
20
+ response.end(page);
21
+ }
22
+ }).listen(5000);
23
+ console.log("Server running at http://localhost:5000/ (http://localhost:5000/send)");
package/Laba6/file2.js ADDED
@@ -0,0 +1,23 @@
1
+ var http = require("http");
2
+ var url = require("url");
3
+ const fs = require("fs");
4
+ let send=require("m0603sol");
5
+ const { request } = require("https");
6
+
7
+
8
+
9
+ http.createServer(function (request, response) {
10
+ console.log(`Запрошенный адрес: ${request.url}`);
11
+ var path=url.parse(request.url).pathname
12
+ if ( path === '/send') {
13
+ request.on('data',data =>{
14
+ let r=JSON.parse(data);
15
+ send(r.sender,r.receiver,r.message); })
16
+ }
17
+ if ( path === '/') {
18
+ let page = fs.readFileSync('./index.html');
19
+ response.writeHead(200, {'Content-Type' : 'text/html; charset=utf-8'});
20
+ response.end(page);
21
+ }
22
+ }).listen(5000);
23
+ console.log("Server running at http://localhost:5000/ (http://localhost:5000/send)");
@@ -0,0 +1,63 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
+ <title>Document</title>
8
+ <style type="text/css">
9
+ h2
10
+ {
11
+ color: rgb(142, 113, 34);
12
+ font-weight: bolder;
13
+
14
+ }
15
+
16
+ </style>
17
+ </head>
18
+ <body>
19
+ <main>
20
+ <h2>Форма для сообщения</h2>
21
+ <form>
22
+ <label for="sender">Отправитель: </label>
23
+ <input type="text" id="sender"><br><br>
24
+ <label for="receiver">Получатель: </label>
25
+ <input type="text" id="receiver"><br><br>
26
+ <label for="message">Сообщение: </label>
27
+ <textarea type="text" id="message"></textarea><br><br>
28
+ <button onclick="Post()">Отправить</button>
29
+ </form>
30
+ </main>
31
+ </body>
32
+ <script>
33
+
34
+
35
+
36
+
37
+
38
+ function Post() {
39
+ let Sender = document.getElementById("sender");
40
+ let Receiver = document.getElementById("receiver");
41
+ let Message = document.getElementById("message")
42
+ if (Receiver.value && Message.value && Sender.value) {
43
+ fetch(`http://localhost:5000/send`, {
44
+ method: 'POST',
45
+ headers: {'Content-Type': 'application/json'},
46
+ body: JSON.stringify(
47
+ {
48
+ sender: Sender.value,
49
+ receiver: Receiver.value,
50
+ message: Message.value
51
+ }
52
+ )})
53
+ .then(response => { return response.json(); })
54
+ .then(pdata => {
55
+ console.log('POST ', pdata);
56
+ });
57
+ }
58
+ else {
59
+ alert('Ошибка в данных!')
60
+ }
61
+ }
62
+ </script>
63
+ </html>
package/Laba6/m0603.js ADDED
@@ -0,0 +1,29 @@
1
+ const nodemailer=require('nodemailer');
2
+ const smtpTransport=require('nodemailer-smtp-transport');
3
+
4
+ function send(sender,receiver,message)
5
+ {
6
+ let transporter=nodemailer.createTransport(smtpTransport({
7
+ host:'smtp.gmail.com',
8
+ port: 587,
9
+ secure: false,
10
+ auth:{
11
+ user:sender,
12
+ pass:'ociqxonvpbwgnxbb'
13
+ }
14
+ }));
15
+
16
+ var mailOptions={
17
+ from: sender,
18
+ to: receiver,
19
+ subject:'Lab6',
20
+ text:message,
21
+ html:`<i>${message}</i>`
22
+ };
23
+
24
+ transporter.sendMail(mailOptions,function(error,info){
25
+ error ? console.log(error):console.log(`Email.sent:Sender-${sender} Receiver-${receiver} Message-${message}`);
26
+ })
27
+ };
28
+
29
+ module.exports=send
@@ -0,0 +1,83 @@
1
+ {
2
+ "name": "laba6",
3
+ "version": "1.0.0",
4
+ "lockfileVersion": 3,
5
+ "requires": true,
6
+ "packages": {
7
+ "node_modules/httpntlm": {
8
+ "version": "1.6.1",
9
+ "resolved": "https://registry.npmjs.org/httpntlm/-/httpntlm-1.6.1.tgz",
10
+ "integrity": "sha512-Tcz3Ct9efvNqw3QdTl3h6IgRRlIQxwKkJELN/aAIGnzi2xvb3pDHdnMs8BrxWLV6OoT4DlVyhzSVhFt/tk0lIw==",
11
+ "dependencies": {
12
+ "httpreq": ">=0.4.22",
13
+ "underscore": "~1.7.0"
14
+ },
15
+ "engines": {
16
+ "node": ">=0.8.0"
17
+ }
18
+ },
19
+ "node_modules/httpreq": {
20
+ "version": "0.5.2",
21
+ "resolved": "https://registry.npmjs.org/httpreq/-/httpreq-0.5.2.tgz",
22
+ "integrity": "sha512-2Jm+x9WkExDOeFRrdBCBSpLPT5SokTcRHkunV3pjKmX/cx6av8zQ0WtHUMDrYb6O4hBFzNU6sxJEypvRUVYKnw==",
23
+ "engines": {
24
+ "node": ">= 6.15.1"
25
+ }
26
+ },
27
+ "node_modules/m0603sol": {
28
+ "version": "1.0.0",
29
+ "resolved": "https://registry.npmjs.org/m0603sol/-/m0603sol-1.0.0.tgz",
30
+ "integrity": "sha512-J+UomYZ0QptXSaNOyQC0xrvY7asWLWhe4fT/lQqAhKL6xRlQ529dcl5Tl2AvoZWg4HO97sGtnSQ90NjzHq8pWQ=="
31
+ },
32
+ "node_modules/nodemailer": {
33
+ "version": "6.9.1",
34
+ "resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.9.1.tgz",
35
+ "integrity": "sha512-qHw7dOiU5UKNnQpXktdgQ1d3OFgRAekuvbJLcdG5dnEo/GtcTHRYM7+UfJARdOFU9WUQO8OiIamgWPmiSFHYAA==",
36
+ "engines": {
37
+ "node": ">=6.0.0"
38
+ }
39
+ },
40
+ "node_modules/nodemailer-fetch": {
41
+ "version": "1.6.0",
42
+ "resolved": "https://registry.npmjs.org/nodemailer-fetch/-/nodemailer-fetch-1.6.0.tgz",
43
+ "integrity": "sha512-P7S5CEVGAmDrrpn351aXOLYs1R/7fD5NamfMCHyi6WIkbjS2eeZUB/TkuvpOQr0bvRZicVqo59+8wbhR3yrJbQ=="
44
+ },
45
+ "node_modules/nodemailer-shared": {
46
+ "version": "1.1.0",
47
+ "resolved": "https://registry.npmjs.org/nodemailer-shared/-/nodemailer-shared-1.1.0.tgz",
48
+ "integrity": "sha512-68xW5LSyPWv8R0GLm6veAvm7E+XFXkVgvE3FW0FGxNMMZqMkPFeGDVALfR1DPdSfcoO36PnW7q5AAOgFImEZGg==",
49
+ "dependencies": {
50
+ "nodemailer-fetch": "1.6.0"
51
+ }
52
+ },
53
+ "node_modules/nodemailer-smtp-transport": {
54
+ "version": "2.7.4",
55
+ "resolved": "https://registry.npmjs.org/nodemailer-smtp-transport/-/nodemailer-smtp-transport-2.7.4.tgz",
56
+ "integrity": "sha512-1e86YhJ633OZWk3OHWS5TpuoYXG/LtY2/RzNiB5+EkFifDdqHCNHBnExd5cobx0ZSHJLNGM8EKnDuHRFIjFi6Q==",
57
+ "dependencies": {
58
+ "nodemailer-shared": "1.1.0",
59
+ "nodemailer-wellknown": "0.1.10",
60
+ "smtp-connection": "2.12.0"
61
+ }
62
+ },
63
+ "node_modules/nodemailer-wellknown": {
64
+ "version": "0.1.10",
65
+ "resolved": "https://registry.npmjs.org/nodemailer-wellknown/-/nodemailer-wellknown-0.1.10.tgz",
66
+ "integrity": "sha512-/VV4mjAEjfm2fn0loUvrpjvugw5rgurNjPO4WU24CuVSoeumsyLOTgaEWG8WoGdPxh1biOAp5JxDoy1hlA2zsw=="
67
+ },
68
+ "node_modules/smtp-connection": {
69
+ "version": "2.12.0",
70
+ "resolved": "https://registry.npmjs.org/smtp-connection/-/smtp-connection-2.12.0.tgz",
71
+ "integrity": "sha512-UP5jK4s5SGcUcqPN4U9ingqKt9mXYSKa52YhqxPuMecAnUOsVJpOmtgGaOm1urUBJZlzDt1M9WhZZkgbhxQlvg==",
72
+ "dependencies": {
73
+ "httpntlm": "1.6.1",
74
+ "nodemailer-shared": "1.1.0"
75
+ }
76
+ },
77
+ "node_modules/underscore": {
78
+ "version": "1.7.0",
79
+ "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.7.0.tgz",
80
+ "integrity": "sha512-cp0oQQyZhUM1kpJDLdGO1jPZHgS/MpzoWYfe9+CM2h/QGDZlqwT2T3YGukuBdaNJ/CAPoeyAZRRHz8JFo176vA=="
81
+ }
82
+ }
83
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "node": true,
3
+ "laxbreak": true
4
+ }
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013 Sam
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,148 @@
1
+ # httpntlm
2
+
3
+ __httpntlm__ is a Node.js library to do HTTP NTLM authentication
4
+
5
+ It's a port from the Python libary [python-ntml](https://code.google.com/p/python-ntlm/)
6
+
7
+ ## Install
8
+
9
+ You can install __httpntlm__ using the Node Package Manager (npm):
10
+
11
+ npm install httpntlm
12
+
13
+ ## How to use
14
+
15
+ ```js
16
+ var httpntlm = require('httpntlm');
17
+
18
+ httpntlm.get({
19
+ url: "https://someurl.com",
20
+ username: 'm$',
21
+ password: 'stinks',
22
+ workstation: 'choose.something',
23
+ domain: ''
24
+ }, function (err, res){
25
+ if(err) return err;
26
+
27
+ console.log(res.headers);
28
+ console.log(res.body);
29
+ });
30
+ ```
31
+
32
+ It supports __http__ and __https__.
33
+
34
+ ## Options
35
+
36
+ - `url:` _{String}_ URL to connect. (Required)
37
+ - `username:` _{String}_ Username. (Required)
38
+ - `password:` _{String}_ Password. (Required)
39
+ - `workstation:` _{String}_ Name of workstation or `''`.
40
+ - `domain:` _{String}_ Name of domain or `''`.
41
+
42
+ You can also pass along all other options of [httpreq](https://github.com/SamDecrock/node-httpreq), including custom headers, cookies, body data, ... and use POST, PUT or DELETE instead of GET.
43
+
44
+ ## Advanced
45
+
46
+ If you want to use the NTLM-functions yourself, you can access the ntlm-library like this (https example):
47
+
48
+ ```js
49
+ var ntlm = require('httpntlm').ntlm;
50
+ var async = require('async');
51
+ var httpreq = require('httpreq');
52
+ var HttpsAgent = require('agentkeepalive').HttpsAgent;
53
+ var keepaliveAgent = new HttpsAgent();
54
+
55
+ var options = {
56
+ url: "https://someurl.com",
57
+ username: 'm$',
58
+ password: 'stinks',
59
+ workstation: 'choose.something',
60
+ domain: ''
61
+ };
62
+
63
+ async.waterfall([
64
+ function (callback){
65
+ var type1msg = ntlm.createType1Message(options);
66
+
67
+ httpreq.get(options.url, {
68
+ headers:{
69
+ 'Connection' : 'keep-alive',
70
+ 'Authorization': type1msg
71
+ },
72
+ agent: keepaliveAgent
73
+ }, callback);
74
+ },
75
+
76
+ function (res, callback){
77
+ if(!res.headers['www-authenticate'])
78
+ return callback(new Error('www-authenticate not found on response of second request'));
79
+
80
+ var type2msg = ntlm.parseType2Message(res.headers['www-authenticate']);
81
+ var type3msg = ntlm.createType3Message(type2msg, options);
82
+
83
+ setImmediate(function() {
84
+ httpreq.get(options.url, {
85
+ headers:{
86
+ 'Connection' : 'Close',
87
+ 'Authorization': type3msg
88
+ },
89
+ allowRedirects: false,
90
+ agent: keepaliveAgent
91
+ }, callback);
92
+ });
93
+ }
94
+ ], function (err, res) {
95
+ if(err) return console.log(err);
96
+
97
+ console.log(res.headers);
98
+ console.log(res.body);
99
+ });
100
+ ```
101
+
102
+ ## Download binary files
103
+
104
+ ```javascript
105
+ httpntlm.get({
106
+ url: "https://someurl.com/file.xls",
107
+ username: 'm$',
108
+ password: 'stinks',
109
+ workstation: 'choose.something',
110
+ domain: '',
111
+ binary: true
112
+ }, function (err, response) {
113
+ if(err) return console.log(err);
114
+ fs.writeFile("file.xls", response.body, function (err) {
115
+ if(err) return console.log("error writing file");
116
+ console.log("file.xls saved!");
117
+ });
118
+ });
119
+ ```
120
+
121
+ ## More information
122
+
123
+ * [python-ntlm](https://code.google.com/p/python-ntlm/)
124
+ * [NTLM Authentication Scheme for HTTP](http://www.innovation.ch/personal/ronald/ntlm.html)
125
+ * [LM hash on Wikipedia](http://en.wikipedia.org/wiki/LM_hash)
126
+
127
+
128
+ ## License (MIT)
129
+
130
+ Copyright (c) Sam Decrock <https://github.com/SamDecrock/>
131
+
132
+ Permission is hereby granted, free of charge, to any person obtaining a copy
133
+ of this software and associated documentation files (the "Software"), to deal
134
+ in the Software without restriction, including without limitation the rights
135
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
136
+ copies of the Software, and to permit persons to whom the Software is
137
+ furnished to do so, subject to the following conditions:
138
+
139
+ The above copyright notice and this permission notice shall be included in
140
+ all copies or substantial portions of the Software.
141
+
142
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
143
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
144
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
145
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
146
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
147
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
148
+ THE SOFTWARE.
@@ -0,0 +1,104 @@
1
+ 'use strict';
2
+
3
+ var url = require('url');
4
+ var httpreq = require('httpreq');
5
+ var ntlm = require('./ntlm');
6
+ var _ = require('underscore');
7
+ var http = require('http');
8
+ var https = require('https');
9
+
10
+ exports.method = function(method, options, finalCallback){
11
+ if(!options.workstation) options.workstation = '';
12
+ if(!options.domain) options.domain = '';
13
+
14
+ // extract non-ntlm-options:
15
+ var httpreqOptions = _.omit(options, 'url', 'username', 'password', 'workstation', 'domain');
16
+
17
+ // is https?
18
+ var isHttps = false;
19
+ var reqUrl = url.parse(options.url);
20
+ if(reqUrl.protocol == 'https:') isHttps = true;
21
+
22
+ // set keepaliveAgent (http or https):
23
+ var keepaliveAgent;
24
+
25
+ if(isHttps){
26
+ keepaliveAgent = new https.Agent({keepAlive: true});
27
+ }else{
28
+ keepaliveAgent = new http.Agent({keepAlive: true});
29
+ }
30
+
31
+ // build type1 request:
32
+
33
+ function sendType1Message (callback) {
34
+ var type1msg = ntlm.createType1Message(options);
35
+
36
+ var type1options = {
37
+ headers:{
38
+ 'Connection' : 'keep-alive',
39
+ 'Authorization': type1msg
40
+ },
41
+ timeout: options.timeout || 0,
42
+ agent: keepaliveAgent,
43
+ allowRedirects: false // don't redirect in httpreq, because http could change to https which means we need to change the keepaliveAgent
44
+ };
45
+
46
+ // pass along timeout and ca:
47
+ if(httpreqOptions.timeout) type1options.timeout = httpreqOptions.timeout;
48
+ if(httpreqOptions.ca) type1options.ca = httpreqOptions.ca;
49
+
50
+ // send type1 message to server:
51
+ httpreq.get(options.url, type1options, callback);
52
+ }
53
+
54
+ function sendType3Message (res, callback) {
55
+ // catch redirect here:
56
+ if(res.headers.location) {
57
+ options.url = res.headers.location;
58
+ return exports[method](options, finalCallback);
59
+ }
60
+
61
+
62
+ if(!res.headers['www-authenticate'])
63
+ return callback(new Error('www-authenticate not found on response of second request'));
64
+
65
+ // parse type2 message from server:
66
+ var type2msg = ntlm.parseType2Message(res.headers['www-authenticate']);
67
+
68
+ // create type3 message:
69
+ var type3msg = ntlm.createType3Message(type2msg, options);
70
+
71
+ // build type3 request:
72
+ var type3options = {
73
+ headers: {
74
+ 'Connection': 'Close',
75
+ 'Authorization': type3msg
76
+ },
77
+ allowRedirects: false,
78
+ agent: keepaliveAgent
79
+ };
80
+
81
+ // pass along other options:
82
+ type3options.headers = _.extend(type3options.headers, httpreqOptions.headers);
83
+ type3options = _.extend(type3options, _.omit(httpreqOptions, 'headers'));
84
+
85
+ // send type3 message to server:
86
+ httpreq[method](options.url, type3options, callback);
87
+ }
88
+
89
+
90
+ sendType1Message(function (err, res) {
91
+ if(err) return finalCallback(err);
92
+ setImmediate(function () { // doesn't work without setImmediate()
93
+ sendType3Message(res, finalCallback);
94
+ });
95
+ });
96
+
97
+ };
98
+
99
+ ['get', 'put', 'patch', 'post', 'delete', 'options'].forEach(function(method){
100
+ exports[method] = exports.method.bind(exports, method);
101
+ });
102
+
103
+ exports.ntlm = ntlm; //if you want to use the NTML functions yourself
104
+