Enforce admin privileges

This commit is contained in:
2021-06-21 20:04:16 +02:00
parent 30a9dbc85c
commit 991edfe747
13 changed files with 215 additions and 117 deletions

View File

@@ -73,6 +73,8 @@ class Spot extends Main
{
//Install DB
$this->oDb->install();
$this->oUser->addUser('admin@admin.com', $this->oLang->getLanguage(), date_default_timezone_get());
}
public function syncPics() {
@@ -93,13 +95,14 @@ class Spot extends Main
Project::PROJ_TABLE => array('name', 'codename', 'active_from', 'active_to'),
self::POST_TABLE => array(Db::getId(Project::PROJ_TABLE), Db::getId(User::USER_TABLE), 'name', 'content', 'site_time', 'timezone'),
Media::MEDIA_TABLE => array(Db::getId(Project::PROJ_TABLE), 'filename', 'type', 'taken_on', 'posted_on', 'timezone', 'rotate', 'comment'),
User::USER_TABLE => array('name', 'email', 'gravatar', 'language', 'timezone', 'active'),
User::USER_TABLE => array('name', 'email', 'gravatar', 'language', 'timezone', 'active', 'clearance'),
self::MAP_TABLE => array('codename', 'geo_name', 'min_zoom', 'max_zoom', 'attribution'),
self::MAPPING_TABLE => array(Db::getId(self::MAP_TABLE) , Db::getId(Project::PROJ_TABLE))
),
'types' => array
(
'active' => "BOOLEAN",
'active' => "BOOLEAN DEFAULT ".User::USER_INACTIVE,
'clearance' => "TINYINT(1) DEFAULT ".User::CLEARANCE_USER,
'active_from' => "TIMESTAMP DEFAULT 0",
'active_to' => "TIMESTAMP DEFAULT 0",
'battery_state' => "VARCHAR(10)",
@@ -149,8 +152,14 @@ class Spot extends Main
);
}
public function getMainPage($asGlobalVars = array(), $sMainPage = 'index', $asMainPageTags=array())
public function getAppMainPage()
{
//Cache Page List
$asPages = array_diff($this->asMasks, array('email_update', 'email_conf'));
if(!$this->oUser->checkUserClearance(User::CLEARANCE_ADMIN)) {
$asPages = array_diff($asPages, array('admin', 'upload'));
}
return parent::getMainPage(
array(
'vars' => array(
@@ -166,7 +175,7 @@ class Spot extends Main
'default_timezone' => Settings::TIMEZONE
)
),
$sMainPage,
'index',
array(
'host_url' => $this->asContext['serv_name'],
'filepath_css' => self::addTimestampToFilePath('style/spot.css'),
@@ -176,10 +185,15 @@ class Spot extends Main
'filepath_js_jquery_mods' => self::addTimestampToFilePath('script/jquery.mods.js'),
'filepath_js_spot' => self::addTimestampToFilePath('script/spot.js'),
'filepath_js_lightbox' => self::addTimestampToFilePath('script/lightbox.js')
)
),
$asPages
);
}
public function checkUserClearance($iClearance) {
return $this->oUser->checkUserClearance($iClearance);
}
/* Managing projects */
public function setProjectId($iProjectId=0) {
@@ -188,6 +202,8 @@ class Spot extends Main
public function updateProject() {
$bNewMsg = false;
$bSuccess = true;
$sDesc = '';
//Update all feeds belonging to the project
$asFeeds = $this->oProject->getFeedIds();
@@ -227,8 +243,13 @@ class Spot extends Main
if($iPostCount == self::MAIL_CHUNK_SIZE) break;
}
$oEmail->send();
$bSuccess = $oEmail->send();
if(!$bSuccess) $sDesc = $oEmail->ErrorInfo;
else $sDesc = 'mail_sent';
}
else $sDesc = 'no_new_msg';
return self::getJsonResult($bSuccess, $sDesc);
}
public function genCronFile() {
@@ -303,9 +324,8 @@ class Spot extends Main
$this->oLang->setLanguage($this->oUser->getLang(), self::DEFAULT_LANG);
$asResult = $this->oUser->removeUser();
$sDesc = $asResult['desc'];
if($sDesc=='') $sDesc = $this->oLang->getTranslation('nl_unsubscribed');
return $sDesc;
$sDesc = explode(':', $asResult['desc'])[1];
return $this->oLang->getTranslation($sDesc);
}
private function getSpotMessages()
@@ -491,7 +511,8 @@ class Spot extends Main
$asData = array(
'project' => $this->oProject->getProjects(),
'feed' => $oFeed->getFeeds(),
'spot' => $oFeed->getSpots()
'spot' => $oFeed->getSpots(),
'user' => $this->oUser->getActiveUsersInfo()
);
foreach($asData['project'] as &$asProject) {
@@ -499,6 +520,8 @@ class Spot extends Main
$asProject['active_to'] = substr($asProject['active_to'], 0, 10);
}
foreach($asData['user'] as &$asUser) $asUser['id'] = $asUser[Db::getId(User::USER_TABLE)];
return self::getJsonResult(true, '', $asData);
}
@@ -587,10 +610,6 @@ class Spot extends Main
));
}
public function convertGpxToGeojson($sGeoFileName) {
return Converter::convertToGeoJson($sGeoFileName);
}
public static function decToDms($dValue, $sType) {
if($sType=='lat') $sDirection = ($dValue >= 0)?'N':'S'; //Latitude
else $sDirection = ($dValue >= 0)?'E':'W'; //Longitude