This commit is contained in:
zortazert 2022-04-03 13:10:22 -05:00
commit b2504187c6
4 changed files with 64 additions and 16 deletions

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
port.json port.json
config.json
*.pyc *.pyc

View file

@ -23,7 +23,7 @@ The software is built on Python. So you will need to have python3 installed. The
`python3 server.py` `python3 server.py`
It will prompt you to select a `PORT` to which on your end to bind the server. For now it binds it to your localhost. You can edit that part. We are using a standard SimpleHTTPServer python module for it. On first run, you will be prompted to edit the newly created `config.json`. You should set the URL to be the URL in which you are hosting **Free Competitors** (ex. `http://5wxkwfl6n4abwjsqv5r6roebwbc7fnc22dq3clpooojzdmdnzzo3amad.onion/`). If you do not wish to set a URL, you should set it to `/`. Then, you should specify the port to serve on, and the CSS to use.
Please tell us if you start an instance. We want to add it's link here. Please tell us if you start an instance. We want to add it's link here.

View file

@ -145,16 +145,19 @@ def suggestions(page, json):
page = page + "</details>" page = page + "</details>"
return page return page
def search_widget(page): def search_widget(page, address):
# Adds a search bar to the page # Adds a search bar to the page
page = page + """ page = page + """
<form action="/search" method="GET"> <form action="""
page = page + address
page = page + """search method="GET">
<input type="text" name="item" class="search" placeholder="Name of Software"> <input type="text" name="item" class="search" placeholder="Name of Software">
<button type="submit">Search</button> <button type="submit">Search</button>
</form> </form>
""" """
#page = page.format(ADDRESS)
return page return page

View file

@ -1,3 +1,5 @@
#!/usr/bin/python3
# THIS SOFTWARE IS A PART OF FREE COMPETITOR PROJECT # THIS SOFTWARE IS A PART OF FREE COMPETITOR PROJECT
# THE FOLLOWING SOURCE CODE I UNDER THE GNU # THE FOLLOWING SOURCE CODE I UNDER THE GNU
# AGPL LICENSE V3 OR ANY LATER VERSION. # AGPL LICENSE V3 OR ANY LATER VERSION.
@ -15,18 +17,59 @@ import os
from modules import search from modules import search
from modules import render from modules import render
CSS = "https://zortazert.codeberg.page/style/styles.css" # Author: https://www.delftstack.com/howto/python/python-print-colored-text/
class bcolors:
OK = '\033[92m' #GREEN
WARNING = '\033[93m' #YELLOW
FAIL = '\033[91m' #RED
RESET = '\033[0m' #RESET COLOR
try: print("""╔═╗┬─┐┌─┐┌─┐╔═╗┌─┐┌┬┐┌─┐┌─┐┌┬┐┬┌┬┐┌─┐┬─┐┌─┐
with open("port.json","r") as f:
json_stuff = json.load(f)
PORT = json_stuff["port"]
except: Copyright (C) 2022 Jeison Yehuda Amihud
PORT = input("Port: ")
try: This program is free software: you can redistribute it and/or modify
PORT = int(PORT) it under the terms of the GNU Affero General Public License as published by
except: the Free Software Foundation, either version 3 of the License, or
print("Port should be a number") (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
""")
print("Loading config...")
if os.path.exists("config.json"):
with open("config.json","r") as f:
srvConfig = json.load(f)
ADDRESS = srvConfig["address"]
PORT = srvConfig["port"]
CSS = srvConfig["css"]
print(bcolors.OK + "Loaded Configuration: " + bcolors.RESET)
print("Address: "+ ADDRESS)
print("Port: "+ str(PORT)) # Do not think people are smart at syntax
print("CSS: "+ CSS)
try:
PORT = int(PORT)
except:
print(bcolors.FAIL + "ERR: Port should be a number" + bcolors.RESET)
exit()
else:
newConfig = open("config.json", "w")
newConfig.write("""{
"INFO" : "You would be better off setting address to the full URL of the FreeCompetitors instance.",
"address" : "/",
"port" : 8080,
"css" : "https://zortazert.codeberg.page/style/styles.css"
}""")
newConfig.close
print(bcolors.WARNING + "Please edit the configuration file \"config.json\"." + bcolors.RESET)
exit() exit()
# Who fucking made this http.server so I need to use classes? # Who fucking made this http.server so I need to use classes?
@ -73,7 +116,7 @@ class handler(BaseHTTPRequestHandler):
# If the user is at the front page, let him get only the search bar # If the user is at the front page, let him get only the search bar
page = "<center><br><br><br><h1>Free Competitors</h1>" page = "<center><br><br><br><h1>Free Competitors</h1>"
page = render.search_widget(page) page = render.search_widget(page, ADDRESS)
page = page + "<p>Please search for any software to which you would like to find a Free Software replacement.</p></center>" page = page + "<p>Please search for any software to which you would like to find a Free Software replacement.</p></center>"
page = render.source_code_link(page) page = render.source_code_link(page)
self.send(page) self.send(page)
@ -95,7 +138,7 @@ class handler(BaseHTTPRequestHandler):
software_data, match = search.search_app(software) software_data, match = search.search_app(software)
page = render.search_widget("") page = render.search_widget("", ADDRESS)
page = page +"Search match: "+ str(int(match*100))+"%" page = page +"Search match: "+ str(int(match*100))+"%"
# Let's add the found software to the page # Let's add the found software to the page
page = render.html(page, software_data) page = render.html(page, software_data)
@ -105,4 +148,5 @@ class handler(BaseHTTPRequestHandler):
self.send(page) self.send(page)
serve = HTTPServer(("", PORT), handler) serve = HTTPServer(("", PORT), handler)
print(bcolors.OK + "⚡Now serving on port "+ str(PORT) +" at "+ ADDRESS +"." + bcolors.RESET)
serve.serve_forever() serve.serve_forever()