| 1: | <?php |
| 2: | declare(strict_types=1); |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: | |
| 16: | |
| 17: | |
| 18: | |
| 19: | |
| 20: | class Tomcat_Module extends Module_Skeleton implements \Module\Skeleton\Contracts\Hookable |
| 21: | { |
| 22: | const DEPENDENCY_MAP = ['apache']; |
| 23: | const TOMCAT_PORT = 8080; |
| 24: | |
| 25: | public $exportedFunctions; |
| 26: | |
| 27: | public function __construct() |
| 28: | { |
| 29: | parent::__construct(); |
| 30: | $this->exportedFunctions = array( |
| 31: | '*' => PRIVILEGE_SITE, |
| 32: | 'version' => PRIVILEGE_ALL, |
| 33: | 'system_user' => PRIVILEGE_ALL, |
| 34: | 'enabled' => PRIVILEGE_SITE | PRIVILEGE_USER, |
| 35: | 'permitted' => PRIVILEGE_SITE | PRIVILEGE_USER |
| 36: | |
| 37: | ); |
| 38: | } |
| 39: | |
| 40: | |
| 41: | |
| 42: | |
| 43: | |
| 44: | |
| 45: | public function system_user(): ?string |
| 46: | { |
| 47: | $user = $this->_getKey(); |
| 48: | |
| 49: | |
| 50: | return posix_getpwnam($user)['name'] ?? null; |
| 51: | } |
| 52: | |
| 53: | |
| 54: | |
| 55: | |
| 56: | |
| 57: | |
| 58: | private function _getKey() |
| 59: | { |
| 60: | $version = platform_version(); |
| 61: | if (version_compare($version, '5', '>=')) { |
| 62: | |
| 63: | return 'tomcat'; |
| 64: | } |
| 65: | |
| 66: | return 'tomcat4'; |
| 67: | } |
| 68: | |
| 69: | |
| 70: | |
| 71: | |
| 72: | |
| 73: | |
| 74: | public function enabled() |
| 75: | { |
| 76: | $key = $this->_getKey(); |
| 77: | |
| 78: | return (bool)$this->getServiceValue($key, 'enabled'); |
| 79: | } |
| 80: | |
| 81: | |
| 82: | |
| 83: | |
| 84: | |
| 85: | |
| 86: | public function permitted() |
| 87: | { |
| 88: | $version = platform_version(); |
| 89: | if (version_compare($version, '4.5', '>=')) { |
| 90: | |
| 91: | $key = $this->_getKey(); |
| 92: | |
| 93: | return (bool)$this->getServiceValue($key, 'permit'); |
| 94: | } |
| 95: | |
| 96: | |
| 97: | return (bool)$this->sql_enabled('pgsql'); |
| 98: | } |
| 99: | |
| 100: | |
| 101: | |
| 102: | |
| 103: | |
| 104: | |
| 105: | public function version() |
| 106: | { |
| 107: | static $version; |
| 108: | if (isset($version) && $version) { |
| 109: | return $version; |
| 110: | } |
| 111: | $cache = Cache_Global::spawn(); |
| 112: | $key = 'tomcat.version'; |
| 113: | $version = $cache->get($key); |
| 114: | if ($version) { |
| 115: | return $version; |
| 116: | } |
| 117: | |
| 118: | |
| 119: | |
| 120: | |
| 121: | $platformver = platform_version(); |
| 122: | $prefix = null; |
| 123: | if (version_compare($platformver, '4.5', '>=')) { |
| 124: | |
| 125: | $prefix = $this->_getPrefix(); |
| 126: | } |
| 127: | $path = $prefix . '/bin/version.sh'; |
| 128: | |
| 129: | if (file_exists($path)) { |
| 130: | $resp = Util_Process::exec($path); |
| 131: | if (preg_match(Regex::TOMCAT_VERSION, $resp['output'], $m)) { |
| 132: | $version = $m['version']; |
| 133: | } |
| 134: | } |
| 135: | |
| 136: | |
| 137: | if (!$version) { |
| 138: | $req = new HTTP_Request2('http://127.0.0.1:' . self::TOMCAT_PORT, |
| 139: | HTTP_Request2::METHOD_GET, array('use_brackets' => true)); |
| 140: | $response = $req->send()->getBody(); |
| 141: | if (preg_match(Regex::TOMCAT_VERSION, $response, $m)) { |
| 142: | $version = $m['version']; |
| 143: | } |
| 144: | } |
| 145: | if (!$version) { |
| 146: | $version = 'undefined'; |
| 147: | } |
| 148: | $cache->set($key, $version); |
| 149: | |
| 150: | return $version; |
| 151: | } |
| 152: | |
| 153: | |
| 154: | |
| 155: | |
| 156: | |
| 157: | |
| 158: | private function _getPrefix() |
| 159: | { |
| 160: | $version = platform_version(); |
| 161: | if (version_compare($version, '5', '>=')) { |
| 162: | |
| 163: | return '/opt/tomcat'; |
| 164: | } else { |
| 165: | return '/opt/tomcat4'; |
| 166: | } |
| 167: | } |
| 168: | |
| 169: | |
| 170: | |
| 171: | |
| 172: | |
| 173: | |
| 174: | public function _edit() |
| 175: | { |
| 176: | $key = $this->_getKey(); |
| 177: | |
| 178: | $conf_old = $this->getAuthContext()->conf($key, 'old'); |
| 179: | $conf_new = $this->getAuthContext()->conf($key, 'new'); |
| 180: | |
| 181: | if ($conf_new === $conf_old) { |
| 182: | return; |
| 183: | } |
| 184: | $log = '/var/log/catalina.out'; |
| 185: | $path = $this->domain_fs_path() . $log; |
| 186: | $origlog = $this->_getPrefix() . $log; |
| 187: | if (file_exists($path)) { |
| 188: | unlink($path); |
| 189: | } |
| 190: | if ($conf_new['enabled']) { |
| 191: | link($origlog, $path); |
| 192: | } |
| 193: | |
| 194: | return true; |
| 195: | } |
| 196: | |
| 197: | public function _verify_conf(\Opcenter\Service\ConfigurationContext $ctx): bool |
| 198: | { |
| 199: | return true; |
| 200: | } |
| 201: | |
| 202: | public function _create() |
| 203: | { |
| 204: | |
| 205: | } |
| 206: | |
| 207: | public function _delete() |
| 208: | { |
| 209: | |
| 210: | } |
| 211: | |
| 212: | public function _create_user(string $user) |
| 213: | { |
| 214: | |
| 215: | } |
| 216: | |
| 217: | public function _delete_user(string $user) |
| 218: | { |
| 219: | |
| 220: | } |
| 221: | |
| 222: | public function _edit_user(string $userold, string $usernew, array $oldpwd) |
| 223: | { |
| 224: | |
| 225: | } |
| 226: | |
| 227: | |
| 228: | } |
| 229: | |