Skip to content

Commit

Permalink
dockerized the application
Browse files Browse the repository at this point in the history
  • Loading branch information
Gokul committed Apr 6, 2023
1 parent 451d38f commit b8650aa
Show file tree
Hide file tree
Showing 25 changed files with 146 additions and 43 deletions.
23 changes: 23 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM python:3.9-slim-buster

WORKDIR /app

COPY requirements.txt .

COPY .gf /root/.gf

RUN apt-get update -y && apt-get install -y --no-install-recommends gcc libcurl4-openssl-dev libc6-dev libssl-dev dnsutils && rm -rf /var/lib/apt/lists/*

RUN pip install --upgrade pip

RUN pip install -r requirements.txt

COPY app.py .

COPY . .

ENV PYTHONWARNINGS=ignore

RUN chmod -R 777 .

CMD ["python3", "app.py"]
16 changes: 16 additions & 0 deletions Dockerfile.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM python:3.9

WORKDIR /app

COPY . /app

RUN apt-get update && apt-get install -y libcurl4-openssl-dev

RUN pip install --upgrade pip

RUN pip install --no-cache-dir -r requirements.txt

EXPOSE 5000

CMD ["python", "app.py"]

47 changes: 14 additions & 33 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@

app = Flask(__name__)

conn = psycopg2.connect(
host="db",
database="test_db",
user="test_user",
password="test_password"
)

cur = conn.cursor()

#########################################################################

@app.route("/")
Expand All @@ -21,17 +30,10 @@ def home():
def adder():
if request.method == "POST":
url = request.form.get('url')
DATABASE_URL = os.environ['DATABASE_URL']

conn = psycopg2.connect(DATABASE_URL, sslmode='require')
cur = conn.cursor()

cur.execute(f"insert into queue (target) values ('{url}')")
conn.commit()

cur.close()
conn.close()

return render_template("index.html", info="Added to queue !")

#########################################################################
Expand Down Expand Up @@ -369,9 +371,6 @@ def check_queue():
res = ''
res = res + q1

DATABASE_URL = os.environ['DATABASE_URL']
conn = psycopg2.connect(DATABASE_URL, sslmode='require')
cur = conn.cursor()
cur.execute("select * from queue")
t = cur.fetchall()

Expand All @@ -387,8 +386,6 @@ def check_queue():

res = res + q2
conn.commit()
cur.close()
conn.close()

return res

Expand Down Expand Up @@ -724,9 +721,6 @@ def scanned():
res = ''
res = res + s1

DATABASE_URL = os.environ['DATABASE_URL']
conn = psycopg2.connect(DATABASE_URL, sslmode='require')
cur = conn.cursor()
cur.execute("select domain from output")
t = cur.fetchall()

Expand All @@ -742,8 +736,6 @@ def scanned():

res = res + s2
conn.commit()
cur.close()
conn.close()
return res

#########################################################################
Expand All @@ -755,13 +747,9 @@ def delete_item():
key = list(dic.keys())
id = key[0]

DATABASE_URL = os.environ['DATABASE_URL']
conn = psycopg2.connect(DATABASE_URL, sslmode='require')
cur = conn.cursor()
cur.execute("delete from queue where id={}".format(id))
conn.commit()
cur.close()
conn.close()

return redirect(url_for("check_queue"))

#########################################################################
Expand All @@ -781,9 +769,6 @@ def about():
@app.route("/output/<url>")
def output(url):
url = url
DATABASE_URL = os.environ['DATABASE_URL']
conn = psycopg2.connect(DATABASE_URL, sslmode='require')
cur = conn.cursor()

cur.execute(f"select result from output where domain = '{url}'")
t = cur.fetchall()
Expand All @@ -797,8 +782,7 @@ def output(url):
f.close()

conn.commit()
cur.close()
conn.close()

return send_file("/app/results/{}-output.txt".format(url))

#########################################################################
Expand All @@ -822,9 +806,6 @@ def results():
@app.route("/gau/<url>")
def gau_urls(url):
url = url
DATABASE_URL = os.environ['DATABASE_URL']
conn = psycopg2.connect(DATABASE_URL, sslmode='require')
cur = conn.cursor()

cur.execute(f"select gau from output where domain = '{url}'")
t = cur.fetchall()
Expand All @@ -838,11 +819,11 @@ def gau_urls(url):
f.close()

conn.commit()
cur.close()
conn.close()

return send_file("/app/results/{}-gau.txt".format(url))

#########################################################################

if __name__ == "__main__":
app.run(port=8000)
app.run(host='0.0.0.0', port=5000)

8 changes: 6 additions & 2 deletions cron.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
import psycopg2
import base64

DATABASE_URL = os.environ['DATABASE_URL']
conn = psycopg2.connect(
host="db",
database="test_db",
user="test_user",
password="test_password"
)

conn = psycopg2.connect(DATABASE_URL, sslmode='require')
cur = conn.cursor()

#checks the db queue table every 60 secs
Expand Down
29 changes: 29 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
version: '3'

services:
db:
image: postgres
container_name: reconator-db
environment:
POSTGRES_USER: test_user
POSTGRES_PASSWORD: test_password
POSTGRES_DB: test_db
volumes:
- db-data:/var/lib/postgresql/data
ports:
- "5432:5432"

app:
build: .
container_name: reconator-app
environment:
CHAT_ID: 1214546863
API_KEY: 6247297064:AAFlsbd24qvsVBJXwwoBwbf562F6ty8ml-M
ports:
- "5000:5000"
depends_on:
- db

volumes:
db-data:

29 changes: 29 additions & 0 deletions docker-compose.yml.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
version: '3'

services:
db:
image: postgres
restart: always
environment:
POSTGRES_USER: myuser
POSTGRES_PASSWORD: mypassword
POSTGRES_DB: mydb
volumes:
- db-data:/var/lib/postgresql/data
- ./pg_hba.conf:/var/lib/postgresql/data/pg_hba.conf
ports:
- 5432:5432

app:
build: .
ports:
- 5000:5000
environment:
CHAT_ID: 1214546863
API_KEY: 6247297064:AAFlsbd24qvsVBJXwwoBwbf562F6ty8ml-M
depends_on:
- db

volumes:
db-data:

9 changes: 7 additions & 2 deletions initialise.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@

CHAT_ID = os.environ['CHAT_ID']
API_KEY = os.environ['API_KEY']
DATABASE_URL = os.environ['DATABASE_URL']

bot = telebot.TeleBot(API_KEY)

conn = psycopg2.connect(DATABASE_URL, sslmode='require')
conn = psycopg2.connect(
host="db",
database="test_db",
user="test_user",
password="test_password"
)

cur = conn.cursor()

# to save the result of recon on target
Expand Down
9 changes: 7 additions & 2 deletions insert.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,20 @@
last = False

url = sys.argv[1]
DATABASE_URL = os.environ['DATABASE_URL']

try:
temp = sys.argv[2]
last = True
except:
pass

conn = psycopg2.connect(DATABASE_URL, sslmode='require')
conn = psycopg2.connect(
host="db",
database="test_db",
user="test_user",
password="test_password"
)

cur = conn.cursor()

#checking if any previous entry in the database to avoid duplicates
Expand Down
Loading

0 comments on commit b8650aa

Please sign in to comment.