1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231:
| unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdTCPConnection, IdSimpleServer, ShellApi, IdTCPServer, IdContext, IdThread, Sockets, IniFiles, Tlhelp32;
type TForm1 = class(TForm) anz: TMemo; IdTCPServer1: TIdTCPServer; procedure anzChange(Sender: TObject); procedure IdTCPServer1ListenException(AThread: TIdListenerThread; AException: Exception); procedure IdTCPServer1Exception(AContext: TIdContext; AException: Exception); procedure IdTCPServer1Disconnect(AContext: TIdContext); procedure IdTCPServer1Connect(AContext: TIdContext); procedure FormDestroy(Sender: TObject); procedure IdTCPServer1Execute(AContext: TIdContext); procedure sc_restart; procedure FormCreate(Sender: TObject); private tcp_buffer:string; login_password,sc_filename:String; apppath:string; public end;
var Form1: TForm1;
implementation
{$R *.dfm}
procedure KillProcess(dwProcID: DWORD); var hProcess : Cardinal; dw : DWORD; begin hProcess := OpenProcess(SYNCHRONIZE or PROCESS_TERMINATE, False, dwProcID); TerminateProcess(hProcess, 0); dw := WaitForSingleObject(hProcess, 5000); case dw of WAIT_OBJECT_0: Messagebox(Application.Handle, 'Prozess wurde beendet.', 'Prozess beenden', MB_ICONINFORMATION); WAIT_TIMEOUT: begin Messagebox(Application.Handle, 'Es konnte innerhalb von fünf Sekundnen ein Prozeß nicht beendet werden!', 'Prozess beenden', MB_ICONSTOP); CloseHandle(hProcess); exit; end; WAIT_FAILED: begin RaiseLastOSError; CloseHandle(hProcess); exit; end; end; CloseHandle(hProcess); end;
function KillTask(ExeFileName: string): Integer; const PROCESS_TERMINATE = $0001; var ContinueLoop: BOOL; FSnapshotHandle: THandle; FProcessEntry32: TProcessEntry32; begin Result := 0; FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); FProcessEntry32.dwSize := SizeOf(FProcessEntry32); ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32);
while Integer(ContinueLoop) <> 0 do begin if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) = UpperCase(ExeFileName)) or (UpperCase(FProcessEntry32.szExeFile) = UpperCase(ExeFileName))) then Result := Integer(TerminateProcess( OpenProcess(PROCESS_TERMINATE, BOOL(0), FProcessEntry32.th32ProcessID), 0)); ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32); end; CloseHandle(FSnapshotHandle); end;
procedure TForm1.sc_restart; begin
if FileExists(apppath+sc_filename) then begin KillTask(sc_filename); ShellExecute(Application.Handle, 'open', PChar(apppath+sc_filename), Nil, Nil, SW_NORMAL); end else anz.Lines.Add('ERORR NO FILE '+apppath+sc_filename);
end;
procedure TForm1.FormCreate(Sender: TObject); var ini:TIniFile; begin tcp_buffer:=''; apppath:=ExtractFilePath(ParamStr(0));
Randomize;
ini:=TIniFile.Create(ChangeFileExt(Application.ExeName, '.INI' )); if not FileExists(ini.FileName) then begin ini.WriteString('shoutcast','filename_sc','sc_serv.exe'); ini.WriteString('login','password',inttostr(Random(99999999))); end; sc_filename:=ini.ReadString('shoutcast','filename_sc','sc_serv.exe'); login_password:=ini.ReadString('login','password',inttostr(Random(99999999))); ini.Free;
IdTCPServer1.Active:=true;
if not FileExists(apppath+sc_filename) then anz.Lines.Add('ERORR NO FILE '+apppath+sc_filename); end;
procedure TForm1.IdTCPServer1Execute(AContext: TIdContext); var TCPData:TStringList; line,tmp:String; OutOfBuffer:Boolean; i:integer; begin tcp_buffer:=Acontext.Connection.IOHandler.ReadLnWait(1000); TCPData:= TStringList.Create; OutOfBuffer:=false;
TCPData.Text:=tcp_buffer; tcp_buffer:='';
while ((TCPData.Count>0) and not(OutOfBuffer)) do begin
anz.Lines.Add('Read'); line:=TCPData[0]; if line='close' then begin Acontext.Connection.Disconnect; TCPData.Delete(0); end else if line='restart' then begin if TCPData.Count>1 then begin if login_password=TCPData[1] then begin anz.Lines.Add('Shoutcast restart'); sc_restart; Acontext.Connection.IOHandler.WriteLn('restart_ok'); end else begin anz.Lines.Add('BAD PASSWORD'); Acontext.Connection.IOHandler.WriteLn('pw_false'); end; for i:=1 to 2 do TCPData.Delete(0); end else OutOfBuffer:=true;
end else begin TCPData.Delete(0); end;
end;
if OutOfBuffer then tcp_buffer:=TCPData.Text;
TCPData.Free; end;
procedure TForm1.FormDestroy(Sender: TObject); begin IdTCPServer1.Active:=false; end;
procedure TForm1.IdTCPServer1Connect(AContext: TIdContext); begin anz.Lines.Add('OPEN '+AContext.Binding.PeerIP); end;
procedure TForm1.IdTCPServer1Disconnect(AContext: TIdContext); begin anz.Lines.Add('CLOSE '+AContext.Binding.PeerIP); end;
procedure TForm1.IdTCPServer1Exception(AContext: TIdContext; AException: Exception); begin anz.Lines.Add('ERORR: '+AException.Message); end;
procedure TForm1.IdTCPServer1ListenException(AThread: TIdListenerThread; AException: Exception); begin anz.Lines.Add('ERORR LISTEN: '+AException.Message); end;
procedure TForm1.anzChange(Sender: TObject); begin
while anz.Lines.Count>100 do anz.Lines.Delete(0);
end;
end. |