[79] | 1 | <?php
|
---|
| 2 |
|
---|
| 3 | include_once(dirname(__FILE__).'/../../Base/Model.php');
|
---|
| 4 |
|
---|
| 5 | define('CONNECTION_ERROR', 'Připojení k %s:%s se nezdařilo.');
|
---|
| 6 | define('NO_SUCH_USER', 'Neznámý uživatel.');
|
---|
| 7 | define('WRONG_PASS', 'Špatné heslo.');
|
---|
| 8 | define('NOT_ENOUGH_PRIVILEGES', 'Nedostatečné oprávnění uživatele.');
|
---|
| 9 | define('AUTH_ERROR', 'Chyba během přihlašování.');
|
---|
| 10 |
|
---|
| 11 | class RemoteConsole //extends Model
|
---|
| 12 | {
|
---|
| 13 | var $Socket;
|
---|
| 14 | var $Host = 'localhost';
|
---|
| 15 | var $Port = 3443;
|
---|
| 16 | var $UserName = 'administrator';
|
---|
| 17 | var $Password = 'administrator';
|
---|
| 18 | var $WelcomeMessage;
|
---|
| 19 |
|
---|
| 20 | function Open()
|
---|
| 21 | {
|
---|
| 22 | $this->Socket = fsockopen($this->Host, $this->Port);
|
---|
| 23 | if(!$this->Socket) die(sprintf(CONNECTION_ERROR, $this->Host, $this->Port));
|
---|
| 24 | else
|
---|
| 25 | {
|
---|
| 26 | $this->WelcomeMessage = trim(fgets($this->Socket, 1000));
|
---|
| 27 | fputs($this->Socket, 'USER '.$this->UserName."\n");
|
---|
| 28 | fputs($this->Socket, 'PASS '.$this->Password."\n");
|
---|
| 29 | $Line = fgets($this->Socket, 1000);
|
---|
| 30 | if($Line == "-No such user.\r\n") die(NO_SUCH_USER);
|
---|
| 31 | if($Line == "-Wrong pass.\r\n") die(WRONG_PASS);
|
---|
| 32 | if($Line == "-Not enough privileges.\r\n") die(NOT_ENOUGH_PRIVILEGES);
|
---|
| 33 | if($Line != "+Logged in.\r\n") die(AUTH_ERROR.': '.$Line);
|
---|
| 34 | stream_get_line($this->Socket, 1000, 'mangos>');
|
---|
| 35 | }
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | function Close()
|
---|
| 39 | {
|
---|
| 40 | fclose($this->Socket);
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | function Execute($Command)
|
---|
| 44 | {
|
---|
| 45 | fputs($this->Socket, $Command."\n");
|
---|
| 46 | stream_get_line($this->Socket, 1000, 'mangos>');
|
---|
| 47 | $Data = stream_get_line($this->Socket, 100000, 'mangos>');
|
---|
| 48 | return($Data);
|
---|
| 49 | }
|
---|
| 50 | }
|
---|