summaryrefslogblamecommitdiffstats
path: root/management-interface/index.php
blob: c206e665bb7418d01c8940199efa0f258ec8c369 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
      
                 




                               


                               





                                                                                                        

                                  
                             
 
                           


                                                                  
    
 






                                                                                                           











                                                                                                                                                               
                  


            
   
                                                                                                
 
                                    
                                 


                                                 
                         
                                                      
                  








                                                  
   






                                                              
   



            
<?php
session_start();

$f3 = require('lib/base.php');

$f3->set('DEBUG', 3);

ini_set('display_errors', 1); 
error_reporting(E_ALL);

$f3->set('AUTOLOAD', 'api/models/');

// set defaults
$f3->set('loggedin', (isset($f3->get('SESSION')['username']))?true:false);
$f3->set('username', (isset($f3->get('SESSION')['username']))?$f3->get('SESSION')['username']:'Guest');
$f3->set('message', '');

$f3->config('config/global.cfg');
require('config/mysql.php');

$f3->set('DB', new DB\SQL(
	'mysql:host=localhost;port=3306;dbname='.$mysql_database,
	$mysql_username,
	$mysql_password
));

$f3->route('POST /do/@action',
	function($f3, $params) {
		$master = new Master;
		if ($params['action'] === 'login') {
			if (isset($_POST['user']) && isset($_POST['pass'])) {
				$master->dologin($f3, $f3->get('POST')['user'], $f3->get('POST')['pass']);
			}
		} else if ($params['action'] === 'savesatellite') {
			if(isset($_POST['organization']) && isset($_POST['address'])
					&& isset($_POST['name']) && isset($_POST['prefix']) && isset($_POST['publickey'])) {
				$master->saveSatellite($f3, $_POST['organization'], $_POST['address'], $_POST['name'], $_POST['prefix'], $_POST['publickey']);
			}
		} else if ($params['action'] === 'newsatellite') {
                        if(isset($_POST['organization']) && isset($_POST['address'])
                                        && isset($_POST['name']) && isset($_POST['prefix']) && isset($_POST['publickey'])) {
				$master->newSatellite($f3, $_POST['organization'], $_POST['address'], $_POST['name'], $_POST['prefix'], $_POST['publickey']);
			}
		} else {
			$f3->reroute('@module(@m=home)');
		}
	},
	0,
	512
);
	// ^ sending files with a maximum rate of 64 KB/s --> slow responses to prevent attacks

$f3->route('GET @module: /site/@m',
	function($f3, $params) {
		$master = new Master;
		if ($params['m'] === 'logout') {
			$master->dologout($f3);
		} else {
			$master->parse($f3, $params);
		}
	}
);

$f3->route('GET /',
	function($f3) {
		$f3->reroute('@module(@m=home)');
	}
);

/*
$f3->set('ONERROR',
	function($f3) {
		// recursively clear existing output buffers:
		while (ob_get_level()) ob_end_clean();
		echo $f3->get('ERROR.title');
	}
);
*/

$f3->run();

?>