Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
amluckydave authored Sep 7, 2019
1 parent 5f617d7 commit d2af79e
Show file tree
Hide file tree
Showing 6 changed files with 233 additions and 51 deletions.
129 changes: 129 additions & 0 deletions linkSHU(wifi).py
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_())
10 changes: 5 additions & 5 deletions linkSHUPath.py
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
2 changes: 1 addition & 1 deletion netName.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
70 changes: 35 additions & 35 deletions ruijie.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class shuConnect:
def __init__(self, user=0, passwd='shu'):
self.user = user
self.passwd = passwd
self.ssid = 'Shu(ForAll)'

def check_connect(self):
r = get("http://10.10.9.9:8080")
Expand All @@ -22,25 +21,29 @@ def check_connect(self):
return False

def catch_data(self):
r = get("http://123.123.123.123/")
query_string = r.text
st = query_string.find("index.jsp?") + 10
end = query_string.find("'</script>")
query_string = query_string[st:end]

data = {"userId": self.user,
"password": self.passwd,
"passwordEncrypt": "false",
"queryString": query_string,
"service": "",
"operatorPwd": "",
"operatorUserId": "",
"validcode": ""}

with open(linkpath + r'\catch_data.json', 'w') as data_file:
dump(data, data_file)

return data
try:
r = get("http://123.123.123.123/")
query_string = r.text
st = query_string.find("index.jsp?") + 10
end = query_string.find("'</script>")
query_string = query_string[st:end]

data = {"userId": self.user,
"password": self.passwd,
"passwordEncrypt": "false",
"queryString": query_string,
"service": "",
"operatorPwd": "",
"operatorUserId": "",
"validcode": ""}

with open(linkpath + r'\catch_data.json', 'w') as data_file:
dump(data, data_file)

return data
except:
s = '频繁登录下线操作,可能该无线网卡MAC地址已被锐捷封禁. \n\n 补救方法:点击下方“关于&更新”'
return s

def connect(self):
r = post("http://10.10.9.9:8080/eportal/InterFace.do?method=login", data=self.catch_data())
Expand All @@ -55,25 +58,22 @@ def connect(self):
def start_connect(self):
t = strftime("%Y-%m-%d %H:%M:%S")

try:
status = self.check_connect()
if status:
s = '已认证 & 用户已在线 \n' +t
status = self.check_connect()
if status:
s = '已认证 & 用户已在线 \n' +t

else:
r, msg = self.connect()
if r:
s = '认证成功 & 用户上线\n' + t
else:
r, msg = self.connect()
if r:
s = '认证成功 & 用户上线\n' + t

else:
s = '认证失败\n' + t + msg
else:
s = '认证失败\n' + t + msg

return s
except:
return
return s

def logOut(self):
t = strftime("%Y-%m-%d %H:%M:%S")
t = strftime("%H:%M:%S")
try:
with open(linkpath + r'\catch_data.json', 'r') as data_file:
logoutData = load(data_file)
Expand All @@ -85,5 +85,5 @@ def logOut(self):
s = resp["message"] + '\n' + t
return s
except IOError:
s = '提示:首次使用,打开浏览器,地址栏转到 \nhttp://10.10.9.9:8080 \n进行网络下线'
s = '提示:首次使用,请打开浏览器转到 http://10.10.9.9:8080 网络认证下线后,再使用客户端登录'
return s
26 changes: 16 additions & 10 deletions shuClient.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- coding: utf-8 -*-
import sys, os

import sys, \
os
if hasattr(sys, 'frozen'):
os.environ['PATH'] = sys._MEIPASS + ";" + os.environ['PATH']

Expand All @@ -13,10 +15,13 @@

linkpath = shuPath()


tmp = open(linkpath + r'\timg.png', 'wb')
tmp.write(base64.b64decode(timg))
tmp.close()
sss = os.path.exists(linkpath + r'\timg.png')
if not sss:
tmp = open(linkpath + r'\timg.png', 'wb')
tmp.write(base64.b64decode(timg))
tmp.close()
else:
pass


class Ui_MainWindow(object):
Expand Down Expand Up @@ -101,12 +106,12 @@ def setupUi(self, MainWindow):
self.horizontalLayout_2 = QHBoxLayout(self.horizontalLayoutWidget_3)
self.horizontalLayout_2.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.wireButton = QPushButton(self.horizontalLayoutWidget_3)
self.wifiButton = QPushButton(self.horizontalLayoutWidget_3)
font = QFont()
font.setFamily("微软雅黑")
self.wireButton.setFont(font)
self.wireButton.setObjectName("wireButton")
self.horizontalLayout_2.addWidget(self.wireButton)
self.wifiButton.setFont(font)
self.wifiButton.setObjectName("wifiButton")
self.horizontalLayout_2.addWidget(self.wifiButton)
self.groupBox_2 = QGroupBox(self.centralwidget)
self.groupBox_2.setGeometry(QRect(240, 70, 141, 171))
self.groupBox_2.setTitle("")
Expand Down Expand Up @@ -198,8 +203,9 @@ def retranslateUi(self, MainWindow):
self.passwd.setText(_translate("MainWindow", "密 码"))
self.passwdCB.setText(_translate("MainWindow", "记住密码"))
self.auto_login.setText(_translate("MainWindow", "自动登录"))
self.wireButton.setText(_translate("MainWindow", "有线连接"))
self.wifiButton.setText(_translate("MainWindow", "WIFI连接"))
self.status_lable.setText(_translate("MainWindow", "连接状态"))
self.logout.setText(_translate("MainWindow", "下线"))
self.updateLabel.setText(_translate("MainWindow", "关于 & 更新"))
self.text.setText(_translate("MainWindow", "校 园 网"))

47 changes: 47 additions & 0 deletions wifiConnect.py
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

0 comments on commit d2af79e

Please sign in to comment.