diff --git a/.github/workflows/hlib-samoshkin-341-lab5.yml b/.github/workflows/hlib-samoshkin-341-lab5.yml new file mode 100644 index 0000000..4cb269f --- /dev/null +++ b/.github/workflows/hlib-samoshkin-341-lab5.yml @@ -0,0 +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 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 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 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) 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) 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() diff --git a/Lab4/logs_reader.py b/Lab4/logs_reader.py new file mode 100644 index 0000000..68dd77f --- /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) 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 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') 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() 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