forked from poppyred/1.6.x
/
exec.system.php
executable file
·135 lines (103 loc) · 4.91 KB
/
exec.system.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
<?php
include_once(dirname(__FILE__).'/ressources/class.templates.inc');
include_once(dirname(__FILE__).'/ressources/class.ini.inc');
include_once(dirname(__FILE__).'/ressources/class.os.system.inc');
include_once(dirname(__FILE__).'/framework/frame.class.inc');
if(posix_getuid()<>0){die("Cannot be used in web server mode\n\n");}
if(!Build_pid_func(__FILE__,"MAIN")){
events(basename(__FILE__)." Already executed.. aborting the process");
die();
}
if($argv[1]=="--proxy"){PROXY();die();}
if($argv[1]=="--sys-paquages"){SYNC_PACKAGES();die();}
function PROXY(){
$ini=new Bs_IniHandler();
$sock=new sockets();
$ini->loadString($sock->GET_INFO("ArticaProxySettings"));
$ArticaProxyServerEnabled=$ini->_params["PROXY"]["ArticaProxyServerEnabled"];
$ArticaProxyServerName=$ini->_params["PROXY"]["ArticaProxyServerName"];
$ArticaProxyServerPort=$ini->_params["PROXY"]["ArticaProxyServerPort"];
$ArticaProxyServerUsername=$ini->_params["PROXY"]["ArticaProxyServerUsername"];
$ArticaProxyServerUserPassword=$ini->_params["PROXY"]["ArticaProxyServerUserPassword"];
$ArticaCompiledProxyUri=$ini->_params["PROXY"]["ArticaCompiledProxyUri"];
if(trim($ArticaProxyServerEnabled)<>"yes"){PROXY_DELETE();return;}
if(trim($ArticaProxyServerName==null)){PROXY_DELETE();return;}
if(trim($ArticaProxyServerPort==null)){$ArticaProxyServerPort=80;}
if(!is_numeric($ArticaProxyServerPort)){$ArticaProxyServerPort=80;}
if($ArticaProxyServerUsername<>null){
$pattern="$ArticaProxyServerUsername";
if($ArticaProxyServerUserPassword<>null){
$pattern=$pattern.":$ArticaProxyServerUserPassword";
}
$pattern=$pattern."@";
}
echo "Starting......: ".date("H:i:s")." Using proxy $ArticaProxyServerName:$ArticaProxyServerPort\n";
$proxypattern="http://$pattern$ArticaProxyServerName:$ArticaProxyServerPort";
$f=explode("\n",@file_get_contents("/etc/environment"));
while (list ($key, $line) = each ($f) ){
if(preg_match("#^HTTP_PROXY#i",$line)){unset($f[$key]);}
}
$f[]="http_proxy=$proxypattern";
if(is_dir("/etc/profile.d")){
$t[]="#!/bin/sh";
$t[]="HTTP_PROXY=$proxypattern";
$t[]="for i in NEWSPOST_PROXY NEWSREPLY_PROXY NEWS_PROXY WAIS_PROXY SNEWSREPLY_PROXY FINGER_PROXY HTTPS_PROXY FTP_PROXY CSO_PROXY SNEWSPOST_PROXY NNTP_PROXY GOPHER_PROXY SNEWS_PROXY; do";
$t[]="export \$i=\$HTTP_PROXY; done";
$t[]="unset i";
@file_put_contents("/etc/profile.d/proxy-mycompany.sh", @implode("\n", $t));
@chmod("/etc/profile.d/proxy-mycompany.sh", 0755);
}
@file_put_contents("/root/.wgetrc",@implode("\n",$f));
@file_put_contents("/etc/profile.local",@implode("\n",$f));
@file_put_contents("/etc/environment",@implode("\n",$f));
if(is_dir("/etc/apt/apt.conf.d")){
echo "Starting......: ".date("H:i:s")." Using proxy with apt-get, apt-mirror...\n";
@file_put_contents("/etc/apt/apt.conf.d/proxy","Acquire::http::Proxy \"$proxypattern\";");
}
}
function PROXY_DELETE(){
$save=false;
$f=explode("\n",@file_get_contents("/etc/environment"));
while (list ($key, $line) = each ($f) ){
if(preg_match("#^HTTP_PROXY#i",$line)){unset($f[$key]);}
}
if(is_file("/etc/profile.local")){
@unlink("/etc/profile.local");
}
if($save){@file_put_contents("/etc/environment",@implode("\n",$f));}
if(is_file("/etc/apt/apt.conf.d/proxy")){@unlink("/etc/apt/apt.conf.d/proxy");}
if(is_file("/etc/profile.d/proxy-mycompany.sh")){@unlink("/etc/profile.d/proxy-mycompany.sh");}
}
function SYNC_PACKAGES(){
$pidfile="/etc/artica-postfix/pids/".basename(__FILE__).".".__FUNCTION__.".pid";
$unix=new unix();
$aptget=$unix->find_program("apt-get");
$pid=@file_get_contents($pidfile);
if($unix->process_exists($pid)){
echo "Already exists PID $pid\n";
return;
}
@file_put_contents($pidfile,getmypid());
$time=time();
exec("/usr/share/artica-postfix/bin/setup-ubuntu --check-base-system 2>&1",$results);
while (list ($key, $line) = each ($results) ){
if(preg_match("#Use.+?apt-get autoremove.+?to remove them#")){
exec("$aptget autoremove -y -q 2>&1",$autoremove);
}
}
$message_text= @implode("\n",$results);
if(count($autoremove)>0){
$message_text=$message_text." Auto-remove task:\n".@implode("\n",$autoremove);
}
$time_text=$unix->distanceOfTimeInWords($time,time(),true);
$unix->send_email_events("Synchronize paquages done ($time_text)",@implode("\n",$message_text),"system");
shell_exec('/bin/rm -f /usr/share/artica-postfix/ressources/logs/cache/*');
shell_exec('/bin/rm -f /usr/share/artica-postfix/ressources/logs/jGrowl-new-versions.txt');
shell_exec('/bin/rm -f /etc/artica-postfix/versions.cache');
shell_exec('/bin/rm -f /usr/share/artica-postfix/ressources/logs/global.versions.conf');
shell_exec('/usr/share/artica-postfix/bin/artica-install --write-versions');
$unix->Process1(true);
shell_exec('/etc/init.d/artica-status reload &');
shell_exec('/etc/init.d/artica-postfix restart artica-exec &');
shell_exec('rm -rf /usr/share/artica-postfix/ressources/web/logs/*.cache');
}