package org.ovirt.engine.core.common.utils;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.ovirt.engine.core.common.businessentities.VdcOption;
import org.ovirt.engine.core.common.config.Config;
import org.ovirt.engine.core.common.config.ConfigValues;
import org.ovirt.engine.core.dal.dbbroker.DbFacade;
import org.slf4j.LoggerFactory;

public class VerifyLicenseStatus {
    private static final org.slf4j.Logger log = LoggerFactory.getLogger(VerifyLicenseStatus.class);
    //验证激活状态
    public static boolean getVerifyActiveState(DbFacade dbf){
        VdcOption vdcOption=dbf.getVdcOptionDao().getByNameAndVersion("ActivCode", "general");
        boolean isAcive=false;
        if(vdcOption!=null&&vdcOption.getoption_value()!=null &&!"".equals(vdcOption.getoption_value())){
            String activCode= vdcOption.getoption_value();
            activCode=SecretKey.decode(activCode);
            activCode=SecretKey.to16String(activCode);
            activCode=activCode.replace("-", "");
            String UUID = VerifyLicenseStatus.getUuid();
            UUID = UUID.replace("-", "");

            isAcive = UUID.equals(activCode);

        }
        return isAcive;

    }
    //验证过期状态
    public static boolean getVerifyExpiredState(){
        String installationTime = Config.<String> getValue(ConfigValues.InstallationTime);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date=null;
        Date currentDate=new Date();
        boolean isTimeout=false;
        try {
            date = sdf.parse(installationTime);
            int addDay = 30;//加30天
            date.setDate(date.getDate()+addDay);
            isTimeout=currentDate.after(date);
        } catch (ParseException e) {
            log.info("时间转换失败！");
            e.printStackTrace();
        }
        return isTimeout;
    }
    //获得UUID
    public static String getUuid(){
        String UUID = null;
        File file = new File("/sys/class/dmi/id/product_uuid");
        try {
            if (file.isFile() && file.exists()) { // 判断文件是否存在
                InputStreamReader read = new InputStreamReader(new FileInputStream(file));
                BufferedReader bufferedReader = new BufferedReader(read);
                UUID = bufferedReader.readLine();
            } else {
                log.info("找不到指定的文件");
            }
        } catch (Exception e) {
            log.info("异常出现");
            e.printStackTrace();
        }
        return UUID;
    }
}

@@ -1931,14 +1931,30 @@
 fo(%22
-%E6%97%B6%E9%97%B4%E8%BD%AC%E6%8D%A2%E5%A4%B1%E8%B4%A5
+Time conversion failed
 %EF%BC%81%22);
@@ -2512,16 +2512,38 @@
 fo(%22
-%E6%89%BE%E4%B8%8D%E5%88%B0%E6%8C%87%E5%AE%9A%E7%9A%84%E6%96%87%E4%BB%B6
+Cannot find the specified file
 %22);%0A
@@ -2614,12 +2614,26 @@
 fo(%22
-%E5%BC%82%E5%B8%B8%E5%87%BA%E7%8E%B0
+Error getting UUID
 %22);%0A

Update VerifyLicenseStatus.java