-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5f617d7
commit d2af79e
Showing
6 changed files
with
233 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import sys, \ | ||
os | ||
if hasattr(sys, 'frozen'): | ||
os.environ['PATH'] = sys._MEIPASS + ";" + os.environ['PATH'] | ||
|
||
from sys import argv, exit | ||
from shuClient import Ui_MainWindow | ||
from wifiConnect import wifi_connect_status | ||
from ruijie import shuConnect | ||
from PyQt5.QtWidgets import QMainWindow, QApplication | ||
from PyQt5.QtCore import QSettings, Qt, QTimer | ||
from PyQt5.QtGui import QIcon | ||
from logo_png import img as logo | ||
import base64 | ||
from linkSHUPath import shuPath | ||
|
||
|
||
linkpath = shuPath() | ||
|
||
sss = os.path.exists(linkpath + r'\logo.png') | ||
if not sss: | ||
tmp = open(linkpath + r'\logo.png', 'wb') | ||
tmp.write(base64.b64decode(logo)) | ||
tmp.close() | ||
else: | ||
pass | ||
|
||
|
||
class shuUi(QMainWindow, Ui_MainWindow): | ||
def __init__(self, parent=None): | ||
super(shuUi, self).__init__(parent) | ||
self.setupUi(self) | ||
|
||
self.setWindowTitle('linkSHU for wireless') | ||
self.setWindowIcon(QIcon(linkpath + r'\logo.png')) | ||
|
||
self.resize(391, 282) | ||
self.setFixedSize(self.width(), self.height()) | ||
self.setWindowFlags(Qt.WindowCloseButtonHint) | ||
|
||
self.input_user.setPlaceholderText("请输入用户名") | ||
self.input_passwd.setPlaceholderText("请输入密码") | ||
self.updateLabel.setText("<A href='https://github.com/Holaplace/shuClient'>关于 & 更新</a>") | ||
self.updateLabel.setOpenExternalLinks(True) | ||
|
||
self.init_login_info() | ||
self.wifiButton.clicked.connect(self.on_pushButton_enter_clicked) | ||
|
||
# 自动登录 | ||
self.timer0 = QTimer(self) | ||
self.timer0.timeout.connect(self.goto_autologin) | ||
self.timer0.setSingleShot(True) | ||
self.timer0.start(1000) | ||
|
||
# 保存登录信息 | ||
def save_login_info(self): | ||
settings = QSettings(linkpath + r"\config.ini", QSettings.IniFormat) | ||
settings.setValue("account", self.input_user.text()) | ||
settings.setValue("password", self.input_passwd.text()) | ||
settings.setValue("remeberpassword", self.passwdCB.isChecked()) | ||
settings.setValue("autologin", self.auto_login.isChecked()) | ||
|
||
# 初始化登录信息 | ||
def init_login_info(self): | ||
settings = QSettings(linkpath + r"\config.ini", QSettings.IniFormat) | ||
the_account =settings.value("account") | ||
the_password = settings.value("password") | ||
the_remeberpassword = settings.value("remeberpassword") | ||
the_autologin = settings.value("autologin") | ||
|
||
self.input_user.setText(the_account) | ||
# 记住密码判断 | ||
if the_remeberpassword == "true" or the_remeberpassword is True: | ||
self.passwdCB.setChecked(True) | ||
self.input_passwd.setText(the_password) | ||
|
||
# 自动登录判断 | ||
if the_autologin == "true" or the_autologin is True: | ||
self.auto_login.setChecked(True) | ||
|
||
# 自动登录 | ||
def goto_autologin(self): | ||
if self.auto_login.isChecked() is True: | ||
self.on_pushButton_enter_clicked() | ||
|
||
def on_pushButton_enter_clicked(self): | ||
# 账号密码NULL判断 | ||
if self.input_user.text() == "" or self.input_passwd.text() == "": | ||
return | ||
|
||
self.auto_login.stateChanged.connect(self.cancel_autologin) | ||
|
||
# 保存登录信息 | ||
self.save_login_info() | ||
self.wifiConnect() | ||
|
||
def cancel_autologin(self): | ||
if not self.auto_login.isChecked(): | ||
settings = QSettings(linkpath + r"\config.ini", QSettings.IniFormat) | ||
settings.setValue("autologin", False) | ||
|
||
def wifiConnect(self): | ||
# 账号密码NULL判断 | ||
if self.input_user.text() == "" or self.input_passwd.text() == "": | ||
return | ||
|
||
user = int(self.input_user.text()) | ||
passwd = str(self.input_passwd.text()) | ||
s = wifi_connect_status(user, passwd) | ||
self.status.setText(s) | ||
|
||
def stopConnect(self): | ||
shu = shuConnect() | ||
s = shu.logOut() | ||
self.status.setText(s) | ||
|
||
|
||
if __name__ == "__main__": | ||
app = QApplication(argv) | ||
ui = shuUi() | ||
|
||
ui.wifiButton.clicked.connect(ui.wifiConnect) | ||
ui.logout.clicked.connect(ui.stopConnect) | ||
|
||
ui.show() | ||
|
||
exit(app.exec_()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
from os import getenv, makedirs | ||
from os import path, makedirs | ||
|
||
|
||
def shuPath(): | ||
rootPath = getenv('SYSTEMROOT') | ||
rootPath = path.expanduser('~') | ||
try: | ||
makedirs(rootPath + r'\linkSHU') | ||
addrSHU = rootPath + r'\linkSHU' | ||
makedirs(rootPath + r'\linkSHUwifi') | ||
addrSHU = rootPath + r'\linkSHUwifi' | ||
except: | ||
addrSHU = rootPath + r'\linkSHU' | ||
addrSHU = rootPath + r'\linkSHUwifi' | ||
|
||
return addrSHU |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,6 @@ | |
def netHi(): | ||
s = net_if_addrs() | ||
for key in s.keys(): | ||
if '以太' in key: | ||
if 'WLAN' in key: | ||
s = key | ||
return s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from pywifi import PyWiFi, Profile, const | ||
from time import sleep | ||
from ruijie import shuConnect | ||
import psutil | ||
from netName import netHi | ||
|
||
nameHi = netHi() | ||
|
||
|
||
def wifi_connect_status(user, passwd): | ||
if not psutil.net_if_stats()[nameHi].isup: # wifi未连接到shuforall或未打开WiFi开关 | ||
try: | ||
s = connect_wifi(user, passwd) | ||
except Exception as e: | ||
s = e | ||
return s | ||
|
||
else: # wifi已连接到shuforall | ||
s0 = "Shu(ForAll) 连接成功\n" | ||
shu = shuConnect(user, passwd) | ||
s = s0 + shu.start_connect() | ||
return s | ||
|
||
|
||
def connect_wifi(user, passwd): | ||
wifi = PyWiFi() # 创建一个wifi对象 | ||
iface = wifi.interfaces()[0] # 取第一个无限网卡 | ||
iface.disconnect() # 断开网卡连接 | ||
|
||
profile = Profile() # 配置文件 | ||
profile.ssid = "Shu(ForAll)" # wifi名称 | ||
|
||
iface.remove_all_network_profiles() # 删除其他配置文件 | ||
tmp_profile = iface.add_network_profile(profile) # 加载配置文件 | ||
|
||
iface.connect(tmp_profile) # 连接 | ||
sleep(1.5) # 不延时,状态码来不及改变 | ||
|
||
if iface.status() == const.IFACE_CONNECTED: | ||
s0 = "Shu(ForAll) 连接成功\n" | ||
shu = shuConnect(user, passwd) | ||
s = s0 + shu.start_connect() | ||
|
||
else: | ||
s = "无线网卡未打开,请打开 WLAN 开关\n" | ||
|
||
return s |