Moved the Agents into their own repo. Kept the agent.pl just for reference

This commit is contained in:
Frank Harris 2025-09-11 13:27:32 -04:00
parent 22381be29a
commit 8680a02b13
18132 changed files with 0 additions and 2569420 deletions

View file

@ -1,26 +0,0 @@
<?php
// Setting error reporting to all errors
error_reporting(E_ALL);
include "functions.php";
function exec_ogp_module(){
if($_SERVER['REQUEST_METHOD'] === 'GET'){
$homeid = $_GET['home_id'];
echo "<center><h4>This Module is Currently not Working - Testing phase -
if you need to restore from backup see @shootingBlanks or @dimrod on discord</h4></center>";
echo '<center>';
echo '<h2>Backups Available for game server '.$homeid.'</h2>';
echo '<div><form method="POST">';
echo '<input type="hidden" name="home_id" value="'.$homeid.'"/>';
getAvailableBackups($homeid);
echo "</form></div>";
echo '</center>';
}elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
$action = $_POST['dothis'];
$homeid = $_POST['home_id'];
doButtons($action, $homeid);
}
}

View file

@ -1,134 +0,0 @@
<?php
function getHomeID() {
$homeid = $_GET['home_id'];
return $homeID;
}
function postHomeID(){
$homeid = $_POST(['home_id']);
$action = $_POST['dothis'];
}
function getLatestBackup($path) {
$latest = readlink($path);
$base = basename($latest);
return $base;
}
function getAvailableBackups($homeid) {
$dir = "/sdb1/backup/gameserver";
$servers = glob("$dir/*/$homeid", GLOB_ONLYDIR); //put all homeID backup paths into array
$length = count($servers);
for ($i = 0; $i < $length; $i++) {
$path = explode("/",$servers[$i]);
$path1 = explode("-",$path[4]);
if ("$path1[1]" === "latest"){
$latest = getLatestBackup(dirname($servers[$i])); // latest is softlinked to the last backup preformed
$latest1 = explode("-",$latest);
$skip = $latest1[1]; // get the day name to add to top row buttons
topRowButtons($skip); // go make buttons for the top row
$unset1=$i; // get the index of latest backups
}elseif("$path1[1]" === "$skip"){
$unset2=$i; // get index of day name of latest backup
}
}
unset($servers[$unset1], $servers[$unset2]); // remove the indexes from the $servers array
echo '<div>';
bottomRowButtons($servers);
echo '</div>';
}
function topRowButtons($latest){ // now create the top row buttons
echo '<div>';
echo '<button type="submit" name="dothis" value="go_back"><<&emsp;Go Back</button>';
echo '&emsp;&emsp;&emsp;';
echo '<button type="submit" name="dothis" value="latest">'.$latest.' (Latest Backup)</button>';
echo '&emsp;&emsp;&emsp;';
echo '<button type="submit" name="dothis" value="backup_now">Create Backup Now</button>';
echo '</div>';
}
function bottomRowButtons($bottomRow){ // create the bottom row buttons for older possiable backups
$newArray=array_values($bottomRow); // rebuild array to get rid of removed indexes
$length = count($newArray);
for ($i = 0; $i < $length; $i++) {
$path = explode("/",$newArray[$i]);
$path1 = explode("-",$path[4]);
echo '<button type="submit" name="dothis" value="'.$path1[1].'">'.$path1[1].'</button>&emsp;'; }
}
function doButtons($action, $homeid){
echo "<br>66: $action, $homeid";
switch ($action) {
case go_back:
echo "<br>63: Case go_back $action, $homeid";
goBack($action, $homeid);
break;
case backup_now:
echo "<br>67: backup_now $action, $homeid";
backupNow($action, $homeid);
break;
default:
echo "<br>71: default $action, $homeid";
restore($action, $homeid);
break;
}
}
function buildBackupCmd($action, $homeid){
$xmlFile = "/sdb1/backup/servers.xml";
$xmlData = simplexml_load_file($xmlFile);
$serverINFO = findServer($serverID, $xmlData);
}
function backupNow($action, $homeid){
echo "<br>98: backup: $action, $homeid";
}
function restore($action, $homeid){
$backup = backupServer($action, $homeid);
echo "<h3>You have chosen to Restore Server from backup <br>".$backup."</h3>";
}
function backupServer($action, $homeid){
$dir = "/sdb1/backup/gameserver";
$servers = glob("$dir/*/$homeid", GLOB_ONLYDIR); //put all homeID backup paths into array
$key = customSearch($action, $servers);
$backupServer = $servers[$key];
return $backupServer;
}
//===== DONE =============================
function goBack($action, $homeid){
$baseURL = "https://panel.iaregamer.com/home.php?m=gamemanager&p=game_monitor&home_id=$homeid";
header('Location: '.$baseURL);
exit();
}
function findServer($serverid, $xmldata) {
foreach ($xml->server as $server) {
if ( $server->servername == $serverid ) {
$serverINFO[servername] = "$server->servername";
$serverINFO[serverlogin] = "$server->login";
$serverINFO[serverpass] = "$server->pass";
$serverINFO[homedir] = "$server->files";
$serverINFO[backupdir] = "$server->backupdir";
return $serverINFO;
}
}
}
function customSearch($keyword, $arrayToSearch){
foreach($arrayToSearch as $key => $arrayItem){
if( stristr( $arrayItem, $keyword ) ){
return $key;
}
}
}
function printArray($array){ // quick way to print the array, I got tired of typing this in the code during testing
echo "<br>PrintArray<pre>";
print_r($array);
echo "</pre><br>";
}

View file

@ -1,35 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<servers>
<server>
<servername>kc.gameserver</servername>
<pass>Inc0rrect</pass>
<login>gameserver@kc.iaregamer.com</login>
<homedir>/home/gameserver/</homedir>
<backupdir>/sdb1/backup/gameserver</backupdir>
</server>
<server>
<servername>kcwin.C.drive</servername>
<pass>S4wihr6q8rzc!</pass>
<login>cyg_server@kcwin.iaregamer.com</login>
<homedir>/cygdrive/c/OGP64/home/gameserver/</homedir>
<backupdir>/sdb1/backup/gameserver</backupdir>
</server>
<server>
<servername>kcwin.D.drive</servername>
<pass>S4wihr6q8rzc!</pass>
<login>cyg_server@kcwin.iaregamer.com</login>
<homedir>/cygdrive/d/OGP64/home/gameserver/</homedir>
<backupdir>/sdb1/backup/gameserver</backupdir>
</server>
<server>
<servername>host.iaregamer.panel</servername>
<pass>Inc0rrect!</pass>
<login>gameserver@host.iaregamer.com</login>
<homedir>/var/www/html/panel/</homedir>
<backupdir>/sdb1/backup/panel</backupdir>
</server>
</servers>

View file

@ -1,49 +0,0 @@
<?php
include "function.php";
function exec_ogp_module(){
if($_SERVER['REQUEST_METHOD'] === 'GET'){
$homeid = $_GET['home_id'];
if($homeid == ""){
$home = "https://panel.iaregamer.com/home.php?m=dashboard&p=dashboard";
echo '<center>';
echo '<h1>WE HAVE A PROBLEM:</h1>';
echo '<h3>Theres NO homeid</h3>';
// echo '<button onclick="window.location.href="'.$home.';">&emsp; OK &emsp;</button>';
echo '</center>';
}else{
echo "<center><div>";
echo '<h3 style="text-transform: none;">
This Module is Currently not Working - Testing phase - if you need to
restore from a backup see &emsp; @shootingBlanks &emsp; or &emsp; @dimrod
&emsp; on discord</h3>';
echo '<p><b>You can push buttons to see what it does,
you wont hurt anything right now!</b></p>';
echo '<div><form id="mianForm" method="POST">';
echo '<input type="hidden" name="home_id" value="'.$homeid.'"/>';
getButtonList($homeid);
echo " </form></div></center>";
}
}elseif($_SERVER['REQUEST_METHOD'] === 'POST'){
$homeid = $_GET['home_id'];
$action = $_POST['dothis'];
if($action == "backupNow"){
$homeid = $_POST['home_id'];
$action = $_POST['dothis'];
BackupNow($homeid, $action);
}elseif($action == "restoreNow"){
$homeid = $_POST['home_id'];
$action = $_POST['dothis'];
restoreNow($homeid, $action);
}elseif($action == cancel){
$homeid = $_POST['home_id'];
goBack($homeid);
}else{
$action = $_POST['dothis'];
$homeid = $_POST['home_id'];
doButtons($homeid, $action);
}
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 59 KiB

View file

@ -1,233 +0,0 @@
<?php
// GET Functions ====================
function getButtonList($homeid){
// Get Avaliable back ups for $homeid
$backupPaths = backupPaths($homeid);
$latestDay = latestBackup($backupPaths);
topRow();
echo '<br><strong style="font-size:30px">Backups Available for game server '.$homeid.'</strong>';
bottomRow($latestDay,$backupPaths);
}
function topRow(){
// echo '<div>';
echo '<button type="submit" name="dothis" value="goBack"><<&emsp;Go Back</button>';
echo '&emsp;&emsp;&emsp;';
echo '<button type="submit" name="dothis" value="backup">Create New Backup</button>';
// echo '</div>';
}
function bottomRow($latestDay,$backupPaths){
echo '<br><div>';
$latest = customSearch($latestDay,$backupPaths);
$length = count($backupPaths);
for ($i = 0; $i < $length; $i++) {
$path = explode("/",$backupPaths[$i]);
$path1 = explode("-",$path[4]);
if( $path1[0] == 0 ){
//dont need this one
}elseif ( "$path1[0]" == "$latest" ) {
$day = $path1[1];
$dayLatest = "$path1[1]"." -> Latest";
echo '<button type="submit" name="dothis" value="'.$day.'">'.$dayLatest.'</button>&emsp;';
}else{
$day = $path1[1];
echo '<button type="submit" name="dothis" value="'.$day.'">'.$day.'</button>&emsp;';
}
}
echo '</div><br>';
}
// POST Functions ================
function doButtons($homeid, $action){
switch ($action) {
case "goBack":
goBack($homeid);
break;
case "backup":
backup($homeid,$action);
break;
default:
restore($homeid,$action);
}
}
function goBack($homeid){
$baseURL = "https://panel.iaregamer.com/home.php?m=gamemanager&p=game_monitor&home_id=$homeid";
header('Location: '.$baseURL);
exit;
}
function backup($homeid, $action){
echo '<center><div><form id="backupNow" method="POST">';
echo '<h3>You have chosen to create a new backup.';
echo '<br>This will overwrite the latest backup and';
echo '<br>create a new one for this day.</h3>';
echo '<input type="hidden" name="home_id" value="'.$homeid.'"/>';
echo '<button type="submit" name="dothis" value="cancel">Last Chance to Cancel</button>';
echo '&emsp;&emsp;&emsp;';
echo '<button type="submit" name="dothis" value="backupNow">
Backup Home Dir '.$homeid.'</button>';
echo '</form></div></center>';
}
function backupNow($homeid){
$backupPaths = backupPaths($homeid);
$latestDay = latestBackup($backupPaths);
$backup = customSearch($latestDay, $backupPaths);
$backupfolder = $backupPaths[$backup];
$gameServer = gameServer($homeid);
$serverINFO = serverINFO($gameServer);
$servername = $serverINFO['servername'];
$serverlogin = $serverINFO['serverlogin'];
$serverpass = $serverINFO['serverpass'];
$homedir = $serverINFO['homedir'];
$backupdir = $serverINFO['backupdir'];
$backuplink = "00-latest-$servername";
// $pass = "******";
// --dry-run
$sshpass = 'sshpass -p '.$serverpass;
$rsync = 'rsync -avP --delete --dry-run -e "ssh -p 12322"';
$softlink = '--link-dest '.$backupdir.'/'.$backuplink;
$gameserver = $serverlogin.':'.$homedir.$homeid;
$localdir = $backupfolder;
$command = $sshpass.' '.$rsync.' '.$softlink.' '.$gameserver.' '.$localdir;
// echo "<br>Command:<br> $command<br>";
$output = [];
$returnVar = 0;
exec($command, $output, $returnVar);
echo '<center><div>';
echo "<h3>Backing up: $homeid </h3>";
echo '<form method="POST">';
echo '<input type="hidden" name="home_id" value="'.$homeid.'"/>';
echo '<button type="submit" name="dothis" value="cancel">Go Back Home</button>';
if ($returnVar === 0) {
echo "<h4>Rsync completed successfully.</h4>";
}else{
echo "<h4>Rsync failed with status $returnVar.</h4>";
}
echo '</form>';
echo '<div>';
echo '<textarea readonly id="backup" name="backup" rows="20" cols="30">';
foreach ($output as $line) { echo $line."\n";}
echo '</textarea>';
echo '</div></div></center>';
}
function info(){
// Local to Local: rsync [OPTION]... [SRC]... DEST
// Local to Remote: rsync [OPTION]... [SRC]... [USER@]HOST:DEST
// Remote to Local: rsync [OPTION]... [USER@]HOST:SRC... [DEST]
//Push rsync -a
// localDir
// username@remote_host:destination_directory
//Pull rsync -a
// username@remote_host:/home/username/dir1
// localDir
}
function restore($homeid, $action){
echo '<center><div><h3>';
echo 'You Have chosen to Restore';
echo "<br>Home: $homeid from $action's backup.";
echo '</h3></div></center>';
echo '<center><div><form id="restore" method="POST">';
echo '<input type="hidden" name="home_id" value="'.$homeid.'"/>';
echo '<input type="hidden" name="restore" value="'.$action.'"/>';
echo '<button type="submit" name="dothis" value="cancel">Last Chance to Cancel</button>';
echo '&emsp;&emsp;&emsp;';
echo '<button type="submit" name="dothis" value="restoreNow">
Restore Home Dir from '.$action.'\'s backup</button>';
echo '</form></div></center>';
}
function restoreNow($homeid, $action){
$restore = $_POST['restore']; // day of week to restore
$backupPaths = backupPaths($homeid); //list of all backups for this home dir
$pathNum = customSearch($restore, $backupPaths); // key number of array of the backup
$localPath = $backupPaths[$pathNum]; //local path of the backup file
$gameServer = gameServer($homeid); //gameserver name
$serverINFO = serverINFO($gameServer);
// gameserver INFO from xml file
$gameserver = $serverINFO[servername]; //[servername] => kcwin.D.drive
$serverlogin = $serverINFO[serverlogin]; //[serverlogin] => cyg_server@kcwin.iaregamer.com
$serverpass = $serverINFO[serverpass]; //[serverpass] => S4wihr6q8rzc!
$homedir = $serverINFO[homedir]; //[homedir] => /cygdrive/d/OGP64/home/gameserver/
$backupdir = $serverINFO[backupdir]; //[backupdir] => /sdb1/backup/gameserver
// build the $command
$sshpass = 'sshpass -p '.$serverpass;
$rsync = 'rsync -avP --delete --dry-run -e "ssh -p 12322"';
$gameserver = $serverlogin.':'.$homedir;
$localdir = $localPath;
// Local to Remote: rsync [OPTION]... [SRC]... [USER@]HOST:DEST
$command = $sshpass.' '.$rsync.' '.$localdir.' '.$gameserver;
//echo $command;
echo "<center><div>";
echo '<form method="POST">';
echo "<h3>Restoring: $homeid from $restore's</h3>";
echo '<input type="hidden" name="home_id" value="'.$homeid.'"/>';
echo '<button type="submit" name="dothis" value="cancel">Go Back Home</button>';
// echo 'This is where the actual Restore will take place<br>';
exec($command, $output, $returnVar);
if ($returnVar === 0) {
echo "<h4>Rsync completed successfully.</h4>";
}else{
echo "<h4>Rsync failed with status $returnVar.</h4>";
}
echo '</form>';
echo '<div>';
echo '<textarea readonly id="backup" name="backup" rows="20" cols="30">';
foreach ($output as $line) { echo $line."\n";}
echo '</textarea>';
echo "</div>";
echo "</div></center>";
}
// General Functions =================
function gameServer($homeid){ // Gets serverName for $homeid
$dir = "/sdb1/backup/gameserver";
$servers = backupPaths($homeid);
$name = $servers[0];
$name = explode("-",$name);
$gameServer = dirname($name[2]);
return $gameServer;
}
function latestBackup($backupPaths){
$latest = readlink(dirname($backupPaths[0]));
$latestDay = explode("/",$latest);
$latestDay = explode("-",$latestDay[4]);
$latestDay = $latestDay[1];
return $latestDay;
}
function backupPaths($homeid){
$dir = "/sdb1/backup/gameserver";
$backupPaths = glob("$dir/*/$homeid", GLOB_ONLYDIR);
return $backupPaths;
}
function serverINFO($serverid) { // returns serverINFO Array
$xmlData = simplexml_load_file("/sdb1/backup/servers.xml");
foreach ($xmlData->server as $server) {
if ($server->servername == $serverid) {
$serverINFO[servername] = "$server->servername";
$serverINFO[serverlogin] = "$server->login";
$serverINFO[serverpass] = "$server->pass";
$serverINFO[homedir] = "$server->files";
$serverINFO[backupdir] = "$server->backupdir";
}
}
return $serverINFO;
}
function customSearch($keyword, $arrayToSearch){
foreach($arrayToSearch as $key => $arrayItem){
if( stristr($arrayItem, $keyword)){
return $key;
}
}
}
// quick way to print the array, I got tired of typing this during testing
function printArray($array){
echo "<br>PrintArray<pre>";
print_r($array);
echo "</pre><br>";
}

View file

@ -1,14 +0,0 @@
<?php
//- version
//- name
//- menu entries
//- sql installation queries
//* navigation.xml (OPTIONAL):
$module_title = "Backup/Restore";
$module_version = "0.2";
$db_version = 0;
$module_required = false;
?>

View file

@ -1,37 +0,0 @@
<?php
/*
*
* OGP - Open Game Panel
* Copyright (C) 2008 - 2018 The OGP Development Team
*
* http://www.opengamepanel.org/
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
$module_buttons = array(
"<a class='monitorbutton' href='?m=backup-restore&amp;home_id=".$server_home['home_id']."'>
<img src='".check_theme_image("images/backup-restore.png")." title='Restore/backup'>
<span>Backup/Restore</span>
</a>"
);
/*
* href='http://host.iaregamer.com/panel/modules/restore/restore.php' target='_blank'>
*
* "<a class='monitorbutton' href='?m=ftp&amp;home_id=".$server_home['home_id']."'>
*/
?>

View file

@ -1,3 +0,0 @@
<navigation>
<page key="default" file="backup-restore.php" access="user,admin" />
</navigation>

File diff suppressed because one or more lines are too long

View file

@ -1,11 +0,0 @@
#!/bin/bash
# --dry-run
sshpass -p S4wihr6q8rzc! \
rsync -avP --delete -e "ssh -p 12322" \
--link-dest /sdb1/backup/gameserver/00-latest-kcwin.D.drive \
cyg_server@kcwin.iaregamer.com:/cygdrive/d/OGP64/home/gameserver/1437 \
/sdb1/backup/gameserver/07-Sunday-kcwin.D.drive/1437