From 84637d82d4957ab51f3eaf76f0fe28b89f6d5a90 Mon Sep 17 00:00:00 2001 From: "Andreas Burchert (scarya)" Date: Wed, 20 Oct 2010 21:33:39 +0000 Subject: [PATCH] - updated demousage - updated FroxlorPkgCreator (fix for manual added files) - first cron version for remote server data deploying --- .../sshtransport/class.FroxlorPkgCreator.php | 8 ++-- lib/classes/sshtransport/demousage.php | 3 +- ...on_tasks.inc.multiserver.client_deploy.php | 46 +++++++++++++++++-- 3 files changed, 47 insertions(+), 10 deletions(-) diff --git a/lib/classes/sshtransport/class.FroxlorPkgCreator.php b/lib/classes/sshtransport/class.FroxlorPkgCreator.php index 609304ed..35bde8f8 100644 --- a/lib/classes/sshtransport/class.FroxlorPkgCreator.php +++ b/lib/classes/sshtransport/class.FroxlorPkgCreator.php @@ -55,7 +55,7 @@ class FroxlorPkgCreator /** * Manual added files. - * Uses key as filename! + * Contains an array with an array (name, data); * * @var array */ @@ -131,7 +131,7 @@ class FroxlorPkgCreator */ public function addFile($name, $data) { - $this->_manualFiles[$name] = $data; + $this->_manualFiles[] = array("name" => $name, "data" => $data; } /** @@ -156,8 +156,8 @@ class FroxlorPkgCreator } // add manual files - foreach ($this->_manualFiles as $key=>$var) { - $zip->addFromString($key, $var); + foreach ($this->_manualFiles as $var) { + $zip->addFromString($var['name'], $var['data']); } // close it diff --git a/lib/classes/sshtransport/demousage.php b/lib/classes/sshtransport/demousage.php index 3eb8aead..f97db36c 100644 --- a/lib/classes/sshtransport/demousage.php +++ b/lib/classes/sshtransport/demousage.php @@ -85,4 +85,5 @@ FroxlorDeployfileCreator::saveListTo("deploy.txt"); /* * and create a zip archive */ -new FroxlorPkgCreator("deploy.txt", "deploy.zip"); +$pkg = new FroxlorPkgCreator("deploy.txt", "deploy.zip"); +$pkg->pack(); diff --git a/scripts/jobs/cron_tasks.inc.multiserver.client_deploy.php b/scripts/jobs/cron_tasks.inc.multiserver.client_deploy.php index b798bdd4..56673b93 100644 --- a/scripts/jobs/cron_tasks.inc.multiserver.client_deploy.php +++ b/scripts/jobs/cron_tasks.inc.multiserver.client_deploy.php @@ -79,6 +79,31 @@ class client_deployer /** * @TODO implement me */ + + $deployList = "/tmp/froxlor_deploy_".time().".txt"; + $zipPath = "/tmp/froxlor_deploy_".time().".zip"; + + $remoteTo = "/var/ww/froxlor/"; // TODO setting variable?! + + // TODO get a deploy configuration from database/panel? + // create the deploy list + FroxlorDeployfileCreator::createList( + array( + "/var/www/froxlor/lib/", + "/var/www/froxlor/lng/", + "/var/www/froxlor/scripts/", + "/var/www/froxlor/actions/", + "/var/www/froxlor/templates/" + ) + ); + + FroxlorDeployfileCreator::saveListTo($deployList); + + // prepare and pack files + $this->_prepareFiles($deployList, $zipPath); + + // transfer the data + $bytes = $this->_transferArchive($ssh, $zipPath, $remoteTo); // close the session $ssh->close(); @@ -91,9 +116,13 @@ class client_deployer * * @return double amount of bytes transferd */ - private function _transferArchive() + private function _transferArchive($ssh, $from, $to) { - $archive = $this->_prepareFiles(); + if ($ssh->sendFile($from, $to)) { + return stat($from)['7']; + } else { + return 0.0; + } } /** @@ -102,14 +131,21 @@ class client_deployer * * @return string path to the created archive */ - private function _prepareFiles() + private function _prepareFiles($deployList, $toPath) { - + $pkg = FroxlorPkgCreator($deployList, $toPath); + /** * create userdata file which * has to be included to the archive */ $userdatafile = $this->_createUserdataFile(); + + // add userdata.inc.php + $pkg->addFile("lib/userdata.inc.php", $userdatafile); + + // pack it + $pkg->pack(); } /** @@ -122,6 +158,6 @@ class client_deployer */ private function _createUserdataFile() { - + return "Chuck Norris doesn't need a userdata.inc.php to run Froxlor!"; } }