-
Notifications
You must be signed in to change notification settings - Fork 1
/
ui.combodo-ansible-datamodel.php
147 lines (127 loc) · 4.99 KB
/
ui.combodo-ansible-datamodel.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
/*
* @copyright Copyright (C) 2023 iTop
* @license http://opensource.org/licenses/AGPL-3.0
*/
/*********************************************************************
*
* Main user interface pages for Zone Management extension starts here
*
* *******************************************************************/
if (!defined('__DIR__')) {
define('__DIR__', dirname(__FILE__));
}
if (!defined('APPROOT')) {
if (file_exists(__DIR__.'/../../approot.inc.php')) {
require_once(__DIR__.'/../../approot.inc.php'); // When in env-xxxx folder
} else {
require_once(__DIR__.'/../../../approot.inc.php'); // When in datamodels/x.x folder
}
}
require_once(APPROOT.'/application/application.inc.php');
require_once(APPROOT.'/application/startup.inc.php');
require_once(APPROOT.'/application/wizardhelper.class.inc.php');
try {
$operation = utils::ReadParam('operation', '');
$bPrintable = (utils::ReadParam('printable', 0) == '1');
require_once(APPROOT.'/application/loginwebpage.class.inc.php');
$sLoginMessage = LoginWebPage::DoLogin(); // Check user rights and prompt if needed
$oAppContext = new ApplicationContext();
$oP = new iTopWebPage(Dict::S('UI:WelcomeToITop'), $bPrintable);
$oP->SetMessage($sLoginMessage);
$oP->set_base(utils::GetAbsoluteUrlAppRoot().'pages/');
// All the following actions use advanced forms that require more javascript to be loaded
$oP->LinkScriptFromAppRoot('js/forms-json-utils.js');
$oP->LinkScriptFromAppRoot('js/wizardhelper.js');
$oP->LinkScriptFromAppRoot('js/wizard.utils.js');
$oP->LinkScriptFromAppRoot('js/links/links_widget.js');
$oP->LinkScriptFromAppRoot('js/extkeywidget.js');
switch ($operation) {
///////////////////////////////////////////////////////////////////////////////////////////
case 'inventoryfiledisplay': // Display zone in BIND format
$sClass = utils::ReadParam('class', '');
$id = utils::ReadParam('id', '');
$sFormat = utils::ReadParam('format', '');
// Check if right parameters have been given
if (empty($sClass) || empty($id)) {
throw new ApplicationException(Dict::Format('UI:Error:2ParametersMissing', 'class', 'id'));
}
if ($sClass != 'AnsibleInventory') {
throw new ApplicationException(Dict::Format('UI:Error:WrongActionForClass', $operation, $sClass));
}
// Check if the object exists
$oObj = MetaModel::GetObject($sClass, $id, false /* MustBeFound */);
if (is_null($oObj)) {
$oP->set_title(Dict::S('UI:ErrorPageTitle'));
$oP->P(Dict::S('UI:ObjectDoesNotExist'));
} else {
// Dump data file
$oObj->DisplayInventoryFile($oP, array('format' => $sFormat));
}
break; // End case datafiledisplay
///////////////////////////////////////////////////////////////////////////////////////////
case 'cancel': // An action was cancelled
case 'displaylist':
default: // Menu node rendering (templates)
ApplicationMenu::LoadAdditionalMenus();
$oMenuNode = ApplicationMenu::GetMenuNode(ApplicationMenu::GetMenuIndexById(ApplicationMenu::GetActiveNodeId()));
if (is_object($oMenuNode)) {
$oMenuNode->RenderContent($oP, $oAppContext->GetAsHash());
$oP->set_title($oMenuNode->GetLabel());
}
break;
}
$oP->output(); // Display the whole content now !
} catch (CoreException $e) {
require_once(APPROOT.'/setup/setuppage.class.inc.php');
$oP = new SetupPage(Dict::S('UI:PageTitle:FatalError'));
if ($e instanceof SecurityException) {
$oP->add("<h1>".Dict::S('UI:SystemIntrusion')."</h1>\n");
} else {
$oP->add("<h1>".Dict::S('UI:FatalErrorMessage')."</h1>\n");
}
$oP->error(Dict::Format('UI:Error_Details', $e->getHtmlDesc()));
$oP->output();
if (MetaModel::IsLogEnabledIssue()) {
if (MetaModel::IsValidClass('EventIssue')) {
try {
$oLog = new EventIssue();
$oLog->Set('message', $e->getMessage());
$oLog->Set('userinfo', '');
$oLog->Set('issue', $e->GetIssue());
$oLog->Set('impact', 'Page could not be displayed');
$oLog->Set('callstack', $e->getTrace());
$oLog->Set('data', $e->getContextData());
$oLog->DBInsertNoReload();
} catch (Exception $e) {
IssueLog::Error("Failed to log issue into the DB");
}
}
IssueLog::Error($e->getMessage());
}
// For debugging only
//throw $e;
} catch (Exception $e) {
require_once(APPROOT.'/setup/setuppage.class.inc.php');
$oP = new SetupPage(Dict::S('UI:PageTitle:FatalError'));
$oP->add("<h1>".Dict::S('UI:FatalErrorMessage')."</h1>\n");
$oP->error(Dict::Format('UI:Error_Details', $e->getMessage()));
$oP->output();
if (MetaModel::IsLogEnabledIssue()) {
if (MetaModel::IsValidClass('EventIssue')) {
try {
$oLog = new EventIssue();
$oLog->Set('message', $e->getMessage());
$oLog->Set('userinfo', '');
$oLog->Set('issue', 'PHP Exception');
$oLog->Set('impact', 'Page could not be displayed');
$oLog->Set('callstack', $e->getTrace());
$oLog->Set('data', array());
$oLog->DBInsertNoReload();
} catch (Exception $e) {
IssueLog::Error("Failed to log issue into the DB");
}
}
IssueLog::Error($e->getMessage());
}
}