source: trunk/www/Module/RemoteConsole/Model.php

Last change on this file was 95, checked in by chronos, 10 years ago
  • Upraveno: Soubory různých logických částí systému odděleny do aplikačních modulů.
File size: 1.5 KB
Line 
1<?php
2
3include_once(dirname(__FILE__).'/../../Base/Model.php');
4
5define('CONNECTION_ERROR', 'Připojení k %s:%s se nezdařilo.');
6define('NO_SUCH_USER', 'Neznámý uživatel.');
7define('WRONG_PASS', 'Špatné heslo.');
8define('NOT_ENOUGH_PRIVILEGES', 'Nedostatečné oprávnění uživatele.');
9define('AUTH_ERROR', 'Chyba během přihlašování.');
10
11class 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}
Note: See TracBrowser for help on using the repository browser.