One Hat Cyber Team
Your IP :
216.73.217.131
Server IP :
185.33.55.30
Server :
Linux cl30.webspacecontrol.com 5.14.0-611.38.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Mar 10 17:21:28 EDT 2026 x86_64
Server Software :
Apache
PHP Version :
8.1.34
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
opt
/
cxs2
/
app
/
tasks
/
Edit File:
CommonTask.php
<?php /** * CommonTask, Common Task * * @copyright Copyright (c) 2007 DotRoll Kft. (http://www.dotroll.com) * @author Zoltán Istvanovszki <zoltan.istvanovszki@dotroll.com> * @since 2017.04.20. * @package domainabc.hu */ use Pheanstalk\Pheanstalk; use Phalcon\Cli\Task; #[AllowDynamicProperties] abstract class CommonTask extends Task { /** * Prefix * * @var string * @const */ protected const PREFIX = 'cxs2'; /** * Panel type * * @var string */ protected $panelType; /** * Get technical panel type * * @return string */ protected function getType(): string { if (!empty($this->panelType)) { return $this->panelType; } return $this->panelType = \strpos(\gethostname(), '.dadmin.hu') !== false ? 'DirectAdmin' : 'cPanel'; } /** * Check existing lock * * @param string $className Caller class name */ protected function lock($className) { if (!$this->tryLock($className)) { die(); } } /** * Try lock * * @param string $className Caller class name * @return boolean */ protected function tryLock($className) { if (!\defined('LOCK_FILE')) { \define('LOCK_FILE', "/var/run/$className.lock"); // \register_shutdown_function('unlink', \LOCK_FILE); } if (@\symlink("/proc/" . \getmypid(), \LOCK_FILE) !== false) { return true; } if (\is_link(\LOCK_FILE) && !\is_dir(\LOCK_FILE)) { \unlink(\LOCK_FILE); return $this->tryLock($className); } return false; } protected function doJob(string $action, string $hash, string $enviroment, bool $requeue = false) { $tube = \gethostname() . '-' . $enviroment; $request = $this->getBeanstalkInstance(); $request->useTube("$tube-request"); $jobId = $request->put(\serialize([ 'action' => $action, 'hash' => $hash, 'requeue' => $requeue, 'enviroment' => $enviroment, ])); if ($requeue === true) { $response = $this->getBeanstalkInstance(); $response->useTube("$tube-response-$jobId"); while (true) { while (($job = $response->peekReady()) !== false) { $job->delete(); return $job->getBody(); } \usleep(50000); } } else { return ''; } } /** * Create and retunr a beanstalk client instance * * @return Pheanstalk */ protected function getBeanstalkInstance(): Pheanstalk { return Pheanstalk::create($this->di->get('config')->beanstalk->host, $this->di->get('config')->beanstalk->port); } /** * Start a worker * * @param string $tube Worker tube */ protected function startWorker(string $tube) { echo \date('Y-m-d H:i:s') . \chr(9) . "Starting $tube worker\n"; $cronTube = \gethostname() . '-cron'; $request = $this->getBeanstalkInstance(); $request->useTube("$tube-request"); $response = $this->getBeanstalkInstance(); while (true) { if (@$request->stats() === false) { // Stats is false, sleeping 60 sec"; \sleep(60); $request = $this->getBeanstalkInstance(); $request->useTube("$tube-request"); $response = $this->getBeanstalkInstance(); } /** * @var \Pheanstalk\Job */ $job = $request->peekReady(); if (!empty($job)) { // Handle a job $message = \unserialize($job->getData()); $requeue = !empty($message['requeue']) && $message['requeue'] === true ? true : false; if (empty($message['action']) || !\method_exists('JobTask', "{$message['action']}Action")) { $this->dispatcher->setParam('jobResponse', 'Not enforceable task: ' . \json_encode($message)); echo \date('Y-m-d H:i:s') . \chr(9) . $this->dispatcher->getParam('jobResponse') . \PHP_EOL; } else { echo \date('Y-m-d H:i:s') . \chr(9) . 'Handle task: ' . \json_encode($message) . \PHP_EOL; $action = $message['action']; unset($message['action']); if (isset($message['requeue'])) { unset($message['requeue']); } $arguments = [ 'task' => 'Job', 'action' => $action, 'params' => $message ]; $this->console->handle($arguments); } if ($requeue === true) { $response->useTube("$tube-response-{$job->getId()}"); // echo 'Put response: ' . $this->dispatcher->getParam('jobResponse') . \PHP_EOL; $response->put(\serialize($this->dispatcher->getParam('jobResponse'))); } $request->delete($job); } elseif (empty($job) && $cronTube == $tube) { // Cron worker make a new background jobs immediately for all hashes $accounts = []; if ($this->getType() == 'DirectAdmin') { foreach (\glob("/usr/local/directadmin/data/users/*/user.conf") as $userPath) { $conf = \parse_ini_file($userPath); if (empty($conf['suspended']) && $conf['username'] != 'admin') { $accounts[] = $conf['username']; } } } else { /* @var $cpanel \CXS\Cpanel */ $cpanel = $this->di->get('cpanel'); $data = $cpanel->cAPI('listaccts'); if (!empty($data['acct'])) { foreach ($data['acct'] as $account) { if ($account['suspended'] == 0) { $accounts[] = $account['user']; } } } } foreach ($accounts as $account) { echo "Add to cron tube: $account" . \PHP_EOL; try { $request->put(\serialize([ 'action' => 'check', 'hash' => $account, 'requeue' => false, 'enviroment' => 'cron', ])); } catch (\Exception $e) { \sleep(60); // Recreate Beanstalk instances $request = $this->getBeanstalkInstance(); $request->useTube("$tube-request"); $response = $this->getBeanstalkInstance(); } } } \usleep(50000); } } /** * Call cPanel API * * @param string $hostname cPanel server hostname * @param string $command API command * @return \stdClass */ protected function cpanelJson(string $hostname, string $command): \stdClass { $curl = 'https://' . $this->di->get('config')->cpanel->username . ':' . $this->di->get('config')->cpanel->password . "@$hostname:2087/json-api/$command"; try { $socket = \curl_init($curl); \curl_setopt($socket, \CURLOPT_RETURNTRANSFER, true); \curl_setopt($socket, \CURLOPT_CONNECTTIMEOUT, 10); \curl_setopt($socket, \CURLOPT_TIMEOUT, 120); $data = \curl_exec($socket); if ($data === false) { $this->log( 'curl_exec threw error "' . \curl_error($socket) . "\" for https://$hostname:2087/json-api/$command ErrNo: " . \curl_errno($socket) ); return new \stdClass(); } \curl_close($socket); return \json_decode($data); } catch (\Exception $e) { $this->log( __METHOD__ . ' throw an Exception. Message: ' . $e->getMessage() . ' Code: ' . $e->getCode() . ' File: ' . $e->getFile() . ' Line: ' . $e->getFile() ); return new \stdClass(); } } /** * Increase a Serial Number in SOA */ protected function updateSoa() { $record = \Records::find("type = 'SOA'")->getFirst(); $content = \explode(' ', $record->content); if (\count($content) == 7) { $content[2] = \intval($content[2]) + 1; } $record->content = \implode(' ', $content); if ($record->save() === false) { $this->log("SOA update: '{$record->content}' failed with message: " . \implode(\PHP_EOL, $record->getMessages())); } else { $this->log("SOA update: '{$record->content}' success"); } } /** * Get cPanel user IPv4 address * * @param string $username cPanel username * @return string */ protected function getCpanelIp(string $username): string { $result = $this->cpanelJson(\gethostname(), "accountsummary?user=$username"); if (!empty($result->acct[0]->ip)) { return $result->acct[0]->ip; } return ''; } /** * Add IPv6 * * @param string $username Username * @param string $email E-mail * @param string $ipv4 IPv4 address */ protected function addIpv6(string $username, string $email, string $ipv4) { $result = \DnsApi::query("/ipv6/add/$username/" . \gethostname() . '/' . \str_replace(' ', '', $email)); if (!empty($result['result'])) { $ipv6 = $result['result']; // Add loginssl record $record = new \Records(); $record->name = "$username.ipv6.loginssl.com"; $record->type = 'AAAA'; $record->content = $ipv6; if ($record->save() === false) { $this->log("Create: {$record->name} $ipv6 failed with message: " . \implode(\PHP_EOL, $record->getMessages())); } else { $this->log("Create: {$record->name} $ipv6 success"); } // Add IPv6 range to cPanel \exec("/usr/sbin/whmapi1 ipv6_range_add enabled=1 name=$username range=" . \urlencode("$ipv6/128")); \exec("/usr/sbin/whmapi1 ipv6_enable_account user=$username range=$username"); // Remove outsider IPv6s \DnsApi::query("/ipv6/purge/$ipv4/$ipv6"); } } /** * Put message to log * * @param string $msg Message */ protected function log(string $msg) { $this->di->get('logger')->info($msg); } }
Simpan