From f13f6de449a02a2fce153e673c8a494a4781bb1b Mon Sep 17 00:00:00 2001 From: IntolerantOne <87035879+IntolerantOne@users.noreply.github.com> Date: Sun, 11 Jul 2021 15:32:15 +0300 Subject: [PATCH 01/15] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4942958..0b34210 100644 --- a/README.md +++ b/README.md @@ -1 +1 @@ -# devops_practice \ No newline at end of file +Гліб Самошкін 341 From 5bd099ffcbb3bb50bca4c1213d5fb69558177554 Mon Sep 17 00:00:00 2001 From: IntolerantOne <87035879+IntolerantOne@users.noreply.github.com> Date: Sun, 11 Jul 2021 17:27:49 +0300 Subject: [PATCH 02/15] Add files via upload --- Lab1.txt | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 Lab1.txt diff --git a/Lab1.txt b/Lab1.txt new file mode 100644 index 0000000..9638b42 --- /dev/null +++ b/Lab1.txt @@ -0,0 +1,98 @@ + 1 mkdir -p ~/.ssh + 2 chmod 700 ~/.ssh + 3 cd ~/.ssh/ + 4 sudo nano authorized_keys + 5 exit + 6 exit + 7 cd ~/.ssh/ + 8 sudo nano authorized_keys + 9 sudo systemctl restart sshd + 10 ssh -p 2200 Mike@localhost + 11 exit + 12 cd ~/.ssh/ + 13 sudo nano authorized_keys + 14 sudo systemctl restart sshd + 15 exit + 16 ls + 17 pwd + 18 man man + 19 info ls + 20 info ls + 21 ls -info + 22 whatis ls + 23 whatis -ls + 24 cd + 25 pwd + 26 ls + 27 ls -a + 28 cd /home/documents + 29 cat > File1 + 30 cat File1 + 31 cat File2 + 32 cat > File2 + 33 cat File1 File2 > Res + 34 cat Res + 35 ls -a > New + 36 cat New + 37 history > Lab1 + 38 cat history + 39 cat Lab1 + 40 pwd + 41 history > Lab1 + 42 cat Lab1 + 43 mkdir trash + 44 pwd + 45 cd trash + 46 cd .. + 47 man mkdir + 48 cp File1 File2 + 49 cat File2 + 50 cat File1 + 51 cp File1 File2 trash + 52 cd trash + 53 ls + 54 cd .. + 55 mkdir Test + 56 cp -r trash Ookla + 57 pwd + 58 ls + 59 cd Ookla + 60 ls -a + 61 cd .. + 62 cp -r trash Test Ookla + 63 rm File1 + 64 rm -r trash + 65 ls + 66 cat > File3 + 67 mv File3 Test + 68 cd Test + 69 ls + 70 cd .. + 71 ls + 72 mv File2 Soska + 73 ls + 74 mv [S]* Test + 75 cd Test + 76 ls + 77 cd .. + 78 history > Lab1 + 79 cat Lab1 + 80 chown douglas Res + 81 sudo chown douglas Res + 82 man chgrp + 83 ls + 84 chgrp dudes New + 85 groups + 86 ls -al + 87 chmod {+} [o] New + 88 chmod --help + 89 chmod u+x New + 90 fork() SA + 91 umask + 92 getuid + 93 getuid() das + 94 getuid(void) + 95 man gcc + 96 gcc -info + 97 gcc + 98 history > Lab1 From e5498323194481db121709364f0e00f8825b4823 Mon Sep 17 00:00:00 2001 From: IntolerantOne <87035879+IntolerantOne@users.noreply.github.com> Date: Sun, 11 Jul 2021 19:48:59 +0300 Subject: [PATCH 03/15] Lab2 --- Lab2-renamer.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Lab2-renamer.sh diff --git a/Lab2-renamer.sh b/Lab2-renamer.sh new file mode 100644 index 0000000..37910c3 --- /dev/null +++ b/Lab2-renamer.sh @@ -0,0 +1,12 @@ + +#!/bin/bash +echo "Input path : " +read path +cd $path +value=1 +for file in * +do + mv "$file" $value-"$file" + (( value ++ )) +done +ls From 414340001213923b881f2e7f1451c1ed1f7a6174 Mon Sep 17 00:00:00 2001 From: IntolerantOne <87035879+IntolerantOne@users.noreply.github.com> Date: Sat, 17 Jul 2021 15:22:35 +0300 Subject: [PATCH 04/15] Create task1.py --- Lab3-1/task1.py | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 Lab3-1/task1.py diff --git a/Lab3-1/task1.py b/Lab3-1/task1.py new file mode 100644 index 0000000..95548b0 --- /dev/null +++ b/Lab3-1/task1.py @@ -0,0 +1,6 @@ +from itertools import permutations +for x in permutations('aeiou'): + sample='' + for z in x: + sample += z + print(sample) From 02b2e261f8349a9e2f427a8057cefa19e9cd6dc2 Mon Sep 17 00:00:00 2001 From: IntolerantOne <87035879+IntolerantOne@users.noreply.github.com> Date: Sat, 17 Jul 2021 15:23:43 +0300 Subject: [PATCH 05/15] Add files via upload --- Lab3-1/task2.py | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 Lab3-1/task2.py diff --git a/Lab3-1/task2.py b/Lab3-1/task2.py new file mode 100644 index 0000000..76274ad --- /dev/null +++ b/Lab3-1/task2.py @@ -0,0 +1,6 @@ +import sys +z = int(sys.argv[1]) +x = int(sys.argv[2]) +c = int(sys.argv[3]) +v = z*z + x*x + c*c +print(v) From 4b6b9ee26d1638e488c24430430124c2f38b4070 Mon Sep 17 00:00:00 2001 From: IntolerantOne <87035879+IntolerantOne@users.noreply.github.com> Date: Sun, 18 Jul 2021 16:43:51 +0300 Subject: [PATCH 06/15] Create logs_parser.py --- Lab4/logs_parser.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Lab4/logs_parser.py diff --git a/Lab4/logs_parser.py b/Lab4/logs_parser.py new file mode 100644 index 0000000..98f8e81 --- /dev/null +++ b/Lab4/logs_parser.py @@ -0,0 +1,32 @@ +import re +from sqlalchemy import create_engine, MetaData, Table, Column, Integer, String, DateTime +import datetime +import sys + +engine = create_engine('sqlite:///access_logs.db', echo = False) +meta = MetaData() + +access_logs = Table( + 'access_logs', meta, + Column('id', Integer, primary_key = True), + Column('hostname', String), + Column('ip_address', String), + Column('date_time', DateTime), + Column('message', String), +) + +meta.create_all(engine) +conn = engine.connect() +logs_entries = [] +file = open(sys.argv[1], 'r') + +for entry in file: + line = re.compile(r'^((Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s+\d{1,2}\s+\d{2}:\d{2}:\d{2})\s+(\S+)\s+(sshd)\S+:\s+(.*?(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}).*)$').search(entry) + if line: + datetime_str = line.group(1) + " " + str(datetime.datetime.now().year) + datetime_obj = datetime.datetime.strptime(datetime_str, '%b %d %H:%M:%S %Y') + logs_entries.append({"hostname": line.group(3), "ip_address": line.group(6), "date_time": datetime_obj, "message":line.group(5)}) + +result = conn.execute(access_logs.insert(None), logs_entries) +file.close() +conn.close() From 59db2cc92b86cb069293fde3a6aad3dc5d730250 Mon Sep 17 00:00:00 2001 From: IntolerantOne <87035879+IntolerantOne@users.noreply.github.com> Date: Sun, 18 Jul 2021 16:45:28 +0300 Subject: [PATCH 07/15] Add files via upload --- Lab4/logs_reader.py | 13 +++++++++++++ Lab4/requirements.txt | 5 +++++ 2 files changed, 18 insertions(+) create mode 100644 Lab4/logs_reader.py create mode 100644 Lab4/requirements.txt diff --git a/Lab4/logs_reader.py b/Lab4/logs_reader.py new file mode 100644 index 0000000..aefb8cb --- /dev/null +++ b/Lab4/logs_reader.py @@ -0,0 +1,13 @@ +import sys +from sqlalchemy import create_engine + +engine = create_engine('sqlite:///access_logs.db', echo = False) +connection = engine.connect() + +user_ip = sys.argv[1] +que = "SELECT * FROM access_logs WHERE ip_address=:ip" +info = connection.execute(que, ip = user_ip).fetchall() +connection.close() + +for d in info: + print(d) \ No newline at end of file diff --git a/Lab4/requirements.txt b/Lab4/requirements.txt new file mode 100644 index 0000000..1245a33 --- /dev/null +++ b/Lab4/requirements.txt @@ -0,0 +1,5 @@ +greenlet==1.1.0 +importlib-metadata==4.6.1 +SQLAlchemy==1.4.21 +typing-extensions==3.10.0.0 +zipp==3.5.0 From c4dffcd06b4bd21c515815c2047144326ffe7a90 Mon Sep 17 00:00:00 2001 From: IntolerantOne <87035879+IntolerantOne@users.noreply.github.com> Date: Sun, 18 Jul 2021 16:47:15 +0300 Subject: [PATCH 08/15] Update logs_reader.py --- Lab4/logs_reader.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lab4/logs_reader.py b/Lab4/logs_reader.py index aefb8cb..4a1164f 100644 --- a/Lab4/logs_reader.py +++ b/Lab4/logs_reader.py @@ -5,9 +5,9 @@ connection = engine.connect() user_ip = sys.argv[1] -que = "SELECT * FROM access_logs WHERE ip_address=:ip" +que = "SELECT * FROM access_logs WHERE user_ip=:ip" info = connection.execute(que, ip = user_ip).fetchall() connection.close() for d in info: - print(d) \ No newline at end of file + print(d) From a8b8a3f646139277e3cc4f6a6d0042ec6236c113 Mon Sep 17 00:00:00 2001 From: IntolerantOne <87035879+IntolerantOne@users.noreply.github.com> Date: Sun, 18 Jul 2021 16:55:36 +0300 Subject: [PATCH 09/15] Update logs_reader.py --- Lab4/logs_reader.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lab4/logs_reader.py b/Lab4/logs_reader.py index 4a1164f..68dd77f 100644 --- a/Lab4/logs_reader.py +++ b/Lab4/logs_reader.py @@ -5,7 +5,7 @@ connection = engine.connect() user_ip = sys.argv[1] -que = "SELECT * FROM access_logs WHERE user_ip=:ip" +que = "SELECT * FROM access_logs WHERE ip_address=:ip" info = connection.execute(que, ip = user_ip).fetchall() connection.close() From 673c59d7edcc068c07d6bcc7a2f7af288e3b3adc Mon Sep 17 00:00:00 2001 From: IntolerantOne <87035879+IntolerantOne@users.noreply.github.com> Date: Thu, 22 Jul 2021 18:01:45 +0300 Subject: [PATCH 10/15] Create samoshkin-hlib-341-lab5.yml --- .github/workflows/samoshkin-hlib-341-lab5.yml | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 .github/workflows/samoshkin-hlib-341-lab5.yml diff --git a/.github/workflows/samoshkin-hlib-341-lab5.yml b/.github/workflows/samoshkin-hlib-341-lab5.yml new file mode 100644 index 0000000..03b3932 --- /dev/null +++ b/.github/workflows/samoshkin-hlib-341-lab5.yml @@ -0,0 +1,26 @@ +name: Hlib-Samoshkin-341-lab5 + +on: + workflow_dispatch: +jobs: + sendemailwithuniqueid: + runs-on: ubuntu-latest + + steps: + - name: Check repo + uses: actions/checkout@v2 + - name: Get log file using wget + run: wget https://gitlab.com/oyakivchik/logfile/-/raw/main/access.log + - name: Install python + uses: actions/setup-python@v2 + with: + python-version: 3.8 + - name: Installing requirements + run: + pip install -r Lab5/requirements.txt + - name: run log_parser + run: + python Lab5/log_parser.py —path access.log + - name: Send unique ip to email + run: + python Lab5/ip_email.py From fc39d19d53a48a05a3909e07eda5a57e237bb8a0 Mon Sep 17 00:00:00 2001 From: IntolerantOne <87035879+IntolerantOne@users.noreply.github.com> Date: Thu, 22 Jul 2021 18:12:39 +0300 Subject: [PATCH 11/15] Create logs_parser.py --- Lab5/logs_parser.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Lab5/logs_parser.py diff --git a/Lab5/logs_parser.py b/Lab5/logs_parser.py new file mode 100644 index 0000000..98f8e81 --- /dev/null +++ b/Lab5/logs_parser.py @@ -0,0 +1,32 @@ +import re +from sqlalchemy import create_engine, MetaData, Table, Column, Integer, String, DateTime +import datetime +import sys + +engine = create_engine('sqlite:///access_logs.db', echo = False) +meta = MetaData() + +access_logs = Table( + 'access_logs', meta, + Column('id', Integer, primary_key = True), + Column('hostname', String), + Column('ip_address', String), + Column('date_time', DateTime), + Column('message', String), +) + +meta.create_all(engine) +conn = engine.connect() +logs_entries = [] +file = open(sys.argv[1], 'r') + +for entry in file: + line = re.compile(r'^((Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s+\d{1,2}\s+\d{2}:\d{2}:\d{2})\s+(\S+)\s+(sshd)\S+:\s+(.*?(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}).*)$').search(entry) + if line: + datetime_str = line.group(1) + " " + str(datetime.datetime.now().year) + datetime_obj = datetime.datetime.strptime(datetime_str, '%b %d %H:%M:%S %Y') + logs_entries.append({"hostname": line.group(3), "ip_address": line.group(6), "date_time": datetime_obj, "message":line.group(5)}) + +result = conn.execute(access_logs.insert(None), logs_entries) +file.close() +conn.close() From c4d8bba90127f6accc81bcd88900728179a380d5 Mon Sep 17 00:00:00 2001 From: IntolerantOne <87035879+IntolerantOne@users.noreply.github.com> Date: Thu, 22 Jul 2021 18:15:18 +0300 Subject: [PATCH 12/15] Create ip_email.py --- Lab5/ip_email.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Lab5/ip_email.py diff --git a/Lab5/ip_email.py b/Lab5/ip_email.py new file mode 100644 index 0000000..21c0d77 --- /dev/null +++ b/Lab5/ip_email.py @@ -0,0 +1,47 @@ +import smtplib, ssl +from email.mime.text import MIMEText +from email.mime.multipart import MIMEMultipart +from sqlalchemy import * +from sqlalchemy.sql import select + +engine = create_engine('sqlite:///access_logs.db', echo=False) +meta = MetaData() +result_list = '' + +access_logs = Table( + 'access_logs', meta, + Column('id',Integer,primary_key=True), + Column('hostname',String), + Column('ip_address',String), + Column('date_time',DateTime), + Column('message',String), +) + +conn = engine.connect() +query = select(access_logs.c.ip_address).distinct() +result = conn.execute(query) + +for row in result: + result_list += str(row.ip_address)+'\n' + print(row.ip_address) + +conn.close() + +sender_email = "zalupa.tvoego.slona@gmail.com" +receiver_email = "olexiy.jakivtchik@gmail.com" +password = "12345Qwert" + +message = MIMEMultipart("alternative") +message["Subject"] = "Самошкін-Гліб-341 Lab5" +message["From"] = sender_email +message["To"] = receiver_email + +text = result_list +mess = MIMEText(text, "plain") +message.attach(mess) + +context = ssl.create_default_context() +with smtplib.SMTP_SSL("smtp.gmail.com", 465 , context=context) as server: + server.login(sender_email, password) + server.sendmail(sender_email, receiver_email, message.as_string()) +print('Completed') From 78741c111d7000bbff362221ec4f57a1f36843ac Mon Sep 17 00:00:00 2001 From: IntolerantOne <87035879+IntolerantOne@users.noreply.github.com> Date: Thu, 22 Jul 2021 18:44:48 +0300 Subject: [PATCH 13/15] Delete .github directory --- .github/workflows/samoshkin-hlib-341-lab5.yml | 26 ------------------- 1 file changed, 26 deletions(-) delete mode 100644 .github/workflows/samoshkin-hlib-341-lab5.yml diff --git a/.github/workflows/samoshkin-hlib-341-lab5.yml b/.github/workflows/samoshkin-hlib-341-lab5.yml deleted file mode 100644 index 03b3932..0000000 --- a/.github/workflows/samoshkin-hlib-341-lab5.yml +++ /dev/null @@ -1,26 +0,0 @@ -name: Hlib-Samoshkin-341-lab5 - -on: - workflow_dispatch: -jobs: - sendemailwithuniqueid: - runs-on: ubuntu-latest - - steps: - - name: Check repo - uses: actions/checkout@v2 - - name: Get log file using wget - run: wget https://gitlab.com/oyakivchik/logfile/-/raw/main/access.log - - name: Install python - uses: actions/setup-python@v2 - with: - python-version: 3.8 - - name: Installing requirements - run: - pip install -r Lab5/requirements.txt - - name: run log_parser - run: - python Lab5/log_parser.py —path access.log - - name: Send unique ip to email - run: - python Lab5/ip_email.py From 8a95a8994d8162302e81ecd105fcf65866714ee0 Mon Sep 17 00:00:00 2001 From: IntolerantOne <87035879+IntolerantOne@users.noreply.github.com> Date: Thu, 22 Jul 2021 18:46:06 +0300 Subject: [PATCH 14/15] Create hlib-samoshkin-341-lab5.yml --- .github/workflows/hlib-samoshkin-341-lab5.yml | 1 + 1 file changed, 1 insertion(+) create mode 100644 .github/workflows/hlib-samoshkin-341-lab5.yml diff --git a/.github/workflows/hlib-samoshkin-341-lab5.yml b/.github/workflows/hlib-samoshkin-341-lab5.yml new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/.github/workflows/hlib-samoshkin-341-lab5.yml @@ -0,0 +1 @@ + From 721bd6fd5bd7b673b57f358054d9679aa320ec97 Mon Sep 17 00:00:00 2001 From: IntolerantOne <87035879+IntolerantOne@users.noreply.github.com> Date: Thu, 22 Jul 2021 18:48:28 +0300 Subject: [PATCH 15/15] Update hlib-samoshkin-341-lab5.yml --- .github/workflows/hlib-samoshkin-341-lab5.yml | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/.github/workflows/hlib-samoshkin-341-lab5.yml b/.github/workflows/hlib-samoshkin-341-lab5.yml index 8b13789..4cb269f 100644 --- a/.github/workflows/hlib-samoshkin-341-lab5.yml +++ b/.github/workflows/hlib-samoshkin-341-lab5.yml @@ -1 +1,27 @@ +name: Hlib-Samoshkin-341-Lab5 + +on: + workflow_dispatch: +jobs: + sendemailwithuniqueid: + runs-on: ubuntu-latest + + steps: + - name: Check repo + uses: actions/checkout@v2 + - name: Get log file using wget + run: wget https://gitlab.com/oyakivchik/logfile/-/raw/main/access.log + - name: Install python + uses: actions/setup-python@v2 + with: + python-version: 3.8 + - name: Installing requirements + run: + pip install -r Lab5/requirements.txt + - name: run log_parser + run: + python Lab5/log_parser.py —path access.log + - name: Send unique ip to email + run: + python Lab5/ip_email.py