rkihacker commited on
Commit
32441c9
·
verified ·
1 Parent(s): 707c922

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +51 -50
main.py CHANGED
@@ -8,8 +8,9 @@ from fastapi import FastAPI, Form, Request
8
  from fastapi.responses import HTMLResponse
9
 
10
  # --- UI Template (HTML, CSS, JS) ---
11
- # A modern, responsive, dark-mode UI embedded directly in the Python file.
12
- # It includes a simple JavaScript for a loading state.
 
13
 
14
  HTML_TEMPLATE = """
15
  <!DOCTYPE html>
@@ -19,7 +20,7 @@ HTML_TEMPLATE = """
19
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
20
  <title>FastAPI Port Scanner</title>
21
  <style>
22
- :root {
23
  --bg-color: #1a1a1a;
24
  --surface-color: #2c2c2c;
25
  --primary-color: #00aaff;
@@ -28,8 +29,8 @@ HTML_TEMPLATE = """
28
  --text-muted-color: #a0a0a0;
29
  --success-color: #4CAF50;
30
  --border-color: #444;
31
- }
32
- body {
33
  font-family: 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
34
  background-color: var(--bg-color);
35
  color: var(--text-color);
@@ -39,8 +40,8 @@ HTML_TEMPLATE = """
39
  justify-content: center;
40
  align-items: center;
41
  min-height: 100vh;
42
- }
43
- .container {
44
  background-color: var(--surface-color);
45
  padding: 2.5rem;
46
  border-radius: 12px;
@@ -48,27 +49,27 @@ HTML_TEMPLATE = """
48
  width: 100%;
49
  max-width: 650px;
50
  border: 1px solid var(--border-color);
51
- }
52
- h1, h2 {
53
  color: var(--primary-color);
54
  text-align: center;
55
  margin-top: 0;
56
- }
57
- form {
58
  display: flex;
59
  flex-direction: column;
60
  gap: 1.2rem;
61
- }
62
- .form-group {
63
  display: flex;
64
  flex-direction: column;
65
- }
66
- label {
67
  font-weight: bold;
68
  margin-bottom: 0.5rem;
69
  font-size: 0.9rem;
70
- }
71
- input {
72
  padding: 0.8rem 1rem;
73
  border-radius: 6px;
74
  border: 1px solid var(--border-color);
@@ -76,13 +77,13 @@ HTML_TEMPLATE = """
76
  color: var(--text-color);
77
  font-size: 1rem;
78
  transition: border-color 0.3s, box-shadow 0.3s;
79
- }
80
- input:focus {
81
  outline: none;
82
  border-color: var(--primary-color);
83
  box-shadow: 0 0 0 3px rgba(0, 170, 255, 0.2);
84
- }
85
- button {
86
  padding: 1rem;
87
  border-radius: 6px;
88
  border: none;
@@ -93,11 +94,11 @@ HTML_TEMPLATE = """
93
  cursor: pointer;
94
  transition: background-color 0.3s;
95
  margin-top: 1rem;
96
- }
97
- button:hover {
98
  background-color: var(--primary-hover-color);
99
- }
100
- .disclaimer {
101
  font-size: 0.8rem;
102
  color: #ffeb3b;
103
  text-align: center;
@@ -105,13 +106,13 @@ HTML_TEMPLATE = """
105
  border: 1px dashed #ffeb3b;
106
  padding: 0.5rem;
107
  border-radius: 4px;
108
- }
109
- .loader {
110
  text-align: center;
111
  padding: 3rem 0;
112
  display: none; /* Hidden by default */
113
- }
114
- .spinner {
115
  border: 8px solid var(--border-color);
116
  border-top: 8px solid var(--primary-color);
117
  border-radius: 50%;
@@ -119,42 +120,42 @@ HTML_TEMPLATE = """
119
  height: 60px;
120
  animation: spin 1s linear infinite;
121
  margin: 0 auto 1rem;
122
- }
123
- @keyframes spin {
124
- 0% { transform: rotate(0deg); }
125
- 100% { transform: rotate(360deg); }
126
- }
127
- .results-table {
128
  width: 100%;
129
  border-collapse: collapse;
130
  margin-top: 1.5rem;
131
- }
132
- .results-table th, .results-table td {
133
  padding: 0.8rem;
134
  text-align: left;
135
  border-bottom: 1px solid var(--border-color);
136
- }
137
- .results-table th {
138
  color: var(--primary-color);
139
- }
140
- .open-port {
141
  color: var(--success-color);
142
  font-weight: bold;
143
- }
144
- .scan-summary p {
145
  font-size: 1.1em;
146
  background: #252525;
147
  padding: 0.8em;
148
  border-radius: 6px;
149
- }
150
- a {
151
  color: var(--primary-color);
152
  text-decoration: none;
153
  display: inline-block;
154
  margin-top: 1.5rem;
155
  text-align: center;
156
  width: 100%;
157
- }
158
  </style>
159
  </head>
160
  <body>
@@ -164,14 +165,14 @@ HTML_TEMPLATE = """
164
  </div>
165
 
166
  <script>
167
- function showLoader() {
168
  const formContainer = document.getElementById('form-container');
169
  const loader = document.getElementById('loader');
170
- if (formContainer && loader) {
171
  formContainer.style.display = 'none';
172
  loader.style.display = 'block';
173
- }
174
- }
175
  </script>
176
  </body>
177
  </html>
 
8
  from fastapi.responses import HTMLResponse
9
 
10
  # --- UI Template (HTML, CSS, JS) ---
11
+ # NOTE: All curly braces for CSS and JS are doubled (e.g., {{ ... }})
12
+ # to escape them from Python's .format() method. The only single-brace
13
+ # placeholder is {content}.
14
 
15
  HTML_TEMPLATE = """
16
  <!DOCTYPE html>
 
20
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
21
  <title>FastAPI Port Scanner</title>
22
  <style>
23
+ :root {{
24
  --bg-color: #1a1a1a;
25
  --surface-color: #2c2c2c;
26
  --primary-color: #00aaff;
 
29
  --text-muted-color: #a0a0a0;
30
  --success-color: #4CAF50;
31
  --border-color: #444;
32
+ }}
33
+ body {{
34
  font-family: 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
35
  background-color: var(--bg-color);
36
  color: var(--text-color);
 
40
  justify-content: center;
41
  align-items: center;
42
  min-height: 100vh;
43
+ }}
44
+ .container {{
45
  background-color: var(--surface-color);
46
  padding: 2.5rem;
47
  border-radius: 12px;
 
49
  width: 100%;
50
  max-width: 650px;
51
  border: 1px solid var(--border-color);
52
+ }}
53
+ h1, h2 {{
54
  color: var(--primary-color);
55
  text-align: center;
56
  margin-top: 0;
57
+ }}
58
+ form {{
59
  display: flex;
60
  flex-direction: column;
61
  gap: 1.2rem;
62
+ }}
63
+ .form-group {{
64
  display: flex;
65
  flex-direction: column;
66
+ }}
67
+ label {{
68
  font-weight: bold;
69
  margin-bottom: 0.5rem;
70
  font-size: 0.9rem;
71
+ }}
72
+ input {{
73
  padding: 0.8rem 1rem;
74
  border-radius: 6px;
75
  border: 1px solid var(--border-color);
 
77
  color: var(--text-color);
78
  font-size: 1rem;
79
  transition: border-color 0.3s, box-shadow 0.3s;
80
+ }}
81
+ input:focus {{
82
  outline: none;
83
  border-color: var(--primary-color);
84
  box-shadow: 0 0 0 3px rgba(0, 170, 255, 0.2);
85
+ }}
86
+ button {{
87
  padding: 1rem;
88
  border-radius: 6px;
89
  border: none;
 
94
  cursor: pointer;
95
  transition: background-color 0.3s;
96
  margin-top: 1rem;
97
+ }}
98
+ button:hover {{
99
  background-color: var(--primary-hover-color);
100
+ }}
101
+ .disclaimer {{
102
  font-size: 0.8rem;
103
  color: #ffeb3b;
104
  text-align: center;
 
106
  border: 1px dashed #ffeb3b;
107
  padding: 0.5rem;
108
  border-radius: 4px;
109
+ }}
110
+ .loader {{
111
  text-align: center;
112
  padding: 3rem 0;
113
  display: none; /* Hidden by default */
114
+ }}
115
+ .spinner {{
116
  border: 8px solid var(--border-color);
117
  border-top: 8px solid var(--primary-color);
118
  border-radius: 50%;
 
120
  height: 60px;
121
  animation: spin 1s linear infinite;
122
  margin: 0 auto 1rem;
123
+ }}
124
+ @keyframes spin {{
125
+ 0% {{ transform: rotate(0deg); }}
126
+ 100% {{ transform: rotate(360deg); }}
127
+ }}
128
+ .results-table {{
129
  width: 100%;
130
  border-collapse: collapse;
131
  margin-top: 1.5rem;
132
+ }}
133
+ .results-table th, .results-table td {{
134
  padding: 0.8rem;
135
  text-align: left;
136
  border-bottom: 1px solid var(--border-color);
137
+ }}
138
+ .results-table th {{
139
  color: var(--primary-color);
140
+ }}
141
+ .open-port {{
142
  color: var(--success-color);
143
  font-weight: bold;
144
+ }}
145
+ .scan-summary p {{
146
  font-size: 1.1em;
147
  background: #252525;
148
  padding: 0.8em;
149
  border-radius: 6px;
150
+ }}
151
+ a {{
152
  color: var(--primary-color);
153
  text-decoration: none;
154
  display: inline-block;
155
  margin-top: 1.5rem;
156
  text-align: center;
157
  width: 100%;
158
+ }}
159
  </style>
160
  </head>
161
  <body>
 
165
  </div>
166
 
167
  <script>
168
+ function showLoader() {{
169
  const formContainer = document.getElementById('form-container');
170
  const loader = document.getElementById('loader');
171
+ if (formContainer && loader) {{
172
  formContainer.style.display = 'none';
173
  loader.style.display = 'block';
174
+ }}
175
+ }}
176
  </script>
177
  </body>
178
  </html>