iT邦幫忙

2023 iThome 鐵人賽

DAY 9
0
IT管理

OCS Inventory:開源資產管理解決方案系列 第 9

如何在 OCS Inventory 安裝 Office Pack 外掛程式

  • 分享至 

  • xImage
  •  

上一篇我們已經教大家如何在 OCS Inventory 安裝 Winupdate 外掛程式,今天就來教大家如何在 OCS Inventory 安裝 Office Pack 外掛程式來取得 Office 授權金鑰,讓管理人員可以透過後五碼來比對公司是否有人私自使用盜版的金鑰來啟動 Office 軟體。

外掛模組從 OCS Inventory 2.6 版之後已經完全重寫和改進,官方也有提供許多好用的外掛程式。

例如幫您獲取 Anydesk 或者 Teamviewer 的版本與 ID,大家可以參考下列網址。
https://plugins.ocsinventory-ng.org/

若要使用外掛模組,在伺服器上安裝 Python3 是必須的。

同時,我們也需要安裝一個 python 的 scp 套件

sudo apt install python3-scp

在您的伺服器上安裝外掛分為 3 個步驟:

  • 在管理伺服器的文件系統上安裝外掛程式
  • 通過管理控制台啟用外掛程式
  • 在通訊伺服器安裝外掛程式

配置管理伺服器
我們將以 Office Pack 這個外掛程式作為演示範例

先將下載的 zip 文件放在管理伺服器的 extensions 文件夾中並解壓縮。

wget https://github.com/PluginsOCSInventory-NG/officepack/releases/download/3.4/officepack.zip
sudo apt install zip
sudo unzip officepack.zip -d /usr/share/ocsinventory-reports/ocsreports/extensions

預設路徑為 /usr/share/ocsinventory-reports/ocsreports/extensions

Archive:  officepack.zip
   creating: /usr/share/ocsinventory-reports/ocsreports/extensions/officepack/
   creating: /usr/share/ocsinventory-reports/ocsreports/extensions/officepack/APACHE/
  inflating: /usr/share/ocsinventory-reports/ocsreports/extensions/officepack/APACHE/Map.pm  
  inflating: /usr/share/ocsinventory-reports/ocsreports/extensions/officepack/APACHE/officepack.conf  
  inflating: /usr/share/ocsinventory-reports/ocsreports/extensions/officepack/LICENSE  
  inflating: /usr/share/ocsinventory-reports/ocsreports/extensions/officepack/README.md  
   creating: /usr/share/ocsinventory-reports/ocsreports/extensions/officepack/agent/
  inflating: /usr/share/ocsinventory-reports/ocsreports/extensions/officepack/agent/msofficekey.vbs  
   creating: /usr/share/ocsinventory-reports/ocsreports/extensions/officepack/cd_officepack/
  inflating: /usr/share/ocsinventory-reports/ocsreports/extensions/officepack/cd_officepack/cd_officepack.php  
  inflating: /usr/share/ocsinventory-reports/ocsreports/extensions/officepack/hook.xml  
  inflating: /usr/share/ocsinventory-reports/ocsreports/extensions/officepack/infos.json  
  inflating: /usr/share/ocsinventory-reports/ocsreports/extensions/officepack/install.php  
   creating: /usr/share/ocsinventory-reports/ocsreports/extensions/officepack/language/
   creating: /usr/share/ocsinventory-reports/ocsreports/extensions/officepack/language/en_GB/
  inflating: /usr/share/ocsinventory-reports/ocsreports/extensions/officepack/language/en_GB/en_GB.txt  
   creating: /usr/share/ocsinventory-reports/ocsreports/extensions/officepack/language/fr_FR/
  inflating: /usr/share/ocsinventory-reports/ocsreports/extensions/officepack/language/fr_FR/fr_FR.txt  
   creating: /usr/share/ocsinventory-reports/ocsreports/extensions/officepack/ms_officepack/
  inflating: /usr/share/ocsinventory-reports/ocsreports/extensions/officepack/ms_officepack/ms_officepack.php  
  inflating: /usr/share/ocsinventory-reports/ocsreports/extensions/officepack/preview.png 

解壓縮完畢後就可以將壓縮檔刪除

sudo rm officepack.zip

變更資料夾權限

sudo chown -R www-data:www-data /usr/share/ocsinventory-reports/ocsreports/extensions/officepack

配置管理控制台
接下來到管理控制台的 Extensions 點選 Extensions manager

下拉式選單選擇 officepack,點選 Install。

安裝成功後,要求您登出再重新登入一次。

配置通訊伺服器
接下來要在通訊伺服器透過 install_plugin.py 腳本進行安裝

cd /usr/share/ocsinventory-reports/ocsreports/tools
sudo python3 install_plugin.py

腳本詢問外掛程式存放位置,使用預設輸入 Enter 即可。

Where is the plugins location [/usr/share/ocsinventory-reports/ocsreports/extensions/]

腳本偵測到 officepack 外掛,輸入 0 並按 Enter 即可。

[0] => officepack
[1] => winupdate

詢問管理與通訊伺服器是否為同一台,按 Enter 即可。

The server is installed on the same server ? [y]/n

詢問通訊伺服器配置目錄的路徑,按 Enter 即可。

該腳本會將所有需要的文件複製到您的通訊伺服器的配置目錄中

Where is the server location [/etc/ocsinventory-server]

winupdatehas been successfully installed ! Don't forget to restart your Apache server

安裝成功,記得重啟 Apache 伺服器。

sudo service apache2 restart

配置客戶端
在您的伺服器上安裝外掛後,您仍然需要在所有的代理程式更新資料。

每個外掛套件裡面都會有一個 Agent 目錄

將 Agent 目錄底下的檔案複製到 OCS Inventory Agent 的 Plugins 即可

預設路徑為 C:\Program Files\OCS Inventory Agent\Plugins

接下來我們手動重啟服務就可以蒐集到 Office Key 的資料

登入 OCS Inventory 管理控制台,點選電腦名稱進入 Software 頁面。

往下拉到 Office Licences 已經幫您列出該台電腦目前安裝了哪些 Office 的版本與後五碼的授權金鑰。

很奇怪的跑出兩筆與中文亂碼,手動執行 msofficekey.vbs 看看

C:\Users\ivan_cheng\Downloads\officepack\agent>wscript msofficekey.vbs

的確是跳了兩次視窗偵測到兩筆,可能是我的筆電的登錄檔不乾淨。

此外產品名字是有正常顯示的,看樣子是寫入資料庫前變成亂碼了。

我們也可以使用下列指令,手動驗證後五碼的授權金鑰是否正確。

cscript "C:\Program Files\Microsoft Office\Office16\OSPP.VBS" /dstatus

注意看 msofficekey.vbs 也是透過上面的指令取得授權金鑰資訊,但是不包含 PRODUCT 的名稱。

Function getOfficeOSPPInfos(version)
 Dim WshShell, oExec
 Dim mTab
 Dim key, value
 Dim path
 Dim writeProduct
 Dim objOfficeDict
  
 Set WshShell = WScript.CreateObject("WScript.Shell")
 Set WshShellObj = WScript.CreateObject("WScript.Shell") 
 Set WshProcessEnv = WshShellObj.Environment("Process") 
 Set objOfficeDict = CreateObject("Scripting.Dictionary") 

 result = WshShell.Run("cmd /c cscript ""C:\Program Files (x86)\Microsoft Office\Office" & version & "\OSPP.VBS"" /dstatus > %USERPROFILE%\output.txt", 0, true)
 ' Debug : if 32 bits version available ?
 ' wscript.echo result

 ' If file not there command throw an error and return is 1 and abover
 If result > 0 then
  ' Try with the 64 bits version if available
  result = WshShell.Run("cmd /c cscript ""C:\Program Files\Microsoft Office\Office" & version & "\OSPP.VBS"" /dstatus > %USERPROFILE%\output.txt", 0, true)
  ' Debug : if 64 bits version available ?
  ' WScript.Echo result
 End If

原來 PRODUCT 的名稱是透過機碼取得的

' Office 2019
 If IsNullOrEmpty(oProd) Then
  oReg.EnumKey HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows\CurrentVersion\Uninstall", aUninstallKeys
  If Not IsNull(aUninstallKeys) Then
   For Each UninstallKey In aUninstallKeys   
    oReg.GetStringValue HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows\CurrentVersion\Uninstall\" & UninstallKey, "UninstallString", sValue, "REG_SZ"
    If InStr(LCase(sValue), "microsoft office " & Left(aOffID(a,1),2)) > 0 OR _
      (InStr(LCase(sValue), "productstoremove=") > 0 AND _
      InStr(sValue, "." & Left(aOffID(a,1),2) & "_") > 0) Then
     oNote = Mid(sValue, InStr(sValue, "productstoremove="))
     oNote = Replace(oNote, "productstoremove=","")
     oNote = Left(oNote, InStr(oNote, ".1") - 1) ' E.g: HomeBusiness2019Retail
      
     oReg.GetStringValue HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows\CurrentVersion\Uninstall\" & UninstallKey, "DisplayName", oProd, "REG_SZ"
     
     oInstall = "1"
    End If
   Next
  End If
 End If

透過 microsoft office 再去找到 DisplayName

可惜產品名稱有中文亂碼的問題,雖然不影響使用。

可能是作者在 Office Pack 3.4 版本修改了偵測 Office 版本有 Bug 吧?

希望下個版本作者能夠解決這個問題,建議大家先安裝 Office Pack 3.3 版。

到 Extensions manager,選擇 Office Pack 的 Actions 點擊刪除。

根據上面的步驟重新安裝 Office Pack 3.3 版,來源如下。

wget https://github.com/PluginsOCSInventory-NG/officepack/releases/download/3.3/officepack.zip

這次資料只有一筆,看起來正常多了。

Office Key Management
電腦這麼多台當然不可能一台一台點進去看 Office Key,因此 Office Pack 還有提供 Office Key Management 的頁面。

預設是沒有權限看到 Office Key Management 的頁面。

點選 Super Administators 進行配置

往下拉在 Pages 這邊勾選 ms_officepack 並儲存

登出再重新登入,此時 Extensions 便可看見 Office Key Management

已經根據 Office 的版本幫我們統計好數量了,是不是相當方便。

點選 Office 16, RETAIL(MAK) channel 看看

今天已經教大家如何安裝 Office Pack 外掛程式來取得授權金鑰,管理人員只要透過後五碼來比對,就可以知道公司是否有人私自使用盜版的金鑰來啟動 Office 軟體。

相信在熟悉了 Winupdate 與 Office Pack 這兩種外掛的安裝,想要安裝其他的外掛應該就難不倒大家了。

接下來我們將介紹如何在 OCS Inventory 使用 CVE 報告功能,下一篇教大家如何在 Ubuntu 20.04 安裝 CVE-Search 伺服器,敬請期待。


上一篇
如何在 OCS Inventory 安裝 Winupdate 外掛程式
下一篇
如何在 Ubuntu 20.04 安裝 CVE-Search 伺服器
系列文
OCS Inventory:開源資產管理解決方案30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言