Bearsampp 2026.9.23
Loading...
Searching...
No Matches
class.action.genSslCertificate.php
Go to the documentation of this file.
1<?php
2/*
3 * Copyright (c) 2021-2026 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
18{
20 private $wbWindow;
22 private $wbLabelName;
24 private $wbInputName;
26 private $wbLabelDest;
28 private $wbInputDest;
30 private $wbBtnDest;
34 private $wbBtnSave;
36 private $wbBtnCancel;
37
39 const GAUGE_SAVE = 2;
40
48 public function __construct($args)
49 {
50 global $bearsamppRoot, $bearsamppLang, $bearsamppWinbinder;
51
52 $initServerName = 'test.local';
53 $initDocumentRoot = Path::formatWindowsPath(Path::getSslPath());
54
55 $bearsamppWinbinder->reset();
56 $this->wbWindow = $bearsamppWinbinder->createAppWindow($bearsamppLang->getValue(Lang::GENSSL_TITLE), 490, 160, WBC_NOTIFY, WBC_KEYDOWN | WBC_KEYUP);
57
58 $this->wbLabelName = $bearsamppWinbinder->createLabel($this->wbWindow, $bearsamppLang->getValue(Lang::NAME) . ' :', 15, 15, 85, null, WBC_RIGHT);
59 $this->wbInputName = $bearsamppWinbinder->createInputText($this->wbWindow, $initServerName, 105, 13, 150, null);
60
61 $this->wbLabelDest = $bearsamppWinbinder->createLabel($this->wbWindow, $bearsamppLang->getValue(Lang::TARGET) . ' :', 15, 45, 85, null, WBC_RIGHT);
62 $this->wbInputDest = $bearsamppWinbinder->createInputText($this->wbWindow, $initDocumentRoot, 105, 43, 190, null, null, WBC_READONLY);
63 $this->wbBtnDest = $bearsamppWinbinder->createButton($this->wbWindow, $bearsamppLang->getValue(Lang::BUTTON_BROWSE), 300, 43, 110);
64
65 $this->wbProgressBar = $bearsamppWinbinder->createProgressBar($this->wbWindow, self::GAUGE_SAVE + 1, 15, 97, 275);
66 $this->wbBtnSave = $bearsamppWinbinder->createButton($this->wbWindow, $bearsamppLang->getValue(Lang::BUTTON_SAVE), 300, 92);
67 $this->wbBtnCancel = $bearsamppWinbinder->createButton($this->wbWindow, $bearsamppLang->getValue(Lang::BUTTON_CANCEL), 387, 92);
68
69 $bearsamppWinbinder->setHandler($this->wbWindow, $this, 'processWindow');
70 $bearsamppWinbinder->mainLoop();
71 $bearsamppWinbinder->reset();
72 }
73
86 public function processWindow($window, $id, $ctrl, $param1, $param2)
87 {
88 global $bearsamppLang, $bearsamppOpenSsl, $bearsamppWinbinder;
89
90 $name = $bearsamppWinbinder->getText($this->wbInputName[WinBinder::CTRL_OBJ]);
91 $target = $bearsamppWinbinder->getText($this->wbInputDest[WinBinder::CTRL_OBJ]);
92
93 switch ($id) {
94 case $this->wbBtnDest[WinBinder::CTRL_ID]:
95 $target = $bearsamppWinbinder->sysDlgPath($window, $bearsamppLang->getValue(Lang::GENSSL_PATH), $target);
96 if ($target && is_dir($target)) {
97 $bearsamppWinbinder->setText($this->wbInputDest[WinBinder::CTRL_OBJ], $target . '\\');
98 }
99 break;
100 case $this->wbBtnSave[WinBinder::CTRL_ID]:
101 $bearsamppWinbinder->setProgressBarMax($this->wbProgressBar, self::GAUGE_SAVE + 1);
102 $bearsamppWinbinder->incrProgressBar($this->wbProgressBar);
103
104 $target = Path::formatUnixPath($target);
105 if ($bearsamppOpenSsl->createCrt($name, $target)) {
106 $bearsamppWinbinder->incrProgressBar($this->wbProgressBar);
107 $bearsamppWinbinder->messageBoxInfo(
108 sprintf($bearsamppLang->getValue(Lang::GENSSL_CREATED), $name),
110 );
111 $bearsamppWinbinder->destroyWindow($window);
112 } else {
113 $bearsamppWinbinder->messageBoxError($bearsamppLang->getValue(Lang::GENSSL_CREATED_ERROR), $bearsamppLang->getValue(Lang::GENSSL_TITLE));
114 $bearsamppWinbinder->resetProgressBar($this->wbProgressBar);
115 }
116 break;
117 case IDCLOSE:
118 case $this->wbBtnCancel[WinBinder::CTRL_ID]:
119 $bearsamppWinbinder->destroyWindow($window);
120 break;
121 }
122 }
123}
124
global $bearsamppLang
global $bearsamppRoot
processWindow($window, $id, $ctrl, $param1, $param2)
const GENSSL_TITLE
const GENSSL_CREATED
const NAME
const BUTTON_BROWSE
const BUTTON_CANCEL
const GENSSL_PATH
const BUTTON_SAVE
const GENSSL_CREATED_ERROR
const TARGET
static getSslPath($aetrayPath=false)
static formatWindowsPath($path)
static formatUnixPath($path)