Files
databap/index.php
2019-12-08 10:50:09 +01:00

278 lines
8.2 KiB
PHP
Executable File

<?php
/*
Databap Project
http://git.lutran.fr/databap.git
Copyright (C) 2014 François Lutran
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses
*/
//load classes
ob_start();
require_once 'classmanagement.php';
$oClassManagement = new ClassManagement('databap');
//Global values
ToolBox::cleanPost($_POST);
ToolBox::cleanPost($_GET);
ToolBox::cleanPost($_REQUEST);
ToolBox::fixGlobalVars(isset($argv)?$argv:array());
//Global variables (reserved names) and default values
$sPage = isset($_GET['p'])?$_GET['p']:'welcome';
$sAction = isset($_GET['a'])?$_GET['a']:'';
$oUser = isset($_REQUEST['user'])?$_REQUEST['user']:'';
$sToken = isset($_REQUEST['auth_token'])?$_REQUEST['auth_token']:'';
$sOldToken = isset($_POST['old_auth_token'])?$_POST['old_auth_token']:'';
$sNewToken = isset($_POST['new_auth_token'])?$_POST['new_auth_token']:'';
$sContent = isset($_POST['content'])?$_POST['content']:'';
$sCategory = isset($_GET['cat'])?$_GET['cat']:'';
$sTitle = isset($_POST['title'])?$_POST['title']:'';
$sDescription = isset($_POST['description'])?$_POST['description']:'';
$sLink = isset($_REQUEST['link_escaped'])?$_REQUEST['link_escaped']:'';
$sKeyWords = isset($_REQUEST['keywords'])?$_REQUEST['keywords']:'';
$sMessage = isset($_POST['message'])?$_POST['message']:'';
$sChan = isset($_REQUEST['chan'])?$_REQUEST['chan']:'';
$asAttendees = isset($_REQUEST['attendees'])?$_REQUEST['attendees']:'';
$bFirstConn = isset($_GET['first_conn'])?$_GET['first_conn']:false;
$iMessageId = isset($_GET['message_id'])?$_GET['message_id']:0;
$oItemId = isset($_REQUEST['id'])?$_REQUEST['id']:0;
$sSystem = isset($_POST['system'])?$_POST['system']:'';
$bSimul = isset($_POST['simul'])?$_POST['simul']:false;
$sLastName = isset($_POST['last_name'])?$_POST['last_name']:'';
$sFirstName = isset($_POST['first_name'])?$_POST['first_name']:'';
$sEmail = isset($_POST['email'])?$_POST['email']:'';
$sCompany = isset($_POST['company'])?$_POST['company']:'';
$sResult = '';
//Launching application
$oDatabap = new Databap($oClassManagement);
//Auth check
$bUserOk = $oDatabap->logMeIn($sToken, $sAction);
//if connected
if($bUserOk && $sAction!=Databap::EXT_ACCESS)
{
//if expected page, relocate
//$oDatabap->redirectExpectedPage();
//loading data
if($sAction!='')
{
//Public actions
switch($sAction)
{
case 'log_me_out':
$oDatabap->logMeOut();
break;
case 'add_code':
$sResult = $oDatabap->addCode(array('description'=>$sDescription, 'content'=>$sContent, 'link'=>$sLink));
break;
case 'edit_code':
$sResult = $oDatabap->editCode($oItemId, $sContent);
break;
case 'read_code':
if($oItemId!==false) $sResult = $oDatabap->getColoredCode($oItemId);
break;
case 'nude_code':
if($oItemId!==false) $sResult = $oDatabap->getNudeCode($oItemId);
break;
case 'raw_code':
if($oItemId!==false) $sResult = $oDatabap->getRawCode($oItemId);
break;
case 'dl_code':
if($oItemId!==false) $sResult = $oDatabap->getSavedCode($oItemId);
break;
case 'dl_file':
$sResult = $oDatabap->getFile($oItemId);
break;
case 'print_code':
if($oItemId!==false) $sResult = $oDatabap->getRawCode($oItemId, true);
break;
case 'add_procedure':
$sResult = $oDatabap->addProcedure($_POST);
break;
case 'get_procedure':
$sResult = $oDatabap->getProcedure($oItemId);
break;
case 'add_doc':
$sResult = $oDatabap->addDoc($_POST);
break;
case 'get_doc':
$sResult = $oDatabap->getDoc($oItemId);
break;
case 'add_table':
$sResult = $oDatabap->addTable($sSystem, $sTitle, $sDescription, $sKeyWords, $oItemId, $bSimul);
break;
case 'get_table':
$sResult = $oDatabap->getTable($oItemId);
break;
case 'get_article':
$sResult = $oDatabap->getArticle($oItemId);
break;
case 'art_redirect':
$sResult = $oDatabap->redirectArticle($oItemId);
break;
case 'upload_image':
$sResult = $oDatabap->uploadFile('image');
break;
case 'upload_doc':
$sResult = $oDatabap->uploadFile('doc');
break;
case 'url':
$sResult = $oDatabap->getUrlAvailability($sLink);
break;
case 'user_info':
$sResult = $oDatabap->getUserInfo($oDatabap->getUserId(), true);
break;
case 'profile':
$sResult = $oDatabap->getProfile($oItemId);
break;
case 'search':
$sResult = $oDatabap->search($sKeyWords);
break;
case 'code_block':
$sResult = $oDatabap->getCodeBlock();
break;
case 'join_chan':
$sResult = $oDatabap->joinChan($sChan, $bFirstConn, $asAttendees);
break;
case 'quit_chan':
$sResult = $oDatabap->quitChan($sChan);
break;
case 'invite_chan':
$sResult = $oDatabap->inviteChan($oUser, $sChan);
break;
case 'disconnect_chat':
$sResult = $oDatabap->disconnectChat();
break;
case 'add_message':
$sResult = $oDatabap->addChatMessage($sMessage, $sChan);
break;
case 'messages':
$sResult = $oDatabap->getMessages($iMessageId);
break;
case 'news':
$sResult = $oDatabap->getNews();
break;
case 'connected_users':
$sResult = $oDatabap->getConnectedUsers(true);
break;
case 'get_options':
$sResult = $oDatabap->getOptions();
break;
case 'set_options':
$sResult = $oDatabap->setOptions($_POST, false);
break;
case 'set_pass':
$sResult = $oDatabap->checkSetPass($sOldToken, $sNewToken);
break;
case 'list':
$sResult = $oDatabap->getItemList();
break;
case 'note':
$sResult = $oDatabap->getNote($oItemId);
break;
case 'css':
$sResult = $oDatabap->getStyleSheet();
break;
default:
//Admin actions
if($oDatabap->checkUserClearance(Databap::CLEARANCE_ADMIN))
{
switch($sAction)
{
case 'add_user':
$sResult = $oDatabap->addUser($sFirstName, $sLastName, $oItemId, $sEmail);
break;
case 'add_company':
$sResult = $oDatabap->addCompany($sCompany);
break;
case 'update_web_crawler':
$sResult = $oDatabap->updateWebCrawler();
break;
case 'reset_pass':
$sResult = $oDatabap->resetPass($oUser);
break;
case 'assign_user':
$sResult = $oDatabap->assignUser($oUser, $sCompany);
break;
case 'install_queries':
$oMySqlInstall = new MySqlManager(Settings::DB_SERVER, Settings::DB_LOGIN, Settings::DB_PASS, Settings::DB_NAME, Databap::getSqlOptions(), Settings::DB_ENC);
$sResult = $oMySqlInstall->getFullInstallQuery();
break;
case 'reset_chan_safe_names':
$sResult = $oDatabap->resetChanSafeNames();
break;
case 'golive':
$sResult = $oDatabap->goLive();
break;
}
}
break;
}
}
//Loading a page
else
{
$sResult = $oDatabap->getPage($sPage, $oItemId, $_GET);
}
}
//External Access with token
elseif($bUserOk && $sAction==Databap::EXT_ACCESS)
{
//Public actions
switch($sPage)
{
case 'rss': //RSS Feed
$sResult = $oDatabap->getRss($sCategory);
break;
default:
//Restricted actions
if($oDatabap->checkUserClearance(Databap::CLEARANCE_ADMIN))
{
switch($sPage)
{
case 'blogs': //Syncing Blogs with database & spreading the news on chat
$sResult = $oDatabap->syncSapBlog();
break;
}
}
elseif($sResult=='') $sResult = 'No Clearance';
break;
}
}
elseif($sAction!='')
{
$sResult = Databap::DISCONNECTED;
}
//loading logon
else
{
//$oDatabap->setExpectedPage($_SERVER['REQUEST_URI']);
$sResult = $oDatabap->getLogonPage($sToken=='');
//TODO delete in v1.0.0
if($_SERVER['QUERY_STRING']!='') header('Location:'.$_GET['serv_name']);
}
//clean unwanted error log
$sDebug = ob_get_clean();
if(Settings::DEBUG && $sDebug!='') $oDatabap->addUncaughtError($sDebug);
echo $sResult;
?>