home *** CD-ROM | disk | FTP | other *** search
/ ftp.f-secure.com / 2014.06.ftp.f-secure.com.tar / ftp.f-secure.com / support / hotfix / fsav-server / FSAVSRV900_HF07.fsfix / iuwebui / forms / common / commonphp.php < prev    next >
PHP Script  |  2010-09-07  |  20KB  |  638 lines

  1. <?php
  2.  
  3. setlocale(LC_ALL, "");
  4.  
  5. require('common2.php');
  6.  
  7. $INSIDE_TEXT_WIDTH = 524;
  8.  
  9. define('GLOBAL_FSCSS_SERVICE_NAME', 'F-Secure Anti-Virus Server Daemon');
  10. define('GLOBAL_FSMA_SERVICE_NAME', 'FSMA');
  11. define('GLOBAL_FSAVIM_SERVICE_NAME', 'fsavag4im');
  12. define('GLOBAL_FSAVIGW_SERVICE_NAME', 'F-Secure Anti-Virus for Internet Gateways Daemon');
  13. define('GLOBAL_FSAVMSE_SERVICE_NAME', 'fsavmsed');
  14. define('GLOBAL_FSAVMSE_SERVICE_NAME2', 'fsavag4mse');
  15. define('GLOBAL_BACKWEB_SERVICE_NAME1', 'FSAUA');
  16. define('GLOBAL_BACKWEB_SERVICE_NAME2', 'BackWeb Client - 7681197');
  17. define('GLOBAL_BACKWEB_SERVICE_NAME3', 'BackWeb Plug-in - 7681197');
  18. define('GLOBAL_WORLDMAP_SERVICE_NAME', 'F-Secure World Map Reporting Service');
  19.  
  20. define("GLOBAL_INT", 0);
  21. define("GLOBAL_STR", 1);
  22. define("GLOBAL_TBL", 2);
  23. define("GLOBAL_TIME_TICKS", 3);
  24. define("GLOBAL_TIMESTAMP", 4);
  25. define("GLOBAL_REG_INT", 5);
  26. define("GLOBAL_REG_STR", 6);
  27.  
  28. define("GLOBAL_SIZE_BYTES", fsloc('bytes'));
  29. define("GLOBAL_SIZE_KB", fsloc('KB'));
  30. define("GLOBAL_SIZE_MB", fsloc('MB'));
  31. define("GLOBAL_SIZE_GB", fsloc('GB'));
  32. define("GLOBAL_SIZE_TB", fsloc('TB'));
  33.  
  34. define('GLOBAL_EMPTYTBL_TEXT', 'No entries specified');
  35.  
  36. define('GLOBAL_MATCHLISTS_OID', '1.3.6.1.4.1.2213.20.1.100.40.10');
  37. define('GLOBAL_MESSAGETEMPLATES_OID', '1.3.6.1.4.1.2213.20.1.100.40.20');
  38.  
  39. define('GLOBAL_WORLDMAP_SERVICE_NAME', 'F-Secure World Map Reporting Service');
  40.  
  41. $GLOBAL_PRODUCT_NAME = 'F-Secure Web Console';
  42.  
  43. $GLOBAL_LOC_LANGS = array('DEU' => 'de_DE', 'ENG' => 'en_EMEA', 'ESN' => 'en_EMEA', 'FRA' => 'fr_FR', 'JPN' => 'ja_JP', 'ITA' => 'it_IT');
  44.  
  45. /* no fsma mode */
  46. if(GLOBAL_NO_FSMA_MODE == 1  || GLOBAL_NO_SERVICE_CHECK == 1)
  47.     define('GLOBAL_NO_FSMA_MODE', 1);
  48. else
  49.     define('GLOBAL_NO_FSMA_MODE', 0);
  50.  
  51. /* no service checks mode */
  52. if(isset($_SERVER[NO_SERVICE_CHECK]) && $_SERVER[NO_SERVICE_CHECK] == 1)
  53.     define('GLOBAL_NO_SERVICE_CHECK', 1);
  54. else
  55.     define('GLOBAL_NO_SERVICE_CHECK', 0);
  56.  
  57. /* no fsma mode */
  58. if(isset($_SERVER[DEMO_MODE]) && $_SERVER[DEMO_MODE] == 1)
  59. {
  60.     define('GLOBAL_NO_SERVICE_CHECK', 1);
  61.     define('GLOBAL_DEMO_MODE', 1);
  62. }
  63. else
  64.     define('GLOBAL_DEMO_MODE', 0);
  65.  
  66. function readSettings($Page_Settings) 
  67. {
  68.     for($i = 0; $i < count($Page_Settings); $i++)
  69.     {
  70.         if(GLOBAL_NO_FSMA_MODE == 1)
  71.         {
  72.             if($Page_Settings[$i][type] == GLOBAL_INT)
  73.                 settings_get_default_int($Page_Settings[$i][oid], &$Page_Settings[$i][value]);
  74.             else if($Page_Settings[$i][type] == GLOBAL_STR)
  75.                 settings_get_default_str($Page_Settings[$i][oid], &$Page_Settings[$i][value]);
  76.             else if($Page_Settings[$i][type] == GLOBAL_REG_INT)
  77.                 settings_get_reg_default_int($Page_Settings[$i][oid], &$Page_Settings[$i][value]);
  78.             else if($Page_Settings[$i][type] == GLOBAL_REG_STR)
  79.                 settings_get_reg_default_str($Page_Settings[$i][oid], &$Page_Settings[$i][value]);
  80.             else if($Page_Settings[$i][type] == GLOBAL_TBL)
  81.             {
  82.                 $Page_Settings[$i][value] = array();
  83.                 settings_get_default_table($Page_Settings[$i][oid], $Page_Settings[$i][value]);        
  84.             }
  85.         }
  86.         else
  87.         {
  88.             if($Page_Settings[$i][type] == GLOBAL_INT) {
  89.                 settings_get_int($Page_Settings[$i][oid], &$Page_Settings[$i][value]);
  90.                 // PHP supports unsigned integers only! values > 2147483647 becomes negative
  91.                 //  here we conert it to a normal view
  92.                 if ($Page_Settings[$i][value] < 0) $Page_Settings[$i][value] = 4294967296 + $Page_Settings[$i][value];
  93.             }
  94.             else if($Page_Settings[$i][type] == GLOBAL_STR)
  95.                 settings_get_str($Page_Settings[$i][oid], &$Page_Settings[$i][value]);
  96.             else if($Page_Settings[$i][type] == GLOBAL_REG_INT)
  97.                 settings_get_reg_int($Page_Settings[$i][oid], &$Page_Settings[$i][value]);
  98.             else if($Page_Settings[$i][type] == GLOBAL_REG_STR)
  99.                 settings_get_reg_str($Page_Settings[$i][oid], &$Page_Settings[$i][value]);
  100.             else if($Page_Settings[$i][type] == GLOBAL_TBL)
  101.             {
  102.                 $Page_Settings[$i][value] = array();
  103.                 settings_get_table($Page_Settings[$i][oid], $Page_Settings[$i][value]);        
  104.             }
  105.             if(($Page_Settings[$i][type] == GLOBAL_INT || $Page_Settings[$i][type] == GLOBAL_STR)
  106.                && settings_is_final($Page_Settings[$i][oid], 0))
  107.                 $Page_Settings[$i][lock] = getLockImg();
  108.         }
  109.     }
  110. }
  111.  
  112. function getLockImg() 
  113. {
  114.     return '<img src="/pics/lock.gif" border=0 alt="' . fsloc('Setting is final') . '" class="final_lock">';
  115. }
  116.  
  117. function readDefaultSettings($Page_Settings) 
  118. {
  119.     for($i = 0; $i < count($Page_Settings); $i++)
  120.     {
  121.         if($Page_Settings[$i][skip] == true)
  122.         {
  123.             continue;
  124.         }
  125.         
  126.         if($Page_Settings[$i][type] == GLOBAL_INT)
  127.         {
  128.             settings_get_default_int($Page_Settings[$i][oid], &$Page_Settings[$i][value]);
  129.             settings_set_int($Page_Settings[$i][oid], $Page_Settings[$i][value]);
  130.         }
  131.         else if($Page_Settings[$i][type] == GLOBAL_STR)
  132.         {    
  133.             settings_get_default_str($Page_Settings[$i][oid], &$Page_Settings[$i][value]);
  134.             settings_set_str($Page_Settings[$i][oid], $Page_Settings[$i][value]);
  135.         }
  136.         else if($Page_Settings[$i][type] == GLOBAL_TBL)
  137.         {
  138.             $Page_Settings[$i][value] = array();
  139.             settings_get_default_table($Page_Settings[$i][oid], $Page_Settings[$i][value]);        
  140.             settings_set_table($Page_Settings[$i][oid], $Page_Settings[$i][value]);
  141.         }
  142.         else if($Page_Settings[$i][type] == GLOBAL_REG_INT)
  143.         {
  144.             settings_get_reg_default_int($Page_Settings[$i][oid], &$Page_Settings[$i][value]);
  145.             settings_set_reg_int($Page_Settings[$i][oid], $Page_Settings[$i][value]);
  146.         }
  147.         else if($Page_Settings[$i][type] == GLOBAL_REG_STR)
  148.         {
  149.             settings_get_reg_default_str($Page_Settings[$i][oid], &$Page_Settings[$i][value]);
  150.             settings_set_reg_str($Page_Settings[$i][oid], $Page_Settings[$i][value]);
  151.         }
  152.     }
  153. }
  154.  
  155. function writeSettings($Page_Settings) 
  156. {
  157.     if($_SERVER[CACHED_TAG] != $_SERVER[MASTER_CACHE])
  158.         return;
  159.         
  160.     for($i = 0; $i < count($Page_Settings); $i++)
  161.     {
  162.         if(($Page_Settings[$i][type] == GLOBAL_INT || $Page_Settings[$i][type] == GLOBAL_STR) 
  163.            && settings_is_final($Page_Settings[$i][oid], 0))
  164.             continue;
  165.  
  166.         if(isset($_POST["VAR_PAGE_SETTINGS_$i"]) && $Page_Settings[$i][type] == GLOBAL_INT)
  167.             settings_set_int($Page_Settings[$i][oid], $_POST["VAR_PAGE_SETTINGS_$i"]);
  168.         else if(isset($_POST["VAR_PAGE_SETTINGS_$i"]) && $Page_Settings[$i][type] == GLOBAL_STR)
  169.             settings_set_str($Page_Settings[$i][oid], stripslashes($_POST["VAR_PAGE_SETTINGS_$i"]));
  170.         else if($Page_Settings[$i][type] == GLOBAL_TBL)
  171.             settings_set_table($Page_Settings[$i][oid], $Page_Settings[$i][value]);
  172.         else if(isset($_POST["VAR_PAGE_SETTINGS_$i"]) && $Page_Settings[$i][type] == GLOBAL_REG_INT)
  173.             settings_set_reg_int($Page_Settings[$i][oid], $_POST["VAR_PAGE_SETTINGS_$i"]);
  174.         else if(isset($_POST["VAR_PAGE_SETTINGS_$i"]) && $Page_Settings[$i][type] == GLOBAL_REG_STR)
  175.             settings_set_reg_str($Page_Settings[$i][oid], stripslashes($_POST["VAR_PAGE_SETTINGS_$i"]));
  176.     }
  177.  
  178.     if(isset($_POST[APPLY_SETTINGS])&& $_POST[APPLY_SETTINGS] == 1)    
  179.         settings_write_changed();        
  180. }
  181.  
  182.  
  183. function readPageData($Page_Settings) 
  184. {
  185.     for($i = 0; $i < count($Page_Settings); $i++)
  186.     {
  187.         if(isset($_POST["VAR_PAGE_SETTINGS_{$i}"]))
  188.         {
  189.             $Page_Settings[$i][value] = stripslashes($_POST["VAR_PAGE_SETTINGS_{$i}"]);
  190.         }
  191.         else if($Page_Settings[$i][type] == GLOBAL_INT)
  192.             settings_get_int($Page_Settings[$i][oid], &$Page_Settings[$i][value]);
  193.         else if($Page_Settings[$i][type] == GLOBAL_STR)
  194.             settings_get_str($Page_Settings[$i][oid], &$Page_Settings[$i][value]);
  195.         else if($Page_Settings[$i][type] == GLOBAL_REG_INT)
  196.             settings_get_reg_int($Page_Settings[$i][oid], &$Page_Settings[$i][value]);
  197.         else if($Page_Settings[$i][type] == GLOBAL_REG_STR)
  198.             settings_get_reg_str($Page_Settings[$i][oid], &$Page_Settings[$i][value]);
  199.     }
  200. }
  201.  
  202. function cleanPath($path)
  203. {
  204.     $arrsearch = array("\\\\", "//", "/");
  205.     $path = str_replace("\"", "", $path);
  206.     $path = str_replace($arrsearch, "\\", $path);
  207.  
  208.     $result = array();
  209.     $pathA = explode('\\', $path);
  210.     if (!$pathA[0])
  211.        $result[] = '';
  212.     foreach ($pathA AS $key => $dir) {
  213.        if ($dir == '..') {
  214.            if (end($result) == '..') {
  215.                $result[] = '..';
  216.            } elseif (!array_pop($result)) {
  217.                $result[] = '..';
  218.            }
  219.        } elseif ($dir && $dir != '.') {
  220.            $result[] = $dir;
  221.        }
  222.     }
  223.     if (!end($pathA))
  224.        $result[] = '';
  225.     return implode('\\', $result);
  226. }
  227.  
  228. function makeFullPath($param, $product)
  229. {
  230.     if(strpos($param, '\\\\') === 0)
  231.     {
  232.         if(strpos($param, '\\\\\\\\') === 0)
  233.             return stripslashes($param);
  234.         else
  235.             return $param;
  236.     }
  237.  
  238.     if(strpos($param, ':') !== false)
  239.     {
  240.         $param_m = cleanPath($param);
  241.         $ret = realpath($param_m);
  242.         if (strlen($ret)>0)
  243.             return $ret;
  244.         else
  245.             return $param_m;
  246.     }
  247.  
  248.     if($product == 'MSE')
  249.         dfp_get_policy_str('1.3.6.1.4.1.2213.20.2.5', &$product_dir);
  250.     else if($product == 'AVIM')
  251.         dfp_get_policy_str('1.3.6.1.4.1.2213.22.2.5', &$product_dir);
  252.     else if($product == 'AVIGW')
  253.         dfp_get_policy_str('1.3.6.1.4.1.2213.24.2.5', &$product_dir);
  254.     else if($product == 'CSS')
  255.         dfp_get_policy_str('1.3.6.1.4.1.2213.18.2.5', &$product_dir);
  256. //    else if($product == 'AUA')
  257. //        dfp_get_policy_str('1.3.6.1.4.1.2213.42.2.5', &$product_dir);
  258.     else if($product == 'FSMA')
  259.         dfp_get_policy_str('1.3.6.1.4.1.2213.11.2.5', &$product_dir);
  260.     else if($product == 'FQM' || $product == 'AUA')
  261.     {
  262.         dfp_get_policy_str('1.3.6.1.4.1.2213.11.2.5', &$product_dir);
  263.         $slashposition = strrpos($product_dir, '\\', -2);
  264.         if($slashposition !== FALSE)
  265.             $product_dir = substr($product_dir, 0, $slashposition) . ($product == 'FQM' ? "\\Quarantine Manager\\" : "\\FSAUA\\");
  266.     }
  267.     else 
  268.         return '';
  269.         
  270.     if ($product_dir[strlen($product_dir)-1] != "\\")
  271.         $product_dir .= "\\";
  272.  
  273.     $product_dir .= $param;
  274.     $product_dir = cleanPath($product_dir);
  275.     $ret = realpath($product_dir);
  276.     if ($ret == '')
  277.         return $product_dir;
  278.     else
  279.         return $ret;
  280. }
  281.  
  282. function get_service_installed($service_name, $status, $cache = FALSE)
  283. {
  284.     if(GLOBAL_DEMO_MODE)
  285.     {
  286.         $status = 4;
  287.         return $status;
  288.     }
  289.         
  290.     if($cache)    
  291.         system_is_service_installed_cache($service_name, &$status);
  292.     else
  293.         system_is_service_installed($service_name, &$status);
  294.  
  295.     return $status;
  296. }
  297.  
  298. function get_service_info($service_name, $status, $status_readable, $status_image)
  299. {
  300.     $status_readable = fsloc('Unknown');
  301.     $status_image = '/pics/icon/icon_yellow.gif';
  302.  
  303.     if(system_get_service_status($service_name, &$status) == -1)
  304.         return -1;
  305.             
  306.     if($status == 1) 
  307.     {
  308.         $status_image = '/pics/icon/icon_red.gif';
  309.         $status_readable = fsloc('Stopped');
  310.     }
  311.     else if($status == 2)
  312.         $status_readable = fsloc('Starting');
  313.     else if($status == 3)
  314.         $status_readable = fsloc('Stopping');
  315.     else if($status == 4)
  316.     {
  317.         $status_image = '/pics/icon/icon_green.gif';
  318.         $status_readable = fsloc('Running');
  319.     }
  320. }
  321.  
  322. function chech_db_date($css_update_version)
  323. {
  324.     $year = substr($css_update_version, 0, 4);
  325.     $month = substr($css_update_version, 5, 2);
  326.     $day = substr($css_update_version, 8, 2);
  327.  
  328.     $database_age = time() - mktime(0, 0, 0, $month, $day, $year);
  329.     @dfp_get_policy_int('1.3.6.1.4.1.2213.18.1.27.51', &$database_allowed_age); 
  330.  
  331.     if($database_age / (60*60*24) > $database_allowed_age)
  332.         return false;
  333.  
  334.     return true;
  335. }
  336.  
  337. function submit_if_standalone()
  338. {
  339.     if($GLOBALS["NoEdit"] != 'true')
  340.     {
  341.         echo '
  342.             document.form.SUBMIT_TABLE.value = 1;
  343.             document.form.submit();';
  344.     }
  345. }
  346.  
  347. function ConvertKB2KMGTB($size)
  348. {
  349.     if ($size === false || $size == "") $size = 0;
  350.     if($size > 1073741824)
  351.         $size_str = round($size / 1073741824) . ' ' . GLOBAL_SIZE_TB;
  352.     if($size > 1048576)
  353.         $size_str = round($size / 1048576) . ' ' . GLOBAL_SIZE_GB;
  354.     else if($size > 1024)
  355.         $size_str = round($size / 1024) . ' ' . GLOBAL_SIZE_MB;
  356.     else
  357.         $size_str = $size . ' ' . GLOBAL_SIZE_KB;
  358.     return $size_str;
  359. }
  360.  
  361. function utf8_substr($str,$start)
  362. {
  363.    preg_match_all("/./su", $str, $ar);
  364.  
  365.    if(func_num_args() >= 3) {
  366.        $end = func_get_arg(2);
  367.        return join("",array_slice($ar[0],$start,$end));
  368.    } else {
  369.        return join("",array_slice($ar[0],$start));
  370.    }
  371. }
  372.  
  373. function size_readable($size, $max_unit = null, $retstring = null, $need_unit = null) 
  374.     // Units 
  375.     $sizes = array(GLOBAL_SIZE_BYTES, GLOBAL_SIZE_KB, GLOBAL_SIZE_MB, GLOBAL_SIZE_GB, GLOBAL_SIZE_TB); 
  376.   
  377.     // Need unit 
  378.     if ($need_unit !== null)
  379.        $need_unit = array_search((string) $need_unit, $sizes);
  380.  
  381.     if($need_unit === null || $need_unit === false)
  382.     {
  383.         $need_unit = -1; 
  384.         // Max unit 
  385.         if ($max_unit !== null)
  386.             $max_unit = array_search((string) $max_unit, $sizes); 
  387.         if ($max_unit === null || $max_unit === false)
  388.             $max_unit = 4; 
  389.     }
  390.     else
  391.         $max_unit = $need_unit; 
  392.  
  393.     
  394.     $i = 0; 
  395.     while (($size >= 1024 || $i < $need_unit) && $i < $max_unit) 
  396.     { 
  397.         $size /= 1024; 
  398.         $i++; 
  399.     } 
  400.   
  401.     // Return string \
  402.     if ($retstring === null)
  403.         $retstring = '%01.2f %s'; 
  404.  
  405.     // don't need 123.00 B
  406.     if($i == 0 && $size < 1024)
  407.         $retstring = '%s %s'; 
  408.  
  409.     
  410.     return sprintf($retstring, $size, $sizes[$i]); 
  411.  
  412. function convert2localtime($time)
  413. {
  414.     $i = preg_split("/[^0-9]/", $time);  // 2005-11-15T11:59:01
  415.                                  //     hours  min    sec    months days   years
  416.     return date('Y-n-j g:i:s A', mktime($i[3], $i[4], $i[5], $i[1], $i[2], $i[0]) + date('Z'));
  417. }                        
  418.  
  419. function parse_time_period($miliseconds, &$normalized, &$index)
  420. {
  421.     $miliseconds /= 100; // convert to seconds
  422.     $index = INDEX_UNKNOWN;
  423.  
  424.     if($miliseconds<(60)) {
  425.        // Seconds
  426.        $normalized = $miliseconds;
  427.        $index = INDEX_SECONDS;
  428.     } else if($miliseconds<(60*60)) {
  429.         // Minutes
  430.         $normalized = round($miliseconds/60);
  431.         $index = INDEX_MINUTES;
  432.     } else if($miliseconds<(60*60*24)) {
  433.         // Hours
  434.         $normalized = round($miliseconds/60/60);
  435.         $index = INDEX_HOURS;
  436.     } else if($miliseconds<(60*60*24*7)) {
  437.         // Days
  438.         $normalized = round($miliseconds/60/60/24);
  439.         $index = INDEX_DAYS;
  440.     } else if($miliseconds<(60*60*24*30)) {
  441.         // Weeks
  442.         $normalized = round($miliseconds/60/60/24/7);
  443.         $index = INDEX_WEEKS;
  444.     } else if($miliseconds<(60*60*24*365)) {
  445.         // Months
  446.         $normalized = round($miliseconds/60/60/24/30);
  447.         $index = INDEX_MONTHS;
  448.     } else {
  449.         // Years
  450.         $normalized = round($miliseconds/60/60/24/365);
  451.         $index = INDEX_YEARS;
  452.     }
  453. }
  454.  
  455. function myFind($sDir, $sPattern, $nFlags = NULL)
  456. {
  457.     if(@file_exists("$sDir\\$sPattern")) 
  458.         return $sDir;
  459.     
  460.     $subfolders = glob($sDir . '\\*', GLOB_ONLYDIR);
  461.     if(is_array($subfolders) === FALSE)
  462.         return;
  463.     
  464.     foreach ($subfolders as $sSubDir)
  465.     {
  466.         if(strlen($sSubDir) == 0)
  467.             continue;
  468.         $foundPath = myFind($sSubDir, $sPattern, $nFlags);
  469.         if(strlen($foundPath) > 0)
  470.             return $foundPath;
  471.     }
  472.  
  473. function empty_temp_folder()
  474. {
  475.     $curpath = '..\\temp\\';
  476.     $dir = dir($curpath);
  477.     if(!$dir)
  478.         return;
  479.     while ($file = $dir->read()) 
  480.     {
  481.         if(    $file != "." && $file != ".." && 
  482.             $file != 'f-secure-background.jpg' && 
  483.             is_file($curpath.$file))
  484.         {
  485.             unlink($curpath.$file);    
  486.         }
  487.     }
  488.     $dir->close();
  489. }
  490.  
  491. function adapt_range_bound($val, $adapt)
  492. {
  493.     if ($adapt)
  494.         return $adapt."(".$val.")";
  495.     return $val;
  496. }
  497.  
  498. function get_validation_script_impl($s, $adapt)
  499. {
  500.     if ($s[type]==GLOBAL_INT)
  501.     {
  502.         // Numbers are converted to scientific format with guaranteed '.' separator.
  503.         // Manual conversion to scintific format is needed because min or max values before adaption 
  504.         // may be outside of integer range and autoconverion to string in adapt_range_bound() 
  505.         // may produce representation with ',' separator.
  506.         // Note that parseInt() used in parse_and_validate_int recognizes scientific 
  507.         // representations correctly.
  508.         $min = adapt_range_bound(sprintf("%e", $s[min]), $adapt);
  509.         $max = adapt_range_bound(sprintf("%e", $s[max]), $adapt);
  510.         return "
  511.             msg = parse_and_validate_int(v, ".$min.",".$max.");
  512.         ";
  513.     }
  514.     else if ($s[type]==GLOBAL_STR && isset($s[required]))
  515.     {
  516.         $s_name = isset($s[name]) ? ('"' . $s[name] . '"') : 'this setting';
  517.         return "
  518.             msg = (v && v != '') ? null : 'Empty value for $s_name is not allowed';
  519.         ";
  520.     }
  521.     return "";
  522. }
  523.  
  524. function make_search_virus_link($infection_name)
  525. {
  526.     if ($infection_name == "")
  527.         return "-";
  528.     return "<a href='http://cgi.f-secure.com/cgi-bin/search.cgi?q=".urlencode($infection_name)."' target=_blank style='COLOR: blue;'>".$infection_name."</a>";
  529. }
  530.  
  531. function get_validation_script($setting, $tab_name, $input_indices, $range_adapter_fn = null)
  532. {    
  533.     $form_name = "form_".$tab_name;
  534.     if ($setting[type]==GLOBAL_INT && (!isset($setting[min]) || !isset($setting[max])))
  535.         return "";
  536.     return "
  537.     {
  538.         var f = document.".$form_name.";
  539.         if (f)
  540.         {
  541.             var e = f.".$input_indices.";
  542.             if (e)
  543.             {
  544.                 var v = e.value;
  545.                 var msg = null;
  546.                 ".get_validation_script_impl($setting, $range_adapter_fn)."
  547.                 if (msg != null)
  548.                 {
  549.                     show_webui_message_box('" . fsloc('Invalid input') . "', msg, 0);
  550.                     try {e.focus();} catch (e) {}
  551.                     return false;
  552.                 }
  553.             }
  554.         }
  555.     };";
  556. }
  557.  
  558. function is_backweb_service_installed()
  559. {
  560.     foreach (array(GLOBAL_BACKWEB_SERVICE_NAME1, GLOBAL_BACKWEB_SERVICE_NAME2, GLOBAL_BACKWEB_SERVICE_NAME3) as $i) 
  561.         if (get_service_installed($i, null, TRUE) == 1)
  562.             return $i;
  563.     return null;
  564. }
  565. function is_mse_service_installed()
  566. {
  567.     if (!products_is_av4mse_installed())
  568.         return null;
  569.     foreach (array(GLOBAL_FSAVMSE_SERVICE_NAME, GLOBAL_FSAVMSE_SERVICE_NAME2) as $i) 
  570.         if (get_service_installed($i, null, TRUE) == 1)
  571.             return $i;
  572.     return null;
  573. }
  574.  
  575. function is_transport_agent_installed($mse_service_name)
  576. {
  577.     if (!products_is_av4mse_installed())
  578.         return false;
  579.     if (GLOBAL_NO_SERVICE_CHECK)
  580.         return true;
  581.     if($mse_service_name == GLOBAL_FSAVMSE_SERVICE_NAME2)
  582.         return true;
  583.  
  584.     return system_get_registry_value('HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\MSExchangeTransport', 'ObjectName', &$tra_acc) == 0 && $tra_acc != '';
  585. }
  586.  
  587. function is_store_agent_installed()
  588. {
  589.     if (!products_is_av4mse_installed())
  590.         return false;
  591.     if (GLOBAL_NO_SERVICE_CHECK)
  592.         return true;
  593.     return system_get_registry_value('HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\MSExchangeIS', 'ObjectName', &$store_acc) == 0 && $store_acc != '';
  594. }
  595.  
  596. function get_query_string_param($key, $def = null)
  597. {
  598.     foreach (explode('&', $_SERVER['QUERY_STRING']) as $entry)
  599.     {
  600.         $tmp = explode('=', $entry);
  601.         if (isset($tmp[0]) && $tmp[0] === $key && isset($tmp[1]))
  602.             return $tmp[1];
  603.     }
  604.     return $def;
  605. }
  606.  
  607. function EscapeJSCodeString($str)
  608. {
  609.     return '"'.htmlspecialchars(addcslashes($str, '"\\'), ENT_QUOTES).'"';
  610. }
  611.  
  612. function cut_ctr_chars($string)
  613. {
  614.     if ($string[0] >= 0 && $string[0] < 32)
  615.     {
  616.         return substr($string,1,-1);
  617.     }
  618.     return $string;
  619. }
  620.  
  621. class SortUtil {
  622.     static private $sortfield = null;
  623.     static private $sortorder = 1;
  624.     static private function sort_callback(&$a, &$b) {
  625.         if($a[self::$sortfield] == $b[self::$sortfield]) return 0;
  626.         return ($a[self::$sortfield] < $b[self::$sortfield])? -self::$sortorder : self::$sortorder;
  627.     }
  628.     static function sort(&$v, $field, $asc=true) {
  629.         self::$sortfield = $field;
  630.         self::$sortorder = $asc? 1 : -1;
  631.         usort($v, array('SortUtil', 'sort_callback'));
  632.     }
  633. }
  634.  
  635. ?>