1: | <?php |
2: | |
3: | |
4: | |
5: | |
6: | |
7: | |
8: | namespace Aurora\Modules\MailChangePasswordPoppassdExtendedPlugin; |
9: | |
10: | use function Sabre\Uri\split; |
11: | |
12: | |
13: | |
14: | |
15: | |
16: | |
17: | |
18: | |
19: | |
20: | |
21: | |
22: | |
23: | class Module extends \Aurora\Modules\MailChangePasswordPoppassdPlugin\Module |
24: | { |
25: | public function init() |
26: | { |
27: | parent::init(); |
28: | $this->subscribeEvent('ChangePassword::before', array($this, 'onBeforeChangePassword')); |
29: | $this->subscribeEvent('Core::Login::before', array($this, 'onBeforeLogin')); |
30: | } |
31: | |
32: | |
33: | |
34: | |
35: | public static function getInstance() |
36: | { |
37: | return parent::getInstance(); |
38: | } |
39: | |
40: | |
41: | |
42: | |
43: | public static function Decorator() |
44: | { |
45: | return parent::Decorator(); |
46: | } |
47: | |
48: | |
49: | |
50: | |
51: | public function getModuleSettings() |
52: | { |
53: | return $this->oModuleSettings; |
54: | } |
55: | |
56: | public function onBeforeChangePassword(&$aArgs, &$mResult) |
57: | { |
58: | if (!isset($aArgs['AccountId'])) { |
59: | $aUserInfo = \Aurora\System\Api::getAuthenticatedUserInfo( |
60: | \Aurora\System\Api::getAuthenticatedUserAuthToken() |
61: | ); |
62: | |
63: | if (isset($aUserInfo['account'])) { |
64: | $aArgs['AccountId'] = (int) $aUserInfo['account']; |
65: | } |
66: | } |
67: | } |
68: | |
69: | |
70: | public function onBeforeLogin($aArgs, &$mResult, &$mSubResult) |
71: | { |
72: | if (null === $this->oPopPassD) { |
73: | $this->oPopPassD = new \Aurora\Modules\MailChangePasswordPoppassdPlugin\Poppassd( |
74: | $this->oModuleSettings->Host, |
75: | $this->oModuleSettings->Port |
76: | ); |
77: | } |
78: | |
79: | if ($this->oPopPassD && $this->oPopPassD->Connect()) { |
80: | $sLogin = $aArgs['Login']; |
81: | $sPassword = $aArgs['Password']; |
82: | try { |
83: | $this->oPopPassD->SendLine('getuser ' . $sLogin); |
84: | |
85: | if ($this->oPopPassD->CheckResponse($this->oPopPassD->ReadLine())) { |
86: | if ($this->oPopPassD->SendLine('pass ' . $sPassword) && $this->oPopPassD->CheckResponse($this->oPopPassD->ReadLine())) { |
87: | while ($sLine = $this->oPopPassD->ReadLine()) { |
88: | $aLine = \explode(' ', $sLine); |
89: | if ($aLine[0] == 200) { |
90: | if (\count($aLine) === 3) { |
91: | $aResult[$aLine[1]] = \trim($aLine[2]); |
92: | } |
93: | if (\strtolower(\trim($aLine[1])) === 'complete.') { |
94: | break; |
95: | } |
96: | } |
97: | } |
98: | |
99: | $iExpire = isset($aResult['EXPIRE']) ? (int) $aResult['EXPIRE'] : 0; |
100: | $iCfgGrace = isset($aResult['CFGGRACE']) ? (int) $aResult['CFGGRACE'] : 0; |
101: | $iCfgWarn = isset($aResult['CFGWARN']) ? (int) $aResult['CFGWARN'] : 0; |
102: | |
103: | $mSubResult = [ |
104: | 'CallHelpdesk' => ($iExpire < 0 && abs($iExpire) > $iCfgGrace) ? true : false, |
105: | 'ChangePassword' => ($iExpire <= $iCfgWarn) ? true : false, |
106: | 'DaysBeforeExpire' => $iExpire, |
107: | ]; |
108: | } |
109: | } |
110: | } catch (\Exception $oException) { |
111: | $this->oPopPassD->Disconnect(); |
112: | throw $oException; |
113: | } |
114: | } |
115: | } |
116: | } |
117: | |