Merge branch 'devel' of dev.sourcefabric.org:airtime into devel

This commit is contained in:
martin 2011-09-16 17:53:37 -04:00
commit 3485b5a39f
17 changed files with 220 additions and 553 deletions

View file

@ -1,214 +0,0 @@
<?php
require_once (dirname(__FILE__).'/Crontab.php');
require_once (dirname(__FILE__).'/../../conf.php');
/**
* This class can call a PHP function from crontab.
* Example:
* <pre>
* $cron = new Cron();
* $access = $cron->openCrontab('write');
* if ($access != 'write') {
* do {
* $access = $cron->forceWriteable();
* } while ($access != 'write');
* }
* $cron->addCronJob('*','*','*','*','*',
* 'ClassName',
* array('first','secound','third')
* );
* $cron->closeCrontab();
* </pre>
* @package Airtime
* @subpackage StorageServer.Cron
*/
class Cron {
/**
* @var Crontab
*/
public $ct;
/**
* @var array This array created with getCommand() function
*/
private $params;
/**
* @var string available values: read | write
*/
private $ctAccess = 'read';
private $lockfile;
private $cronfile;
private $paramdir;
private $cronUserName;
/**
* Constructor
*/
function Cron() {
global $CC_CONFIG;
$this->lockfile = $CC_CONFIG['lockfile'];
$this->cronfile = $CC_CONFIG['cronfile'];
$this->paramdir = $CC_CONFIG['paramdir'];
$this->cronUserName = $CC_CONFIG['cronUserName'];
}
/* ==================================================== Cronjob functions */
/**
* Add a cronjob to the crontab
*
* @access public
* @param string $m minute
* @param string $h hour
* @param string $dom day of month
* @param string $mo month
* @param string $dow day of week
* @param string $className name of class, which's execute() is called by croncall.php
* @param string $params the parameter(s)
* @return bool true if success else PEAR error.
*/
function addCronJob($m, $h, $dom, $mo, $dow, $className, $params)
{
if ($this->ctAccess == 'write') {
$this->ct->addCron($m, $h, $dom, $mo, $dow,
$this->getCommand($className, $params));
return true;
} else {
return PEAR::raiseError('CronJob::addCronJob : '.
'The crontab is not writable');
}
}
/**
* This function return with the active cronjobs
*
* @access public
* @return array array of cronjob struct
*/
function listCronJob()
{
return $this->ct->getByType(CRON_CMD);
}
/**
* Remove a cronjob.
*
* @access public
* @param int $index index of the cronjobs' array.
* @return bool true if success else PEAR error.
*/
function removeCronJob($index)
{
if ($this->ctAccess == 'write') {
$this->crontab->delEntry($index);
return true;
} else {
return PEAR::raiseError('CronJob::removeCronJob : '.
'The crontab is not writable');
}
}
/* ==================================================== Crontab functions */
/**
* Open the crontab
*
* @access public
* @param string $access only for listing 'read', for add and delete 'write'
* @return string sucessed access - available values read | write
*/
function openCrontab($access = 'read')
{
$access = strtolower($access);
$this->ct = new Crontab($this->cronUserName);
if ($access == 'write' &&
$this->isCrontabWritable() &&
$this->lockCrontab()) {
$this->ctAccess = $access;
} else {
$this->ctAccess = 'read';
}
return $this->ctAccess;
}
/**
* Close the crontab
*
* @access public
* @return bool true if everything is ok, false is the lock file can't delete
*/
function closeCrontab()
{
if ($this->ctAccess == 'write') {
$this->ct->writeCrontab();
}
return $this->ctAccess == 'write' ? $this->unlockCrontab() : true;
}
/**
* Check the crontab is writable
*
* @access private
* @return bool
*/
function isCrontabWritable()
{
return !is_file($this->lockfile);
}
/**
* Try to lock the crontab
*
* @access private
* @return bool true if the locking is success
*/
function lockCrontab()
{
return @touch($this->lockfile);
}
/**
* Try to unlock the crontab
*
* @access private
* @return bool true if the unlocking is success
*/
function unlockCrontab()
{
return unlink($this->lockfile);
}
/**
* If the crontab opened with read access. This function force set
* the access to write.
*
* @access public
* @return bool true if the setting is success
*/
function forceWriteable()
{
if ($this->isCrontabWritable() && $this->lockCrontab()) {
$this->ctAccess = 'write';
return true;
}
return false;
}
/* ======================================================= Misc functions */
/**
* Get the shell command for the cronjob
*
* @param string $className name of the class what is called by croncall.php
* @param mixed $params with this parameter could be called the execute() of class
* @return string shell command
*/
function getCommand($className, $params)
{
$this->params = array (
'class' => $className,
'params' => $params
);
return $this->cronfile.' "'.str_replace('"','\"',serialize($this->params)).'"';
}
}

View file

@ -1,17 +0,0 @@
<?php
/**
* Cron jobs handling abstract class
*
* @package Airtime
* @subpackage StorageServer.Cron
*/
class CronJob
{
/**
* The croncall.php call this function after the objectcreation.
*/
function execute()
{
}
}

View file

@ -1,284 +0,0 @@
<?php
define('CRON_COMMENT', 0);
define('CRON_ASSIGN', 1);
define('CRON_CMD', 2);
define('CRON_SPECIAL', 3);
define('CRON_EMPTY', 4);
/**
* A class that interfaces with the crontab. (cjpa@audiophile.com)
*
* This class lets you manipulate a user's crontab.
* It lets you add delete update entries easily.
*
* @package Airtime
* @subpackage StorageServer.Cron
*/
class Crontab
{
// {{{ properties
/**
* Holds all the different lines.
* Lines are associative arrays with the following fields:
* "minute" : holds the minutes (0-59)
* "hour" : holds the hour (0-23)
* "dayofmonth" : holds the day of the month (1-31)
* "month" : the month (1-12 or the names)
* "dayofweek" : 0-7 (or the names)
*
* or a line can be a 2-value array that represents an assignment:
* "name" => "value"
* or a line can be a comment (string beginning with #)
* or it can be a special command (beginning with an @)
* @var array
*/
private $crontabs;
/**
* The user for whom the crontab will be manipulated
* @var string
*/
private $user;
/**
* Lists the type of line of each line in $crontabs.
* can be: any of the CRON_* constants.
* so $linetype[5] is the type of $crontabs[5].
* @var string
*/
private $linetypes;
// }}}
/**
* Constructor
*
* Initialises $this->crontabs
*
* @param string $user the user for whom the crontab will be manipulated
*/
function Crontab($user)
{
$this->user = $user;
$this->readCrontab();
}
/**
* This reads the crontab of $this->user and parses it in $this->crontabs
*
*/
function readCrontab()
{
// return code is 0 or 1 if crontab was empty, elsewhere stop here
$cmd = "crontab -u {$this->user} -l";
@exec("crontab -u {$this->user} -l", $crons, $return);
if ($return > 1) {
return PEAR::raiseError("*** Can't read crontab ***\n".
" Set crontab manually!\n");
}
foreach ($crons as $line)
{
$line = trim($line); // discarding all prepending spaces and tabs
// empty lines..
if (!$line) {
$this->crontabs[] = "empty line";
$this->linetypes[] = CRON_EMPTY;
continue;
}
// checking if this is a comment
if ($line[0] == "#") {
$this->crontabs[] = trim($line);
$this->linetypes[] = CRON_COMMENT;
continue;
}
// Checking if this is an assignment
if (ereg("(.*)=(.*)", $line, $assign)) {
$this->crontabs[] = array ("name" => $assign[1], "value" => $assign[2]);
$this->linetypes[] = CRON_ASSIGN;
continue;
}
// Checking if this is a special @-entry. check man 5 crontab for more info
if ($line[0] == '@') {
$this->crontabs[] = split("[ \t]", $line, 2);
$this->linetypes[] = CRON_SPECIAL;
continue;
}
// It's a regular crontab-entry
$ct = split("[ \t]", $line, 6);
$this->addCron($ct[0], $ct[1], $ct[2], $ct[3], $ct[4], $ct[5]);
}
}
/**
* Writes the current crontab
*/
function writeCrontab()
{
global $DEBUG, $PATH;
if (empty($this->linetypes)) {
return;
}
$filename = ($DEBUG ? tempnam("$PATH/crons", "cron") : tempnam("/tmp", "cron"));
$file = fopen($filename, "w");
foreach($this->linetypes as $i => $line) {
switch ($this->linetypes[$i]) {
case CRON_COMMENT:
$line = $this->crontabs[$i];
break;
case CRON_ASSIGN:
$line = $this->crontabs[$i][name]." = ".$this->crontabs[$i][value];
break;
case CRON_CMD:
$line = implode(" ", $this->crontabs[$i]);
break;
case CRON_SPECIAL:
$line = implode(" ", $this->crontabs[$i]);
break;
case CRON_EMPTY:
$line = "\n"; // an empty line in the crontab-file
break;
default:
unset($line);
echo "Something very weird is going on. This line ($i) has an unknown type.\n";
break;
}
// echo "line $i : $line\n";
if ($line) {
$r = @fwrite($file, $line."\n");
if($r === FALSE) {
return PEAR::raiseError("*** Can't write crontab ***\n".
" Set crontab manually!\n");
}
}
}
fclose($file);
if ($DEBUG) {
echo "DEBUGMODE: not updating crontab. writing to $filename instead.\n";
} else {
exec("crontab -u {$this->user} $filename", $returnar, $return);
if ($return != 0) {
echo "Error running crontab ($return). $filename not deleted\n";
} else {
unlink($filename);
}
}
}
/**
* Add a item of type CRON_CMD to the end of $this->crontabs
*
* @param string $m
* minute
* @param string $h
* hour
* @param string $dom
* day of month
* @param string $mo
* month
* @param string $dow
* day of week
* @param string $cmd
* command
*
*/
function addCron($m, $h, $dom, $mo, $dow, $cmd)
{
$this->crontabs[] = array ("minute" => $m, "hour" => $h, "dayofmonth" => $dom, "month" => $mo, "dayofweek" => $dow, "command" => $cmd);
$this->linetypes[] = CRON_CMD;
}
/**
* Add a comment to the cron to the end of $this->crontabs
*
* @param string $comment
*/
function addComment($comment)
{
$this->crontabs[] = "# $comment\n";
$this->linetypes[] = CRON_COMMENT;
}
/**
* Add a special command (check man 5 crontab for more information)
*
* @param string $sdate special date
* string meaning
* ------ -------
* @reboot Run once, at startup.
* @yearly Run once a year, "0 0 1 1 *".
* @annually (same as @yearly)
* @monthly Run once a month, "0 0 1 * *".
* @weekly Run once a week, "0 0 * * 0".
* @daily Run once a day, "0 0 * * *".
* @midnight (same as @daily)
* @hourly Run once an hour, "0 * * * *".
* @param string $cmd command
*/
function addSpecial($sdate, $cmd)
{
$this->crontabs[] = array ("special" => $sdate, "command" => $cmd);
$this->linetypes[] = CRON_SPECIAL;
}
/**
* Add an assignment (name = value)
*
* @param string $name
* @param string $value
*/
function addAssign($name, $value)
{
$this->crontabs[] = array ("name" => $name, "value" => $value);
$this->linetypes[] = CRON_ASSIGN;
}
/**
* Delete a line from the arrays.
*
* @param int $index the index in $this->crontabs
*/
function delEntry($index)
{
unset ($this->crontabs[$index]);
unset ($this->linetypes[$index]);
}
/**
* Get all the lines of a certain type in an array
*
* @param string $type
*/
function getByType($type)
{
if ($type < CRON_COMMENT || $type > CRON_EMPTY)
{
trigger_error("Wrong type: $type", E_USER_WARNING);
return 0;
}
$returnar = array ();
for ($i = 0; $i < count($this->linetypes); $i ++)
if ($this->linetypes[$i] == $type)
$returnar[] = $this->crontabs[$i];
return $returnar;
}
}

View file

@ -1,8 +0,0 @@
#!/usr/bin/php
<?php
chdir(dirname(__FILE__));
$p = unserialize($argv[1]);
require_once (dirname(__FILE__).'/'.$p['class'].'.php');
$cronjob = new $p['class']();
$ret = $cronjob->execute($p['params']);
exit(0);

View file

@ -335,10 +335,10 @@ fieldset.plain {
font-family:Arial, Helvetica, sans-serif;
border: 1px solid #5b5b5b;
font-size: 12px;
height: 23px;
/*height: 23px;*/
margin: 0;
padding: 0;
text-indent: 3px;
padding: 4px 3px;
/*text-indent: 3px;*/
width:auto;
background-color: #dddddd;
border: 1px solid #5b5b5b;
@ -456,7 +456,7 @@ dl.inline-list dd {
background-color: #95d5f7 !important;
}
.datatable tr td:first-child, .datatable tr th:first-child, .datatable tr th.ui-state-default:first-child {
.datatable tr td:first-child, .datatable tr th:first-child, .datatable tr th.ui-state-default:first-child, tr td:first-child, tr th:first-child {
border-left-width:0 !important;
}
.ui-widget-header + .datatable {
@ -530,12 +530,10 @@ dl.inline-list dd {
}
.dataTables_filter input {
background: url("images/search_auto_bg.png") no-repeat scroll 0 0 #DDDDDD;
text-indent: 25px;
width: 60%;
border: 1px solid #5B5B5B;
height: 23px;
margin: 0;
padding: 0;
padding: 4px 3px 4px 25px;
}
.dataTables_length select {
background-color: #DDDDDD;
@ -1067,7 +1065,7 @@ h2#scheduled_playlist_name span {
}
.simple-formblock dd .input_text {
width: 100%;
width: 97.8%;
}
.simple-formblock h2 {
@ -1135,7 +1133,7 @@ button, input {
padding-bottom: 12px;
}
.user-management .dataTables_filter input {
width: 99.6%;
width: 93.8%;
margin-bottom:8px;
}
.user-data.simple-formblock dd {
@ -1426,7 +1424,7 @@ div.success{
.text-content {
padding:20px 10px 40px 58px;
background: url(images/sf_arror.png) no-repeat 60% 0;
height:100%;
min-height: 300px;
}
.text-content h2 {
font-size:2.4em;
@ -1748,6 +1746,7 @@ button.ui-button.md-cancel {
.dialogPopup fieldset dd input[type="text"], .dialogPopup fieldset dd textarea {
width:99.5%;
padding:0;
height:23px;
}
.dialogPopup fieldset dd select {
width:100%;
@ -1799,7 +1798,7 @@ label span {
}
#watched-folder-section dd.block-display input[type="text"] {
width: 65%;
width: 63.6%;
}
#watched-folder-section dd.block-display input[type="button"] {
@ -1923,7 +1922,7 @@ dd .info-text-small {
padding: 4px 0;
}
.stream-config dt.block-display {
width: 130px;
width:auto;
}
.stream-config dd {
margin-bottom:0px;
@ -1965,7 +1964,7 @@ dt.block-display.info-block {
}
.stream-config dd.block-display input[type="text"].with-info, .stream-config dd.block-display input[type="password"].with-info {
width: 85%;
width: 83.6%;
}
.stream-config dd.block-display p {
font-size:13px;
@ -1984,11 +1983,212 @@ dt.block-display.info-block {
opacity:0.6;
}
.stream-setting-content {
margin-top:-1px;
/*---//////////////////// ERROR PAGE ////////////////////---*/
.error-content {
background:url(images/404.png) no-repeat 0 0;
width:300px;
margin: 24px 15px;
padding: 0px 10px 0 420px;
}
.error-content h2 {
margin:0;
padding:0 0 10px 0;
font-size:36px;
font-weight:bold;
color:#3e3e3e;
text-align:left;
letter-spacing:-.3px;
text-shadow: rgba(248,248,248,.3) 0 1px 0, rgba(0,0,0,.8) 0 -1px 0;
rgba(51,51,51,.9)
}
.error-content p {
color: #272727;
font-size: 16px;
margin: 0;
padding:8px 2px;
}
.error-content .button-bar {
margin-top:47px;
padding-left:2px;
}
.error-content .toggle-button {
border: 1px solid #434343;
border-width:1px 1px 0px 1px;
background-color: #636363;
background: -moz-linear-gradient(top, #737373 0, #545454 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0, #737373), color-stop(100%, #545454));
color: #1b1b1b;
font-size:15px;
font-weight:bold;
padding:5px 14px 6px 15px;
text-shadow: rgba(248,248,248,.24) 0 1px 0;
box-shadow: rgba(248,248,248,.3) 0px 1px 0px, rgba(0, 0, 0, 0.2) 0 2px 2px inset;
-moz-box-shadow: rgba(248,248,248,.3) 0px 1px 0px, rgba(0, 0, 0, 0.2) 0 2px 2px inset;
-webkit-box-shadow: rgba(248,248,248,.3) 0px 1px 0px, rgba(0, 0, 0, 0.2) 0 2px 2px inset;
margin: 0 5px 0 0;
}
.error-content .toggle-button:hover {
border: 1px solid #000;
border-width:1px 1px 0px 1px;
background-color: #353535;
background: -moz-linear-gradient(top, #393939 0, #000000 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0, #393939), color-stop(100%, #000000));
color: #ff5d1a;
text-shadow:none;
box-shadow: rgba(248,248,248,.3) 0px 1px 0px, rgba(0, 0, 0, 0.6) 0 2px 2px inset;
-moz-box-shadow: rgba(248,248,248,.3) 0px 1px 0px, rgba(0, 0, 0, 0.6) 0 2px 2px inset;
-webkit-box-shadow: rgba(248,248,248,.3) 0px 1px 0px, rgba(0, 0, 0, 0.6) 0 2px 2px inset;
}
.login-content dd .center {
margin-left: 42%;
/*---//////////////////// DEFAULT TABLE ////////////////////---*/
table {
border-color: #5b5b5b;
border-style: solid;
border-width: 2px 1px 1px 1px;
background-color: #D8D8D8;
}
tbody tr th {
color: #000000;
background-color: #b1b1b1;
background: -moz-linear-gradient(top, #bebebe 0, #a2a2a2 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0, #bebebe), color-stop(100%, #a2a2a2));
font-size: 13px;
padding: 5px 5px;
border-color: #b1b1b1;
border-style: solid;
border-width: 1px 0 0 1px;
border-top-color: #5b5b5b;
text-align:left;
}
thead tr th {
color: #FFFFFF;
font-size: 13px;
padding: 5px 5px;
border-color:#CCCCCC;
background-color: #6e6e6e;
background: -moz-linear-gradient(top, #868686 0, #6e6e6e 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0, #868686), color-stop(100%, #6e6e6e));
border-style: solid;
border-width: 0 0 0 1px;
}
tr td {
border-color: #b1b1b1;
border-style: solid;
border-width: 1px 0 0 1px;
font-size: 13px;
padding: 5px 5px;
}
tfoot tr td, tfoot tr th {
color:#FFFFFF;
background-color: #6e6e6e;
background: -moz-linear-gradient(top, #6e6e6e 0, #868686 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0, #6e6e6e), color-stop(100%, #868686));
font-size: 13px;
padding: 5px 5px;
border-color: #b1b1b1;
border-style: solid;
border-width: 1px 0 0 1px;
}
tfoot tr th {
font-weight:bold;
text-align:left;
}
/*---//////////////////// STATUS TABLE ////////////////////---*/
.statustable tr td {
text-align:center;
vertical-align:text-top;
}
.statustable tr td:first-child, .statustable tr th:first-child {
text-align:left;
}
.checked-icon {
width:100%;
margin:0;
background: url("images/accept.png") no-repeat center center;
height:16px;
margin:0;
display:block;
}
.not-available-icon {
width:100%;
margin:0;
background: url("images/delete.png") no-repeat center center;
height:16px;
margin:0;
display:block;
}
.statustable ul {
margin:4px 0;
padding:0;
}
.statustable ul li {
background:#bbb;
margin:2px 0 6px 0;
padding:4px 8px 0;
position:relative;
min-height:22px;
border-radius: 4px;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
font-size:13px;
}
.big {
width:120px;
height:10px;
background:#444444;
background: -moz-linear-gradient(top, #464646 0, #3e3e3e 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0, #3e3e3e), color-stop(100%, #464646));
border-bottom:1px solid #fff;
margin: 0 auto;
padding: 1px;
display:inline-block;
}
.diskspace {
background-color:#e76400;
background: -moz-linear-gradient(top, #ff6f01 0, #bc5200 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0, #ff6f01), color-stop(100%, #bc5200));
height:10px;
}
.statustable a {
color: #222;
text-decoration: underline;
}
.statustable a:visited {
color: #666;
text-decoration: underline;
}
.statustable a:hover {
color: #e76400;
text-decoration: underline;
}
.strong {
font-weight:bold;
}
/*---//////////////////// PLUPLOAD ERROR ////////////////////---*/
#plupload_error{
margin-top:10px;
}
#plupload_error table {
color:red;
border:1px solid #c83f3f;
background:#c6b4b4;
}
#plupload_error table td {
color:#902d2d;
font-size:12px;
font-weight:bold;
padding:2px 4px;
margin-bottom:2px;
border:none;
margin:0;
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -1,4 +1,3 @@
#!/usr/bin/env python2.6
# -*- coding: utf-8 -*-
import time

View file

@ -1,4 +1,3 @@
#!/usr/bin/env python2.6
# -*- coding: utf-8 -*-
import os

View file

@ -1,4 +1,3 @@
#!/usr/bin/env python2.6
# -*- coding: utf-8 -*-
import time

View file

@ -1,4 +1,3 @@
#!/usr/bin/env python2.6
# -*- coding: utf-8 -*-
import os

View file

@ -1,4 +1,3 @@
#!/usr/bin/env python2.6
# -*- coding: utf-8 -*-
"""

View file

@ -1,4 +1,3 @@
#!/usr/bin/env python2.6
# -*- coding: utf-8 -*-
"""

View file

@ -1,4 +1,3 @@
#!/usr/bin/env python2.6
# -*- coding: utf-8 -*-
import sys
import time

View file

@ -1,4 +1,3 @@
#!/usr/bin/env python2.6
# -*- coding: utf-8 -*-
import time

View file

@ -1,4 +1,3 @@
#!/usr/bin/env python2.6
# -*- coding: utf-8 -*-
import os

View file

@ -1,4 +1,3 @@
#!/usr/bin/env python2.6
# -*- coding: utf-8 -*-
#-------------------------------------------------------------------------------
# Copyright (c) 2010 Sourcefabric O.P.S.