Skip to content

Instantly share code, notes, and snippets.

@DarkMatterMatt
Last active July 2, 2018 09:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DarkMatterMatt/3819417c98f5e6cd7145599bc97e8398 to your computer and use it in GitHub Desktop.
Save DarkMatterMatt/3819417c98f5e6cd7145599bc97e8398 to your computer and use it in GitHub Desktop.
Run SalienCheat for multiple users and auto-updates every 30 mins. Webpage to view the log online (support for pretty colours).
#!/bin/bash
declare -A USERS # associative array
# enter users here
USERS[name1]="token1xxxxxxxxxxxxxxxxxxxxxxxxxx steamID64optional"
USERS[name2]="token2xxxxxxxxxxxxxxxxxxxxxxxxxx steamID64optional"
USERS[examp]="efa1d62e8e422acc0a76aff5ac889d71 76561197295961561"
BASE_DIR=/home/pi/saliencheat
CHEAT=$BASE_DIR/cheat.php
LOG_DIR=$BASE_DIR/log
BOLD="" # background colour is dark blue
NORM="" # back to normal colours
# stores pids of running scripts
pids=()
# output terminal colours for PHP display
export DISABLE_COLORS=0
export SHOW_ALL_PLAYERS_FIGHTING_BOSS=0
# update git repository
git -C $BASE_DIR pull origin master >> $LOG_DIR/git_update.log 2>&1
# clear logs & run scripts & store pids
echo "Starting SalienCheat @ $(date)"
for name in "${!USERS[@]}"; do
echo "${BOLD}Starting SalienCheat @ $(date)${NORM}" > $LOG_DIR/$name.log
$CHEAT ${USERS[$name]} >> $LOG_DIR/$name.log 2>&1 &
pids+=($!)
done
while true; do
# sleep 30 mins
sleep 30m
echo "" >> $LOG_DIR/git_update.log
git -C $BASE_DIR pull origin master 2>&1 | tee $LOG_DIR/git_update.log | grep cheat.php
if [[ $? == 0 ]]; then
# stop scripts
for pid in pids; do
kill $pid
done
# run scripts
echo "Restarting script to update "
for name in "${!USERS[@]}"; do
echo "${BOLD}Restarting script to update${NORM}" > $LOG_DIR/$name.log
$CHEAT ${USERS[$name]} >> $LOG_DIR/$name.log 2>&1 &
pids+=($!)
done
fi
done
<?php
// saliens.php uses default name
// saliens.php?name=name1
// saliens.php?name=name1&getall
$DEFAULT_NAME = 'msm';
$LOG_FILE_DIR = '/home/pi/saliencheat/log';
$colors = [
/* normal */ "\033[0m" => '</span>',
/* green */ "\033[0;32m" => '<span class="green">',
/* yellow */ "\033[1;33m" => '<span class="yellow">',
/* red */ "\033[1;31m" => '<span class="red">',
/* blue */ "\033[0;36m" => '<span class="blue">',
/* background blue */
"\033[37;44m" => '<span class="background_blue">'
];
$name = isset($_GET['name']) && !empty($_GET['name']) ? $_GET['name'] : $DEFAULT_NAME;
$file = fopen("$LOG_FILE_DIR/$name.log", 'r');
if (!$file) {
echo 'Failed to open log';
die;
}
// only return last 15000 characters by default
if (!isset($_GET['getall'])) {
fseek($file, -15000, SEEK_END);
fgets($file);
}
// loop through each line, making sure colours are closed and adding <br>s
$log = '';
while (!feof($file)) {
$line = trim(htmlspecialchars(fgets($file)));
// close all colour open tags with a "\033[0m"
$num_colours_open = substr_count($line, "\033[") - 2 * substr_count($line, "\033[0m");
if ($num_colours_open > 0) {
$line .= str_repeat("\033[0m", $num_colours_open);
}
$log .= $line . "<br>\n";
}
// cut last 10 characters off (two <br>s and a \n)
$log = substr($log, 0, strlen($log) - 10);
// replace colours with coloured span
$log = str_replace(array_keys($colors), $colors, $log);
?>
<!DOCTYPE html>
<html>
<head>
<title>Saliens Log</title>
<style>
body {
background-color: black;
color: lightgrey;
font-family: "Lucida Console", Monaco, monospace;
}
pre {
line-height: 0.45rem;
}
.green { color: rgb(0, 187, 0); }
.yellow { color: rgb(187, 187, 0 ); }
.red { color: rgb(187, 0, 0); }
.blue { color: rgb(0, 187, 187); }
.background_blue { background-color: rgb(0, 0, 187) }
</style>
</head>
<body>
<pre><?php echo $log; ?></pre>
<script>
// scroll to bottom automatically
setTimeout(function() {
window.scrollTo(0, document.body.scrollHeight);
}, 10);
// reload every 30 secs
setTimeout(function() {
window.location.reload(true);
}, 30 * 1000);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment