Skip to content

Commit

Permalink
初次提交
Browse files Browse the repository at this point in the history
  • Loading branch information
kotori2 committed Oct 18, 2017
1 parent d790210 commit d4a86ca
Show file tree
Hide file tree
Showing 8 changed files with 675 additions and 0 deletions.
70 changes: 70 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#
# Copyright (C) 2017 scsz <lijun00326@gmail.com>
#
# This is free software, licensed under the GNU Affero General Public License v3.0
# See /LICENSE for more information.
#

include $(TOPDIR)/rules.mk

PKG_NAME:=luci-app-jlu-drcom
PKG_VERSION:=0.1.0
PKG_RELEASE:=0

PKG_LICENSE:=AGPLv3
PKG_LICENSE_FILES:=LICENSE
PKG_MAINTAINER:=scsz

PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)

include $(INCLUDE_DIR)/package.mk

define Package/$(PKG_NAME)
SECTION:=luci
CATEGORY:=LuCI
SUBMENU:=3. Applications
TITLE:=LuCI Support for jlu drcom
PKGARCH:=all
DEPENDS:=+python-light
endef

define Package/$(PKG_NAME)/description
LuCI Support for jlu-drcom.
endef

define Build/Prepare
$(foreach po,$(wildcard ${CURDIR}/files/luci/i18n/*.po), \
po2lmo $(po) $(PKG_BUILD_DIR)/$(patsubst %.po,%.lmo,$(notdir $(po)));)
endef

define Package/$(PKG_NAME)/conffiles
/etc/config/jlu-drcom
endef

define Build/Configure
endef

define Build/Compile
endef

define Package/$(PKG_NAME)/postinst
#!/bin/sh
chmod 755 /etc/init.d/drcom
exit 0
endef

define Package/$(PKG_NAME)/install
$(INSTALL_DIR) $(1)/usr/lib/lua/luci/controller
$(INSTALL_DATA) ./files/luci/controller/jlu-drcom.lua $(1)/usr/lib/lua/luci/controller/
$(INSTALL_DIR) $(1)/usr/lib/lua/luci/i18n
$(INSTALL_DATA) $(PKG_BUILD_DIR)/jlu-drcom.*.lmo $(1)/usr/lib/lua/luci/i18n/
$(INSTALL_DIR) $(1)/usr/lib/lua/luci/model/cbi
$(INSTALL_DATA) ./files/luci/model/cbi/jlu-drcom.lua $(1)/usr/lib/lua/luci/model/cbi/
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_DATA) ./files/root/etc/init.d/drcom $(1)/etc/init.d/
$(INSTALL_DIR) $(1)/lib/jlu-drcom
$(INSTALL_DATA) ./files/root/lib/jlu-drcom/newclient.py $(1)/lib/jlu-drcom
$(INSTALL_DATA) ./files/root/lib/jlu-drcom/daemon.py $(1)/lib/jlu-drcom
endef

$(eval $(call BuildPackage,$(PKG_NAME)))
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# luci-app-jlu-drcom
# 简介
本软件包是基于 [jlu-drcom-client](https://github.com/drcoms/jlu-drcom-client) 开发的吉大Dr.com工具的LuCI界面。方便使用OpenWrt的同学使用。
# 编译
将该项目复制到OpenWrt源码的`package`目录下,执行
```
make V=s package/luci-app-jlu-drcom/compile
```
即可编译出软件包。你也可以从本项目的release页面下载预编译软件包。
# 依赖
本项目的依赖项为python-light,Python内需包含`subprocess socket hashlib struct`等库。
15 changes: 15 additions & 0 deletions files/luci/controller/jlu-drcom.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--
-- Copyright (C) 2017 scsz <lijun00326@gmail.com>
--
-- This is free software, licensed under the GNU Affero General Public License v3.0
-- See /LICENSE for more information.
--

module("luci.controller.jlu-drcom", package.seeall)

function index()
if not nixio.fs.access("/etc/config/jlu-drcom") then
return
end
entry({"admin","services","jlu-drcom"}, cbi("jlu-drcom"), _("Dr.com"), 60)
end
39 changes: 39 additions & 0 deletions files/luci/i18n/jlu-drcom.zh-cn.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
msgid ""
msgstr "Content-Type: text/plain; charset=UTF-8\n"

msgid "Username"
msgstr "用户名"

msgid "Password"
msgstr "密码"

msgid "Dr.com Client for JLU"
msgstr "吉林大学Dr.com认证模块"

msgid "General Setting"
msgstr "通用设置"

msgid "MAC adress"
msgstr "MAC地址"

msgid "Computer name"
msgstr "计算机名"

msgid "Operating system"
msgstr "操作系统"

msgid "IP adress"
msgstr "IP地址"

msgid "The static adress used in WAN."
msgstr "学校分配的静态IP"

msgid "Reconnect on error"
msgstr "断线重连"

msgid "Log"
msgstr "日志"

msgid "Daemon log"
msgstr "守护进程日志"

60 changes: 60 additions & 0 deletions files/luci/model/cbi/jlu-drcom.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
--
-- Copyright (C) 2017 scsz <lijun00326@gmail.com>
--
-- This is free software, licensed under the GNU Affero General Public License v3.0
-- See /LICENSE for more information.
--

local m, s ,o

m = Map("jlu-drcom", translate("Dr.com"), translate("Dr.com Client for JLU"))

s = m:section(TypedSection, "general", translate("General Setting") )
s.anonymous = true

o = s:option(Value, "mac", translate("MAC adress"))
o.datatype = "macaddr"

o = s:option(Value, "name", translate("Computer name"))
o.default = "My Computer"

o = s:option(Value, "os", translate("Operating system"))
o.default = "Windows 10"

o = s:option(Value, "ip", translate("IP adress"))
o.datatype = "ipaddr"
o.placeholder = translate("The static adress used in WAN.")

o = s:option(Value, "username", translate("Username"))

o = s:option(Value, "password", translate("Password"))
o.password = true

o = s:option(Flag, "reconnect", translate("Reconnect on error"))
o.default = 1

local apply = luci.http.formvalue("cbi.apply")
if apply then
io.popen("/etc/init.d/drcom stop")
io.popen("/etc/init.d/drcom start")
end

s = m:section(TypedSection, "general", translate("Log"))
s.anonymous = true
o = s:option(TextValue,"log")
o.readonly = true
o.rows = 30
o.cfgvalue = function()
return luci.sys.exec("tail -n 100 /tmp/drcom.log")
end

s = m:section(TypedSection, "general", translate("Daemon log"))
s.anonymous = true
o = s:option(TextValue,"daemon_log")
o.readonly = true
o.rows = 15
o.cfgvalue = function()
return luci.sys.exec("tail -n 100 /tmp/drdaemon.log")
end

return m
20 changes: 20 additions & 0 deletions files/root/etc/init.d/drcom
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/sh /etc/rc.common
#
# Copyright (C) 2017 scsz <lijun00326@gmail.com>
#
# This is free software, licensed under the GNU Affero General Public License v3.0
# See /LICENSE for more information.
#
#

START=99
STOP=99

start() {
python -u /lib/jlu-drcom/daemon.py >/tmp/drdaemon.log &
}

stop() {
kill -s 9 `pgrep -f newclient.py`
kill -s 9 `pgrep -f daemon.py`
}
33 changes: 33 additions & 0 deletions files/root/lib/jlu-drcom/daemon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#coding=utf8
#
# Copyright (C) 2017 scsz <lijun00326@gmail.com>
#
# This is free software, licensed under the GNU Affero General Public License v3.0
# See /LICENSE for more information.
#

import subprocess
import time

#load config from /etc/config/jlu-drcom
confile = open("/etc/config/jlu-drcom", "r")
conf = confile.read()
confile.close()
confs = conf.split("\n")
for i in confs:
if i.find("reconnect") > 0:
s = i.find("'")
reconnect = int(i[s+1:-1])

f = open("/tmp/drcom.log", "w")
process = subprocess.Popen(["python", "-u", "/lib/jlu-drcom/newclient.py"], stdout=f, stderr=f)
while True:
time.sleep(5)
print(time.strftime('[%Y-%m-%d %H:%M:%S]',time.localtime(time.time())) + "Process running...")
if process.poll() != None:
if reconnect:
print(time.strftime('[%Y-%m-%d %H:%M:%S]',time.localtime(time.time())) + "Restarting process...")
process = subprocess.Popen(["python", "-u", "/lib/jlu-drcom/newclient.py"], stdout=f, stderr=f)
else:
print(time.strftime('[%Y-%m-%d %H:%M:%S]',time.localtime(time.time())) + "Dr.com down! Do nothing.")
break
Loading

0 comments on commit d4a86ca

Please sign in to comment.