2016-04-30 19:33:41 +02:00
< ? php
function format_time ( $seconds ) {
2017-05-16 10:05:52 +02:00
$secs = intval ( $seconds % 60 );
$mins = intval ( $seconds / 60 % 60 );
$hours = intval ( $seconds / 3600 % 24 );
$days = intval ( $seconds / 86400 );
$uptimeString = " " ;
2016-04-30 19:33:41 +02:00
2017-01-10 15:04:51 +01:00
if ( $days > 0 ) {
$uptimeString .= $days ;
$uptimeString .= (( $days == 1 ) ? " day " : " days " );
}
if ( $hours > 0 ) {
$uptimeString .= (( $days > 0 ) ? " , " : " " ) . $hours ;
$uptimeString .= (( $hours == 1 ) ? " hr " : " hrs " );
}
if ( $mins > 0 ) {
$uptimeString .= (( $days > 0 || $hours > 0 ) ? " , " : " " ) . $mins ;
$uptimeString .= (( $mins == 1 ) ? " min " : " mins " );
}
if ( $secs > 0 ) {
$uptimeString .= (( $days > 0 || $hours > 0 || $mins > 0 ) ? " , " : " " ) . $secs ;
$uptimeString .= (( $secs == 1 ) ? " s " : " s " );
}
return $uptimeString ;
2016-04-30 19:33:41 +02:00
}
2016-05-01 22:53:23 +02:00
function startsWith ( $haystack , $needle ) {
2017-01-10 15:04:51 +01:00
return $needle === " " || strrpos ( $haystack , $needle , - strlen ( $haystack )) !== false ;
2016-05-01 22:53:23 +02:00
}
2016-05-12 15:55:02 +02:00
function getMHZ ( $freq ) {
2017-01-10 15:04:51 +01:00
return substr ( $freq , 0 , 3 ) . " . " . substr ( $freq , 3 , 6 ) . " MHz " ;
2016-05-12 15:55:02 +02:00
}
2016-05-15 23:03:52 +02:00
function isProcessRunning ( $processname ) {
2017-01-10 15:04:51 +01:00
exec ( " pgrep " . $processname , $pids );
if ( empty ( $pids )) {
// process not running!
return false ;
} else {
// process running!
return true ;
}
2016-05-15 23:03:52 +02:00
}
2017-07-12 20:35:32 +02:00
function clean ( $string ) {
2017-11-02 22:31:06 +01:00
return preg_replace ( '/[^A-Za-z0-9:\-\/\ \.\_\>\&]/' , '' , $string ); // Removes special chars.
2017-07-12 20:35:32 +02:00
}
2016-10-26 09:46:15 +02:00
function createConfigLines () {
2017-01-10 15:04:51 +01:00
$out = " " ;
foreach ( $_GET as $key => $val ) {
if ( $key != " cmd " ) {
2017-11-02 22:27:18 +01:00
//$val = clean($val);
2017-01-10 15:04:51 +01:00
$out .= " define( \" $key\ " , \ " $val\ " ); " . " \n " ;
}
}
return $out ;
2016-10-26 09:46:15 +02:00
}
2016-05-20 14:16:33 +02:00
2016-07-12 19:34:21 +02:00
function getSize ( $filesize , $precision = 2 ) {
2017-01-10 15:04:51 +01:00
$units = array ( '' , 'K' , 'M' , 'G' , 'T' , 'P' , 'E' , 'Z' , 'Y' );
foreach ( $units as $idUnit => $unit ) {
if ( $filesize > 1024 )
$filesize /= 1024 ;
else
break ;
}
return round ( $filesize , $precision ) . ' ' . $units [ $idUnit ] . 'B' ;
2016-07-12 19:34:21 +02:00
}
2016-05-20 14:16:33 +02:00
function checkSetup () {
2017-01-10 15:04:51 +01:00
$el = error_reporting ();
error_reporting ( E_ERROR | E_WARNING | E_PARSE );
2020-05-03 23:05:51 +02:00
if ( file_exists ( " setup.php " ) && ! defined ( " DISABLESETUPWARNING " )) {
2017-01-10 15:04:51 +01:00
?>
2017-03-14 07:31:30 +01:00
< div class = " alert alert-danger " role = " alert " >< ? php echo _ ( " You forgot to remove setup.php in root-directory of your dashboard or you forgot to configure it! Please delete the file or configure your Dashboard by calling <a href= \" setup.php \" >setup.php</a>! " ); ?> </div>
2017-01-10 15:04:51 +01:00
< ? php
}
error_reporting ( $el );
2016-05-20 14:16:33 +02:00
}
2016-10-12 17:45:24 +02:00
function startStopwatch () {
2018-04-04 21:06:19 +02:00
$time = microtime ();
$time = explode ( ' ' , $time );
$time = $time [ 1 ] + $time [ 0 ];
$_SESSION [ 'starttime' ] = $time ;
return $time ;
2016-10-12 17:45:24 +02:00
}
function getLapTime () {
2018-04-04 21:06:19 +02:00
$start = $_SESSION [ 'starttime' ];
$time = microtime ();
$time = explode ( ' ' , $time );
$time = $time [ 1 ] + $time [ 0 ];
$finish = $time ;
$lap_time = round (( $finish - $start ), 4 );
return $lap_time ;
2016-10-12 17:45:24 +02:00
}
function showLapTime ( $func ) {
2018-04-04 21:06:19 +02:00
if ( defined ( " DEBUG " ) ) {
?> <script>console.log('<?php echo $func . ": ". getLapTime(); ?> sec.');</script><?php
}
2016-10-12 17:45:24 +02:00
}
2016-11-03 21:08:31 +01:00
function convertTimezone ( $timestamp ) {
2018-04-04 21:06:19 +02:00
try {
$date = new DateTime ( $timestamp );
$date -> setTimezone ( new DateTimeZone ( TIMEZONE ));
return $date -> format ( 'Y-m-d H:i:s' );
} catch ( Exception $err ) {}
2016-11-03 21:08:31 +01:00
}
2017-02-13 21:48:20 +01:00
function encode ( $hex ) {
2018-04-04 21:06:19 +02:00
$validchars = " abcdefghijklmnopqrstuvwxyzäöüßABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÜ0123456789 " ;
2017-05-16 10:05:52 +02:00
$str = '' ;
$chrval = hexdec ( $hex );
$str = chr ( $chrval );
2017-02-13 21:48:20 +01:00
if ( strpos ( $validchars , $str ) >= 0 )
return $str ;
else
return " " ;
}
2017-03-23 20:40:34 +01:00
function recursive_array_search ( $needle , $haystack ) {
foreach ( $haystack as $key => $value ) {
2017-05-16 10:05:52 +02:00
$current_key = $key ;
2017-03-23 20:40:34 +01:00
if ( $needle === $value OR ( is_array ( $value ) && recursive_array_search ( $needle , $value ) !== false )) {
return $current_key ;
}
}
return false ;
}
2020-09-21 22:29:17 +02:00
function rot1 ( $text ) {
$ric = 0 ;
$slot = 0 ;
$out = " " ;
for ( $i = 0 ; $i < strlen ( $text ); $i ++ ) {
if ( $i == 0 )
$ric = ord ( $text [ $i ]) - 31 ;
if ( $i == 1 )
$slot = ord ( $text [ $i ]) - 32 ;
if ( $i > 1 )
$out .= chr ( ord ( $text [ $i ]) - 1 );
}
return " Skyper-Rubric-No.: " . $ric . " , Slot: " . $slot . " , message: " . $out ;
}
2016-06-24 13:50:26 +02:00
?>