-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.py
executable file
·181 lines (160 loc) · 6.45 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
from kivy.app import App
from kivy.properties import StringProperty
from kivy.uix.screenmanager import ScreenManager, Screen, SlideTransition
import os
from kivy.config import Config
import login
from kivy.core.window import Window
from kivy.uix.popup import Popup
from kivy.uix.label import Label
from kivy.clock import Clock
from connected import Connected
from settings import Settings
from threading import Thread
from kivy.logger import Logger
Config.set('graphics', 'width', '340')
Config.set('graphics', 'height', '250')
Config.set('input', 'mouse', 'mouse,multitouch_on_demand')
Config.set('kivy','log_level','debug')
Config.set('kivy','log_enable','1')
Config.set('kivy','log_name','uncap_%y-%m-%d-_%_.txt')
Config.set('kivy','log_maxfile','100')
Logger.info('logger enabled')
#Config.set('graphics', 'borderless', '1')
class Login(Screen):
def thread_netcheck(self,dt):
self.st=Thread(target=self.netcheck)
self.st.start()
def netcheck(self):
import checks
if not checks.checkSpeed():
if not checks.checkInternet():
self.do_autologin('','')
def start_new_clock(self):
self.schedule=Clock.schedule_interval(self.thread_netcheck,3)
def kill_prev_clocks(self):
try:
self.schedule.cancel()
# self.stop_th.set()
except:
Logger.info("no previous schedule")
def do_autologin(self,usr,pwd):
popup = Popup(title='logging in...',content=Label(text='please wait'),auto_dismiss=False,size_hint=(None, None), size=(200, 100))
popup.open()
s=Thread(target=self.autoLogin,args=(usr,popup))
s.start()
def autoLogin(self,usr,popu):
creds={}
with open('cred.bin','rb') as f:
from pickle import load
creds=load(f)
if usr != '':
try:
if login.login(usr,creds[usr]).success:
popu.dismiss()
self.kill_prev_clocks()
self.start_new_clock()
if (self.manager.current=='connected' or self.manager.current=='login'):
Clock.schedule_once(self.setsize, 0)
self.manager.transition = SlideTransition(direction="left")
self.manager.current = 'connected'
self.manager.get_screen("connected").ids['username'].text = username
return
except:
Logger.error("error occured with provided user")
for username in creds.keys():
popu.content=Label(text=username)
if login.login(username,creds[username]).success:
try:
self.kill_prev_clocks()
except:
Logger.info("no prev clocks running")
popu.dismiss()
self.start_new_clock()
if (self.manager.current=='connected' or self.manager.current=='login'):
Clock.schedule_once(self.setsize, 0)
self.manager.transition = SlideTransition(direction="left")
self.manager.current = 'connected'
self.manager.get_screen("connected").ids['username'].text = username
return
else:
pass
self.ids['status'].text="autologin failed"
popu.dismiss()
def setsize(self,dt):
Window.size=(340,150)
def do_asynclogin(self,username,password):
if username == '' or password == '':
self.do_autologin(username,password)
popup = Popup(title='logging in...', content=Label(text='please wait'),auto_dismiss=False,size_hint=(None, None), size=(200, 100))
popup.open()
s=Thread(target=self.do_login,args=(username,password,popup))
s.start()
# s.join()S
def do_login(self, username, password,popu):
#self.ids['status'].color=[1,1,1,1]
self.ids['status'].text="enter username and password"
if((username or password) == ''):
self.ids['status'].text="username and password cannot be blank"
#self.ids['status'].color=[1,0,0,1]
popu.dismiss()
return
app = App.get_running_app()
stat=login.login(username,password)
popu.dismiss()
if(stat.success):
Clock.schedule_once(self.setsize, 0)
self.manager.transition = SlideTransition(direction="left")
self.manager.current = 'connected'
self.manager.get_screen("connected").ids['username'].text = self.ids['login'].text
app.config.read(app.get_application_config())
app.config.write()
else:
self.ids['status'].text=stat.reason
def settings(self):
self.manager.transition = SlideTransition(direction="up")
self.manager.current = 'settings'
self.manager.get_screen('settings').setprev_('login')
def resetForm(self):
self.ids['login'].text = ""
self.ids['password'].text = ""
def getusername(self):
return self.ids['login'].text
def exit(self):
exit()
class LoginApp(App):
Window.size = (350, 225)
username = StringProperty(None)
password = StringProperty(None)
title='unCap by Uday'
def build(self):
try:
with open('cred.bin','rb') as f:
pass
except:
try:
with open('cred.bin','wb') as f:
a={'user':'password'}
from pickle import dump
dump(a,f)
except:
Logger.warning("i don't have write access")
self.icon='res/icon.png'
manager = ScreenManager()
manager.add_widget(Login(name='login'))
manager.add_widget(Connected(name='connected'))
manager.add_widget(Settings(name='settings'))
# manager.add_widget(CredMan(name='credman'))
return manager
def get_application_config(self):
Logger.info("application config inside")
if(not self.username):
return super(LoginApp, self).get_application_config()
conf_directory = self.user_data_dir + '/' + self.username
if(not os.path.exists(conf_directory)):
os.makedirs(conf_directory)
return super(LoginApp, self).get_application_config(
'%s/config.cfg' % (conf_directory)
)
if __name__ == '__main__':
LoginApp().run()