forked from poppyred/1.6.x
/
exec.vmwaretools.php
executable file
·227 lines (169 loc) · 6.8 KB
/
exec.vmwaretools.php
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
<?php
if(posix_getuid()<>0){die("Cannot be used in web server mode\n\n");}
include_once(dirname(__FILE__).'/ressources/class.templates.inc');
include_once(dirname(__FILE__).'/ressources/class.ini.inc');
include_once(dirname(__FILE__).'/ressources/class.users.menus.inc');
include_once(dirname(__FILE__).'/ressources/class.mysql.inc');
include_once(dirname(__FILE__).'/ressources/class.os.system.inc');
include_once(dirname(__FILE__).'/ressources/class.mount.inc');
include_once(dirname(__FILE__)."/framework/class.unix.inc");
include_once(dirname(__FILE__)."/framework/frame.class.inc");
$GLOBALS["DEBUG"]=false;
$GLOBALS["VERBOSE"]=false;
$GLOBALS["LOGFILE"]="/usr/share/artica-postfix/ressources/logs/vmtools.debug";
if(preg_match("#--verbose#",implode(" ",$argv))){
ini_set('display_errors', 1); ini_set('html_errors',0);ini_set('display_errors', 1);ini_set('error_reporting', E_ALL);
$GLOBALS["DEBUG"]=true;$GLOBALS["VERBOSE"]=true;}
$unix=new unix();
$pidfile="/etc/artica-postfix/pids/".basename(__FILE__).".pid";
$pid=@file_get_contents($pidfile);
if($pid<100){$pid=null;}
$unix=new unix();
if($unix->process_exists($pid,basename(__FILE__))){events("PID: $pid Already exists....");die();}
if($argv[1]=="--cd"){installapt();die();}
if($argv[1]=="--path"){@unlink($GLOBALS["LOGFILE"]);installapt($argv[2]);die();}
if($argv[1]=="--install"){@unlink($GLOBALS["LOGFILE"]);installapt($argv[2]);die();}
function installapt(){
@unlink($GLOBALS["LOGFILE"]);
$unix=new unix();
$mount=$unix->find_program("mount");
$umount=$unix->find_program("umount");
$tar=$unix->find_program("tar");
$rm=$unix->find_program("rm");
echo "Please wait...\n";
build_progress("{update_debian_repository}",5);
$aptget=$unix->find_program("apt-get");
build_progress("{updating_repository}",15);
echo "Please wait, running apt-get install\n";
$cmd="DEBIAN_FRONTEND=noninteractive $aptget --force-yes update";
system($cmd);
build_progress("{INSTALL_VMWARE_TOOLS}",50);
$unix->DEBIAN_INSTALL_PACKAGE("open-vm-tools");
if(!is_file("/usr/bin/vmware-toolbox-cmd")){
build_progress("{INSTALL_VMWARE_TOOLS} {failed_to_install}",110);
return;
}
build_progress("{INSTALL_VMWARE_TOOLS} {success}",90);
build_progress("{removing_caches}",95);
$unix->REMOVE_INTERFACE_CACHE();
build_progress("{success}",100);
}
function installbycd(){
@unlink($GLOBALS["LOGFILE"]);
$unix=new unix();
$mount=$unix->find_program("mount");
$umount=$unix->find_program("umount");
$tar=$unix->find_program("tar");
$rm=$unix->find_program("rm");
build_progress(5, "Mounting media...");
if(!is_media_mounted()){
events("Mount the CD-ROM on /media/cdrom0...");
exec("$mount /media/cdrom0 2>&1",$results);
while (list ($i, $line) = each ($results)){events("$line");}
}
if(!is_media_mounted()){
build_progress(110, "Failed to Mount the CD-ROM");
events("Failed to Mount the CD-ROM on /media/cdrom0...");
return;
}
$SourceFile=LatestVmSourcePackage("/media/cdrom0");
build_progress(10, "$SourceFile");
if($SourceFile==null){
build_progress(110, "Failed to find VMWare Tools Source");
events("Failed to find VMWare Tools Source package File on /media/cdrom0");
shell_exec("$umount -l /media/cdrom0 &");
return;
}
installbyPath($SourceFile);
shell_exec("$umount -l /media/cdrom0 &");
}
function installbyPath($SourceFile){
$unix=new unix();
$mount=$unix->find_program("mount");
$umount=$unix->find_program("umount");
$tar=$unix->find_program("tar");
$rm=$unix->find_program("rm");
if(!is_file($SourceFile)){
build_progress(110, "$SourceFile no such file");
events("Failed $SourceFile no such file...");
return;
}
build_progress(15, "Extracting ".basename($SourceFile));
events("Extract ". basename($SourceFile)." Source package...");
if(is_dir("/root/VMwareArticaInstall")){recursive_remove_directory("/root/VMwareArticaInstall");}
@mkdir("/root/VMwareArticaInstall",0640,true);
shell_exec("$tar -xf $SourceFile -C /root/VMwareArticaInstall/");
events("Extract ". basename($SourceFile)." Source package done");
build_progress(20, "Extracting ".basename($SourceFile)." success");
if(!is_file("/root/VMwareArticaInstall/vmware-tools-distrib/vmware-install.pl")){
build_progress(110, "vmware-install.pl no such file");
events("Failed /root/VMwareArticaInstall/vmware-tools-distrib/vmware-install.pl no such file");
recursive_remove_directory("/root/VMwareArticaInstall");
return;
}
build_progress(25, "Execute the setup...");
events("Launch setup vmware-install.pl");
if(!is_dir("/root/VMwareArticaInstall/vmware-tools-distrib")){
events("Failed /root/VMwareArticaInstall/vmware-tools-distrib no such directory");
build_progress(110, "vmware-tools-distrib no such directory");
return;
}
chdir("/root/VMwareArticaInstall/vmware-tools-distrib");
events("Installing VMWare Tools....");
$results=array();
exec("./vmware-install.pl --default 2>&1",$results);
while (list ($i, $line) = each ($results)){events("$line");}
build_progress(50, "Removing package");
recursive_remove_directory("/root/VMwareArticaInstall");
if(file_exists("/etc/init.d/vmware-tools")){
build_progress(55, "Starting VMWare Tools service");
events("Starting VMWare Tools service");
$results=array();
exec("/etc/init.d/vmware-tools start",$results);
while (list ($i, $line) = each ($results)){events("$line");}
}
if(file_exists("/usr/bin/vmware-toolbox-cmd")){
events("VMWare Tools installed");
$results=array();
exec("/usr/bin/vmware-toolbox-cmd -v 2>&1",$results);
while (list ($i, $line) = each ($results)){events("$line");}
}
if(is_dir("/root/VMwareArticaInstall")){recursive_remove_directory("/root/VMwareArticaInstall");}
build_progress(80, "Indexing softwares database");
events("Indexing softwares database");
shell_exec("/usr/share/artica-postfix/bin/process1 --force --verbose ".time());
}
function LatestVmSourcePackage($path){
echo "Scanning $path\n";
foreach (glob("$path/*.gz") as $filename) {
echo "Checks $filename\n";
if(preg_match("#VMwareTools(.+?)\.tar\.gz#", $filename)){return $filename;}
}
}
function is_media_mounted(){
$mount=new mount();
return $mount->ismounted("/media/cdrom0");
}
function build_progress($text,$pourc){
$cachefile="/usr/share/artica-postfix/ressources/logs/vmware.install.progress";
if(is_numeric($text)){
$array["POURC"]=$text;
$array["TEXT"]=$pourc;
}else{
$array["POURC"]=$pourc;
$array["TEXT"]=$text;
}
@file_put_contents($cachefile, serialize($array));
@chmod($cachefile,0755);
}
function events($text){
$pid=@getmypid();
$date=@date("H:i:s");
echo "$date [$pid]:".basename(__FILE__).": $text\n";
$size=@filesize($GLOBALS["LOGFILE"]);
if($size>1000000){@unlink($GLOBALS["LOGFILE"]);}
$f = @fopen($GLOBALS["LOGFILE"], 'a');
@fwrite($f, "$date [$pid]:".basename(__FILE__).": $text\n");
@fclose($f);
@chmod($GLOBALS["LOGFILE"], 0777);
}