Skip to content
This repository has been archived by the owner on Apr 19, 2022. It is now read-only.

Commit

Permalink
修复脚本传参问题,增加界面自动下移
Browse files Browse the repository at this point in the history
  • Loading branch information
nsfoxer committed Apr 7, 2020
0 parents commit 3422927
Show file tree
Hide file tree
Showing 16 changed files with 1,130 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/temp/:
!/temp/timeout.png
/scripts/Fuck
/cloud_note
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Learn_to_be_strong_scripts_server

[TOC]

## 简介

学习强国服务器脚本部署,支持多人多开。

实际本身属于套壳软件,使用脚本拼凑起来,简单使用

使用需要先注册,再使用App扫码登录

使用[学习强国](https://github.com/fuck-xuexiqiangguo/Fuck-XueXiQiangGuo)脚本

## 安装

### centos

- `sudo yum install -y xorg-x11-utils xorg-x11-server-Xvfb ImageMagick mariadb php-mysql httpd`

- `sudo systemctl start httpd.service`

-[学习强国](https://github.com/fuck-xuexiqiangguo/Fuck-XueXiQiangGuo)克隆至本项目`scripts`/下,并重命名为`Fcuk`,同时下载脚本所需依赖

-`login.php`$servername, $username,$password, $dbname,$table_name修改为自己的数据库

- 数据库表中,需要`username`,与`passwd`两项

- 在网页根目录处,需要新建`temp/`文件夹,并且保证`apache`对该目录有写权限,

```bash
# mkdir temp
# setfacl -m u:apache:rwz temp/
```



## 截图

![image-20200330115915709](http://47.94.151.63/cloud_note/pictures_bed/image-20200330115915709.png)

![image-20200401153043781](http://47.94.151.63/cloud_note/pictures_bed/image-20200401153043781.png)
105 changes: 105 additions & 0 deletions css/dmaku.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/****************************************************************
* *
* 代码库 *
* www.dmaku.com *
* 努力创建完善、持续更新插件以及模板 *
* *
****************************************************************/
.login-page {
width: 360px;
padding: 8% 0 0;
margin: auto;
}
.form {
position: relative;
z-index: 1;
background: #FFFFFF;
max-width: 360px;
margin: 0 auto 100px;
padding: 45px;
text-align: center;
box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.2), 0 5px 5px 0 rgba(0, 0, 0, 0.24);
}
.form input {
font-family: "Roboto", sans-serif;
outline: 0;
background: #f2f2f2;
width: 100%;
border: 0;
margin: 0 0 15px;
padding: 15px;
box-sizing: border-box;
font-size: 14px;
}
.form button {
font-family: "Roboto", sans-serif;
text-transform: uppercase;
outline: 0;
background: #4CAF50;
width: 100%;
border: 0;
padding: 15px;
color: #FFFFFF;
font-size: 14px;
-webkit-transition: all 0.3 ease;
transition: all 0.3 ease;
cursor: pointer;
}
.form button:hover,.form button:active,.form button:focus {
background: #43A047;
}
.form .message {
margin: 15px 0 0;
color: #b3b3b3;
font-size: 12px;
}
.form .message a {
color: #4CAF50;
text-decoration: none;
}
.form .register-form {
display: none;
}
.container {
position: relative;
z-index: 1;
max-width: 300px;
margin: 0 auto;
}
.container:before, .container:after {
content: "";
display: block;
clear: both;
}
.container .info {
margin: 50px auto;
text-align: center;
}
.container .info h1 {
margin: 0 0 15px;
padding: 0;
font-size: 36px;
font-weight: 300;
color: #1a1a1a;
}
.container .info span {
color: #4d4d4d;
font-size: 12px;
}
.container .info span a {
color: #000000;
text-decoration: none;
}
.container .info span .fa {
color: #EF3B3A;
}
body {
background: #76b852; /* fallback for old browsers */
background: -webkit-linear-gradient(right, #76b852, #8DC26F);
background: -moz-linear-gradient(right, #76b852, #8DC26F);
background: -o-linear-gradient(right, #76b852, #8DC26F);
background: linear-gradient(to left, #76b852, #8DC26F);
font-family: "Roboto", sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
Binary file added favicon.ico
Binary file not shown.
39 changes: 39 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<title>登录</title>
<link rel="stylesheet" href="css/dmaku.css">
</head>
<!--/************************************************************
* *
* 代码库 *
* www.dmaku.com *
* 努力创建完善、持续更新插件以及模板 *
* *
**************************************************************-->
<body>
<div class="login-page">
<p>学习强国--脚本</p><br/>
<p>刷课有风险,偷懒需谨慎</p>
<p>由于套壳程序各种问题,网站需要不定期更新,会造成使用不稳定,请见谅!</P>
<div class="form">
<form action="#" method="post" class="register-form">
<input type="username" name="username" placeholder="用户名">
<input type="passwd" name="passwd" placeholder="密码">
<!-- <input placeholder="邮箱">-->
<button type="submit" name="register" value="null">注册</button>
<p class="message">已有账号? <a href="javascript:">立即登录</a></p>
</form>
<form action="#" method="post" class="login-form">
<input type="text" name="username" placeholder="用户名">
<input type="password" name="passwd" placeholder="密码">
<button type="submit" name="login" value="login">登录</button>
<p class="message">还没有账号?<a href="javascript:">立即注册</a></p>
</form>
</div>
</div>
<script src="js/jquery.min.js"></script>
<script src="js/dmaku.js"></script>
</body>
</html>
10 changes: 10 additions & 0 deletions js/dmaku.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/****************************************************************
* *
* 代码库 *
* www.dmaku.com *
* 努力创建完善、持续更新插件以及模板 *
* *
****************************************************************/
$('.message a').click(function(){
$('form').animate({height: "toggle", opacity: "toggle"}, "slow");
});
12 changes: 12 additions & 0 deletions js/jquery.min.js

Large diffs are not rendered by default.

72 changes: 72 additions & 0 deletions login.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php
$servername = "localhost";
$username = "httpd";
$password = "172440136104";
$dbname = "shuake";
$table_name = "study_user_info";

$conn = mysqli_connect($servername, $username, $password, $dbname);
if (!$conn) {
die("数据库连接失败");
} else {
// echo "数据库连接成功" . "<br>";
}
session_start();
if (isset($_POST["login"])) {
$sql = 'prepare stmt from "select username,passwd from ' . $table_name . ' where username=?";';
mysqli_query($conn, $sql);
$sql = 'set @a="' . $_POST["username"] . "\";";
mysqli_query($conn, $sql);
$sql = 'execute stmt using @a;';
$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) == 0) {
echo "用户不存在 <br>";
echo '<a href="JavaScript:history.back()">返回登入</a>';
} else {
$row = mysqli_fetch_array($result);
if (md5($_POST["passwd"]) == $row["passwd"]) {
$_SESSION["name"] = $_POST["username"];
echo '登入成功,<a href="user_home.php">进入个人中心(请等待10秒)</a>';
} else {
echo "password error";
echo '密码错误! <a href="JavaScript:history.back()">返回登入</a>';
}
}
} else if (isset($_POST["register"])) {
if ($_POST["username"] == "" || $_POST["passwd"] == "") {
echo "用户名和密码不能为空";
}
else {
$sql = 'prepare stmt_rg from "insert into ' . $table_name . ' set username=?, passwd=?";';
mysqli_query($conn, $sql);
$sql = 'set @a="' . $_POST["username"] . "\";";
mysqli_query($conn, $sql);
$passwd = md5($_POST["passwd"]);
$sql = 'set @b="' . $passwd . '";';
mysqli_query($conn, $sql);
$sql = 'execute stmt_rg using @a, @b;';
$result = mysqli_query($conn, $sql);
if ($result == false) {
print_r($result);
echo "<p>注册失败,用户名已存在,请联系邮箱:[email protected]</p><br>";
echo '<br><a href="JavaScript:history.back()">返回</a>';
} else {
echo "<p>注册成功</p><br>";
echo "用户名:" . $_POST["username"];
echo '<br><a href="JavaScript:history.back()">返回</a>';
}
}
} else {
// echo '
// <form action="#" method="post">
// <p>帐号:<input type="text" name="username"/></p>
// <p>密码:<input type="password" name="passwd"/></p>
// <p><input type="submit" name="login" value="登入"/>
// <input type="submit" name="register" value="注册"/> </p>
// </form> ';
include("index.html");

}
mysqli_close($conn);
?>
16 changes: 16 additions & 0 deletions logout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
session_start();
$pwd = dirname(__FILE__);
if (isset($_SESSION['pid'])) {
// $shell = $pwd . "/scripts/xuexi_stop.sh " . $_SESSION['name'] . " " . $_SESSION['window'] . " " . $_SESSION['pid'] . " >> temp/log.txt &";
$name = $_SESSION['name'];
$pid = $_SESSION['pid'];
$windowid = $_SESSION['window'];
$shell = "${pwd}/scripts/xuexi_stop.sh ${name} ${windowid} ${pid} test >> temp/log.txt";
exec($shell, $result);
echo "关闭脚本中";
}
session_destroy();
header('Refresh:3; url="login.php"');
echo "退出成功,三秒后返回登入页面";
?>
13 changes: 13 additions & 0 deletions scripts/get_picture.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh
# 2020年 03月 29日 星期日 15:15:14 CST
# 2020年 04月 05日 星期日 19:26:24 CST
# 2020年 04月 07日 星期二 13:24:36 CST
# 输入: 窗口id
# 输出: 窗口id.png

windowid=$1
export DISPLAY=":9"
location=$(dirname $0)
png_file="${location}/../temp/${windowid}.png"
xdotool click -window ${windowid} --repeat=2 5
import -window ${windowid} ${png_file}
20 changes: 20 additions & 0 deletions scripts/pid2windowid.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/sh
# 2020年 03月 29日 星期日 13:53:50 CST
# 将pid转为window——id
# 参考:https://blog.csdn.net/superkeep/article/details/88948634
findpid=$1
known_windows=$(xwininfo -root -children|sed -e 's/^ *//' | grep -E "^0x" | awk '{ print $1 }')
for id in ${known_windows}
do
test_pid=$(xprop -id $id _NET_WM_PID)
if [ $? -eq 0 ];then
test_pid=$(xprop -id $id _NET_WM_PID|cut -d'=' -f2|tr -d ' ')
if [[ ${test_pid} == ${findpid} ]];then
echo "${id}"
exit 0
fi
fi
done
echo "0"
exit 1

55 changes: 55 additions & 0 deletions scripts/xuexi_start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/sh
# 2020年 03月 29日 星期日 14:47:03 CST
# 2020年 04月 05日 星期日 19:30:02 CST
# 2020年 04月 07日 星期二 13:26:48 CST
# 参数: 用户名
# 输出: ../temp/username_pid.txt ../temp/username_window.pid
user=$1
display=":9"

# 判断Xvfb程序是否已经打开
PIDS=$(ps -ef|grep Xvfb|grep -v grep|awk '{print $2}')
if [ -z ${PIDS} ];then
Xvfb -ac -screen scrn 1024x768x8 ${display} &
fi

# 运行Fuck程序,同时输出Fuck程序pid
# sleep是防止程序没有完全打开时,去读取windowid,造成windowid读取失败
export DISPLAY=${display}
location=$(dirname $0)
program="${location}/Fuck/Fuck学习强国"
${program} --user=${user} &
subpid=$!
echo -n ${subpid} > ${location}/../temp/${user}_pid.txt
sleep 5s

# 得到Fuck进程窗口id,同时输出windowid
window_id=$(${location}/pid2windowid.sh ${subpid} | grep -v '^$' | tr -d ' ')
echo -n ${window_id} > ${location}/../temp/${user}_window.txt

# 模拟鼠标滑轮向下移动
# xdotool click -window ${window_id} --repeat=2 5

# 得到Fuck进程窗口图片
get_pic_program="${location}/get_picture.sh"
${get_pic_program} ${window_id}

# 运行时间超过60m 后,自动退出后台进程,同时复制超时图片
# 每5min判断一次,Fuck程序是否存活
runtime=0
program_live=$(ps -p ${subpid} | wc -l)
while [[ ${runtime} -le 60 && ${program_live} -gt 1 ]]
do
sleep 5m
runtime=$(( ${runtime} + 5 ))
done

# 超时后,fuck程序依旧存活,此时自动调用退出程序,避免用户不退出登录而fuck程序的运行
if [ ${program_live} -gt 1 ]
then
${location}/xuexi_stop.sh ${user} ${window_id} ${subpid}
# 需要等待上一条命令执行完成
cp ${location}/../temp/timeout.png ${location}/../temp/${window_id}.png
fi

exit 0
Loading

0 comments on commit 3422927

Please sign in to comment.