index.html 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  1. <!DOCTYPE html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  4. <title>moe</title>
  5. <script type="text/javascript" src="/js/jquery.min.js"></script>
  6. <link rel="stylesheet" href="/css/bootstrap.min.css">
  7. <script type="text/javascript" src="/js/bootstrap.min.js"></script>
  8. <link rel="preconnect" href="https://fonts.googleapis.com">
  9. <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
  10. <link href="/css/css2.css" rel="stylesheet">
  11. <link rel="stylesheet" href="/css/style.css">
  12. <script>
  13. var status = 0, oid, user, pwd, paused = []
  14. const rot = '43.143.233.184:81', root = 'https://43.143.233.184:81/'
  15. function getCookie(name) {
  16. let arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
  17. if (arr != null) return arr[2];
  18. return null;
  19. }
  20. function delCookie(name, path = 'u') {
  21. var exp = new Date();
  22. exp.setTime(exp.getTime() - 1);
  23. var cval = getCookie(name);
  24. if (cval != null)
  25. document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString() + ((path == 'u') ? '' : ';path=' + path)
  26. }
  27. function getUrl(e) {
  28. return e.replace('dd.sdsz.com.cn', rot).replace(/^http:/, 'https:').replace(rot.split(':')[0] + '/', rot + '/').replace('service=http%3A%2F%2F' + root, 'service=http%3A%2F%2Fdd.sdsz.com.cn')
  29. }
  30. function setStatus(e, fast) {
  31. console.log('STATUS', e)
  32. status = e
  33. if (e == 1) {
  34. paused = []
  35. $('#loginSt').text('登录成功')
  36. $('.login').hide(200)
  37. $('#loginSt').addClass('label-success')
  38. $('#loginSt').removeClass('label-danger')
  39. $('.reqLogin').show(300)
  40. } else if (e == 2) {
  41. $('#loginSt').text('登录失败')
  42. $('#loginSt').removeClass('label-success')
  43. $('#loginSt').addClass('label-danger')
  44. } else if (e == 3) {
  45. delCookie('moe', '/')
  46. document.cookie = 'moe=guest;path=/';
  47. $('#loginSt').text('游客')
  48. $('.login').hide(200)
  49. $('.reqLogin').show(300)
  50. } else {
  51. $('.login').show(200)
  52. $('#loginSt').text('未登录')
  53. $('#loginSt').removeClass('label-success')
  54. $('#loginSt').removeClass('label-danger')
  55. $('.reqLogin').hide(300 * !fast)
  56. $('#user').text('-')
  57. }
  58. }
  59. function delCookies(force = 0) {
  60. if (force) {
  61. delCookie('CASTGC', '/')
  62. delCookie('moe', '/')
  63. delCookie('gosh', '/score/')
  64. if (force <= 2) {
  65. delCookie('gosh', '/sso/')
  66. delCookie('gowd', '/sso/')
  67. }
  68. }
  69. if (force >= 2) {
  70. delCookie('JSESSIONID', '/bxn-portal/')
  71. delCookie('JSESSIONID', '/bxn-library/')
  72. delCookie('JSESSIONID', '/bxn-core-uic/')
  73. }
  74. delCookie('JSESSIONID', '/')
  75. delCookie('SSOID', '/')
  76. delCookie('JSESSIONID', '/sso/')
  77. }
  78. function gget(url, call) {
  79. fetch(url, {
  80. "headers": {
  81. "content-type": "application/x-www-form-urlencoded; charset=UTF-8",
  82. },
  83. "method": "GET",
  84. "credentials": 'include'
  85. }).then(e => e.text()).then(call)
  86. }
  87. function getStatus(ds, dt) {
  88. let s = new Date(ds), t = new Date(dt), e = new Date();
  89. console.log(s, t, e)
  90. if (e < s) return '未开始'
  91. if (e < t) return '进行中'
  92. else return '已结束'
  93. }
  94. function adminStuff() {
  95. $('.admin').show()
  96. }
  97. function contestTouch() {
  98. fetch('contest/touch', {
  99. headers: { 'Content-type': 'application/json' },
  100. method: "POST",
  101. credentials: 'include',
  102. body: JSON.stringify({
  103. no: $('#tNo').val(),
  104. title: $('#tTitle').val(),
  105. description: $('#tDescription').val(),
  106. dates: new Date($('#tStart')[0].valueAsNumber).toUTCString(),
  107. datet: new Date($('#tEnd')[0].valueAsNumber).toUTCString()
  108. }),
  109. }).then(e => e.json()).then(e => {
  110. if (e.no) alert('您无权进行此操作')
  111. else {
  112. $('.contestNew').toggle(300)
  113. debug('TOUCH', 'affected ' + e.affectedRows + ' rows.')
  114. postLogin();
  115. }
  116. })
  117. }
  118. function contestRm(id, name) {
  119. console.log(name)
  120. if (prompt('确认删除?输入“' + name + '”以确认。') != name) return
  121. fetch('contest/rm', {
  122. headers: { 'Content-type': 'application/json' },
  123. method: "POST",
  124. credentials: 'include',
  125. body: `{"id":"${id}"}`
  126. }).then(e => e.json()).then(e => {
  127. console.log(e)
  128. if (e.no) alert('您无权进行此操作')
  129. else {
  130. debug('RM', 'affected ' + e.affectedRows + ' rows.')
  131. postLogin();
  132. }
  133. })
  134. }
  135. function postLogin() {
  136. debug('LOGIN DONE.', 'initiate fetching.')
  137. if (status != 1 && status != 3) return;
  138. if (status == 1) {
  139. if (!user) user = getCookie('gosh'), pwd = getCookie('gowd')
  140. document.cookie = "gosh=" + user + ";path=/score/;expires=Fri, 05 Feb 2077 12:34:56 GMT";
  141. document.cookie = "gosh=" + user + ";path=/sso/;expires=Fri, 05 Feb 2077 12:34:56 GMT";
  142. document.cookie = "gowd=" + pwd + ";path=/sso/;expires=Fri, 05 Feb 2077 12:34:56 GMT";
  143. if (getCookie('moe')[0] == '!') $('#user').text('admin')
  144. else get('bxn-portal/portal/api/proxy?username=true&userId=true&needvalidate=true&t=http%3A%2F%2F202.94.10.118%2Fbxn-library%2Fapi%2Flibrary%2FgetLatestBorrowBook%3Fcategory%3D1&resourceId=103519&cache=nocache&systime=0', e => {
  145. e = JSON.parse(e)
  146. $('#user').text(e.requestParams[0].ownerName)
  147. oid = e.requestParams[0].ownerId
  148. })
  149. }
  150. gget('contest', e => {
  151. e = JSON.parse(e)
  152. $('#contest').empty()
  153. for (let i = 0; i < e.length; i++) {
  154. $('#contest').prepend(`\
  155. <li id="contest-${e[i].id}">\
  156. <span onclick="$(this).toggleClass('active').siblings('div').toggle(300)" class="title">第 ${e[i].no} 届${e[i].title}\
  157. <span class="pull-right" style="color:#999"><span class="admin"><a href="javascript:contestRm(${e[i].id},'第${e[i].no}届${e[i].title}')">删除</a> ${e[i].id} - </span>${getStatus(e[i].dates, e[i].datet)}</span>\
  158. </span>
  159. <div class="content" style="display:none;white-space: pre-wrap;">${e[i].description}</div>\
  160. </li>`)
  161. }
  162. if (status == 1 && getCookie('moe')[0] == '!') adminStuff()
  163. else $('.admin').hide()
  164. })
  165. }
  166. function debug(e, str = '') {
  167. $('.debugList').append(`<li class="auto-warp"><b>${e}</b> ${str} <span class="pull-right" style="color:#999">${status}</span></li>`)
  168. }
  169. function login() {
  170. debug('LOGIN.')
  171. if (status == 1) return;
  172. delCookies()
  173. user = $('#loginId').val(), pwd = $('#loginPwd').val()
  174. return fetch(root + "sso/login", {
  175. headers: {
  176. "content-type": "application/x-www-form-urlencoded; charset=UTF-8",
  177. // "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36"
  178. },
  179. method: "GET",
  180. mode: "cors",
  181. credentials: 'include'
  182. }).then(() => {
  183. return fetch('https://43.143.233.184/moelogin', {
  184. method: 'POST',
  185. headers: { 'Content-type': 'application/json' },
  186. body: JSON.stringify({
  187. user: user,
  188. pwd: pwd,
  189. cook: getCookie('JSESSIONID')
  190. }),
  191. credentials: 'include',
  192. })
  193. }).then(e => e.text()).then(e => { setStatus((e != 'success') + 1), Promise.resolve() })
  194. }
  195. function matches(e) {
  196. return e.match(/(^\[\]$|param":"|<tr>|DOCTYPE|in\?username=|requestParams|\"newmessage\"|Sorry, Page Not Found|北师大实验中学--登录)/s)
  197. }
  198. // 异步递归嘿嘿嘿,再多 302 也不怕;再加上回调函数,真是妙
  199. async function next(e, call, ac, login) {
  200. if (e.length < 3000 && !matches(e) && (!e.match('\/login\\?') || login)) {
  201. return fetch(getUrl(e), {
  202. method: 'GET',
  203. credentials: 'include',
  204. headers: {
  205. Accept: ac
  206. }
  207. }).then(e => e.text()).then(res => { next(res, call, ac, login) })
  208. }
  209. else return call(e), new Promise((resolve, reject) => { })
  210. }
  211. function pre(e, url, call) {
  212. if (e.match('北师大实验中学--登录')) {
  213. debug('OUTDATED CAS! NEED RELOGIN')
  214. delCookie('CASTGC', '/')
  215. tryLogin()
  216. }
  217. if (e.length < 3000 && e.match('\/login\\?')) {
  218. var name = url.split('/')[0], f = paused.filter(e => e.name == name)
  219. debug('FAILED', url)
  220. if (url.match('\/login\\?')) return
  221. if (f.length) f[0].arr.push(url), f[0].carr.push(call)
  222. else {
  223. paused.push({ name: name, arr: [url], carr: [call] })
  224. debug('GET COOKIE...')
  225. get(name + '/casfailed.jsp', () => {
  226. let f = paused.filter(e => e.name == name)[0]
  227. for (let i = 0; i < f.arr.length; i++)get(f.arr[i], f.carr[i])
  228. paused.splice(paused.indexOf(f), 1)
  229. }, '*/*', 1)
  230. }
  231. } else {
  232. $('#bxn' + url.split('bxn')[1].split(/(\/|%2F)/)[0]).addClass('bg-success').addClass('text-success')
  233. if (status == 1) call(e)
  234. }
  235. }
  236. function get(url, call = () => { }, ac = '*/*', login = 0) {
  237. if (getCookie('moe')[0] == '!') return
  238. console.log("GET", url)
  239. debug('GET', url)
  240. if (status != 1) return
  241. next(root + url, e => { pre(e, url, call); }, ac, login)
  242. }
  243. let trying = 0
  244. function tryLogin() {
  245. if (trying) return debug('LOGIN', 'already in progress.')
  246. if (getCookie('moe') && getCookie('moe')[0] == '!') {
  247. debug('LOGIN', 'admin!')
  248. setStatus(1), postLogin()
  249. } else if (getCookie('CASTGC')) {
  250. debug('LOGIN', 'using CAS.')
  251. setStatus(1), postLogin()
  252. } else if (getCookie('gosh') && getCookie('gosh') != 'null' && getCookie('gowd') != 'null') {
  253. debug('LOGIN', 'using stored cookie.')
  254. setStatus(0)
  255. trying = 1
  256. $('#loginId').val(getCookie('gosh'))
  257. $('#loginPwd').val(getCookie('gowd'))
  258. login().then(() => { status == 2 ? setStatus(0, 1) : (trying = 0, postLogin()); })
  259. } else debug('LOGIN', 'no available method.'), setStatus(0, 1)
  260. }
  261. $().ready(() => {
  262. $('.e').addClass('reqLogin')
  263. $('.e').removeClass('e')
  264. tryLogin()
  265. $("[data-toggle='tooltip']").tooltip();
  266. $('.banner').text('庆祝 moe 建站 ' + Math.ceil((new Date().getTime() - 1676000714191) / 86400000) + ' 天')
  267. })
  268. </script>
  269. <style>
  270. .pass {
  271. font-weight: bold;
  272. font-family: 'Courier New', Courier, monospace;
  273. }
  274. li {
  275. border-bottom: 3px solid #eee;
  276. word-wrap: break-word;
  277. }
  278. li>.title {
  279. transition-duration: 300ms;
  280. display: inline-block;
  281. width: 100%;
  282. cursor: pointer;
  283. font-size: 18px
  284. }
  285. li>.active.title {
  286. font-size: 22px;
  287. font-weight: bold;
  288. }
  289. li>.active+div {
  290. background-image: linear-gradient(to right, #fffaf0, #f4f2ef);
  291. border-left: 3px solid #ccc;
  292. padding-left: 5px;
  293. }
  294. li:hover {
  295. background-color: #eee;
  296. }
  297. .box {
  298. transition-duration: 300ms;
  299. min-height: 210px;
  300. }
  301. .box::before {
  302. content: '';
  303. display: block;
  304. width: 100%;
  305. height: 3px;
  306. margin-top: 10px;
  307. border-bottom: 1px solid;
  308. border-image: linear-gradient(to right, transparent, #6aaad8, #75ddb6, transparent) 1;
  309. }
  310. .box:hover::before {
  311. border-bottom: 3px solid;
  312. border-image: linear-gradient(to right, transparent, #6aaad8, #75ddb6, transparent) 1;
  313. }
  314. .box:hover {
  315. background-image: linear-gradient(#faffef, transparent);
  316. }
  317. .page-header.nohr {
  318. margin-bottom: 0;
  319. border-bottom: none;
  320. }
  321. span.full {
  322. width: 100%;
  323. display: inline-block;
  324. cursor: pointer;
  325. }
  326. .breadcrumb {
  327. padding: 0;
  328. margin-bottom: 5px;
  329. }
  330. .auto-warp {
  331. word-wrap: break-word;
  332. word-break: break-all;
  333. overflow: hidden;
  334. transition-duration: 500ms;
  335. max-height: 22.4px;
  336. }
  337. .auto-warp:hover {
  338. max-height: 100px;
  339. }
  340. </style>
  341. </head>
  342. <body>
  343. <div class="page-header nohr">
  344. <h2>
  345. <!-- <img src="RC.png" width="32px" style="position:relative;top:-4px"> -->
  346. 实萌
  347. </h2>
  348. <span id="loginSt" class="label label-default">未登录</span>
  349. <span id="user" class="label label-default">-</span>
  350. <button class="btn btn-danger btn-xs e" onclick="postLogin()" title="刷新数据">
  351. <span class="glyphicon glyphicon-refresh"></span>
  352. </button>
  353. <button class="btn btn-danger btn-xs e" onclick="delCookies(1);setStatus(0)" onmouseenter="$('#double-off').css('scale','100%')" onmouseleave="$('#double-off').css('scale','0')" title="退出登录">
  354. <span class="glyphicon glyphicon-log-out"></span>
  355. </button>
  356. <button id="double-off" class="btn btn-danger btn-xs e" onclick="delCookies(2);location.reload()" onmouseenter="$('#double-off').css('scale','100%')" onmouseleave="$('#double-off').css('scale','0')" style="scale:0;transition-duration: 1000ms;" data-toggle="tooltip" data-placement="right" title="全部重置">
  357. <span class="glyphicon glyphicon-off"></span>
  358. </button>
  359. <button class="btn btn-danger btn-xs login" onclick="delCookies(2);location.reload()" data-toggle="tooltip" data-placement="right" title="全部重置">
  360. <span class="glyphicon glyphicon-off"></span>
  361. </button>
  362. </div>
  363. <div class="col-sm-12 e box box-contest">
  364. <div class="page-header">
  365. <h3><span class="glyphicon glyphicon-fire"></span> 比赛列表
  366. </h3>
  367. </div>
  368. <ul id="contest" class="list-unstyled"></ul>
  369. <button class="btn btn-default admin" onclick="$('.contestNew').toggle(300)">新建比赛 <span class="glyphicon glyphicon-plus"></span></button>
  370. <div class="contestNew" style="display:none">
  371. <div class="col-md-4">
  372. 标题
  373. <div class="input-group">
  374. <div class="input-group-addon">第</div>
  375. <input id="tNo" class="form-control" placeholder="0" autocomplete="off">
  376. <div class="input-group-addon">届</div>
  377. <input id="tTitle" class="form-control" placeholder="测试赛" autocomplete="off">
  378. </div>
  379. </div>
  380. <div class="col-md-4">
  381. 开始时间
  382. <input class="form-control" type="date" id="tStart" min="2022-01-01" value="2023-02-10">
  383. </div>
  384. <div class="col-md-4">
  385. 结束时间
  386. <input class="form-control" type="date" id="tEnd" min="2022-01-01" value="2023-02-10">
  387. </div>
  388. <div class="col-sm-12" style="margin-top: 10px;">
  389. <textarea id="tDescription" class="form-control" placeholder="介绍(请勿使用英文引号和分号)" style="resize: vertical"></textarea>
  390. <button class="btn btn-default" onclick="contestTouch()" style="margin-top: 10px;">提交 <span class="glyphicon glyphicon-send tSend"></span></button>
  391. </div>
  392. </div>
  393. </div>
  394. <div class="col-md-4 col-sm-6 box">
  395. <div class="page-header">
  396. <h3><span class="glyphicon glyphicon-user"></span> 账号
  397. <ul class="btn-group breadcrumb debug" style="display: none;font-size:10px;top:5px">
  398. <li id="bxn-portal" onclick="get('bxn-portal/portal/osforstudent/index')">bxn-portal</li>
  399. <li id="bxn-core-uic" onclick="get('bxn-core-uic/uic/index')">bxn-core-uic</li>
  400. <li id="bxn-library" onclick="get('bxn-library/library/jumpExamreport?jumpUrl=')">bxn-library</li>
  401. <li id="bxn-office" onclick="get('bxn-office/mail/index')">bxn-office</li>
  402. </ul>
  403. </h3>
  404. </div>
  405. <button class="btn btn-default e" onclick="$('.debug').toggle(200)">debug</button>
  406. <div class="login">
  407. (登录数字校园)
  408. <br>
  409. <div class="input-group">
  410. <span class="input-group-addon">账号</span>
  411. <input id="loginId" type="id" class="pass form-control" placeholder="20222222">
  412. </div>
  413. <br>
  414. <div class="input-group">
  415. <span class="input-group-addon">密码</span>
  416. <input id="loginPwd" type="password" class="pass form-control" placeholder="password">
  417. <span class="input-group-btn">
  418. <button class="btn btn-default" type="button" onclick="login().then(postLogin)">
  419. <span class="glyphicon glyphicon-log-in"></span> 登录
  420. </button>
  421. </span>
  422. </div>
  423. <br>
  424. <button class="btn btn-default" onclick="setStatus(3);postLogin()"><span class="glyphicon glyphicon-user"></span> 游客</button><small>(可能不计入投票结果)</small>
  425. </div>
  426. <div class="debug" style="display: none;">
  427. <button class="btn btn-default btn-xs" onclick="$('.debugList').empty()"><span class="glyphicon glyphicon-trash"></span> 清除</button>
  428. <ul class="debugList list-unstyled" style="font-family: 'Courier New', Courier, monospace;"></ul>
  429. </div>
  430. </div>
  431. <div style="position:fixed;bottom:10px;left:10px;color:#ccc">
  432. 北师大实验中学
  433. </div>
  434. <div style="position:fixed;bottom:10px;right:10px;color:#ccc" class="banner"></div>
  435. </body>