|
|
@@ -237,8 +237,22 @@ jQuery(document).ready(function () {
|
|
|
public function _encodeSource($appLicenceInfo) {
|
|
|
if (empty($appLicenceInfo->ID)) throw new Exception("Nie wybrano serwera/licencji.");
|
|
|
if (empty($appLicenceInfo->domains)) throw new Exception("Domains not found");
|
|
|
- $installPath = $appLicenceInfo->installPath;
|
|
|
+ if (empty($appLicenceInfo->installPath)) throw new Exception("Install path not found");
|
|
|
+ UI::startContainer();
|
|
|
+ $this->encodeSourceFiles($appLicenceInfo->installPath, $appLicenceInfo->domains, $dbg = true);
|
|
|
+ // try {
|
|
|
+ // $this->encodeSourceFiles($appLicenceInfo->installPath, $appLicenceInfo->domains, $dbg = false);
|
|
|
+ // UI::alert('success', "OK");
|
|
|
+ // } catch (Exception $e) {
|
|
|
+ // UI::alert('danger', $e->getMessage());
|
|
|
+ // }
|
|
|
+ UI::endContainer();
|
|
|
+ }
|
|
|
+
|
|
|
+ // @usage: Router::getRoute('Install')->encodeSourceFiles($installPath = '/path_to_git_repo', $domains = [ 'domain.com', 'localhost' ], $dbg = false);
|
|
|
+ public function encodeSourceFiles($installPath, $domains, $dbg = false) {
|
|
|
if (empty($installPath)) throw new Exception("Install path not found");
|
|
|
+ if (empty($domains)) throw new Exception("Domains not found");
|
|
|
|
|
|
$phpVersionsForSgencoder = '--phpversion 5.5 --phpversion 5.6';// encode for PHP 5.x (currently supported PHP 5.0-5.6)
|
|
|
|
|
|
@@ -246,151 +260,86 @@ jQuery(document).ready(function () {
|
|
|
$cmd = "cd {$installPath}/SE && /Applications/SourceGuardian.app/Contents/MacOS/sgencoder --help ";
|
|
|
$out = ''; $ret = '';
|
|
|
exec($cmd, $out, $ret);
|
|
|
- echo'<pre>cmd: '. $cmd . ': (return:'.$ret.')'."\n";print_r($out);echo'</pre>';
|
|
|
- exit;
|
|
|
- }
|
|
|
- if (0) {//'1' == V::get('DBG_ENCODER_TEST_IP', '', $_REQUEST)) {
|
|
|
- $phpFiles = array();
|
|
|
- $phpFiles[] = 't.php';
|
|
|
- $cmd = "cd {$installPath}/SE && echo '<?php' > t.php ; echo 'echo \"test\\n\";' >> t.php ";
|
|
|
- //$cmd = "cd {$installPath}/SE && rm t.php ";
|
|
|
- V::exec($cmd, $out, $ret);
|
|
|
- DBG::_(true, true, "cmd: {$cmd} (return: {$ret})", $out, __CLASS__, __FUNCTION__, __LINE__);
|
|
|
-
|
|
|
- $cmd = "cd {$installPath}/SE && /Applications/SourceGuardian.app/Contents/MacOS/sgencoder {$phpVersionsForSgencoder} -b- ";
|
|
|
- //$mac = '38:c9:86:31:80:77';
|
|
|
- //$cmd .= " --mac {$mac}";
|
|
|
- foreach ($appLicenceInfo->domains as $domain) {
|
|
|
- $cmd .= " --domain {$domain} ";
|
|
|
- }
|
|
|
- $cmd .= " " . implode(" ", $phpFiles);
|
|
|
- V::exec($cmd, $out, $ret);
|
|
|
- DBG::_(true, true, "cmd: {$cmd} (return: {$ret})", $out, __CLASS__, __FUNCTION__, __LINE__);
|
|
|
- if (0 !== $ret) throw new Exception("Error at encode files");
|
|
|
- if (empty($out)) throw new Exception("No output for encode files command");
|
|
|
+ DBG::nicePrint($out, "cmd: `{$cmd}` (return:{$ret})");
|
|
|
exit;
|
|
|
}
|
|
|
|
|
|
- {
|
|
|
-/*
|
|
|
- $phpFiles = array();
|
|
|
- $skipPhpFiles = array();
|
|
|
- $skipPhpFiles[] = 'bash_sync_perms.php';
|
|
|
- $skipPhpFiles[] = 'bash_install_check.php';
|
|
|
- $skipPhpFiles[] = '.config.php';
|
|
|
- $skipPhpFiles[] = '.config_base_structure.php';
|
|
|
- $skipPhpFiles[] = 'se-lib/V.php';
|
|
|
- $skipPhpFiles[] = 'se-lib/Lib.php';
|
|
|
- $skipPhpFiles[] = 'se-lib/DB.php';
|
|
|
- $skipPhpFiles[] = 'se-lib/DBG.php';
|
|
|
- $skipPhpFiles[] = 'se-lib/User.php';
|
|
|
- $skipPhpFiles[] = 'se-lib/UserProfile.php';
|
|
|
- $skipPhpFiles[] = 'se-lib/Config.php';
|
|
|
- $skipPhpFiles[] = 'se-lib/Config/INI.php';
|
|
|
- $skipPhpFiles[] = 'se-lib/FoldersConfig.php';
|
|
|
- $skipPhpFiles[] = 'se-lib/FileUploader.php';
|
|
|
- $skipPhpFiles[] = 'se-lib/Route/Budget.php';
|
|
|
- $skipPhpFiles[] = 'se-lib/Route/FixCrmProcesInitIdx.php';
|
|
|
- $skipPhpFiles[] = 'se-lib/Route/FixProjectPath.php';
|
|
|
- $skipPhpFiles[] = 'se-lib/Route/FixZasobPath.php';
|
|
|
- //$skipPhpFiles[] = 'se-lib/Route/Install.php';
|
|
|
- $skipPhpFiles[] = 'se-lib/Route/Msgs.php';
|
|
|
- $skipPhpFiles[] = 'se-lib/Route/UrlAction/WmsGenerate.php';
|
|
|
- $skipPhpFiles[] = 'se-lib/Route/UrlAction/BiAuditGenerate.php';
|
|
|
- $skipPhpFiles[] = 'superedit-DB_PROCEDURES_CREATE.php';
|
|
|
- $skipPhpFiles[] = 'se-lib/Theme.php';
|
|
|
- //$skipPhpFiles[] = '';
|
|
|
-
|
|
|
- $skipPhpFiles[] = 'se-lib/DataSourceException.php';
|
|
|
- $skipPhpFiles[] = 'se-lib/Core/Pdo.php';
|
|
|
- $skipPhpFiles[] = 'se-lib/Cron.php';
|
|
|
- $skipPhpFiles[] = 'se-lib/Router.php';
|
|
|
- $skipPhpFiles[] = 'se-lib/RouteBase.php';
|
|
|
- $skipPhpFiles[] = 'se-lib/HttpException.php';
|
|
|
- $skipPhpFiles[] = 'se-lib/DebugExecutionTime.php';
|
|
|
- $skipPhpFiles[] = 'se-lib/UI.php';
|
|
|
- $skipPhpFiles[] = 'se-lib/Request.php';
|
|
|
-
|
|
|
- $cmd = "cd {$installPath}/SE && find . -name '*.php' ";
|
|
|
- $out = ''; $ret = '';
|
|
|
- exec($cmd, $out, $ret);
|
|
|
- echo'<pre>cmd: '. $cmd . ': (return:'.$ret.')'."\n";print_r($out);echo'</pre>';
|
|
|
- if (0 !== $ret) throw new Exception("Error at find php files");
|
|
|
- if (empty($out)) throw new Exception("No php files found");
|
|
|
- foreach ($out as $phpFilePath) {
|
|
|
- $phpFilePath = ('./' == substr($phpFilePath, 0, 2))? substr($phpFilePath, 2) : $phpFilePath;
|
|
|
- if (in_array($phpFilePath, $skipPhpFiles)) continue;
|
|
|
- if ('schema/' == substr($phpFilePath, 0, 7)) continue;
|
|
|
- $phpFiles[] = $phpFilePath;
|
|
|
- }
|
|
|
-
|
|
|
- DBG::_(true, true, 'phpFiles', $phpFiles, __CLASS__, __FUNCTION__, __LINE__);
|
|
|
- if (empty($phpFiles)) throw new Exception("No php files to encode");
|
|
|
-*/
|
|
|
-
|
|
|
- $domainEncodePhpFiles = [
|
|
|
- 'ant.php',
|
|
|
- 'api.php',
|
|
|
- 'budynki.php',
|
|
|
- 'index-ajax.php',
|
|
|
- 'index.php',
|
|
|
- 'procesy5.php',
|
|
|
- 'session-expire.php',
|
|
|
- 'test-sync.php',
|
|
|
- 'wfs-data.php',
|
|
|
- 'wfs-qgis.php',
|
|
|
- 'wfs.php',
|
|
|
- ];
|
|
|
- $freeEncodePhpFiles = [];
|
|
|
-
|
|
|
- $cmd = "cd {$installPath}/SE && find . -name '*.php' ";
|
|
|
+ $domainEncodePhpFiles = [
|
|
|
+ 'ant.php',
|
|
|
+ 'api.php',
|
|
|
+ 'budynki.php',
|
|
|
+ 'index-ajax.php',
|
|
|
+ 'index.php',
|
|
|
+ 'procesy5.php',
|
|
|
+ 'session-expire.php',
|
|
|
+ 'test-sync.php',
|
|
|
+ 'wfs-data.php',
|
|
|
+ 'wfs-qgis.php',
|
|
|
+ 'wfs.php',
|
|
|
+ ];
|
|
|
+
|
|
|
+ $cmd = "find . -name '*.php' ";
|
|
|
+ $out = ''; $ret = '';
|
|
|
+ exec("cd {$installPath}/SE && {$cmd}", $out, $ret);
|
|
|
+ if ($dbg) DBG::nicePrint($out, "cmd: `{$cmd}` (return:{$ret})");
|
|
|
+ else DBG::log($out, 'array', "cmd: `{$cmd}` (return:{$ret})");
|
|
|
+ if (0 !== $ret) throw new Exception("Error at find php files");
|
|
|
+ if (empty($out)) throw new Exception("No php files found");
|
|
|
+ $allPhpFiles = array_map(function ($phpFilePath) {
|
|
|
+ return ('./' == substr($phpFilePath, 0, 2))? substr($phpFilePath, 2) : $phpFilePath;
|
|
|
+ }, $out);
|
|
|
+ $freeEncodePhpFiles = array_filter($allPhpFiles, function ($phpFilePath) use ($domainEncodePhpFiles) {
|
|
|
+ if ('se-lib/Vendor/' === substr($phpFilePath, 0, strlen('se-lib/Vendor/'))) return false; // SKIP se-lib/Vendor/*
|
|
|
+ if ('.ini.php' === substr($phpFilePath, -1 * strlen('.ini.php'))) return false; // SKIP *.ini.php
|
|
|
+ return (!in_array($phpFilePath, $domainEncodePhpFiles));
|
|
|
+ });
|
|
|
+ DBG::log($freeEncodePhpFiles, 'array', "\$freeEncodePhpFiles");
|
|
|
+ if (empty($freeEncodePhpFiles)) throw new Exception("No php files to encode");
|
|
|
+
|
|
|
+ $cmdTempl = "cd {$installPath}/SE && /Applications/SourceGuardian.app/Contents/MacOS/sgencoder {$phpVersionsForSgencoder} -b- ";
|
|
|
+ $cmdDomainEncodeDomainsTempl = " --domain " . implode(" --domain ", array_merge($domains, ['localhost']));
|
|
|
+ $cmdDomainEncodeFilesTempl = " " . implode(" ", $domainEncodePhpFiles);
|
|
|
+ $cmdFreeEncodeFilesTempl = " " . implode(" ", $freeEncodePhpFiles);
|
|
|
+
|
|
|
+ $cmds = [
|
|
|
+ $cmdTempl . $cmdDomainEncodeDomainsTempl . $cmdDomainEncodeFilesTempl,
|
|
|
+ $cmdTempl . $cmdFreeEncodeFilesTempl,
|
|
|
+ ];
|
|
|
+
|
|
|
+ $returnValues = [];
|
|
|
+ foreach ($cmds as $cmd) {
|
|
|
$out = ''; $ret = '';
|
|
|
exec($cmd, $out, $ret);
|
|
|
- echo'<pre>cmd: '. $cmd . ': (return:'.$ret.')'."\n";print_r($out);echo'</pre>';
|
|
|
- if (0 !== $ret) throw new Exception("Error at find php files");
|
|
|
- if (empty($out)) throw new Exception("No php files found");
|
|
|
- foreach ($out as $phpFilePath) {
|
|
|
- $phpFilePath = ('./' == substr($phpFilePath, 0, 2))? substr($phpFilePath, 2) : $phpFilePath;
|
|
|
- if (in_array($phpFilePath, $domainEncodePhpFiles)) continue;
|
|
|
- $freeEncodePhpFiles[] = $phpFilePath;
|
|
|
- }
|
|
|
-
|
|
|
- DBG::_(true, true, 'freeEncodePhpFiles', $freeEncodePhpFiles, __CLASS__, __FUNCTION__, __LINE__);
|
|
|
- if (empty($freeEncodePhpFiles)) throw new Exception("No php files to encode");
|
|
|
- }
|
|
|
-
|
|
|
- {
|
|
|
-/*
|
|
|
- $cmd = "cd {$installPath}/SE && /Applications/SourceGuardian.app/Contents/MacOS/sgencoder {$phpVersionsForSgencoder} -b- ";
|
|
|
- foreach ($appLicenceInfo->domains as $domain) {
|
|
|
- $cmd .= " --domain {$domain} ";
|
|
|
+ $encoderSummaryLine = end($out);
|
|
|
+ $returnValues[] = $encoderSummaryLine;
|
|
|
+ if ($dbg) {
|
|
|
+ DBG::nicePrint([$cmd], "cmd");
|
|
|
+ DBG::nicePrint($out, "return: '{$ret}'");
|
|
|
+ // DBG::nicePrint([$encoderSummaryLine], "cmd last line");
|
|
|
}
|
|
|
- $cmd .= " --domain localhost ";
|
|
|
- $cmd .= " " . implode(" ", $phpFiles);
|
|
|
- $out = ''; $ret = '';
|
|
|
- exec($cmd, $out, $ret);
|
|
|
- echo'<pre>cmd: '. $cmd . ': (return:'.$ret.')'."\n";print_r($out);echo'</pre>';
|
|
|
- if (0 !== $ret) throw new Exception("Error at encode files");
|
|
|
+ else DBG::log([$cmd, $out], 'array', "cmd return:'{$ret}'");
|
|
|
+ // if (0 !== $ret) throw new Exception("Error at encode files");
|
|
|
if (empty($out)) throw new Exception("No output for encode files command");
|
|
|
-*/
|
|
|
-
|
|
|
- $cmdTempl = "cd {$installPath}/SE && /Applications/SourceGuardian.app/Contents/MacOS/sgencoder {$phpVersionsForSgencoder} -b- ";
|
|
|
- $cmdDomainEncodeDomainsTempl = " --domain " . implode(" --domain ", array_merge($appLicenceInfo->domains, ['localhost']));
|
|
|
- $cmdDomainEncodeFilesTempl = " " . implode(" ", $domainEncodePhpFiles);
|
|
|
- $cmdFreeEncodeFilesTempl = " " . implode(" ", $freeEncodePhpFiles);
|
|
|
-
|
|
|
- $cmds = [
|
|
|
- $cmdTempl . $cmdDomainEncodeDomainsTempl . $cmdDomainEncodeFilesTempl,
|
|
|
- $cmdTempl . $cmdFreeEncodeFilesTempl,
|
|
|
+ }
|
|
|
+ $statusInfo = array_reduce($returnValues, function ($ret, $encoderSummaryLine) {
|
|
|
+ DBG::log([$ret, $encoderSummaryLine], 'array', "DBG reduce [\$ret, \$encoderSummaryLine]");
|
|
|
+ $matches = [];
|
|
|
+ preg_match_all('/(\d+) files, (\d+) processed, (\d+) errors/', $encoderSummaryLine, $matches, PREG_SET_ORDER, 0);
|
|
|
+ return [
|
|
|
+ 'files' => $ret['files'] + (int)$matches[0][1],
|
|
|
+ 'processed' => $ret['processed'] + (int)$matches[0][2],
|
|
|
+ 'errors' => $ret['errors'] + (int)$matches[0][3],
|
|
|
];
|
|
|
-
|
|
|
- foreach ($cmds as $cmd) {
|
|
|
- $out = ''; $ret = '';
|
|
|
- exec($cmd, $out, $ret);
|
|
|
- echo'<pre>cmd: '. $cmd . ': (return:'.$ret.')'."\n";print_r($out);echo'</pre>';
|
|
|
- if (0 !== $ret) throw new Exception("Error at encode files");
|
|
|
- if (empty($out)) throw new Exception("No output for encode files command");
|
|
|
- }
|
|
|
+ }, [
|
|
|
+ 'files' => 0,
|
|
|
+ 'processed' => 0,
|
|
|
+ 'errors' => 0,
|
|
|
+ ]);
|
|
|
+ if ($statusInfo['errors'] === 0 && $statusInfo['files'] > 0) {
|
|
|
+ if ($dbg) UI::alert('success', "{$statusInfo['files']} files, {$statusInfo['processed']} processed, {$statusInfo['errors']} errors");
|
|
|
+ } else {
|
|
|
+ if ($dbg) UI::alert('danger', "{$statusInfo['files']} files, {$statusInfo['processed']} processed, {$statusInfo['errors']} errors");
|
|
|
+ else throw new Exception("{$statusInfo['files']} files, {$statusInfo['processed']} processed, {$statusInfo['errors']} errors");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -450,8 +399,8 @@ jQuery(document).ready(function () {
|
|
|
|
|
|
public function fetchActiveLicences() {
|
|
|
$activeLic = array();
|
|
|
- $db = DB::getDB();
|
|
|
- $sql = "select l.`ID`
|
|
|
+ $sql = "
|
|
|
+ select l.`ID`
|
|
|
, l.`SERVER_ADDRESS`
|
|
|
, l.`SERVER_ADDRESS_SHORT` as domain -- domain for sgencoder
|
|
|
, l.`SERVER_ADDRESS_IP`
|
|
|
@@ -460,8 +409,9 @@ jQuery(document).ready(function () {
|
|
|
-- TODO: and l.`A_STATUS` in('NORMAL','WAITING')
|
|
|
order by l.`ID` DESC
|
|
|
";
|
|
|
- $res = $db->query($sql);
|
|
|
- while ($r = $db->fetch($res)) {
|
|
|
+ $rows = DB::getPDO()->fetchAll($sql);
|
|
|
+ foreach ($rows as $row) {
|
|
|
+ $r = (object)$row;
|
|
|
$activeLic[$r->ID] = $r;
|
|
|
}
|
|
|
return $activeLic;
|
|
|
@@ -469,8 +419,8 @@ jQuery(document).ready(function () {
|
|
|
|
|
|
public function fetchDomainsByLicenceId($licenceId) {
|
|
|
$domains = array();
|
|
|
- $db = DB::getDB();
|
|
|
- $sql = "select g.`SERVER_ADDRESS_SHORT`, g.`SERVER_ADDRESS`
|
|
|
+ $sql = "
|
|
|
+ select g.`SERVER_ADDRESS_SHORT`, g.`SERVER_ADDRESS`
|
|
|
from `SES_PROCESY5_A` g
|
|
|
where g.`SERVER_ADDRESS_IP`=(select l.`SERVER_ADDRESS_IP`
|
|
|
from `SES_PROCESY5_A` l
|
|
|
@@ -479,8 +429,9 @@ jQuery(document).ready(function () {
|
|
|
)
|
|
|
-- TODO: and g.`A_STATUS` in('NORMAL','WAITING')
|
|
|
";
|
|
|
- $res = $db->query($sql);
|
|
|
- while ($r = $db->fetch($res)) {
|
|
|
+ $rows = DB::getPDO()->fetchAll($sql);
|
|
|
+ foreach ($rows as $row) {
|
|
|
+ $r = (object)$row;
|
|
|
$domains[] = $r->SERVER_ADDRESS_SHORT;
|
|
|
if ($r->SERVER_ADDRESS != $r->SERVER_ADDRESS_SHORT) {
|
|
|
$domains[] = $r->SERVER_ADDRESS;
|
|
|
@@ -490,23 +441,17 @@ jQuery(document).ready(function () {
|
|
|
}
|
|
|
|
|
|
public function fetchMainServerByLicenceId($licenceId) {
|
|
|
- $mainServer = null;
|
|
|
- $db = DB::getDB();
|
|
|
- $sql = "select g.`SERVER_ADDRESS`
|
|
|
+ return DB::getPDO()->fetchValue("
|
|
|
+ select g.`SERVER_ADDRESS`
|
|
|
from `SES_PROCESY5_A` g
|
|
|
where g.`ID`='{$licenceId}'
|
|
|
-- TODO: and g.`A_STATUS` in('NORMAL','WAITING')
|
|
|
- ";
|
|
|
- $res = $db->query($sql);
|
|
|
- while ($r = $db->fetch($res)) {
|
|
|
- $mainServer = $r->SERVER_ADDRESS;
|
|
|
- }
|
|
|
- return $mainServer;
|
|
|
+ ");
|
|
|
}
|
|
|
|
|
|
public function fetchAppLicenceInfo($licenceId) {
|
|
|
$licenceInfo = null;
|
|
|
- $sth = DB::getPDO()->prepare("
|
|
|
+ $sql = "
|
|
|
select g.ID
|
|
|
, g.SERVER_ADDRESS as mainServer
|
|
|
, g.ADMIN_USERNAME as rootLogin
|
|
|
@@ -515,10 +460,8 @@ jQuery(document).ready(function () {
|
|
|
from SES_PROCESY5_A g
|
|
|
where g.`ID`=:id_licence
|
|
|
-- TODO: and g.A_STATUS in('NORMAL','WAITING')
|
|
|
- ");
|
|
|
- $sth->bindValue('id_licence', $licenceId, PDO::PARAM_INT);
|
|
|
- $sth->execute();
|
|
|
- $all = $sth->fetchAll();
|
|
|
+ ";
|
|
|
+ $all = DB::getPDO()->fetchAll($sql, [ ':id_licence' => $licenceId ]);
|
|
|
if (empty($all)) throw new Exception("Brak licencji o nr '{$licenceId}'");
|
|
|
$licenceInfo = reset($all);
|
|
|
if (!$licenceInfo['sshPort']) $licenceInfo['sshPort'] = 22;
|