VNC a Machine from OTRS Freetext Field

English! place to talk about development, programming and coding
Post Reply
dgshue
Znuny newbie
Posts: 17
Joined: 13 Jul 2011, 14:53
Znuny Version: 3.3.7

VNC a Machine from OTRS Freetext Field

Post by dgshue »

Hello everyone,
I thought I would share a little piece of code that I pulled together to create a VNC file based on a Freetext field to assist an agent in gaining remote access to a machine. Using version 2.4 for the moment, haven't got into 3 yet. Couple of things that need to be setup first:

- You need to have a freetext field as 'PC Name' or 'Equipment Name' and of course have it setup for entry at ticket creation. --->

ZZZAuto.pm
################################################

Code: Select all

$Self->{'TicketFreeKey3'} =  {
  'Equipment Name/PC Name' => 'Equipment Name/PC Name'
};

$Self->{'Ticket::Frontend::AgentTicketCompose'}->{'TicketFreeText'} =  {
  '1' => '1',
  '10' => '0',
  '11' => '0',
  '12' => '0',
  '13' => '0',
  '14' => '0',
  '15' => '0',
  '16' => '0',
  '2' => '1',
  '3' => '1',
  '4' => '0',
  '5' => '0',
  '6' => '0',
  '7' => '0',
  '8' => '0',
  '9' => '0'
};
##########################################
<---- Notice I'm using TicketFreeText3

- Next, you will need to create a download Perl script to generate the VNC file. I'm no Perl programmer, I just found allot of this floating around the net. I'm open to suggestions ---->
vnc.pl
#########################################

Code: Select all

#!c:/strawberry/perl/bin/perl -w
# -- who wherever your perl exec is



use POSIX;
use CGI;

#Directory where the text file will be created.
$directory =  'C:/OTRS/OTRS/var/tmp';
$pc_name = $ARGV[$0];
if (!(-d "$directory")) { #check if directory exists -  returns true if doesn't exist.
        printf "No directory\n", $? >> 8;
        exit (1); #exit because directory doesn't exist.
}

#Dynamic file name, this does not get cleaned up so someone may want to find a easy way of cleaning
#up old VNC files
my $filename=strftime("vnc_%y%M%d.vnc", localtime);
open(FILE, ">$directory/$filename") || die("Couldn't open file");
print FILE "[connection]\nhost=$pc_name\nport=5900";
close(FILE);

my $q = CGI->new;

# Uncomment the next line only for debugging the script 
open(my $DLFILE, '<', "$directory/$filename") or die "Can't open file '$directory/$filename' : $!";

# Comment the next line if you uncomment the above line 
#open(my $DLFILE, '<', "$directory/$filename") or return(0);

# This prints the download headers with the file size included
# so you get a progress bar in the dialog box that displays during file downlaods. 
print $q->header(-type            => 'application/x-download',
				-attachment      => $filename,
				'Content-length' => -s "$directory/$filename",
);

binmode $DLFILE;
print while <$DLFILE>;
undef ($DLFILE);
return(1);

exit(0);
##########################################################
------> I put this file in /bin/cgi-bin with index.pl and such.

- Lastly, update your layout to create a link and to pass the freetext field to the perl script. ----->
OTRS/Kernel/Output/HTML/TemplateYourUsing/AgentTicketZoom.dtl
##########################################################
<!-- dtl:block:TicketFreeText3 -->
<tr valign="top">
<td><b>VNC:</b></td>
<td>
<!-- dtl:block:TicketFreeTextPlain3 -->
<div title="Click Here"><a href="http://servername/otrs/vnc.pl?$QData{"TicketFreeText3"}" target="_blank">Click Here</a></div>
<!-- dtl:block:TicketFreeTextPlain3 -->
</td>
</tr>
<!-- dtl:block:TicketFreeText3 -->
###########################################################
--------> That's IT!

I did have a problem where I wanted to display the FreeTextField, and the VNC link at the same time. This took modifying AgentTickeZoom.pm ------->
OTRS/Kernel/Modules/AgentTicketZoom.pm
############################################################
# ticket free text
for my $Count ( 1 .. 16 ) {
if ( $Param{ 'TicketFreeText' . $Count } ) {
$Self->{LayoutObject}->Block(
Name => 'TicketFreeText' . $Count,
Data => { %Param, %AclAction },
);
$Self->{LayoutObject}->Block(
Name => 'TicketFreeText',
Data => {
%Param, %AclAction,
TicketFreeKey => $Param{ 'TicketFreeKey' . $Count },
TicketFreeText => $Param{ 'TicketFreeText' . $Count },
Count => $Count,
},
);
if ( !$Self->{ConfigObject}->Get( 'TicketFreeText' . $Count . '::Link' ) ) {
$Self->{LayoutObject}->Block(
Name => 'TicketFreeTextPlain' . $Count,
Data => { %Param, %AclAction },
);
$Self->{LayoutObject}->Block(
Name => 'TicketFreeTextPlain',
Data => {
%Param, %AclAction,
TicketFreeKey => $Param{ 'TicketFreeKey' . $Count },
TicketFreeText => $Param{ 'TicketFreeText' . $Count },
Count => $Count,
},
);
}
else {
$Self->{LayoutObject}->Block(
Name => 'TicketFreeTextLink' . $Count,
Data => { %Param, %AclAction },
);
$Self->{LayoutObject}->Block(
Name => 'TicketFreeTextLink',
Data => {
%Param, %AclAction,
TicketFreeTextLink => $Self->{ConfigObject}->Get(
'TicketFreeText' . $Count . '::Link'
),
TicketFreeKey => $Param{ 'TicketFreeKey' . $Count },
TicketFreeText => $Param{ 'TicketFreeText' . $Count },
Count => $Count,
},
);
}
}
}

#VNC ticket free text fields
#Custom added by Me
for my $Count ( 1 .. 16 ) {
if ( $Param{ 'TicketFreeText' . $Count } ) {
$Self->{LayoutObject}->Block(
Name => 'TicketFreeText_VNC' . $Count,
Data => { %Param, %AclAction },
);
$Self->{LayoutObject}->Block(
Name => 'TicketFreeText_VNC',
Data => {
%Param, %AclAction,
TicketFreeKey => $Param{ 'TicketFreeKey' . $Count },
TicketFreeText => $Param{ 'TicketFreeText' . $Count },
Count => $Count,
},
);
if ( !$Self->{ConfigObject}->Get( 'TicketFreeText' . $Count . '::Link' ) ) {
$Self->{LayoutObject}->Block(
Name => 'TicketFreeTextPlain_VNC' . $Count,
Data => { %Param, %AclAction },
);
$Self->{LayoutObject}->Block(
Name => 'TicketFreeTextPlain_VNC',
Data => {
%Param, %AclAction,
TicketFreeKey => $Param{ 'TicketFreeKey' . $Count },
TicketFreeText => $Param{ 'TicketFreeText' . $Count },
Count => $Count,
},
);
}
else {
$Self->{LayoutObject}->Block(
Name => 'TicketFreeTextLink' . $Count,
Data => { %Param, %AclAction },
);
$Self->{LayoutObject}->Block(
Name => 'TicketFreeTextLink_VNC',
Data => {
%Param, %AclAction,
TicketFreeTextLink => $Self->{ConfigObject}->Get(
'TicketFreeText' . $Count . '::Link'
),
TicketFreeKey => $Param{ 'TicketFreeKey' . $Count },
TicketFreeText => $Param{ 'TicketFreeText' . $Count },
Count => $Count,
},
);
}
}
}
###################################################################################

And then your .dtl file would look like this ---->
################################################################################
<!-- dtl:block:TicketFreeText_VNC3 -->
<tr valign="top">
<td><b>VNC:</b></td>
<td>
<!-- dtl:block:TicketFreeTextPlain_VNC3 -->
<div title="Click Here"><a href="http://servername/otrs/vnc.pl?$QData{"TicketFreeText3"}" target="_blank">Click Here</a></div>
<!-- dtl:block:TicketFreeTextPlain_VNC3 -->
</td>
</tr>
<!-- dtl:block:TicketFreeText_VNC3 -->
#############################################################################

Enjoy!
jojo
Znuny guru
Posts: 15020
Joined: 26 Jan 2007, 14:50
Znuny Version: Git Master
Contact:

Re: VNC a Machine from OTRS Freetext Field

Post by jojo »

To complicated... just define a link in the Sysconfig for the used freefield using port 5800
"Production": OTRS™ 8, OTRS™ 7, STORM powered by OTRS
"Testing": ((OTRS Community Edition)) and git Master

Never change Defaults.pm! :: Blog
Professional Services:: http://www.otrs.com :: enjoy@otrs.com
dgshue
Znuny newbie
Posts: 17
Joined: 13 Jul 2011, 14:53
Znuny Version: 3.3.7

Re: VNC a Machine from OTRS Freetext Field

Post by dgshue »

Interesting, but it is using the Java viewer... still, it is a more simpler solution.
Andre Bauer
Znuny guru
Posts: 2189
Joined: 08 Dec 2005, 17:01
Znuny Version: 5.0.x
Real Name: André Bauer
Company: Magix Software GmbH
Location: Dresden
Contact:

Re: VNC a Machine from OTRS Freetext Field

Post by Andre Bauer »

jojo wrote:To complicated... just define a link in the Sysconfig for the used freefield using port 5800
Would be nic you could show how ;-)
Prod: Ubuntu Server 16.04 / Zammad 1.2

DO NOT PM ME WITH OTRS RELATED QUESTIONS! ASK IN THE FORUMS!

OtterHub.org
dgshue
Znuny newbie
Posts: 17
Joined: 13 Jul 2011, 14:53
Znuny Version: 3.3.7

Re: VNC a Machine from OTRS Freetext Field

Post by dgshue »

I think this is what he was getting at:

OTRS/Kernel/Output/HTML/TemplateYourUsing/AgentTicketZoom.dtl

<!-- dtl:block:TicketFreeText3 -->
<tr valign="top">
<td><b>VNC:</b></td>
<td>
<!-- dtl:block:TicketFreeTextPlain3 -->
<div title="Click Here"><a href="http://$QData{"TicketFreeText3"}:5800" target="_blank">Click Here</a></div>
<!-- dtl:block:TicketFreeTextPlain3 -->
</td>
</tr>
<!-- dtl:block:TicketFreeText3 -->
jojo
Znuny guru
Posts: 15020
Joined: 26 Jan 2007, 14:50
Znuny Version: Git Master
Contact:

Re: VNC a Machine from OTRS Freetext Field

Post by jojo »

You don't need to change code or a template.

Youst change the setting TicketFreeText3::Link via sysconfig to include: http://$LQData{"TicketFreeText3"}:5800 (assuming that FreeText3 is used)


You should use LQData instead of QData. Please fill your signature with some more infos on your system
"Production": OTRS™ 8, OTRS™ 7, STORM powered by OTRS
"Testing": ((OTRS Community Edition)) and git Master

Never change Defaults.pm! :: Blog
Professional Services:: http://www.otrs.com :: enjoy@otrs.com
dgshue
Znuny newbie
Posts: 17
Joined: 13 Jul 2011, 14:53
Znuny Version: 3.3.7

Re: VNC a Machine from OTRS Freetext Field

Post by dgshue »

Jojo,
Thanks for the info for creating a link in Sysconfig. Looks like I found the hard way.
Post Reply