gt:             v[0] = uplib_check_angel_prog;
context: /*
    This file is part of the "UpLib 1.7.11" release.
    Copyright (C) 2003-2011  Palo Alto Research Center, Inc.
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation, Inc.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
  
  package com.parc.uplib.portal;
  
  import javax.swing.JApplet;
  import java.io.*;
  import java.awt.dnd.*;
  import java.util.*;
  import java.util.regex.*;
  import java.util.logging.*;
  import java.awt.event.*;
  import java.awt.image.*;
  import java.awt.geom.*;
  import java.awt.font.*;
  import java.awt.*;
  import java.awt.dnd.*;
  import java.awt.CardLayout;
  import java.awt.datatransfer.*;
  import java.awt.BorderLayout;
  import javax.swing.*;
  import javax.swing.event.*;
  import javax.swing.text.*;
  import javax.swing.text.html.*;
  import javax.swing.border.*;
  import javax.imageio.*;
  import java.net.URL;
  import java.net.URLEncoder;
  import java.net.HttpURLConnection;
  import javax.net.ssl.HttpsURLConnection;
  import java.lang.reflect.*;
  import java.lang.ref.SoftReference;
  import java.text.SimpleDateFormat;
  
  import com.parc.uplib.util.BrowserLauncher;
  import com.parc.uplib.util.Configurator;
  import com.parc.uplib.util.MetadataFile;
  import com.parc.uplib.util.LogStackTrace;
  import com.parc.uplib.util.DocIDFilenameFilter;
  import com.parc.uplib.util.WorkThread;
  import com.parc.uplib.util.WorkPopup;
  import com.parc.uplib.util.ErrorDialog;
  
  public class RepositoryMonitor extends JPanel implements ActionListener {
  
      public final static int STATE_RUNNING = 0;
      public final static int STATE_TROUBLED = 1;
      public final static int STATE_STOPPED = 2;
      public final static int STATE_TRANSITIONING = 4;
      public final static int STATE_MISSING = 8;
  
      private final static Color BACKGROUND_COLOR = new Color(.878f, .941f, .973f);
      private final static Color YELLOW = new Color(1.0f, 1.0f, 0.0f);
      private final static Color UPLIB_ORANGE = new Color(.937f, .157f, .055f);
      private final static Color TOOLS_COLOR = new Color(.754f, .848f, .910f);
      private final static Color LEGEND_COLOR = new Color(.602f, .676f, .726f);
      private final static Color WHITE = new Color(1.0f, 1.0f, 1.0f);
      private final static Color BLACK = new Color(0, 0, 0);
      private final static Color DARK_COLOR = new Color(.439f, .475f, .490f);
  
      private final static Border OK_BORDER = new LineBorder(TOOLS_COLOR, 5);
      private final static String hostFQDN = Configurator.fqdnName();
      private final static PendingFolderFilenameFilter PFILTER = new PendingFolderFilenameFilter();
      private final static LogFileFilter LOGFILE_COUNT_FILTER = new LogFileFilter();
      private final static DocIDFilenameFilter DOCID_FILTER = new DocIDFilenameFilter();
  
      private final static long ONE_MONTH = (31L * 24L * 60L * 60L * 1000L);  // milliseconds in a month
  
      private final static long BYTES_PER_MB = (1024 * 1024);
  
      private final static int OSTYPE_WINDOWS = 1;
      private final static int OSTYPE_MACOSX = 2;
      private final static int OSTYPE_LINUX = 3;
  
      private static MonitorThread monThread = new MonitorThread();
      private static String uplib_check_angel_prog = null;
      private static String konqueror_path = null;
      private static String nautilus_path = null;
      private static int os_type = 0;
  
      // JLabel repo_identifier;
      TitledBorder repo_identifier;
      File repo_location;
      String normal_path;
      String canonical_path;
      JPanel buttons_flipper;
      JLabel subproc_identifier;
      JButton start_button;
      JButton stop_button;
      JButton restart_button;
      JButton log_button;
      JButton pending_button;
      JButton clearpassword_button;
      JButton opendeleted_button;
      JButton purgelogs_button;
      JButton open_button;
      JCheckBox auto_restart;
      File angeloutdotlog;
      File metadata;
      long metadata_read;
      File pending_folder;
      File deleted_folder;
      File overhead_folder;
      File docs_folder;
      long docs_folder_read;
      int docs_count;
      int angel_port;
      int stunnel_port;
      String name;
      String fqdn;
      URL ping_URL;
      URL main_URL;
      String main_URL_string;
      WorkThread.SubProc subproc;
      Logger logger = null;
      private boolean has_password;
      private boolean removing_password;
      private boolean not_there;
      private int last_state;
      private Vector listeners = null;
      
      static {
          String osname = Configurator.osName();
  
          if (osname.equals("win32"))
              os_type = OSTYPE_WINDOWS;
          else if (osname.equals("Darwin"))
              os_type = OSTYPE_MACOSX;
          else if (osname.equals("Linux"))
              os_type = OSTYPE_LINUX;
  
          Logger l = Logger.getLogger("global");
          try {
              Configurator c = new Configurator();
              uplib_check_angel_prog = c.get("uplib-check-repository-program");
              nautilus_path = c.get("nautilus-browser-program");
              konqueror_path = c.get("konqueror-browser-program");
          } catch (Exception x) {
              LogStackTrace.severe(l, "Exception attempting to locate subsidiary programs", x);
              System.exit(1);
          }
      }
  
      private static class MonitorThread extends Thread {
  
          private Vector repos;
  
          public MonitorThread() {
              super("Repository Monitor Thread");
              repos = new Vector();
              this.setDaemon(true);
          }
      
          public void add(RepositoryMonitor rm) {
              repos.add(rm);
          }
  
          public void run () {
              while (true) {
                  for (int i = 0;  i < repos.size();  i++) {
                      RepositoryMonitor rm = (RepositoryMonitor) repos.get(i);
                      // rm.getLogger().info("checking " + rm.normal_path);
                      try {
                          rm.setState(rm.checkRepository());
                      } catch (IOException x) {
                          rm.getLogger().info("IOException attempting to validate repository " + rm.normal_path + ":  " + x);
                          x.printStackTrace(System.err);
                      }
                  }
                  try {
                      sleep(15 * 1000);
                  } catch (InterruptedException x) {
                      // ignore
                  }
              }
          }
      }
  
      private static class PendingFolderFilenameFilter implements java.io.FilenameFilter {
          public PendingFolderFilenameFilter () {
          }
          public boolean accept (File dir, String name) {
              return (!name.startsWith("."));
          }
      }
  
      private static class LogFileFilter implements java.io.FileFilter {
          public LogFileFilter () {
          }
          public boolean accept (File f) {
              return ((f.getName().startsWith("angel.log.ends") ||
                       f.getName().startsWith("stunnel.log-")) &&
                      (f.lastModified() < (System.currentTimeMillis() - ONE_MONTH)));
          }
      }
  
      public static class StateChanged extends ActionEvent {
          public final static String LABEL = "stateChanged";
          public int state;
          public StateChanged (RepositoryMonitor m, int newstate) {
              super(m, ActionEvent.ACTION_PERFORMED, LABEL);
              state = newstate;            
          }
      }
  
      public static class DocsCountChanged extends ActionEvent {
          public final static String LABEL = "docsCountChanged";
          public int count;
          public DocsCountChanged (RepositoryMonitor m, int newcount) {
              super(m, ActionEvent.ACTION_PERFORMED, LABEL);
              count = newcount;
          }
      }
  
      static String[] format_check_angel (String path, String action) {
          if (os_type == OSTYPE_WINDOWS) {
              String[] v = new String[(action == null) ? 2 : 3];
  