起因

北京清元优软科技有限公司在 05 年开发的 URP 综合教务管理系统在很多高校都有使用,悲剧的是,除去教务管理人员,在普通学生和老师的眼里,落下的几乎都是”坏名声”!几乎每个学期开始和结束都会听到诸如“为毛手机查不了成绩”,“为啥打印没反应啊”,“成绩分析单咋没图了”等等的吐槽。

分析

通过对 html 代码的分析,早期的前端设计和技术方案适应不了浏览器的高速发展是主因,因为没有服务器的管理权,直接修改源代码是不可行的,也不想利用系统漏洞,所以在思考、实验、排除了 n 种方案之后,使用 nginx 做反向代理 配合 substitute 组件调整代码是相对来说较为容易且可行的解决方案,主要解决三个问题,高速浏览器下超链接不跳转以及无法打印还有无法批量填充成绩。

方案

以河北工业大学的为例,教务系统源站为 http://zhjw.hebut.edu.cn (暂称为 A ),我使用的反向代理站为 http://zhjw.scse.hebut.edu.cn (暂称为 B ),反向代理规则中指定了 .php 文件为 B 站本地解析,/assets 资源为 B 站本地资源,其他均为代理 A 站。对应的 nginx 配置文件如下

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
server {
server_name zhjw.scse.hebut.edu.cn littledog.cn zhjw.hebut.edu.cn;
listen 80;

#开启页面压缩
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
#gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-JavaScript text/css application/xml text/javascript;
gzip_vary off;
gzip_disable "MSIE [1-6]\.";

#反向代理的默认设定
location / {
index index.php index.html index.htm;
root /data/www/zhjw.scse.hebut.edu.cn/htdocs;

#反向代理设置
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

include fastcgi_params;
proxy_pass http://zhjw.hebut.edu.cn/;

#指定替换类型
subs_filter_types text/html text/css text/xml;

#登录后起始页设定为本站 start.php
subs_filter '<frame src="" id="mainF"' '<frame src="/start.php" id="mainF"' gi;

#指定使用高速浏览模式,但貌似对360浏览器无效,360浏览器对于教育网网站总是启用兼容模式
subs_filter '<head>' '<head><meta name="renderer" content="webkit"><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">' gi;

#一些需要修改内容的页面装载 jquery,jqprint,printArea
subs_filter '<link href="css/style.css" rel="stylesheet" type="text/css">' '<link href="css/style.css" rel="stylesheet" type="text/css"><script src="/assets/js/jquery-1.8.2.min.js"></script><script src="/assets/js/jquery.PrintArea.js"></script><script src="/assets/js/jquery.jqprint.js"></script>' gi;

subs_filter '<link rel="stylesheet" type="text/css" href="styles.css">' '<link rel="stylesheet" type="text/css" href="styles.css"><script src="/assets/js/jquery-1.8.2.min.js"></script><script src="/assets/js/jquery.PrintArea.js"></script><script src="/assets/js/jquery.jqprint.js"></script>' gi;

subs_filter '<link href="/css/newcss/project.css" rel="stylesheet" type="text/css">' '<link href="/css/newcss/project.css" rel="stylesheet" type="text/css"><script src="/assets/js/jquery-1.8.2.min.js"></script><script src="/assets/js/jquery.PrintArea.js"></script><script src="/assets/js/jquery.jqprint.js"></script>' gi;

subs_filter '<link href="/css/style.css" rel="stylesheet" type="text/css">' '<link href="/css/style.css" rel="stylesheet" type="text/css"><script src="/assets/js/jquery-1.8.2.min.js"></script><script src="/assets/js/jquery.PrintArea.js"></script><script src="/assets/js/jquery.jqprint.js"></script>' gi;

#学生中文成绩单打印页面添加高速打印功能
subs_filter '<form action="cj_zwcjd_all.jsp" method="post">' '<script>function webprint(){jQuery("table:first table:first").css("display","none");window.print();jQuery("table:first table:first").css("display","block");};jQuery(document).ready(function(){jQuery("table,tr,td").attr("align","center");jQuery("#report1 tr:first").css("height","50px");jQuery("#report1").css("width","720").css("margin-top","60").attr("cellpadding","5px");jQuery("table:first table:first a:last").after(" >> <a href=# onclick=webprint();return;>&#39640;&#36895;&#27983;&#35272;&#22120;&#25171;&#21360;<\/a>");jQuery("div:contains(\"- - -\")").remove();});</script><form action="cj_zwcjd_all.jsp" method="post">' gi;

#教学记录表页面添加高速打印功能并设定打印效果
subs_filter '//new jw080724hnn' 'function webprint(){jQuery("form").css("display","none");jQuery("table:eq(5)").css("display","none");window.print();/*jQuery("table:eq(4)").jqprint();*/jQuery("form").css("display","inline");jQuery("table:eq(5)").css("display","block");}jQuery(document).ready(function(){jQuery("#report1").css("width","1000");jQuery("form table:eq(1)").attr("width","1000").attr("align","center");/*jQuery("select:first").attr("onchange","cx();");*/jQuery("select:first").after("<button onclick=cx();>&#26597;&#35810;</button>");jQuery("form").css("display","inline");jQuery("table:eq(3)").remove();jQuery(".report1_6_1").text("");jQuery("tr[height=20]:lt(2)").remove();jQuery("table:eq(5) a:last").after(" >> <a href=# onclick=webprint();return;>&#39640;&#36895;&#27983;&#35272;&#22120;&#25171;&#21360;<\/a>");jQuery("div:contains(\"- - -\")").remove();});' gi;

#成绩分析页面添加高速打印功能并设定打印效果
subs_filter 'function report1_importExcel()' 'function webprint(){jQuery("table:first").css("display","none");window.print();jQuery("table:first").css("display","block");};jQuery(document).ready(function(){jQuery("table").attr("align","center");jQuery("tr[height=20]:last").remove();jQuery("tr[height=9]:last").remove();jQuery("#report1").css("width","640");jQuery("#report1_sub_8_1").css("width","640").css("border-right","1px solid");jQuery("img").css("width","638").css("height","160").css("border","1px solid");jQuery("#report1_sub_11_4").css("width","426");jQuery("#report1_sub_12_4").css("width","426");jQuery("#runqian_submit").after(" >> <a href=# onclick=webprint();return;>&#39640;&#36895;&#27983;&#35272;&#22120;&#25171;&#21360;<\/a>");jQuery("div:contains(\"- - -\")").remove();});function report1_importExcel()' gi;

#打印成绩单页面添加高速打印功能并设定打印效果
#subs_filter '<tr height="20" style="height:20px;">(.*)</tr>' '' gir;
#subs_filter ' <td class="report1_1_1"></td>' '' gi;

subs_filter 'function initialization(){' 'function webprint(){jQuery("form:first").css("display","none");jQuery("table:eq(2) table:first").css("display","none");window.print();jQuery("form:first").css("display","block");jQuery("table:eq(2) table:first").css("display","block");};jQuery(document).ready(function(){jQuery("tr[height=20]:lt(1)").remove();jQuery("table:first").attr("width","640");jQuery("#report1").css("width","640");jQuery("table:eq(2) a:last").after(" >> <a href=# onclick=webprint();return;>&#39640;&#36895;&#27983;&#35272;&#22120;&#25171;&#21360;<\/a>");jQuery("div:contains(\"- - -\")").remove();});function initialization(){' gi;

subs_filter onClick="getType() onClick="window.open('/reportFiles/cj/cj_kccj.jsp','','height=800,width=750,toolbar=no,resizable=yes,menubar=yes,scrollbars=yes') gi;

#历年成绩查询并添加高速打印功能、设定打印效果
subs_filter '<form action="/reportFiles/cj/xs_kccjb.jsp"' '<script>function webprint(){jQuery("form:first").css("display","none");jQuery("table:lt(2)").css("display","none");window.print();jQuery("form:first").css("display","block");jQuery("table:lt(2)").css("display","block");};jQuery(document).ready(function(){jQuery("table").attr("width","640").attr("align","center");jQuery("#report1").css("width","640");jQuery("table:eq(1) a:last").after(" >> <a href=# onclick=webprint();return;>&#39640;&#36895;&#27983;&#35272;&#22120;&#25171;&#21360;<\/a>");jQuery("div:contains(\"- - -\")").remove();});</script><form action="/reportFiles/cj/xs_kccjb.jsp"' gi;

#教师课表、教室课表、班级课表添加高速打印功能并设定打印效果
subs_filter '<td colspan="9">&nbsp;<p align="center" class="td2 style5">' '<td colspan="9"><p align="center" class="td2 style5">' gi;
subs_filter 'function printkb()' 'function webprint(){jQuery("table:eq(16)").jqprint();};jQuery(document).ready(function(){jQuery("#btprint").parent().attr("width","200");jQuery("#btprint").after(" >> <a href=# onclick=webprint();return;>&#39640;&#36895;&#27983;&#35272;&#22120;&#25171;&#21360;<\/a>");jQuery("div:contains(\"- - -\")").remove();});function printkb()' gi;

#登录成绩添加自动填充功能
subs_filter 'height="400"' 'height="100%"' gi;
subs_filter '<table width="640"' '<table width="100%"' gi;

subs_filter '<form name="CjlrmxFrom" method="post" action="cjlrmxAction.do?actionType=1">' '<script src="/assets/js/autoscore.js"></script><form name="CjlrmxFrom" method="post" action="cjlrmxAction.do?actionType=1"><table width="100%"><tr><td><textarea class="manuscript" id="ss" rows=5 cols=20 style="width:100%;"></textarea></td></tr><tr><td><button onclick="autoscore();return false;">&#33258;&#21160;&#22635;&#20805;&#25104;&#32489;</button>&nbsp;&nbsp;<button onclick="autoscorehelp();return false;">&#20351;&#29992;&#35828;&#26126;</button></td></tr><tr><td><div id="autoscoremsg" style="background:blue;color:white;padding:2px;2px;2px;2px;"></div></td></tr></table>' gi;

}

#一些静态资源比如jquery等不进行代理,使用本站提供,注意页面中一定使用 /assets/ 相对链接
location /assets/ {
index index.php index.html;
include fastcgi_params;
root /data/www/zhjw.scse.hebut.edu.cn/htdocs/;
}

#网站主页替换为本站 login.php ,这样可以自定义登录外观,可不替换。
location =/ {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://zhjw.scse.hebut.edu.cn/login.php;
}

#顶部框架使用 top.php 替换
location /menu/top.jsp {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://zhjw.scse.hebut.edu.cn/top.php;
}

#左侧框架使用menu.php替换,根据不同角色切换为不同菜单。
location /menu/menu.jsp {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://zhjw.scse.hebut.edu.cn/menu.php;
}

#php 页面解析为本站解析
location ~ \.php$ {
include fastcgi_params;
fastcgi_index index.php;
#fastcgi_pass 127.0.0.1:9000;
#fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_param SCRIPT_FILENAME /data/www/zhjw.scse.hebut.edu.cn/htdocs$fastcgi_script_name;
}
}

效果

还不错,至少各种浏览器都能打开了,一些必须的页面也可以在高速浏览模式打印了,打印效果也基本满足要求,批量从 excel 中导入成绩也工作的很好。

[

主界面效果](/media/urp1.jpg)
主界面效果](/media/urp1.jpg)

教学记录表打印效果
教学记录表打印效果