#!/usr/clearos/sandbox/usr/bin/php
<?php

/**
 * Samba initialization script.
 *
 * @category   apps
 * @package    samba
 * @subpackage scripts
 * @author     ClearFoundation <developer@clearfoundation.com>
 * @copyright  2012 ClearFoundation
 * @license    http://www.gnu.org/copyleft/lgpl.html GNU Lesser General Public License version 3 or later
 * @link       http://www.clearfoundation.com/docs/developer/apps/samba/
 */

///////////////////////////////////////////////////////////////////////////////
// B O O T S T R A P
///////////////////////////////////////////////////////////////////////////////

$bootstrap = getenv('CLEAROS_BOOTSTRAP') ? getenv('CLEAROS_BOOTSTRAP') : '/usr/clearos/framework/shared';
require_once $bootstrap . '/bootstrap.php';

///////////////////////////////////////////////////////////////////////////////
// D E P E N D E N C I E S
///////////////////////////////////////////////////////////////////////////////

use \clearos\apps\base\File as File;
use \clearos\apps\base\Webconfig as Webconfig;

clearos_load_library('base/File');
clearos_load_library('base/Webconfig');

///////////////////////////////////////////////////////////////////////////////
// M A I N
///////////////////////////////////////////////////////////////////////////////

// Bail if we have already set the system certificate
$file = new File('/var/clearos/certificate_manager/webconfig');

if ($file->exists())
    exit(0);

// Set the system certificate
$webconfig = new Webconfig();
$options = $webconfig->get_ssl_certificate_options();

if (!array_key_exists('sys-0-cert.pem', $options))
    exit(0);

$webconfig->set_ssl_certificate('sys-0-cert.pem');
$file->create('root', 'root', '0644');
