Skip to content

Королев С.В. Пи20-1 #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions 3_reg.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<html>
<head>
<meta charset "utf-8">
<title>Registration</title>
<style type="text/css">
body {
background-image: url(https://www.pixel-creation.com/wp-content/uploads/carbon-fiber-wallpaper-6887670.jpg);
}


.button{
color: lime;

border: 1px solid black;
width: 100%;
}


.box {
padding: 20px;
left: 30%;
width: 40%;
position: relative;
background: rgba(90, 90, 90, 0.4);
}

p {
color:gold;
}
h4 {
color:white;
padding: 10px;
}
input{
background: transparent;
}
</style>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-F3w7mX95PdgyTmZZMECAngseQB83DfGTowi0iMjiWaeVhAn4FJkqJByhZMI3AhiU" crossorigin="anonymous">
</head>
<form>
<div class="container">
<div class="row">
<div class="col">
<pre><a href="Index.html" target="_blank"><img src="https://allcarbrandslist.com/wp-content/uploads/2020/12/Nissan-Logo-1978.png" width="100" height="75" hspace="2" alt="img4" usemap="#link"></a></pre>
</div>
<div class="col">
<pre align="right", style="color:white">Already have an account? <a href="Index.html" target="_blank"> Sign in →</a></pre>
</div>
</div>
<div class="box">
<p>Welcome to NissanHub!</p>
<p>Pain starts here</p>
<h4>Enter your email</h4>
<div class="row">
<div class="col">
<input type="email" method="post" class="input">
</div>
<div class="col">
<a href="https://github.com/MikeMarshall36" target="_blank">Git</a>
<input type="submit" value="Continue" class="button">
</div>
</div>
</div>
</div>





</form>
</body>
</html>
66 changes: 66 additions & 0 deletions Index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<html>
<head>
<meta charset "utf-8">
<title>Authorization</title>
<style type="text/css">
.button{
color: white;
background: rgba(30, 170, 60);
border: 0px;
width: 100%;
}
.input {
width: 100%;
margin: 0px 0px 10px;
}

.box {
padding: 10px;
left: 30%;
width: 40%;
position: relative;
background: rgba(200, 200, 200, 0.5);
}
.box2 {
position: relative;
margin: 10px 0px 10px;
padding: 10px;
left: 30%;
width: 40%;

border: 1px solid black;
}
</style>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-F3w7mX95PdgyTmZZMECAngseQB83DfGTowi0iMjiWaeVhAn4FJkqJByhZMI3AhiU" crossorigin="anonymous">
</head>
<form>
<p align="center"><a href="https://allcarbrandslist.com/wp-content/uploads/2020/12/Nissan-Logo-1978.png" target="_blank"><img src="https://allcarbrandslist.com/wp-content/uploads/2020/12/Nissan-Logo-1978.png" width="100" height="75" hspace="2" alt="img4" usemap="#link"></a></p>
<h3 align="center">Sign in NissanHub</h3>

<div class="container">
<div class="box">
<p>Username or email address</p>
<input type="name" method="post" class="input">
<div class="row">
<div class="col">

<p>Password</p>
</div>
<div class="col">
<p align="right"><a href="https://allcarbrandslist.com/wp-content/uploads/2020/12/Nissan-Logo-1978.png" target="_blank"> Forgot password?</a></p>
</p>
</div>
</div>
<input type="passwd" method="post" class="input">

<input type="submit" value="Sign in" class="button">
</div>


<div class="box2">
<pre align="center">First time? <a href="3_reg.html" target="_blank">Create a hole in your wallet.</pre>
</div>
</div>
</form>
</body>
</html>
3 changes: 3 additions & 0 deletions settings.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
port: 8080
directoria: 127.0.0.1
max_b: 4096
116 changes: 116 additions & 0 deletions web_server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import datetime as c_data
import os
from contextlib import closing
import socket
import threading

class Web_server(threading.Thread):
def __init__(self, conn, addr, direct):
super().__init__(daemon=True)
self.conn = conn
self.addr = addr
self.ip = str(addr)
self.connection()
self.direct = direct
self.client_handeling()

def connection(self):
print(f'Connection came from: {self.addr}')

def client_handeling(self):
while True:
try:
fl = self.conn.makefile('r')
except ConnectionAbortedError:
break
msg = fl.readline(customs[2]).split()[1]
if msg == '/':
msg = '/index.html'
file_type = 'html'
else:
try:
file_type = msg.split('.')[-1]
except IndexError:
file_type = '-'
fl = os.path.join(self.direct, msg[1:])
if os.path.exists(fl) == True:
if file_type == 'txt' or file_type == 'html':
file_type = 'text/html'
self.response(file_reader(fl), msg, file_type, 'non_error')
else:
self.response("Error 403. The format is not supported", msg, file_type, '403')
else:
self.response("Error 404. File not found", msg, file_type, '404')
self.conn.close()

def response(self, resp, msg, file_type, err):
log_date = str(c_data.datetime.date(c_data.datetime.today()))
logging(msg, err, log_date, self.ip)
ln_res = len(resp)
resp = f"""HTTP/1.1 200 OK
Server: simple_http_server v0.0.1
Content-type: {file_type}
Date: {date}
Connection: close
Date: {date}
Content-length: {ln_res}
{resp}"""
self.conn.send(resp.encode('utf-8'))

def logging(name, error_code, date, ip):
f = open(log_name, 'a')
f.write(date + ' ' + ip + ' ' + name + ' ' + error_code + '\n')
f.close()

def find_free_port(ip_set):
with closing(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as s:
s.bind((ip_set, 0))
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
return s.getsockname()[1]

customs = []
with open('settings.txt', 'r') as f:
for i in f:
customs.append(i.split(': ')[1][:-1])
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
customs[0] = int(customs[0])
customs[2] = int(customs[2])
try:

sock.bind((customs[1], customs[0]))
print(f"Ваш адрес {customs[1]} {customs[0]}")

except OSError:

customs[0] = find_free_port(customs[1])
print(f'Выбранный вами порт уже занят.\nНовый порт: {customs[1]}{customs[0]}')
sock.bind(('', customs[0]))
customs[0] = str(customs[0])
log_name = 'log_server' + customs[1] + '_' + str(customs[0]) + '.txt'
date = str(c_data.datetime.date(c_data.datetime.today()))


try:

with open(log_name, 'a') as f:
f.write(date+' '+nastroi[1]+' '+nastroi[0]+' admin Server activate\n')
print('Начата запись в лог файл')
except FileNotFoundError:
with open(log_name, 'w') as f:
f.write(date+' '+nastroi[1]+' '+nastroi[0]+' admin Server activate\n')
Print('Лог файл создан. Запись начата')
sock.listen(1)

def file_reader(name):
file = open(name, 'r')
content = file.read()
file.close()
return content

direct = os.getcwd()
while True:
try:
sockt = Web_server(*sock.accept(), direct)
sockt.start()
except:
continue
Binary file not shown.