Plugins:TeamViewer

From OCS Inventory NG
Jump to: navigation, search

Take control of remote computers with TeamViewer

Thanks to Benoit SARDA for this contribution.

Windows Agent configuration

Creation of the VBscript

This script is a VB script.

You have to place it in C:\Program Files\OCS Inventory Agent\Plugins .

The name is not important.

Nothing more to do.

Code

'-------------------------------------------
' Autor : Benoit SARDA
'-------------------------------------------
On Error Resume Next
 
'permet de lire une valeur dans la base de registre 
Set WshShell = CreateObject("Wscript.Shell") 
 
 
Dim RegTVClientID,RegTVVersion
Dim arrSubKeys(3,2)
 
arrSubKeys(0,0) = "TeamViewer 8"
arrSubKeys(0,1) = "HKEY_LOCAL_MACHINE\Software\TeamViewer\Version8\ClientID"
arrSubKeys(0,2) = "HKEY_LOCAL_MACHINE\Software\TeamViewer\Version8\Version"
arrSubKeys(1,0) = "TeamViewer 8"
arrSubKeys(1,1) = "HKEY_LOCAL_MACHINE\Software\Wow6432Node\TeamViewer\Version8\ClientID"
arrSubKeys(1,2) = "HKEY_LOCAL_MACHINE\Software\Wow6432Node\TeamViewer\Version8\Version"
arrSubKeys(2,0) = "TeamViewer 7"
arrSubKeys(2,1) = "HKEY_LOCAL_MACHINE\Software\TeamViewer\Version7\ClientID"
arrSubKeys(2,2) = "HKEY_LOCAL_MACHINE\Software\TeamViewer\Version7\Version"
arrSubKeys(3,0) = "TeamViewer 7"
arrSubKeys(3,1) = "HKEY_LOCAL_MACHINE\Software\Wow6432Node\TeamViewer\Version7\ClientID"
arrSubKeys(3,2) = "HKEY_LOCAL_MACHINE\Software\Wow6432Node\TeamViewer\Version7\Version"
arrSubKeys(4,0) = "TeamViewer 6"
arrSubKeys(4,1) = "HKEY_LOCAL_MACHINE\Software\TeamViewer\Version6\ClientID"
arrSubKeys(4,2) = "HKEY_LOCAL_MACHINE\Software\TeamViewer\Version6\Version"
arrSubKeys(5,0) = "TeamViewer 6"
arrSubKeys(5,1) = "HKEY_LOCAL_MACHINE\Software\Wow6432Node\TeamViewer\Version6\ClientID"
arrSubKeys(5,2) = "HKEY_LOCAL_MACHINE\Software\Wow6432Node\TeamViewer\Version6\Version"
arrSubKeys(6,0) = "TeamViewer 5"
arrSubKeys(6,1) = "HKEY_LOCAL_MACHINE\Software\TeamViewer\Version5\ClientID"
arrSubKeys(6,2) = "HKEY_LOCAL_MACHINE\Software\TeamViewer\Version5\Version"
arrSubKeys(7,0) = "TeamViewer 5"
arrSubKeys(7,1) = "HKEY_LOCAL_MACHINE\Software\Wow6432Node\TeamViewer\Version5\ClientID"
arrSubKeys(7,2) = "HKEY_LOCAL_MACHINE\Software\Wow6432Node\TeamViewer\Version5\Version"
 
' pour chaque element du tableau
For x = LBound(arrSubKeys, 1) To UBound(arrSubKeys, 1)
	' lecture des clés
	RegTVClientID = WshShell.RegRead( arrSubKeys(x,1) )
	RegTVVersion = WshShell.RegRead( arrSubKeys(x,2) )
	If Not IsNull(RegTVClientID) AND RegTVClientID <> "" Then
		'MsgBox RegTVClientID, vbInformation
		'MsgBox RegTVVersion, vbInformation
		' Ecriture des donnees vers la sortie standard, qui sera le XML
		Wscript.Echo "<TEAMVIEWER>"
		Wscript.Echo "<TVCLIENTID>" & RegTVClientID & "</TVCLIENTID>"
		Wscript.Echo "<TVVERSION>" & RegTVVersion & "</TVVERSION>"
		Wscript.Echo "</TEAMVIEWER>"
		' puis on quitte, il ne peut y avoir qu'un seul teamviewer
		Exit For
	End If
Next

Database server

Creation of table in database to store informations

You have to create a new table which will receive new data

CREATE TABLE teamviewer (ID INTEGER NOT NULL AUTO_INCREMENT, HARDWARE_ID INTEGER NOT NULL, TVCLIENTID VARCHAR(255) DEFAULT NULL,
TVVERSION VARCHAR(255) DEFAULT NULL, PRIMARY KEY (ID,HARDWARE_ID)) ENGINE=INNODB ;

Management server

Modification of the engine

You have to modify Map.pm ( in /usr/local/share/perl/5.10.0/Apache/Ocsinventory/ )

#Plugin TEAMVIEWVER
  teamviewer => {
   mask => 0,
   multi => 1,
   auto => 1,
   delOnReplace => 1,
   sortBy => 'TVCLIENTID',
   writeDiff => 0,
   cache => 0,
   fields => {
        TVCLIENTID => {},
        TVVERSION => {},
    }
  },
Warning: When you will upgrade your OCS Inventory Server, Map.pm will be overwrite. Don't forget to save this file before upgrading.


Communication server

Create the workspace

First, it's important to respect files architecture. It's necessary to create a new branch in the

plugins/computer_detail directory

and named your new directory

cd_<your_module_name> 

In our case, cd_teamviewer. This directory will contain cd_teamviewer.php.


Plugin teamviewer 1.jpg

Then, import your 3 icons in

plugins/computer_detail/img

The name of the new icon will be in the form cd_<your_module_name>.png for inactive icon and cd_<your_module_name>_a.png for active icon. Add an icon is not an obligation because you can add your module to a menu already in place or even create a menu on a icon.


Here, icons you can use :

Cd teamviewer.pngCd teamviewer a.pngCd teamviewer d.png

Create the PHP file

I copy it in

plugins/computer_detail/cd_teamviewer/

and rename it in

cd_teamviewer.php

I modify the code simply to specify the path of LauchTeamViewer.exe that you will create at the end of page.

<?php
//====================================================================================
// OCS INVENTORY REPORTS
// Copyleft Benoit SARDA
// Web: http://www.ocsinventory-ng.org
//
// This code is open source and may be copied and modified as long as the source
// code is always made freely available.
// Please refer to the General Public Licence http://www.gnu.org/ or Licence.txt
//====================================================================================
 
	print_item_header("TeamViewer CLientID & Version");
	if (!isset($protectedPost['SHOW']))
		$protectedPost['SHOW'] = 'NOSHOW';
	$form_name="teamviewer";
	$table_name=$form_name;
	echo "<form name='".$form_name."' id='".$form_name."' method='POST' action=''>";
	$list_fields=array('TVCLIENTID' => 'TVCLIENTID',
			   'TVVERSION' => 'TVVERSION');
 
		$list_col_cant_del=$list_fields;
	//$tab_options['LBL']['OTHER']=$l->g(6001);
 	$tab_options['LIEN_LBL']['TVCLIENTID']="teamviewer://"; //change this link for you
	$tab_options['LIEN_CHAMP']['TVCLIENTID']='TVCLIENTID';
	$tab_options['LIEN_TYPE']['TVCLIENTID']='POPUP';
	$tab_options['POPUP_SIZE']['TVCLIENTID']="width=900,height=600";
	$default_fields= $list_fields;
	$queryDetails  = "SELECT * FROM teamviewer WHERE (hardware_id = $systemid)";
	tab_req($table_name,$list_fields,$default_fields,$list_col_cant_del,$queryDetails,$form_name,80,$tab_options);
	echo "</form>";
?>
Warning: You need to fix good permissions on cd_teamviewer.php.


chmod 0755 ./cd_teamviewer.php
chown root:www-data ./cd_teamviewer.php

Modification of language file

Files are in

plugins/language/

We will modify english language, so

plugins/language/english/english.txt

And add at the end of file

6041 TeamViewer
6042 TeamViewer CLientID & Version

Activation of the plugin

You have to activate your plugin in

/plugins/computer_detail/cd_config.txt

Here, just the diff of this file.

<ORDER>
.......
.......
24:cd_teamviewer
</ORDER>

<LBL>
.......
.......
cd_teamviewer:g(6041)
</LBL>

<ISAVAIL>
.......
.......
cd_teamviewer:teamviewer
</ISAVAIL>

<URL>
.......
cd_teamviewer:24
.......
</URL>

Modification of multicriteria search page

The goal is to have possibility to do a multicriteria search on these new data File to modify is

plugins/main_sections/ms_multi_search/ms_multi_search.php

Code to add :

$sort_list=array("HARDWARE-IPADDR" =>$l->g(82).": ".$l->g(34),
                 "NETWORKS-MACADDR"=>$l->g(82).": ".$l->g(95),
                 "SOFTWARES-NAME"=>$l->g(20).": ".$l->g(49),
                   "SOFTWARES-VERSION"=>$l->g(20).": ".$l->g(277),
                 "SOFTWARES-BITSWIDTH"=>$l->g(20).": ".$l->g(1247),
                 "SOFTWARES-PUBLISHER"=>$l->g(20).": ".$l->g(69),
                   "HARDWARE-DESCRIPTION"=>$l->g(25).": ".$l->g(53),
                 "HARDWARE-USERDOMAIN"=>$l->g(82).": ".$l->g(557),
                    "BIOS-BVERSION"=>$l->g(273).": ".$l->g(209),
                 "HARDWARE-USERID"=>$l->g(243).": ".$l->g(49),
                 "HARDWARE-OSCOMMENTS"=>$l->g(25).": ".$l->g(51),
                 "NETWORKS-IPGATEWAY"=>$l->g(82).": ".$l->g(207),
                 "NETWORKS-IPSUBNET"=>$l->g(82).": ".$l->g(331),
                 "NETWORKS-IPDHCP"=>$l->g(82).": ".$l->g(281),
                 "BIOS-SSN"=>$l->g(273).": ".$l->g(36),
                 "BIOS-SMODEL"=>$l->g(273).": ".$l->g(65),
                 "HARDWARE-NAME"=>$l->g(729).": ".$l->g(49),
                 "HARDWARE-PROCESSORT"=>$l->g(54).": ".$l->g(66),
                 "BIOS-SMANUFACTURER"=>$l->g(729).": ".$l->g(64),
                 "MONITORS-SERIAL"=>$l->g(554),
                 "MONITORS-DESCRIPTION"=>$l->g(556),
                 "MONITORS-MANUFACTURER"=>$l->g(555),
                 "DRIVES-VOLUMN"=>$l->g(92).": ".$l->g(964),
                 "BIOS-BMANUFACTURER"=>$l->g(273).": ".$l->g(284),
                 "BIOS-BVERSION"=>$l->g(273).": ".$l->g(277),
                 "BIOS-ASSETTAG"=>$l->g(273).": ".$l->g(216),
                 "HARDWARE-LASTDATE"=>"OCS: ".$l->g(46),
                 "HARDWARE-LASTCOME"=>"OCS: ".$l->g(820),
                 "HARDWARE-WORKGROUP"=>$l->g(82).": ".$l->g(33),
                 "STORAGES-NAME"=>$l->g(63).": ".$l->g(49),
                 "STORAGES-SERIALNUMBER"=>$l->g(63).": ".$l->g(36),
                 "STORAGES-DISKSIZE"=>$l->g(63).": ".$l->g(67),
            ++ "TEAMVIEWER-TVCLIENTID"=>$l->g(6042).": ".TVCLIENTID,
	    ++ "TEAMVIEWER-TVVERSION"=>$l->g(6042).": ".TVVERSION);

and

$optSelectField=array( "HARDWARE-IPADDR"=>$sort_list["HARDWARE-IPADDR"],
               "NETWORKS-MACADDR"=>$sort_list["NETWORKS-MACADDR"],//$l->g(82).": ".$l->g(95),
               "SOFTWARES-NAME"=>$sort_list["SOFTWARES-NAME"],//$l->g(20).": ".$l->g(49),
               "SOFTWARES-VERSION"=>$sort_list["SOFTWARES-VERSION"],//$l->g(20).": ".$l->g(277),
               "SOFTWARES-BITSWIDTH"=> $sort_list["SOFTWARES-BITSWIDTH"],
               "SOFTWARES-PUBLISHER"=> $sort_list["SOFTWARES-PUBLISHER"],
               "HARDWARE-DESCRIPTION"=>$sort_list["HARDWARE-DESCRIPTION"],//$l->g(25).": ".$l->g(53),
               "HARDWARE-USERDOMAIN"=>$sort_list["HARDWARE-USERDOMAIN"],//$l->g(82).": ".$l->g(557),
               "BIOS-BVERSION"=>$sort_list["BIOS-BVERSION"],//$l->g(273).": ".$l->g(209),
               "HARDWARE-USERID"=>$sort_list["HARDWARE-USERID"],//$l->g(243).": ".$l->g(49),
               "HARDWARE-OSCOMMENTS"=>$sort_list["HARDWARE-OSCOMMENTS"],//$l->g(25).": ".$l->g(51),
               "NETWORKS-IPGATEWAY"=>$sort_list["NETWORKS-IPGATEWAY"],//$l->g(82).": ".$l->g(207),
               "NETWORKS-IPSUBNET"=>$sort_list["NETWORKS-IPSUBNET"],//$l->g(82).": ".$l->g(331),
               "NETWORKS-IPDHCP"=>$sort_list["NETWORKS-IPDHCP"],//$l->g(82).": ".$l->g(281),
               "BIOS-SSN"=>$sort_list["BIOS-SSN"],//$l->g(273).": ".$l->g(36),
               "BIOS-SMODEL"=>$sort_list["BIOS-SMODEL"],//$l->g(273).": ".$l->g(65),
               "HARDWARE-NAME"=>$sort_list["HARDWARE-NAME"],//$l->g(729).": ".$l->g(49),
               "HARDWARE-PROCESSORT"=>$sort_list["HARDWARE-PROCESSORT"],//$l->g(54).": ".$l->g(66),
               "BIOS-SMANUFACTURER"=>$sort_list["BIOS-SMANUFACTURER"],//$l->g(729).": ".$l->g(64),
               "MONITORS-SERIAL"=>$sort_list["MONITORS-SERIAL"],//$l->g(554),
               "MONITORS-DESCRIPTION"=>$sort_list["MONITORS-DESCRIPTION"],//$l->g(556),
               "MONITORS-MANUFACTURER"=>$sort_list["MONITORS-MANUFACTURER"],//$l->g(555),
                "DRIVES-VOLUMN"=>$sort_list["DRIVES-VOLUMN"],//$l->g(92).": ".$l->g(964),
               "BIOS-BMANUFACTURER"=>$sort_list["BIOS-BMANUFACTURER"],//$l->g(273).": ".$l->g(284),
               "BIOS-BVERSION"=>$sort_list["BIOS-BVERSION"],//$l->g(273).": ".$l->g(277),
               "BIOS-ASSETTAG"=>$sort_list["BIOS-ASSETTAG"],//$l->g(273).": ".$l->g(277),
               "HARDWARE-LASTDATE"=>$sort_list["HARDWARE-LASTDATE"],//"OCS: ".$l->g(46),
               "HARDWARE-LASTDATE-LBL"=>"calendar",
               "HARDWARE-LASTDATE-SELECT"=>array("small"=>$l->g(346),"tall"=>$l->g(347)),
               "HARDWARE-LASTCOME"=>$sort_list["HARDWARE-LASTCOME"],//"OCS: ".$l->g(820),
               "HARDWARE-LASTCOME-LBL"=>"calendar",
               "HARDWARE-LASTCOME-SELECT"=>array("small"=>$l->g(346),"tall"=>$l->g(347)),
               "HARDWARE-WORKGROUP"=>$sort_list["HARDWARE-WORKGROUP"],
               "STORAGES-NAME"=>$sort_list["STORAGES-NAME"],
               "STORAGES-SERIALNUMBER"=>$sort_list["STORAGES-SERIALNUMBER"],
               "STORAGES-DISKSIZE" =>$sort_list["STORAGES-DISKSIZE"],
               "STORAGES-DISKSIZE-SELECT"=>array("exact"=>$l->g(410),"small"=>$l->g(201),"tall"=>$l->g(202)),
               "STORAGES-DISKSIZE-LBL"=>"MB",
        ++  "TEAMVIEWER-TVCLIENTID"=>$sort_list["TEAMVIEWER-TVCLIENTID"]);

and

$sort_list_2Select=array("HARDWARE-USERAGENT"=>"OCS: ".$l->g(966),
				"DEVICES-IPDISCOVER"=>$l->g(107).": ".$l->g(312),
				"DEVICES-FREQUENCY"=>$l->g(107).": ".$l->g(429),
				"GROUPS_CACHE-GROUP_ID"=>$l->g(583).": ".$l->g(49),
				"DOWNLOAD_HISTORY-PKG_ID"=>$l->g(512).": ".$l->g(969),
				"STORAGES-TYPE"=>$l->g(63).": ".$l->g(66),
				"STORAGES-DESCRIPTION"=>$l->g(63).": ".$l->g(53),
				"STORAGES-MODEL"=>$l->g(63).": ".$l->g(65),
			   	"BIOS-TYPE"=>$l->g(273).": ".$l->g(66),
		++	"TEAMVIEWER-TVVERSION"=>"TeamViewer ClientID & Version".": ".TVVERSION);

and finally

$opt2Select=array("HARDWARE-USERAGENT"=>$sort_list_2Select["HARDWARE-USERAGENT"],//"OCS: ".$l->g(966),
	"HARDWARE-USERAGENT-SQL1"=>"select distinct USERAGENT as 'NAME' from hardware where USERAGENT != '' ".(isset($list_id_computer)? " and id in ".$list_id_computer : '')." order by 1",
	"HARDWARE-USERAGENT-SELECT"=>array('exact'=>$l->g(410)
						,'diff'=>$l->g(130)
						),
	"DEVICES-IPDISCOVER"=>$sort_list_2Select["DEVICES-IPDISCOVER"],//$l->g(107).": ".$l->g(312),
	"DEVICES-IPDISCOVER-SQL1"=>array("1"=>$l->g(502),"2"=>$l->g(503),"0"=>$l->g(506),"DEFAULT1"=>$l->g(504),"DEFAULT0"=>$l->g(505)),
	"DEVICES-IPDISCOVER-SELECT"=>array('exact'=>$l->g(410)
						,'diff'=>$l->g(130)
						),
	"DEVICES-FREQUENCY"=>$sort_list_2Select["DEVICES-FREQUENCY"],//$l->g(107).": ".$l->g(429),
	"DEVICES-FREQUENCY-SQL1"=>array("0"=>$l->g(485),"DEFAULT"=>$l->g(488),"-1"=>$l->g(486),"PERSO"=>$l->g(487)),
	"DEVICES-FREQUENCY-SELECT"=>array('exact'=>$l->g(410)
						,'diff'=>$l->g(130)
						),
	"GROUPS_CACHE-GROUP_ID"=>$sort_list_2Select["GROUPS_CACHE-GROUP_ID"],//$l->g(583).": ".$l->g(49),
	"GROUPS_CACHE-GROUP_ID-SQL1"=>"select ID,NAME from hardware where deviceid = '_SYSTEMGROUP_' order by 2",
	"GROUPS_CACHE-GROUP_ID-SELECT"=>array('exact'=>$l->g(967)
						,'diff_exact'=>$l->g(968)
						),
	"DOWNLOAD_HISTORY-PKG_ID"=>$sort_list_2Select["DOWNLOAD_HISTORY-PKG_ID"],//$l->g(512).": ".$l->g(969),
	"DOWNLOAD_HISTORY-PKG_ID-SQL1"=>$sql_history_download,
	"DOWNLOAD_HISTORY-PKG_ID-SELECT"=>array('exact'=>$l->g(507)
						,'diff'=>$l->g(508)
						),
	"STORAGES-TYPE"=>$sort_list_2Select["STORAGES-TYPE"],//$l->g(512).": ".$l->g(969),
	"STORAGES-TYPE-SQL1"=>"select distinct type as ID,type as NAME from storages order by 2",
	"STORAGES-TYPE-SELECT"=>array('exact'=>$l->g(507)
						,'diff'=>$l->g(508)
						),					
	"STORAGES-DESCRIPTION"=>$sort_list_2Select["STORAGES-DESCRIPTION"],//$l->g(512).": ".$l->g(969),
	"STORAGES-DESCRIPTION-SQL1"=>"select distinct description as ID,description as NAME from storages order by 2",
	"STORAGES-DESCRIPTION-SELECT"=>array('exact'=>$l->g(507)
						,'diff'=>$l->g(508)
						),		
	"STORAGES-MODEL"=>$sort_list_2Select["STORAGES-MODEL"],//$l->g(512).": ".$l->g(969),
	"STORAGES-MODEL-SQL1"=>"select distinct MODEL as ID,MODEL as NAME from storages order by 2",
	"STORAGES-MODEL-SELECT"=>array('exact'=>$l->g(507)
						,'diff'=>$l->g(508)
						),		
 
	"BIOS-TYPE"=>$sort_list_2Select["BIOS-TYPE"],//$l->g(273).": ".$l->g(66),
	"BIOS-TYPE-SQL1"=>"select distinct TYPE as ID,TYPE as NAME from bios order by 2",
	"BIOS-TYPE-SELECT"=>array('exact'=>$l->g(507)
						,'diff'=>$l->g(508)
						),		
	++    "TEAMVIEWER-TVVERSION"=>$sort_list_2Select["TEAMVIEWER-TVVERSION"],
	++    "TEAMVIEWER-TVVERSION-SQL1"=>"select distinct TVVERSION as ID,TVVERSION as NAME from teamviewer order by 2",
	++    "TEAMVIEWER-TVVERSION-SELECT"=>array('exact'=>$l->g(410)
						,'diff'=>$l->g(130)),
	                			 );

Add TeamViewer column in the "All computers" page

If you would see the TeamViewer Client ID in the list of all computers, you need to modify the php file. File to modify is

plugins/main_sections/ms_all_computers/ms_all_computers.php

Code to add :

$list_fields2 = array ( $l->g(46) => "h.lastdate",
			......
                       $l->g(557) => "h.userdomain",
           ++       $l->g(6040) => "t.tvclientid");

and

$queryDetails  = $sql['SQL']." from hardware h
                                ......
                                LEFT JOIN teamviewer t ON t.hardware_id=h.id
				......

Display the result in administration console

Connect to the GUI, select a machine, and click on new icon. You can see the Teamviewer version and Client ID.

Plugin teamviewer 2.jpg

If you click on Teamviewer ID, TeamViewver is launched.

Creation of link to launch TeamViewer

You have to create a .reg file, execute it on computer which take control on remonte computer. After that, you will just have to go to URL teamviewer:// through your browser to launch TeamViewer

TeamViewer.reg

Windows Registry Editor Version 5.00
 
[HKEY_CLASSES_ROOT\teamviewer]
@="URL:TeamViewer Remote Control"
"URL Protocol"=""
 
[HKEY_CLASSES_ROOT\teamviewer\DefaultIcon]
@="\"C:\\Program Files\\TeamViewer\\Version6\\TeamViewer.exe\""
 
 
[HKEY_CLASSES_ROOT\teamviewer\shell\open\command]
@="\"C:\\Program Files\\TeamViewer\\Version6\\TeamViewer.exe\"

Execute this file on earch computer that will take control on remote hosts (admin computer)