HEX
Server: Apache/2.4.59 (Debian)
System: Linux keymana 4.19.0-21-cloud-amd64 #1 SMP Debian 4.19.249-2 (2022-06-30) x86_64
User: lijunjie (1003)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/doco/keytest/wp-content/themes/ormedia/daemon-negawatt.php
<?php
//header('Content-type: text/html; charset=utf-8');
// require_once 'key_alert_functions.php';
require_once "/var/www/html/wp-load.php";
require_once '/var/www/html/wp-content/themes/ormedia/key_alert_functions.php';

echo current_time("Y-m-d H:i:s") . PHP_EOL;


$mbox = imap_open("{imap.exmail.qq.com:993/imap/ssl}INBOX", "jacky.mok@keylab.cc", "Bldp0wer!");

// echo "<h1>Mailboxes</h1>\n";

$emails = imap_search($mbox, 'UNSEEN');

if ($emails) {
	$output = '';
	rsort($emails);

	foreach ($emails as $email_number) {
		$overview = imap_fetch_overview($mbox, $email_number, 0);
		$structure = imap_fetchstructure($mbox, $email_number);
		$h = imap_headerinfo($mbox, $email_number, 100, 100);
		$creation = preg_replace("/\+.*/", "", $h->date);
		if (isset($structure->parts) && is_array($structure->parts) && isset($structure->parts[1])) {
			if (is_array($h->to)) {
				if ($h->to[0]->mailbox != "alert") {
					continue;
				}
			}
			$part = $structure->parts[1];
			$status = imap_setflag_full($mbox, $email_number, "\\Seen", ST_UID);
			$message = imap_fetchbody($mbox, $email_number, 2);
			$stitle = preg_replace("/\'/", "", (base64_decode($h->Subject)));
			$title = substr($stitle, 3, strlen($stitle) - 4);
			if ($part->encoding == 3) {
				$message = imap_base64($message);
			} else if ($part->encoding == 1) {
				$message = imap_8bit($message);
			} else {
				$message = imap_qprint($message);
			}
			$data = [
				'title' => "Keylab Alert: " . $creation,
				'alert' => $title,
				'extras' => [
					'msg_id' => $wpdb->insert_id,
				]
			];
			$msg = $wpdb->get_row("SELECT * from keylab_alert_msg where msgid=" . $email_number);
			echo 'Processing email: ' . $email_number . ' ' . $title . PHP_EOL;
			if ($msg->id > 0) {
				echo 'Mail already exist, ignoring mail. Part 1' . PHP_EOL;
			} else {

				$id = c_alert($title, $message, 0, $email_number);
				if ($id > 0) {
					echo 'Processing mail' . PHP_EOL;
					$alert = r_alert($id);
					$push_id = get_push_id_by_cat($cat);
					$res = send_alert($alert, $push_id);
					echo 'Mail already exist, ignoring mail. Part 2' . PHP_EOL;
				} else {
					echo 'Processing mail' . PHP_EOL;
					// $alert = r_alert($id);
					// $push_id = get_push_id_by_cat($cat);
					// $res = send_alert($alert, $push_id);
				}
			}
		}
	}
}

imap_close($mbox);


?>