sonic-buildimage/platform/broadcom/sonic-platform-modules-juniper/qfx5200/utils/show_thresholds
Mai Bui 2f6b34a637
[device/juniper] Mitigation for security vulnerability (#11838)
Signed-off-by: maipbui maibui@microsoft.com
Dependency: [https://github.com/sonic-net/sonic-buildimage/pull/12065](https://github.com/sonic-net/sonic-buildimage/pull/12065)
#### Why I did it
`commands` module is not secure
command injection in `getstatusoutput` being used without a static string
#### How I did it
Eliminate `commands` module, use `subprocess` module only
Convert Python 2 to Python 3
2022-11-22 10:46:12 -05:00

43 lines
1.1 KiB
Python
Executable File

#!/usr/bin/env python
import os
from sonic_py_common.general import getstatusoutput_noshell
def fantype_detect():
refpgaTMC_path = "/sys/devices/pci0000:00/0000:00:1c.0/0000:0f:00.0/refpga-tmc.15"
AFO = "1"
AFI = "0"
#default fan type is AFI
default_fantype = 0
for filename in os.listdir(refpgaTMC_path):
if filename.endswith('_type'):
fantype_path = os.path.join(refpgaTMC_path, filename)
fantype_string = ["cat", fantype_path]
status, fan_type = getstatusoutput_noshell(fantype_string)
if ((fan_type == AFO) or (fan_type == AFI)):
return fan_type
else:
pass
return default_fantype
def main():
AFO_value = "1"
fan_type = fantype_detect()
if fan_type == AFO_value:
temp_thres_file = open("/usr/local/bin/temperature_thresholds_AFO.txt", "r+")
print temp_thres_file.read()
else:
temp_thres_file = open("/usr/local/bin/temperature_thresholds_AFI.txt", "r+")
print temp_thres_file.read()
temp_thres_file.close()
if __name__ == "__main__":
main()