Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function DialogInfo($message) {
- echo(" <div class=\"alert alert-info fade in\">
- <button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-hidden=\"true\">x</button>
- ");
- echo($message);
- echo(" </div>
- ");
- }
- function DialogWarning($message) {
- echo(" <div class=\"alert alert-warning fade in\">
- <button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-hidden=\"true\">x</button>
- ");
- echo($message);
- echo(" </div>
- ");
- }
- function DialogError($message) {
- echo(" <div class=\"alert alert-danger fade in\">
- <button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-hidden=\"true\">x</button>
- ");
- echo($message);
- echo(" </div>
- ");
- }
- function DialogSuccess($message) {
- echo(" <div class=\"alert alert-success fade in\">
- <button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-hidden=\"true\">x</button>
- ");
- echo($message);
- echo(" </div>
- ");
- }
- function timezone_select_html($selected = false) {
- $return = "";
- $timezones = DateTimeZone::listIdentifiers(DateTimeZone::ALL);
- foreach ($timezones as $label => $timezone) {
- error_reporting(-1);
- ini_set("display_errors", "On");
- $t = new DateTimeZone($timezone);
- $c = new DateTime(null, $t);
- $currenttime = $c->format("g:i A");
- $label = $timezone;
- $return .= "<option value=\"" . $timezone . "\"" . ($timezone == $selected ? " selected=selected" : "") . (">" . $label . " - " . $currenttime . "</option>");
- }
- return $return;
- }
- function timezone_array() {
- $timezones = DateTimeZone::listIdentifiers(DateTimeZone::ALL);
- $timezone_offsets = array();
- foreach ($timezones as $timezone) {
- $tz = new DateTimeZone($timezone);
- $timezone_offsets[$timezone] = $tz->getOffset(new DateTime());
- }
- asort($timezone_offsets);
- $timezone_list = array();
- foreach ($timezone_offsets as $timezone => $offset) {
- $offset_prefix = $offset < 0 ? "-" : "+";
- $offset_formatted = gmdate("H:i", abs($offset));
- $pretty_offset = "UTC" . $offset_prefix . $offset_formatted;
- $timezone_list[$timezone] = "(" . $pretty_offset . ") " . $timezone;
- }
- return $timezone_list;
- }
- function InitiateDebugging() {
- global $setting;
- if (!(isset($setting["debugging"]))) {
- return false;
- }
- switch ($setting["debugging"]) {
- case "errors":
- ini_set("display_errors", "On");
- error_reporting(-1);
- break;
- case "warnings":
- ini_set("display_errors", "On");
- error_reporting(255);
- break;
- case "disabled":
- ini_set("display_errors", "Off");
- error_reporting(0);
- }
- }
- function LogError($ServiceID = "sys", $message, $DATA) {
- global $setting;
- $DATA = wordwrap(base64_encode($DATA), 10000, "
- ", true);
- $handle = @fopen($setting["dir_to_cpanel"] . "temp/error." . $ServiceID . __DIR__ . time() . ".log", "w");
- @fwrite($handle, $method . "
- ");
- @fwrite($handle, $message . "
- ");
- @fwrite($handle, $DATA);
- @fclose($handle);
- }
- function time_to_timezone($time, $ConvertToTimezone, $ConvertFromTimezone = false) {
- $dateFormat = "Y-m-d H:i:s";
- $date = date($dateFormat, $time);
- $date = date_to_timezone($dateFormat, $date, $ConvertToTimezone, $ConvertFromTimezone);
- return strtotime($date);
- }
- function date_to_timezone($dateFormat, $date, $ConvertToTimezone, $ConvertFromTimezone = false, $returnUnix = false) {
- $DefaultTimezone = date_default_timezone_get();
- $OriginalTimezone = $ConvertFromTimezone ? $ConvertFromTimezone : $DefaultTimezone;
- $OriginalDate = new DateTime($date, new DateTimeZone($OriginalTimezone));
- date_default_timezone_set($ConvertToTimezone);
- $result = date($dateFormat, $OriginalDate->format("U"));
- if ($returnUnix) {
- $result = strtotime($result);
- }
- date_default_timezone_set($DefaultTimezone);
- return $result;
- }
- function strtotimefromtimezone($dateFormat, $date, $ConvertFromTimezone) {
- $Date = date_to_timezone($dateFormat, $date, date_default_timezone_get(), $ConvertFromTimezone);
- return strtotime($Date);
- }
- function timezone_offset($time, $ConvertToTimezone) {
- $DefaultTZ = new DateTimeZone(date_default_timezone_get());
- $ConvertTZ = new DateTimeZone($ConvertToTimezone);
- $Offset = $DefaultTZ->getOffset($ConvertTZ);
- if (0 < $Offset) {
- return $time + $Offset;
- }
- return $time - $Offset;
- }
- function timezone_get_offset($ConvertToTimezone) {
- $dateTimeZoneFrom = new DateTimeZone(date_default_timezone_get());
- $dateTimeZoneTo = new DateTimeZone($ConvertToTimezone);
- $dateTimeFrom = new DateTime("now", $dateTimeZoneFrom);
- $dateTimeTo = new DateTime("now", $dateTimeZoneTo);
- $timeOffset = $dateTimeZoneTo->getOffset($dateTimeFrom) - $dateTimeZoneFrom->getOffset($dateTimeFrom);
- $f = ":";
- $t = $timeOffset;
- return $t < 0 ? "-" : "+" . sprintf("%02d%s%02d", floor(abs($t) / 3600), $f, abs($t) / 60 % 60, $f, abs($t) % 60);
- }
- function max_upload_size() {
- $POSTMAXSIZE = numeric_make(ini_get("post_max_size"));
- $UPLOADMAXSIZE = numeric_make(ini_get("upload_max_filesize"));
- return $UPLOADMAXSIZE < $POSTMAXSIZE ? $UPLOADMAXSIZE : $POSTMAXSIZE;
- }
- function path($path) {
- if (substr(PHP_OS, 0, 3) == "WIN") {
- return str_replace(array("/", "\\"), "/", $path);
- }
- return str_replace(array("/", "\\"), "/", $path);
- }
- function SystemLogError($data) {
- if (isset($_GET["debug"])) {
- echo($data);
- }
- $handle = fopen(BASE . "temp/system_log.txt", "w");
- fwrite($handle, $data . "
- ");
- fclose($handle);
- }
- function UpgradeLogError($data) {
- if (isset($_GET["debug"])) {
- echo($data);
- }
- $handle = fopen(BASE . "temp/upgrade_log.txt", "w");
- fwrite($handle, $data . "
- ");
- fclose($handle);
- }
- function StatCacheSmarty($params, &$smarty) {
- global $smarty;
- $smarty->assign("StatCache", StatCache_Retrieve($params["service_id"]));
- }
- function StatCache_Retrieve($server_id) {
- global $db_prefix;
- $selectStatCache = mysql_query("SELECT * FROM " . $db_prefix . "statcache WHERE server_id=" . $server_id);
- if (mysql_num_rows($selectStatCache) == 0) {
- $arr["status"] = false;
- $arr["bitrate"] = 0;
- $arr["format"] = "";
- $arr["connections"] = 0;
- $arr["nowplaying"] = "";
- $arr["transfer"] = 0;
- mysql_query("INSERT INTO " . $db_prefix . "statcache (server_id, status, bitrate, connections, nowplaying, transfer, lastupdated)
- VALUES(" . $server_id . ", '" . $arr["status"] . "', " . $arr["bitrate"] . "," . $arr["connections"] . ",'" . $arr["nowplaying"] . "'," . $arr["transfer"] . "," . time() . ")");
- return $arr;
- }
- return mysql_fetch_assoc($selectStatCache);
- }
- function StatCache_Update($server_id, $arr) {
- global $db_prefix;
- if (!$arr || count($arr) == 0) {
- return false;
- }
- $selectStatCache = mysql_query("SELECT * FROM " . $db_prefix . "statcache WHERE server_id=" . $server_id);
- if (mysql_num_rows($selectStatCache) == 0) {
- $arr["status"] = isset($arr["status"]) ? $arr["status"] * 1 : false;
- $arr["bitrate"] = isset($arr["bitrate"]) ? $arr["bitrate"] * 1 : 0;
- $arr["format"] = isset($arr["format"]) ? alphanumeric_make($arr["format"], "/") : 0;
- $arr["connections"] = isset($arr["connections"]) ? $arr["connections"] * 1 : 0;
- $arr["nowplaying"] = isset($arr["nowplaying"]) ? alphanumeric_make($arr["nowplaying"], " ") : "";
- $arr["transfer"] = isset($arr["transfer"]) ? $arr["transfer"] * 1 : 0;
- foreach ($arr as $field => $value) {
- $arr[$field] = mysql_real_escape_string($value);
- }
- mysql_query("INSERT INTO " . $db_prefix . "statcache (server_id, status, bitrate, connections, nowplaying, transfer, lastupdated)
- VALUES(" . $server_id . ", '" . $arr["status"] . "', " . $arr["bitrate"] . "," . $arr["connections"] . ",'" . $arr["nowplaying"] . "'," . $arr["transfer"] . "," . time() . ")");
- echo(mysql_error());
- }
- $cache = mysql_fetch_assoc($selectStatCache);
- $arr["status"] = isset($arr["status"]) ? alphanumeric_make($arr["status"]) : $cache["status"];
- $arr["bitrate"] = isset($arr["bitrate"]) ? $arr["bitrate"] * 1 : $cache["bitrate"];
- $arr["format"] = isset($arr["format"]) ? alphanumeric_make($arr["format"], "/") : $cache["format"];
- $arr["connections"] = isset($arr["connections"]) ? $arr["connections"] * 1 : $cache["connections"];
- $arr["nowplaying"] = isset($arr["nowplaying"]) ? alphanumeric_make($arr["nowplaying"], " ") : $cache["nowplaying"];
- $arr["transfer"] = isset($arr["transfer"]) ? $arr["transfer"] * 1 : $cache["transfer"];
- mysql_query("UPDATE " . $db_prefix . "statcache SET
- status='" . $arr["status"] . "',
- bitrate='" . $arr["bitrate"] . "',
- format='" . $arr["format"] . "',
- connections='" . $arr["connections"] . "',
- nowplaying='" . $arr["nowplaying"] . "',
- transfer='" . $arr["transfer"] . "',
- lastupdated=" . time() . (" WHERE server_id=" . $server_id));
- echo(mysql_error());
- return true;
- }
- function SecureUniqueID($input) {
- return alphanumeric_make($input, "-_");
- }
- function serviceStatusCheckUpdate($service_id, $state) {
- global $db_prefix;
- if (!(is_numeric($service_id))) {
- return false;
- }
- return mysql_query("UPDATE " . $db_prefix . "servers SET laststatuscheck=" . time() . ", laststate='" . $state . "' WHERE id=" . $service_id);
- }
- function get_rrd_path($os = "default") {
- if ($os == "default") {
- global $setting;
- $os = $setting["os"];
- }
- if (substr(PHP_OS, 0, 3) == "WIN") {
- return "C:/xampp/CastControl/rrdtool/rrdtool.exe";
- }
- $rrd = @exec("which rrdtool");
- if (!(strstr($rrd, "no rrdtool in")) && is_executable($rrd)) {
- return $rrd;
- }
- if (is_executable("/usr/local/cpanel/3rdparty/bin/rrdtool")) {
- return "/usr/local/cpanel/3rdparty/bin/rrdtool";
- }
- if (is_executable("/usr/local/rrdtool-1.3.6/bin/rrdtool")) {
- return "/usr/local/rrdtool-1.3.6/bin/rrdtool";
- }
- return "/usr/bin/rrdtool";
- }
- function get_ffmpeg() {
- if (substr(PHP_OS, 0, 3) == "WIN") {
- return "C:/xampp/CastControl/ffmpeg/ffmpeg.exe";
- }
- $ffmpeg = @exec("which ffmpeg");
- if (!(strstr($ffmpeg, "no ffmpeg in")) && is_executable($ffmpeg)) {
- return $ffmpeg;
- }
- if (is_executable("/usr/local/bin/ffmpeg")) {
- return "/usr/local/bin/ffmpeg";
- }
- if (is_executable("/usr/bin/ffmpeg")) {
- return "/usr/bin/ffmpeg";
- }
- return "/usr/bin/ffmpeg";
- }
- function get_ffprobe() {
- if (substr(PHP_OS, 0, 3) == "WIN") {
- return "C:/xampp/CastControl/ffmpeg/ffprobe.exe";
- }
- $ffprobe = @exec("which ffprobe");
- if (!(strstr($ffprobe, "no ffprobe in")) && is_executable($ffprobe)) {
- return $ffprobe;
- }
- if (is_executable("/usr/local/bin/ffprobe")) {
- return "/usr/local/bin/ffprobe";
- }
- if (is_executable("/usr/bin/ffprobe")) {
- return "/usr/bin/ffprobe";
- }
- return "/usr/bin/ffprobe";
- }
- function logServerAction($serverData, $type, $action) {
- global $setting;
- global $data;
- if (!(isset($setting["logactions"]))) {
- return false;
- }
- $handle = fopen(BASE . ("actionlogs/" . $serverData["portbase"] . ".log"), "a");
- fwrite($handle, "---------------------------
- " . "Server Action: " . $action . " (" . $type . ")" . "
- " . "System ID: " . $serverData["system_id"] . "
- " . "CastQ?: " . defined("is_cron") ? "Yes" : "No" . "
- " . "Misc:
- " . print_r($_SERVER["argv"], true) . "
- ");
- fclose($handle);
- }
- function queue_add($type, $plugin, $action, $actionid, $systemid = 1, $custom = "none", $forced = 0) {
- global $userdata;
- global $db_prefix;
- global $setting;
- $type = secure_input($type);
- $action = secure_input($action);
- $actionid = secure_input($actionid);
- if ($setting["daemon_method"] == "daemon" && !(defined("is_daemon"))) {
- $array = array("type" => $type, "plugin" => $plugin, "serviceid" => $actionid, "action" => $action, "custom" => $custom);
- require_once(BASE . "system/misc/includes/daemon.class.php");
- $daemonClient = new daemon_client();
- $request = $daemonClient->exec($array);
- if (!$request) {
- return array("status" => "failed", "method" => "daemon", "error" => "Could not connect to daemon service");
- }
- return array("status" => $request["status"], "method" => "daemon", "error" => $request["error"]);
- }
- $select = mysql_query("SELECT id, forced, completed FROM " . $db_prefix . ("cmdqueue WHERE type='" . $type . "' AND plugin='" . $plugin . "' AND actionid='" . $actionid . "'"));
- if (0 < mysql_num_rows($select)) {
- if (mysql_result($select, 0, "forced") == 1 && mysql_result($select, 0, "completed") == 0) {
- return false;
- }
- mysql_query("UPDATE " . $db_prefix . ("cmdqueue SET forced=" . $forced . ", action='" . $action . "', systemid=" . $systemid . ", completed=0, custom='" . $custom . "', timestamp=") . time() . " WHERE id=" . mysql_result($select, 0, "id"));
- }
- else {
- mysql_query("INSERT INTO " . $db_prefix . ("cmdqueue (forced, type, plugin, action, actionid, systemid, custom, timestamp) VALUES(" . $forced . ", '" . $type . "', '" . $plugin . "', '" . $action . "', '" . $actionid . "', '" . $systemid . "', '" . $custom . "', ") . time() . ") ");
- }
- echo(mysql_error());
- return array("status" => "queued", "method" => "queue", "error" => "");
- }
- function copyr($source, $dest) {
- if (!(is_dir($source))) {
- return copy($source, $dest);
- }
- if (!(is_dir($dest))) {
- mkdir($dest);
- }
- foreach (glob($source . "/*") as $entry) {
- if (file_exists($dest . "/" . basename($entry))) {
- continue;
- }
- copyr($entry, $dest . "/" . basename($entry));
- }
- return true;
- }
- function dirsize($path) {
- $size = 0;
- if (substr($path, -1, 1) !== DIRECTORY_SEPARATOR) {
- $path .= DIRECTORY_SEPARATOR;
- }
- if (is_file($path)) {
- return filesize($path);
- }
- if (!(is_dir($path))) {
- return false;
- }
- $queue = array($path);
- $i = 0;
- $j = count($queue);
- while ($i < $j) {
- $parent = $i;
- if (is_dir($queue[$i]) && $dir = @dir($queue[$i])) {
- $subdirs = array();
- while (false !== ($entry = $dir->read())) {
- if ($entry == __DIR__ || $entry == "..") {
- continue;
- }
- $path = $queue[$i] . $entry;
- if (is_dir($path)) {
- $path .= DIRECTORY_SEPARATOR;
- $subdirs[] = $path;
- continue;
- }
- if (!(is_file($path))) {
- continue;
- }
- $size += filesize($path);
- }
- unset($queue[0]);
- $queue = array_merge($subdirs, $queue);
- $i = -1;
- $j = count($queue);
- $dir->close();
- unset($dir);
- }
- ++$i;
- }
- return $size;
- }
- function microtime_float() {
- list($usec, $sec) = explode(" ", microtime());
- return (float)$usec + (float)$sec;
- }
- function checkRequiredFunctions() {
- global $setting;
- $errorArray = array();
- $status = "success";
- if (ini_get("safe_mode")) {
- $status = "failed";
- $errorArray[] = "Your PHP installation has Safe-Mode Enabled<br />Cast-Control <b>CANNOT</b> function with safe-mode enabled";
- }
- $disabledFunctions = ini_get("disable_functions");
- $requestedFunctions = "";
- if (!(empty($disabledFunctions))) {
- $RequiredFunctions = array("exec", "shell_exec", "system", "chmod", "sleep", "set_time_limit", "ignore_user_abort");
- foreach ($RequiredFunctions as $Function) {
- if (!(strstr($disabledFunctions, $Function))) {
- continue;
- }
- $requestedFunctions .= "<li>" . $Function . "()</li>";
- }
- }
- if (is_array($requestedFunctions)) {
- $status = "failed";
- $errorArray[] = "Some features required by cast-control are disabled in your PHP.ini file<br />Please ensure the following functions are allowed:<ul>" . $requestedFunctions . "</ul>";
- }
- if (!(strstr($setting["os"], "windows"))) {
- if (in_array($phpacct, array("nobody", "apache", "root"))) {
- $permlvl = 777;
- }
- else {
- $permlvl = 755;
- }
- $perms["content/"] = array(substr(sprintf("%o", fileperms(BASE . "content/")), -4), $permlvl, true);
- $perms["temp/"] = array(substr(sprintf("%o", fileperms(BASE . "temp/")), -4), $permlvl, true);
- $perms["logs/"] = array(substr(sprintf("%o", fileperms(BASE . "logs/")), -4), $permlvl, true);
- $perms["files/" . $setting["os"] . "/sc_serv"] = array(substr(sprintf("%o", fileperms(BASE . ("files/" . $setting["os"] . "/sc_serv"))), -4), 777, false);
- $perms["files/" . $setting["os"] . "/sc_trans"] = array(substr(sprintf("%o", fileperms(BASE . ("files/" . $setting["os"] . "/sc_trans"))), -4), 777, false);
- $PermContent = "";
- foreach ($perms as $filename => $permarray) {
- $SuccessFail = "Passed";
- if ($permarray[0] < $permarray[1]) {
- $SuccessFail = "<font color=\"red\">Failed</font>";
- }
- if (!(isset($_permfail)) && !(is_writable("./" . $filename)) && is_dir("./" . $filename)) {
- $permarray[1] = 777;
- $SuccessFail = "<font color=\"red\">Failed</font>";
- }
- if (!($SuccessFail != "Passed")) {
- continue;
- }
- $RealPath = BASE . $filename;
- if ($permarray[2] && is_writable("./" . $filename)) {
- $SuccessFail = "Passed";
- break;
- }
- if (function_exists("posix_getpwuid") && function_exists("posix_getgrgid")) {
- $OwnerArray = posix_getpwuid(fileowner($RealPath));
- $GroupArray = posix_getgrgid(filegroup($RealPath));
- }
- else {
- $OwnerArray["name"] = "";
- $GroupArray["name"] = "";
- }
- $PermContent .= "
- <tr>
- <td> ./" . $filename . "</td>
- <td align=\"center\">" . $OwnerArray["name"] . ":" . $GroupArray["name"] . "</td>
- <td align=\"center\">" . $permarray[0] . "</td>
- <td align=\"center\">" . $permarray[1] . "</td>
- <td align=\"center\">" . $SuccessFail . "</td>
- </tr>";
- }
- if ($PermContent != "") {
- $status = "failed";
- $errorArray[] = "
- <table width=\"650\" class=\"box\" id=\"body\" border=\"1\" style=\"border-collapse: collapse;\">
- <tr>
- <th>File / Path</th>
- <th>File Ownership</th>
- <th>Permission</th>
- <th>Required</th>
- <th>Status</th>
- </tr>
- " . $PermContent . "
- </tr>
- </table>
- <br />
- Please correct the permissions of these files immediately!
- ";
- }
- }
- return array("status" => $status, "error" => $errorArray);
- }
- function logSystemEvent($message, $type = "system", $actionid = 0) {
- global $db_prefix;
- $selectEvents = mysql_query("SELECT count(id) FROM " . $db_prefix . "systemlog");
- if (100 <= mysql_result($selectEvents, 0)) {
- $select = mysql_query("SELECT id FROM " . $db_prefix . "systemlog LIMIT 100," . mysql_num_rows($selectEvents));
- while ($data = mysql_fetch_array($select)) {
- mysql_query("DELETE FROM " . $db_prefix . "systemlog WHERE id=" . $data["id"]);
- echo(mysql_error());
- }
- }
- mysql_query("INSERT INTO " . $db_prefix . "systemlog(type, actionid, log) VALUES('" . alphanumeric_make($type, "@.-_") . "', '" . numeric_make($actionid) . "', '" . mysql_real_escape_string($message) . "')");
- }
- function CheckPasswordStrength($pwd) {
- $strength = array("Blank", "Very Weak", "Weak", "Medium", "Strong", "Very Strong");
- $score = 1;
- if (strlen($pwd) < 1) {
- return $strength[0];
- }
- if (strlen($pwd) < 4) {
- return $strength[1];
- }
- if (8 <= strlen($pwd)) {
- ++$score;
- }
- if (10 <= strlen($pwd)) {
- ++$score;
- }
- if (preg_match("/[a-z]/", $pwd) && preg_match("/[A-Z]/", $pwd)) {
- ++$score;
- }
- if (preg_match("/[0-9]/", $pwd)) {
- ++$score;
- }
- if (preg_match("/.[!,@,#,\$,%,^,&,*,?,_,~,-,�,(,)]/", $pwd)) {
- ++$score;
- }
- return $score;
- }
- function generatePassword($length = 8) {
- $password = "";
- $possible = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUV";
- $i = 0;
- while ($i < $length) {
- $char = substr($possible, mt_rand(0, strlen($possible) - 1), 1);
- if (strstr($password, $char)) {
- continue;
- }
- $password .= $char;
- ++$i;
- }
- return $password;
- }
- function generateStrongPassword($length = 12, $add_dashes = false, $available_sets = "luds") {
- $sets = array();
- if (strpos($available_sets, "l") !== false) {
- $sets[] = "abcdefghjkmnpqrstuvwxyz";
- }
- if (strpos($available_sets, "u") !== false) {
- $sets[] = "ABCDEFGHJKMNPQRSTUVWXYZ";
- }
- if (strpos($available_sets, "d") !== false) {
- $sets[] = "23456789";
- }
- if (strpos($available_sets, "s") !== false) {
- $sets[] = "!@\$%*";
- }
- $all = "";
- $password = "";
- foreach ($sets as $set) {
- $password .= $set[array_rand(str_split($set))];
- $all .= $set;
- }
- $all = str_split($all);
- $i = 0;
- while ($i < $length - count($sets)) {
- $password .= $all[array_rand($all)];
- ++$i;
- }
- $password = str_shuffle($password);
- if (!$add_dashes) {
- return $password;
- }
- $dash_len = floor(sqrt($length));
- $dash_str = "";
- while ($dash_len < strlen($password)) {
- $dash_str .= substr($password, 0, $dash_len) . "-";
- $password = substr($password, $dash_len);
- }
- $dash_str .= $password;
- return $dash_str;
- }
- function mysql_reestablish($link = false) {
- global $db_connection;
- if (!$link) {
- $link = $db_connection;
- }
- if (!(@mysql_ping($link))) {
- @mysql_close($link);
- global $db_host;
- global $db_username;
- global $db_password;
- global $database;
- $db_connection = mysql_connect($db_host, $db_username, $db_password, true);
- if (!(is_resource($db_connection))) {
- return false;
- }
- if (!(mysql_select_db($database))) {
- return false;
- }
- }
- return $db_connection;
- }
- function billing_PT_human($PaymentTowards) {
- global $db_prefix;
- global $setting;
- $Towards = explode(":", $PaymentTowards);
- switch ($Towards[0]) {
- case "server":
- $PlanSelect = mysql_query("SELECT name FROM " . $db_prefix . "plans WHERE id='" . $Towards[2] . "' AND type='server'");
- if ($Towards[2] == "none" || mysql_num_rows($PlanSelect) == 0) {
- $output["error"] = "no_existant_plan";
- $output["error_detail"] = "The server plan does not exist";
- return $PaymentTowards;
- }
- $Plan = mysql_fetch_array($PlanSelect);
- if ($Towards[1] == "new") {
- return "New service with plan " . $Plan["name"];
- }
- $ServerSelect = mysql_query("SELECT portbase FROM " . $db_prefix . "servers WHERE id='" . $Towards[1] . "'");
- if (mysql_num_rows($ServerSelect) == 0) {
- $output["error"] = "no_server";
- $output["error_detail"] = "The server id specified does not exist";
- return $PaymentTowards;
- }
- $Server = mysql_fetch_array($ServerSelect);
- if ($Towards[3] == "life") {
- return "Credit added to expiry on " . $Server["portbase"];
- }
- if ($Towards[3] == "bandwidth") {
- return "Bandwidth added on " . $Server["portbase"];
- }
- break;
- case "reseller":
- $PlanSelect = mysql_query("SELECT name FROM " . $db_prefix . "plans WHERE id='" . $Towards[1] . "' AND type='reseller'");
- if ($Towards[2] == "none" || mysql_num_rows($PlanSelect) == 0) {
- $output["error"] = "no_existant_plan";
- $output["error_detail"] = "The reseller plan does not exist";
- return $PaymentTowards;
- }
- $Plan = mysql_fetch_array($PlanSelect);
- return "Reseller " . $Plan["name"] . " Purchased";
- default:
- return "Panel Account Credit";
- }
- }
- function pureftpd_restart() {
- system("/etc/init.d/pure-ftpd-mysql restart");
- return true;
- }
- function pureftpd_adduser($userid) {
- global $db_prefix;
- global $setting;
- $output = "";
- if (!(is_numeric($userid))) {
- $output = "incorrect_userid";
- return false;
- }
- $select_user = mysql_query("SELECT * FROM " . $db_prefix . "users WHERE id='" . secure_input($userid) . "'");
- if (mysql_num_rows($select_user) == 0) {
- $output = "no_user";
- return false;
- }
- $usersdata = mysql_fetch_array($select_user);
- mysql_query("INSERT INTO `ftpd` (`User`,
- `status`,
- `Password`,
- `Uid`,
- `Gid`,
- `Dir`,
- `ULBandwidth`,
- `DLBandwidth`,
- `comment`,
- `ipaccess`,
- `QuotaSize`,
- `QuotaFiles`)
- VALUES ('" . $usersdata["username"] . "',
- '1',
- '" . md5($usersdata["user_password"]) . "'),
- '2001',
- '2001',
- '" . $setting["dir_to_cpanel"] . "/content/user_" . $userid . "',
- '50',
- '50',
- '',
- '*',
- '50',
- '0')");
- }
- function file_get_mimetype($file) {
- if (function_exists("finfo_file")) {
- $finfo = finfo_open(FILEINFO_MIME_TYPE);
- $mime = finfo_file($finfo, $file);
- finfo_close($finfo);
- return $mime;
- }
- if (function_exists("mime_content_type")) {
- return mime_content_type($file);
- }
- return false;
- }
- function mail_custom($To, $Subject, $Content, $From, $ReplyTo = "", $attachment = false) {
- global $headers;
- global $setting;
- if ($To == "" || $From == "") {
- return false;
- }
- require_once(BASE . "system/misc/PHPMailer/class.phpmailer.php");
- $mail = new PHPMailer();
- if ($setting["smtp"] == "enabled") {
- $mail->IsSMTP();
- $mail->Host = $setting["smtp_host"];
- $mail->SMTPAuth = strtolower($setting["smtp_auth"]) == "enabled";
- $mail->Username = $setting["smtp_username"];
- $mail->Password = $setting["smtp_password"];
- $mail->SMTPSecure = $setting["smtp_secure"];
- }
- $mail->From = $From;
- $mail->FromName = $setting["company"];
- $mail->AddAddress($To);
- $mail->Subject = $Subject;
- $mail->AltBody = strip_tags($Content);
- $mail->MsgHTML($Content);
- if ($attachment) {
- $attach = array("filename" => basename($attachment), "content" => file_get_contents($attachment), "mimetype" => file_get_mimetype($attachment));
- $mail->AddStringAttachment($attach["content"], $attach["filename"], "base64", $attach["mimetype"]);
- }
- if (!$mail->Send()) {
- if (isset($setting["smtp_debug"]) && strtolower($setting["smtp_debug"]) == "enabled") {
- echo("SMTP Message could not be sent.");
- echo("Mailer Error: " . $mail->ErrorInfo);
- }
- return false;
- }
- return true;
- }
- function include_lang($filename) {
- global $setting;
- global $vars;
- global $lang;
- if (!(isset($setting["user_lang"]))) {
- $setting["user_lang"] = $setting["language"];
- }
- try {
- include(BASE . "system/languages/english/" . $filename);
- }
- catch (Exception $e) {
- exit("Could not load " . BASE . "system/languages/english/" . $filename);
- }
- if ($setting["user_lang"] != "english") {
- try {
- include(BASE . "system/languages/" . $setting["user_lang"] . "/" . $filename);
- }
- catch (Exception $e) {
- exit("Could not load " . BASE . "system/languages/" . $setting["user_lang"] . "/" . $filename);
- }
- }
- foreach ($lang as $search => $replace) {
- if (is_array($lang[$search])) {
- foreach ($lang[$search] as $search1 => $replace1) {
- if (is_array($lang[$search][$search1])) {
- foreach ($lang[$search][$search1] as $search2 => $replace2) {
- if (is_array($lang[$search][$search1][$search2])) {
- continue;
- }
- $vars[strtoupper("{LANG[" . $search . "][" . $search1 . "][" . $search2 . "]}")] = $replace2;
- }
- continue;
- }
- $vars[strtoupper("{LANG[" . $search . "][" . $search1 . "]}")] = $replace1;
- }
- continue;
- }
- $vars[strtoupper("{LANG[" . $search . "]}")] = $replace;
- }
- unset($search);
- unset($replace);
- return true;
- }
- function shellscript_check() {
- global $setting;
- if (!(is_file(BASE . "temp/castcontrol.sh"))) {
- shellscript_create();
- return true;
- }
- $handle = file(BASE . "temp/castcontrol.sh");
- foreach ($handle as $line) {
- if (isset($hash)) {
- $line = explode("hash=", $line);
- $line = str_replace("\"", "", $line[1]);
- if (trim($line) != $setting["sh_auth"]) {
- shellscript_create();
- break;
- }
- break;
- }
- if (isset($shoutcastexec)) {
- $line = explode("# ", $line);
- list(, $line) = $line;
- if (trim($line) != $setting["os"]) {
- shellscript_create();
- break;
- }
- $hash = true;
- unset($shoutcastexec);
- }
- if (isset($pathtocc)) {
- $line = explode("# ", $line);
- list(, $line) = $line;
- if (trim($line) != $setting["dir_to_cpanel"]) {
- shellscript_create();
- break;
- }
- unset($pathtocc);
- $shoutcastexec = true;
- }
- if (!(strstr($line, "#-----------------"))) {
- continue;
- }
- $detected_start = true;
- $pathtocc = true;
- }
- if (empty($detected_start)) {
- shellscript_create();
- return true;
- }
- }
- function shellscript_create() {
- global $setting;
- $handle = @fopen(BASE . "temp/castcontrol.sh", "w+");
- $contents = "#!/bin/bash
- #-----------------
- # " . $setting["dir_to_cpanel"] . "
- # " . $setting["os"] . "
- hash=\"" . $setting["sh_auth"] . "\"
- if [ \"\$1\" = \"\$hash\" ]; then
- if [ \"\$2\" = \"\" ]; then
- echo \"ERROR: No command passed to script\"
- exit 0
- fi
- if [ \"\$2\" = \"server\" ]; then
- if [ \"\$3\" = \"start\" ]; then
- " . $setting["dir_to_cpanel"] . "files/" . $setting["os"] . "/" . sc_serv . "_\$4 \$5 > /dev/null &
- ps -o pid -p \$!
- exit 1
- fi
- if [ \"\$3\" = \"stop\" ]; then
- killall " . sc_serv . "_\$4
- echo \"killing \$4\";
- exit 1
- fi
- exit 0
- fi
- if [ \"\$2\" = \"scanner\" ]; then
- if [ \$3 = \"start\" ]; then
- \$4 -f \"" . $setting["dir_to_cpanel"] . "scanner/index.php\" > /dev/null &
- ps -o pid -p \$!
- fi
- fi
- if [ \"\$2\" = \"trans\" ]; then
- if [ \$3 = \"start\" ]; then
- " . $setting["dir_to_cpanel"] . "files/" . $setting["os"] . "/sc_trans \$4 > /dev/null &
- ps -o pid -p \$!
- fi
- fi
- if [ \"\$2\" = \"killpid\" ]; then
- kill \$3
- fi
- if [ \"\$2\" = \"copyserv\" ]; then
- cp " . $setting["dir_to_cpanel"] . "files/" . $setting["os"] . "/" . sc_serv . " " . $setting["dir_to_cpanel"] . "files/" . $setting["os"] . "/" . sc_serv . "_\$3
- chmod 0777 " . $setting["dir_to_cpanel"] . "files/" . $setting["os"] . "/" . sc_serv . "_\$3
- fi
- else
- echo \"Access Denied\"
- exit 0
- fi
- ";
- fwrite($handle, $contents);
- fclose($handle);
- system("chmod +x " . BASE . "temp/castcontrol.sh");
- }
- function ResellerTotalUsers($resellerID) {
- global $db_prefix;
- $selectOwner = mysql_query("SELECT username FROM " . $db_prefix . "users WHERE id=" . $resellerID);
- $selectResoldServers = mysql_query("SELECT SUM(maxuser) FROM " . $db_prefix . "servers WHERE reseller=" . $resellerID);
- $totalusers = mysql_result($selectResoldServers, 0);
- return 0 < $totalusers ? $totalusers : 0;
- }
- function ResellerTotalTransfer($resellerID) {
- global $db_prefix;
- $selectOwner = mysql_query("SELECT username FROM " . $db_prefix . "users WHERE id=" . $resellerID);
- $owner = mysql_result($selectOwner, 0);
- $totalTransfer = "";
- $selectResoldServers = mysql_query("SELECT id FROM " . $db_prefix . ("servers WHERE owner='" . $owner . "' AND reseller=") . $resellerID);
- while ($serverData = mysql_fetch_assoc($selectResoldServers)) {
- $selectBandwidth = "SELECT SUM(bandwidth) FROM " . $db_prefix . "bandwidth WHERE month = '" . date("F") . "' AND year='" . date("Y") . "' AND serverid=" . $serverData["id"];
- $selectBandwidth = mysql_query($selectBandwidth);
- if (!(0 < mysql_num_rows($selectBandwidth))) {
- continue;
- }
- $totalTransfer += mysql_result($selectBandwidth, 0);
- }
- return $totalTransfer;
- }
- function ResellerTotalQuota($resellerID) {
- global $db_prefix;
- $totalQuota = "";
- $selectResoldServers = mysql_query("SELECT SUM(quota) FROM " . $db_prefix . "servers WHERE reseller=" . $resellerID);
- $value = @mysql_result($selectResoldServers, 0);
- return $value ? $value : 0;
- }
- function alert($text) {
- if (!(defined("java_alert"))) {
- define("java_alert", $text);
- return true;
- }
- return false;
- }
- function product($license) {
- return strtolower(substr($license, 3, strpos(str_replace("MP-", "", $license), "-")));
- }
- function api($api) {
- global $error;
- $connection = fsockopen($api["http_host"], $api["http_port"], $errno, $errstr, 6);
- if (!$connection) {
- $error = "no_connection";
- return false;
- }
- $send = "";
- foreach ($api as $option => $setting) {
- if (strstr($option, "http_")) {
- continue;
- }
- if (is_array($setting)) {
- $setting = serialize($setting);
- }
- $send .= $option . "=" . urlencode($setting) . "&";
- }
- $request = $send;
- $headers = "POST " . $api["http_path"] . "/system/api.php HTTP/1.0
- ";
- $headers .= "Host: " . $api["http_host"] . "
- ";
- $headers .= "Content-Type: application/x-www-form-urlencoded
- ";
- $headers .= "User-Agent: Cast-control 1.4.2 (http://cast-control.net)
- ";
- $headers .= "Content-Length: " . strlen($request) . "
- ";
- $headers .= "Connection: close
- ";
- $headers .= $request . "
- ";
- fputs($connection, $headers);
- $res = "";
- while (!(feof($connection))) {
- $res .= fgets($connection, 1024);
- }
- fclose($connection);
- $res = substr($res, strrpos($res, "
- "), strlen($res));
- if (strstr($res, "Error,Your API Key is not valid")) {
- $error = "auth_failed";
- return false;
- }
- return $res;
- }
- function get_real_path($exclusion = false) {
- $cwd = getcwd();
- $cwd = str_replace("\\", "/", $cwd);
- if ($exclusion !== false && $exclusion != "") {
- $exclusion = str_replace("/", "", $exclusion);
- $exclude = false;
- $split = explode("/", $cwd);
- $i = 0;
- while ($i < count($split)) {
- if ($split[$i] == $exclusion) {
- $exclude = $i;
- }
- ++$i;
- continue;
- }
- if ($exclude !== false) {
- $real_path = "";
- $i = 0;
- while ($i < count($split)) {
- if ($i == $exclude) {
- break;
- }
- $real_path .= $split[$i] . "/";
- ++$i;
- continue;
- }
- }
- else {
- $real_path = $cwd;
- }
- }
- else {
- $real_path = $cwd;
- }
- $check_last = @strrpos($real_path, "/");
- if ($check_last + 1 == @strlen($real_path)) {
- $real_path = substr($real_path, 0, $check_last);
- }
- return $real_path;
- }
- function get_real_url($exclusion = false) {
- $_SERVER =& global $_SERVER;
- global $setting;
- if (isset($_SERVER["HTTPS"]) && strtolower($_SERVER["HTTPS"]) == "on") {
- $prefix = "https://";
- }
- else {
- $prefix = "http://";
- }
- $path = $prefix . $_SERVER["HTTP_HOST"] . $_SERVER["SCRIPT_NAME"];
- if ($exclusion) {
- $path = substr($path, 0, strpos($path, $exclusion));
- }
- return $path;
- }
- function table($title, $width = "90%") {
- global $setting;
- global $smarty;
- global $lang;
- if (isset($_GET["page"])) {
- $page = $_GET["page"];
- }
- else {
- $page = "main";
- }
- if ($page == "admin" && strstr($title, "Administration")) {
- $title_search = array("Administration", "Mass Email", "Settings", "Payment Processors", "Servers", "Users", "Customers", "Permissions", "Support", "Reseller Plans", "Server Plans", "Invoices", "Scanner", "API", "Systems Management", "Transactions", "Email Templates", "Global Statistics");
- $title_replace = array("<a class=\"box\" id=\"title\" href=\"index.php?page=admin\">" . $lang["titles"]["administration"] . "</a>", "<a class=\"box\" id=\"title\" href=\"index.php?page=admin&m=massemail\">" . $lang["titles"]["mass_email"] . "</a>", "<a class=\"box\" id=\"title\" href=\"index.php?page=admin&m=settings\">" . $lang["titles"]["settings"] . "</a>", "<a class=\"box\" id=\"title\" href=\"index.php?page=admin&m=payment_processors\">" . $lang["titles"]["payment_processors"] . "</a>", "<a class=\"box\" id=\"title\" href=\"index.php?page=admin&m=servers\">" . $lang["titles"]["servers"] . "</a>", "<a class=\"box\" id=\"title\" href=\"index.php?page=admin&m=users\">" . $lang["titles"]["users"] . "</a>", "<a class=\"box\" id=\"title\" href=\"index.php?page=admin&m=users\">" . $lang["titles"]["customers"] . "</a>", "<a class=\"box\" id=\"title\" href=\"index.php?page=admin&m=permissions\">" . $lang["titles"]["permissions"] . "</a>", "<a class=\"box\" id=\"title\" href=\"index.php?page=admin&m=support\">" . $lang["titles"]["support"] . "</a>", "<a class=\"box\" id=\"title\" href=\"index.php?page=admin&m=reseller_plans\">" . $lang["titles"]["reseller_plans"] . "</a>", "<a class=\"box\" id=\"title\" href=\"index.php?page=admin&m=server_plans\">" . $lang["titles"]["server_plans"] . "</a>", "<a class=\"box\" id=\"title\" href=\"index.php?page=admin&m=invoices\">" . $lang["titles"]["invoices"] . "</a>", "<a class=\"box\" id=\"title\" href=\"index.php?page=admin&m=scanner\">" . $lang["titles"]["scanner"] . "</a>", "<a class=\"box\" id=\"title\" href=\"index.php?page=admin&m=api\">" . $lang["titles"]["api"] . "</a>", "<a class=\"box\" id=\"title\" href=\"index.php?page=admin&m=systems\">" . $lang["titles"]["systems"] . "</a>", "<a class=\"box\" id=\"title\" href=\"index.php?page=admin&m=transactions\">" . $lang["titles"]["transactions"] . "</a>", "<a class=\"box\" id=\"title\" href=\"index.php?page=admin&m=emailtemplates\">" . $lang["titles"]["emailtemplates"] . "</a>", "<a class=\"box\" id=\"title\" href=\"index.php?page=admin&m=globalstatistics\">" . $lang["titles"]["globalstatistics"] . "</a>");
- $title = str_replace($title_search, $title_replace, $title);
- }
- else {
- if ($page == "resell") {
- $title_search = array("Servers", "Users", "Resell", "Order");
- $title_replace = array("<a class=\"box\" id=\"title\" href=\"index.php?page=resell&m=servers\">" . $lang["resell_titles"]["servers"] . "</a>", "<a class=\"box\" id=\"title\" href=\"index.php?page=resell&m=users\">" . $lang["resell_titles"]["users"] . "</a>", "<a class=\"box\" id=\"title\" href=\"index.php?page=resell\">" . $lang["resell_titles"]["resell"] . "</a>", "<a class=\"box\" id=\"title\" href=\"index.php?page=resell&m=order\">" . $lang["resell_titles"]["order"] . "</a>");
- $title = str_replace($title_search, $title_replace, $title);
- }
- else {
- if ($page == "billing") {
- $title_search = array("Billing", "Servers", "Invoices", "Purchase", "Resell");
- $title_replace = array("<a class=\"box\" id=\"title\" href=\"index.php?page=billing\">" . $lang["billing_titles"]["billing"] . "</a>", "<a class=\"box\" id=\"title\" href=\"index.php?page=billing&m=servers\">" . $lang["billing_titles"]["servers"] . "</a>", "<a class=\"box\" id=\"title\" href=\"index.php?page=billing&m=invoices\">" . $lang["billing_titles"]["invoices"] . "</a>", "<a class=\"box\" id=\"title\" href=\"index.php?page=billing&m=buyserver\">" . $lang["billing_titles"]["purchase"] . "</a>", "<a class=\"box\" id=\"title\" href=\"index.php?page=billing&m=resell\">" . $lang["billing_titles"]["resell"] . "</a>");
- $title = str_replace($title_search, $title_replace, $title);
- }
- else {
- $title_search = array("Servers", "Accounts", "Resell", "User Control Panel");
- $title_replace = array("<a class=\"box\" id=\"title\" href=\"index.php?page=servers\">" . $lang["norm_titles"]["servers"] . "</a>", "<a class=\"box\" id=\"title\" href=\"index.php?page=accounts\">" . $lang["norm_titles"]["accounts"] . "</a>", "<a class=\"box\" id=\"title\" href=\"index.php?page=resell\">" . $lang["norm_titles"]["resell"] . "</a>", "<a class=\"box\" id=\"title\" href=\"index.php?page=userpanel\">User Control Panel</a>");
- $title = str_replace($title_search, $title_replace, $title);
- }
- }
- }
- if ($smarty) {
- $smarty->assign("TABLESECTION", "TOP");
- $smarty->assign("TABLETITLE", $title);
- $smarty->assign("TABLEWIDTH", $width);
- $smarty->display(THEME . "table.tpl");
- }
- }
- function closetable($width = "89%", $footer = "") {
- global $setting;
- global $smarty;
- if ($smarty) {
- $smarty->assign("TABLEFOOTER", $footer);
- $smarty->assign("TABLESECTION", "BOTTOM");
- $smarty->assign("TABLEWIDTH", $width);
- $smarty->display(THEME . "table.tpl");
- }
- }
- function compile($file, $s_and_r) {
- if (!($handle = file($file))) {
- return false;
- }
- $file_content = "";
- foreach ($handle as $line) {
- $file_content .= $line;
- }
- foreach ($s_and_r as $search => $replace) {
- $file_content = @str_replace($search, $replace, $file_content);
- }
- echo($file_content);
- return true;
- }
- function clean_transactions() {
- global $db_prefix;
- mysql_query("DELETE FROM " . $db_prefix . "payments WHERE status='Awaiting Payment' AND time<" . (time() - 432000) . " AND ( payment_towards='' OR payment_towards LIKE '%:new:%' )");
- }
- function clean_users() {
- return true;
- }
- function clean_temp() {
- global $setting;
- $dir = BASE . "temp/";
- $files = array_merge(glob($dir . "*.conf"), glob($dir . "*.ini"), glob($dir . "*.sh"), glob($dir . "*.xml"));
- if (0 < count($files)) {
- foreach ($files as $filename) {
- $creationtime = filemtime($filename);
- if (!(300 < time() - $creationtime && !(is_dir($filename)))) {
- continue;
- }
- @unlink($filename);
- }
- }
- }
- function check_reseller() {
- global $setting;
- global $userdata;
- global $db_prefix;
- if ($userdata["reseller_plan"] != "none" && $userdata["reseller_plan_expire"] - time() < 0 && $userdata["reseller_plan_expire"] != 0) {
- $server_select = mysql_query("UPDATE " . $db_prefix . "servers SET expire='" . (time() - 1) . ("' WHERE reseller='" . $userdata["id"] . "' AND expire='0'"));
- }
- if ($userdata["reseller"] != "none") {
- $select_reseller = mysql_query("SELECT id,reseller_plan,reseller_plan_expire FROM " . $db_prefix . "users WHERE id='" . $userdata["reseller"] . "' ");
- $reselldata = mysql_fetch_array($select_reseller);
- if ($reselldata["reseller_plan"] != "none" && $reselldata["reseller_plan_expire"] - time() < 0 && $reselldata["reseller_plan_expire"] != 0) {
- $server_select = mysql_query("UPDATE " . $db_prefix . "servers SET expire='" . (time() - 1) . ("' WHERE reseller='" . $reselldata["id"] . "' AND expire='0'"));
- }
- }
- }
- function scanner_start($php = false) {
- global $setting;
- if ($php !== false && function_exists("is_direct_file") && @is_direct_file($php)) {
- if (strstr($setting["os"], "windows")) {
- $WshShell = new COM("WScript.Shell");
- $oExec = $WshShell->Run("\"" . $php . "\" \"" . $setting["dir_to_cpanel"] . "scanner/index.php\"", 3, false);
- }
- else {
- $sudo = "";
- if ($setting["sudo"] == "Enabled") {
- $pid = shell_exec("sudo -u " . $setting["sudo_username"] . " " . $setting["dir_to_cpanel"] . "temp/castcontrol.sh " . $setting["sh_auth"] . (" scanner start \"" . $php . "\""));
- }
- else {
- $command = "\"" . $php . "\" -f \"" . $setting["dir_to_cpanel"] . "scanner/index.php\" > /dev/null & echo \$!";
- $pid = shell_exec("\"" . $php . "\" -f \"" . $setting["dir_to_cpanel"] . "scanner/index.php\" > /dev/null & echo \$!");
- }
- }
- return true;
- }
- if ($connection = fsockopen($_SERVER["HTTP_HOST"], 80, $errno, $errstr, 5)) {
- $path = ereg_replace("index.php*", "scanner/index.php", $_SERVER["SCRIPT_NAME"]);
- $path = ereg_replace("install/install.php*", "scanner/index.php", $path);
- $headers = "GET " . $path . " HTTP/1.1
- ";
- $headers .= "Host: " . $_SERVER["HTTP_HOST"] . "
- ";
- $headers .= "Content-Type: application/x-www-form-urlencoded
- ";
- $headers .= "User-Agent: Cast-control 1.4.3 (http://cast-control.net)
- ";
- $headers .= "Connection: close
- ";
- fputs($connection, $headers);
- sleep(1);
- fclose($connection);
- return true;
- }
- return false;
- }
- function check_scanner() {
- global $setting;
- global $db_prefix;
- ignore_user_abort(true);
- $scandata = mysql_result(mysql_query("SELECT value FROM " . $db_prefix . "settings WHERE setting='scanner_detail'"), 0);
- $pid = "";
- if ($scandata != "") {
- $scanner = explode("||", $scandata);
- $pid = trim($scanner[1]);
- $timestamp = trim($scanner[0]);
- }
- if (!(empty($pid))) {
- if (strstr($setting["os"], "windows")) {
- $output = array();
- exec("tasklist /FI \"PID eq " . $pid . "\" /NH", $output);
- foreach ($output as $id => $line) {
- if (strstr($line, $pid)) {
- $online = true;
- }
- if (!(strstr($line, "INFO:"))) {
- continue;
- }
- return 1;
- }
- }
- else {
- $output = array();
- exec("ps -p " . $pid, $output);
- if (1 < count($output)) {
- $online = true;
- }
- }
- }
- if (isset($online)) {
- return 2;
- }
- if (isset($scanner)) {
- return 1;
- }
- return 0;
- }
- function stop_scanner() {
- global $setting;
- global $db_prefix;
- $scandata = mysql_result(mysql_query("SELECT value FROM " . $db_prefix . "settings WHERE setting='scanner_detail'"), 0);
- $scanner = explode("||", $scandata);
- $pid = trim($scanner[1]);
- if (strstr($setting["os"], "windows")) {
- $output = array();
- exec("tasklist /fi \"pid eq " . $pid . "\" /NH", $output);
- $output_name = explode(" ", $output[1]);
- $output_name = $output_name[0];
- if (strlen($output_name) == 0) {
- mysql_query("UPDATE " . $db_prefix . "settings SET value='' WHERE setting='scanner_detail'");
- return true;
- }
- unset($output);
- $output = array();
- if (!(exec("taskkill /pid " . $pid . " /f", $output))) {
- return false;
- }
- if (!(strstr($output[0], "SUCCESS"))) {
- return false;
- }
- }
- if (strtolower($setting["sudo"]) == "enabled") {
- $command = "sudo -u " . $setting["sudo_username"] . " " . $setting["dir_to_cpanel"] . "temp/castcontrol.sh " . $setting["sh_auth"] . (" killpid " . $pid);
- }
- else {
- $command = "kill " . $pid;
- }
- exec($command, $output);
- mysql_query("UPDATE " . $db_prefix . "settings SET value='' WHERE setting='scanner_detail'");
- return true;
- }
- function serv_status($id, $connect = 0, $display_unconnectable = false, $clustered = false) {
- require_once(BASE . "system/shoutcast.php");
- return shoutcast_status($id, $connect, $display_unconnectable, $clustered);
- }
- function expire($expiry) {
- $expiredays = round(($expiry - time()) / 86400, 2);
- $expirehours = round(($expiry - time()) / 3600, 2);
- $expiremins = round(($expiry - time()) / 60, 1);
- $expiresecs = round($expiry - time(), 2);
- $expire = round(($expiry - time()) / 2592000, 1) . " Months";
- if ($expire < 1) {
- $expire = round($expiredays) . " Days";
- }
- if ($expiredays < 1) {
- $expire = "<font color='brown'>" . round($expirehours) . " Hours</font>";
- }
- if ($expirehours < 1) {
- $expire = "<font color='red'>" . round($expiremins) . " Minutes</font>";
- }
- if ($expiremins < 1) {
- $expire = "<font color='red'>" . round($expiresecs) . " Seconds</font>";
- }
- if ($expiresecs <= 0) {
- $expire = "<font color='red'>EXPIRED</font>";
- }
- if ($expiry == 0) {
- $expire = "Never";
- }
- return $expire;
- }
- function convert_tstamp($data) {
- $start = strtok($data, " ");
- $start = str_replace(array("<", ">"), "", $start);
- $start = split("@", $start);
- return strtotime($start[0] . " " . $start[1]);
- }
- function keepalive($file, $status = 0, $dir = "./logs/") {
- global $setting;
- $file = BASE . "logs/" . $file;
- if ($status == 1) {
- if (!(is_file($file))) {
- return false;
- }
- $contents = "";
- $i = 0;
- $handle = file($file);
- foreach ($handle as $line) {
- $contents .= $line;
- if (!(strstr($line, "[cast-control] Keep-Alive"))) {
- continue;
- }
- $keepalive[$i]["time"] = convert_tstamp($line);
- $keepalive[$i]["line"] = $line;
- ++$i;
- }
- if (!(isset($keepalive))) {
- $keepalive[0]["time"] = 0;
- $keepalive[0]["line"] = "[cast-control] Keep-Alive";
- }
- $count = count($keepalive) - 1;
- $seconds = time() - $keepalive[$count]["time"];
- if (180 < $seconds) {
- ...............................................................
- ..........................
- ...........
Add Comment
Please, Sign In to add comment