-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmodmgr.inc.php
More file actions
174 lines (149 loc) · 6.57 KB
/
modmgr.inc.php
File metadata and controls
174 lines (149 loc) · 6.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<?php
// Read in the information from the ModInfo.xml file
function readModInfo($fullPathToModInfoXML)
{
$fileArray=file($fullPathToModInfoXML);
foreach($fileArray as $line)
{
if(strpos($line,'Name value')!==FALSE) $rtn['Name']=extractValue($line);
if(strpos($line,'Description value')!==FALSE) $rtn['Description']=extractValue($line);
if(strpos($line,'Author value')!==FALSE) $rtn['Author']=extractValue($line);
if(strpos($line,'Version value')!==FALSE) $rtn['Version']=extractValue($line);
if(strpos($line,'Website value')!==FALSE) $rtn['Website']=extractValue($line);
}
return($rtn);
}
// Return only what is after the double-quote
// This is used in the readModInfo function
function extractValue($line)
{ $pieces=explode('"',$line); return($pieces[1]); }
// Returns True if the mod is enabled
function is_mod_enabled($INSTALL_DIR, $SymLinkString)
{
$result=exec("ls -l $INSTALL_DIR/Mods | grep \"$SymLinkString\"");
if(strlen($result)>1) return true;
else return false;
}
// Create the SymLink to enable a mod
function enable_mod($INSTALL_DIR, $MOD_DIR_PATH)
{
$name_Pieces=explode('/',$MOD_DIR_PATH);
$name_Position=count($name_Pieces)-1;
$ModName=$name_Pieces[$name_Position];
if(!is_dir("$INSTALL_DIR/Mods/$ModName"))
{
//echo "SymLink: $INSTALL_DIR/Mods/$ModName --> $MOD_DIR_PATH";
symlink($MOD_DIR_PATH,"$INSTALL_DIR/Mods/".$ModName);
}
}
// Remove the SymLink to disable a mod
function disable_mod($INSTALL_DIR, $MOD_DIR_PATH)
{
$name_Pieces=explode('/',$MOD_DIR_PATH);
$name_Position=count($name_Pieces)-1;
$ModName=$name_Pieces[$name_Position];
if(is_dir("$INSTALL_DIR/Mods/$ModName"))
{
//echo "REMOVING SYMLINK: $INSTALL_DIR/Mods/$ModName";
unlink("$INSTALL_DIR/Mods/$ModName");
}
}
function SDD_ModMgr()
{
$INSTALL_DIR="/data/7DTD";
$MODS_DIR="$INSTALL_DIR/Mods-Available";
//echo "PRINTING POST:";
//print_r($_POST);
// Build array of ModInfo.xml instances installed
$it = new RecursiveDirectoryIterator($MODS_DIR);
foreach(new RecursiveIteratorIterator($it) as $file)
{ if(basename($file)=='ModInfo.xml') $MOD_ARRAY[]=$file; }
// Perform any Modlet Updating, so that we can display the outcome right here on the page
if($_GET['update']!='')
{
$SUBDIRNAME=exec("cat $MODS_DIR/$_GET[update]/ModURL.txt | rev | cut -d/ -f1 | rev | sed 's|.git||g'");
$GITDIRNAME="$MODS_DIR/$_GET[update]/$SUBDIRNAME";
$command="cd $GITDIRNAME && /usr/bin/git pull";
$command_output=exec($command);
$rtn="<table cellspacing=0 border=1><tr><td><b>Update Command output:</b><br><font size=2><i>$ $command<br>$command_output</i></font></td></tr></table><br>";
}
// Perform update of the ServerMod Manager
if($_GET['smmupdate']==1)
{
$command="rm -rf $INSTALL_DIR/7dtd-servermod && cd $INSTALL_DIR && git clone https://github.com/XelaNull/7dtd-servermod.git && chmod a+x $INSTALL_DIR/7dtd-servermod/*.sh";
$command_output=exec($command);
$rtn="<table cellspacing=0 border=1><tr><td><b>Update Command output:</b><br><font size=2><i>$command_output</i></font></td></tr></table><br>";
}
if($_GET['smmreset']==1)
{
$command="rm -rf $INSTALL_DIR/Mods/* $INSTALL_DIR/Mods-Available/*; cd $INSTALL_DIR/7dtd-servermod && ./install_mods.sh $INSTALL_DIR && ./default_mods.sh";
$command_output=exec($command);
$rtn="<table cellspacing=0 border=1><tr><td><b>Reset Command output:</b><br><font size=2><i>$command_output</i></font></td></tr></table><br>";
}
// Show as a table
$rtn.="
<table id=\"myDummyTable\" class=\"tablesorter\" border=0 cellpadding=0 cellspacing=1>
<thead>
<tr>
<th> </td>
<th align=left><b>Name</b></th>
<th align=left width=120><b>DL / Update</b></th>
<th align=left><b>Description</b></th>
<th align=left><b>Author</b></th>
</tr>
</thead>
<tbody>
";
$modcnt=0;
// Loop through all the mods
foreach($MOD_ARRAY as $ModPath)
{
$modcnt++;
$FullModPath_ModInfoXML=$ModPath;
$FullModDir=str_replace('/ModInfo.xml','',$ModPath);
$modInfo_Array=readModInfo($FullModPath_ModInfoXML);
$ShortModPath=str_replace($MODS_DIR.'/','',$ModPath); // Strip off the MODS_DIR path prefix
$modPath_Pieces=explode('/',$ShortModPath);
$SymLinkString=$MODS_DIR.'/'.dirname($ShortModPath);
// echo "MOD_OUTPUT($SymLinkString)[$modcnt]: ".is_mod_enabled('/data/7DTD',$SymLinkString)."<br>";
if(is_mod_enabled('/data/7DTD',$SymLinkString))
{
$checkTXT='checked';
if(@$_POST['ModIDNum']==$modcnt && @$_POST["modID$modcnt"]!='on')
{ disable_mod($INSTALL_DIR,$FullModDir); $checkTXT=''; }
}
else
{
$checkTXT='';
if(@$_POST['ModIDNum']==$modcnt && @$_POST["modID$modcnt"]=='on')
{ enable_mod($INSTALL_DIR,$FullModDir); $checkTXT='checked'; }
}
if($_GET['disableall']==1) { disable_mod($INSTALL_DIR,$FullModDir); $checkTXT=''; }
elseif($_GET['enableall']==1) { enable_mod($INSTALL_DIR,$FullModDir); $checkTXT='checked'; }
if(@$modInfo_Array['Website']!='')
$Author="<a href=$modInfo_Array[Website]>$modInfo_Array[Author]</a>";
else $Author="$modInfo_Array[Author]";
// Collect the URL that we downloaded this mod from
@$URL=file_get_contents($MODS_DIR.'/'.$modPath_Pieces[0].'/ModURL.txt');
$PkgNum=$modPath_Pieces[0];
if(strpos($URL,'github')!==FALSE)
$update_Link="<a href=\"index.php?update=$PkgNum\" title=\"Perform GIT Pull to UPDATE Modlet\" ><img align=top height=28 src=update.png ALT=\"Perform GIT Pull to UPDATE Modlet\"></a>";
else $update_Link="";
if($URL!='') $download_Link="<td width=90 align=center><a href=\"$URL\" title=\"Download Modlet\" ><img align=top height=28 src=direct-download.png alt=\"Download Modlet\"></a> $update_Link</td>";
else $download_Link="<td>$update_Link</td>";
$rtn.="<tr><form method=post action=index.php?do=modmgr>
<td><input type=hidden name=ModIDNum value=$modcnt><input $checkTXT name=modID$modcnt type=checkbox onChange=\"this.form.submit();\"></td>
<td width=350><b>$modInfo_Array[Name]</b><br>Version: $modInfo_Array[Version]</td>
$download_Link
<td width=auto><font size=2>$modInfo_Array[Description]</font></td>
<td><font size=2>$Author</td>
</form>
</tr>";
}
$rtn.="</tbody>\n</table>";
$rtn.="<A href=?enableall=1>enable all</a> . <a href=?disableall=1>disable all</a>";
$rtn.="<br>Total Modlets: ".number_format(count($MOD_ARRAY))."<br>";
$rtn.="<a href=index.php?smmreset=1>Reset & Redownload all Mods</a>";
return($rtn);
}
?>