| 1: | <?php |
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | namespace Aurora\Modules\MailChangePasswordPoppassdPlugin; |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: | |
| 16: | |
| 17: | |
| 18: | class Poppassd extends \Aurora\System\Net\AbstractProtocol |
| 19: | { |
| 20: | |
| 21: | |
| 22: | |
| 23: | public function Connect() |
| 24: | { |
| 25: | $bResult = false; |
| 26: | if (parent::Connect()) { |
| 27: | $bResult = $this->CheckResponse($this->GetNextLine(), 0); |
| 28: | } |
| 29: | return $bResult; |
| 30: | } |
| 31: | |
| 32: | |
| 33: | |
| 34: | |
| 35: | |
| 36: | |
| 37: | public function Login($sLogin, $sPassword) |
| 38: | { |
| 39: | return $this->SendCommand('user ' . $sLogin, array(), 1) && $this->SendCommand('pass ' . $sPassword, array($sPassword), 1); |
| 40: | } |
| 41: | |
| 42: | |
| 43: | |
| 44: | |
| 45: | |
| 46: | |
| 47: | public function ConnectAndLogin($sLogin, $sPassword) |
| 48: | { |
| 49: | return $this->Connect() && $this->Login($sLogin, $sPassword); |
| 50: | } |
| 51: | |
| 52: | |
| 53: | |
| 54: | |
| 55: | public function Disconnect() |
| 56: | { |
| 57: | return parent::Disconnect(); |
| 58: | } |
| 59: | |
| 60: | |
| 61: | |
| 62: | |
| 63: | public function Logout() |
| 64: | { |
| 65: | return $this->SendCommand('quit', array(), 0); |
| 66: | } |
| 67: | |
| 68: | |
| 69: | |
| 70: | |
| 71: | public function LogoutAndDisconnect() |
| 72: | { |
| 73: | return $this->Logout() && $this->Disconnect(); |
| 74: | } |
| 75: | |
| 76: | |
| 77: | |
| 78: | |
| 79: | |
| 80: | public function NewPass($sNewPassword) |
| 81: | { |
| 82: | $bResult = false; |
| 83: | $sMessage = ''; |
| 84: | $aLines = []; |
| 85: | if ($this->WriteLine('newpass ' . $sNewPassword, array($sNewPassword))) { |
| 86: | while ($sLine = $this->GetNextLine()) { |
| 87: | $aLine = \explode(' ', $sLine); |
| 88: | if ($aLine[0] == 200) { |
| 89: | $bResult = true; |
| 90: | break; |
| 91: | } |
| 92: | if ($aLine[0] == 500) { |
| 93: | $bResult = false; |
| 94: | $aLines[] = substr($sLine, 4) ; |
| 95: | } |
| 96: | } |
| 97: | } |
| 98: | if (!$bResult) { |
| 99: | $sMessage = implode("\n", $aLines); |
| 100: | } |
| 101: | |
| 102: | return [$bResult, $sMessage]; |
| 103: | |
| 104: | |
| 105: | } |
| 106: | |
| 107: | |
| 108: | |
| 109: | |
| 110: | |
| 111: | public function SendLine($sCmd) |
| 112: | { |
| 113: | return $this->WriteLine($sCmd); |
| 114: | } |
| 115: | |
| 116: | |
| 117: | |
| 118: | |
| 119: | |
| 120: | |
| 121: | |
| 122: | public function SendCommand($sCmd, $aHideValues = array(), $iCheckType = 0) |
| 123: | { |
| 124: | if ($this->WriteLine($sCmd, $aHideValues)) { |
| 125: | return $this->CheckResponse($this->GetNextLine(), $iCheckType); |
| 126: | } |
| 127: | |
| 128: | return false; |
| 129: | } |
| 130: | |
| 131: | |
| 132: | |
| 133: | |
| 134: | public function GetNextLine() |
| 135: | { |
| 136: | return $this->ReadLine(); |
| 137: | } |
| 138: | |
| 139: | |
| 140: | |
| 141: | |
| 142: | |
| 143: | |
| 144: | public function CheckResponse($sResponse, $iCheckType = 0) |
| 145: | { |
| 146: | switch ($iCheckType) { |
| 147: | case 0: |
| 148: | return (bool) preg_match('/^2\d\d/', $sResponse); |
| 149: | break; |
| 150: | case 1: |
| 151: | return (bool) preg_match('/^[23]\d\d/', $sResponse); |
| 152: | break; |
| 153: | } |
| 154: | |
| 155: | return false; |
| 156: | } |
| 157: | } |
| 158: | |