m06_ram 1.0.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of m06_ram might be problematic. Click here for more details.

package/06-02.html ADDED
@@ -0,0 +1,99 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <style type="text/css">
6
+ * {
7
+ margin: 0;
8
+ padding: 0;
9
+ font-size: large;
10
+ font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif
11
+ }
12
+
13
+ button {
14
+ border: none;
15
+ border-radius: 8px;
16
+ padding: 8px 15px;
17
+ background-color: rgb(137, 87, 236);
18
+ color: white;
19
+ cursor: pointer;
20
+ }
21
+ input, textarea {
22
+ border: 1px solid #afafaf;
23
+ border-radius: 10px;
24
+ padding: 3px 10px;
25
+ }
26
+
27
+ .container {
28
+ margin: 20px 40px;
29
+ }
30
+ .input-name {
31
+ margin-bottom: 5px;
32
+ font-size: smaller;
33
+ font-weight: 600;
34
+ color: rgb(131, 83, 156);
35
+ }
36
+ .input-name + input, .input-name + textarea {
37
+ margin-bottom: 20px;
38
+ }
39
+ .send-btn {
40
+ margin-top: 10px;
41
+ }
42
+ .answer {
43
+ margin-top: 20px;
44
+ }
45
+ </style>
46
+ </head>
47
+ <body>
48
+ <div class="container">
49
+ <form id="mail-form" action="http://localhost:5000/" method="POST">
50
+ <p class="input-name">Отправитель</p>
51
+ <input type="email" name="sender" required/>
52
+
53
+ <p class="input-name">Пароль</p>
54
+ <input type="password" name="password" value="jknm kkir asau dzvf" required/>
55
+
56
+ <p class="input-name">Получатель</p>
57
+ <input type="email" name="receiver" required/>
58
+
59
+ <p class="input-name">Тема сообщения</p>
60
+ <input type="text" name="subject"/>
61
+
62
+ <p class="input-name">Текст сообщения</p>
63
+ <textarea name="message"></textarea>
64
+
65
+ <div><button type="submit" class="send-btn">Отправить</button></div>
66
+ </form>
67
+
68
+ <p id="answer" class="answer"></p>
69
+ </div>
70
+
71
+ <script>
72
+ const kForm = document.querySelector('#mail-form');
73
+ const kAnswer = document.querySelector('#answer');
74
+
75
+ kForm.addEventListener('submit', e => {
76
+ e.preventDefault();
77
+ fetch(kForm.action, {
78
+ method: kForm.method,
79
+ headers: {
80
+ 'Content-Type': 'application/x-www-forfm-urlencoded',
81
+ },
82
+ body: `${new URLSearchParams(new FormData(kForm))}`,
83
+ }).then(resp => {
84
+ if (resp.ok) {
85
+ return resp.text();
86
+ } else {
87
+ throw new Error(resp.statusText);
88
+ }
89
+ }).then(data => {
90
+ kAnswer.style.color = 'green';
91
+ kAnswer.innerHTML = `${data}`;
92
+ }).catch(error => {
93
+ kAnswer.style.color = 'darkred';
94
+ kAnswer.innerHTML = `${error}`;
95
+ });
96
+ });
97
+ </script>
98
+ </body>
99
+ </html>
package/06-02.js ADDED
@@ -0,0 +1,57 @@
1
+ import { createServer } from 'http';
2
+ import url from 'url';
3
+ import nodemailer from 'nodemailer';
4
+ import querystring from 'querystring';
5
+
6
+ import { yellow, green } from './console_style.mjs';
7
+ import { invite, handleUserError, returnFile } from './labs_util.mjs';
8
+
9
+ const URL = '/';
10
+ const PORT = 5000;
11
+ const FILE_PATH = './06-02.html';
12
+
13
+ createServer((req, resp) => {
14
+ const kUrlPathName = url.parse(req.url).pathname;
15
+
16
+ if (kUrlPathName === URL && req.method === 'GET') {
17
+ returnFile(resp, FILE_PATH);
18
+ return;
19
+ }
20
+
21
+ if (kUrlPathName === URL && req.method === 'POST') {
22
+ let body = '';
23
+ req.on('data', chunk => {
24
+ body += chunk.toString();
25
+ }).on('end', () => {
26
+ const kParams = querystring.parse(body);
27
+
28
+ const kTransport = nodemailer.createTransport({
29
+ service: 'gmail',
30
+ auth: {
31
+ user: kParams.sender,
32
+ pass: kParams.password,
33
+ },
34
+ });
35
+
36
+ const kMailOptions = {
37
+ from: kParams.sender,
38
+ to: kParams.receiver,
39
+ subject: kParams.subject,
40
+ text: kParams.message,
41
+ }
42
+
43
+ kTransport.sendMail(kMailOptions, (error, info) => {
44
+ if (error) {
45
+ handleUserError(resp, error);
46
+ return;
47
+ }
48
+ console.log(green('Email sent: ') + yellow(info.response));
49
+ resp.writeHead(200)
50
+ .end('Отправлено!');
51
+ });
52
+ });
53
+ return;
54
+ }
55
+
56
+ invite(resp, PORT, URL);
57
+ }).listen(PORT);
package/06-03.js ADDED
@@ -0,0 +1,5 @@
1
+ import send from './m06_RAM.js';
2
+
3
+ send('alesha.rom@gmail.com',
4
+ 'jknm kkir asau dzvf',
5
+ 'Hello!');
package/06-04.js ADDED
@@ -0,0 +1,10 @@
1
+ // 'C:\\Users\\valda\\AppData\\Roaming\\npm\\node_modules\\secxmail'
2
+ // `${process.env.NODE_GLOBAL}\\secxmail`
3
+ import { createServer } from 'http';
4
+ import { send } from './m06_RAM';
5
+
6
+ createServer((req, res) => {
7
+ res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
8
+ send('[06-04] hello from secxmail GLOBAL module!');
9
+ res.end('<h2>Message sucessfully sent.</h2>');
10
+ }).listen(5000, () => console.log('Server running at localhost:5000/\n'));
@@ -0,0 +1,62 @@
1
+ export const Mod = {
2
+ Reset: 0,
3
+ Bold: 1,
4
+ Dim: 2,
5
+ Italic: 3,
6
+ Underline: 4,
7
+ Blink: 5,
8
+ RapidBlink: 6,
9
+ ReverseVideo: 7,
10
+ Conceal: 8,
11
+ CrossedOut: 9,
12
+ PrimaryFont: 10,
13
+ AltFont1: 11,
14
+ AltFont2: 12,
15
+ AltFont3: 13,
16
+ AltFont4: 14,
17
+ AltFont5: 15,
18
+ AltFont6: 16,
19
+ AltFont7: 17,
20
+ AltFont8: 18,
21
+ AltFont9: 19,
22
+ Fraktur: 20,
23
+ BoldOff: 21,
24
+ NormalColorOrIntensity: 22,
25
+ NotItalicOrFraktur: 23,
26
+ UnderlineOff: 24,
27
+ BlinkOff: 25,
28
+ Reserved26: 26,
29
+ ImageNegative: 27,
30
+ RevealOrConcealOff: 28,
31
+ NotCrossedOut: 29,
32
+ };
33
+
34
+ export const Color = {
35
+ Black: 0,
36
+ Red: 1,
37
+ Green: 2,
38
+ Yellow: 3,
39
+ Blue: 4,
40
+ Magenta: 5,
41
+ Cyan: 6,
42
+ White: 7,
43
+ Default: 9,
44
+ };
45
+
46
+ // Mode
47
+ export function bold(text) { return `\x1b[${Mod.Bold}m${text}\x1b[${Mod.NormalColorOrIntensity}m`; }
48
+ export function italic(text) { return `\x1b[${Mod.Italic}m${text}\x1b[${Mod.NotItalicOrFraktur}m`; }
49
+ export function underline(text) { return `\x1b[${Mod.Underline}m${text}\x1b[${Mod.UnderlineOff}m`; }
50
+ export function reverse(text) { return `\x1b[${Mod.ReverseVideo}m${text}\x1b[${Mod.ImageNegative}m`; }
51
+ export function conceal(text) { return `\x1b[${Mod.Conceal}m${text}\x1b[${Mod.RevealOrConcealOff}m`; }
52
+ export function crossedOut(text) { return `\x1b[${Mod.CrossedOut}m${text}\x1b[${Mod.NotCrossedOut}m`; }
53
+
54
+ // Foreground
55
+ export function fgColor(text, fgColor) { return `\x1b[3${fgColor}m${text}\x1b[3${Color.Default}m`; }
56
+ export function red(text) { return fgColor(text, Color.Red); }
57
+ export function green(text) { return fgColor(text, Color.Green); }
58
+ export function yellow(text) { return fgColor(text, Color.Yellow); }
59
+
60
+ // Background
61
+ export function bgColor(text, bgColor) { return `\x1b[4${bgColor}m${text}\x1b[4${Color.Default}m`; }
62
+ export function onYellow(text) { return bgColor(text, Color.Yellow); }
package/labs_util.mjs ADDED
@@ -0,0 +1,34 @@
1
+ import { readFile } from 'fs';
2
+
3
+ export function handleUserError(resp, error, code = 400, msg = error.message) {
4
+ resp.writeHead(code, {'Content-Type': 'text/plain; charset=utf-8'})
5
+ .end(msg);
6
+ }
7
+
8
+ export function handleServerError(resp, error, code = 500, msg = 'Internal Server Error') {
9
+ resp.writeHead(code, {'Content-Type': 'text/plain; charset=utf-8'})
10
+ .end(msg);
11
+ console.error(error);
12
+ }
13
+
14
+ export function invite(resp, port, url) {
15
+ resp.writeHead(200, {'Content-Type': 'text/html; charset=utf-8'})
16
+ .end(
17
+ '<!DOCTYPE html><html><head></head>' +
18
+ '<body>'+
19
+ `<a href='http://localhost:${port}${url}'>Перейти на ${url}</a>` +
20
+ '</body>' +
21
+ '</html>'
22
+ );
23
+ }
24
+
25
+ export function returnFile(resp, path) {
26
+ readFile(path, 'utf-8', (error, data) => {
27
+ if (error) {
28
+ handleServerError(resp, error);
29
+ return;
30
+ }
31
+ resp.writeHead(200, {'Content-Type': 'text/html; charset=utf-8'})
32
+ .end(data);
33
+ });
34
+ }
package/m06_RAM.js ADDED
@@ -0,0 +1,26 @@
1
+ import { createTransport } from 'nodemailer';
2
+ import { green, yellow } from './console_style.mjs';
3
+
4
+ export default function send(email, password, message) {
5
+ const kTransport = createTransport({
6
+ service: 'gmail',
7
+ auth: {
8
+ user: email,
9
+ pass: password,
10
+ },
11
+ });
12
+
13
+ const kMailOptions = {
14
+ from: email,
15
+ to: email,
16
+ text: message,
17
+ }
18
+
19
+ kTransport.sendMail(kMailOptions, (error, info) => {
20
+ if (error) {
21
+ console.error(error);
22
+ return;
23
+ }
24
+ console.log(green('Email sent: ') + yellow(info.response));
25
+ });
26
+ }
package/package.json ADDED
@@ -0,0 +1,12 @@
1
+ {
2
+ "type": "module",
3
+ "dependencies": {
4
+ "nodemailer": "^6.9.6"
5
+ },
6
+ "name": "m06_ram",
7
+ "version": "1.0.0",
8
+ "description": "Talk with yourself using nodemailer.",
9
+ "main": "m06_RAM.js",
10
+ "devDependencies": {},
11
+ "author": "Aliaksiej Ramanchuk"
12
+ }
package/xd/06-02.js ADDED
@@ -0,0 +1,67 @@
1
+ // import http from 'http';
2
+ // import url from 'url';
3
+ // import fs from 'fs';
4
+ // import { parse } from 'querystring';
5
+ // import nodemailer from 'nodemailer';
6
+ // to use imports instead of require, open package.json
7
+ // and add "type": "module", before "dependencies"
8
+ // xbguckzhonlehivd
9
+
10
+
11
+
12
+ const http = require('http');
13
+ const url = require('url');
14
+ const fs = require('fs');
15
+ const { parse } = require('querystring');
16
+ const nodemailer = require('nodemailer');
17
+
18
+
19
+
20
+ http.createServer((request, response) => {
21
+ response.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
22
+
23
+ if (url.parse(request.url).pathname === '/' && request.method === 'GET')
24
+ {
25
+ response.end(fs.readFileSync('./06-02.html'));
26
+ }
27
+ else if (url.parse(request.url).pathname === '/' && request.method === 'POST')
28
+ {
29
+ let body = '';
30
+ request.on('data', chunk => { body += chunk.toString(); });
31
+
32
+ request.on('end', () => {
33
+ let parm = parse(body);
34
+
35
+ const transporter = nodemailer.createTransport({
36
+ host: 'smtp.gmail.com',
37
+ port: 465,
38
+ secure: false,
39
+ service: 'Gmail',
40
+ auth: {
41
+ user: parm.sender,
42
+ pass: parm.password
43
+ }
44
+ });
45
+
46
+ const mailOptions = {
47
+ from: parm.sender,
48
+ to: parm.receiver,
49
+ subject: parm.subject,
50
+ text: parm.message
51
+ }
52
+
53
+ transporter.sendMail(mailOptions, (err, info) => {
54
+ err ? console.log(err) : console.log('Sent: ' + info.response);
55
+ })
56
+
57
+ response.end(`<h2>Отправитель: ${parm.sender}</br>Получатель: ${parm.receiver}
58
+ </br>Тема: ${parm.subject}</br>Сообщение: ${parm.message}</h2>`);
59
+ })
60
+ }
61
+
62
+ else
63
+ response.end('<html><body><h1>Error! Visit localhost:5000/</h1></body></html>');
64
+ }).listen(5000, () => console.log('Server running at localhost:5000/\n'));
65
+
66
+
67
+