camera-control-webcam-switc.../main.pas

1080 lines
39 KiB
Plaintext
Raw Normal View History

2020-01-28 22:31:29 +01:00
unit Main;
{$mode objfpc}{$H+}
{$warnings off}
{$hints off}
// Created at 23th of January 2020, by Linuxer (https://gitlab.com/psposito), from scratch with Free Pascal
// Redesigned and further Developed at 28th of January 2020, by Initial developer
2020-01-28 22:31:29 +01:00
// to provide Camera and Mic status alone with On/Off and Mute/Unmute fuctions
// Developed further for intrusion feeling and logging at 2nd of February 2020, by Initial developer
// Developed for Blacklisting/Whitelisting functions for both camera & audio at 7th of February 2020, by Initial developer
2020-02-15 22:07:48 +01:00
// Finalized, except traslations at 15th of February 2020.
2020-01-28 22:31:29 +01:00
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls,
2020-02-15 22:07:48 +01:00
Menus, PopupNotifier, UTF8Process, VpClock, Unix, process, About, Logs,
Reboot, LCLTranslator;
2020-01-28 22:31:29 +01:00
type
{ TForm1 }
TForm1 = class(TForm)
ImageListCam : TImageList;
2020-02-15 22:07:48 +01:00
ImageListCam1 : TImageList;
2020-02-02 19:52:14 +01:00
ImageListStatus : TImageList;
2020-01-28 22:31:29 +01:00
ImageListMic : TImageList;
AProcess : TProcessUTF8;
ImageListSystem : TImageList;
2020-01-28 22:31:29 +01:00
MenuItem1 : TMenuItem;
MenuItem10 : TMenuItem;
MenuItem11 : TMenuItem;
2020-02-02 19:52:14 +01:00
MenuItem12 : TMenuItem;
MenuItem13 : TMenuItem;
MenuItem14 : TMenuItem;
MenuItem15 : TMenuItem;
MenuItem16 : TMenuItem;
MenuItem17 : TMenuItem;
MenuItem18 : TMenuItem;
MenuItem19 : TMenuItem;
2020-01-28 22:31:29 +01:00
MenuItem2 : TMenuItem;
MenuItem20 : TMenuItem;
MenuItem21 : TMenuItem;
MenuItem22 : TMenuItem;
MenuItem24 : TMenuItem;
MenuItem25 : TMenuItem;
MenuItem26 : TMenuItem;
MenuItem27 : TMenuItem;
MenuItem28 : TMenuItem;
MenuItem29 : TMenuItem;
2020-01-28 22:31:29 +01:00
MenuItem3 : TMenuItem;
MenuItem30 : TMenuItem;
MenuItem31 : TMenuItem;
MenuItem32 : TMenuItem;
MenuItem33 : TMenuItem;
MenuItem35 : TMenuItem;
MenuItem39 : TMenuItem;
2020-01-28 22:31:29 +01:00
MenuItem4 : TMenuItem;
MenuItem40 : TMenuItem;
MenuItem41 : TMenuItem;
MenuItem42 : TMenuItem;
MenuItem43 : TMenuItem;
MenuItem44 : TMenuItem;
MenuItem45 : TMenuItem;
2020-01-28 22:31:29 +01:00
MenuItem5 : TMenuItem;
MenuItem6 : TMenuItem;
MenuItem7 : TMenuItem;
MenuItem8 : TMenuItem;
MenuItem9 : TMenuItem;
PopupMenu1 : TPopupMenu;
2020-02-02 19:52:14 +01:00
PopupMenu2 : TPopupMenu;
PopupMenu3 : TPopupMenu;
PopupMenu4 : TPopupMenu;
PopupMenu5 : TPopupMenu;
2020-02-15 22:07:48 +01:00
PopupNotifier1 : TPopupNotifier;
PopupNotifier2 : TPopupNotifier;
PopupNotifier3 : TPopupNotifier;
PopupNotifier4 : TPopupNotifier;
PopupNotifier5 : TPopupNotifier;
PopupNotifier6 : TPopupNotifier;
PopupNotifier7 : TPopupNotifier;
PopupNotifier8 : TPopupNotifier;
PopupNotifier9 : TPopupNotifier;
2020-01-28 22:31:29 +01:00
ProcessUTF8_1 : TProcessUTF8;
TrayIcon1 : TTrayIcon;
TrayIcon2 : TTrayIcon;
2020-02-02 19:52:14 +01:00
TrayIcon3 : TTrayIcon;
TrayIcon4 : TTrayIcon;
2020-02-15 22:07:48 +01:00
TrayIcon5 : TTrayIcon;
VpClock1 : TVpClock;
2020-01-28 22:31:29 +01:00
procedure FormCreate(Sender: TObject);
procedure MenuItem10Click(Sender: TObject);
2020-02-02 19:51:14 +01:00
procedure MenuItem12Click(Sender: TObject);
procedure MenuItem13Click(Sender: TObject);
procedure MenuItem27Click(Sender: TObject);
procedure MenuItem29Click(Sender: TObject);
2020-01-28 22:31:29 +01:00
procedure MenuItem2Click(Sender: TObject);
procedure MenuItem32Click(Sender: TObject);
procedure MenuItem33Click(Sender: TObject);
2020-01-28 22:31:29 +01:00
procedure MenuItem3Click(Sender: TObject);
procedure MenuItem4Click(Sender: TObject);
procedure MenuItem6Click(Sender: TObject);
procedure MenuItem7Click(Sender: TObject);
procedure MenuItem9Click(Sender: TObject);
2020-02-15 22:07:48 +01:00
procedure PopupNotifier1Close(Sender: TObject; var CloseAction: TCloseAction);
procedure PopupNotifier2Close(Sender: TObject; var CloseAction: TCloseAction);
procedure PopupNotifier3Close(Sender: TObject; var CloseAction: TCloseAction);
procedure PopupNotifier4Close(Sender: TObject; var CloseAction: TCloseAction);
2020-01-28 22:31:29 +01:00
procedure TrayIcon1Click(Sender: TObject);
procedure TrayIcon2Click(Sender: TObject);
2020-02-02 19:51:14 +01:00
procedure TrayIcon3Click(Sender: TObject);
procedure TrayIcon4Click(Sender: TObject);
2020-02-15 22:07:48 +01:00
procedure VideoFrame(Sender: TObject; Buffer: pointer; Size: integer; Error: boolean);
procedure VideoFrameSynchronized(Sender: TObject; Buffer: pointer; Size: integer; Error: boolean);
procedure VpClock1SecondChange(Sender: TObject);
2020-01-28 22:31:29 +01:00
private
CamImageIndex : integer;
MicImageIndex : integer;
2020-01-28 22:31:29 +01:00
public
end;
var
2020-02-15 22:07:48 +01:00
ReleaseNo : String;
Form1 : TForm1;
S : LongInt;
MicSwitchStr : String;
Password : String;
isMicOn : boolean;
MicStatus : boolean;
CamStatus : byte;
CamSavedStatus : Byte;
HasPassword : boolean;
MicClicked : boolean;
CamClicked : boolean;
MicClicksCounter : byte;
CamClicksCounter : byte;
GridLine : Integer;
SndCardsStringList : TStringList;
SndCardsCountNumber : Integer;
n : Integer;
HomeDir : String;
CmdString : String;
FileString : String;
FileDestDir : String;
LastAction : byte;
NewWidth : Integer;
NewHeight : Integer;
Breath : Integer = 50;
VideoCapt : boolean;
//VideoStringList : TStringList;
VideoCardsCountNumber : Integer;
LoopCounter : Integer;
PopUpWebcamCaptStatus : Boolean;
V4L2Val : integer;
2020-01-28 22:31:29 +01:00
implementation
2020-02-15 22:07:48 +01:00
procedure RebootSystem; forward;
{$R *.frm}
2020-01-28 22:31:29 +01:00
{ TForm1 }
2020-02-15 22:07:48 +01:00
procedure AdjustBalloonPosition;
var
width : Integer;
begin
Width := Screen.Monitors[0].Width;
NewWidth := Width div 2;
NewHeight := Screen.Monitors[0].Height;
end;
2020-02-10 01:04:10 +01:00
procedure SetReleaseNo;
begin
2020-02-15 22:07:48 +01:00
ReleaseNo := '1.4-1';
2020-02-10 01:04:10 +01:00
end;
2020-01-28 22:31:29 +01:00
procedure GetMicCaptureStatus;
var
AStringList : TStringList;
AProcess : TProcess;
begin
2020-02-15 22:07:48 +01:00
AProcess := TProcess.Create(nil);
AProcess.Executable := '/bin/sh';
2020-01-28 22:31:29 +01:00
AProcess.Parameters.Add('-c');
AProcess.Parameters.Add('amixer get Capture control');
2020-02-15 22:07:48 +01:00
AProcess.Options := AProcess.Options + [poWaitOnExit, poUsePipes];
2020-01-28 22:31:29 +01:00
AProcess.Execute;
2020-02-15 22:07:48 +01:00
AStringList := TStringList.Create;
2020-01-28 22:31:29 +01:00
AStringList.LoadFromStream(AProcess.Output);
2020-02-15 22:07:48 +01:00
MicSwitchStr := TrimLeft(RightStr(AStringList.Strings[AstringList.Count-1], 5));
2020-01-28 22:31:29 +01:00
if CompareText(MicSwitchStr,'[On]') = 0 then
2020-02-02 19:51:14 +01:00
begin
isMicOn := true;
end
2020-01-28 22:31:29 +01:00
//if CompareText(MicSwitchStr,'[Off]') = 0 then
else
2020-02-02 19:51:14 +01:00
begin
isMicOn := false;
end;
2020-01-28 22:31:29 +01:00
AStringList.Free;
AProcess.Free;
end;
2020-02-15 22:07:48 +01:00
procedure GetVideoCards; // VideoCards /dev/ Names
var
AStringList : TStringList;
AProcess : TProcess;
Str : String;
SubStr : String = '(deleted)';
n : integer;
m : integer;
l : integer;
begin
Str := 'lsof /dev/ ' + '|' + ' grep video';
AStringList := TStringList.Create;
AProcess := TProcess.Create(nil);
AProcess.Executable := '/bin/sh';
AProcess.Parameters.Add('-c');
AProcess.Parameters.Add(Str);
AProcess.Options := AProcess.Options + [poWaitOnExit, poUsePipes];
AProcess.Execute;
AStringList.LoadFromStream(AProcess.Output);
V4L2Val := StrToInt(BoolToStr(not DirectoryExists('/dev/v4l/')));
if V4L2Val = - 1 then
VideoCardsCountNumber := 0
else
begin
m := 0;
l := 0;
for n:= 0 to AStringList.Count - 1 do
if CompareText(RightStr(AStringList.Strings[n], Length(SubStr)), SubStr) = 0 then
Inc(m);
if CompareText(RightStr(AStringList.Strings[n], Length(SubStr)), SubStr) <> 0 then
Inc(l);
VideoCardsCountNumber := AStringList.Count - m;
end;
writeln(VideoCardsCountNumber);
AStringList.Free;
AProcess.Free;
end;
procedure GetCameraStatus; // My way because v4l2 does not privide webcam getstatus method.
begin
V4L2Val := StrToInt(BoolToStr(not DirectoryExists('/dev/v4l/'))); // If there is another way, please make an issue
if (VideoCardsCountNumber = 0) and (V4L2Val = -1) then // -> Camera is off
CamStatus := 0;
if (VideoCardsCountNumber = 0) and (V4L2Val = 0 ) then // -> Camera is On
CamStatus := 1;
if (VideoCardsCountNumber = 1) and (V4L2Val = 0 ) then // -> Camera is Capturing
CamStatus := 2;
end;
procedure PopUpWebcamOn;
begin
Form1.PopupNotifier2.Text := 'Camera is On' + LineEnding + 'Video Device: /dev/video1/';
Form1.PopupNotifier2.ShowAtPos(NewWidth - 200 , NewHeight div 2 - 400);
Form1.TrayIcon5.Hint := 'Camera Status' + LineEnding + 'Camera is On';
end;
procedure PopUpWebcamOff;
begin
Form1.PopupNotifier1.Text := 'No Camera' + LineEnding + 'Video Device: /dev/video1/';
Form1.PopupNotifier1.ShowAtPos(NewWidth - 200 , NewHeight div 2 - 400);
Form1.TrayIcon5.Hint := 'Camera Status' + LineEnding + 'Camera is Disabled';
end;
procedure PopUpWebcamCaptures;
begin
Form1.PopupNotifier7.Text := 'Camera is Capturing' + LineEnding + 'Video Device: /dev/video1/';
Form1.PopupNotifier7.ShowAtPos(NewWidth - 200 , NewHeight div 2 - 400);
Form1.TrayIcon5.Hint := 'Camera Status' + LineEnding + 'Camera is Capturing';
end;
procedure PopUpWebcamHacked;
begin
Form1.PopupNotifier8.Text := 'Camera is Hacked' + LineEnding + 'Video Device: /dev/video1/' + LineEnding + 'Check Logs';
Form1.PopupNotifier8.ShowAtPos(NewWidth - 200 , NewHeight div 2 - 400);
Form1.TrayIcon5.Hint := 'Camera Status' + LineEnding + 'Camera is Hacked' + LineEnding + 'Check Logs';
end;
procedure PopUpMicHacked;
begin
Form1.PopupNotifier9.Text := 'Microphone is Hacked' + LineEnding + 'Alsa Driver Changed Status';
Form1.PopupNotifier9.ShowAtPos(NewWidth - 200 , NewHeight div 2 - 200);
Form1.TrayIcon5.Hint := 'Microphone Status' + LineEnding + 'Microphone is Hacked' + LineEnding + 'Check Logs';
end;
procedure PopUpNoWebcam;
begin
Form1.TrayIcon5.Hint := 'No Camera' + LineEnding + 'Camera is Disabled';
end;
procedure PopUpWebcamCapturing;
begin
Form1.TrayIcon5.Hint := 'Camera On' + LineEnding + 'Camera is Enabled and Capturing';
end;
procedure PopUpWebcamNotCapturing;
begin
Form1.PopupNotifier6.Text := 'Camera is not Capturing' + LineEnding + 'Video Device: /dev/video1/';
Form1.PopupNotifier6.ShowAtPos(NewWidth - 200 , NewHeight div 2 - 400);
Form1.TrayIcon5.Hint := 'Camera On' + LineEnding + 'Camera is Enabled, but is not Capturing';
end;
procedure PopUpWebcamNoCapturing;
begin
Form1.TrayIcon5.Hint := 'Camera On' + LineEnding + 'Camera is Enabled, but is not Capturing';
end;
procedure PopUpMicOn;
begin
Form1.PopupNotifier3.Text := 'Microphone is Unmuted' + LineEnding + 'Alsa Driver Status: cap';
Form1.PopupNotifier3.ShowAtPos(NewWidth - 200 , NewHeight div 2 - 200);
Form1.TrayIcon2.Hint := 'Microphone Status & Menu' + LineEnding + 'Microphone is Unmuted';
end;
procedure PopUpMicOff;
begin
Form1.PopupNotifier4.Text := 'Microphone is Muted' + LineEnding + 'Alsa Driver Status: nocap';
Form1.PopupNotifier4.ShowAtPos(NewWidth - 200 , NewHeight div 2 - 200);
Form1.TrayIcon2.Hint := 'Microphone Status & Menu' + LineEnding + 'Microphone is Muted';
end;
2020-01-28 22:31:29 +01:00
procedure TForm1.FormCreate(Sender: TObject);
begin
2020-02-15 22:07:48 +01:00
//ShowMessage(Concat('Video Status = ', BoolToStr(Form1.Video.Open)));
ImageListCam1.GetIcon(0, TrayIcon5.Icon);
2020-02-10 01:04:10 +01:00
SetReleaseNo;
2020-02-15 22:07:48 +01:00
application.showmainform := false; // Hide Main form
2020-01-28 22:31:29 +01:00
HasPassword := false;
CamImageIndex := 0;
MicImageIndex := 0;
2020-02-02 19:51:14 +01:00
MicClicked := false;
CamClicked := false;
2020-02-15 22:07:48 +01:00
MicStatus := false;
2020-02-02 19:51:14 +01:00
CamClicksCounter := 0;
MicClicksCounter := 0;
GridLine := 1;
2020-02-15 22:07:48 +01:00
VideoCapt := false;
VpClock1.Active := true;
2020-02-15 22:07:48 +01:00
LoopCounter := 0;
PopUpWebcamCaptStatus := false;
V4L2Val := StrToInt(BoolToStr(not DirectoryExists('/dev/v4l/')));
AdjustBalloonPosition;
2020-02-15 22:07:48 +01:00
ImageListCam1.GetIcon(0, TrayIcon5.Icon);
ImageListStatus.GetIcon(0, TrayIcon3.Icon);
2020-02-15 22:07:48 +01:00
ImageListCam.GetIcon(2, TrayIcon1.Icon);
ImageListSystem.GetIcon(0, TrayIcon4.Icon);
2020-01-28 22:31:29 +01:00
2020-02-15 22:07:48 +01:00
GetVideoCards;
GetCameraStatus;
// if (VideoCardsCountNumber = 0) and (V4L2Val = -1) then CamStatus := 0; // -> Camera is off
// if (VideoCardsCountNumber = 0) and (V4L2Val = 0 ) then CamStatus := 1; // -> Camera is On
// if (VideoCardsCountNumber = 1) and (V4L2Val = 0 ) then CamStatus := 2; // -> Camera is Capturing
if CamStatus = 0 then // -> Camera is off
2020-01-28 22:31:29 +01:00
begin
2020-02-15 22:07:48 +01:00
//ImageListCam.GetIcon(1, TrayIcon1.Icon);
PopUpWebcamOff;
ImageListCam1.GetIcon(0, TrayIcon5.Icon);
//ShowMessage('Camera is Off or No Camera exists');
2020-02-15 22:07:48 +01:00
CamClicked := false;
CamClicksCounter := 0;
CamSavedStatus := 0;
end;
if CamStatus = 1 then // -> Camera is On
begin
//ImageListCam.GetIcon(0, TrayIcon1.Icon);
PopUpWebcamOn;
ImageListCam1.GetIcon(2, TrayIcon5.Icon);
//ShowMessage('Camera is On');
CamClicked := false;
CamClicksCounter := 0;
CamSavedStatus := 1;
2020-01-28 22:31:29 +01:00
end;
2020-02-15 22:07:48 +01:00
if CamStatus = 2 then // -> Camera is Capturing
begin
PopUpWebcamCaptures;
PopUpWebcamCaptStatus := true;
ImageListCam1.GetIcon(1, TrayIcon5.Icon);
VideoCapt := true;
CamClicked := false;
CamClicksCounter := 0;
CamSavedStatus := 2;
end;
GetMicCaptureStatus;
2020-01-28 22:31:29 +01:00
if isMicOn = true then
begin
ImageListMic.GetIcon(0, TrayIcon2.Icon);
2020-02-02 19:51:14 +01:00
MicStatus := true;
2020-02-15 22:07:48 +01:00
PopUpMicOn;
2020-01-28 22:31:29 +01:00
end;
if isMicOn = false then
begin
ImageListMic.GetIcon(1, TrayIcon2.Icon);
2020-02-02 19:51:14 +01:00
MicStatus := false;
2020-02-15 22:07:48 +01:00
PopUpMicOff;
2020-01-28 22:31:29 +01:00
end;
2020-02-02 19:51:14 +01:00
end;
procedure CheckSStatus;
begin
if (S <> 0) then
begin
if (S = 256) then
begin
ShowMessage('Incorrect password');
end;
if (S <> 256) then
begin
ShowMessage('Error Number: ' + IntToStr(S));
end;
HasPassword := false;
end;
end;
2020-02-15 22:07:48 +01:00
procedure GetSoundCards; // GetSoundCards Unique Driver Names
var
AStringList : TStringList;
AProcess : TProcess;
m : Integer;
n : Integer;
RightChar : Integer;
begin
AProcess := TProcess.Create(nil);
AProcess.Executable := '/bin/sh';
AProcess.Parameters.Add('-c');
AProcess.Parameters.Add('cat /proc/asound/modules ');
AProcess.Options := AProcess.Options + [poWaitOnExit, poUsePipes];
AProcess.Execute;
AStringList := TStringList.Create;
SndCardsStringList := TStringList.Create;
SndCardsStringList.Sorted := true;
SndCardsStringList.Duplicates := dupIgnore;
AStringList.LoadFromStream(AProcess.Output);
m := AStringList.Count - 1;
n := 0;
SndCardsCountNumber := 0;
While (n <= m) do
begin
RightChar := Pos(' ', AStringList.Strings[n]) + 1;
SndCardsStringList.AddStrings(Copy(AStringList.Strings[n], RightChar + 2, (Length(AStringList.Strings[n]))));
inc(n);
end;
SndCardsCountNumber := SndCardsStringList.Count - 1;
AStringList.Free;
AProcess.Free;
end;
2020-02-15 22:07:48 +01:00
procedure AskPassword;
begin
Password := PasswordBox('Authorization Needed / User Input','Please Enter Password');
HasPassword := True;
2020-01-28 22:31:29 +01:00
end;
2020-02-15 22:07:48 +01:00
procedure TForm1.MenuItem10Click(Sender: TObject); // Exit
2020-01-28 22:31:29 +01:00
begin
Form1.Close;
2020-02-15 22:07:48 +01:00
//VideoStringList.Free;
SndCardsStringList.Free;
Halt(0);
2020-01-28 22:31:29 +01:00
end;
2020-02-15 22:07:48 +01:00
procedure TForm1.MenuItem12Click(Sender: TObject); //ShowLogs;
2020-02-02 19:51:14 +01:00
begin
Logs.Form3.Show;
end;
2020-02-15 22:07:48 +01:00
procedure TForm1.MenuItem13Click(Sender: TObject); //ClearLogs;
2020-02-02 19:51:14 +01:00
begin
ImageListStatus.GetIcon(0, TrayIcon3.Icon);
Logs.Form3.StringGrid1.Clean;
GridLine := 1;
Logs.Form3.StringGrid1.InsertRowWithValues(0,['DateTime Stamp', 'Event Description']);
ImageListStatus.GetIcon(0, TrayIcon3.Icon);
2020-02-15 22:07:48 +01:00
if CamClicked then
CamClicked := false;
if MicClicked then
MicClicked := false;
//CamClicksCounter := 1;
2020-02-02 19:51:14 +01:00
end;
2020-02-15 22:07:48 +01:00
procedure TForm1.MenuItem27Click(Sender: TObject); // Blaclist Camera and Reboot
var
BlackListStr : String;
begin
2020-02-10 01:04:10 +01:00
Password := '';
AskPassword;
CmdString := '';
HomeDir := expandfilename('~/');
FileString := Concat(HomeDir,'.blacklistuvcvideo ');
FileDestDir := '/etc/modprobe.d/blacklistuvcvideo.conf ';
BlackListStr := '''blacklist uvcvideo''';
if (FileExists(FileDestDir) = false) then
begin
if (HasPassword = false) then
begin
AskPassword;
end;
CmdString := Concat('rm ', FileString);
S := FpSystem(CmdString);
CmdString := Concat(Concat(Concat('echo ', BlackListStr),' >> '), FileString);
S := FpSystem(CmdString);
CmdString := Concat(Concat(Concat(Concat('echo ', Password), ' | sudo -S cp '), FileString), FileDestDir);
S := FpSystem(CmdString);
CheckSStatus;
if (S = 0) then
begin
LastAction := 0;
RebootSystem;
end;
end
else
begin
ShowMessage('Camera was not Whitelisted');
end;
2020-02-10 01:04:10 +01:00
CmdString := '';
end;
2020-02-15 22:07:48 +01:00
procedure TForm1.MenuItem29Click(Sender: TObject); // Whitelist Camera and Reboot
begin
2020-02-10 01:04:10 +01:00
Password := '';
AskPassword;
CmdString := '';
FileDestDir := '/etc/modprobe.d/blacklistuvcvideo.conf';
if (FileExists(FileDestDir) = true) then
begin
If (HasPassword = false) then
begin
AskPassword;
end;
CmdString := Concat(Concat(Concat('echo ', Password), ' | sudo -S rm '), FileDestDir);
S := FpSystem(CmdString);
CheckSStatus;
if (S = 0) then
begin
LastAction := 1;
RebootSystem;
end;
end
else
begin
ShowMessage('Camera was not Blacklisted');
end;
2020-02-10 01:04:10 +01:00
CmdString := '';
end;
2020-02-15 22:07:48 +01:00
procedure TForm1.MenuItem2Click(Sender: TObject); // Password Reset
2020-01-28 22:31:29 +01:00
begin
HasPassword := false;
ShowMessage('Passsword, has been reset');
end;
2020-02-15 22:07:48 +01:00
procedure TForm1.MenuItem32Click(Sender: TObject); // Blacklist Audio and Reboot
2020-01-28 22:31:29 +01:00
begin
Password := '';
HasPassword := false;
2020-02-10 01:04:10 +01:00
CmdString := '';
AskPassword;
GetSoundCards;
HomeDir := expandfilename('~/');
FileString := Concat(HomeDir,'.blacklistaudio ');
FileDestDir := '/etc/modprobe.d/blacklistaudio.conf ';
S := FpSystem(CmdString);
if SndCardsStringList <> Nil then
begin
CmdString := Concat(Concat('rm ', HomeDir),'.blacklistaudio');
S := FpSystem(CmdString);
//ShowMessage(SndCardsStringList.Text);
for n := 0 to SndCardsStringList.Count - 1 do
begin
CmdString := Concat(Concat(Concat(Concat('echo blacklist ''', SndCardsStringList.Strings[n])), ''' >> '), FileString);
S:= FpSystem(CmdString);
end;
If (HasPassword = false) then
begin
AskPassword;
end;
CmdString := Concat(Concat(Concat(Concat('echo ', Password), ' | sudo -S cp '), FileString), FileDestDir);
S:= FpSystem(CmdString);
CheckSStatus;
if (S = 0) and (HasPassword = true) then
begin
LastAction := 2;
RebootSystem;
end;
end
else
begin
ShowMessage('Audio Card(s) not Whitelisted before');
end;
2020-02-10 01:04:10 +01:00
CmdString := '';
2020-01-28 22:31:29 +01:00
end;
2020-02-15 22:07:48 +01:00
procedure TForm1.MenuItem33Click(Sender: TObject); // Whitelistlist Audio and Reboot
2020-01-28 22:31:29 +01:00
begin
2020-02-10 01:04:10 +01:00
Password := '';
HasPassword := false;
CmdString := '';
AskPassword;
FileString := '/etc/modprobe.d/blacklistaudio.conf';
CmdString := Concat(Concat(Concat('echo ', Password), ' | sudo -S rm '), FileString);
if (FileExists(FileString) = true) then
begin
If (HasPassword = false) then
begin
AskPassword;
end;
S:= FpSystem(CmdString);
CheckSStatus;
if (S = 0) and (HasPassword = true) then
begin
LastAction := 3;
RebootSystem;
end;
end
else
begin
ShowMessage('Audio Card(s) not Blacklisted before');
end;
2020-02-10 01:04:10 +01:00
CmdString := '';
2020-01-28 22:31:29 +01:00
end;
procedure RebootSystem;
begin
Reboot.Form4.Button2.Default := true;
Reboot.Form4.ListBox1.Items.Add(' System will now Reboot!!! ');
Reboot.Form4.ListBox1.Items.Add(' ');
Reboot.Form4.ListBox1.Items.Add('Please make sure that you have saved');
Reboot.Form4.ListBox1.Items.Add('all of your files and closed all open');
Reboot.Form4.ListBox1.Items.Add('Windows, before pressing the Reboot ');
Reboot.Form4.ListBox1.Items.Add('Button below.');
Form4.Password := Password;
Form4.HasPassword := HasPassword;
Form4.LastAction := LastAction;
Reboot.Form4.Show;
end;
procedure CameraOn;
begin
S := FpSystem(Concat('echo ', Password, ' | sudo -S modprobe uvcvideo'));
CheckSStatus;
end;
procedure CameraOff;
2020-01-28 22:31:29 +01:00
begin
2020-02-15 22:07:48 +01:00
//S := FpSystem(Concat('echo ', Password, ' | sudo -S rmmod -f uvcvideo'));
S := FpSystem(Concat('echo ', Password, ' | sudo -S modprobe -rf uvcvideo'));
CheckSStatus;
2020-01-28 22:31:29 +01:00
end;
2020-02-15 22:07:48 +01:00
procedure TForm1.MenuItem3Click(Sender: TObject); // Camera Off -> On
2020-01-28 22:31:29 +01:00
begin
2020-02-15 22:07:48 +01:00
if CamStatus = 0 then
2020-01-28 22:31:29 +01:00
begin
2020-02-02 19:51:14 +01:00
if HasPassword then
begin
2020-02-15 22:07:48 +01:00
CameraOn;
//ImageListCam.GetIcon(2, TrayIcon1.Icon);
ImageListCam1.GetIcon(2, TrayIcon5.Icon);
2020-02-02 19:51:14 +01:00
CamClicksCounter := 1;
2020-02-15 22:07:48 +01:00
PopUpWebCamOn;
CamStatus := 1;
VideoCapt := true;
CamSavedStatus := 1;
2020-02-02 19:51:14 +01:00
end
2020-02-15 22:07:48 +01:00
else
begin
AskPassword;
CameraOn;
if HasPassword then
begin
//ImageListCam.GetIcon(2, TrayIcon1.Icon);
ImageListCam1.GetIcon(2, TrayIcon5.Icon);
CamClicksCounter := 1;
PopUpWebCamOn;
CamStatus := 1;
VideoCapt := true;
CamSavedStatus := 1;
end
end;
2020-01-28 22:31:29 +01:00
end;
2020-02-02 19:51:14 +01:00
CamClicked := true;
2020-01-28 22:31:29 +01:00
end;
2020-02-15 22:07:48 +01:00
procedure TForm1.MenuItem4Click(Sender: TObject); // Camera On -> Off
2020-01-28 22:31:29 +01:00
begin
2020-02-15 22:07:48 +01:00
if CamStatus <> 0 then
2020-01-28 22:31:29 +01:00
begin
2020-02-15 22:07:48 +01:00
if HasPassword then
begin
CameraOff;
//ImageListCam.GetIcon(2, TrayIcon1.Icon);
ImageListCam1.GetIcon(0, TrayIcon5.Icon);
CamClicksCounter := 1;
PopUpWebCamOff;
CamStatus := 0;
VideoCapt := false;
CamSavedStatus := 0;
end
else
begin
AskPassword;
CameraOff;
if HasPassword then
begin
//ImageListCam.GetIcon(2, TrayIcon1.Icon);
ImageListCam1.GetIcon(0, TrayIcon5.Icon);
CamClicksCounter := 1;
PopUpWebCamOff;
CamStatus := 0;
VideoCapt := false;
CamSavedStatus := 0;
end
end;
end;
if CamStatus = 2 then // Camera forced to Off
2020-02-02 19:51:14 +01:00
begin
if HasPassword then
begin
2020-02-15 22:07:48 +01:00
CameraOff;
//ImageListCam.GetIcon(2, TrayIcon1.Icon);
ImageListCam1.GetIcon(0, TrayIcon5.Icon);
2020-02-02 19:51:14 +01:00
CamClicksCounter := 1;
2020-02-15 22:07:48 +01:00
PopUpWebCamOff;
CamStatus := 0;
VideoCapt := false;
CamSavedStatus := 0;
2020-02-02 19:51:14 +01:00
end
2020-02-15 22:07:48 +01:00
else
begin
AskPassword;
CameraOff;
if HasPassword then
begin
//ImageListCam.GetIcon(2, TrayIcon1.Icon);
ImageListCam1.GetIcon(0, TrayIcon5.Icon);
CamClicksCounter := 1;
PopUpWebCamOff;
CamStatus := 0;
VideoCapt := false;
CamSavedStatus := 0;
end
end;
2020-01-28 22:31:29 +01:00
end;
2020-02-02 19:51:14 +01:00
CamClicked := true;
2020-01-28 22:31:29 +01:00
end;
2020-02-15 22:07:48 +01:00
procedure TForm1.MenuItem6Click(Sender: TObject); // Microphone Mute
2020-01-28 22:31:29 +01:00
begin
2020-02-15 22:07:48 +01:00
If MicStatus = true then
begin
S := FpSystem('amixer set Capture nocap');
//ShowMessage('Microphone has been mutted');
ImageListMic.GetIcon(1, TrayIcon2.Icon);
PopUpMicOff;
MicClicked := true;
MicClicksCounter := 1;
MicStatus := false;
end;
2020-01-28 22:31:29 +01:00
end;
2020-02-15 22:07:48 +01:00
procedure TForm1.MenuItem7Click(Sender: TObject); // Microphone Unmute
2020-01-28 22:31:29 +01:00
begin
2020-02-15 22:07:48 +01:00
If MicStatus = false then
begin
S := FpSystem('amixer set Capture cap');
//ShowMessage('Microphone has been unmutted');
PopUpMicOn;
ImageListMic.GetIcon(0, TrayIcon2.Icon);
MicClicked := true;
MicClicksCounter := 1;
MicStatus := true;
end;
2020-01-28 22:31:29 +01:00
end;
2020-02-15 22:07:48 +01:00
procedure TForm1.MenuItem9Click(Sender: TObject); // About
2020-01-28 22:31:29 +01:00
begin
About.Form2.Label1.Caption:='Developer';
About.Form2.Label2.Caption:='Licence';
About.Form2.Label3.Caption:='Project';
About.Form2.ListBox1.Items.Clear;
About.Form2.ListBox1.Items.Add(Concat('Camera & Microphone Control Switches for Linux Rel. ', ReleaseNo));
About.Form2.ListBox1.Items.Add('is an LGPL2 Free Pascal Project with LCL components,');
About.Form2.ListBox1.Items.Add('completely developed from scratch, at 23th, of January 2020 by');
About.Form2.ListBox1.Items.Add('Linuxer パスカリス スポシト');
About.Form2.ListBox1.Items.Add(' ');
About.Form2.ListBox1.Items.Add('Redesigned and further Developed at 28th of January 2020,');
About.Form2.ListBox1.Items.Add('in order to provide Camera and Mic statuses alone with On/Off and');
2020-01-28 22:31:29 +01:00
About.Form2.ListBox1.Items.Add('Mute/Unmute fuctions');
About.Form2.ListBox1.Items.Add(' ');
About.Form2.ListBox1.Items.Add('Final Development Stage at 6th of February 2020, for System ');
About.Form2.ListBox1.Items.Add('Blacklist/Whitelist Modules functions for Camera and Audio');
About.Form2.ListBox1.Items.Add(' ');
About.Form2.ListBox1.Items.Add('Bugs Corrected at 10th of February 2020, (Undo Audio Bug) ');
About.Form2.ListBox1.Items.Add('Password is asked every time for Blacklist/Whitelist - Better');
About.Form2.ListBox1.Items.Add('Security, and Password Reset was removed from System''s menu ');
2020-02-15 22:07:48 +01:00
About.Form2.ListBox1.Items.Add(' ');
About.Form2.ListBox1.Items.Add('Finalized from previous Stages, by providing exactly the same');
About.Form2.ListBox1.Items.Add('functions with Camera Monitor, plus the Off stage, so now it ');
About.Form2.ListBox1.Items.Add('has a realtime Off (Uvc Video Off), a realtime On (Uvc Video On)');
About.Form2.ListBox1.Items.Add('and a realtime Capture On/Off Icon Statuses ');
About.Form2.ListBox1.Items.Add('This is the final project''s stage of design, except when ');
About.Form2.ListBox1.Items.Add('translations will be finished and added at 15th of February 2020');
About.Form2.ListBox1.Items.Add('Note: A big part of code, changed in order to add these statuses');
About.Form2.ListBox1.Items.Add('because it reallocated the total violations algorithms (hacks) ');
2020-01-28 22:31:29 +01:00
About.Form2.Show;
end;
2020-02-15 22:07:48 +01:00
procedure TForm1.PopupNotifier1Close(Sender: TObject;
var CloseAction: TCloseAction);
begin
PopUpNotifier1.Hide;
end;
procedure TForm1.PopupNotifier2Close(Sender: TObject;
var CloseAction: TCloseAction);
begin
PopUpNotifier2.Hide;
end;
procedure TForm1.PopupNotifier3Close(Sender: TObject;
var CloseAction: TCloseAction);
begin
PopUpNotifier3.Hide;
end;
procedure TForm1.PopupNotifier4Close(Sender: TObject;
var CloseAction: TCloseAction);
begin
PopUpNotifier4.Hide;
end;
2020-01-28 22:31:29 +01:00
procedure TForm1.TrayIcon1Click(Sender: TObject);
begin
PopUpMenu4.PopUp;
2020-01-28 22:31:29 +01:00
end;
procedure TForm1.TrayIcon2Click(Sender: TObject);
begin
PopUpMenu3.PopUp;
2020-01-28 22:31:29 +01:00
end;
2020-02-02 19:51:14 +01:00
procedure TForm1.TrayIcon3Click(Sender: TObject);
begin
PopUpMenu2.PopUp;
end;
procedure TForm1.TrayIcon4Click(Sender: TObject);
begin
PopUpMenu5.PopUp;
end;
2020-02-15 22:07:48 +01:00
procedure TForm1.VideoFrame(Sender: TObject; Buffer: pointer; Size: integer;
Error: boolean);
begin
ImageListCam1.GetIcon(1, TrayIcon5.Icon);
VideoCapt := true;
end;
procedure TForm1.VideoFrameSynchronized(Sender: TObject; Buffer: pointer;
Size: integer; Error: boolean);
begin
ImageListCam1.GetIcon(1, TrayIcon5.Icon);
VideoCapt := true;
end;
procedure TForm1.VpClock1SecondChange(Sender: TObject); // Check Statuses and External Events Notifications and Logs
2020-02-02 19:51:14 +01:00
var
HackedTime : TDateTime;
2020-02-15 22:07:48 +01:00
Str : String;
2020-02-02 19:51:14 +01:00
begin
GetMicCaptureStatus;
2020-01-28 22:31:29 +01:00
2020-02-15 22:07:48 +01:00
GetVideoCards;
GetCameraStatus;
// VideoCardsCountNumber = 0 & V4L2Val = -1 -> CamStatus = 0 -> Camera is off
// VideoCardsCountNumber = 0 & V4L2Val = 0 -> CamStatus = 1 -> Camera is On
// VideoCardsCountNumber = 1 & V4L2Val = 0 -> CamStatus = 2 -> CameraCapturing
//Str := 'VidCardsNum = ' + IntToStr(VideoCardsCountNumber) +
// ' /dev/video1/ = ' + BoolToStr(DirectoryExists('/dev/video1/')) +
// ' V4L2Val = ' + IntToStr(V4L2Val) +
// ' CamStatus = ' + IntToStr(CamStatus) +
// ' CamSavedStat = ' + IntToStr(CamSavedStatus);
//
//writeln(Str);
if (CamStatus = 2) and (CamSavedStatus = 1) then // Webcam Captures
begin
2020-02-15 22:07:48 +01:00
ImageListCam1.GetIcon(1, TrayIcon5.Icon);
if (VideoCapt = false) then
2020-02-02 19:51:14 +01:00
begin
2020-02-15 22:07:48 +01:00
PopUpWebcamCapturing;
PopUpWebcamCaptures;
PopUpWebcamCaptStatus := true;
VideoCapt := true;
CamSavedStatus := 2;
2020-02-02 19:51:14 +01:00
end;
2020-02-15 22:07:48 +01:00
end;
if (CamStatus = 1) and (CamSavedStatus = 2) then // Webcam Stopped Capturing
begin
2020-02-15 22:07:48 +01:00
ImageListCam1.GetIcon(2, TrayIcon5.Icon);
if (VideoCapt = true) then
2020-02-02 19:51:14 +01:00
begin
2020-02-15 22:07:48 +01:00
PopUpWebcamNotCapturing;
PopUpWebcamNoCapturing;
PopUpWebcamCaptStatus := false;
VideoCapt := false;
CamSavedStatus := 1;
2020-02-02 19:51:14 +01:00
end;
end;
2020-02-15 22:07:48 +01:00
if ((CamStatus = 1) and (CamSavedStatus = 1) and (CamClicked = true) and (CamClicksCounter= 1)) then // Webcam is On, User Clicked
begin
PopUpWebcamOn;
ImageListCam1.GetIcon(2, TrayIcon5.Icon);
PopUpWebcamCaptStatus := false;
PopUpWebcamNoCapturing;
PopUpWebcamCaptStatus := true;
CamClicked := false;
CamClicksCounter := 0;
end;
if ((CamStatus = -1) and (CamSavedStatus = -1) and (CamClicked = true) and (CamClicksCounter= 1)) then // Webcam disabled, User Clicked
begin
ImageListCam1.GetIcon(0, TrayIcon5.Icon);
PopUpNoWebcam;
CamClicked := false;
CamClicksCounter := 0;
end;
if ((CamStatus = 1) and (CamSavedStatus = 0) and (CamClicked = false) and (CamClicksCounter= 0)) then // Webcam went On from Off, No User Clicked -> Hacked
begin
HackedTime := now;
PopUpWebcamHacked;
Logs.Form3.StringGrid1.InsertRowWithValues ( GridLine, [FormatDateTime('dd/mm/yyyy, ', HackedTime)
+ RightStr(DateTimeToStr(VPClock1.Time), 8), 'Camera Hacked to On']);
Inc(GridLine);
ImageListStatus.GetIcon(1, TrayIcon3.Icon);
ImageListCam1.GetIcon(2, TrayIcon5.Icon);
//CamClicksCounter := 1;
//CamClicked := false;
CamSavedStatus := 1;
//PopUpWebcamCaptStatus := false;
PopUpWebcamNoCapturing;
PopUpWebcamCaptStatus := true;
end;
if ((CamStatus = 0) and (CamSavedStatus = 1) and (CamClicked = false) and (CamClicksCounter= 0)) then // Webcam went Off from On, No User Clicked -> Hacked
begin
HackedTime := now;
PopUpWebcamHacked;
Logs.Form3.StringGrid1.InsertRowWithValues ( GridLine, [FormatDateTime('dd/mm/yyyy, ', HackedTime)
+ RightStr(DateTimeToStr(VPClock1.Time), 8), 'Camera Hacked to On']);
Inc(GridLine);
ImageListStatus.GetIcon(1, TrayIcon3.Icon);
ImageListCam1.GetIcon(0, TrayIcon5.Icon);
//CamClicksCounter := 1;
//CamClicked := false;
CamSavedStatus := 0;
//PopUpWebcamCaptStatus := false;
PopUpWebcamNoCapturing;
PopUpWebcamCaptStatus := true;
end;
if ((CamStatus = 1) and (CamSavedStatus = 0) and (CamClicked = false) and (CamClicksCounter = 0)) then // Webcam disabled (Off), No User Clicked -> Hacked
begin
HackedTime := now;
PopUpWebcamHacked;
Logs.Form3.StringGrid1.InsertRowWithValues ( GridLine, [FormatDateTime('dd/mm/yyyy, ', HackedTime)
+ RightStr(DateTimeToStr(VPClock1.Time), 8), 'Camera Hacked to Off']);
Inc(GridLine);
ImageListStatus.GetIcon(1, TrayIcon3.Icon);
ImageListCam1.GetIcon(0, TrayIcon5.Icon);
CamSavedStatus := -1;
//PopUpWebcamCaptStatus := false;
PopUpWebcamNoCapturing;
PopUpWebcamCaptStatus := false;
//CamClicked := false;
//CamClicksCounter := 1;
end;
//LoopCounter := 0;
//end;
if isMicOn = true then
begin
ImageListMic.GetIcon(0, TrayIcon2.Icon);
2020-02-02 19:51:14 +01:00
If ((MicStatus = false) and (MicClicked = true) and (MicClicksCounter = 1)) then
begin
MicClicked := false;
MicClicksCounter := 0;
MicStatus := true;
end;
If ((MicStatus = false) and (MicClicked = false) and (MicClicksCounter = 0)) then
begin
ImageListStatus.GetIcon(1, TrayIcon3.Icon);
HackedTime := now;
2020-02-15 22:07:48 +01:00
//ShowMessage('Microphone hacked !!! Please Check Log');
Logs.Form3.StringGrid1.InsertRowWithValues(GridLine,[FormatDateTime('dd/mm/yyyy, ', HackedTime) + RightStr(DateTimeToStr(VPClock1.Time), 8), 'Microphone Hacked to Unmuted']);
2020-02-02 19:51:14 +01:00
MicStatus := true;
Inc(GridLine);
2020-02-02 19:51:14 +01:00
ImageListStatus.GetIcon(1, TrayIcon3.Icon);
2020-02-15 22:07:48 +01:00
PopUpMicHacked;
2020-02-02 19:51:14 +01:00
end;
end;
if isMicOn = false then
begin
ImageListMic.GetIcon(1, TrayIcon2.Icon);
2020-02-02 19:51:14 +01:00
If ((MicStatus = true) and (MicClicked = true) and (MicClicksCounter = 1)) then
begin
MicClicked := false;
MicClicksCounter := 0;
MicStatus := false;
end;
If ((MicStatus = true) and (MicClicked = false) and (MicClicksCounter = 0)) then
begin
ImageListStatus.GetIcon(1, TrayIcon3.Icon);
HackedTime := now;
2020-02-15 22:07:48 +01:00
//ShowMessage('Microphone hacked !!! Please Check Log');
Logs.Form3.StringGrid1.InsertRowWithValues(GridLine,[FormatDateTime('dd/mm/yyyy, ', HackedTime) + RightStr(DateTimeToStr(VPClock1.Time), 8), 'Microphone Hacked to Muted']);
2020-02-02 19:51:14 +01:00
MicStatus := false;
Inc(GridLine);
2020-02-02 19:51:14 +01:00
ImageListStatus.GetIcon(1, TrayIcon3.Icon);
2020-02-15 22:07:48 +01:00
PopUpMicHacked;
2020-02-02 19:51:14 +01:00
end;
end;
2020-02-15 22:07:48 +01:00
//VideoStringList.Free;
end;
2020-02-10 01:04:10 +01:00
end.