function syncApacheAuth() { # This setups files needed for apache authentication, using htpasswd command , from database, directories table.. # all these functions written by info@ehcp.net # ingilizce yazdigima bakmayin, bu programin orjinali turkcedir. Ben de Turkiyede yasiyorum. $this->requireCommandLine(__FUNCTION__); $tablename = $this->conf['passwddirectoriestable']['tablename']; # select directories first, $directories = $this->query("select distinct(directory) from " . $tablename . " where directory is not null and directory<>''"); print "dirs:"; print_r($directories); $dircount = 0; $conf = ''; passthru2("mkdir -p /etc/ehcp"); # then find users related to directories, and setup configuration for this.. # delete old htpasswd files: passthru("rm -rvf /etc/ehcp/htpasswd_*"); # this only fails when there are many files that linux cannot pass * as a parameter. # if i use passthru2 above, * is converted to \* and dont work... foreach ($directories as $d) { $dir = securefilename($d['directory']); $dircount++; $users = $this->query("select * from " . $tablename . " where directory='{$dir}'"); print "users related to dir: {$dir} \n"; print_r($users); if (!file_exists($dir)) { passthru2("mkdir -p {$dir}"); # setup dir if not exists... passthru2("chown {$this->ftpowner} -Rf {$dir}"); } if (!file_exists($dir . "/index.php") and !file_exists($dir . "/index.html")) { writeoutput($dir . "/index.php", "This is a password protected page... put here your own data... "); } $setup = ' -c '; # parameter to htpasswd command for first user creation $passwdfile = "/etc/ehcp/htpasswd_{$dircount}"; foreach ($users as $user) { $cmd = "htpasswd {$setup} -b {$passwdfile} " . $user['username'] . " " . $user['password']; passthru2($cmd); if ($setup != '') { $setup = ''; } # setup file only at first user } switch ($this->miscconfig['webservertype']) { case 'nginx': # this part not tested yet. apache and nginx handles passworded dirs differently. apache: may be put in a separate file, nginx: should be in same nginx config block. $dominfo = $this->getDomainInfo($d['domainname']); $homedir = $dominfo['homedir'] . "/httpdocs"; $dir = str_replace($homedir, "", $dir); # this config should be put in nginx config section for that domain... this will not work yet.. $conf .= "\n\t\t\t\t\tlocation {$dir} {\n\t\t\t\t\t\troot {$homedir};\n\t\t\t\t\t\tauth_basic \"Restricted\";\n\t\t\t\t\t\tauth_basic_user_file {$passwdfile};\n\t\t\t\t\t}\n\t\t\t\t\t"; case 'apache2': $conf .= "\n\t\t\t\t\t<Directory {$dir}>\n\t\t\t\t\tAuthType Basic\n\t\t\t\t\tAuthName 'Enter your password'\n\t\t\t\t\tAuthUserFile {$passwdfile}\n\t\t\t\t\tRequire valid-user\n\t\t\t\t\t</Directory>\n\t\t\t\t\t"; break; default: $this->echoln(__FUNCTION__ . ': Webservertype is not supported for this func'); } } writeoutput2("{$this->ehcpdir}/apachehcp_auth.conf", $conf, 'w'); #passthru2("/etc/init.d/apache2 reload"); zaten syncsubdomains icinde reload var. return True; }
function scandb() { # checking and rebuilding domains already in database global $app, $ehcpmysqlpass; $mysqlkullaniciadi = "ehcp"; $mysqlsifre = $ehcpmysqlpass; $dbadi = "ehcp"; $baglanti = mysqli_connect("localhost", $mysqlkullaniciadi, $mysqlsifre); if (!$baglanti) { echo mysql_error(); echo "cannot connect to db: username: {$mysqlkullaniciadi}, pass: {$mysqlsifre} \n"; return; } exec("mkdir " . $app->conf['vhosts']); echo "checking and rebuilding domains already in database:\n\n\tattn!: panelusername and domain main ftpusername must be same to function correctly, while rebuilding domains from db !!....\n "; $query = "select panelusername,domainname from domains"; $result = mysql_db_query("{$dbadi}", $query); if ($result) { while ($r = mysql_fetch_assoc($result)) { echo "domain: " . $r['domainname'] . " \n"; $base1 = $app->conf['vhosts'] . '/' . securefilename($r['panelusername']); $base = $base1 . "/" . trim($r['domainname']); exec("mkdir -p {$base}"); exec("mkdir -p {$base}/logs"); exec("mkdir -p {$base}/httpdocs"); addifnotexists("Under Construction", "{$base}/httpdocs/index.php"); addifnotexists("", "{$base}/logs/error_log"); // setup file if not exists exec("chmod a+r {$base1} -Rf"); exec("chown -Rf vsftpd {$base1} "); } } else { echo "error occured:" . mysql_error(); } passthru("service apache2 reload"); echo "finished db ops\n"; cizgi(); }