Commit a8687aee authored by Benoit Mortier's avatar Benoit Mortier
Browse files

Fixes: #2052 merge game into fusiondirectory-plugins

parent 65480249
dev 6104-mail-methods-refactor 6231-give-the-ability-to-the-webservice-to-notice-if-an-attribute-is-monovalued-or-multivalued 6237-add-requiredattrs-array-to-the-webservice-informations 6245-adapt-the-ci-to-the-reorganisation-of-the-dev-tools-and-fixing-the-trigger-downstream-pipelines 6250-supann-configuration-backend-requires-account-life-cycle-section 6280-plugins-update-plugins-to-take-into-consideration-the-new-directory-of-core-structure 6310-tasks-reminder-error-in-the-schema-duplicate-attribute-id 6311-put-the-version-1-5-in-all-yaml-for-fusiondirectory-1-5 6322-template-issue-when-creating-a-template-with-empty-password-error-message-should-not-be-seen-2 6332-zimbra-allows-update-of-data-for-unknown-domain-name-for-specific-individual-aliases 6337-webservice-issue-with-archiving-post-request-not-responding-but-successfully-archiving-user 6341-supann-extract-resources-states-sub-states-from-backend-configuration-to-their-own-objects master fusiondirectory-1.5 fusiondirectory-1.4 fusiondirectory-1.3.1 fusiondirectory-1.3 fusiondirectory-1.2.3 fusiondirectory-1.2.2 fusiondirectory-1.2.1 fusiondirectory-1.2 fusiondirectory-1.1.1 fusiondirectory-1.1 fusiondirectory-1.0.20 fusiondirectory-1.0.19 fusiondirectory-1.0.18 fusiondirectory-1.0.17 fusiondirectory-1.0.16 fusiondirectory-1.0.15 fusiondirectory-1.0.14 fusiondirectory-1.0.13 fusiondirectory-1.0.12 fusiondirectory-1.0.11 fusiondirectory-1.0.10 fusiondirectory-1.0.9.3 fusiondirectory-1.0.9.2 fusiondirectory-1.0.9.1 fusiondirectory-1.0.9 fusiondirectory-1.0.8.9 fusiondirectory-1.0.8.8 fusiondirectory-1.0.8.7 fusiondirectory-1.0.8.6 fusiondirectory-1.0.8.5 fusiondirectory-1.0.8.4 fusiondirectory-1.0.8.3 fusiondirectory-1.0.8.2 fusiondirectory-1.0.8.1 fusiondirectory-1.0.8 fusiondirectory-1.0.7.5 fusiondirectory-1.0.7.4 fusiondirectory-1.0.7.3 fusiondirectory-1.0.7.2 fusiondirectory-1.0.7.1 fusiondirectory-1.0.7 fusiondirectory-1.0.6 fusiondirectory-1.0.5
No related merge requests found
Showing with 328 additions and 0 deletions
+328 -0
<?php
class Game
{
private $config;
private $missions;
private $mission;
private function __construct($config, $missions)
{
$this->config =& $config;
$this->missions = $missions;
$this->mission = 0;
}
private function _run()
{
$smarty = get_smarty();
$i = $this->mission;
$end = FALSE;
$smarty->assign('success', FALSE);
while (($i < count($this->missions)) && $this->missions[$i]->validate()) {
$i++;
$this->mission = $i;
$smarty->assign('success', TRUE);
if ($i < count($this->missions)) {
$this->missions[$i]->init();
}
}
if ($i >= count($this->missions)) {
self::stop();
} else {
$smarty->assign('mission_number', $i);
$smarty->assign('mission', $this->missions[$i]->compute_infos());
}
return $smarty->fetch(get_template_path('game.tpl', TRUE, dirname(__FILE__)));
}
static function run()
{
global $config;
if (isset($_GET['start_game'])) {
$instance = new Game($config, self::beatles_scenario());
session::global_set('game_instance', $instance);
}
if (session::global_is_set('game_instance')) {
$instance = session::global_get('game_instance');
return $instance->_run();
}
}
static function stop()
{
session::global_un_set('game_instance');
}
static function beatles_scenario() {
return array(
new Mission(_('John Lennon has arrived'),
array(
'Game::john_created' => _('Create a user for John Lennon with login <b>john</b>')
), ''
),
new Mission(_('The Beatles are here'),
array(
'Game::template_created' => _('Create a user template named <b>beatle</b>, using <i>http://%l|givenName%.com</i> as homepage and <i>%l|sn%</i> (lower case first name) as password'),
'Game::paul_created' => _('Create a user for Paul McCartney using beatle profile (login paul)'),
'Game::george_created' => _('Create a user for George Harrison using beatle profile (login george)'),
'Game::ringo_created' => _('Create a user for Ringo Starr using beatle profile (login ringo)'),
'Game::beatles_created' => _('Create a group for The Beatles named <b>beatles</b> and add the 4 beatles to this group'),
), ''
),
/* new Mission(_('The Beatles hired a manager'),
array(
'Game::manager_created' => _('Create a user for the manager with login <b>manager</b>'),
'Game::manager_rights' => _('Give this user full rights on users'),
'Game::manager_login' => _('Log out and log in using the manager account'),
'Game::beatles_management' => _('Set the birth date of John to 1940-10-09'),
)
),*/
new Mission(_('The Beatles bought computers'),
array(
'Game::submarine_created' => _('Create a server named <b>yellow-submarine</b> with IP 192.168.1.129 and MAC 00:11:22:33:44:01'),
'Game::dns_created' => _('Add a DNS service for zone <b>beatles.fake</b> on this server'),
'Game::dhcp_created' => _('Add a DHCP service for the network <b>192.168.1.128/26</b> on this server'),
'Game::station_created' => _('Create a workstation for John\'s laptop, with IP 192.168.1.130 and MAC 00:11:22:33:44:02'),
'Game::windows_created' => _('Create a winstation for George\'s laptop, as he is running windows, with IP 192.168.1.131 and MAC 00:11:22:33:44:03'),
), ''
),
);
}
static function john_created()
{
return self::user_created('john');
}
static function paul_created()
{
return self::user_created('paul');
}
static function george_created()
{
return self::user_created('george');
}
static function ringo_created()
{
return self::user_created('ringo');
}
static function user_created($uid)
{
global $config;
$ldap = $config->get_ldap_link();
$ldap->cd ($config->current['BASE']);
$ldap->search ('(&(objectClass=gosaAccount)(uid='.$uid.'))', array('uid'));
if ($ldap->fetch()) {
return TRUE;
}
return FALSE;
}
static function template_created()
{
global $config;
$ldap = $config->get_ldap_link();
$ldap->cd ($config->current['BASE']);
$ldap->search ('(&(objectClass=gosaUserTemplate)(cn=beatle))', array('labeledURI'));
if ($attrs = $ldap->fetch()) {
return ($attrs['labeledURI'][0] == 'http://%l|givenName%.com');
}
return FALSE;
}
static function beatles_created()
{
global $config;
$ldap = $config->get_ldap_link();
$ldap->cd ($config->current['BASE']);
$ldap->search ('(&(objectClass=posixGroup)(cn=beatles))', array('cn', 'memberUid'));
if ($attrs = $ldap->fetch()) {
unset($attrs['memberUid']['count']);
return (count(array_diff($attrs['memberUid'], array('john', 'paul', 'george', 'ringo'))) == 0);
}
return FALSE;
}
static function submarine_created()
{
return self::system_created('goServer', 'yellow-submarine','192.168.1.129','00:11:22:33:44:01');
}
static function station_created()
{
return self::system_created('gotoWorkstation', '*','192.168.1.130','00:11:22:33:44:02');
}
static function windows_created()
{
return self::system_created('sambaSamAccount', '*','192.168.1.131','00:11:22:33:44:03');
}
static function system_created($class, $cn, $ip, $mac)
{
global $config;
$ldap = $config->get_ldap_link();
$ldap->cd (get_ou('systemRDN').$config->current['BASE']);
$ldap->search ('(&(objectClass='.$class.')(cn='.$cn.')(ipHostNumber='.$ip.')(macAddress='.$mac.'))', array('cn'));
if ($attrs = $ldap->fetch()) {
return TRUE;
}
return FALSE;
}
static function dhcp_created ()
{
return self::system_created('dhcpServer', 'yellow-submarine','192.168.1.129','00:11:22:33:44:01');
}
static function dns_created ()
{
$cn = 'yellow-submarine';
global $config;
$ldap = $config->get_ldap_link();
$ldap->cd (get_ou('systemRDN').$config->current['BASE']);
$ldap->search ('(&(objectClass=goServer)(cn='.$cn.'))', array('cn'));
if ($attrs = $ldap->fetch()) {
$dns = new serviceDNS($config, $attrs['dn']);
if ($dns->is_this_account($attrs)) {
return isset($dns->Zones['beatles.fake.']);
} else {
return FALSE;
}
}
return FALSE;
}
}
?>
<?php
class Mission
{
private $title;
private $objective;
private $objectives;
private $init_f;
function __construct($title, $objectives, $init)
{
$this->title = $title;
$this->objective = 0;
$this->objectives = array();
foreach ($objectives as $func => $label) {
$this->objectives[] = array('func' => $func, 'label' => $label, 'done' => FALSE);
}
$this->init_f = $init;
}
/* Starts the mission */
public function init()
{
$func = $this->init_f;
if (!empty($this->init_f)) {
call_user_func($this->init_f);
}
}
/* Returns true if mission complete */
public function validate()
{
foreach ($this->objectives as &$obj) {
if (call_user_func($obj['func'])) {
$obj['done'] = TRUE;
} else {
return FALSE;
}
}
return TRUE;
}
public function compute_infos()
{
return array(
'title' => $this->title,
'objectives' => $this->objectives
);
}
}
?>
<style type="text/css">
{literal}
div.fd_game {
background:#FFF6BF none repeat scroll 0 0;
border-color:#FFD324;
color:#514721;
border:2px solid #DDDDDD;
margin:.2em;
padding-left:1em;
padding-right:1em;
padding-top:.5em;
padding-bottom:.5em;
}
div.success {
background:#E6EFC2 none repeat scroll 0 0;
border:2px solid #C6D880;
color:#264409;
margin:.2em;
padding-left:1em;
padding-right:1em;
padding-top:.5em;
padding-bottom:.5em;
font-size:1.5em;
}
div.overlay {
color:#264409;
background:none;
border:none;
position:absolute;
width:100%;
opacity:1;
text-align:center;
vertical-align:middle;
height:100%;
margin:0;
padding:0;
font-size:7em;
margin-top:15%;
}
li.done {
list-style-type: disk;
}
li.not_done {
list-style-type: circle;
}
{/literal}
</style>
{if $mission}
{if $success}
<div class="success">
<img src="plugins/game/images/mission_complete.png" style="vertical-align:middle;height:60px;"/>
Mission complete
</div>
{/if}
<div class="fd_game">
<p style="font-size:2em;"><img src="plugins/game/images/game_logo.png" style="height:50px;"/>FusionDirectory - The game<img src="plugins/game/images/game_logo.png" style="height:50px;"/></p>
<h4>Mission {$mission_number} : {$mission.title}</h4>
<ul>
{foreach from=$mission.objectives item=obj}
{if $obj.done}
<li class="done">
{else}
<li class="not_done">
{/if}
{$obj.label}
</li>
{/foreach}
</ul>
</div>
{else}
<div class="overlay">
<img src="plugins/game/images/win.png" style="vertical-align:middle;height:200px;"/>
You won the game
</div>
{/if}
game/html/images/game_logo.png

3.06 KB

game/html/images/mission_complete.png

6.59 KB

game/html/images/win.png

34.4 KB

Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment