Guest User

Untitled

a guest
Apr 24th, 2015
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 46.46 KB | None | 0 0
  1. <?php
  2.  
  3. function DialogInfo($message) {
  4. echo(" <div class=\"alert alert-info fade in\">
  5. <button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-hidden=\"true\">x</button>
  6. ");
  7. echo($message);
  8. echo(" </div>
  9. ");
  10. }
  11.  
  12. function DialogWarning($message) {
  13. echo(" <div class=\"alert alert-warning fade in\">
  14. <button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-hidden=\"true\">x</button>
  15. ");
  16. echo($message);
  17. echo(" </div>
  18. ");
  19. }
  20.  
  21. function DialogError($message) {
  22. echo(" <div class=\"alert alert-danger fade in\">
  23. <button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-hidden=\"true\">x</button>
  24. ");
  25. echo($message);
  26. echo(" </div>
  27. ");
  28. }
  29.  
  30. function DialogSuccess($message) {
  31. echo(" <div class=\"alert alert-success fade in\">
  32. <button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-hidden=\"true\">x</button>
  33. ");
  34. echo($message);
  35. echo(" </div>
  36. ");
  37. }
  38.  
  39. function timezone_select_html($selected = false) {
  40. $return = "";
  41. $timezones = DateTimeZone::listIdentifiers(DateTimeZone::ALL);
  42. foreach ($timezones as $label => $timezone) {
  43. error_reporting(-1);
  44. ini_set("display_errors", "On");
  45. $t = new DateTimeZone($timezone);
  46. $c = new DateTime(null, $t);
  47. $currenttime = $c->format("g:i A");
  48. $label = $timezone;
  49. $return .= "<option value=\"" . $timezone . "\"" . ($timezone == $selected ? " selected=selected" : "") . (">" . $label . " - " . $currenttime . "</option>");
  50. }
  51. return $return;
  52. }
  53.  
  54. function timezone_array() {
  55. $timezones = DateTimeZone::listIdentifiers(DateTimeZone::ALL);
  56. $timezone_offsets = array();
  57. foreach ($timezones as $timezone) {
  58. $tz = new DateTimeZone($timezone);
  59. $timezone_offsets[$timezone] = $tz->getOffset(new DateTime());
  60. }
  61. asort($timezone_offsets);
  62. $timezone_list = array();
  63. foreach ($timezone_offsets as $timezone => $offset) {
  64. $offset_prefix = $offset < 0 ? "-" : "+";
  65. $offset_formatted = gmdate("H:i", abs($offset));
  66. $pretty_offset = "UTC" . $offset_prefix . $offset_formatted;
  67. $timezone_list[$timezone] = "(" . $pretty_offset . ") " . $timezone;
  68. }
  69. return $timezone_list;
  70. }
  71.  
  72. function InitiateDebugging() {
  73. global $setting;
  74. if (!(isset($setting["debugging"]))) {
  75. return false;
  76. }
  77. switch ($setting["debugging"]) {
  78. case "errors":
  79. ini_set("display_errors", "On");
  80. error_reporting(-1);
  81. break;
  82.  
  83. case "warnings":
  84. ini_set("display_errors", "On");
  85. error_reporting(255);
  86. break;
  87.  
  88. case "disabled":
  89. ini_set("display_errors", "Off");
  90. error_reporting(0);
  91.  
  92. }
  93. }
  94.  
  95. function LogError($ServiceID = "sys", $message, $DATA) {
  96. global $setting;
  97. $DATA = wordwrap(base64_encode($DATA), 10000, "
  98. ", true);
  99. $handle = @fopen($setting["dir_to_cpanel"] . "temp/error." . $ServiceID . __DIR__ . time() . ".log", "w");
  100. @fwrite($handle, $method . "
  101. ");
  102. @fwrite($handle, $message . "
  103.  
  104. ");
  105. @fwrite($handle, $DATA);
  106. @fclose($handle);
  107. }
  108.  
  109. function time_to_timezone($time, $ConvertToTimezone, $ConvertFromTimezone = false) {
  110. $dateFormat = "Y-m-d H:i:s";
  111. $date = date($dateFormat, $time);
  112. $date = date_to_timezone($dateFormat, $date, $ConvertToTimezone, $ConvertFromTimezone);
  113. return strtotime($date);
  114. }
  115.  
  116. function date_to_timezone($dateFormat, $date, $ConvertToTimezone, $ConvertFromTimezone = false, $returnUnix = false) {
  117. $DefaultTimezone = date_default_timezone_get();
  118. $OriginalTimezone = $ConvertFromTimezone ? $ConvertFromTimezone : $DefaultTimezone;
  119. $OriginalDate = new DateTime($date, new DateTimeZone($OriginalTimezone));
  120. date_default_timezone_set($ConvertToTimezone);
  121. $result = date($dateFormat, $OriginalDate->format("U"));
  122. if ($returnUnix) {
  123. $result = strtotime($result);
  124. }
  125. date_default_timezone_set($DefaultTimezone);
  126. return $result;
  127. }
  128.  
  129. function strtotimefromtimezone($dateFormat, $date, $ConvertFromTimezone) {
  130. $Date = date_to_timezone($dateFormat, $date, date_default_timezone_get(), $ConvertFromTimezone);
  131. return strtotime($Date);
  132. }
  133.  
  134. function timezone_offset($time, $ConvertToTimezone) {
  135. $DefaultTZ = new DateTimeZone(date_default_timezone_get());
  136. $ConvertTZ = new DateTimeZone($ConvertToTimezone);
  137. $Offset = $DefaultTZ->getOffset($ConvertTZ);
  138. if (0 < $Offset) {
  139. return $time + $Offset;
  140. }
  141. return $time - $Offset;
  142. }
  143.  
  144. function timezone_get_offset($ConvertToTimezone) {
  145. $dateTimeZoneFrom = new DateTimeZone(date_default_timezone_get());
  146. $dateTimeZoneTo = new DateTimeZone($ConvertToTimezone);
  147. $dateTimeFrom = new DateTime("now", $dateTimeZoneFrom);
  148. $dateTimeTo = new DateTime("now", $dateTimeZoneTo);
  149. $timeOffset = $dateTimeZoneTo->getOffset($dateTimeFrom) - $dateTimeZoneFrom->getOffset($dateTimeFrom);
  150. $f = ":";
  151. $t = $timeOffset;
  152. return $t < 0 ? "-" : "+" . sprintf("%02d%s%02d", floor(abs($t) / 3600), $f, abs($t) / 60 % 60, $f, abs($t) % 60);
  153. }
  154.  
  155. function max_upload_size() {
  156. $POSTMAXSIZE = numeric_make(ini_get("post_max_size"));
  157. $UPLOADMAXSIZE = numeric_make(ini_get("upload_max_filesize"));
  158. return $UPLOADMAXSIZE < $POSTMAXSIZE ? $UPLOADMAXSIZE : $POSTMAXSIZE;
  159. }
  160.  
  161. function path($path) {
  162. if (substr(PHP_OS, 0, 3) == "WIN") {
  163. return str_replace(array("/", "\\"), "/", $path);
  164. }
  165. return str_replace(array("/", "\\"), "/", $path);
  166. }
  167.  
  168. function SystemLogError($data) {
  169. if (isset($_GET["debug"])) {
  170. echo($data);
  171. }
  172. $handle = fopen(BASE . "temp/system_log.txt", "w");
  173. fwrite($handle, $data . "
  174.  
  175. ");
  176. fclose($handle);
  177. }
  178.  
  179. function UpgradeLogError($data) {
  180. if (isset($_GET["debug"])) {
  181. echo($data);
  182. }
  183. $handle = fopen(BASE . "temp/upgrade_log.txt", "w");
  184. fwrite($handle, $data . "
  185.  
  186. ");
  187. fclose($handle);
  188. }
  189.  
  190. function StatCacheSmarty($params, &$smarty) {
  191. global $smarty;
  192. $smarty->assign("StatCache", StatCache_Retrieve($params["service_id"]));
  193. }
  194.  
  195. function StatCache_Retrieve($server_id) {
  196. global $db_prefix;
  197. $selectStatCache = mysql_query("SELECT * FROM " . $db_prefix . "statcache WHERE server_id=" . $server_id);
  198. if (mysql_num_rows($selectStatCache) == 0) {
  199. $arr["status"] = false;
  200. $arr["bitrate"] = 0;
  201. $arr["format"] = "";
  202. $arr["connections"] = 0;
  203. $arr["nowplaying"] = "";
  204. $arr["transfer"] = 0;
  205. mysql_query("INSERT INTO " . $db_prefix . "statcache (server_id, status, bitrate, connections, nowplaying, transfer, lastupdated)
  206. VALUES(" . $server_id . ", '" . $arr["status"] . "', " . $arr["bitrate"] . "," . $arr["connections"] . ",'" . $arr["nowplaying"] . "'," . $arr["transfer"] . "," . time() . ")");
  207. return $arr;
  208. }
  209. return mysql_fetch_assoc($selectStatCache);
  210. }
  211.  
  212. function StatCache_Update($server_id, $arr) {
  213. global $db_prefix;
  214. if (!$arr || count($arr) == 0) {
  215. return false;
  216. }
  217. $selectStatCache = mysql_query("SELECT * FROM " . $db_prefix . "statcache WHERE server_id=" . $server_id);
  218. if (mysql_num_rows($selectStatCache) == 0) {
  219. $arr["status"] = isset($arr["status"]) ? $arr["status"] * 1 : false;
  220. $arr["bitrate"] = isset($arr["bitrate"]) ? $arr["bitrate"] * 1 : 0;
  221. $arr["format"] = isset($arr["format"]) ? alphanumeric_make($arr["format"], "/") : 0;
  222. $arr["connections"] = isset($arr["connections"]) ? $arr["connections"] * 1 : 0;
  223. $arr["nowplaying"] = isset($arr["nowplaying"]) ? alphanumeric_make($arr["nowplaying"], " ") : "";
  224. $arr["transfer"] = isset($arr["transfer"]) ? $arr["transfer"] * 1 : 0;
  225. foreach ($arr as $field => $value) {
  226. $arr[$field] = mysql_real_escape_string($value);
  227. }
  228. mysql_query("INSERT INTO " . $db_prefix . "statcache (server_id, status, bitrate, connections, nowplaying, transfer, lastupdated)
  229. VALUES(" . $server_id . ", '" . $arr["status"] . "', " . $arr["bitrate"] . "," . $arr["connections"] . ",'" . $arr["nowplaying"] . "'," . $arr["transfer"] . "," . time() . ")");
  230. echo(mysql_error());
  231. }
  232. $cache = mysql_fetch_assoc($selectStatCache);
  233. $arr["status"] = isset($arr["status"]) ? alphanumeric_make($arr["status"]) : $cache["status"];
  234. $arr["bitrate"] = isset($arr["bitrate"]) ? $arr["bitrate"] * 1 : $cache["bitrate"];
  235. $arr["format"] = isset($arr["format"]) ? alphanumeric_make($arr["format"], "/") : $cache["format"];
  236. $arr["connections"] = isset($arr["connections"]) ? $arr["connections"] * 1 : $cache["connections"];
  237. $arr["nowplaying"] = isset($arr["nowplaying"]) ? alphanumeric_make($arr["nowplaying"], " ") : $cache["nowplaying"];
  238. $arr["transfer"] = isset($arr["transfer"]) ? $arr["transfer"] * 1 : $cache["transfer"];
  239. mysql_query("UPDATE " . $db_prefix . "statcache SET
  240. status='" . $arr["status"] . "',
  241. bitrate='" . $arr["bitrate"] . "',
  242. format='" . $arr["format"] . "',
  243. connections='" . $arr["connections"] . "',
  244. nowplaying='" . $arr["nowplaying"] . "',
  245. transfer='" . $arr["transfer"] . "',
  246. lastupdated=" . time() . (" WHERE server_id=" . $server_id));
  247. echo(mysql_error());
  248. return true;
  249. }
  250.  
  251. function SecureUniqueID($input) {
  252. return alphanumeric_make($input, "-_");
  253. }
  254.  
  255. function serviceStatusCheckUpdate($service_id, $state) {
  256. global $db_prefix;
  257. if (!(is_numeric($service_id))) {
  258. return false;
  259. }
  260. return mysql_query("UPDATE " . $db_prefix . "servers SET laststatuscheck=" . time() . ", laststate='" . $state . "' WHERE id=" . $service_id);
  261. }
  262.  
  263. function get_rrd_path($os = "default") {
  264. if ($os == "default") {
  265. global $setting;
  266. $os = $setting["os"];
  267. }
  268. if (substr(PHP_OS, 0, 3) == "WIN") {
  269. return "C:/xampp/CastControl/rrdtool/rrdtool.exe";
  270. }
  271. $rrd = @exec("which rrdtool");
  272. if (!(strstr($rrd, "no rrdtool in")) && is_executable($rrd)) {
  273. return $rrd;
  274. }
  275. if (is_executable("/usr/local/cpanel/3rdparty/bin/rrdtool")) {
  276. return "/usr/local/cpanel/3rdparty/bin/rrdtool";
  277. }
  278. if (is_executable("/usr/local/rrdtool-1.3.6/bin/rrdtool")) {
  279. return "/usr/local/rrdtool-1.3.6/bin/rrdtool";
  280. }
  281. return "/usr/bin/rrdtool";
  282. }
  283.  
  284. function get_ffmpeg() {
  285. if (substr(PHP_OS, 0, 3) == "WIN") {
  286. return "C:/xampp/CastControl/ffmpeg/ffmpeg.exe";
  287. }
  288. $ffmpeg = @exec("which ffmpeg");
  289. if (!(strstr($ffmpeg, "no ffmpeg in")) && is_executable($ffmpeg)) {
  290. return $ffmpeg;
  291. }
  292. if (is_executable("/usr/local/bin/ffmpeg")) {
  293. return "/usr/local/bin/ffmpeg";
  294. }
  295. if (is_executable("/usr/bin/ffmpeg")) {
  296. return "/usr/bin/ffmpeg";
  297. }
  298. return "/usr/bin/ffmpeg";
  299. }
  300.  
  301. function get_ffprobe() {
  302. if (substr(PHP_OS, 0, 3) == "WIN") {
  303. return "C:/xampp/CastControl/ffmpeg/ffprobe.exe";
  304. }
  305. $ffprobe = @exec("which ffprobe");
  306. if (!(strstr($ffprobe, "no ffprobe in")) && is_executable($ffprobe)) {
  307. return $ffprobe;
  308. }
  309. if (is_executable("/usr/local/bin/ffprobe")) {
  310. return "/usr/local/bin/ffprobe";
  311. }
  312. if (is_executable("/usr/bin/ffprobe")) {
  313. return "/usr/bin/ffprobe";
  314. }
  315. return "/usr/bin/ffprobe";
  316. }
  317.  
  318. function logServerAction($serverData, $type, $action) {
  319. global $setting;
  320. global $data;
  321. if (!(isset($setting["logactions"]))) {
  322. return false;
  323. }
  324. $handle = fopen(BASE . ("actionlogs/" . $serverData["portbase"] . ".log"), "a");
  325. fwrite($handle, "---------------------------
  326. " . "Server Action: " . $action . " (" . $type . ")" . "
  327. " . "System ID: " . $serverData["system_id"] . "
  328. " . "CastQ?: " . defined("is_cron") ? "Yes" : "No" . "
  329. " . "Misc:
  330. " . print_r($_SERVER["argv"], true) . "
  331. ");
  332. fclose($handle);
  333. }
  334.  
  335. function queue_add($type, $plugin, $action, $actionid, $systemid = 1, $custom = "none", $forced = 0) {
  336. global $userdata;
  337. global $db_prefix;
  338. global $setting;
  339. $type = secure_input($type);
  340. $action = secure_input($action);
  341. $actionid = secure_input($actionid);
  342. if ($setting["daemon_method"] == "daemon" && !(defined("is_daemon"))) {
  343. $array = array("type" => $type, "plugin" => $plugin, "serviceid" => $actionid, "action" => $action, "custom" => $custom);
  344. require_once(BASE . "system/misc/includes/daemon.class.php");
  345. $daemonClient = new daemon_client();
  346. $request = $daemonClient->exec($array);
  347. if (!$request) {
  348. return array("status" => "failed", "method" => "daemon", "error" => "Could not connect to daemon service");
  349. }
  350. return array("status" => $request["status"], "method" => "daemon", "error" => $request["error"]);
  351. }
  352. $select = mysql_query("SELECT id, forced, completed FROM " . $db_prefix . ("cmdqueue WHERE type='" . $type . "' AND plugin='" . $plugin . "' AND actionid='" . $actionid . "'"));
  353. if (0 < mysql_num_rows($select)) {
  354. if (mysql_result($select, 0, "forced") == 1 && mysql_result($select, 0, "completed") == 0) {
  355. return false;
  356. }
  357. 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"));
  358. }
  359. else {
  360. mysql_query("INSERT INTO " . $db_prefix . ("cmdqueue (forced, type, plugin, action, actionid, systemid, custom, timestamp) VALUES(" . $forced . ", '" . $type . "', '" . $plugin . "', '" . $action . "', '" . $actionid . "', '" . $systemid . "', '" . $custom . "', ") . time() . ") ");
  361. }
  362. echo(mysql_error());
  363. return array("status" => "queued", "method" => "queue", "error" => "");
  364. }
  365.  
  366. function copyr($source, $dest) {
  367. if (!(is_dir($source))) {
  368. return copy($source, $dest);
  369. }
  370. if (!(is_dir($dest))) {
  371. mkdir($dest);
  372. }
  373. foreach (glob($source . "/*") as $entry) {
  374. if (file_exists($dest . "/" . basename($entry))) {
  375. continue;
  376. }
  377. copyr($entry, $dest . "/" . basename($entry));
  378. }
  379. return true;
  380. }
  381.  
  382. function dirsize($path) {
  383. $size = 0;
  384. if (substr($path, -1, 1) !== DIRECTORY_SEPARATOR) {
  385. $path .= DIRECTORY_SEPARATOR;
  386. }
  387. if (is_file($path)) {
  388. return filesize($path);
  389. }
  390. if (!(is_dir($path))) {
  391. return false;
  392. }
  393. $queue = array($path);
  394. $i = 0;
  395. $j = count($queue);
  396. while ($i < $j) {
  397. $parent = $i;
  398. if (is_dir($queue[$i]) && $dir = @dir($queue[$i])) {
  399. $subdirs = array();
  400. while (false !== ($entry = $dir->read())) {
  401. if ($entry == __DIR__ || $entry == "..") {
  402. continue;
  403. }
  404. $path = $queue[$i] . $entry;
  405. if (is_dir($path)) {
  406. $path .= DIRECTORY_SEPARATOR;
  407. $subdirs[] = $path;
  408. continue;
  409. }
  410. if (!(is_file($path))) {
  411. continue;
  412. }
  413. $size += filesize($path);
  414. }
  415. unset($queue[0]);
  416. $queue = array_merge($subdirs, $queue);
  417. $i = -1;
  418. $j = count($queue);
  419. $dir->close();
  420. unset($dir);
  421. }
  422. ++$i;
  423. }
  424. return $size;
  425. }
  426.  
  427. function microtime_float() {
  428. list($usec, $sec) = explode(" ", microtime());
  429. return (float)$usec + (float)$sec;
  430. }
  431.  
  432. function checkRequiredFunctions() {
  433. global $setting;
  434. $errorArray = array();
  435. $status = "success";
  436. if (ini_get("safe_mode")) {
  437. $status = "failed";
  438. $errorArray[] = "Your PHP installation has Safe-Mode Enabled<br />Cast-Control <b>CANNOT</b> function with safe-mode enabled";
  439. }
  440. $disabledFunctions = ini_get("disable_functions");
  441. $requestedFunctions = "";
  442. if (!(empty($disabledFunctions))) {
  443. $RequiredFunctions = array("exec", "shell_exec", "system", "chmod", "sleep", "set_time_limit", "ignore_user_abort");
  444. foreach ($RequiredFunctions as $Function) {
  445. if (!(strstr($disabledFunctions, $Function))) {
  446. continue;
  447. }
  448. $requestedFunctions .= "<li>" . $Function . "()</li>";
  449. }
  450. }
  451. if (is_array($requestedFunctions)) {
  452. $status = "failed";
  453. $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>";
  454. }
  455. if (!(strstr($setting["os"], "windows"))) {
  456. if (in_array($phpacct, array("nobody", "apache", "root"))) {
  457. $permlvl = 777;
  458. }
  459. else {
  460. $permlvl = 755;
  461. }
  462. $perms["content/"] = array(substr(sprintf("%o", fileperms(BASE . "content/")), -4), $permlvl, true);
  463. $perms["temp/"] = array(substr(sprintf("%o", fileperms(BASE . "temp/")), -4), $permlvl, true);
  464. $perms["logs/"] = array(substr(sprintf("%o", fileperms(BASE . "logs/")), -4), $permlvl, true);
  465. $perms["files/" . $setting["os"] . "/sc_serv"] = array(substr(sprintf("%o", fileperms(BASE . ("files/" . $setting["os"] . "/sc_serv"))), -4), 777, false);
  466. $perms["files/" . $setting["os"] . "/sc_trans"] = array(substr(sprintf("%o", fileperms(BASE . ("files/" . $setting["os"] . "/sc_trans"))), -4), 777, false);
  467. $PermContent = "";
  468. foreach ($perms as $filename => $permarray) {
  469. $SuccessFail = "Passed";
  470. if ($permarray[0] < $permarray[1]) {
  471. $SuccessFail = "<font color=\"red\">Failed</font>";
  472. }
  473. if (!(isset($_permfail)) && !(is_writable("./" . $filename)) && is_dir("./" . $filename)) {
  474. $permarray[1] = 777;
  475. $SuccessFail = "<font color=\"red\">Failed</font>";
  476. }
  477. if (!($SuccessFail != "Passed")) {
  478. continue;
  479. }
  480. $RealPath = BASE . $filename;
  481. if ($permarray[2] && is_writable("./" . $filename)) {
  482. $SuccessFail = "Passed";
  483. break;
  484. }
  485. if (function_exists("posix_getpwuid") && function_exists("posix_getgrgid")) {
  486. $OwnerArray = posix_getpwuid(fileowner($RealPath));
  487. $GroupArray = posix_getgrgid(filegroup($RealPath));
  488. }
  489. else {
  490. $OwnerArray["name"] = "";
  491. $GroupArray["name"] = "";
  492. }
  493. $PermContent .= "
  494. <tr>
  495. <td>&nbsp;&nbsp;&nbsp;./" . $filename . "</td>
  496. <td align=\"center\">" . $OwnerArray["name"] . ":" . $GroupArray["name"] . "</td>
  497. <td align=\"center\">" . $permarray[0] . "</td>
  498. <td align=\"center\">" . $permarray[1] . "</td>
  499. <td align=\"center\">" . $SuccessFail . "</td>
  500. </tr>";
  501. }
  502. if ($PermContent != "") {
  503. $status = "failed";
  504. $errorArray[] = "
  505. <table width=\"650\" class=\"box\" id=\"body\" border=\"1\" style=\"border-collapse: collapse;\">
  506. <tr>
  507. <th>File / Path</th>
  508. <th>File Ownership</th>
  509. <th>Permission</th>
  510. <th>Required</th>
  511. <th>Status</th>
  512. </tr>
  513. " . $PermContent . "
  514. </tr>
  515. </table>
  516. <br />
  517. Please correct the permissions of these files immediately!
  518. ";
  519. }
  520. }
  521. return array("status" => $status, "error" => $errorArray);
  522. }
  523.  
  524. function logSystemEvent($message, $type = "system", $actionid = 0) {
  525. global $db_prefix;
  526. $selectEvents = mysql_query("SELECT count(id) FROM " . $db_prefix . "systemlog");
  527. if (100 <= mysql_result($selectEvents, 0)) {
  528. $select = mysql_query("SELECT id FROM " . $db_prefix . "systemlog LIMIT 100," . mysql_num_rows($selectEvents));
  529. while ($data = mysql_fetch_array($select)) {
  530. mysql_query("DELETE FROM " . $db_prefix . "systemlog WHERE id=" . $data["id"]);
  531. echo(mysql_error());
  532. }
  533. }
  534. mysql_query("INSERT INTO " . $db_prefix . "systemlog(type, actionid, log) VALUES('" . alphanumeric_make($type, "@.-_") . "', '" . numeric_make($actionid) . "', '" . mysql_real_escape_string($message) . "')");
  535. }
  536.  
  537. function CheckPasswordStrength($pwd) {
  538. $strength = array("Blank", "Very Weak", "Weak", "Medium", "Strong", "Very Strong");
  539. $score = 1;
  540. if (strlen($pwd) < 1) {
  541. return $strength[0];
  542. }
  543. if (strlen($pwd) < 4) {
  544. return $strength[1];
  545. }
  546. if (8 <= strlen($pwd)) {
  547. ++$score;
  548. }
  549. if (10 <= strlen($pwd)) {
  550. ++$score;
  551. }
  552. if (preg_match("/[a-z]/", $pwd) && preg_match("/[A-Z]/", $pwd)) {
  553. ++$score;
  554. }
  555. if (preg_match("/[0-9]/", $pwd)) {
  556. ++$score;
  557. }
  558. if (preg_match("/.[!,@,#,\$,%,^,&,*,?,_,~,-,�,(,)]/", $pwd)) {
  559. ++$score;
  560. }
  561. return $score;
  562. }
  563.  
  564. function generatePassword($length = 8) {
  565. $password = "";
  566. $possible = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUV";
  567. $i = 0;
  568. while ($i < $length) {
  569. $char = substr($possible, mt_rand(0, strlen($possible) - 1), 1);
  570. if (strstr($password, $char)) {
  571. continue;
  572. }
  573. $password .= $char;
  574. ++$i;
  575. }
  576. return $password;
  577. }
  578.  
  579. function generateStrongPassword($length = 12, $add_dashes = false, $available_sets = "luds") {
  580. $sets = array();
  581. if (strpos($available_sets, "l") !== false) {
  582. $sets[] = "abcdefghjkmnpqrstuvwxyz";
  583. }
  584. if (strpos($available_sets, "u") !== false) {
  585. $sets[] = "ABCDEFGHJKMNPQRSTUVWXYZ";
  586. }
  587. if (strpos($available_sets, "d") !== false) {
  588. $sets[] = "23456789";
  589. }
  590. if (strpos($available_sets, "s") !== false) {
  591. $sets[] = "!@\$%*";
  592. }
  593. $all = "";
  594. $password = "";
  595. foreach ($sets as $set) {
  596. $password .= $set[array_rand(str_split($set))];
  597. $all .= $set;
  598. }
  599. $all = str_split($all);
  600. $i = 0;
  601. while ($i < $length - count($sets)) {
  602. $password .= $all[array_rand($all)];
  603. ++$i;
  604. }
  605. $password = str_shuffle($password);
  606. if (!$add_dashes) {
  607. return $password;
  608. }
  609. $dash_len = floor(sqrt($length));
  610. $dash_str = "";
  611. while ($dash_len < strlen($password)) {
  612. $dash_str .= substr($password, 0, $dash_len) . "-";
  613. $password = substr($password, $dash_len);
  614. }
  615. $dash_str .= $password;
  616. return $dash_str;
  617. }
  618.  
  619. function mysql_reestablish($link = false) {
  620. global $db_connection;
  621. if (!$link) {
  622. $link = $db_connection;
  623. }
  624. if (!(@mysql_ping($link))) {
  625. @mysql_close($link);
  626. global $db_host;
  627. global $db_username;
  628. global $db_password;
  629. global $database;
  630. $db_connection = mysql_connect($db_host, $db_username, $db_password, true);
  631. if (!(is_resource($db_connection))) {
  632. return false;
  633. }
  634. if (!(mysql_select_db($database))) {
  635. return false;
  636. }
  637. }
  638. return $db_connection;
  639. }
  640.  
  641. function billing_PT_human($PaymentTowards) {
  642. global $db_prefix;
  643. global $setting;
  644. $Towards = explode(":", $PaymentTowards);
  645. switch ($Towards[0]) {
  646. case "server":
  647. $PlanSelect = mysql_query("SELECT name FROM " . $db_prefix . "plans WHERE id='" . $Towards[2] . "' AND type='server'");
  648. if ($Towards[2] == "none" || mysql_num_rows($PlanSelect) == 0) {
  649. $output["error"] = "no_existant_plan";
  650. $output["error_detail"] = "The server plan does not exist";
  651. return $PaymentTowards;
  652. }
  653. $Plan = mysql_fetch_array($PlanSelect);
  654. if ($Towards[1] == "new") {
  655. return "New service with plan " . $Plan["name"];
  656. }
  657. $ServerSelect = mysql_query("SELECT portbase FROM " . $db_prefix . "servers WHERE id='" . $Towards[1] . "'");
  658. if (mysql_num_rows($ServerSelect) == 0) {
  659. $output["error"] = "no_server";
  660. $output["error_detail"] = "The server id specified does not exist";
  661. return $PaymentTowards;
  662. }
  663. $Server = mysql_fetch_array($ServerSelect);
  664. if ($Towards[3] == "life") {
  665. return "Credit added to expiry on " . $Server["portbase"];
  666. }
  667. if ($Towards[3] == "bandwidth") {
  668. return "Bandwidth added on " . $Server["portbase"];
  669. }
  670. break;
  671.  
  672. case "reseller":
  673. $PlanSelect = mysql_query("SELECT name FROM " . $db_prefix . "plans WHERE id='" . $Towards[1] . "' AND type='reseller'");
  674. if ($Towards[2] == "none" || mysql_num_rows($PlanSelect) == 0) {
  675. $output["error"] = "no_existant_plan";
  676. $output["error_detail"] = "The reseller plan does not exist";
  677. return $PaymentTowards;
  678. }
  679. $Plan = mysql_fetch_array($PlanSelect);
  680. return "Reseller " . $Plan["name"] . " Purchased";
  681.  
  682. default:
  683. return "Panel Account Credit";
  684.  
  685. }
  686. }
  687.  
  688. function pureftpd_restart() {
  689. system("/etc/init.d/pure-ftpd-mysql restart");
  690. return true;
  691. }
  692.  
  693. function pureftpd_adduser($userid) {
  694. global $db_prefix;
  695. global $setting;
  696. $output = "";
  697. if (!(is_numeric($userid))) {
  698. $output = "incorrect_userid";
  699. return false;
  700. }
  701. $select_user = mysql_query("SELECT * FROM " . $db_prefix . "users WHERE id='" . secure_input($userid) . "'");
  702. if (mysql_num_rows($select_user) == 0) {
  703. $output = "no_user";
  704. return false;
  705. }
  706. $usersdata = mysql_fetch_array($select_user);
  707. mysql_query("INSERT INTO `ftpd` (`User`,
  708. `status`,
  709. `Password`,
  710. `Uid`,
  711. `Gid`,
  712. `Dir`,
  713. `ULBandwidth`,
  714. `DLBandwidth`,
  715. `comment`,
  716. `ipaccess`,
  717. `QuotaSize`,
  718. `QuotaFiles`)
  719.  
  720. VALUES ('" . $usersdata["username"] . "',
  721. '1',
  722. '" . md5($usersdata["user_password"]) . "'),
  723. '2001',
  724. '2001',
  725. '" . $setting["dir_to_cpanel"] . "/content/user_" . $userid . "',
  726. '50',
  727. '50',
  728. '',
  729. '*',
  730. '50',
  731. '0')");
  732. }
  733.  
  734. function file_get_mimetype($file) {
  735. if (function_exists("finfo_file")) {
  736. $finfo = finfo_open(FILEINFO_MIME_TYPE);
  737. $mime = finfo_file($finfo, $file);
  738. finfo_close($finfo);
  739. return $mime;
  740. }
  741. if (function_exists("mime_content_type")) {
  742. return mime_content_type($file);
  743. }
  744. return false;
  745. }
  746.  
  747. function mail_custom($To, $Subject, $Content, $From, $ReplyTo = "", $attachment = false) {
  748. global $headers;
  749. global $setting;
  750. if ($To == "" || $From == "") {
  751. return false;
  752. }
  753. require_once(BASE . "system/misc/PHPMailer/class.phpmailer.php");
  754. $mail = new PHPMailer();
  755. if ($setting["smtp"] == "enabled") {
  756. $mail->IsSMTP();
  757. $mail->Host = $setting["smtp_host"];
  758. $mail->SMTPAuth = strtolower($setting["smtp_auth"]) == "enabled";
  759. $mail->Username = $setting["smtp_username"];
  760. $mail->Password = $setting["smtp_password"];
  761. $mail->SMTPSecure = $setting["smtp_secure"];
  762. }
  763. $mail->From = $From;
  764. $mail->FromName = $setting["company"];
  765. $mail->AddAddress($To);
  766. $mail->Subject = $Subject;
  767. $mail->AltBody = strip_tags($Content);
  768. $mail->MsgHTML($Content);
  769. if ($attachment) {
  770. $attach = array("filename" => basename($attachment), "content" => file_get_contents($attachment), "mimetype" => file_get_mimetype($attachment));
  771. $mail->AddStringAttachment($attach["content"], $attach["filename"], "base64", $attach["mimetype"]);
  772. }
  773. if (!$mail->Send()) {
  774. if (isset($setting["smtp_debug"]) && strtolower($setting["smtp_debug"]) == "enabled") {
  775. echo("SMTP Message could not be sent.");
  776. echo("Mailer Error: " . $mail->ErrorInfo);
  777. }
  778. return false;
  779. }
  780. return true;
  781. }
  782.  
  783. function include_lang($filename) {
  784. global $setting;
  785. global $vars;
  786. global $lang;
  787. if (!(isset($setting["user_lang"]))) {
  788. $setting["user_lang"] = $setting["language"];
  789. }
  790. try {
  791. include(BASE . "system/languages/english/" . $filename);
  792. }
  793. catch (Exception $e) {
  794. exit("Could not load " . BASE . "system/languages/english/" . $filename);
  795. }
  796. if ($setting["user_lang"] != "english") {
  797. try {
  798. include(BASE . "system/languages/" . $setting["user_lang"] . "/" . $filename);
  799. }
  800. catch (Exception $e) {
  801. exit("Could not load " . BASE . "system/languages/" . $setting["user_lang"] . "/" . $filename);
  802. }
  803. }
  804. foreach ($lang as $search => $replace) {
  805. if (is_array($lang[$search])) {
  806. foreach ($lang[$search] as $search1 => $replace1) {
  807. if (is_array($lang[$search][$search1])) {
  808. foreach ($lang[$search][$search1] as $search2 => $replace2) {
  809. if (is_array($lang[$search][$search1][$search2])) {
  810. continue;
  811. }
  812. $vars[strtoupper("{LANG[" . $search . "][" . $search1 . "][" . $search2 . "]}")] = $replace2;
  813. }
  814. continue;
  815. }
  816. $vars[strtoupper("{LANG[" . $search . "][" . $search1 . "]}")] = $replace1;
  817. }
  818. continue;
  819. }
  820. $vars[strtoupper("{LANG[" . $search . "]}")] = $replace;
  821. }
  822. unset($search);
  823. unset($replace);
  824. return true;
  825. }
  826.  
  827. function shellscript_check() {
  828. global $setting;
  829. if (!(is_file(BASE . "temp/castcontrol.sh"))) {
  830. shellscript_create();
  831. return true;
  832. }
  833. $handle = file(BASE . "temp/castcontrol.sh");
  834. foreach ($handle as $line) {
  835. if (isset($hash)) {
  836. $line = explode("hash=", $line);
  837. $line = str_replace("\"", "", $line[1]);
  838. if (trim($line) != $setting["sh_auth"]) {
  839. shellscript_create();
  840. break;
  841. }
  842. break;
  843. }
  844. if (isset($shoutcastexec)) {
  845. $line = explode("# ", $line);
  846. list(, $line) = $line;
  847. if (trim($line) != $setting["os"]) {
  848. shellscript_create();
  849. break;
  850. }
  851. $hash = true;
  852. unset($shoutcastexec);
  853. }
  854. if (isset($pathtocc)) {
  855. $line = explode("# ", $line);
  856. list(, $line) = $line;
  857. if (trim($line) != $setting["dir_to_cpanel"]) {
  858. shellscript_create();
  859. break;
  860. }
  861. unset($pathtocc);
  862. $shoutcastexec = true;
  863. }
  864. if (!(strstr($line, "#-----------------"))) {
  865. continue;
  866. }
  867. $detected_start = true;
  868. $pathtocc = true;
  869. }
  870. if (empty($detected_start)) {
  871. shellscript_create();
  872. return true;
  873. }
  874. }
  875.  
  876. function shellscript_create() {
  877. global $setting;
  878. $handle = @fopen(BASE . "temp/castcontrol.sh", "w+");
  879. $contents = "#!/bin/bash
  880.  
  881. #-----------------
  882. # " . $setting["dir_to_cpanel"] . "
  883. # " . $setting["os"] . "
  884. hash=\"" . $setting["sh_auth"] . "\"
  885.  
  886. if [ \"\$1\" = \"\$hash\" ]; then
  887.  
  888. if [ \"\$2\" = \"\" ]; then
  889. echo \"ERROR: No command passed to script\"
  890. exit 0
  891. fi
  892.  
  893. if [ \"\$2\" = \"server\" ]; then
  894.  
  895. if [ \"\$3\" = \"start\" ]; then
  896. " . $setting["dir_to_cpanel"] . "files/" . $setting["os"] . "/" . sc_serv . "_\$4 \$5 > /dev/null &
  897. ps -o pid -p \$!
  898. exit 1
  899. fi
  900.  
  901. if [ \"\$3\" = \"stop\" ]; then
  902. killall " . sc_serv . "_\$4
  903. echo \"killing \$4\";
  904. exit 1
  905. fi
  906. exit 0
  907.  
  908. fi
  909.  
  910. if [ \"\$2\" = \"scanner\" ]; then
  911. if [ \$3 = \"start\" ]; then
  912. \$4 -f \"" . $setting["dir_to_cpanel"] . "scanner/index.php\" > /dev/null &
  913. ps -o pid -p \$!
  914. fi
  915. fi
  916.  
  917. if [ \"\$2\" = \"trans\" ]; then
  918. if [ \$3 = \"start\" ]; then
  919. " . $setting["dir_to_cpanel"] . "files/" . $setting["os"] . "/sc_trans \$4 > /dev/null &
  920. ps -o pid -p \$!
  921. fi
  922. fi
  923.  
  924. if [ \"\$2\" = \"killpid\" ]; then
  925. kill \$3
  926. fi
  927.  
  928. if [ \"\$2\" = \"copyserv\" ]; then
  929. cp " . $setting["dir_to_cpanel"] . "files/" . $setting["os"] . "/" . sc_serv . " " . $setting["dir_to_cpanel"] . "files/" . $setting["os"] . "/" . sc_serv . "_\$3
  930. chmod 0777 " . $setting["dir_to_cpanel"] . "files/" . $setting["os"] . "/" . sc_serv . "_\$3
  931. fi
  932.  
  933. else
  934. echo \"Access Denied\"
  935. exit 0
  936. fi
  937. ";
  938. fwrite($handle, $contents);
  939. fclose($handle);
  940. system("chmod +x " . BASE . "temp/castcontrol.sh");
  941. }
  942.  
  943. function ResellerTotalUsers($resellerID) {
  944. global $db_prefix;
  945. $selectOwner = mysql_query("SELECT username FROM " . $db_prefix . "users WHERE id=" . $resellerID);
  946. $selectResoldServers = mysql_query("SELECT SUM(maxuser) FROM " . $db_prefix . "servers WHERE reseller=" . $resellerID);
  947. $totalusers = mysql_result($selectResoldServers, 0);
  948. return 0 < $totalusers ? $totalusers : 0;
  949. }
  950.  
  951. function ResellerTotalTransfer($resellerID) {
  952. global $db_prefix;
  953. $selectOwner = mysql_query("SELECT username FROM " . $db_prefix . "users WHERE id=" . $resellerID);
  954. $owner = mysql_result($selectOwner, 0);
  955. $totalTransfer = "";
  956. $selectResoldServers = mysql_query("SELECT id FROM " . $db_prefix . ("servers WHERE owner='" . $owner . "' AND reseller=") . $resellerID);
  957. while ($serverData = mysql_fetch_assoc($selectResoldServers)) {
  958. $selectBandwidth = "SELECT SUM(bandwidth) FROM " . $db_prefix . "bandwidth WHERE month = '" . date("F") . "' AND year='" . date("Y") . "' AND serverid=" . $serverData["id"];
  959. $selectBandwidth = mysql_query($selectBandwidth);
  960. if (!(0 < mysql_num_rows($selectBandwidth))) {
  961. continue;
  962. }
  963. $totalTransfer += mysql_result($selectBandwidth, 0);
  964. }
  965. return $totalTransfer;
  966. }
  967.  
  968. function ResellerTotalQuota($resellerID) {
  969. global $db_prefix;
  970. $totalQuota = "";
  971. $selectResoldServers = mysql_query("SELECT SUM(quota) FROM " . $db_prefix . "servers WHERE reseller=" . $resellerID);
  972. $value = @mysql_result($selectResoldServers, 0);
  973. return $value ? $value : 0;
  974. }
  975.  
  976. function alert($text) {
  977. if (!(defined("java_alert"))) {
  978. define("java_alert", $text);
  979. return true;
  980. }
  981. return false;
  982. }
  983.  
  984. function product($license) {
  985. return strtolower(substr($license, 3, strpos(str_replace("MP-", "", $license), "-")));
  986. }
  987.  
  988. function api($api) {
  989. global $error;
  990. $connection = fsockopen($api["http_host"], $api["http_port"], $errno, $errstr, 6);
  991. if (!$connection) {
  992. $error = "no_connection";
  993. return false;
  994. }
  995. $send = "";
  996. foreach ($api as $option => $setting) {
  997. if (strstr($option, "http_")) {
  998. continue;
  999. }
  1000. if (is_array($setting)) {
  1001. $setting = serialize($setting);
  1002. }
  1003. $send .= $option . "=" . urlencode($setting) . "&";
  1004. }
  1005. $request = $send;
  1006. $headers = "POST " . $api["http_path"] . "/system/api.php HTTP/1.0
  1007. ";
  1008. $headers .= "Host: " . $api["http_host"] . "
  1009. ";
  1010. $headers .= "Content-Type: application/x-www-form-urlencoded
  1011. ";
  1012. $headers .= "User-Agent: Cast-control 1.4.2 (http://cast-control.net)
  1013. ";
  1014. $headers .= "Content-Length: " . strlen($request) . "
  1015. ";
  1016. $headers .= "Connection: close
  1017.  
  1018. ";
  1019. $headers .= $request . "
  1020. ";
  1021. fputs($connection, $headers);
  1022. $res = "";
  1023. while (!(feof($connection))) {
  1024. $res .= fgets($connection, 1024);
  1025. }
  1026. fclose($connection);
  1027. $res = substr($res, strrpos($res, "
  1028. "), strlen($res));
  1029. if (strstr($res, "Error,Your API Key is not valid")) {
  1030. $error = "auth_failed";
  1031. return false;
  1032. }
  1033. return $res;
  1034. }
  1035.  
  1036. function get_real_path($exclusion = false) {
  1037. $cwd = getcwd();
  1038. $cwd = str_replace("\\", "/", $cwd);
  1039. if ($exclusion !== false && $exclusion != "") {
  1040. $exclusion = str_replace("/", "", $exclusion);
  1041. $exclude = false;
  1042. $split = explode("/", $cwd);
  1043. $i = 0;
  1044. while ($i < count($split)) {
  1045. if ($split[$i] == $exclusion) {
  1046. $exclude = $i;
  1047. }
  1048. ++$i;
  1049. continue;
  1050. }
  1051. if ($exclude !== false) {
  1052. $real_path = "";
  1053. $i = 0;
  1054. while ($i < count($split)) {
  1055. if ($i == $exclude) {
  1056. break;
  1057. }
  1058. $real_path .= $split[$i] . "/";
  1059. ++$i;
  1060. continue;
  1061. }
  1062. }
  1063. else {
  1064. $real_path = $cwd;
  1065. }
  1066. }
  1067. else {
  1068. $real_path = $cwd;
  1069. }
  1070. $check_last = @strrpos($real_path, "/");
  1071. if ($check_last + 1 == @strlen($real_path)) {
  1072. $real_path = substr($real_path, 0, $check_last);
  1073. }
  1074. return $real_path;
  1075. }
  1076.  
  1077. function get_real_url($exclusion = false) {
  1078. $_SERVER =& global $_SERVER;
  1079. global $setting;
  1080. if (isset($_SERVER["HTTPS"]) && strtolower($_SERVER["HTTPS"]) == "on") {
  1081. $prefix = "https://";
  1082. }
  1083. else {
  1084. $prefix = "http://";
  1085. }
  1086. $path = $prefix . $_SERVER["HTTP_HOST"] . $_SERVER["SCRIPT_NAME"];
  1087. if ($exclusion) {
  1088. $path = substr($path, 0, strpos($path, $exclusion));
  1089. }
  1090. return $path;
  1091. }
  1092.  
  1093. function table($title, $width = "90%") {
  1094. global $setting;
  1095. global $smarty;
  1096. global $lang;
  1097. if (isset($_GET["page"])) {
  1098. $page = $_GET["page"];
  1099. }
  1100. else {
  1101. $page = "main";
  1102. }
  1103. if ($page == "admin" && strstr($title, "Administration")) {
  1104. $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");
  1105. $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>");
  1106. $title = str_replace($title_search, $title_replace, $title);
  1107. }
  1108. else {
  1109. if ($page == "resell") {
  1110. $title_search = array("Servers", "Users", "Resell", "Order");
  1111. $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>");
  1112. $title = str_replace($title_search, $title_replace, $title);
  1113. }
  1114. else {
  1115. if ($page == "billing") {
  1116. $title_search = array("Billing", "Servers", "Invoices", "Purchase", "Resell");
  1117. $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>");
  1118. $title = str_replace($title_search, $title_replace, $title);
  1119. }
  1120. else {
  1121. $title_search = array("Servers", "Accounts", "Resell", "User Control Panel");
  1122. $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>");
  1123. $title = str_replace($title_search, $title_replace, $title);
  1124. }
  1125. }
  1126. }
  1127. if ($smarty) {
  1128. $smarty->assign("TABLESECTION", "TOP");
  1129. $smarty->assign("TABLETITLE", $title);
  1130. $smarty->assign("TABLEWIDTH", $width);
  1131. $smarty->display(THEME . "table.tpl");
  1132. }
  1133. }
  1134.  
  1135. function closetable($width = "89%", $footer = "") {
  1136. global $setting;
  1137. global $smarty;
  1138. if ($smarty) {
  1139. $smarty->assign("TABLEFOOTER", $footer);
  1140. $smarty->assign("TABLESECTION", "BOTTOM");
  1141. $smarty->assign("TABLEWIDTH", $width);
  1142. $smarty->display(THEME . "table.tpl");
  1143. }
  1144. }
  1145.  
  1146. function compile($file, $s_and_r) {
  1147. if (!($handle = file($file))) {
  1148. return false;
  1149. }
  1150. $file_content = "";
  1151. foreach ($handle as $line) {
  1152. $file_content .= $line;
  1153. }
  1154. foreach ($s_and_r as $search => $replace) {
  1155. $file_content = @str_replace($search, $replace, $file_content);
  1156. }
  1157. echo($file_content);
  1158. return true;
  1159. }
  1160.  
  1161. function clean_transactions() {
  1162. global $db_prefix;
  1163. mysql_query("DELETE FROM " . $db_prefix . "payments WHERE status='Awaiting Payment' AND time<" . (time() - 432000) . " AND ( payment_towards='' OR payment_towards LIKE '%:new:%' )");
  1164. }
  1165.  
  1166. function clean_users() {
  1167. return true;
  1168. }
  1169.  
  1170. function clean_temp() {
  1171. global $setting;
  1172. $dir = BASE . "temp/";
  1173. $files = array_merge(glob($dir . "*.conf"), glob($dir . "*.ini"), glob($dir . "*.sh"), glob($dir . "*.xml"));
  1174. if (0 < count($files)) {
  1175. foreach ($files as $filename) {
  1176. $creationtime = filemtime($filename);
  1177. if (!(300 < time() - $creationtime && !(is_dir($filename)))) {
  1178. continue;
  1179. }
  1180. @unlink($filename);
  1181. }
  1182. }
  1183. }
  1184.  
  1185. function check_reseller() {
  1186. global $setting;
  1187. global $userdata;
  1188. global $db_prefix;
  1189. if ($userdata["reseller_plan"] != "none" && $userdata["reseller_plan_expire"] - time() < 0 && $userdata["reseller_plan_expire"] != 0) {
  1190. $server_select = mysql_query("UPDATE " . $db_prefix . "servers SET expire='" . (time() - 1) . ("' WHERE reseller='" . $userdata["id"] . "' AND expire='0'"));
  1191. }
  1192. if ($userdata["reseller"] != "none") {
  1193. $select_reseller = mysql_query("SELECT id,reseller_plan,reseller_plan_expire FROM " . $db_prefix . "users WHERE id='" . $userdata["reseller"] . "' ");
  1194. $reselldata = mysql_fetch_array($select_reseller);
  1195. if ($reselldata["reseller_plan"] != "none" && $reselldata["reseller_plan_expire"] - time() < 0 && $reselldata["reseller_plan_expire"] != 0) {
  1196. $server_select = mysql_query("UPDATE " . $db_prefix . "servers SET expire='" . (time() - 1) . ("' WHERE reseller='" . $reselldata["id"] . "' AND expire='0'"));
  1197. }
  1198. }
  1199. }
  1200.  
  1201. function scanner_start($php = false) {
  1202. global $setting;
  1203. if ($php !== false && function_exists("is_direct_file") && @is_direct_file($php)) {
  1204. if (strstr($setting["os"], "windows")) {
  1205. $WshShell = new COM("WScript.Shell");
  1206. $oExec = $WshShell->Run("\"" . $php . "\" \"" . $setting["dir_to_cpanel"] . "scanner/index.php\"", 3, false);
  1207. }
  1208. else {
  1209. $sudo = "";
  1210. if ($setting["sudo"] == "Enabled") {
  1211. $pid = shell_exec("sudo -u " . $setting["sudo_username"] . " " . $setting["dir_to_cpanel"] . "temp/castcontrol.sh " . $setting["sh_auth"] . (" scanner start \"" . $php . "\""));
  1212. }
  1213. else {
  1214. $command = "\"" . $php . "\" -f \"" . $setting["dir_to_cpanel"] . "scanner/index.php\" > /dev/null & echo \$!";
  1215. $pid = shell_exec("\"" . $php . "\" -f \"" . $setting["dir_to_cpanel"] . "scanner/index.php\" > /dev/null & echo \$!");
  1216. }
  1217. }
  1218. return true;
  1219. }
  1220. if ($connection = fsockopen($_SERVER["HTTP_HOST"], 80, $errno, $errstr, 5)) {
  1221. $path = ereg_replace("index.php*", "scanner/index.php", $_SERVER["SCRIPT_NAME"]);
  1222. $path = ereg_replace("install/install.php*", "scanner/index.php", $path);
  1223. $headers = "GET " . $path . " HTTP/1.1
  1224. ";
  1225. $headers .= "Host: " . $_SERVER["HTTP_HOST"] . "
  1226. ";
  1227. $headers .= "Content-Type: application/x-www-form-urlencoded
  1228. ";
  1229. $headers .= "User-Agent: Cast-control 1.4.3 (http://cast-control.net)
  1230. ";
  1231. $headers .= "Connection: close
  1232.  
  1233. ";
  1234. fputs($connection, $headers);
  1235. sleep(1);
  1236. fclose($connection);
  1237. return true;
  1238. }
  1239. return false;
  1240. }
  1241.  
  1242. function check_scanner() {
  1243. global $setting;
  1244. global $db_prefix;
  1245. ignore_user_abort(true);
  1246. $scandata = mysql_result(mysql_query("SELECT value FROM " . $db_prefix . "settings WHERE setting='scanner_detail'"), 0);
  1247. $pid = "";
  1248. if ($scandata != "") {
  1249. $scanner = explode("||", $scandata);
  1250. $pid = trim($scanner[1]);
  1251. $timestamp = trim($scanner[0]);
  1252. }
  1253. if (!(empty($pid))) {
  1254. if (strstr($setting["os"], "windows")) {
  1255. $output = array();
  1256. exec("tasklist /FI \"PID eq " . $pid . "\" /NH", $output);
  1257. foreach ($output as $id => $line) {
  1258. if (strstr($line, $pid)) {
  1259. $online = true;
  1260. }
  1261. if (!(strstr($line, "INFO:"))) {
  1262. continue;
  1263. }
  1264. return 1;
  1265. }
  1266. }
  1267. else {
  1268. $output = array();
  1269. exec("ps -p " . $pid, $output);
  1270. if (1 < count($output)) {
  1271. $online = true;
  1272. }
  1273. }
  1274. }
  1275. if (isset($online)) {
  1276. return 2;
  1277. }
  1278. if (isset($scanner)) {
  1279. return 1;
  1280. }
  1281. return 0;
  1282. }
  1283.  
  1284. function stop_scanner() {
  1285. global $setting;
  1286. global $db_prefix;
  1287. $scandata = mysql_result(mysql_query("SELECT value FROM " . $db_prefix . "settings WHERE setting='scanner_detail'"), 0);
  1288. $scanner = explode("||", $scandata);
  1289. $pid = trim($scanner[1]);
  1290. if (strstr($setting["os"], "windows")) {
  1291. $output = array();
  1292. exec("tasklist /fi \"pid eq " . $pid . "\" /NH", $output);
  1293. $output_name = explode(" ", $output[1]);
  1294. $output_name = $output_name[0];
  1295. if (strlen($output_name) == 0) {
  1296. mysql_query("UPDATE " . $db_prefix . "settings SET value='' WHERE setting='scanner_detail'");
  1297. return true;
  1298. }
  1299. unset($output);
  1300. $output = array();
  1301. if (!(exec("taskkill /pid " . $pid . " /f", $output))) {
  1302. return false;
  1303. }
  1304. if (!(strstr($output[0], "SUCCESS"))) {
  1305. return false;
  1306. }
  1307. }
  1308. if (strtolower($setting["sudo"]) == "enabled") {
  1309. $command = "sudo -u " . $setting["sudo_username"] . " " . $setting["dir_to_cpanel"] . "temp/castcontrol.sh " . $setting["sh_auth"] . (" killpid " . $pid);
  1310. }
  1311. else {
  1312. $command = "kill " . $pid;
  1313. }
  1314. exec($command, $output);
  1315. mysql_query("UPDATE " . $db_prefix . "settings SET value='' WHERE setting='scanner_detail'");
  1316. return true;
  1317. }
  1318.  
  1319. function serv_status($id, $connect = 0, $display_unconnectable = false, $clustered = false) {
  1320. require_once(BASE . "system/shoutcast.php");
  1321. return shoutcast_status($id, $connect, $display_unconnectable, $clustered);
  1322. }
  1323.  
  1324. function expire($expiry) {
  1325. $expiredays = round(($expiry - time()) / 86400, 2);
  1326. $expirehours = round(($expiry - time()) / 3600, 2);
  1327. $expiremins = round(($expiry - time()) / 60, 1);
  1328. $expiresecs = round($expiry - time(), 2);
  1329. $expire = round(($expiry - time()) / 2592000, 1) . " Months";
  1330. if ($expire < 1) {
  1331. $expire = round($expiredays) . " Days";
  1332. }
  1333. if ($expiredays < 1) {
  1334. $expire = "<font color='brown'>" . round($expirehours) . " Hours</font>";
  1335. }
  1336. if ($expirehours < 1) {
  1337. $expire = "<font color='red'>" . round($expiremins) . " Minutes</font>";
  1338. }
  1339. if ($expiremins < 1) {
  1340. $expire = "<font color='red'>" . round($expiresecs) . " Seconds</font>";
  1341. }
  1342. if ($expiresecs <= 0) {
  1343. $expire = "<font color='red'>EXPIRED</font>";
  1344. }
  1345. if ($expiry == 0) {
  1346. $expire = "Never";
  1347. }
  1348. return $expire;
  1349. }
  1350.  
  1351. function convert_tstamp($data) {
  1352. $start = strtok($data, " ");
  1353. $start = str_replace(array("<", ">"), "", $start);
  1354. $start = split("@", $start);
  1355. return strtotime($start[0] . " " . $start[1]);
  1356. }
  1357.  
  1358. function keepalive($file, $status = 0, $dir = "./logs/") {
  1359. global $setting;
  1360. $file = BASE . "logs/" . $file;
  1361. if ($status == 1) {
  1362. if (!(is_file($file))) {
  1363. return false;
  1364. }
  1365. $contents = "";
  1366. $i = 0;
  1367. $handle = file($file);
  1368. foreach ($handle as $line) {
  1369. $contents .= $line;
  1370. if (!(strstr($line, "[cast-control] Keep-Alive"))) {
  1371. continue;
  1372. }
  1373. $keepalive[$i]["time"] = convert_tstamp($line);
  1374. $keepalive[$i]["line"] = $line;
  1375. ++$i;
  1376. }
  1377. if (!(isset($keepalive))) {
  1378. $keepalive[0]["time"] = 0;
  1379. $keepalive[0]["line"] = "[cast-control] Keep-Alive";
  1380. }
  1381. $count = count($keepalive) - 1;
  1382. $seconds = time() - $keepalive[$count]["time"];
  1383. if (180 < $seconds) {
  1384. ...............................................................
  1385. ..........................
  1386. ...........
Add Comment
Please, Sign In to add comment