Skip to content

Commit

Permalink
Version 1.1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
dirtyredz committed Jun 26, 2017
1 parent d3d636c commit c4447aa
Show file tree
Hide file tree
Showing 23 changed files with 825 additions and 153 deletions.
18 changes: 17 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
1.1.5
Fixed HighScore.php being erased on update
Added commands enablerestart and disablerestart
Added manager options -d, -o, -b, -v
Added Mail parsing to player parser
Added Mail player page net worth to net worth column
Added Mail resources/money to player page
Added file detection to zlib decompressor
Fixed Session not renewing when the browser is left open for a long period of time
Changed display of graphs to include small definitions and better font styles
Changed font styles for configuration page
Updated help output of manager
Changed Alliance Icon
Improved zlib decompression script
Added Scripts memory graphs

1.1.4
Fixed player flags
Replaced grep command with php for loop in player list of home page
Expand All @@ -10,7 +26,7 @@
Added Alliance To players parser
Added Alliance Parser to cron job
Added manager-config options to adjust cronjob times for data parser scripts

1.1.3
Fixed Variable name in manager for default IPAddress

Expand Down
9 changes: 5 additions & 4 deletions avorion-manager/GetAllianceData.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,22 @@ echo "<?php" > $AllianceDataTmp;
echo "\$AllianceData = array(" >> $AllianceDataTmp;
for i in {1..5000}
do
find ${DIR}/${GALAXYNAME}/alliances/ -name \*.tmp -delete
file=${DIR}/${GALAXYNAME}/alliances/alliance_$i.dat.0
[ -e "$file" ] || continue
file=$(ls -t ${DIR}/${GALAXYNAME}/alliances/alliance_$i.dat.* | head -1)
[ -e "$file" ] || continue
dd if=$file bs=1 skip=44 of=${file}.tmp > /dev/null 2>&1
php -f ${PWD}/avorion-manager/zlib_Uncompress.php "${file}.tmp" "AllianceUncompressed.tmp"
rm ${file}.tmp
#dd if=$file bs=1 skip=44 of=${file}.tmp > /dev/null 2>&1
php -f ${PWD}/avorion-manager/zlib_Uncompress.php "${file}" "AllianceUncompressed.tmp"
#rm ${file}.tmp
OriginalFile=$file
file=AllianceUncompressed.tmp
NameStart=$(grep -b -a -o -P 'name' "${file}" | sed 's/:.*//' | head -n1)
if [ "${NameStart}" ]; then
ID=$(echo $OriginalFile | sed -e 's/.*_//g' -e 's/.dat.*//g')
Name=$(xxd -ps -l 50 -seek "$((${NameStart} + 16 ))" "${file}" | xxd -r -p | head -n1)
LeaderStart=$(grep -b -a -o -P 'leader' "${file}" | sed 's/:.*//' | head -n1)
Leader=$(xxd -ps -l 4 -seek "$((${LeaderStart} + 11 ))" "${file}")
Leader=$(xxd -ps -l 4 -seek "$((${LeaderStart} + 14 ))" "${file}")

MoneyStart=$(grep -b -a -o -P 'money64' "${file}" | sed 's/:.*//' | head -n1)
Money=$(xxd -ps -l 4 -seek "$((${MoneyStart} + 15 ))" "${file}" )
Expand Down
129 changes: 116 additions & 13 deletions avorion-manager/GetPlayerData.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ echo "<?php" > $PlayerDataTmp;
echo "\$PlayerData = array(" >> $PlayerDataTmp;
for i in {1..10000}
do
find ${DIR}/${GALAXYNAME}/players/ -name \*.tmp -delete
file=${DIR}/${GALAXYNAME}/players/player_$i.dat.0
[ -e "$file" ] || continue
file=$(ls -t ${DIR}/${GALAXYNAME}/players/player_$i.dat.* | head -1)
[ -e "$file" ] || continue
dd if=$file bs=1 skip=44 of=${file}.tmp > /dev/null 2>&1
php -f ${PWD}/avorion-manager/zlib_Uncompress.php "${file}.tmp" "PlayerUncompressed.tmp"
rm ${file}.tmp
#dd if=$file bs=1 skip=44 of=${file}.tmp > /dev/null 2>&1
php -f ${PWD}/avorion-manager/zlib_Uncompress.php "${file}" "PlayerUncompressed.tmp"
#rm ${file}.tmp
OriginalFile=$file
file=PlayerUncompressed.tmp
StartingPositionName=$(grep -b -a -o -P 'name' "${file}" | sed 's/:.*//' | head -n1 | awk '{SUM = $1 + 13 } END {print SUM}')
Expand Down Expand Up @@ -53,20 +54,122 @@ do
#Were seen in console add today
LastSeen=$(/bin/date +\%Y-\%m-\%d)
fi

#Mail Money
MailCheck=$(grep -b -a -o -P 'mail_items' "${file}" | sed 's/:.*//' | head -n1)
MailHeader=$(xxd -ps -l 6 -seek "$((${MailCheck} + 33 ))" "${file}" | xxd -r -p | head -n1)
MailCount=0
MailMoney='array()'
MailIron='array()'
MailTitanium='array()'
MailNaonite='array()'
MailTrinium='array()'
MailXanion='array()'
MailOgonite='array()'
MailAvorion='array()'
if [[ "$MailHeader" == "header" ]]; then
MailStart=$(grep -b -a -o -P 'money64' "${file}" | sed 's/:.*//' | head -n1)
MailCount=$(xxd -ps -l 1 -seek "$((${MailStart} + 11 ))" "${file}")
MailCount=$((0x$MailCount))
Count=15
Index=1
MailMoney='array('
until [ $Index -gt $MailCount ]
do
MailMoney=$MailMoney'"'$(xxd -ps -l 8 -seek "$((${MailStart} + $Count ))" "${file}")'",'
Count=$(($Count+8))
Index=$(($Index+1))
done
MailMoney=$MailMoney')'

#MailResources
MailResourcesStart=$(grep -b -a -o -P 'resources640' "${file}" | sed 's/:.*//' | head -n1)
Count=20
Index=1
MailIron='array('
until [ $Index -gt $MailCount ]
do
MailIron=$MailIron'"'$(xxd -ps -l 8 -seek "$((${MailResourcesStart} + $Count ))" "${file}")'",'
Count=$(($Count+8))
Index=$(($Index+1))
done
MailIron=$MailIron')'
Count=$(($Count+24))
Index=1
MailTitanium='array('
until [ $Index -gt $MailCount ]
do
MailTitanium=$MailTitanium'"'$(xxd -ps -l 8 -seek "$((${MailResourcesStart} + $Count ))" "${file}")'",'
Count=$(($Count+8))
Index=$(($Index+1))
done
MailTitanium=$MailTitanium')'
Count=$(($Count+24))
Index=1
MailNaonite='array('
until [ $Index -gt $MailCount ]
do
MailNaonite=$MailNaonite'"'$(xxd -ps -l 8 -seek "$((${MailResourcesStart} + $Count ))" "${file}")'",'
Count=$(($Count+8))
Index=$(($Index+1))
done
MailNaonite=$MailNaonite')'
Count=$(($Count+24))
Index=1
MailTrinium='array('
until [ $Index -gt $MailCount ]
do
MailTrinium=$MailTrinium'"'$(xxd -ps -l 8 -seek "$((${MailResourcesStart} + $Count ))" "${file}")'",'
Count=$(($Count+8))
Index=$(($Index+1))
done
MailTrinium=$MailTrinium')'
Count=$(($Count+24))
Index=1
MailXanion='array('
until [ $Index -gt $MailCount ]
do
MailXanion=$MailXanion'"'$(xxd -ps -l 8 -seek "$((${MailResourcesStart} + $Count ))" "${file}")'",'
Count=$(($Count+8))
Index=$(($Index+1))
done
MailXanion=$MailXanion')'
Count=$(($Count+24))
Index=1
MailOgonite='array('
until [ $Index -gt $MailCount ]
do
MailOgonite=$MailOgonite'"'$(xxd -ps -l 8 -seek "$((${MailResourcesStart} + $Count ))" "${file}")'",'
Count=$(($Count+8))
Index=$(($Index+1))
done
MailOgonite=$MailOgonite')'
Count=$(($Count+24))
Index=1
MailAvorion='array('
until [ $Index -gt $MailCount ]
do
MailAvorion=$MailAvorion'"'$(xxd -ps -l 8 -seek "$((${MailResourcesStart} + $Count ))" "${file}")'",'
Count=$(($Count+8))
Index=$(($Index+1))
done
MailAvorion=$MailAvorion')'
fi
#Other Stuff
AllianceStart=$(grep -b -a -o -P 'alliance' "${file}" | sed 's/:.*//' | head -n1)
Alliance=$(xxd -ps -l 1 -seek "$((${AllianceStart} + 16 ))" "${file}")
Alliance=$(xxd -ps -l 4 -seek "$((${AllianceStart} + 16 ))" "${file}")
StartingPosition=$(grep -b -a -o -P 'play_time' "${file}" | sed 's/:.*//' | tail -n1)
SteamID=$(xxd -ps -l 8 -seek "$((${StartingPosition} - 39 ))" "${file}" )
Money=$(xxd -ps -l 4 -seek "$((${StartingPosition} - 12 ))" "${file}" )
Iron=$(xxd -ps -l 4 -seek "$((${StartingPosition} + 45 ))" "${file}" )
Titanium=$(xxd -ps -l 4 -seek "$((${StartingPosition} + 77 ))" "${file}" )
Naonite=$(xxd -ps -l 4 -seek "$((${StartingPosition} + 109 ))" "${file}" )
Trinium=$(xxd -ps -l 4 -seek "$((${StartingPosition} + 141 ))" "${file}" )
Xanion=$(xxd -ps -l 4 -seek "$((${StartingPosition} + 173 ))" "${file}" )
Ogonite=$(xxd -ps -l 4 -seek "$((${StartingPosition} + 205 ))" "${file}" )
Avorion=$(xxd -ps -l 4 -seek "$((${StartingPosition} + 237 ))" "${file}" )
Money=$(xxd -ps -l 8 -seek "$((${StartingPosition} - 12 ))" "${file}" )
Iron=$(xxd -ps -l 8 -seek "$((${StartingPosition} + 45 ))" "${file}" )
Titanium=$(xxd -ps -l 8 -seek "$((${StartingPosition} + 77 ))" "${file}" )
Naonite=$(xxd -ps -l 8 -seek "$((${StartingPosition} + 109 ))" "${file}" )
Trinium=$(xxd -ps -l 8 -seek "$((${StartingPosition} + 141 ))" "${file}" )
Xanion=$(xxd -ps -l 8 -seek "$((${StartingPosition} + 173 ))" "${file}" )
Ogonite=$(xxd -ps -l 8 -seek "$((${StartingPosition} + 205 ))" "${file}" )
Avorion=$(xxd -ps -l 8 -seek "$((${StartingPosition} + 237 ))" "${file}" )
PlayTime=$(xxd -ps -l 4 -seek "$((${StartingPosition} + 17 ))" "${file}" )
echo "array(\"ID\" => \"$ID\",\"Name\" => \"$Name\",\"Alliance\" => \"$Alliance\",\"LastSeen\" => \"$LastSeen\",\"Group\" => \"$Group\",\"SteamID\" => \"$SteamID\",\"PlayTime\" => \"$PlayTime\",\"Money\" => \"$Money\",\"Iron\" => \"$Iron\",\"Titanium\" => \"$Titanium\",\"Naonite\" => \"$Naonite\",\"Trinium\" => \"$Trinium\",\"Xanion\" => \"$Xanion\",\"Ogonite\" => \"$Ogonite\",\"Avorion\" => \"$Avorion\")," >> $PlayerDataTmp;
echo "array(\"ID\" => \"$ID\",\"Name\" => \"$Name\",\"Alliance\" => \"$Alliance\",\"LastSeen\" => \"$LastSeen\",\"Group\" => \"$Group\",\"SteamID\" => \"$SteamID\",\"PlayTime\" => \"$PlayTime\",\"Money\" => \"$Money\",\"Iron\" => \"$Iron\",\"Titanium\" => \"$Titanium\",\"Naonite\" => \"$Naonite\",\"Trinium\" => \"$Trinium\",\"Xanion\" => \"$Xanion\",\"Ogonite\" => \"$Ogonite\",\"Avorion\" => \"$Avorion\",\"MailCount\" => \"$MailCount\",\"MailMoney\" => $MailMoney,\"MailIron\" => $MailIron,\"MailTitanium\" => $MailTitanium,\"MailNaonite\" => $MailNaonite,\"MailTrinium\" => $MailTrinium,\"MailXanion\" => $MailXanion,\"MailOgonite\" => $MailOgonite,\"MailAvorion\" => $MailAvorion)," >> $PlayerDataTmp;
fi
done
echo ");" >> $PlayerDataTmp;
Expand Down
6 changes: 3 additions & 3 deletions avorion-manager/GetSectorData.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ for file in ${DIR}/${GALAXYNAME}/sectors/*v; do
if [[ $FACTIONINDEX == 200* ]];
then
FactionFile=${DIR}/${GALAXYNAME}/factions/faction_${FACTIONINDEX}.dat
dd if=$FactionFile bs=1 skip=44 of=${FactionFile}.tmp > /dev/null 2>&1
php -f ${PWD}/avorion-manager/zlib_Uncompress.php "${FactionFile}.tmp" "SectorUncompressed.tmp"
rm ${FactionFile}.tmp
#dd if=$FactionFile bs=1 skip=44 of=${FactionFile}.tmp > /dev/null 2>&1
php -f ${PWD}/avorion-manager/zlib_Uncompress.php "${FactionFile}" "SectorUncompressed.tmp"
#rm ${FactionFile}.tmp
FactionFile=SectorUncompressed.tmp

StartingPositionStateForm=$(grep -b -a -o -P 'state_form' ${FactionFile} | sed 's/:.1*//' | head -n1 | awk '{SUM = $1 + 16 } END {print SUM}')
Expand Down
4 changes: 4 additions & 0 deletions avorion-manager/PHPConfig.ini
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ AccessDiscoveredMapPage=0
AccessFactionsMapPage=0
;The role level required to view the Graphs page. (0=public)
AccessGraphsPage=0
;The role level required to view the Profile page. (0=public)
AccessProfilePage=0
;The role level required to view the User Management page. (0=public)
AccessUserManagmentPage=30
;The role level required to view the Space Invaders page. (0=public)
Expand All @@ -52,6 +54,8 @@ UpdatesGraph=10
CpuUsageGraph=10
;The role level required to view the Server Memory Usage graph on the graphs page. (0=public)
MemoryUsageGraph=10
;The role level required to view the Server Script Memory Usage graph on the graphs page. (0=public)
ScriptMemoryGraph=10
;The role level required to run commands in the console page. (0=public)
ConsoleCommandsAccess=40
;The role level required to run the /stop command in the console page. (0=public)
Expand Down
2 changes: 1 addition & 1 deletion avorion-manager/UpdateManager.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ if [ "${CurrentVersion}" != "${VERSION}" ]; then
cp avorion-manager/PHPConfig.ini avorion-manager/PHPConfig.ini.backup
fi

tar -xvf UpdateDirtyServerManager.tar.gz --exclude='Database.php' --exclude='avorion-manager/PlayerData.php' --exclude='avorion-manager/SectorData.php' --exclude='avorion-manager/logs'
tar -xvf UpdateDirtyServerManager.tar.gz --exclude='Database.php' --exclude='avorion-manager/HighScore.php' --exclude='avorion-manager/PlayerData.php' --exclude='avorion-manager/SectorData.php' --exclude='avorion-manager/logs'

if [ -f manager-config.ini.old ]; then
sed -i 's/^;.*//g' manager-config.ini.old
Expand Down
49 changes: 49 additions & 0 deletions avorion-manager/core/ProfileParser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/**
*/
class ProfileParser
{
/** @var string $FilePath Stores the filepath when parsing so we can write back to same file */
protected $FilePath;
/** @var array $ParsedData Array of INI options and values */
public $ParsedData;
/** @var boolean $Success used to verify when an INI file has been successfully parsed */
public $Success;
/**
* Constructor.
*/
public function __construct($File)
{
//sets the filepath to be used later
$this->FilePath = $File;

$this->parse($File);
}

/**
* Parses through an INI file storing results into an array
* @method ParseINI
* @param string $File File location you wish to parse
*/
private function Parse($File)
{

//test if file exsists the parse
if(file_exists($File) === true){
//ignore errors well write our own if failed
$this->ParsedData = @file_get_contents($File);
}else{
//create empty array since the file doesnt exsist
$this->ParsedData = [];
}
//Weve completed the parsing
$this->Success = true;
//if the file exists but returned false due to an error
if(false === $this->ParsedData){
//parsing failed reset $Succes
$this->Success = false;
throw new \Exception(sprintf('Unable to parse file : %s', $this->FilePath));
}
}

}
16 changes: 16 additions & 0 deletions avorion-manager/core/RefreshController.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,22 @@ public function GetCpuUsage()
}
}

/**
* Verifies Role access of logged in user and returns generated graph detail
* Script Memory Usage, Generated every 5 mins by the manager/cron job
* Requires Class to be constructed with GET 'Range'
* @method GetServerScriptMemoryGraph
* @return string json_encoded array of graph details
*/
public function GetServerScriptMemoryGraph()
{
//checks logged in users role against config options
if($this->RoleAccess($this->Config['ScriptMemoryGraph'])){
//Gets the Graph array from the model and return
echo json_encode($this->RefreshModel->GetServerScriptMemoryGraph());
}
}

/**
* Verifies Role access of logged in user and returns generated graph detail
* Memory Usage of physical server. Generated every 5 mins by the manager/cron job
Expand Down
49 changes: 47 additions & 2 deletions avorion-manager/core/RefreshModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,51 @@ public function GetServerLoadGraph()
return $PlotlyData;
}

/**
* Pulls Server script memory from Status.logs and builds graphing data into an array
* @method GetServerScriptMemoryGraph
* @return array Plotly Graph Data
*/
public function GetServerScriptMemoryGraph()
{
//If no status.log file exsists return an empty array
if(!is_file(dirname(__FILE__).'/../logs/'.date('d-m-Y').'_status.log')){
return array();
}

$Time = `grep -h "Memory used by scripts" $(find {$this->Config['LogsDir']}/*_status.log -printf '%T+ %p\n' | sort -n | sed -e 's/.* //g') | tail -n {$this->Range} | sed -e 's/|.*//g' -e 's/-/:/g3' | tr ' ' 'T' | sed -e 's/..$/00/' | awk '{print q $0 q}' ORS=','`;
$Data = `grep -h "Memory used by scripts" $(find {$this->Config['LogsDir']}/*_status.log -printf '%T+ %p\n' | sort -n | sed -e 's/.* //g') | tail -n {$this->Range} | sed -e 's/.*://g' | tr -d '[:blank:]' | awk '{print q $0 q}' ORS=','`;
/** @var array $Time array of each 5 minute /status command ran withen Range of the Timestamp */
$Time = explode(',',$Time);
/** @var array $Data array of each 5 minute /status command ran withen Range of Server Load */
$Data = explode(',',$Data);

//Remove the last index since awk will always add an additional , at the end
array_pop($Time);
array_pop($Data);
foreach ($Data as $key => $value) {
$ident = substr($value, strlen($value)-2);
$Data[$key] = substr($value, 0, -2);
if($ident == 'GB'){
$Data[$key] *= 1024;
}
}
//Fix array inconsistancys with the $Timearray
list ($Time, $Data) = $this->RunThoughTimeArray($Time, $Data);
//Build Plotly data and return

$PlotlyData = [[
'x' => $Time,
'y' => $Data,
'type' => 'scatter',
'fill' => 'tozeroy',
'text' => 'MB',
'hoverinfo'=>'x+y+text',
'fillcolor' => 'rgba(168, 216, 234, 0.5)'
]];
return $PlotlyData;
}

/**
* Pulls the server(physical) from the status.log's and generates a graph from it
* @method GetServerMemoryUsageGraph
Expand Down Expand Up @@ -666,7 +711,7 @@ public function SendKeys($Message)
{
//Theres a security risk I need to make sure i check for.
//Send the message through /send manager
shell_exec($this->Config['Manager'].' send PHP "'.addslashes($Message).'"');
shell_exec($this->Config['Manager'].' send -o PHP "'.addslashes($Message).'"');
//Log the message
$this->LogMessage('Console command entered: '.$Message);
}
Expand Down Expand Up @@ -704,7 +749,7 @@ public function GetServerTime()
public function GetConsoleData()
{
//Potentall config option to only grab the last x lines instead of everything
$Console = `cat {$this->Config['ConsoleLog']} | sed -e 's/</\&lt;/g' -e 's/>/\&gt;/g' -e 's/$/<br\/>/g'`;
$Console = `tail -n1000 {$this->Config['ConsoleLog']} | sed -e 's/</\&lt;/g' -e 's/>/\&gt;/g' -e 's/$/<br\/>/g'`;
return $Console;
}

Expand Down
Loading

0 comments on commit c4447aa

Please sign in to comment.