/
index.php
304 lines (276 loc) · 11.1 KB
/
index.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="ja">
<head profile="http://gmpg.org/xfn/11">
<title>cloud.jp.oracle.com</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="description" content="Oracle Database Cloud" />
<?php require_once './css.php';?>
</head>
<?php
set_time_limit(600);
require_once './Role.php';
require_once './Resource.php';
require_once './config.php';
require_once './tool.php';
require_once './Parse.php';
require_once './Drive.php';
require_once './Customer.php';
$parse = new Parse();
// Connect to Database
$conn_db = oci_connect(DB_USER, DB_PASSWORD, DB_SERVICE, '', OCI_SYSDBA);
if ($conn_db == FALSE) {
array_push($parse->err_msg, "データベースインスタンスに接続できませんでした。");
}
err_chk($conn_db, $parse->err_msg);
// Fetch ALL ASM Nodes
$state_id = oci_parse($conn_db, 'SELECT inst_name FROM v$active_instances');
$result = oci_execute($state_id);
$array_asm_all_nodes = array();
while ($row = oci_fetch_array($state_id, OCI_BOTH)) {
$array_inst_name = explode(':', $row['INST_NAME']);
array_push($array_asm_all_nodes, $array_inst_name[0]);
}
// Connect to ASM Instance #1
$conn_asm = oci_connect(ASM_USER, ASM_PASSWORD, $array_asm_all_nodes[0] . '/' . ASM_SERVICE, '', OCI_SYSASM);
if ($conn_asm == FALSE) {
array_push($parse->err_msg, "ASMインスタンスに接続できませんでした。");
}
err_chk($conn_asm, $parse->err_msg);
if (isset($_REQUEST["op"])) {
$op = $_REQUEST["op"];
} else {
$op = null;
}
//// Check if Database has been setup for Oracle Database Cloud.
$role = new Role();
$resource = new Resource();
// Check if Role has been created.
$flag_role_required = FALSE;
$result = $role->exist($conn_db, CLOUD_USER);
if ($result == FALSE) {
$op = 'initialize';
$flag_role_required = TRUE;
}
// Check if Consumer Groups have been created.
$flag_consumer_group_required = FALSE;
foreach ($array_consumer_group as $consumer_group) {
$result = $resource->exist_consumer_group($conn_db, $consumer_group);
if ($result == FALSE) {
$op = 'initialize';
$flag_consumer_group_required = TRUE;
}
}
// Check if Plan has been created.
$flag_resource_plan_required = FALSE;
$result = $resource->exist_resource_plan($conn_db, RESOURCE_PLAN);
if ($result == FALSE) {
$op = 'initialize';
$flag_resource_plan_required = TRUE;
}
// Check if Plan has been enabled.
$result = $resource->status_resource_plan($conn_db, RESOURCE_PLAN);
if ($result == 'DISABLED') {
$op = 'initialize';
$flag_resource_plan_disabled = TRUE;
}
// Sanitize
if (isset($_REQUEST["confirmed"])) {
$confirmed = TRUE;
} else {
$confirmed = FALSE;
}
if (isset($_REQUEST["customer_id"])) {
$customer_id = $parse->id($_REQUEST["customer_id"]);
err_chk($customer_id, $parse->err_msg);
}
if (isset($_REQUEST["customer_password"])) {
$customer_password = $parse->password($_REQUEST["customer_password"]);
err_chk($customer_password, $parse->err_msg);
}
if (isset($_REQUEST["consumer_group"])) {
$consumer_group = $parse->select($_REQUEST["consumer_group"], $array_consumer_group);
err_chk($consumer_group, $parse->err_msg);
}
if (isset($_REQUEST["disk_type"])) {
$array_flipped_disk_type = array_flip($array_disk_type);
$disk_type = $parse->select($_REQUEST["disk_type"], $array_flipped_disk_type);
err_chk($disk_type, $parse->err_msg);
}
switch ($op) {
case 'initialize':
if ($confirmed == TRUE) {
$role = new Role();
$resource = new Resource();
// Create Role.
if ($flag_role_required == TRUE) {
$result = $role->create($conn_db, CLOUD_USER);
err_chk($result, $role->err_msg);
}
// Create Consumer Groups.
if ($flag_consumer_group_required == TRUE) {
foreach ($array_consumer_group as $consumer_group) {
$result = $resource->create_consumer_group($conn_db, $consumer_group);
err_chk($result, $resource->err_msg);
}
}
// Create Resource Plan.
if ($flag_resource_plan_required == TRUE) {
$result = $resource->create_resource_plan($conn_db, RESOURCE_PLAN, $array_consumer_group, $array_cpu_utilization_limit);
err_chk($result, $resource->err_msg);
}
// Enable Resource Plan.
if ($flag_resource_plan_disabled == TRUE) {
$result = $resource->enable_resource_plan($conn_db, RESOURCE_PLAN);
err_chk($result, $resource->err_msg);
}
} else {
echo "データベースはOracle Database Cloud用に初期化が必要です。初期化しますか?<br/>";
echo "<a href='/'>いいえ</a><br/>\n";
echo "<a href='?flag_initialize_required=TRUE&op=$op&confirmed=TRUE'>はい、どうぞ</a><br/>\n";
exit;
}
break;
case 'create_customer':
$customer = new Customer();
$customer_id = CUSTOMER_PREFIX . $customer_id;
$result = $customer->create($conn_asm, $conn_db, $customer_id, $customer_password, $disk_type);
err_chk($result, $customer->err_msg);
break;
case 'delete_customer':
$customer = new Customer();
if ($confirmed == TRUE) {
$result = $customer->delete($conn_asm, $conn_db, $customer_id);
err_chk($result, $customer->err_msg);
} else {
echo str_replace(CUSTOMER_PREFIX, "", $customer_id) . "を削除します。よろしいですか?<br/>\n";
echo "<a href='/'>いいえ</a><br/>\n";
echo "<a href='?customer_id=$customer_id&op=$op&confirmed=TRUE'>はい、どうぞ</a><br/>\n";
exit;
}
break;
case 'update_consumer_group':
$customer = new Customer();
$result = $customer->update_consumer_group($conn_db, $customer_id, $consumer_group);
err_chk($result, $customer->err_msg);
break;
case 'migrate_disk':
$customer = new Customer();
$result = $customer->migrate_disk($conn_asm, $customer_id, $disk_type);
err_chk($result, $customer->err_msg);
break;
default:
break;
}
?>
<body>
<div id=head>
<h1 style="margin: 10px 20px 10px 0px;"><a href="/"><img src='logo.png' style='border: solid 2px #dddddd; padding: 3px'/></a></h1>
</div>
<div id=middle>
<div class=box>
<h3>新しいカスタマーの作成</h3>
<form action="/" method=post>
<table style='text-align: left; margin: 0px auto 0px auto;'>
<tr>
<td><input type=text name=customer_id></input></td>
<td>カスタマーID</td>
</tr>
<tr>
<td><input type=password name=customer_password></input></td>
<td>パスワード</td>
</tr>
<tr>
<td style="text-align: right">
<select name=disk_type>
<?php
$drive = new Drive();
foreach ($array_disk_type as $disk_type => $needle) {
$available_disk_num = $drive->fetch_available_disk_num($conn_asm, $disk_type);
if ($available_disk_num == 0) {
continue;
}
if ($disk_type == DEFAULT_DISK_TYPE) {
echo "<option value=$disk_type selected>$disk_type (残" . $available_disk_num . ")</option>\n";
} else {
echo "<option value=$disk_type>$disk_type (残" . $available_disk_num . ")</option>\n";
}
}
?>
</select>
</td>
<td>ディスクタイプ</td>
</tr>
<tr>
<td style='text-align: right'><input type=submit value="作成"></input></td>
<td> </td>
</tr>
<input type=hidden name=op value="create_customer"></input>
</table>
</form>
<?php
if ($op == 'create_customer') {
echo "<div style='margin: 10px 0px 10px 0px'>\n";
echo "新しいカスタマー\"" . strtoupper(str_replace(CUSTOMER_PREFIX, "", $customer_id)) . "\"が作成されました。<br/>\n";
echo "接続先:<span style='color: #cc0000'>" . strtoupper($customer_id) . "/" . $customer_password . "@" . CUSTOMER_SERVICE . "</span><br/>\n";
echo "</div>\n";
}
?>
</div>
<div class=box>
<h3>既存カスタマー</h3>
<?php
$state_id = oci_parse($conn_db, "select USERNAME, INITIAL_RSRC_CONSUMER_GROUP from dba_users where username like '" . CUSTOMER_PREFIX . "%' order by username");
$result = oci_execute($state_id);
if ($result == FALSE) {
echo "エラー: カスタマーリストを取得できませんでした。";
} else {
echo "<table style='margin: 0px auto 0px auto;'>\n";
echo "<tr>\n";
echo "<th>カスタマー</th>";
echo "<th style='padding: 0px 7px 0px 7px; border-bottom: solid 1px #ffffff;'> </th>\n";
echo "<th colspan=3>CPUプラン</th>";
echo "<th style='padding: 0px 7px 0px 7px; border-bottom: solid 1px #ffffff;'> </th>\n";
echo "<th colspan=2>ディスクタイプ</th>";
echo "<th style='padding: 0px 7px 0px 7px; border-bottom: solid 1px #ffffff;'> </th>\n";
echo "<th> </th>\n";
echo "</tr>\n";
while ($row = oci_fetch_array($state_id, OCI_BOTH)) {
echo "<tr>\n";
echo "<td class=matrix_td style='text-align: right;'>" . str_replace(CUSTOMER_PREFIX, "", $row['USERNAME']) . "</td>\n";
echo "<td> </td>\n";
foreach ($array_consumer_group as $consumer_group) {
echo "<td class=matrix_td>\n";
if ($row['INITIAL_RSRC_CONSUMER_GROUP'] == $consumer_group) {
echo "<span class=selected>$consumer_group</span>\n";
} else {
echo "<a href='?customer_id=" . $row['USERNAME'] . "&op=update_consumer_group&consumer_group=$consumer_group'>$consumer_group</a>\n";
}
echo "</td>\n";
}
echo "<td> </td>\n";
$sql2 = "select v\$asm_disk.name from v\$asm_disk join v\$asm_diskgroup on v\$asm_disk.group_number = v\$asm_diskgroup.group_number where v\$asm_diskgroup.name = '" . $row['USERNAME'] . "'";
$state_id2 = oci_parse($conn_asm, $sql2);
$result2 = oci_execute($state_id2);
$row2 = oci_fetch_array($state_id2, OCI_BOTH);
$disk_name = $row2['NAME'];
$disk_type = str_replace($row['USERNAME'] . "_", "", $disk_name);
foreach ($array_disk_type as $k => $v) {
echo "<td class=matrix_td>\n";
if ($disk_type == $k) {
echo "<span class=selected>$k</span>\n";
} else {
echo "<a href='?customer_id=" . $row['USERNAME'] . "&op=migrate_disk&disk_type=$k'>$k</a>\n";
}
echo "</td>\n";
}
echo "<td> </td>\n";
echo "<td class=matrix_td><a href='?customer_id=" . $row['USERNAME'] . "&op=delete_customer'>削除</a></td>\n";
echo "</tr>\n";
}
echo "</table>\n";
}
?>
</div>
</div>
</body>
</html>