Skip to content

Commit

Permalink
Merge branch 'wip'
Browse files Browse the repository at this point in the history
  • Loading branch information
bochoven committed Mar 5, 2014
2 parents ccac37e + 2906c36 commit 13d1b2e
Show file tree
Hide file tree
Showing 77 changed files with 1,181 additions and 667 deletions.
4 changes: 2 additions & 2 deletions app/controllers/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ class admin extends Controller
{
function __construct()
{
if( ! isset($_SESSION['user']))
if( ! $this->authorized())
{
redirect('auth/login');
die('Authenticate first.'); // Todo: return json?
}
}

Expand Down
16 changes: 10 additions & 6 deletions app/controllers/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ class auth extends Controller

function __construct()
{
// Check if we can store sessions
if ( session_save_path() && ! is_writable(session_save_path()))
{
fatal('Session path "'.session_save_path().'" is not writable for PHP!');
}

if(conf('auth_secure') && empty($_SERVER['HTTPS']))
{
redirect('error/client_error/426'); // Switch protocol
Expand Down Expand Up @@ -42,6 +36,12 @@ function index()

function login($return = '')
{

if($this->authorized())
{
redirect($return);
}

$check = FALSE;

// If no valid mechanisms found, bail
Expand Down Expand Up @@ -235,6 +235,10 @@ function login($return = '')

function logout()
{
// Initialize session
$this->authorized();

// Destroy session;
session_destroy();
redirect('');
}
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/clients.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class clients extends Controller
{
function __construct()
{
if( ! isset($_SESSION['user']))
if( ! $this->authorized())
{
redirect('auth/login');
}
Expand Down
23 changes: 14 additions & 9 deletions app/controllers/datatables.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class datatables extends Controller
{
function __construct()
{
if( ! isset($_SESSION['user']))
if( ! $this->authorized())
{
die('Authenticate first.'); // Todo: return json?
}
Expand Down Expand Up @@ -73,14 +73,19 @@ function data()

//print_r($cfg);

// Get model
$obj = new Tablequery($cfg);

//$obj->fetch($cfg);

//return;

echo json_encode($obj->fetch($cfg));
try
{
// Get model
$obj = new Tablequery($cfg);
echo json_encode($obj->fetch($cfg));
}
catch(Exception $e)
{
echo json_encode(array(
'error' => $e->getMessage(),
'sEcho' => intval($cfg['sEcho'])
));
}

}

Expand Down
85 changes: 54 additions & 31 deletions app/controllers/report.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,46 +50,55 @@ function hash_check()
$this->error("Items are missing");
}

// Register check in reportdata
$report = new Reportdata_model($_POST['serial']);
$report->register()->save();

$req_items = unserialize($_POST['items']); //Todo: check if array

$itemarr = array('error' => '');

// Get stored hashes from db
$hash = new Hash();
$hashes = $hash->all($_POST['serial']);

// Compare sent hashes with stored hashes
foreach($req_items as $name => $val)
// Try to register client and lookup hashes in db
try
{
// All models are lowercase
$lkey = strtolower($name);
// Register check in reportdata
$report = new Reportdata_model($_POST['serial']);
$report->register()->save();

// Rename legacy InventoryItem to inventory
$lkey = str_replace('inventoryitem', 'inventory', $lkey);
$req_items = unserialize($_POST['items']); //Todo: check if array

// Remove _model legacy
if(substr($lkey, -6) == '_model')
// Get stored hashes from db
$hash = new Hash();
$hashes = $hash->all($_POST['serial']);

// Compare sent hashes with stored hashes
foreach($req_items as $name => $val)
{
$lkey = substr($lkey, 0, -6);

// All models are lowercase
$lkey = strtolower($name);

// Rename legacy InventoryItem to inventory
$lkey = str_replace('inventoryitem', 'inventory', $lkey);

// Remove _model legacy
if(substr($lkey, -6) == '_model')
{
$lkey = substr($lkey, 0, -6);
}

if( ! (isset($hashes[$lkey]) && $hashes[$lkey] == $val['hash']))
{
$itemarr[$name] = 1;
}
}

if( ! (isset($hashes[$lkey]) && $hashes[$lkey] == $val['hash']))
{
$itemarr[$name] = 1;
}
}
catch (Exception $e)
{
error('hash_check: '.$e->getMessage());
}


// Handle errors
foreach($GLOBALS['alerts'] AS $type => $list)
{
foreach ($list AS $msg)
{
$itemarr['error'] .= "$type : $msg\n";
$itemarr['error'] .= "$type: $msg\n";
}
}

Expand All @@ -111,9 +120,10 @@ function check_in()
$this->error("No items in POST");
}

try {
$arr = unserialize($_POST['items']);
} catch (Exception $e) {
$arr = @unserialize($_POST['items']);

if ( ! is_array($arr))
{
$this->error("Could not parse items, not a proper serialized file");
}

Expand All @@ -125,7 +135,7 @@ function check_in()
// Rename legacy InventoryItem to inventory
$name = str_ireplace('InventoryItem', 'inventory', $name);

$this->msg("Starting: $name");
alert("starting: $name");

// All models are lowercase
$name = strtolower($name);
Expand Down Expand Up @@ -191,6 +201,19 @@ function check_in()
$this->msg("An error occurred while processing: $classname");
$this->msg("Error: " . $e->getMessage());
}

// Handle alerts
foreach($GLOBALS['alerts'] AS $type => $list)
{
foreach ($list AS $msg)
{
$this->msg("$type: $msg");
}

// Remove alert from array
unset($GLOBALS['alerts'][$type]);
}

}
}

Expand All @@ -202,7 +225,7 @@ function check_in()
**/
function msg($msg = 'No message', $exit = FALSE)
{
echo('Server: '.$msg."\n");
echo('Server '.$msg."\n");
if($exit)
{
exit();
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/show.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class show extends Controller
{
function __construct()
{
if( ! isset($_SESSION['user']))
if( ! $this->authorized())
{
redirect('auth/login');
}
Expand Down
9 changes: 6 additions & 3 deletions app/helpers/site_helper.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

// Munkireport version (last number is number of commits)
$GLOBALS['version'] = '2.0.7.674';
$GLOBALS['version'] = '2.0.8.725';

// Return version without commit count
function get_version()
Expand All @@ -18,7 +18,7 @@ function uncaught_exception_handler($e)
ob_end_clean();

// Get error message
error($e->getMessage());
error('Uncaught Exception: '.$e->getMessage());

// Write footer
die(View::do_fetch(conf('view_path').'partials/foot.php'));
Expand Down Expand Up @@ -78,6 +78,9 @@ function getdbh()
{
fatal('Connection failed: '.$e->getMessage());
}

// Set error mode
$GLOBALS['dbh']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

// Store database name in config array
if(preg_match('/.*dbname=([^;]+)/', conf('pdo_dsn'), $result))
Expand Down Expand Up @@ -126,7 +129,7 @@ function lang($str)
conf('lang', 'en') . '/lang.php';
if ((@include_once $path) !== 1)
{
debug('failed to load language file for '.conf('lang', 'en'));
alert('failed to load language file for language: '.conf('lang', 'en'), 'danger');
$lang = array();
}
}
Expand Down
32 changes: 30 additions & 2 deletions app/lang/es/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@
$lang['minutes'] = 'minutos';
$lang['seconds'] = 'segundos';

$lang['version'] = 'versión';
$lang['unknown'] = 'desconocido';
// Miscellaneous

$lang['munkireport_version'] = 'Munkireport versión: %s';
$lang['version'] = 'versión';
$lang['unknown'] = 'desconocido';
$lang['name'] = 'Nombre';
$lang['enabled'] = 'Activado';
$lang['disabled'] = 'Desactivado';

// Authentication

Expand All @@ -47,6 +53,28 @@
// Client

$lang['client_nonexistent'] = 'No existe ningún cliente con el número de serie "%s"';
$lang['tab_munki'] = 'Munki';
$lang['tab_apple_software'] = 'Software de Apple';
$lang['tab_third_party_software'] = 'Software de terceros';
$lang['tab_inventory_items'] = 'Inventario';
$lang['tab_network_interfaces'] = 'Interfaces de red';
$lang['tab_directory_services'] = 'Servicios de directorio';
$lang['installed_apple_software'] = 'Software de Apple instalado';
$lang['installed_third_party_software'] = 'Software de terceros instalado';
$lang['install_date'] = 'Fecha de instalación';
$lang['process_name'] = 'Nombre del proceso';
$lang['no_install_history'] = 'No hay fecha de instalación';
$lang['bundle_id'] = 'BundleID';
$lang['path'] = 'Directorio';

// Network

$lang['ethernet'] = 'Ethernet';
$lang['ip_address'] = 'Dirección IP';
$lang['network_mask'] = 'Máscara';
$lang['prefix_length'] = 'Longitud del prefijo';
$lang['router'] = 'Router';
$lang['configuration'] = 'Configuración';

// Errors

Expand Down
Loading

0 comments on commit 13d1b2e

Please sign in to comment.