Exemplo n.º 1
0
 /**
  * 設定画面を表示
  *
  * @return
  */
 @Get
 @Auth(roles = "admin")
 public Boundary config() {
   ProxyConfigsDao dao = ProxyConfigsDao.get();
   ProxyConfigsEntity entity = dao.selectOnKey(AppConfig.get().getSystemName());
   if (entity != null) {
     entity.setProxyAuthPassword(NO_CHANGE_PASSWORD);
     setAttributeOnProperty(entity);
   }
   setAttribute("systemName", AppConfig.get().getSystemName());
   return forward("config.jsp");
 }
Exemplo n.º 2
0
  @Post
  @Auth(roles = "admin")
  public Boundary delete() throws Exception {
    ProxyConfigsDao dao = ProxyConfigsDao.get();
    dao.physicalDelete(AppConfig.get().getSystemName()); // 物理削除で消してしまう

    ProxyConfigsEntity entity = new ProxyConfigsEntity();
    entity.setSystemName(AppConfig.get().getSystemName());
    setAttributeOnProperty(entity);

    addMsgInfo("message.success.delete.target", getResource("knowledge.proxy.title"));

    return forward("config.jsp");
  }
Exemplo n.º 3
0
  @Post
  @Auth(roles = "admin")
  public Boundary save() throws Exception {
    List<ValidateError> errors = new ArrayList<>();
    errors.addAll(ProxyConfigsEntity.get().validate(getParams()));

    String type = getParam("proxyAuthType");
    // 認証がONの場合のチェック
    if (!type.equals(String.valueOf(AuthType.None.getValue()))) {
      if (StringUtils.isEmpty(getParam("proxyAuthUserId"))) {
        ValidateError error = new ValidateError("errors.required", getResource("label.auth.id"));
        errors.add(error);
      }
      if (StringUtils.isEmpty(getParam("proxyAuthPassword"))) {
        ValidateError error =
            new ValidateError("errors.required", getResource("label.auth.password"));
        errors.add(error);
      }
    }
    if (!errors.isEmpty()) {
      setResult(null, errors);
      return forward("config.jsp");
    }

    ProxyConfigsEntity entity = super.getParamOnProperty(ProxyConfigsEntity.class);
    ProxyConfigsDao dao = ProxyConfigsDao.get();

    if (entity.getProxyAuthPassword().equals(NO_CHANGE_PASSWORD)) {
      // パスワード変更無し
      ProxyConfigsEntity db = dao.selectOnKey(AppConfig.get().getSystemName());
      entity.setProxyAuthPassword(db.getProxyAuthPassword());
      entity.setProxyAuthSalt(db.getProxyAuthSalt());
    } else {
      // パスワードは暗号化する
      String salt = PasswordUtil.getSalt();
      entity.setProxyAuthPassword(PasswordUtil.encrypt(entity.getProxyAuthPassword(), salt));
      entity.setProxyAuthSalt(salt);
    }

    entity = dao.save(entity);

    String successMsg = "message.success.save";
    setResult(successMsg, errors);
    return config();
  }
Exemplo n.º 4
0
  @Post
  @Auth(roles = "admin")
  public Boundary test() throws Exception {
    try {
      ProxyConfigsEntity entity;
      String testUrl = getParam("testUrl");
      Integer testType = getParam("testType", Integer.class);
      if (INT_FLAG.OFF.getValue() == testType.intValue()) {
        entity = new ProxyConfigsEntity();
      } else {
        List<ValidateError> errors = new ArrayList<>();
        errors.addAll(ProxyConfigsEntity.get().validate(getParams()));

        String type = getParam("proxyAuthType");
        // 認証がONの場合のチェック
        if (!type.equals(String.valueOf(AuthType.None.getValue()))) {
          if (StringUtils.isEmpty(getParam("proxyAuthUserId"))) {
            ValidateError error =
                new ValidateError("errors.required", getResource("label.auth.id"));
            errors.add(error);
          }
          if (StringUtils.isEmpty(getParam("proxyAuthPassword"))) {
            ValidateError error =
                new ValidateError("errors.required", getResource("label.auth.password"));
            errors.add(error);
          }
        }
        if (!errors.isEmpty()) {
          setResult(null, errors);
          return forward("config.jsp");
        }

        entity = super.getParamOnProperty(ProxyConfigsEntity.class);
        ProxyConfigsDao dao = ProxyConfigsDao.get();

        if (entity.getProxyAuthPassword().equals(NO_CHANGE_PASSWORD)) {
          // パスワード変更無し
          ProxyConfigsEntity db = dao.selectOnKey(AppConfig.get().getSystemName());
          entity.setProxyAuthPassword(db.getProxyAuthPassword());
          entity.setProxyAuthSalt(db.getProxyAuthSalt());
        } else {
          // パスワードは暗号化する
          String salt = PasswordUtil.getSalt();
          entity.setProxyAuthPassword(PasswordUtil.encrypt(entity.getProxyAuthPassword(), salt));
          entity.setProxyAuthSalt(salt);
        }
      }

      // 確認用のURLで通信出来るか確認
      CrawlerLogic crawlerLogic = CrawlerLogic.get();
      String content = crawlerLogic.crawle(entity, testUrl);
      setAttribute("content", content);

      addMsgInfo("knowledge.proxy.test.done");

    } catch (Exception e) {
      LOG.warn("knowledge.proxy.test.fail", e);
      addMsgError("knowledge.proxy.test.fail");
      addMsgError(e.getClass().getSimpleName());
      if (StringUtils.isNotEmpty(e.getMessage())) {
        addMsgError(e.getMessage());
      }
    }
    return forward("config.jsp");
  }
Exemplo n.º 5
0
  private void start() throws Exception {
    super.dbInit();
    SystemConfigsEntity entity =
        SystemConfigsDao.get()
            .selectOnKey(SystemConfig.DATA_EXPORT, AppConfig.get().getSystemName());
    if (entity == null) {
      send("[Fail] create fail. please try again.");
      return;
    }
    // エクスポートデータを格納するディレクトリ
    AppConfig config = AppConfig.get();
    File base = new File(config.getTmpPath());
    File dir = new File(base, DATA_DIR);
    if (dir.exists()) {
      FileUtil.delete(dir);
    }
    dir.mkdirs();
    File attach = new File(dir, "attach");
    attach.mkdirs();
    File userdir = new File(dir, "user");
    userdir.mkdirs();

    // ナレッジデータを取得
    LoginedUser loginedUser =
        new LoginedUser() {
          @Override
          public boolean isAdmin() {
            return true;
          }
        };
    KnowledgeLogic knowledgeLogic = KnowledgeLogic.get();
    CommentsDao commentsDao = CommentsDao.get();
    KnowledgeFilesDao knowledgeFilesDao = KnowledgeFilesDao.get();

    List<KnowledgesEntity> knowledges = knowledgeLogic.searchKnowledge("", loginedUser, 0, 100);
    for (KnowledgesEntity knowledgesEntity : knowledges) {
      File f =
          new File(
              dir,
              "knowledge-"
                  + StringUtils.zeroPadding(knowledgesEntity.getKnowledgeId(), 6)
                  + ".xml");
      String xml = SerializeUtils.objectToXml(knowledgesEntity);
      FileUtil.write(f, xml);

      // ナレッジのコメントを取得
      List<CommentsEntity> comments =
          commentsDao.selectOnKnowledgeId(knowledgesEntity.getKnowledgeId());
      for (CommentsEntity commentsEntity : comments) {
        File c =
            new File(
                dir,
                "comment-"
                    + StringUtils.zeroPadding(knowledgesEntity.getKnowledgeId(), 6)
                    + "-"
                    + StringUtils.zeroPadding(commentsEntity.getKnowledgeId(), 6)
                    + ".xml");
        xml = SerializeUtils.objectToXml(commentsEntity);
        FileUtil.write(c, xml);
      }
      List<KnowledgeFilesEntity> files =
          knowledgeFilesDao.selectOnKnowledgeId(knowledgesEntity.getKnowledgeId());
      for (KnowledgeFilesEntity knowledgeFilesEntity : files) {
        KnowledgeFilesEntity file = knowledgeFilesDao.selectOnKey(knowledgeFilesEntity.getFileNo());
        File a =
            new File(
                attach,
                "attach-"
                    + StringUtils.zeroPadding(knowledgesEntity.getKnowledgeId(), 6)
                    + "-"
                    + StringUtils.zeroPadding(knowledgeFilesEntity.getFileNo(), 6)
                    + knowledgeFilesEntity.getFileName());
        OutputStream outputStream = new FileOutputStream(a);
        InputStream inputStream = file.getFileBinary();
        try {
          FileUtil.copy(inputStream, outputStream);
        } finally {
          inputStream.close();
          outputStream.close();
        }
      }
      send("[Export] knowledge-" + knowledgesEntity.getKnowledgeId());
    }

    // ユーザ情報を取得
    UsersDao usersDao = UsersDao.get();
    List<UsersEntity> users = usersDao.selectAll();
    for (UsersEntity usersEntity : users) {
      ExportUser user = new ExportUser();
      PropertyUtil.copyPropertyValue(usersEntity, user);
      File f = new File(userdir, "user-" + StringUtils.zeroPadding(user.getUserId(), 6) + ".xml");
      String xml = SerializeUtils.objectToXml(user);
      FileUtil.write(f, xml);
      send("[Export] user-" + user.getUserId());
    }

    // zip圧縮
    send("[Export] during the compression");
    String name = DATA_DIR + ".zip";
    File comp = new File(base, name);

    BufferedOutputStream output = null;
    ZipArchiveOutputStream os = null;
    try {
      output = new BufferedOutputStream(new FileOutputStream(comp));
      os = new ZipArchiveOutputStream(output);
      os.setEncoding("UTF-8");
      CompressLogic.get().addZip(os, dir, null);
    } finally {
      if (os != null) {
        os.close();
      }
      if (output != null) {
        output.close();
      }
    }
    send("[Export] complete!");
    // 圧縮の予約を削除
    SystemConfigsDao.get().physicalDelete(entity);
  }