From 2da8161fb73580bbb175061cf07bbfba83d758e4 Mon Sep 17 00:00:00 2001 From: paul Date: Mon, 5 Feb 2007 14:06:59 +0000 Subject: [PATCH] Fixed database initialization script so that it still works when run multiple times. Previously the StorageRoot would be created again for each installation. Added more verbose output about the database initialization. Added checks for is_null() on the return value for StoredFile::Recall*() functions. Do not create the "public" virtual subfolder when creating a new user. Create the root user in the same way that normal users are created. --- campcaster/src/modules/alib/var/M2tree.php | 4 +- campcaster/src/modules/alib/var/Subjects.php | 5 +- .../modules/htmlUI/var/localizer/index.php | 40 +-- .../modules/htmlUI/var/ui_playlist.class.php | 3 +- .../modules/htmlUI/var/ui_subjects.class.php | 4 +- .../modules/storageServer/var/AccessRecur.php | 2 +- .../src/modules/storageServer/var/Backup.php | 2 +- .../modules/storageServer/var/BasicStor.php | 253 ++++++++++-------- .../modules/storageServer/var/GreenBox.php | 18 +- .../src/modules/storageServer/var/LocStor.php | 22 +- .../modules/storageServer/var/Playlist.php | 20 +- .../modules/storageServer/var/Renderer.php | 2 +- .../src/modules/storageServer/var/Restore.php | 2 +- .../storageServer/var/SmilPlaylist.php | 2 +- .../modules/storageServer/var/Transport.php | 8 +- .../src/modules/storageServer/var/conf.php | 12 +- .../storageServer/var/cron/Crontab.php | 84 +++--- .../storageServer/var/install/installMain.php | 4 + 18 files changed, 266 insertions(+), 221 deletions(-) diff --git a/campcaster/src/modules/alib/var/M2tree.php b/campcaster/src/modules/alib/var/M2tree.php index 9f9afc027..ce6ad71e4 100644 --- a/campcaster/src/modules/alib/var/M2tree.php +++ b/campcaster/src/modules/alib/var/M2tree.php @@ -326,8 +326,8 @@ class M2tree { { global $CC_CONFIG; global $CC_DBC; - if ( ($name == '') && is_null($parId)) { - $name = $CC_CONFIG['RootNode']; + if ($name == '') { + return null; } $escapedName = pg_escape_string($name); $parcond = (is_null($parId) ? "parid is null" : diff --git a/campcaster/src/modules/alib/var/Subjects.php b/campcaster/src/modules/alib/var/Subjects.php index c9eb8a4ba..f555454c4 100644 --- a/campcaster/src/modules/alib/var/Subjects.php +++ b/campcaster/src/modules/alib/var/Subjects.php @@ -27,7 +27,7 @@ class Subjects { /* ======================================================= public methods */ /** - * Add new subject + * Add new subject (a.k.a. "user") * * @param string $p_login * @param string $p_pass @@ -359,6 +359,9 @@ class Subjects { public static function IsGroup($gid) { global $CC_CONFIG, $CC_DBC; + if (empty($gid)) { + return FALSE; + } $sql = "SELECT type FROM ".$CC_CONFIG['subjTable'] ." WHERE id='$gid'"; $r = $CC_DBC->getOne($sql); diff --git a/campcaster/src/modules/htmlUI/var/localizer/index.php b/campcaster/src/modules/htmlUI/var/localizer/index.php index 20093a3b2..8a6e544ab 100644 --- a/campcaster/src/modules/htmlUI/var/localizer/index.php +++ b/campcaster/src/modules/htmlUI/var/localizer/index.php @@ -1,10 +1,10 @@ "; if ($g_localizerConfig['MAINTENANCE']) { - include 'maintenance.php'; + include 'maintenance.php'; } switch ($action) { - case 'translate': - require_once("translate.php"); + case 'translate': + require_once("translate.php"); translationForm($_REQUEST); break; - + case 'save_translation': $targetLanguageId = Input::Get('localizer_target_language'); $data = Input::Get('data', 'array'); Localizer::ModifyStrings($prefix, $targetLanguageId, $data); // Localizer strings are changed -> reload files Localizer::LoadLanguageFiles('globals', $langCode); - Localizer::LoadLanguageFiles('localizer', $langCode); - require_once("translate.php"); + Localizer::LoadLanguageFiles('localizer', $langCode); + require_once("translate.php"); translationForm($_REQUEST); break; - + case 'remove_string': $deleteMe = Input::Get('string', 'string'); Localizer::RemoveString($prefix, $deleteMe); - require_once("translate.php"); + require_once("translate.php"); translationForm($_REQUEST); break; - + case 'move_string': $pos1 = Input::Get('pos1', 'int'); $pos2 = Input::Get('pos2', 'int'); Localizer::MoveString($prefix, $pos1, $pos2); - require_once("translate.php"); + require_once("translate.php"); translationForm($_REQUEST); break; - + case 'add_missing_translation_strings': $missingStrings = Localizer::FindMissingStrings($prefix); if (count($missingStrings) > 0) { Localizer::AddStringAtPosition($prefix, 0, $missingStrings); } - require_once("translate.php"); + require_once("translate.php"); translationForm($_REQUEST); break; - + case 'delete_unused_translation_strings': $unusedStrings = Localizer::FindUnusedStrings($prefix); if (count($unusedStrings) > 0) { Localizer::RemoveString($prefix, $unusedStrings); } - require_once("translate.php"); + require_once("translate.php"); translationForm($_REQUEST); break; - + //case 'add_string': // $pos = Input::Get('pos'); // if ($pos == 'begin') { @@ -100,7 +100,7 @@ switch ($action) { // } // } // // skip if all was unset above - // if (count($_REQUEST['newKey'])) { + // if (count($_REQUEST['newKey'])) { // Localizer::AddStringAtPosition($base, $directory, $pos, $_REQUEST['newKey']); // } // diff --git a/campcaster/src/modules/htmlUI/var/ui_playlist.class.php b/campcaster/src/modules/htmlUI/var/ui_playlist.class.php index ff578649f..77182bf8b 100644 --- a/campcaster/src/modules/htmlUI/var/ui_playlist.class.php +++ b/campcaster/src/modules/htmlUI/var/ui_playlist.class.php @@ -97,7 +97,8 @@ class uiPlaylist } return FALSE; } - if (($userid = $this->Base->gb->playlistIsAvailable($plid, $this->Base->sessid)) !== TRUE) { + $userid = $this->Base->gb->playlistIsAvailable($plid, $this->Base->sessid); + if ($userid !== TRUE) { if (UI_WARNING) { $this->Base->_retMsg('Playlist has been locked by "$1".', Subjects::GetSubjName($userid)); } diff --git a/campcaster/src/modules/htmlUI/var/ui_subjects.class.php b/campcaster/src/modules/htmlUI/var/ui_subjects.class.php index 58425783f..07436f33e 100644 --- a/campcaster/src/modules/htmlUI/var/ui_subjects.class.php +++ b/campcaster/src/modules/htmlUI/var/ui_subjects.class.php @@ -89,7 +89,9 @@ class uiSubjects return FALSE; } - if (PEAR::isError($res = $this->Base->gb->addSubj($request['login'], ($request['passwd']==='' ? NULL : $request['passwd'])))) { + $tmpPassword = $request['passwd']==='' ? NULL : $request['passwd']; + $res = $this->Base->gb->addSubj($request['login'], $tmpPassword); + if (PEAR::isError($res)) { $this->Base->_retMsg($res->getMessage()); return FALSE; } diff --git a/campcaster/src/modules/storageServer/var/AccessRecur.php b/campcaster/src/modules/storageServer/var/AccessRecur.php index 75d7887fb..13dc399a5 100644 --- a/campcaster/src/modules/storageServer/var/AccessRecur.php +++ b/campcaster/src/modules/storageServer/var/AccessRecur.php @@ -34,7 +34,7 @@ class AccessRecur { } $plRes = $r; $r = StoredFile::RecallByGunid($plid); - if (PEAR::isError($r)) { + if (is_null($r) || PEAR::isError($r)) { return $r; } $ac = $r; diff --git a/campcaster/src/modules/storageServer/var/Backup.php b/campcaster/src/modules/storageServer/var/Backup.php index 34d40dd1f..1e399281f 100755 --- a/campcaster/src/modules/storageServer/var/Backup.php +++ b/campcaster/src/modules/storageServer/var/Backup.php @@ -302,7 +302,7 @@ class Backup $gunid = $item['gunid']; // get a stored file object of this gunid $sf = StoredFile::RecallByGunid($gunid); - if (PEAR::isError($sf)) { + if (is_null($sf) || PEAR::isError($sf)) { return $sf; } $lid = BasicStor::IdFromGunid($gunid); diff --git a/campcaster/src/modules/storageServer/var/BasicStor.php b/campcaster/src/modules/storageServer/var/BasicStor.php index 7842b9966..71bca6b2f 100644 --- a/campcaster/src/modules/storageServer/var/BasicStor.php +++ b/campcaster/src/modules/storageServer/var/BasicStor.php @@ -129,7 +129,7 @@ class BasicStor { case "playlist": case "webstream": $storedFile = StoredFile::Recall($id); - if (PEAR::isError($storedFile)) { + if (is_null($storedFile) || PEAR::isError($storedFile)) { // catch nonerror exception: //if($storedFile->getCode() != GBERR_FOBJNEX) return $storedFile; @@ -233,7 +233,7 @@ class BasicStor { public function bsReplaceFile($id, $localFilePath, $metadataFilePath, $mdataLoc='file') { $storedFile = StoredFile::Recall($id); - if (PEAR::isError($storedFile)) { + if (is_null($storedFile) || PEAR::isError($storedFile)) { return $storedFile; } if (!empty($metadataFilePath) && @@ -280,7 +280,7 @@ class BasicStor { case "playlist": case "webstream": $storedFile = StoredFile::Recall($id); - if (PEAR::isError($storedFile)) { + if (is_null($storedFile) || PEAR::isError($storedFile)) { return $storedFile; } if (is_null($did)) { @@ -514,7 +514,7 @@ class BasicStor { public function bsOpenDownload($id, $part='media', $parent='0') { $storedFile = StoredFile::Recall($id); - if (PEAR::isError($storedFile)) { + if (is_null($storedFile) || PEAR::isError($storedFile)) { return $storedFile; } $gunid = $storedFile->gunid; @@ -666,7 +666,7 @@ class BasicStor { } else { // Remember the MD5 sum $storedFile = StoredFile::RecallByToken($token); - if (!PEAR::isError($storedFile)) { + if (!is_null($storedFile) && !PEAR::isError($storedFile)) { $storedFile->setMd5($md5sum); } else { # $error = $storedFile; @@ -800,7 +800,7 @@ class BasicStor { public function bsReplaceMetadata($id, $mdata, $mdataLoc='file') { $storedFile = StoredFile::Recall($id); - if (PEAR::isError($storedFile)) { + if (is_null($storedFile) || PEAR::isError($storedFile)) { return $storedFile; } return $storedFile->setMetadata($mdata, $mdataLoc); @@ -817,7 +817,7 @@ class BasicStor { public function bsGetMetadata($id) { $storedFile = StoredFile::Recall($id); - if (PEAR::isError($storedFile)) { + if (is_null($storedFile) || PEAR::isError($storedFile)) { return $storedFile; } return $storedFile->getMetadata(); @@ -902,7 +902,7 @@ class BasicStor { return null; } $storedFile = StoredFile::Recall($id); - if (PEAR::isError($storedFile) || is_null($storedFile)) { + if (is_null($storedFile) || PEAR::isError($storedFile)) { return $storedFile; } if (is_null($category)) { @@ -948,7 +948,7 @@ class BasicStor { $storedFile =& $id; } else { $storedFile = StoredFile::Recall($id); - if (PEAR::isError($storedFile)) { + if (is_null($storedFile) || PEAR::isError($storedFile)) { return $storedFile; } } @@ -1011,7 +1011,7 @@ class BasicStor { $values = array($values); } $storedFile = StoredFile::Recall($id); - if (PEAR::isError($storedFile)) { + if (is_null($storedFile) || PEAR::isError($storedFile)) { return $storedFile; } foreach ($values as $category => $oneValue) { @@ -1023,7 +1023,7 @@ class BasicStor { } if ($regen) { $storedFile = StoredFile::Recall($id); - if (PEAR::isError($storedFile)) { + if (is_null($storedFile) || PEAR::isError($storedFile)) { return $storedFile; } $r = $storedFile->md->regenerateXmlFile(); @@ -1149,7 +1149,7 @@ class BasicStor { $gunids = array(); foreach ($plids as $plid) { $pl = StoredFile::RecallByGunid($plid); - if (PEAR::isError($pl)) { + if (is_null($pl) || PEAR::isError($pl)) { return $pl; } if ($withContent) { @@ -1177,7 +1177,7 @@ class BasicStor { } foreach ($gunids as $i => $it) { $storedFile = StoredFile::RecallByGunid($it['gunid']); - if (PEAR::isError($storedFile)) { + if (is_null($storedFile) || PEAR::isError($storedFile)) { return $storedFile; } $MDfname = $storedFile->md->getFileName(); @@ -1502,7 +1502,7 @@ class BasicStor { public function bsAnalyzeFile($id) { $storedFile = StoredFile::Recall($id); - if (PEAR::isError($storedFile)) { + if (is_null($storedFile) || PEAR::isError($storedFile)) { return $storedFile; } $ia = $storedFile->analyzeFile(); @@ -1586,6 +1586,9 @@ class BasicStor { } else { $storedFile = StoredFile::Recall($id); } + if (is_null($storedFile)) { + return $storedFile; + } if (PEAR::isError($storedFile)) { // catch some exceptions switch ($storedFile->getCode()) { @@ -1649,7 +1652,7 @@ class BasicStor { public function addSubj($login, $pass=NULL, $realname='') { global $CC_CONFIG; - $uid = Subjects::addSubj($login, $pass, $realname); + $uid = Subjects::AddSubj($login, $pass, $realname); if (PEAR::isError($uid)) { return $uid; } @@ -1671,22 +1674,22 @@ class BasicStor { if (PEAR::isError($res)) { return $res; } - $pfid = BasicStor::bsCreateFolder($fid, 'public'); - if (PEAR::isError($pfid)) { - return $pfid; - } - $res = Alib::AddPerm($uid, '_all', $pfid, 'A'); - if (PEAR::isError($res)) { - return $res; - } - $allGrId = Subjects::GetSubjId($CC_CONFIG['AllGr']); - if (PEAR::isError($allGrId)) { - return $allGrId; - } - $res = Alib::AddPerm($allGrId, 'read', $pfid, 'A'); - if (PEAR::isError($res)) { - return $res; - } + //$pfid = BasicStor::bsCreateFolder($fid, 'public'); + //if (PEAR::isError($pfid)) { + // return $pfid; + //} + //$res = Alib::AddPerm($uid, '_all', $pfid, 'A'); + //if (PEAR::isError($res)) { + // return $res; + //} + //$allGrId = Subjects::GetSubjId($CC_CONFIG['AllGr']); + //if (PEAR::isError($allGrId)) { + // return $allGrId; + //} + //$res = Alib::AddPerm($allGrId, 'read', $pfid, 'A'); + //if (PEAR::isError($res)) { + // return $res; + //} } } return $uid; @@ -1959,7 +1962,7 @@ class BasicStor { } } $storedFile = StoredFile::RecallByGunid($p_playlistId); - if (PEAR::isError($storedFile)) { + if (is_null($storedFile) || PEAR::isError($storedFile)) { return $storedFile; } $state = $storedFile->getState(); @@ -1986,7 +1989,7 @@ class BasicStor { public function isEdited($p_playlistId) { $storedFile = StoredFile::RecallByGunid($p_playlistId); - if (PEAR::isError($storedFile)) { + if (is_null($storedFile) || PEAR::isError($storedFile)) { return $storedFile; } if (!$storedFile->isEdited($p_playlistId)) { @@ -2016,7 +2019,7 @@ class BasicStor { case "playlist": case "webstream": $storedFile = StoredFile::Recall($id); - if (PEAR::isError($storedFile)) { + if (is_null($storedFile) || PEAR::isError($storedFile)) { return $storedFile; } $ac2 = StoredFile::CopyOf($storedFile, $nid); @@ -2043,7 +2046,7 @@ class BasicStor { case "playlist": case "webstream": $storedFile = StoredFile::Recall($id); - if (PEAR::isError($storedFile)) { + if (is_null($storedFile) || PEAR::isError($storedFile)) { return $storedFile; } if ($storedFile->isEdited()) { @@ -2066,8 +2069,7 @@ class BasicStor { /** - * Optionaly remove virtual file with the same name and add new one.
- * Redefined from parent class. + * Add a virtual file. * * @return int * Database ID of the object. @@ -2078,7 +2080,6 @@ class BasicStor { if (PEAR::isError($exid)) { return $exid; } - //if(!is_null($exid)){ BasicStor::RemoveObj($exid); } $name2 = $name; for ( ; $xid = M2tree::GetObjId($name2, $parid), @@ -2333,93 +2334,117 @@ class BasicStor { { global $CC_CONFIG; $this->rootId = M2tree::GetRootNode(); - $this->storId = BasicStor::AddObj('StorageRoot', 'Folder', $this->rootId); - $this->wd = $this->storId; - if (!Subjects::GetSubjId('root')) { - if ($p_verbose) { - echo " * Creating user 'root'..."; - } - // Create user 'root'. - $rootUid = Subjects::AddSubj('root', $CC_CONFIG['tmpRootPass']); - $res = Alib::AddPerm($rootUid, '_all', $this->rootId, 'A'); - if (PEAR::isError($res)) { - return $res; - } - $res = Alib::AddPerm($rootUid, 'subjects', $this->rootId, 'A'); - if (PEAR::isError($res)) { - return $res; - } - $allid = Subjects::AddSubj($CC_CONFIG['AllGr']); - if (PEAR::isError($allid)) { - return $allid; - } - Subjects::AddSubjectToGroup('root', $CC_CONFIG['AllGr']); - Alib::AddPerm($allid, 'read', $this->rootId, 'A'); - $admid = Subjects::AddSubj($CC_CONFIG['AdminsGr']); - if (PEAR::isError($admid)) { - return $admid; - } - $r = Subjects::AddSubjectToGroup('root', $CC_CONFIG['AdminsGr']); - if (PEAR::isError($r)) { - return $r; - } - $res = Alib::AddPerm($admid, '_all', $this->rootId, 'A'); - if (PEAR::isError($res)) { - return $res; - } - if ($p_verbose) { - echo "done.\n"; - } - } elseif ($p_verbose) { - echo " * Skipping: user 'root' already exists.\n"; - } - if ($p_verbose) { - echo " * Creating storage root directory..."; - } - $fid = BasicStor::bsCreateFolder($this->storId, 'root'); - if (PEAR::isError($fid)) { - return $fid; - } - if ($p_verbose) { + // Check if the StorageRoot already exists, if not, create it. + $storageRootId = M2tree::GetObjId('StorageRoot', $this->rootId); + if (is_null($storageRootId)) { + echo " * Creating 'StorageRoot' node..."; + $this->storId = BasicStor::AddObj('StorageRoot', 'Folder', $this->rootId); + $this->wd = $this->storId; echo "done.\n"; + } else { + echo " * Skipping: StorageRoot already exists.\n"; } - if ($CC_CONFIG['useTrash']) { - if ($p_verbose) { - echo " * Creating trashcan..."; - } - $tfid = BasicStor::bsCreateFolder($this->storId, $CC_CONFIG["TrashName"]); - if (PEAR::isError($tfid)) { - return $tfid; - } - if ($p_verbose) { - echo "done.\n"; - } - } - if (!$CC_CONFIG['isArchive']) { - if (!Subjects::GetSubjId('scheduler')) { - if ($p_verbose) { - echo " * Creating user 'scheduler'..."; + + // Create the Admin group + if (!empty($CC_CONFIG['AdminsGr'])) { + if (!Subjects::GetSubjId($CC_CONFIG['AdminsGr'])) { + echo " * Creating group '".$CC_CONFIG['AdminsGr']."'..."; + // Add the admin group + $admid = Subjects::AddSubj($CC_CONFIG['AdminsGr']); + if (PEAR::isError($admid)) { + return $admid; } + + // Add the "all" permission to the "admin" group + $res = Alib::AddPerm($admid, '_all', $this->rootId, 'A'); + if (PEAR::isError($res)) { + return $res; + } + echo "done.\n"; + } else { + echo " * Skipping: group already exists: '".$CC_CONFIG['AdminsGr']."'\n"; + } + } + + // Add the "all" group + if (!empty($CC_CONFIG['AllGr'])) { + if (!Subjects::GetSubjId($CC_CONFIG['AllGr'])) { + echo " * Creating group '".$CC_CONFIG['AllGr']."'..."; + $allid = Subjects::AddSubj($CC_CONFIG['AllGr']); + if (PEAR::isError($allid)) { + return $allid; + } + + // Add the "read" permission to the "all" group. + Alib::AddPerm($allid, 'read', $this->rootId, 'A'); + echo "done.\n"; + } else { + echo " * Skipping: group already exists: '".$CC_CONFIG['AllGr']."'\n"; + } + } + + // Add the "Station Preferences" group + if (!empty($CC_CONFIG['StationPrefsGr'])) { + if (!Subjects::GetSubjId('scheduler')) { + echo " * Creating group '".$CC_CONFIG['StationPrefsGr']."'..."; $stPrefGr = Subjects::AddSubj($CC_CONFIG['StationPrefsGr']); if (PEAR::isError($stPrefGr)) { return $stPrefGr; } Subjects::AddSubjectToGroup('root', $CC_CONFIG['StationPrefsGr']); - // Create the user named 'scheduler'. - Subjects::AddSubj('scheduler', $CC_CONFIG['schedulerPass']); - $res = Alib::AddPerm($rootUid, 'read', $this->rootId, 'A'); - if (PEAR::isError($res)) { - return $res; - } - $r = Subjects::AddSubjectToGroup('scheduler', $CC_CONFIG['AllGr']); - if ($p_verbose) { - echo "done.\n"; - } - } else if ($p_verbose) { - echo " * Skipping: user 'scheduler' already exists.\n"; + echo "done.\n"; + } else { + echo " * Skipping: group already exists: '".$CC_CONFIG['StationPrefsGr']."'\n"; } } + + // Add the root user if it doesnt exist yet. + $rootUid = Subjects::GetSubjId('root'); + if (!$rootUid) { + echo " * Creating user 'root'..."; + $rootUid = $this->addSubj("root", $CC_CONFIG['tmpRootPass']); + if (PEAR::isError($rootUid)) { + return $rootUid; + } + + // Add root user to the admin group + $r = Subjects::AddSubjectToGroup('root', $CC_CONFIG['AdminsGr']); + if (PEAR::isError($r)) { + return $r; + } + echo "done.\n"; + } else { + echo " * Skipping: user already exists: 'root'\n"; + } + + if (!empty($CC_CONFIG['TrashName'])) { + $trashId = M2tree::GetObjId($CC_CONFIG['TrashName'], $this->storId); + if (!$trashId) { + echo " * Creating trash can..."; + $tfid = BasicStor::bsCreateFolder($this->storId, $CC_CONFIG["TrashName"]); + if (PEAR::isError($tfid)) { + return $tfid; + } + echo "done.\n"; + } else { + echo " * Skipping: trash can already exists.\n"; + } + } + + // Create the user named 'scheduler'. + if (!Subjects::GetSubjId('scheduler')) { + echo " * Creating user 'scheduler'..."; + Subjects::AddSubj('scheduler', $CC_CONFIG['schedulerPass']); + $res = Alib::AddPerm($rootUid, 'read', $this->rootId, 'A'); + if (PEAR::isError($res)) { + return $res; + } + $r = Subjects::AddSubjectToGroup('scheduler', $CC_CONFIG['AllGr']); + echo "done.\n"; + } else { + echo " * Skipping: user already exists: 'scheduler'\n"; + } } diff --git a/campcaster/src/modules/storageServer/var/GreenBox.php b/campcaster/src/modules/storageServer/var/GreenBox.php index e3432d78b..9363e0c43 100644 --- a/campcaster/src/modules/storageServer/var/GreenBox.php +++ b/campcaster/src/modules/storageServer/var/GreenBox.php @@ -346,7 +346,7 @@ class GreenBox extends BasicStor { return $res; } $storedFile = StoredFile::Recall($id); - if (PEAR::isError($storedFile)) { + if (is_null($storedFile) || PEAR::isError($storedFile)) { return $storedFile; } $arr = $storedFile->md->genPhpArray(); @@ -596,7 +596,7 @@ class GreenBox extends BasicStor { { $gunid = BasicStor::GunidFromId($id); $pl = StoredFile::Recall($id); - if (PEAR::isError($pl)) { + if (is_null($pl) || PEAR::isError($pl)) { return $pl; } $gunid = $pl->gunid; @@ -643,7 +643,7 @@ class GreenBox extends BasicStor { return $gunid; } $storedFile = StoredFile::RecallByGunid($gunid); - if (PEAR::isError($storedFile)) { + if (is_null($storedFile) || PEAR::isError($storedFile)) { return $storedFile; } $r = $storedFile->md->regenerateXmlFile(); @@ -678,9 +678,9 @@ class GreenBox extends BasicStor { public function addAudioClipToPlaylist($token, $acId, $sessid, $fadeIn=NULL, $fadeOut=NULL, $length=NULL, $pause=NULL) { - require_once"Playlist.php"; + require_once("Playlist.php"); $pl = StoredFile::RecallByToken($token); - if (PEAR::isError($pl)) { + if (is_null($pl) || PEAR::isError($pl)) { return $pl; } $acGunid = BasicStor::GunidFromId($acId); @@ -721,7 +721,7 @@ class GreenBox extends BasicStor { { require_once("Playlist.php"); $pl = StoredFile::RecallByToken($token); - if (PEAR::isError($pl)) { + if (is_null($pl) || PEAR::isError($pl)) { return $pl; } $res = $pl->delAudioClip($plElGunid); @@ -756,7 +756,7 @@ class GreenBox extends BasicStor { { require_once("Playlist.php"); $pl = StoredFile::RecallByToken($token); - if (PEAR::isError($pl)) { + if (is_null($pl) || PEAR::isError($pl)) { return $pl; } $res = $pl->changeFadeInfo($plElGunid, $fadeIn, $fadeOut); @@ -792,7 +792,7 @@ class GreenBox extends BasicStor { { require_once("Playlist.php"); $pl = StoredFile::RecallByToken($token); - if (PEAR::isError($pl)) { + if (is_null($pl) || PEAR::isError($pl)) { return $pl; } $res = $pl->moveAudioClip($plElGunid, $newPos); @@ -872,7 +872,7 @@ class GreenBox extends BasicStor { { require_once("Playlist.php"); $pl = StoredFile::RecallByGunid($plid); - if (PEAR::isError($pl)) { + if (is_null($pl) || PEAR::isError($pl)) { return $pl; } $res = $pl->displayPlaylistClipAtOffset($offset, $distance); diff --git a/campcaster/src/modules/storageServer/var/LocStor.php b/campcaster/src/modules/storageServer/var/LocStor.php index 567e4bd57..d48747765 100644 --- a/campcaster/src/modules/storageServer/var/LocStor.php +++ b/campcaster/src/modules/storageServer/var/LocStor.php @@ -132,7 +132,7 @@ class LocStor extends BasicStor { protected function storeAudioClipClose($sessid, $token) { $storedFile =& StoredFile::RecallByToken($token); - if (PEAR::isError($storedFile)) { + if (is_null($storedFile) || PEAR::isError($storedFile)) { return $storedFile; } $arr = $this->bsClosePut($token); @@ -198,7 +198,7 @@ class LocStor extends BasicStor { return $gunid; } $storedFile =& StoredFile::RecallByGunid($gunid); - if (PEAR::isError($storedFile)) { + if (is_null($storedFile) || PEAR::isError($storedFile)) { return $storedFile; } $oid = $storedFile->getId(); @@ -225,7 +225,7 @@ class LocStor extends BasicStor { public function accessRawAudioData($sessid, $gunid, $parent='0') { $storedFile =& StoredFile::RecallByGunid($gunid); - if (PEAR::isError($storedFile)) { + if (is_null($storedFile) || PEAR::isError($storedFile)) { return $storedFile; } if (($res = BasicStor::Authorize('read', $storedFile->getId(), $sessid)) !== TRUE) { @@ -246,7 +246,7 @@ class LocStor extends BasicStor { public function releaseRawAudioData($sessid, $token) { $storedFile =& StoredFile::RecallByToken($token); - if (PEAR::isError($storedFile)) { + if (is_null($storedFile) || PEAR::isError($storedFile)) { return $storedFile; } return $storedFile->releaseRawMediaData($token); @@ -353,7 +353,7 @@ class LocStor extends BasicStor { protected function getAudioClip($sessid, $gunid) { $storedFile =& StoredFile::RecallByGunid($gunid); - if (PEAR::isError($storedFile)) { + if (is_null($storedFile) || PEAR::isError($storedFile)) { return $storedFile; } if (($res = BasicStor::Authorize('read', $storedFile->getId(), $sessid)) !== TRUE) { @@ -493,7 +493,7 @@ class LocStor extends BasicStor { return $ex; } $storedFile =& StoredFile::RecallByGunid($gunid); - if (PEAR::isError($storedFile)) { + if (is_null($storedFile) || PEAR::isError($storedFile)) { return $storedFile; } return $storedFile->exists(); @@ -567,7 +567,7 @@ class LocStor extends BasicStor { protected function updateAudioClipMetadata($sessid, $gunid, $metadata) { $storedFile =& StoredFile::RecallByGunid($gunid); - if (PEAR::isError($storedFile)) { + if (is_null($storedFile) || PEAR::isError($storedFile)) { return $storedFile; } if (($res = BasicStor::Authorize('write', $storedFile->getId(), $sessid)) !== TRUE) { @@ -670,7 +670,7 @@ class LocStor extends BasicStor { ); } $storedFile =& StoredFile::RecallByGunid($playlistId); - if (PEAR::isError($storedFile)) { + if (is_null($storedFile) || PEAR::isError($storedFile)) { return $storedFile; } $id = $storedFile->getId(); @@ -709,7 +709,7 @@ class LocStor extends BasicStor { return $playlistId; } $storedFile =& StoredFile::RecallByGunid($playlistId); - if (PEAR::isError($storedFile)) { + if (is_null($storedFile) || PEAR::isError($storedFile)) { return $storedFile; } $res = $storedFile->setMetadata($newPlaylist, 'string', 'playlist'); @@ -741,7 +741,7 @@ class LocStor extends BasicStor { return $gunid; } $storedFile =& StoredFile::RecallByGunid($gunid); - if (PEAR::isError($storedFile)) { + if (is_null($storedFile) || PEAR::isError($storedFile)) { return $storedFile; } $id = $storedFile->getId(); @@ -785,7 +785,7 @@ class LocStor extends BasicStor { ); } $storedFile =& StoredFile::RecallByGunid($playlistId); - if (PEAR::isError($storedFile)) { + if (is_null($storedFile) || PEAR::isError($storedFile)) { return $storedFile; } if (($res = BasicStor::Authorize('write', $storedFile->getId(), $sessid)) !== TRUE) { diff --git a/campcaster/src/modules/storageServer/var/Playlist.php b/campcaster/src/modules/storageServer/var/Playlist.php index 73c64cc54..a31695a3a 100644 --- a/campcaster/src/modules/storageServer/var/Playlist.php +++ b/campcaster/src/modules/storageServer/var/Playlist.php @@ -543,7 +543,7 @@ class Playlist extends StoredFile { switch ($el['type']) { case "playlist": $pl = StoredFile::RecallByGunid($acGunid); - if (PEAR::isError($pl)) { + if (is_null($pl) || PEAR::isError($pl)) { return $pl; } if ($dd > 0) { @@ -620,7 +620,7 @@ class Playlist extends StoredFile { switch ($el['type']) { case "playlist": $pl = StoredFile::RecallByGunid($acGunid); - if (PEAR::isError($pl)) { + if (is_null($pl) || PEAR::isError($pl)) { return $pl; } $res2 = $pl->export(); @@ -692,7 +692,7 @@ class Playlist extends StoredFile { return TRUE; } $pl = StoredFile::RecallByGunid($insGunid); - if (PEAR::isError($pl)) { + if (is_null($pl) || PEAR::isError($pl)) { return $pl; } $arr = $pl->md->genPhpArray(); @@ -866,7 +866,7 @@ class Playlist extends StoredFile { private function getAudioClipInfo($acId) { $ac = StoredFile::Recall($acId); - if (PEAR::isError($ac)) { + if (is_null($ac) || PEAR::isError($ac)) { return $ac; } $acGunid = $ac->gunid; @@ -1390,7 +1390,7 @@ class PlaylistElementExport { case "playlist": $gunid = $ac['attrs']['id']; $pl2 = StoredFile::RecallByGunid($gunid); - if (PEAR::isError($pl2)) { + if (is_null($pl2) || PEAR::isError($pl2)) { return $pl2; } $r = $pl2->outputToSmil(FALSE); @@ -1463,7 +1463,7 @@ class PlaylistElementExport { case "playlist": $gunid = $ac['attrs']['id']; $pl2 = StoredFile::RecallByGunid($gunid); - if (PEAR::isError($pl2)) { + if (is_null($pl2) || PEAR::isError($pl2)) { return $pl2; } $r = $pl2->outputToM3u(FALSE); @@ -1507,7 +1507,7 @@ class PlaylistElementExport { case "playlist": $gunid = $ac['attrs']['id']; $pl2 = StoredFile::RecallByGunid($gunid); - if (PEAR::isError($pl2)) { + if (is_null($pl2) || PEAR::isError($pl2)) { return $pl2; } $r = $pl2->outputToRss(FALSE); @@ -1558,7 +1558,7 @@ class PlaylistAudioClipExport { $gunid = $plac['attrs']['id']; $ac = StoredFile::RecallByGunid($gunid); - if (PEAR::isError($ac)) { + if (is_null($ac) || PEAR::isError($ac)) { return $ac; } $RADext = $ac->getFileExtension(); @@ -1578,7 +1578,7 @@ class PlaylistAudioClipExport { $gunid = $plac['attrs']['id']; $ac = StoredFile::RecallByGunid($gunid); - if (PEAR::isError($ac)) { + if (is_null($ac) || PEAR::isError($ac)) { return $ac; } $RADext = $ac->getFileExtension(); @@ -1597,7 +1597,7 @@ class PlaylistAudioClipExport { $gunid = $plac['attrs']['id']; $ac = StoredFile::RecallByGunid($gunid); - if (PEAR::isError($ac)) { + if (is_null($ac) || PEAR::isError($ac)) { return $ac; } $RADext = $ac->getFileExtension(); diff --git a/campcaster/src/modules/storageServer/var/Renderer.php b/campcaster/src/modules/storageServer/var/Renderer.php index c68424930..e03f94b89 100644 --- a/campcaster/src/modules/storageServer/var/Renderer.php +++ b/campcaster/src/modules/storageServer/var/Renderer.php @@ -38,7 +38,7 @@ class Renderer global $CC_CONFIG; // recall playlist: $pl = StoredFile::RecallByGunid($plid); - if (PEAR::isError($pl)) { + if (is_null($pl) || PEAR::isError($pl)) { return $pl; } // smil export: diff --git a/campcaster/src/modules/storageServer/var/Restore.php b/campcaster/src/modules/storageServer/var/Restore.php index 94412f32f..f4e9263bd 100644 --- a/campcaster/src/modules/storageServer/var/Restore.php +++ b/campcaster/src/modules/storageServer/var/Restore.php @@ -333,7 +333,7 @@ class Restore { } } $ac = StoredFile::RecallByGunid($gunid); - if (PEAR::isError($ac)) { + if (is_null($ac) || PEAR::isError($ac)) { return $ac; } $res = $ac->setState('ready'); diff --git a/campcaster/src/modules/storageServer/var/SmilPlaylist.php b/campcaster/src/modules/storageServer/var/SmilPlaylist.php index bf4404ec2..0097bdae1 100644 --- a/campcaster/src/modules/storageServer/var/SmilPlaylist.php +++ b/campcaster/src/modules/storageServer/var/SmilPlaylist.php @@ -263,7 +263,7 @@ class SmilPlaylistAudioElement { //break; default: $ac = StoredFile::RecallByGunid($gunid); - if (PEAR::isError($ac)) { + if (is_null($ac) || PEAR::isError($ac)) { return $ac; } $r = $ac->md->getMetadataElement('dcterms:extent'); diff --git a/campcaster/src/modules/storageServer/var/Transport.php b/campcaster/src/modules/storageServer/var/Transport.php index 2bfb70356..d1d8cf6eb 100644 --- a/campcaster/src/modules/storageServer/var/Transport.php +++ b/campcaster/src/modules/storageServer/var/Transport.php @@ -295,7 +295,7 @@ class Transport case "audioclip": case "webstream": $storedFile = StoredFile::RecallByGunid($gunid); - if (PEAR::isError($storedFile)) { + if (is_null($storedFile) || PEAR::isError($storedFile)) { return $storedFile; } // handle metadata: @@ -333,7 +333,7 @@ class Transport $plid = $gunid; require_once("Playlist.php"); $pl = StoredFile::RecallByGunid($plid); - if (PEAR::isError($pl)) { + if (is_null($pl) || PEAR::isError($pl)) { return $pl; } $fname = $pl->getName(); @@ -1107,7 +1107,7 @@ class Transport if ($state2 == 'paused' || $state2 == 'closed' ) { return TRUE; } - + // status 18 - Partial file. Only a part of the file was transported. // status 28 - Timeout. Too long/slow upload, try to resume next time rather. @@ -1202,7 +1202,7 @@ class Transport if ($state2 == 'paused' || $state2 == 'closed' ) { return TRUE; } - + // check consistency $size = filesize($row['localfile']); if ($size < $row['expectedsize']) { diff --git a/campcaster/src/modules/storageServer/var/conf.php b/campcaster/src/modules/storageServer/var/conf.php index 4b2873604..fab998de1 100644 --- a/campcaster/src/modules/storageServer/var/conf.php +++ b/campcaster/src/modules/storageServer/var/conf.php @@ -166,15 +166,17 @@ if (!is_null($this_file)) { } } -// make dirpaths better (without ../) +// make dirpaths better (without "../") foreach (array('storageDir', 'bufferDir', 'transDir', 'accessDir', 'pearPath', 'cronDir') as $d) { $rp = realpath($CC_CONFIG[$d]); // workaround for missing dirs - if ( $rp === FALSE ) { - mkdir( $CC_CONFIG[$d] ); - $rp = realpath($CC_CONFIG[$d]); +// if ( $rp === FALSE ) { +// mkdir( $CC_CONFIG[$d] ); +// $rp = realpath($CC_CONFIG[$d]); +// } + if ($rp) { + $CC_CONFIG[$d] = $rp; } - $CC_CONFIG[$d] = $rp; } ?> \ No newline at end of file diff --git a/campcaster/src/modules/storageServer/var/cron/Crontab.php b/campcaster/src/modules/storageServer/var/cron/Crontab.php index 8aa0523b3..26796593e 100755 --- a/campcaster/src/modules/storageServer/var/cron/Crontab.php +++ b/campcaster/src/modules/storageServer/var/cron/Crontab.php @@ -8,7 +8,8 @@ define('CRON_EMPTY', 4); /** * A class that interfaces with the crontab. (cjpa@audiophile.com) * - * This class lets you manipulate the crontab. It lets you add delete update entries easily. + * This class lets you manipulate a user's crontab. + * It lets you add delete update entries easily. * * @author $Author: $ * @version $Revision: $ @@ -70,9 +71,10 @@ class Crontab */ function readCrontab() { + // Hmmm...this line looks like it erases the crontab file. -Paul @exec("echo | crontab -u {$this->user} -", $crons, $return); @exec("crontab -u {$this->user} -l", $crons, $return); - if($return != 0){ + if ($return != 0) { return PEAR::raiseError("*** Can't read crontab ***\n". " Set crontab manually!\n"); } @@ -82,32 +84,28 @@ class Crontab $line = trim($line); // discarding all prepending spaces and tabs // empty lines.. - if (!$line) - { + if (!$line) { $this->crontabs[] = "empty line"; $this->linetypes[] = CRON_EMPTY; continue; } // checking if this is a comment - if ($line[0] == "#") - { + if ($line[0] == "#") { $this->crontabs[] = trim($line); $this->linetypes[] = CRON_COMMENT; continue; } // Checking if this is an assignment - if (ereg("(.*)=(.*)", $line, $assign)) - { + 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] == '@') - { + if ($line[0] == '@') { $this->crontabs[] = split("[ \t]", $line, 2); $this->linetypes[] = CRON_SPECIAL; continue; @@ -129,36 +127,34 @@ class Crontab $filename = ($DEBUG ? tempnam("$PATH/crons", "cron") : tempnam("/tmp", "cron")); $file = fopen($filename, "w"); - for ($i = 0; $i < count($this->linetypes); $i ++) - { - switch ($this->linetypes[$i]) - { - case CRON_COMMENT : + for ($i = 0; $i < count($this->linetypes); $i ++) { + switch ($this->linetypes[$i]) { + case CRON_COMMENT: $line = $this->crontabs[$i]; break; - case CRON_ASSIGN : + case CRON_ASSIGN: $line = $this->crontabs[$i][name]." = ".$this->crontabs[$i][value]; break; - case CRON_CMD : + case CRON_CMD: $line = implode(" ", $this->crontabs[$i]); break; - case CRON_SPECIAL : + case CRON_SPECIAL: $line = implode(" ", $this->crontabs[$i]); break; - case CRON_EMPTY : + case CRON_EMPTY: $line = "\n"; // an empty line in the crontab-file break; - default : - unset ($line); + 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){ + if ($line) { $r = @fwrite($file, $line."\n"); - if($r === FALSE){ + if($r === FALSE) { return PEAR::raiseError("*** Can't write crontab ***\n". " Set crontab manually!\n"); } @@ -166,27 +162,34 @@ class Crontab } fclose($file); - if ($DEBUG) + if ($DEBUG) { echo "DEBUGMODE: not updating crontab. writing to $filename instead.\n"; - else - { + } else { exec("crontab -u {$this->user} $filename", $returnar, $return); - if ($return != 0) + if ($return != 0) { echo "Error running crontab ($return). $filename not deleted\n"; - else + } 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 + * @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) @@ -195,10 +198,11 @@ class Crontab $this->linetypes[] = CRON_CMD; } + /** * Add a comment to the cron to the end of $this->crontabs * - * @param string $comment comment + * @param string $comment */ function addComment($comment) { @@ -206,6 +210,7 @@ class Crontab $this->linetypes[] = CRON_COMMENT; } + /** * Add a special command (check man 5 crontab for more information) * @@ -228,11 +233,12 @@ class Crontab $this->linetypes[] = CRON_SPECIAL; } + /** * Add an assignment (name = value) * - * @param string $name name of assingation - * @param string $value value + * @param string $name + * @param string $value */ function addAssign($name, $value) { @@ -240,6 +246,7 @@ class Crontab $this->linetypes[] = CRON_ASSIGN; } + /** * Delete a line from the arrays. * @@ -251,10 +258,11 @@ class Crontab unset ($this->linetypes[$index]); } + /** * Get all the lines of a certain type in an array * - * @param string $type linetype + * @param string $type */ function getByType($type) { diff --git a/campcaster/src/modules/storageServer/var/install/installMain.php b/campcaster/src/modules/storageServer/var/install/installMain.php index 07f26ba30..d8b4d7980 100644 --- a/campcaster/src/modules/storageServer/var/install/installMain.php +++ b/campcaster/src/modules/storageServer/var/install/installMain.php @@ -376,6 +376,10 @@ if (!camp_db_table_exists($CC_CONFIG['accessTable'])) { echo " * Inserting starting data into tables...\n"; $gb = new GreenBox(); $r = $gb->initData(true); +if (PEAR::isError($r)) { + echo "\n * ERROR: "; + print_r($r); +} //echo "done.\n"; //------------------------------------------------------------------------------