ministerchief commited on
Commit
9f08deb
·
verified ·
1 Parent(s): af86a36

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +201 -185
app.py CHANGED
@@ -1,185 +1,201 @@
1
- import os
2
- import tkinter as tk
3
- from tkinter import messagebox, filedialog, scrolledtext
4
- import platform
5
- import webbrowser
6
-
7
- # ---------------- LOGIN SCREEN ---------------- #
8
-
9
- class LoginScreen:
10
- def __init__(self, root):
11
- self.root = root
12
- self.root.title("Mini OS - Login")
13
- self.root.geometry("400x300")
14
- self.root.config(bg="black")
15
-
16
- tk.Label(root, text="Mini Python OS", fg="white", bg="black",
17
- font=("Arial", 20)).pack(pady=20)
18
-
19
- tk.Label(root, text="Username", bg="black", fg="white").pack()
20
- self.username = tk.Entry(root)
21
- self.username.pack()
22
-
23
- tk.Label(root, text="Password", bg="black", fg="white").pack()
24
- self.password = tk.Entry(root, show="*")
25
- self.password.pack()
26
-
27
- tk.Button(root, text="Login", command=self.login,
28
- bg="green", fg="white").pack(pady=20)
29
-
30
- def login(self):
31
- if self.username.get() == "admin" and self.password.get() == "1234":
32
- self.root.destroy()
33
- main_os()
34
- else:
35
- messagebox.showerror("Error", "Invalid Login")
36
-
37
-
38
- # ---------------- MAIN OS ---------------- #
39
-
40
- class MiniOS:
41
- def __init__(self, root):
42
- self.root = root
43
- self.root.title("Mini Python OS")
44
- self.root.geometry("800x500")
45
- self.root.config(bg="#1e1e1e")
46
-
47
- tk.Label(root, text="Mini Python OS Desktop",
48
- bg="#1e1e1e", fg="white",
49
- font=("Arial", 18)).pack(pady=20)
50
-
51
- tk.Button(root, text="File Explorer",
52
- command=self.file_explorer,
53
- width=25, height=2).pack(pady=5)
54
-
55
- tk.Button(root, text="Notepad",
56
- command=self.notepad,
57
- width=25, height=2).pack(pady=5)
58
-
59
- tk.Button(root, text="Calculator",
60
- command=self.calculator,
61
- width=25, height=2).pack(pady=5)
62
-
63
- tk.Button(root, text="System Info",
64
- command=self.system_info,
65
- width=25, height=2).pack(pady=5)
66
-
67
- tk.Button(root, text="Open Google",
68
- command=self.open_google,
69
- width=25, height=2).pack(pady=5)
70
-
71
- tk.Button(root, text="Open ChatGPT",
72
- command=self.open_chatgpt,
73
- width=25, height=2).pack(pady=5)
74
-
75
- tk.Button(root, text="Shutdown",
76
- command=self.shutdown,
77
- width=25, height=2,
78
- bg="red", fg="white").pack(pady=20)
79
-
80
- # -------- File Explorer -------- #
81
- def file_explorer(self):
82
- path = filedialog.askdirectory()
83
- if path:
84
- files = os.listdir(path)
85
- messagebox.showinfo("Files", "\n".join(files))
86
-
87
- # -------- Notepad -------- #
88
- def notepad(self):
89
- pad = tk.Toplevel(self.root)
90
- pad.title("Notepad")
91
- pad.geometry("600x400")
92
-
93
- text_area = scrolledtext.ScrolledText(pad)
94
- text_area.pack(fill="both", expand=True)
95
-
96
- def save_file():
97
- file_path = filedialog.asksaveasfilename(defaultextension=".txt")
98
- if file_path:
99
- with open(file_path, "w") as f:
100
- f.write(text_area.get("1.0", tk.END))
101
- messagebox.showinfo("Saved", "File Saved Successfully")
102
-
103
- tk.Button(pad, text="Save", command=save_file).pack()
104
-
105
- # -------- Calculator -------- #
106
- def calculator(self):
107
- calc = tk.Toplevel(self.root)
108
- calc.title("Calculator")
109
- calc.geometry("300x400")
110
-
111
- entry = tk.Entry(calc, font=("Arial", 18))
112
- entry.pack(fill="both")
113
-
114
- def click(value):
115
- entry.insert(tk.END, value)
116
-
117
- def calculate():
118
- try:
119
- result = eval(entry.get())
120
- entry.delete(0, tk.END)
121
- entry.insert(0, result)
122
- except:
123
- messagebox.showerror("Error", "Invalid Expression")
124
-
125
- buttons = [
126
- '7','8','9','/',
127
- '4','5','6','*',
128
- '1','2','3','-',
129
- '0','.','=','+'
130
- ]
131
-
132
- frame = tk.Frame(calc)
133
- frame.pack()
134
-
135
- row = 0
136
- col = 0
137
-
138
- for button in buttons:
139
- action = calculate if button == '=' else lambda x=button: click(x)
140
- tk.Button(frame, text=button, width=5, height=2,
141
- command=action).grid(row=row, column=col)
142
- col += 1
143
- if col > 3:
144
- col = 0
145
- row += 1
146
-
147
- # -------- System Info -------- #
148
- def system_info(self):
149
- info = f"""
150
- System: {platform.system()}
151
- Node Name: {platform.node()}
152
- Release: {platform.release()}
153
- Version: {platform.version()}
154
- Machine: {platform.machine()}
155
- Processor: {platform.processor()}
156
- """
157
- messagebox.showinfo("System Info", info)
158
-
159
- # -------- Google -------- #
160
- def open_google(self):
161
- webbrowser.open("https://www.google.com")
162
-
163
- # -------- ChatGPT -------- #
164
- def open_chatgpt(self):
165
- webbrowser.open("https://chat.openai.com")
166
-
167
- # -------- Shutdown -------- #
168
- def shutdown(self):
169
- self.root.destroy()
170
-
171
-
172
- # -------- START MAIN OS -------- #
173
-
174
- def main_os():
175
- root = tk.Tk()
176
- app = MiniOS(root)
177
- root.mainloop()
178
-
179
-
180
- # -------- RUN LOGIN FIRST -------- #
181
-
182
- if __name__ == "__main__":
183
- root = tk.Tk()
184
- LoginScreen(root)
185
- root.mainloop()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, render_template_string, request, redirect, url_for, session
2
+ import os
3
+ import platform
4
+
5
+ app = Flask(__name__)
6
+ app.secret_key = "mini_os_secret_key"
7
+
8
+ # ---------------- LOGIN PAGE ---------------- #
9
+ login_page = """
10
+ <!DOCTYPE html>
11
+ <html>
12
+ <head>
13
+ <title>Mini OS Login</title>
14
+ <style>
15
+ body { background:black; color:white; text-align:center; font-family:Arial; }
16
+ .box { margin-top:100px; }
17
+ input { padding:10px; margin:5px; width:200px; }
18
+ button { padding:10px 20px; background:green; color:white; border:none; }
19
+ </style>
20
+ </head>
21
+ <body>
22
+ <div class="box">
23
+ <h1>Mini Python OS</h1>
24
+ <form method="POST">
25
+ <input name="username" placeholder="Username"><br>
26
+ <input name="password" type="password" placeholder="Password"><br>
27
+ <button type="submit">Login</button>
28
+ </form>
29
+ <p>Default: admin / 1234</p>
30
+ <p style="color:red">{{error}}</p>
31
+ </div>
32
+ </body>
33
+ </html>
34
+ """
35
+
36
+ # ---------------- DASHBOARD ---------------- #
37
+ dashboard_page = """
38
+ <!DOCTYPE html>
39
+ <html>
40
+ <head>
41
+ <title>Mini OS Desktop</title>
42
+ <style>
43
+ body { background:#1e1e1e; color:white; font-family:Arial; text-align:center; }
44
+ button { padding:15px; margin:10px; width:200px; cursor:pointer; }
45
+ .container { margin-top:50px; }
46
+ </style>
47
+ </head>
48
+ <body>
49
+ <h1>Mini Python OS Desktop</h1>
50
+ <div class="container">
51
+
52
+ <a href="/files"><button>File Explorer</button></a>
53
+ <a href="/notepad"><button>Notepad</button></a>
54
+ <a href="/calculator"><button>Calculator</button></a>
55
+ <a href="/system"><button>System Info</button></a>
56
+ <a href="https://google.com" target="_blank"><button>Open Google</button></a>
57
+ <a href="https://chat.openai.com" target="_blank"><button>Open ChatGPT</button></a>
58
+
59
+ <br><br>
60
+ <a href="/logout"><button style="background:red;color:white;">Logout</button></a>
61
+ </div>
62
+ </body>
63
+ </html>
64
+ """
65
+
66
+ # ---------------- FILE EXPLORER ---------------- #
67
+ files_page = """
68
+ <h2>File Explorer</h2>
69
+ <ul>
70
+ {% for f in files %}
71
+ <li>{{f}}</li>
72
+ {% endfor %}
73
+ </ul>
74
+ <a href="/dashboard">Back</a>
75
+ """
76
+
77
+ # ---------------- NOTEPAD ---------------- #
78
+ notepad_page = """
79
+ <h2>Notepad</h2>
80
+ <form method="POST">
81
+ <textarea name="text" rows="15" cols="50"></textarea><br>
82
+ <button type="submit">Save</button>
83
+ </form>
84
+ <p>{{msg}}</p>
85
+ <a href="/dashboard">Back</a>
86
+ """
87
+
88
+ # ---------------- CALCULATOR ---------------- #
89
+ calculator_page = """
90
+ <h2>Calculator</h2>
91
+ <form method="POST">
92
+ <input name="exp" placeholder="Enter expression"><br><br>
93
+ <button type="submit">Calculate</button>
94
+ </form>
95
+ <h3>Result: {{result}}</h3>
96
+ <a href="/dashboard">Back</a>
97
+ """
98
+
99
+ # ---------------- SYSTEM INFO ---------------- #
100
+ system_page = """
101
+ <h2>System Info</h2>
102
+ <pre>
103
+ System: {{system}}
104
+ Node: {{node}}
105
+ Release: {{release}}
106
+ Version: {{version}}
107
+ Machine: {{machine}}
108
+ Processor: {{processor}}
109
+ </pre>
110
+ <a href="/dashboard">Back</a>
111
+ """
112
+
113
+ # ---------------- ROUTES ---------------- #
114
+
115
+ @app.route("/", methods=["GET", "POST"])
116
+ def login():
117
+ error = ""
118
+ if request.method == "POST":
119
+ u = request.form["username"]
120
+ p = request.form["password"]
121
+
122
+ if u == "admin" and p == "1234":
123
+ session["user"] = u
124
+ return redirect("/dashboard")
125
+ else:
126
+ error = "Invalid Login"
127
+
128
+ return render_template_string(login_page, error=error)
129
+
130
+
131
+ @app.route("/dashboard")
132
+ def dashboard():
133
+ if "user" not in session:
134
+ return redirect("/")
135
+ return render_template_string(dashboard_page)
136
+
137
+
138
+ @app.route("/files")
139
+ def files():
140
+ if "user" not in session:
141
+ return redirect("/")
142
+ path = "."
143
+ file_list = os.listdir(path)
144
+ return render_template_string(files_page, files=file_list)
145
+
146
+
147
+ @app.route("/notepad", methods=["GET", "POST"])
148
+ def notepad():
149
+ if "user" not in session:
150
+ return redirect("/")
151
+
152
+ msg = ""
153
+ if request.method == "POST":
154
+ text = request.form["text"]
155
+ with open("note.txt", "w") as f:
156
+ f.write(text)
157
+ msg = "Saved to note.txt"
158
+
159
+ return render_template_string(notepad_page, msg=msg)
160
+
161
+
162
+ @app.route("/calculator", methods=["GET", "POST"])
163
+ def calculator():
164
+ if "user" not in session:
165
+ return redirect("/")
166
+
167
+ result = ""
168
+ if request.method == "POST":
169
+ try:
170
+ exp = request.form["exp"]
171
+ result = eval(exp)
172
+ except:
173
+ result = "Error"
174
+
175
+ return render_template_string(calculator_page, result=result)
176
+
177
+
178
+ @app.route("/system")
179
+ def system():
180
+ if "user" not in session:
181
+ return redirect("/")
182
+
183
+ return render_template_string(system_page,
184
+ system=platform.system(),
185
+ node=platform.node(),
186
+ release=platform.release(),
187
+ version=platform.version(),
188
+ machine=platform.machine(),
189
+ processor=platform.processor()
190
+ )
191
+
192
+
193
+ @app.route("/logout")
194
+ def logout():
195
+ session.clear()
196
+ return redirect("/")
197
+
198
+
199
+ # ---------------- RUN APP ---------------- #
200
+ if __name__ == "__main__":
201
+ app.run(host="0.0.0.0", port=7860)