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: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229:
<?php
declare(strict_types=1);
class Tomcat_Module extends Module_Skeleton implements \Opcenter\Contracts\Hookable
{
const DEPENDENCY_MAP = ['apache'];
const TOMCAT_PORT = 8080;
public $exportedFunctions;
public function __construct()
{
parent::__construct();
$this->exportedFunctions = array(
'*' => PRIVILEGE_SITE,
'version' => PRIVILEGE_ALL,
'system_user' => PRIVILEGE_ALL,
'enabled' => PRIVILEGE_SITE | PRIVILEGE_USER,
'permitted' => PRIVILEGE_SITE | PRIVILEGE_USER
);
}
public function system_user(): ?string
{
$user = $this->_getKey();
return posix_getpwnam($user)['name'] ?? null;
}
private function _getKey()
{
$version = platform_version();
if (version_compare($version, '5', '>=')) {
return 'tomcat';
}
return 'tomcat4';
}
public function enabled()
{
$key = $this->_getKey();
return (bool)$this->getServiceValue($key, 'enabled');
}
public function permitted()
{
$version = platform_version();
if (version_compare($version, '4.5', '>=')) {
$key = $this->_getKey();
return (bool)$this->getServiceValue($key, 'permit');
}
return (bool)$this->sql_enabled('pgsql');
}
public function version()
{
static $version;
if (isset($version) && $version) {
return $version;
}
$cache = Cache_Global::spawn();
$key = 'tomcat.version';
$version = $cache->get($key);
if ($version) {
return $version;
}
$platformver = platform_version();
$prefix = null;
if (version_compare($platformver, '4.5', '>=')) {
$prefix = $this->_getPrefix();
}
$path = $prefix . '/bin/version.sh';
if (file_exists($path)) {
$resp = Util_Process::exec($path);
if (preg_match(Regex::TOMCAT_VERSION, $resp['output'], $m)) {
$version = $m['version'];
}
}
if (!$version) {
$req = new HTTP_Request2('http://127.0.0.1:' . self::TOMCAT_PORT,
HTTP_Request2::METHOD_GET, array('use_brackets' => true));
$response = $req->send()->getBody();
if (preg_match(Regex::TOMCAT_VERSION, $response, $m)) {
$version = $m['version'];
}
}
if (!$version) {
$version = 'undefined';
}
$cache->set($key, $version);
return $version;
}
private function _getPrefix()
{
$version = platform_version();
if (version_compare($version, '5', '>=')) {
return '/opt/tomcat';
} else {
return '/opt/tomcat4';
}
}
public function _edit()
{
$key = $this->_getKey();
$conf_old = $this->getAuthContext()->conf($key, 'old');
$conf_new = $this->getAuthContext()->conf($key, 'new');
if ($conf_new === $conf_old) {
return;
}
$log = '/var/log/catalina.out';
$path = $this->domain_fs_path() . $log;
$origlog = $this->_getPrefix() . $log;
if (file_exists($path)) {
unlink($path);
}
if ($conf_new['enabled']) {
link($origlog, $path);
}
return true;
}
public function _verify_conf(\Opcenter\Service\ConfigurationContext $ctx): bool
{
return true;
}
public function _create()
{
}
public function _delete()
{
}
public function _create_user(string $user)
{
}
public function _delete_user(string $user)
{
}
public function _edit_user(string $userold, string $usernew, array $oldpwd)
{
}
}