Skip to content

Commit

Permalink
Merge branch 'wip'
Browse files Browse the repository at this point in the history
  • Loading branch information
bochoven committed Feb 11, 2014
2 parents e1d3f6d + 2a0e43f commit ccac37e
Show file tree
Hide file tree
Showing 34 changed files with 950 additions and 129 deletions.
6 changes: 6 additions & 0 deletions app/controllers/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ 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
20 changes: 11 additions & 9 deletions app/helpers/database_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ function migrate($model_obj)
// Check if directory exists
if( ! is_dir($migration_dir))
{
error('Migration error: no migrations found in '.$migration_dir);
return FALSE;
throw new Exception('no migrations found in '.$migration_dir);
}

$migration_list = array();
Expand All @@ -34,8 +33,7 @@ function migrate($model_obj)

if( $target_version > 0 && ! isset($migration_list[$target_version]))
{
echo('Migration error: migration '.$target_version.' not found');
return FALSE;
throw new Exception($model_name.' migration '.$target_version.' not found');
}

if( $target_version > $current_version )
Expand All @@ -59,18 +57,23 @@ function migrate($model_obj)

if ( ! class_exists($class, FALSE))
{
error('Migration error: migration class '.$class.' not found');
return FALSE;
throw new Exception('migration class '.$class.' not found');
}

if (($method === 'up' && $number > $current_version && $number <= $target_version) OR
($method === 'down' && $number <= $current_version && $number > $target_version))
{
$instance = new $class();

// Check if we have up and down
if( ! method_exists($instance, 'up') || ! method_exists($instance, 'down'))
{
throw new Exception("up() or down() missing from $class");
}

if(call_user_func(array($instance, $method)) === FALSE )
{
error('Migration error: '.$instance->get_errors());
return FALSE;
throw new Exception($instance->get_errors());
}

$migration_obj->version = $number;
Expand All @@ -83,5 +86,4 @@ function migrate($model_obj)
$migration_obj->version = $target_version;
$migration_obj->save();
}
alert('Migrated '.$model_name.' to version '.$migration_obj->version);
}
13 changes: 9 additions & 4 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.5.643';
$GLOBALS['version'] = '2.0.7.674';

// Return version without commit count
function get_version()
Expand All @@ -14,9 +14,14 @@ function get_version()
//===============================================s
function uncaught_exception_handler($e)
{
ob_end_clean(); //dump out remaining buffered text
$vars['message']=$e;
die(View::do_fetch(APP_PATH.'errors/exception_uncaught.php',$vars));
// Dump out remaining buffered text
ob_end_clean();

// Get error message
error($e->getMessage());

// Write footer
die(View::do_fetch(conf('view_path').'partials/foot.php'));
}

function custom_error($msg='')
Expand Down
84 changes: 84 additions & 0 deletions app/migrations/filevault_status_model/001_add_filevault_users.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php

class Migration_add_filevault_users extends Model
{
protected $columname = 'filevault_users';

function __construct()
{
parent::__construct();
$this->tablename = 'filevault_status';
}

public function up()
{
// Get database handle
$dbh = $this->getdbh();

// Wrap in transaction
$dbh->beginTransaction();

// Adding a column is simple...
$sql = sprintf('ALTER TABLE %s ADD COLUMN %s VARCHAR(255)',
$this->enquote($this->tablename), $this->enquote($this->columname));

$this->exec($sql);

// so is adding an index...
$idx_name = $this->tablename . '_' . $this->columname;
$sql = sprintf("CREATE INDEX %s ON %s (%s)",
$idx_name, $this->enquote($this->tablename), $this->columname);

$this->exec($sql);

$dbh->commit();
}

public function down()
{
// Get database handle
$dbh = $this->getdbh();

switch ($this->get_driver())
{
case 'sqlite':// ...removing a column in SQLite is hard

$dbh->beginTransaction();

// Create temporary table
$sql = "CREATE TABLE filevault_status_temp (
id INTEGER PRIMARY KEY,
serial_number VARCHAR(255) UNIQUE,
filevault_status VARCHAR(255))";
$this->exec($sql);

$sql = "INSERT INTO filevault_status_temp
SELECT id, serial_number, filevault_status FROM filevault_status";
$this->exec($sql);

$sql = "DROP table filevault_status";
$this->exec($sql);

$sql = "ALTER TABLE filevault_status_temp RENAME TO filevault_status";
$this->exec($sql);

// Add index for old filevault_status column
$idx_name = $this->tablename . '_filevault_status';
$sql = sprintf("CREATE INDEX %s ON %s (%s)",
$idx_name, $this->enquote($this->tablename), 'filevault_status');

$this->exec($sql);

$dbh->commit();

break;

default: // MySQL (other engines?)

// MySQL drops the index as well -> check for other engines
$sql = sprintf('ALTER TABLE %s DROP COLUMN %s',
$this->enquote($this->tablename), $this->enquote($this->columname));
$this->exec($sql);
}
}
}
85 changes: 85 additions & 0 deletions app/migrations/network_model/001_network_model_fix_ipv4router.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

// Fix the ipv4 router: was integer, should be varchar

class Migration_network_model_fix_ipv4router extends Model
{

public function up()
{
// Get database handle
$dbh = $this->getdbh();

$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

// Wrap in transaction
$dbh->beginTransaction();

switch ($this->get_driver())
{
case 'sqlite':

// Set IPv4 router to string affinity
// Unfortunately this is not very simple
$sql = "CREATE TABLE network_temp (
id INTEGER PRIMARY KEY,
serial_number VARCHAR(255) UNIQUE,
service VARCHAR(255),
`order` INTEGER,
status INTEGER,
ethernet VARCHAR(255),
clientid VARCHAR(255),
ipv4conf VARCHAR(255),
ipv4ip VARCHAR(255),
ipv4mask VARCHAR(255),
ipv4router VARCHAR(255),
ipv6conf VARCHAR(255),
ipv6ip VARCHAR(255),
ipv6prefixlen INTEGER,
ipv6router VARCHAR(255),
timestamp INTEGER)";
$this->exec($sql);

$sql = "INSERT INTO network_temp SELECT * FROM network";
$this->exec($sql);

$sql = "DROP table network";
$this->exec($sql);

$sql = "ALTER TABLE network_temp RENAME TO network";
$this->exec($sql);

// Re-add indexes
$this->tablename = 'network';
$this->idx[] = array('serial_number');
$this->idx[] = array('serial_number', 'service');
$this->set_indexes();

break;

case 'mysql':

// Set ipv4router column to VARCHAR
$sql = "ALTER TABLE network MODIFY ipv4router VARCHAR(255)";
$this->exec($sql);

break;

default:

# code...
break;
}

// Commit changes
$dbh->commit();


}// End function up()

public function down()
{
// As this is an error correction, there's no need for down().
// up() is idempotent
}
}
3 changes: 3 additions & 0 deletions app/models/tablequery.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ function fetch($cfg)
{
$dbh = getdbh();

// Initial value
$iTotal = 0;

// Get tables from column names
$tables = array('machine' => 1);
$formatted_columns = array();
Expand Down
27 changes: 18 additions & 9 deletions app/modules/directory_service/directory_service_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ function __construct($serial='')
$this->rs['adforest'] = ''; // string
$this->rs['addomain'] = ''; // string
$this->rs['computeraccount'] = ''; // string
$this->rs['createmobileaccount'] = ''; $this->rt['createmobileaccount'] = 'BOOL'; // Enabled = 1, Disabled = 0
$this->rs['requireconfirmation'] = ''; $this->rt['requireconfirmation'] = 'BOOL';// Enabled = 1, Disabled = 0
$this->rs['forcehomeinstartup'] = ''; $this->rt['forcehomeinstartup'] = 'BOOL'; // Enabled = 1, Disabled = 0
$this->rs['mounthomeassharepoint'] = ''; $this->rt['mounthomeassharepoint'] = 'BOOL'; // Enabled = 1, Disabled = 0
$this->rs['usewindowsuncpathforhome'] = ''; $this->rt['usewindowsuncpathforhome'] = 'BOOL'; // Enabled = 1, Disabled = 0
$this->rs['createmobileaccount'] = 0; $this->rt['createmobileaccount'] = 'BOOL'; // Enabled = 1, Disabled = 0
$this->rs['requireconfirmation'] = 0; $this->rt['requireconfirmation'] = 'BOOL';// Enabled = 1, Disabled = 0
$this->rs['forcehomeinstartup'] = 0; $this->rt['forcehomeinstartup'] = 'BOOL'; // Enabled = 1, Disabled = 0
$this->rs['mounthomeassharepoint'] = 0; $this->rt['mounthomeassharepoint'] = 'BOOL'; // Enabled = 1, Disabled = 0
$this->rs['usewindowsuncpathforhome'] = 0; $this->rt['usewindowsuncpathforhome'] = 'BOOL'; // Enabled = 1, Disabled = 0
$this->rs['networkprotocoltobeused'] = ''; // string smb or afp
$this->rs['defaultusershell'] = ''; // string
$this->rs['mappinguidtoattribute'] = ''; // string?
$this->rs['mappingusergidtoattribute'] = ''; // string?
$this->rs['mappinggroupgidtoattr'] = ''; // string?
$this->rs['generatekerberosauth'] = ''; $this->rt['generatekerberosauth'] = 'BOOL'; // Enabled = 1, Disabled = 0
$this->rs['generatekerberosauth'] = 0; $this->rt['generatekerberosauth'] = 'BOOL'; // Enabled = 1, Disabled = 0
$this->rs['preferreddomaincontroller'] = ''; // string?
$this->rs['allowedadmingroups'] = ''; //array
$this->rs['authenticationfromanydomain'] = ''; $this->rt['authenticationfromanydomain'] = 'BOOL'; // Enabled = 1, Disabled = 0
$this->rs['authenticationfromanydomain'] = 0; $this->rt['authenticationfromanydomain'] = 'BOOL'; // Enabled = 1, Disabled = 0
$this->rs['packetsigning'] = ''; // allow = 1, ? = 0
$this->rs['packetencryption'] = ''; // allow = 1, ? = 0
$this->rs['passwordchangeinterval'] = ''; // int
Expand Down Expand Up @@ -86,9 +86,18 @@ function process($data)
'Namespace mode = ' => 'namespacemode');

//clear any previous data we had
foreach($translate as $search => $field) {
$this->$field = '';
foreach($translate as $search => $field)
{
if(array_key_exists($field, $this->rt) && $this->rt[$field] == 'BOOL')
{
$this->$field = 0;
}
else
{
$this->$field = '';
}
}

// Parse data
foreach(explode("\n", $data) as $line) {
// Translate standard entries
Expand Down
51 changes: 35 additions & 16 deletions app/modules/directory_service/scripts/directoryservice.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,51 @@ AD_COMMENTS=''

# Find which Directory Service we are bound to
DS=`/usr/bin/dscl localhost -list . | head -n 1`
if [ "${DS}" = "Local" ]; then
DS="Not bound to any server"
fi

# If AD, read Comments Field in AD
if [ "${DS}" = "Active Directory" ]; then


case "$DS" in
"Active Directory")
# Get major OS version (uses uname -r and bash substitution)
# osvers is 10 for 10.6, 11 for 10.7, 12 for 10.8, etc.
# osvers is 10 for 10.6, 11 for 10.7, 12 for 10.8, 13 for 10.9, etc.
osversionlong=$(uname -r)
osvers=${osversionlong/.*/}
localhostname=`/usr/sbin/scutil --get LocalHostName`
# Set variable for Domain
# domain=`dscl localhost -list /Active\ Directory`

domain=`dscl localhost -list /Active\ Directory`
if [[ ${osvers} -ge 11 ]]; then
AD_COMMENTS=`dscl /Search -read Computers/"${localhostname}"$ Comment 2>/dev/null | tr -d '\n' | awk '{$1 =""; print }'`
fi
else
if [ "${osvers}" = 10 ]; then
AD_COMMENTS=`dscl /Active\ Directory/All\ Domains/ -read Computers/"${localhostname}"$ Comment 2>/dev/null | tr -d '\n' | awk '{$1 =""; print }'`
fi
fi

echo "Active Directory Comments = ${AD_COMMENTS}" >> "$DIR/cache/directoryservice.txt"
#dsconfigad always exits with 0; trim spaces at beginning of the line and consecutive white spaces
/usr/sbin/dsconfigad -show | grep "=" | sed 's/^[ \t]*//;s/ */ /g' >> "$DIR/cache/directoryservice.txt"
;;

echo "Directory Service = ${DS}" > "$DIR/cache/directoryservice.txt"
echo "Active Directory Comments = ${AD_COMMENTS}" >> "$DIR/cache/directoryservice.txt"
#dsconfigad always exits with 0; trim spaces at beginning of the line and consecutive white spaces
/usr/sbin/dsconfigad -show | grep "=" | sed 's/^[ \t]*//;s/ */ /g' >> "$DIR/cache/directoryservice.txt"
"LDAPv3")
# Get major OS version (uses uname -r and bash substitution)
# osvers is 10 for 10.6, 11 for 10.7, 12 for 10.8, etc.
osversionlong=$(uname -r)
osvers=${osversionlong/.*/}
localhostname=`/usr/sbin/scutil --get LocalHostName`
# Set variable for Domain
domain=`dscl localhost -list /LDAPv3`
;;

exit 0
"Local") # Indicates not bound to a directory
DS="Not bound to Directory"
domain="Local"
;;

*) #Default Case
DS="Unexpected binding type"
;;
esac

echo "Directory Service = ${DS}" > "$DIR/cache/directoryservice.txt"
echo "Active Directory Domain = ${domain}" >> "$DIR/cache/directoryservice.txt"
exit 0
Loading

0 comments on commit ccac37e

Please sign in to comment.