2024.8.23
Loading...
Searching...
No Matches
class.action.changeDbRootPwd.php
Go to the documentation of this file.
1<?php
2/*
3 * Copyright (c) 2021-2024 Bearsampp
4 * License: GNU General Public License version 3 or later; see LICENSE.txt
5 * Author: Bear
6 * Website: https://bearsampp.com
7 * Github: https://github.com/Bearsampp
8 */
9
10/**
11 * Class ActionChangeDbRootPwd
12 * Handles the process of changing the root password for various database systems.
13 */
15{
16 /**
17 * @var object The database binary object (MySQL, MariaDB, PostgreSQL).
18 */
19 private $bin;
20
21 /**
22 * @var int The count of process actions required for the progress bar.
23 */
25
26 /**
27 * @var object The main window object created by WinBinder.
28 */
29 private $wbWindow;
30
31 /**
32 * @var object The label for the current password input field.
33 */
35
36 /**
37 * @var object The input field for the current password.
38 */
40
41 /**
42 * @var object The label for the new password input field.
43 */
45
46 /**
47 * @var object The input field for the new password.
48 */
50
51 /**
52 * @var object The label for the confirmation of the new password input field.
53 */
55
56 /**
57 * @var object The input field for the confirmation of the new password.
58 */
60
61 /**
62 * @var object The progress bar to show the progress of the password change process.
63 */
65
66 /**
67 * @var object The finish button to submit the password change.
68 */
69 private $wbBtnFinish;
70
71 /**
72 * @var object The cancel button to abort the password change process.
73 */
74 private $wbBtnCancel;
75
76 /**
77 * ActionChangeDbRootPwd constructor.
78 * Initializes the window and controls for changing the database root password.
79 *
80 * @param array $args The arguments passed to the constructor, typically containing the database type.
81 */
82 public function __construct($args)
83 {
84 global $bearsamppLang, $bearsamppBins, $bearsamppWinbinder;
85
86 if (isset($args[0]) && !empty($args[0])) {
87 $this->bin = $bearsamppBins->getMysql();
88 $this->cntProcessActions = 11;
89 if ($args[0] == $bearsamppBins->getMariadb()->getName()) {
90 $this->bin = $bearsamppBins->getMariadb();
91 $this->cntProcessActions = 11;
92 } elseif ($args[0] == $bearsamppBins->getPostgresql()->getName()) {
93 $this->bin = $bearsamppBins->getPostgresql();
94 $this->cntProcessActions = 10;
95 }
96
97 $bearsamppWinbinder->reset();
98 $this->wbWindow = $bearsamppWinbinder->createAppWindow(sprintf($bearsamppLang->getValue(Lang::CHANGE_DB_ROOT_PWD_TITLE), $args[0]), 400, 290, WBC_NOTIFY, WBC_KEYDOWN | WBC_KEYUP);
99
100 $this->wbLabelCurrentPwd = $bearsamppWinbinder->createLabel($this->wbWindow, $bearsamppLang->getValue(Lang::CHANGE_DB_ROOT_PWD_CURRENTPWD_LABEL), 15, 15, 280);
101 $this->wbInputCurrentPwd = $bearsamppWinbinder->createInputText($this->wbWindow, null, 15, 40, 200, null, null, WBC_MASKED);
102
103 $this->wbLabelNewPwd1 = $bearsamppWinbinder->createLabel($this->wbWindow, $bearsamppLang->getValue(Lang::CHANGE_DB_ROOT_PWD_NEWPWD1_LABEL), 15, 80, 280);
104 $this->wbInputNewPwd1 = $bearsamppWinbinder->createInputText($this->wbWindow, null, 15, 105, 200, null, null, WBC_MASKED);
105
106 $this->wbLabelNewPwd2 = $bearsamppWinbinder->createLabel($this->wbWindow, $bearsamppLang->getValue(Lang::CHANGE_DB_ROOT_PWD_NEWPWD2_LABEL), 15, 145, 280);
107 $this->wbInputNewPwd2 = $bearsamppWinbinder->createInputText($this->wbWindow, null, 15, 170, 200, null, null, WBC_MASKED);
108
109 $this->wbProgressBar = $bearsamppWinbinder->createProgressBar($this->wbWindow, $this->cntProcessActions + 1, 15, 227, 190);
110 $this->wbBtnFinish = $bearsamppWinbinder->createButton($this->wbWindow, $bearsamppLang->getValue(Lang::BUTTON_FINISH), 210, 222);
111 $this->wbBtnCancel = $bearsamppWinbinder->createButton($this->wbWindow, $bearsamppLang->getValue(Lang::BUTTON_CANCEL), 297, 222);
112
113 $bearsamppWinbinder->setHandler($this->wbWindow, $this, 'processWindow');
114 $bearsamppWinbinder->setFocus($this->wbInputCurrentPwd[WinBinder::CTRL_OBJ]);
115 $bearsamppWinbinder->mainLoop();
116 $bearsamppWinbinder->reset();
117 }
118 }
119
120 /**
121 * Processes the window events and handles the password change logic.
122 *
123 * @param object $window The window object.
124 * @param int $id The control ID that triggered the event.
125 * @param object $ctrl The control object that triggered the event.
126 * @param mixed $param1 Additional parameter 1.
127 * @param mixed $param2 Additional parameter 2.
128 */
129 public function processWindow($window, $id, $ctrl, $param1, $param2)
130 {
131 global $bearsamppLang, $bearsamppWinbinder;
132 $boxTitle = sprintf($bearsamppLang->getValue(Lang::CHANGE_DB_ROOT_PWD_TITLE), $this->bin);
133 $currentPwd = $bearsamppWinbinder->getText($this->wbInputCurrentPwd[WinBinder::CTRL_OBJ]);
134 $newPwd1 = $bearsamppWinbinder->getText($this->wbInputNewPwd1[WinBinder::CTRL_OBJ]);
135 $newPwd2 = $bearsamppWinbinder->getText($this->wbInputNewPwd2[WinBinder::CTRL_OBJ]);
136
137 switch ($id) {
138 case $this->wbBtnFinish[WinBinder::CTRL_ID]:
139 $bearsamppWinbinder->incrProgressBar($this->wbProgressBar);
140 if ($newPwd1 != $newPwd2) {
141 $bearsamppWinbinder->messageBoxWarning($bearsamppLang->getValue(Lang::CHANGE_DB_ROOT_PWD_NOTSAME_ERROR), $boxTitle);
142 $bearsamppWinbinder->setText($this->wbInputNewPwd1[WinBinder::CTRL_OBJ], '');
143 $bearsamppWinbinder->setText($this->wbInputNewPwd2[WinBinder::CTRL_OBJ], '');
144 $bearsamppWinbinder->setFocus($this->wbInputNewPwd1[WinBinder::CTRL_OBJ]);
145 $bearsamppWinbinder->resetProgressBar($this->wbProgressBar);
146 break;
147 }
148
149 $checkRootPwd = $this->bin->checkRootPassword($currentPwd, $this->wbProgressBar);
150 if ($checkRootPwd !== true) {
151 $bearsamppWinbinder->messageBoxError(
152 sprintf($bearsamppLang->getValue(Lang::CHANGE_DB_ROOT_PWD_INCORRECT_ERROR), $this->bin->getName(), $checkRootPwd),
153 $boxTitle
154 );
155 $bearsamppWinbinder->setText($this->wbInputCurrentPwd[WinBinder::CTRL_OBJ], '');
156 $bearsamppWinbinder->setFocus($this->wbInputCurrentPwd[WinBinder::CTRL_OBJ]);
157 $bearsamppWinbinder->resetProgressBar($this->wbProgressBar);
158 break;
159 }
160
161 $changeRootPwd = $this->bin->changeRootPassword($currentPwd, $newPwd1, $this->wbProgressBar);
162 if ($changeRootPwd !== true) {
163 $bearsamppWinbinder->messageBoxError(
164 sprintf($bearsamppLang->getValue(Lang::CHANGE_DB_ROOT_PWD_INCORRECT_ERROR), $this->bin->getName(), $changeRootPwd),
165 $boxTitle
166 );
167 $bearsamppWinbinder->resetProgressBar($this->wbProgressBar);
168 break;
169 }
170
171 $bearsamppWinbinder->messageBoxInfo(
173 $boxTitle);
174 $bearsamppWinbinder->destroyWindow($window);
175 break;
176 case IDCLOSE:
177 case $this->wbBtnCancel[WinBinder::CTRL_ID]:
178 $bearsamppWinbinder->destroyWindow($window);
179 break;
180 }
181 }
182}
global $bearsamppBins
global $bearsamppLang
processWindow($window, $id, $ctrl, $param1, $param2)
const CHANGE_DB_ROOT_PWD_NEWPWD1_LABEL
const CHANGE_DB_ROOT_PWD_NOTSAME_ERROR
const BUTTON_CANCEL
const CHANGE_DB_ROOT_PWD_INCORRECT_ERROR
const BUTTON_FINISH
const CHANGE_DB_ROOT_PWD_TEXT
const CHANGE_DB_ROOT_PWD_NEWPWD2_LABEL
const CHANGE_DB_ROOT_PWD_TITLE
const CHANGE_DB_ROOT_PWD_CURRENTPWD_LABEL