/** * Looks up user supplied email address / alias and sends a mail * * @param $email email address or username */ function sendMail($in) { $in = trim($in); if (is_email($in)) { $user_id = UserFinder::byEmail($in); } else { $user_id = UserFinder::byUsername($in); } $error = ErrorHandler::getInstance(); if (!$user_id) { $error->add('Invalid email address or username'); return false; } $email = UserSetting::getEmail($user_id); if (!$email) { throw new \Exception('entered email not found'); } $code = Token::generate($user_id, 'activation_code'); $pattern = array('/@USERNAME@/', '/@IP@/', '/@URL@/', '/@EXPIRETIME@/'); $user = User::get($user_id); $page = XmlDocumentHandler::getInstance(); $url = $page->getUrl() . 'u/reset_pwd/' . $code; $replacement = array($user->getName(), client_ip(), $url, shortTimePeriod($this->expire_time_email)); $msg = preg_replace($pattern, $replacement, $this->password_msg); //d($msg); $mail = SendMail::getInstance(); $mail->addRecipient($email); $mail->setSubject('Forgot password'); $mail->send($msg); return true; }
/** * Sends a account activation mail to specified user * * @param $_id user id */ function xxx_sendActivationMail($_id) { if (!is_numeric($_id)) { return false; } $email = loadUserdataEmail($_id); if (!$email) { return false; } $code = generateActivationCode(ACTIVATE_EMAIL, 1000000, 9999999); createActivation(ACTIVATE_EMAIL, $code, $_id); $subj = 'Account activation'; $pattern = array('/__USERNAME__/', '/__IP__/', '/__CODE__/', '/__URL__/', '/__EXPIRETIME__/'); $replacement = array(Users::getName($_id), client_ip(), $code, xhtmlGetUrl("activate.php?id=" . $_id . "&code=" . $code), shortTimePeriod($this->expire_time_email)); $msg = preg_replace($pattern, $replacement, $this->mail_activate_msg); if (!$this->SmtpSend($email, $subj, $msg)) { return false; } $this->activation_sent = true; return true; }
/** * Takes some work orders from the process queue and performs them */ function processQueue() { global $db, $config; //Only allows a few work orders being executed at once, so we can do this very often if (TaskQueue::getTaskQueueStatusCnt(ORDER_EXECUTING) >= $config['process']['process_limit']) { echo "TOO MUCH ACTIVE WORK, ABORTING\n"; return; } $job = TaskQueue::getOldestEntry(); if (!$job) { return; } //mark current job as "IN PROGRESS" so another process won't start on it aswell TaskQueue::markTask($job['entryId'], ORDER_EXECUTING); echo "\n\n-------------\n"; switch ($job['orderType']) { case TASK_IMAGE_RECODE: echo 'IMAGE RECODE<br/>'; if (!in_array($job['orderParams'], $h->files->image_mime_types)) { echo 'error: invalid mime type<br/>'; $h->session->log('Process queue error - image conversion destination mimetype not supported: ' . $job['orderParams'], LOGLEVEL_ERROR); break; } $newId = $h->files->cloneFile($job['referId'], FILETYPE_CLONE_CONVERTED); $exec_start = microtime(true); $check = convertImage($h->files->findUploadPath($job['referId']), $h->files->findUploadPath($newId), $job['orderParams']); $exec_time = microtime(true) - $exec_start; echo 'Execution time: ' . shortTimePeriod($exec_time) . '<br/>'; if (!$check) { $h->session->log('#' . $job['entryId'] . ': IMAGE CONVERT failed! format=' . $job['orderParams'], LOGLEVEL_ERROR); echo 'Error: Image convert failed!<br/>'; break; } $h->files->updateFile($newId, $job['orderParams']); markQueueCompleted($job['entryId'], $exec_time); break; case TASK_AUDIO_RECODE: //Recodes source audio file into orderParams destination format $dst_audio_ok = array('ogg', 'wma', 'mp3'); //FIXME: config item or $h->files->var if (!in_array($job['orderParams'], $dst_audio_ok)) { echo 'error: invalid mime type<br/>'; $h->session->log('Process queue error - audio conversion destination mimetype not supported: ' . $job['orderParams'], LOGLEVEL_ERROR); break; } $file = $h->files->getFileInfo($job['referId']); if (!$file) { echo 'Error: no fileentry existed for fileId ' . $job['referId']; break; } $newId = $h->files->cloneFile($job['referId'], FILETYPE_CLONE_CONVERTED); echo 'Recoding source audio of "' . $file['fileName'] . '" (' . $file['fileMime'] . ') to format ' . $job['orderParams'] . " ...\n"; switch ($job['orderParams']) { case 'application/x-ogg': //FIXME hur anger ja dst-format utan filändelse? tvingas göra det i 2 steg nu $dst_file = 'tmpfile.ogg'; $c = '/usr/local/bin/ffmpeg -i "' . $h->files->findUploadPath($job['referId']) . '" ' . $dst_file; break; case 'audio/x-ms-wma': $dst_file = 'tmpfile.wma'; $c = '/usr/local/bin/ffmpeg -i "' . $h->files->findUploadPath($job['referId']) . '" ' . $dst_file; break; case 'audio/mpeg': case 'audio/x-mpeg': //fixme: source & destination should not be able to be the same! $dst_file = 'tmpfile.mp3'; $c = '/usr/local/bin/ffmpeg -i "' . $h->files->findUploadPath($job['referId']) . '" ' . $dst_file; break; default: die('unknown destination audio format: ' . $job['orderParams']); } echo 'Executing: ' . $c . "\n"; $exec_time = exectime($c); echo 'Execution time: ' . shortTimePeriod($exec_time) . "\n"; if (!file_exists($dst_file)) { echo '<b>FAILED - dst file ' . $dst_file . " dont exist!\n"; break; } //FIXME: behöver inget rename-steg. kan skriva till rätt output fil i första steget rename($dst_file, $h->files->upload_dir . $newId); $h->files->updateFile($newId); markQueueCompleted($job['entryId'], $exec_time); break; case TASK_VIDEO_RECODE: echo "VIDEO RECODE:\n"; $exec_start = microtime(true); if (convertVideo($job['referId'], $job['orderParams']) === false) { markQueue($job['entryId'], ORDER_FAILED); } else { markQueueCompleted($job['entryId'], microtime(true) - $exec_start); } break; case TASK_FETCH: echo "FETCH CONTENT\n"; $fileName = basename($job['orderParams']); //extract filename part of url, used as "filename" in database $http = new HttpClient($job['orderParams']); $http->getHead(); if ($http->getStatus() != 200) { // retry in 20 seconds if file is not yet ready retryQueueEntry($job['entryId'], 20); break; } $newFileId = FileList::createEntry(FILETYPE_PROCESS, 0, 0, $fileName); $c = 'wget ' . escapeshellarg($job['orderParams']) . ' -O ' . FileInfo::getUploadPath($newFileId); echo "\$ " . $c . "\n"; $retval = 0; $exec_time = exectime($c, $retval); if (!$retval) { //TODO: process html document for media links if it is a html document TaskQueue::markTaskCompleted($job['entryId'], $exec_time, $newFileId); FileInfo::updateData($newFileId); } else { //wget failed somehow, delay work for 1 minute retryQueueEntry($job['entryId'], 60); $files->deleteFile($newFileId, 0, true); //remove failed local file entry } break; case TASK_CONVERT_TO_DEFAULT: echo "CONVERT TO DEFAULT\n"; //referId is entryId of previous proccess queue order $params = unserialize($job['orderParams']); $prev_job = TaskQueue::getEntry($job['referId']); if ($prev_job['orderStatus'] != ORDER_COMPLETED) { retryQueueEntry($job['entryId'], 60); break; } $file = $files->getFileInfo($prev_job['referId']); $exec_start = microtime(true); $newId = false; switch ($file['mediaType']) { case MEDIATYPE_VIDEO: $newId = convertVideo($prev_job['referId'], $h->files->default_video, !empty($params['callback']) ? false : true, !empty($params['watermark']) ? $params['watermark'] : ''); break; case MEDIATYPE_AUDIO: $newId = convertAudio($prev_job['referId'], $h->files->default_audio); break; default: echo "UNKNOWN MEDIA TYPE " . $file['mediaType'] . ", MIME TYPE " . $file['fileMime'] . ", CANNOT CONVERT MEDIA!!!\n"; break; } if (!$newId) { markQueue($job['entryId'], ORDER_FAILED); return false; } markQueueCompleted($job['entryId'], microtime(true) - $exec_start); if (empty($params['callback'])) { break; } //'uri' isnt known before the new file is created so it is added at this point $uri = $config['core']['full_url'] . 'api/file.php?id=' . $newId; $params['callback'] .= (strpos($params['callback'], '?') !== false ? '&' : '?') . 'uri=' . urlencode($uri); $data = file_get_contents($params['callback']); echo "Performing callback: " . $params['callback'] . "\n\n"; echo "Callback script returned:\n" . $data; storeCallbackData($job['entryId'], $data, $params); break; default: echo "Unknown ordertype: " . $job['orderType'] . "\n"; d($job); die; } }
<?php require_once 'config.php'; require 'design_head.php'; echo xhtmlMenu($user_menu, 'blog_menu'); echo 'Users online (was active in the last ' . shortTimePeriod($session->online_timeout) . ')<br/><br/>'; $list = Users::allOnline(); foreach ($list as $row) { echo Users::link($row['userId'], $row['userName']) . ' at ' . $row['timeLastActive'] . '<br/>'; } require 'design_foot.php';