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:
CliTask.php
<?php /** * CliTask, Support cli task * * @copyright Copyright (c) 2007 DotRoll Kft. (http://www.dotroll.com) * @author Zoltán Istvanovszki <zoltan.istvanovszki@dotroll.com> * @since 2017.06.09. * @package CXS_2.0 */ use Phalcon\Di\Di; class CliTask extends \CommonTask { /** * Common task injection */ public function onConstruct() { // Maybe no need lock // $this->lock(__CLASS__); } /** * Just an empty action for empty task */ public function mainAction() { $this->helpAction(); } /** * Print a CXS tool version */ public function versionAction() { $this->printVersion(); } /** * Show a usage */ public function helpAction() { $this->printVersion(); $this->printUsage(); } /** * Get a CXS result * * @param string $hash Username */ public function getAction(string $hash = '') { $this->beforeTask('Get a CXS result'); /* @var $cxs \CXS\CXS */ $cxs = $this->di->get('cxs'); $cxs->scan($hash, 'cli'); $this->afterTask(); } /** * Check a webhost * * @param string $hash Username */ public function checkAction(string $hash = '') { $this->beforeTask('Check a webhost'); /* @var $cxs \CXS\CXS */ $cxs = $this->di->get('cxs'); $cxs->check($hash, 'cli'); $this->afterTask(); } /** * Unsuspend a webhost * * @params string $hash Username */ public function unsuspendAction(string $hash = '') { $this->beforeTask('Unsuspend a webhost'); /* @var $unsuspend \CXS\Unsuspend */ $unsuspend = $this->di->get('unsuspend'); $unsuspend->execute($hash); $this->afterTask(); } /** * Suspend a webhost * * @params string $hash Username */ public function suspendAction(string $hash = '') { $this->beforeTask('Suspend a webhost'); /* @var $suspend \CXS\Suspend */ $suspend = $this->di->get('suspend'); $suspend->execute($hash); $this->afterTask(); } /** * E-mail limit a webhost * * @params string $hash Username */ public function limitAction(string $hash = '') { $this->beforeTask('E-mail limit a webhost'); /* @var $limit \CXS\Limit */ $limit = $this->di->get('limit'); $limit->execute($hash); $this->afterTask(); } /** * Restore e-mail limit * * @params string $hash Username */ public function restoreAction(string $hash = '') { $this->beforeTask('Restore e-mail limit'); /* @var $limit \CXS\Limit */ $limit = $this->di->get('limit'); $limit->restore($hash); $this->afterTask(); } /** * Disable cron * * @param string $hash Username */ public function disableCronAction(string $hash = '') { $this->beforeTask('Disable cron'); /* @var $suspend \CXS\Suspend */ $suspend = $this->di->get('suspend'); $suspend->disableCron($hash); $this->afterTask(); } /** * Restore cron * * @param string $hash Username */ public function restoreCronAction(string $hash = '') { $this->beforeTask('Restore cron'); /* @var $unsuspend \CXS\Unsuspend */ $unsuspend = $this->di->get('unsuspend'); $unsuspend->restoreCron($hash); $this->afterTask(); } /** * Remove a suspend reditect * * @param string $hash Username */ public function removeRedirectAction(string $hash = '') { $this->beforeTask('Remove a suspend reditect'); /* @var $unsuspend \CXS\Unuspend */ $unsuspend = $this->di->get('unsuspend'); $unsuspend->removeSuspendRedirect($hash); $this->afterTask(); } /** * Add a suspend reditect * * @params string $hash Username */ public function addRedirectAction(string $hash = '') { $this->beforeTask('Add a suspend reditect'); /* @var $suspend \CXS\Suspend */ $suspend = $this->di->get('suspend'); $suspend->addRedirect($hash); $this->afterTask(); } /** * List email limited webhosts */ public function limitedEmailsAction() { $this->beforeTask('List email limited webhosts'); /* @var $limit \CXS\Limit */ $limit = $this->di->get('limit'); $limit->list(); $this->afterTask(); } /** * List suspended webhosts */ public function listLimitedAction() { $this->beforeTask('List suspended webhosts'); /* @var $suspend \CXS\Suspend */ $suspend = $this->di->get('suspend'); $suspend->list(); $this->afterTask(); } /** * List notice emails * * @param string $hash Username */ public function listNoticeAction(string $hash = '') { $this->checkHash($hash); $this->lista($hash, 'notice'); } /** * List suspend emails * * @param string $hash Username */ public function listSuspendAction(string $hash = '') { $this->checkHash($hash); $this->lista($hash, 'suspend'); } /** * List active riport * * @param string $hash Username */ public function listReportAction(string $hash = '') { $this->checkHash($hash); $this->beforeTask("List active riport for $hash"); /* @var $reports \Reports */ $reports = \Reports::findByHash($hash); foreach ($reports as $report) { echo "Report time: {$report->datetime}" . \PHP_EOL; echo 'Report message:' . \PHP_EOL . $report->message . \PHP_EOL; } $this->success(); } /** * Multiple backup clean */ public function backupCleanAction() { $backups = []; foreach (\glob('/home/*/backup-*.tar.gz') as $backup) { $tmp = \explode('/', $backup); $backups[$tmp[2]][] = $backup; } foreach ($backups as $hash => $backup) { if (\count($backup) > 1) { if ($this->getType() == 'DirectAdmin') { echo "delete: $file\n"; \unlink($file); } else { /* @var $cpanel \CXS\Cpanel */ $cpanel = $this->di->get('cpanel'); $data = $cpanel->cAPI("accountsummary?user=$hash"); if (!empty($data['acct'][0]['owner']) && \in_array($data['acct'][0]['owner'], ['root', 'freeweb', 'freemail', 'domainab'])) { foreach ($backup as $file) { echo "delete: $file\n"; \unlink($file); } } } } } } /** * Migrate old sqlite stuff */ public function migrateAction() { if (\is_file('/opt/CXS/cxs.sqlite3')) { $server = \gethostname(); echo "Migrate $server" . \PHP_EOL; $sqlLite = new \PDO('sqlite:/opt/CXS/cxs.sqlite3'); $sqlLite->setAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE, \PDO::FETCH_ASSOC); $sqlLite->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); // reports \Reports::findByHostname($server)->delete(); \Results::findByHostname($server)->delete(); $sql = " SELECT * FROM `reports` "; foreach ($sqlLite->query($sql)->fetchAll() as $row) { $infected = \strpos($row['message'], '# ') !== false ? true : false; (new \Reports([ 'datetime' => $row['time'], 'enviroment' => 'cron', 'hash' => $row['hash'], 'hostname' => $server, 'infected' => $infected, 'message' => $row['message'], ]))->save(); (new \Results([ 'datetime' => $row['time'], 'enviroment' => 'cron', 'hash' => $row['hash'], 'hostname' => $server, 'infected' => $infected, 'message' => $row['message'], ]))->save(); } // messages \Messages::findByHostname($server)->delete(); $sql = " SELECT * FROM `messages` "; foreach ($sqlLite->query($sql)->fetchAll() as $row) { (new \Messages([ 'reason' => $row['reason'] == 'alert' ? 'notice' : 'suspend', 'hash' => $row['hash'], 'hostname' => $server, 'datetime' => $row['time'], ]))->save(); } // emaillimit \Emaillimit::findByHostname($server)->delete(); $sql = " SELECT * FROM `emaillimit` WHERE elimit > 0 "; foreach ($sqlLite->query($sql)->fetchAll() as $row) { (new \Emaillimit([ 'hash' => $row['hash'], 'hostname' => $server, 'elimit' => $row['elimit'], ]))->save(); } // Suspended \Suspended::findByHostname($server)->delete(); foreach (\glob("/usr/local/apache/conf/userdata/cxs/*.conf") as $path) { (new \Suspended([ 'hash' => \str_replace('.conf', '', \basename($path)), 'hostname' => $server, 'datetime' => \date('Y-m-d H:i:s', \filemtime($path)), ]))->save(); } \rename('/opt/CXS/cxs.sqlite3', '/opt/CXS/cxs.sqlite3.migrated'); $this->success(); } } /** * List avaliable tubes */ public function listTubesAction() { echo "List tubes" . \PHP_EOL; $request = $this->getBeanstalkInstance(); echo 'Stats:' . \PHP_EOL; foreach ($request->listTubes() as $tube) { echo $tube . \PHP_EOL; // ZebraZ::l($request->statsTube($tube)); // echo \PHP_EOL; } $this->success(); } /** * Stats tube * @param array|null $params */ public function statTubeAction(string $tube = '') { if (empty($tube)) { echo "Parameter tube missing!\n"; echo "Usage: cli.php statTube tube\n"; die(); } echo "Stat tube: $tube" . \PHP_EOL; $request = $this->getBeanstalkInstance(); echo 'Stats:' . \PHP_EOL; ZebraZ::l($request->statsTube($tube)); echo \PHP_EOL; $this->success(); } /** * Empty tube * * @param string $tube */ public function emptyTubeAction(string $tube = '') { if (empty($tube)) { echo "Parameter tube missing!\n"; echo "Usage: cli.php statTube tube\n"; die(); } echo "Empty tube: $tube" . \PHP_EOL; $request = $this->getBeanstalkInstance(); echo 'Stats:' . \PHP_EOL; ZebraZ::l($request->statsTube($tube)); $request->useTube($tube); while (true) { if (@$request->stats() === false) { echo "Tube stats failed\n"; die(); } /** * @var \Pheanstalk\Job */ $job = $request->peekReady(); if (!empty($job)) { echo \date('Y-m-d H:i:s') . \chr(9) . 'Delete task: ' . \json_encode(\unserialize($job->getData())) . \PHP_EOL; $request->delete($job); } else { echo "Truncate tube success\n"; die(); } \usleep(50000); } echo \PHP_EOL; $this->success(); } // public function ticketAction(array $params) { // $hash = $this->getHash($params); // // ZebraZ::l($this->di->get('config')->application->enviroment);die(); // // /* @var $ticket \CXS\Ticket */ // $ticket = $this->di->get('ticket'); // $ticket->open('notice', $hash, 'EZ A LOG', 2); // // $this->success(); // } /** * List e-mail by type * * @param string $hash User * @param string $reason Reason */ private function lista(string $hash, string $reason) { $this->beforeTask("List $hash $reason emails"); /* @var $messages \Messages */ $messages = \Messages::find([ 'hash = :hash: AND reason = :reason:', 'bind' => ['hash' => $hash, 'reason' => $reason], 'order' => 'id ASC' ]); foreach ($messages as $message) { echo $message->datetime . \PHP_EOL; } $this->success(); } /** * Print Command completed successfully */ private function success() { echo 'Command completed successfully' . \PHP_EOL; } /** * Check hash * * @param string $hash Username * @return int */ private function checkHash(string $hash) { if (empty($hash)) { echo "Parameter HASH missing!\n\n"; $this->printUsage(); die(); } $posix = \posix_getpwnam($hash); if (empty($posix['uid'])) { echo "$hash user no exist this server\n\n"; $this->printUsage(); die(); } return $posix['uid']; } /** * Print CXS tool version */ private function printVersion() { echo "DotRoll CXS support cli tool version {$this->di->get('config')->application->version}\n"; echo "Copyright (C) " . \date('Y') . " by Zoltán Istvanovszki.\n"; echo " DotRoll <domreg@dotroll.com>\n"; } /** * Print usage */ private function printUsage() { echo "Usage: ./cli.php TASK [hash]\n\n"; echo "Tasks:\n"; echo " version\t\tPrint a CXS tool version\n"; echo " help\t\t\tShow this help\n"; echo " check [hash]\t\tCheck a webhost\n"; echo " unsuspend [hash]\tUnsuspend a webhost\n"; echo " get [hash]\t\tGet a CXS result\n"; echo " suspend [hash]\t\tSuspend a webhost\n"; echo " limit [hash]\t\tE-mail limit a webhost\n"; echo " restore [hash]\t\tRestore e-mail limit\n"; echo " disableCron [hash]\tDisable cron\n"; echo " restoreCron [hash]\tRestore cron\n"; echo " removeRedirect [hash]\tRemove a suspend reditect\n"; echo " addRedirect [hash]\tAdd a suspend reditect\n"; echo " limitedEmails\t\tList email limited webhosts\n"; echo " listLimited\t\tList suspended webhosts\n"; echo " listNotice [hash]\tList notice emails\n"; echo " listSuspend [hash]\tList suspend emails\n"; echo " listReport [hash]\tList active riport\n"; echo " backupClean\t\tMultiple backup clean\n"; } /** * List packages */ public function listPackagesAction() { if ($this->getType() != 'DirectAdmin') { echo 'Only DirectAdmin!'; return; } $packages = []; foreach (\array_map('trim', \file('/usr/local/directadmin/data/users/admin/packages.list')) as $package) { $packages[$package] = \parse_ini_file("/usr/local/directadmin/data/users/admin/packages/$package.pkg"); } echo \json_encode($packages, \JSON_PRETTY_PRINT); } /** * Open a CXS ticket * * @param string $reason * @param string $hash * @param string $log */ public function openTicketAction(string $reason, string $hash, string $log) { if (empty($reason) || !\in_array($reason, ['notice', 'suspend', 'restore'])) { echo "Parameter REASON missing!\n\n"; $this->printUsage(); die(); } if (empty($hash)) { echo "Parameter HASH missing!\n\n"; $this->printUsage(); die(); } if (empty($log)) { echo "Parameter LOG missing!\n\n"; $this->printUsage(); die(); } $this->beforeTask('Open CXS ticket'); $until = new \DateTime(); $until->add(new \DateInterval('P3D')); /* @var $ticket \CXS\Ticket */ $ticket = $this->di->get('ticket'); $ticket->open($reason, $hash, $log, $until->format('Y-m-d H:i:s')); $this->afterTask(); } /** * Called before the task is handled * Print and log message * * @param string $msg Message */ private function beforeTask(string $msg) { echo $msg . \PHP_EOL; $this->log($msg); } /** * Called after the task is handled */ private function afterTask() { echo $this->dispatcher->getParam('jobResponse'); $this->success(); } }
Simpan