. * * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco, * California 94120-7775, or email info@knowledgetree.com. * * The interactive user interfaces in modified source and object code versions * of this program must display Appropriate Legal Notices, as required under * Section 5 of the GNU General Public License version 3. * * In accordance with Section 7(b) of the GNU General Public License version 3, * these Appropriate Legal Notices must retain the display of the "Powered by * KnowledgeTree" logo and retain the original copyright notice. If the display of the * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices * must display the words "Powered by KnowledgeTree" and retain the original * copyright notice. * * @copyright 2008-2009, KnowledgeTree Inc. * @license GNU General Public License version 3 * @author KnowledgeTree Team * @package Installer * @version Version 0.1 */ class unixOpenOffice extends unixService { // utility public $util; // path to office private $path; // host private $host; // pid running private $pidFile; // port to bind to private $port; // bin folder private $bin; // office executable private $soffice; // office log file private $log; private $options; private $office; public $name = "KTOpenOffice"; public function load() { $this->util = new InstallUtil(); $this->office = 'openoffice'; $this->setPort("8100"); $this->setHost("localhost"); $this->setLog("openoffice.log"); $this->setBin($this->soffice = $this->util->getOpenOffice()); $this->setOption(); } private function setPort($port = "8100") { $this->port = $port; } public function getPort() { return $this->port; } private function setHost($host = "localhost") { $this->host = $host; } public function getHost() { return $this->host; } private function setLog($log = "openoffice.log") { $this->log = $log; } public function getLog() { return $this->log; } private function setBin($bin = "soffice") { $this->bin = $bin; } public function getBin() { return $this->bin; } private function setOption() { $this->options = "-nofirststartwizard -nologo -headless -accept=\"socket,host={$this->getHost()},port={$this->getPort()};urp;StarOffice.ServiceManager\""; } public function getOption() { return $this->options; } public function install() { $status = $this->status(); if($status == '') { return $this->start(); } else { return $status; } } private function setOfficeName($office) { $this->office = $office; } public function getOfficeName() { return $this->office; } public function status() { sleep(1); $cmd = "netstat -npa | grep ".$this->getPort(); $response = $this->util->pexec($cmd); if(is_array($response['out'])) { if(count($response['out']) > 0) { preg_match('/8100/', $response['out'][0], $matches); // Ignore grep if($matches) { if($matches[0] == '8100') { return 'STARTED'; } } } else { return ''; } } return ''; } public function start() { $state = $this->status(); if($state != 'STARTED') { $cmd = "nohup {$this->getBin()} ".$this->getOption()." > ".$this->outputDir."{$this->getLog()} 2>&1 & echo $!"; if(DEBUG) { echo "Command : $cmd
"; return ; } $cmd .= "\"{$this->util->getJava()}\" -cp \"".SYS_DIR.";\" openOffice \""; $response = $this->util->pexec($cmd); return $response; } elseif ($state == '') { // Start Service return true; } else { // Service Running Already return true; } return false; } function stop() { $cmd = "pkill -f ".$this->office; $response = $this->util->pexec($cmd); return $response; } function uninstall() { $this->stop(); } public function getName() { return $this->name; } } ?>