Refactored Python3 code and some thinkering to use it with Mimir.
master
Matheus 4 years ago
parent f454f3f8bb
commit ad3c74fa0b

BIN
.DS_Store vendored

Binary file not shown.

@ -0,0 +1,84 @@
#
# _ __ ,---. .-._ _,.---._ ,---.
# .-`.' ,`..--.' \ /==/ \ .-._ _,..---._ ,-.' , - `. .-.,.---. .--.' \
# /==/, - \==\-/\ \ |==|, \/ /, /==/, - \ /==/_, , - \ /==/ ` \ \==\-/\ \
# |==| _ .=. /==/-|_\ | |==|- \| ||==| _ _\==| .=. |==|-, .=., |/==/-|_\ |
# |==| , '=',\==\, - \ |==| , | -||==| .=. |==|_ : ;=: - |==| '=' /\==\, - \
# |==|- '..'/==/ - ,| |==| - _ ||==|,| | -|==| , '=' |==|- , .' /==/ - ,|
# |==|, | /==/- /\ - \|==| /\ , ||==| '=' /\==\ - ,_ /|==|_ . ,'./==/- /\ - \
# /==/ - | \==\ _.\=\.-'/==/, | |- ||==|-, _`/ '.='. - .' /==/ /\ , )==\ _.\=\.-'
# `--`---' `--` `--`./ `--``-.`.____.' `--`--'' `--`-`--`--' `--`
#
# VERSION 0.75
#
# POST and GET kinda implemented
# You gonna need to run PANDORA from the root of the project
# That you're serving
# Otherwhise its not gonna work
#
#
# TODO:
# Serve specific folders/files
# Change dinamically the host
# SSL integration
import http.server
import socket
import socketserver
from io import BytesIO
import ssl # For future implementation with Openssl
PORT = 8040 # Define the standard port
HOST = 'localhost' # Define the standard host
Request = http.server.SimpleHTTPRequestHandler # Simple http request handler, it commits all files and directories within the SelfHost.py folder
SERVE = '/deploy' # Main folder to serve
TEST = '/test' # Test folder
class Pandora():
def Logo():
logo = open('etc/logo.txt', 'r')
for line in logo.readlines():
print(line, end = '')
def Ssl():
context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
context.load_cert_chain(certfile='YOUR CERT')
bindsocket = socket.socket()
bindsocket.bind('', 2099)
bindsocket.listen(5)
def GET(self): # Shitty implementation of GET request
self.sendResponse(200) # Average time response in MS
self.endHeaders()
self.wfile.write('GET REQUEST')
def POST(self): # Shitty implementation of POST request
contentLength = int(self.headers['Content Length'])
body = self.rfile.read(contentLength)
self.sendResponse(200) # Average time response in MS
self.endHeaders()
response = BytesIO()
response.write(b'POST REQUEST SENDED')
response.write(b'RECEIVED POST REQUEST ')
response.write(body)
self.wfile.write(response.getvalue())
def Server():
with socketserver.TCPServer((HOST, PORT), Request) as httpd: # ("host/ip address", desired port), call the resquests from files
print('\n\nRunning @ ',HOST,':',PORT) # Simply outputs on terminal the port that the server is operating
print('Please, open your browser.\n')
httpd.serve_forever() # Method that simply begins listening and responding to incoming requests
while socketserver == True:
listener = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
listener.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
listener.bind((HOST, PORT))
listener.listen(1)
listener.sendall(httpd)
# LOOP
Logo()
Server()

@ -1,38 +0,0 @@
#
# _ __ ,---. .-._ _,.---._ ,---.
# .-`.' ,`..--.' \ /==/ \ .-._ _,..---._ ,-.' , - `. .-.,.---. .--.' \
# /==/, - \==\-/\ \ |==|, \/ /, /==/, - \ /==/_, , - \ /==/ ` \ \==\-/\ \
# |==| _ .=. /==/-|_\ | |==|- \| ||==| _ _\==| .=. |==|-, .=., |/==/-|_\ |
# |==| , '=',\==\, - \ |==| , | -||==| .=. |==|_ : ;=: - |==| '=' /\==\, - \
# |==|- '..'/==/ - ,| |==| - _ ||==|,| | -|==| , '=' |==|- , .' /==/ - ,|
# |==|, | /==/- /\ - \|==| /\ , ||==| '=' /\==\ - ,_ /|==|_ . ,'./==/- /\ - \
# /==/ - | \==\ _.\=\.-'/==/, | |- ||==|-, _`/ '.='. - .' /==/ /\ , )==\ _.\=\.-'
# `--`---' `--` `--`./ `--``-.`.____.' `--`--'' `--`-`--`--' `--`
#
# VERSION 0.5
#
# DO NOT USE IT ON PRODUCTION
#
import http.server
import socketserver
import socket
import ssl # For future implementation with Openssl
PORT = 8080 # Define the standard port
HOST = 'localhost' # Define the standard host
Request = http.server.SimpleHTTPRequestHandler # Simple http request handler, it commits all files and directories within the SelfHost.py folder
with socketserver.TCPServer((HOST, PORT), Request) as httpd: # ("host/ip address", desired port), call the resquests from files
print("Running @ ",HOST,':',PORT) # Simply outputs on terminal the port that the server is operating
httpd.serve_forever() # Method that simply begins listening and responding to incoming requests
while socketserver == True:
listener = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
listener.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
listener.bind((HOST, PORT))
listener.listen(1)
listener.sendall(httpd)

@ -1,5 +1,5 @@
<!-- Pandora Selfhosted Web Server -->
```
_ __ ,---. .-._ _,.---._ ,---.
.-`.' ,`..--.' \ /==/ \ .-._ _,..---._ ,-.' , - `. .-.,.---. .--.' \
/==/, - \==\-/\ \ |==|, \/ /, /==/, - \ /==/_, , - \ /==/ ` \ \==\-/\ \
@ -9,16 +9,21 @@
|==|, | /==/- /\ - \|==| /\ , ||==| '=' /\==\ - ,_ /|==|_ . ,'./==/- /\ - \
/==/ - | \==\ _.\=\.-'/==/, | |- ||==|-, _`/ '.='. - .' /==/ /\ , )==\ _.\=\.-'
`--`---' `--` `--`./ `--``-.`.____.' `--`--'' `--`-`--`--' `--`
```
## Pandora Selfhosted
This project was built with Python 3 and uses basic library to handle files within the Pandora folder, it can access it through localserver and via localhost too. The example files are made with Foundation and shows a very basic usage of the funcionality, and you can use it to learn HTML and CSS without worry about setup a specific server, it's usefull specially if you're still learning.
This project started with Python 3 and have been refactored to GO! and then returned from ashes to Python again because more practicall to change the code to specific usage without the need to recompile it. It handles and serve files within the Pandora folder following any given structure.
It can be accessed through localhost and/or wi-fi.
It can handle a file transfer protocol too and you can make a little file host inside your network, to transfer files from one machine to another or even stream media now.
The new example files are made with Foundation and shows a very basic usage of the funcionality, and you can use it to learn HTML and CSS without worry about setup a specific server, it's usefull specially if you're still learning.
* [Python](https://www.python.org/)
* [Foundation](https://get.foundation/index.html)
<!-- GETTING STARTED -->
### Getting Started
To run and use Pandora, you'll need Python 3 installed on your machine and a modern browser.
### Usage
@ -29,8 +34,10 @@ To run and use Pandora, you'll need Python 3 installed on your machine and a mod
4. Run Pandora with
* Python
```
py PandoraRun.py
py Pandora.py
```
5. It will listen and serve all the folder that Pandora is located in
<!-- LICENSE -->
### License

BIN
assets/.DS_Store vendored

Binary file not shown.

BIN
assets/css/.DS_Store vendored

Binary file not shown.

BIN
assets/js/.DS_Store vendored

Binary file not shown.
Loading…
Cancel
Save