コード例 #1
0
ファイル: krypton_api.java プロジェクト: 0ldMaid/Krypton
  public void restartApplication() {

    try {

      final String javaBin =
          System.getProperty("java.home") + File.separator + "bin" + File.separator + "javaw";
      final File currentJar =
          new File(network.class.getProtectionDomain().getCodeSource().getLocation().toURI());

      System.out.println("javaBin " + javaBin);
      System.out.println("currentJar " + currentJar);
      System.out.println("currentJar.getPath() " + currentJar.getPath());

      /* is it a jar file? */
      // if(!currentJar.getName().endsWith(".jar")){return;}

      try {

        // xmining = 0;
        // systemx.shutdown();

      } catch (Exception e) {
        e.printStackTrace();
      }

      /* Build command: java -jar application.jar */
      final ArrayList<String> command = new ArrayList<String>();
      command.add(javaBin);
      command.add("-jar");
      command.add("-Xms256m");
      command.add("-Xmx1024m");
      command.add(currentJar.getPath());

      final ProcessBuilder builder = new ProcessBuilder(command);
      builder.start();

      // try{Thread.sleep(10000);} catch (InterruptedException e){}

      // close and exit
      SystemTray.getSystemTray().remove(network.icon);
      System.exit(0);

    } // try
    catch (Exception e) {
      JOptionPane.showMessageDialog(null, e.getCause());
    }
  } // ******************************
コード例 #2
0
ファイル: IHM.java プロジェクト: nd4pa/tp
  /*Classe de traitement des évenement
   *@param e objet Evénement
   *@see ActionListener
   *@author Arnaud Prémel-Cabic
   *@author Antoine Blondeau
   */
  public void actionPerformed(ActionEvent e) {
    int tmp = 0;
    if (e.getSource() == bPierre) {
      tmp = ppc.duel(1);
      if (ppc.getIAChoix() == 2) {
        imageAction2.setIcon(pierre);
      }
      if (ppc.getIAChoix() == 1) {
        imageAction2.setIcon(papier);
      }
      if (ppc.getIAChoix() == 3) {
        imageAction2.setIcon(ciseaux);
      }
      imageAction1.setIcon(papier);
    }
    if (e.getSource() == bPapier) {
      tmp = ppc.duel(2);
      if (ppc.getIAChoix() == 2) {
        imageAction2.setIcon(pierre);
      }
      if (ppc.getIAChoix() == 1) {
        imageAction2.setIcon(papier);
      }
      if (ppc.getIAChoix() == 3) {
        imageAction2.setIcon(ciseaux);
      }
      imageAction1.setIcon(pierre);
    }
    if (e.getSource() == bCiseaux) {
      tmp = ppc.duel(3);
      if (ppc.getIAChoix() == 2) {
        imageAction2.setIcon(pierre);
      }
      if (ppc.getIAChoix() == 1) {
        imageAction2.setIcon(papier);
      }
      if (ppc.getIAChoix() == 3) {
        imageAction2.setIcon(ciseaux);
      }
      imageAction1.setIcon(ciseaux);
    }

    if (e.getSource() == exit) {
      System.exit(1);
    }
    if (tmp < 0) {
      iascore = iascore + 1;
      score2.setText("" + iascore);
      ensemble.setBackground(Color.RED);
      noms.setBackground(Color.RED);
      scores.setBackground(Color.RED);
      action.setBackground(Color.RED);
      selection.setBackground(Color.RED);
      menu.setBackground(Color.RED);
    }
    if (tmp > 0) {
      pscore = pscore + 1;
      score1.setText("" + pscore);
      ensemble.setBackground(Color.GREEN);
      noms.setBackground(Color.GREEN);
      scores.setBackground(Color.GREEN);
      action.setBackground(Color.GREEN);
      selection.setBackground(Color.GREEN);
      menu.setBackground(Color.GREEN);
    }
    if (tmp == 0) {
      ensemble.setBackground(Color.WHITE);
      noms.setBackground(Color.WHITE);
      scores.setBackground(Color.WHITE);
      action.setBackground(Color.WHITE);
      selection.setBackground(Color.WHITE);
      menu.setBackground(Color.WHITE);
    }
    if (e.getSource() == reset) {
      score1.setText("");
      score2.setText("");
      imageAction1.setIcon(vierge);
      imageAction2.setIcon(vierge);

      ensemble.setBackground(null);
      noms.setBackground(null);
      scores.setBackground(null);
      action.setBackground(null);
      selection.setBackground(null);
      menu.setBackground(null);
    }
  }
コード例 #3
0
ファイル: krypton_api.java プロジェクト: 0ldMaid/Krypton
    public void
        run() { // ************************************************************************************

      String jsonText2 = new String("");

      JSONObject obj_out = new JSONObject();

      ServerSocket welcomeSocket;

      while (true) {

        try { // *********************************************************

          welcomeSocket = new ServerSocket(network.api_port, 0, InetAddress.getByName("localhost"));
          Socket connectionSocket = welcomeSocket.accept();
          BufferedReader inFromClient =
              new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
          DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream());
          clientSentence = inFromClient.readLine();

          JSONParser parser = new JSONParser();

          try { // *********************************************************

            statex = "0";
            responsex = "e00";
            jsonText = "";

            if (!clientSentence.contains("")) {
              throw new EmptyStackException();
            }
            Object obj = parser.parse(clientSentence);

            jsonObject = (JSONObject) obj;

            String request = (String) jsonObject.get("request");

            String item_id = new String("");
            String item_array = new String("");
            String old_key = new String("");
            String node = new String("");
            try {
              item_id = (String) jsonObject.get("item_id").toString();
            } catch (Exception e) {
              System.out.println("extra info no item_id...");
            }
            try {
              item_array = (String) jsonObject.get("item_array").toString();
            } catch (Exception e) {
              System.out.println("extra info no item_array...");
            }
            try {
              old_key = (String) jsonObject.get("key").toString();
            } catch (Exception e) {
              System.out.println("extra info no key...");
            }
            try {
              node = (String) jsonObject.get("node").toString();
            } catch (Exception e) {
              System.out.println("extra info no node...");
            }

            while (network.database_in_use == 1 && !request.equals("status")) {

              System.out.println("Database in use...");
              try {
                Thread.sleep(1000);
              } catch (InterruptedException e) {
              }
            } // **************************************************************

            if (request.equals("status")) {
              statex = "1";
              responsex = get_status();
            } // ***************************
            else if (request.equals("get_version")) {
              statex = "1";
              responsex = network.versionx;
            } //
            else if (request.equals("get_tor_active")) {
              statex = "1";
              responsex = Integer.toString(network.tor_active);
            } //
            else if (request.equals("get_last_block")) {
              statex = "1";
              responsex = network.last_block_id;
            } //
            else if (request.equals("get_last_block_timestamp")) {
              statex = "1";
              responsex = network.last_block_timestamp;
            } //
            else if (request.equals("get_last_block_hash")) {
              statex = "1";
              responsex = network.last_block_idx;
            } //
            else if (request.equals("get_difficulty")) {
              statex = "1";
              responsex = Long.toString(network.difficultyx);
            } //
            else if (request.equals("get_last_mining_id")) {
              statex = "1";
              responsex = network.last_block_mining_idx;
            } //
            else if (request.equals("get_prev_mining_id")) {
              statex = "1";
              responsex = network.prev_block_mining_idx;
            } //
            else if (request.equals("get_last_unconfirmed_id")) {
              statex = "1";
              responsex = get_item_ids();
            } //
            else if (request.equals("get_my_token_total")) {
              statex = "1";
              responsex = Integer.toString(network.database_listings_owner);
            } //
            else if (request.equals("get_my_id_list")) {
              statex = "1";
              responsex = get_item_ids();
            } //
            else if (request.equals("get_my_ids_limit")) {
              statex = "1";
              responsex = get_item_ids();
            } //
            else if (request.equals("get_token")) {
              statex = "1";
              responsex = get_item_array(item_id);
            } //
            else if (request.equals("get_settings")) {
              statex = "1";
              responsex = get_settings_array();
            } //
            else if (request.equals("get_mining_info")) {
              statex = "1";
              responsex = get_item_array(item_id);
            } //
            else if (request.equals("get_new_keys")) {
              statex = "1";
              responsex = build_keysx();
            } //
            else if (request.equals("delete_node")) {
              statex = "1";
              responsex = delete_node(node);
            } //
            else if (request.equals("delete_all_nodes")) {
              statex = "1";
              responsex = delete_all_nodes();
            } //
            else if (request.equals("set_new_node")) {
              statex = "1";
              responsex = set_new_node(node);
            } //
            else if (request.equals("set_old_key")) {
              statex = "1";
              responsex = set_old_key(old_key);
            } //
            else if (request.equals("set_new_block")) {
              statex = "1";
              responsex = set_new_block(item_array);
            } //
            else if (request.equals("set_edit_block")) {
              statex = "1";
              update_state = "set_edit_block";
              responsex = update_token(item_array);
            } //
            else if (request.equals("set_transfer_block")) {
              statex = "1";
              update_state = "set_transfer_block";
              responsex = update_token(item_array);
            } //
            else if (request.equals("system_restart")) {
              statex = "1";
              responsex = "restarting";
              toolkit = Toolkit.getDefaultToolkit();
              xtimerx = new Timer();
              xtimerx.schedule(new RemindTask_restart(), 0);
            } //
            else if (request.equals("system_exit")) {
              statex = "1";
              System.exit(0);
            } //
            else {
              statex = "0";
              responsex = "e01 UnknownRequestException";
            }

          } // try
          catch (ParseException e) {
            e.printStackTrace();
            statex = "0";
            responsex = "e02 ParseException";
          } catch (Exception e) {
            e.printStackTrace();
            statex = "0";
            responsex = "e03 Exception";
          }

          JSONObject obj = new JSONObject();
          obj.put("response", statex);
          try {
            obj.put("message", responsex);
          } catch (Exception e) {
            e.printStackTrace();
          }

          StringWriter outs = new StringWriter();
          obj.writeJSONString(outs);
          jsonText = outs.toString();
          System.out.println("SEND RESPONSE " + responsex);

          outToClient.writeBytes(jsonText + '\n');
          welcomeSocket.close();

        } catch (Exception e) {
          e.printStackTrace();
          System.out.println("Server ERROR x3");
        }
      } // **********while
    } // runx***************************************************************************************************
コード例 #4
0
ファイル: krypton_api.java プロジェクト: 0ldMaid/Krypton
  public String update_token(String req_array) {

    System.out.println("Update");

    String jsonarry = new String("");

    try {

      JSONParser parser = new JSONParser();
      Object obj = parser.parse(req_array);
      JSONObject jsonObject = (JSONObject) obj;

      String id = (String) jsonObject.get("id");
      String hash_id = (String) jsonObject.get("hash_id");
      String sig_id = (String) jsonObject.get("sig_id");
      String date_id = (String) jsonObject.get("date_id");
      String owner_id = (String) jsonObject.get("owner_id");
      String owner_rating = (String) jsonObject.get("owner_rating");
      String currency = (String) jsonObject.get("currency");
      String custom_template = (String) jsonObject.get("custom_template");
      String custom_1 = (String) jsonObject.get("custom_1");
      String custom_2 = (String) jsonObject.get("custom_2");
      String custom_3 = (String) jsonObject.get("custom_3");
      String item_errors = (String) jsonObject.get("item_errors");
      String item_date_listed = (String) jsonObject.get("item_date_listed");
      String item_date_listed_day = (String) jsonObject.get("item_date_listed_da");
      String item_date_listed_int = (String) jsonObject.get("item_date_listed_int");
      String item_hits = (String) jsonObject.get("item_hits");
      String item_confirm_code = (String) jsonObject.get("item_confirm_code");
      String item_confirmed = (String) jsonObject.get("item_confirmed");
      String item_cost = (String) jsonObject.get("item_cost");
      String item_description = (String) jsonObject.get("item_description");
      String item_id = (String) jsonObject.get("item_id");
      String item_price = (String) jsonObject.get("item_price");
      String item_weight = (String) jsonObject.get("item_weight");
      String item_listing_id = (String) jsonObject.get("item_listing_id");
      String item_notes = (String) jsonObject.get("item_notes");
      String item_package_d = (String) jsonObject.get("item_package_d");
      String item_package_l = (String) jsonObject.get("item_package_l");
      String item_package_w = (String) jsonObject.get("item_package_w");
      String item_part_number = (String) jsonObject.get("item_part_number");
      String item_title = (String) jsonObject.get("item_title");
      String item_title_url = (String) jsonObject.get("item_title");
      String item_type = (String) jsonObject.get("item_type");
      String item_search_1 = (String) jsonObject.get("item_search_1");
      String item_search_2 = (String) jsonObject.get("item_search_2");
      String item_search_3 = (String) jsonObject.get("item_search_3");
      String item_site_id = (String) jsonObject.get("item_site_id");
      String item_site_url = (String) jsonObject.get("item_site_url");
      String item_picture_1 = (String) jsonObject.get("item_picture_1");
      String item_total_on_hand = (String) jsonObject.get("item_total_on_hand");
      String sale_payment_address = (String) jsonObject.get("sale_payment_address");
      String sale_payment_type = (String) jsonObject.get("sale_payment_type");
      String sale_fees = (String) jsonObject.get("sale_fees");
      String sale_id = (String) jsonObject.get("sale_id");
      String sale_seller_id = (String) jsonObject.get("sale_seller_id");
      String sale_status = (String) jsonObject.get("sale_status");
      String sale_tax = (String) jsonObject.get("sale_tax");
      String sale_shipping_company = (String) jsonObject.get("sale_shipping_company");
      String sale_shipping_in = (String) jsonObject.get("sale_shipping_in");
      String sale_shipping_out = (String) jsonObject.get("sale_shipping_out");
      String sale_source_of_sale = (String) jsonObject.get("sale_source_of_sale");
      String sale_total_sale_amount = (String) jsonObject.get("sale_total_sale_amount");
      String sale_tracking_number = (String) jsonObject.get("sale_tracking_number");
      String sale_transaction_id = (String) jsonObject.get("sale_transaction_id");
      String sale_transaction_info = (String) jsonObject.get("sale_transaction_info");
      String seller_address_1 = (String) jsonObject.get("seller_address_1");
      String seller_address_2 = (String) jsonObject.get("seller_address_2");
      String seller_address_city = (String) jsonObject.get("seller_address_city");
      String seller_address_state = (String) jsonObject.get("seller_address_state");
      String seller_address_zip = (String) jsonObject.get("seller_address_zip");
      String seller_address_country = (String) jsonObject.get("seller_address_country");
      String seller_id = (String) jsonObject.get("seller_id");
      String seller_ip = (String) jsonObject.get("seller_ip");
      String seller_email = (String) jsonObject.get("seller_email");
      String seller_first_name = (String) jsonObject.get("seller_first_name");
      String seller_last_name = (String) jsonObject.get("seller_last_name");
      String seller_notes = (String) jsonObject.get("seller_notes");
      String seller_phone = (String) jsonObject.get("seller_phone");
      String seller_logo = (String) jsonObject.get("seller_logo");
      String seller_url = (String) jsonObject.get("seller_url");

      try {
        if (currency.length() < 1) {}
      } catch (Exception e) {
        currency = new String("1");
      }
      try {
        if (custom_template.length() < 1) {}
      } catch (Exception e) {
        custom_template = new String("2");
      }
      try {
        if (custom_1.length() < 1) {}
      } catch (Exception e) {
        custom_1 = new String("3");
      }
      try {
        if (custom_2.length() < 1) {}
      } catch (Exception e) {
        custom_2 = new String("4");
      }
      try {
        if (custom_3.length() < 1) {}
      } catch (Exception e) {
        custom_3 = new String("5");
      }
      try {
        if (item_errors.length() < 1) {}
      } catch (Exception e) {
        item_errors = new String("6");
      }
      try {
        if (item_date_listed.length() < 1) {}
      } catch (Exception e) {
        item_date_listed = new String("7");
      }
      try {
        if (item_date_listed_day.length() < 1) {}
      } catch (Exception e) {
        item_date_listed_day = new String("8");
      }
      try {
        if (item_date_listed_int.length() < 1) {}
      } catch (Exception e) {
        item_date_listed_int = new String("9");
      }
      try {
        if (item_hits.length() < 1) {}
      } catch (Exception e) {
        item_hits = new String("10");
      }
      try {
        if (item_confirm_code.length() < 1) {}
      } catch (Exception e) {
        item_confirm_code = new String("11");
      }
      try {
        if (item_confirmed.length() < 1) {}
      } catch (Exception e) {
        item_confirmed = new String("12");
      }
      try {
        if (item_cost.length() < 1) {}
      } catch (Exception e) {
        item_cost = new String("13");
      }
      try {
        if (item_description.length() < 1) {}
      } catch (Exception e) {
        item_description = new String("14");
      }
      try {
        if (item_id.length() < 1) {}
      } catch (Exception e) {
        item_id = new String("15");
      }
      try {
        if (item_price.length() < 1) {}
      } catch (Exception e) {
        item_price = new String("16");
      }
      try {
        if (item_weight.length() < 1) {}
      } catch (Exception e) {
        item_weight = new String("17");
      }
      try {
        if (item_notes.length() < 1) {}
      } catch (Exception e) {
        item_notes = new String("18");
      }
      try {
        if (item_package_d.length() < 1) {}
      } catch (Exception e) {
        item_package_d = new String("19");
      }
      try {
        if (item_package_l.length() < 1) {}
      } catch (Exception e) {
        item_package_l = new String("20");
      }
      try {
        if (item_package_w.length() < 1) {}
      } catch (Exception e) {
        item_package_w = new String("21");
      }
      try {
        if (item_part_number.length() < 1) {}
      } catch (Exception e) {
        item_part_number = new String("22");
      }
      try {
        if (item_title.length() < 1) {}
      } catch (Exception e) {
        item_title = new String("23");
      }
      try {
        if (item_title_url.length() < 1) {}
      } catch (Exception e) {
        item_title_url = new String("24");
      }
      try {
        if (item_type.length() < 1) {}
      } catch (Exception e) {
        item_type = new String("25");
      }
      try {
        if (item_search_1.length() < 1) {}
      } catch (Exception e) {
        item_search_1 = new String("26");
      }
      try {
        if (item_search_2.length() < 1) {}
      } catch (Exception e) {
        item_search_2 = new String("27");
      }
      try {
        if (item_search_3.length() < 1) {}
      } catch (Exception e) {
        item_search_3 = new String("28");
      }
      try {
        if (item_site_url.length() < 1) {}
      } catch (Exception e) {
        item_site_url = new String("29");
      }
      try {
        if (item_picture_1.length() < 1) {}
      } catch (Exception e) {
        item_picture_1 = new String("30");
      }
      try {
        if (item_total_on_hand.length() < 1) {}
      } catch (Exception e) {
        item_total_on_hand = new String("31");
      }

      String tokenx[] = new String[network.listing_size];

      if (Integer.parseInt(id) >= network.base_int
          && Integer.parseInt(id) <= (network.hard_token_limit + network.base_int)) {

        krypton_database_get_token2 getxt = new krypton_database_get_token2();
        tokenx = getxt.get_token(id);

        // update the noose
        tokenx[3] = Long.toString(System.currentTimeMillis());

        tokenx[4] = network.settingsx[5];

        tokenx[6] = currency;
        tokenx[7] = custom_template;
        tokenx[8] = custom_1;
        tokenx[9] = custom_2;
        tokenx[10] = custom_3;
        tokenx[11] = item_errors;
        tokenx[12] = item_date_listed;
        tokenx[13] = item_date_listed_day;
        tokenx[14] = item_date_listed_int;
        tokenx[15] = item_hits;
        tokenx[16] = item_confirm_code;
        tokenx[17] = item_confirmed;
        tokenx[18] = item_cost;
        tokenx[19] = item_description;
        tokenx[20] = item_id;
        tokenx[21] = item_price;
        tokenx[22] = item_weight;

        tokenx[24] = item_notes;
        tokenx[25] = item_package_d;
        tokenx[26] = item_package_l;
        tokenx[27] = item_package_w;
        tokenx[28] = item_part_number;
        tokenx[29] = item_title;
        tokenx[30] = item_title_url;
        tokenx[31] = item_type;
        tokenx[32] = item_search_1;
        tokenx[33] = item_search_2;
        tokenx[34] = item_search_3;

        tokenx[36] = item_site_url;
        tokenx[37] = item_picture_1;
        tokenx[38] = item_total_on_hand;

        // to help with search
        tokenx[30] = tokenx[29].toLowerCase();

        // base 58
        if (update_state.equals("set_edit_block")) {
          tokenx[60] = network.base58_id;
        } else if (update_state.equals("set_transfer_block")) {
          tokenx[60] = seller_id;
        }

        // seller info
        tokenx[63] = network.settingsx[11]; // name
        tokenx[64] = network.settingsx[12]; // last
        tokenx[54] = network.settingsx[13]; // address
        tokenx[55] = network.settingsx[14]; // address2
        tokenx[56] = network.settingsx[15]; // city
        tokenx[57] = network.settingsx[16]; // state
        tokenx[58] = network.settingsx[17]; // zip
        tokenx[59] = network.settingsx[18]; // country

        tokenx[39] = network.settingsx[19]; // btc
        tokenx[62] = network.settingsx[20]; // email
        tokenx[66] = network.settingsx[21]; // phone
        tokenx[68] = network.settingsx[22]; // website

        // sign

        try {

          String build_hash = new String("");

          build_hash = tokenx[0];
          for (int loop = 3; loop < tokenx.length; loop++) {

            build_hash = build_hash + tokenx[loop]; // save everything else
          } // *************************************************

          String hashx = new String(build_hash);
          byte[] sha256_1x = MessageDigest.getInstance("SHA-256").digest(hashx.getBytes());
          System.out.println(Base64.toBase64String(sha256_1x));

          tokenx[1] = Base64.toBase64String(sha256_1x);

          byte[] message = Base64.toBase64String(sha256_1x).getBytes("UTF8");

          byte[] clear = Base64.decode(network.settingsx[4]);
          PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(clear);
          KeyFactory fact = KeyFactory.getInstance("RSA");
          PrivateKey priv = fact.generatePrivate(keySpec);
          Arrays.fill(clear, (byte) 0);

          Signature sigx = Signature.getInstance("SHA1WithRSA"); // MD5WithRSA
          sigx.initSign(priv);
          sigx.update(message);
          byte[] signatureBytesx = sigx.sign();
          // System.out.println("Public: " + Base64.toBase64String(pub.getEncoded()));
          System.out.println("Singature: " + Base64.toBase64String(signatureBytesx));

          String signxx = Base64.toBase64String(signatureBytesx);

          tokenx[2] = signxx;

          byte[] keyxb3 = Base64.decode(tokenx[4]);

          X509EncodedKeySpec keySpecx3 = new X509EncodedKeySpec(keyxb3);
          KeyFactory factx3 = KeyFactory.getInstance("RSA");
          PublicKey pubx3 = factx3.generatePublic(keySpecx3);
          Arrays.fill(keyxb3, (byte) 0);

          Signature sigpk3 = Signature.getInstance("SHA1WithRSA"); // MD5WithRSA
          byte[] messagex3 = Base64.toBase64String(sha256_1x).getBytes("UTF8");

          byte[] signatureBytesx3 = Base64.decode(signxx);

          sigpk3.initVerify(pubx3);
          sigpk3.update(messagex3);

          boolean testsx = sigpk3.verify(signatureBytesx3);

          System.out.println("testsx " + testsx);

          if (testsx) {

            statex = "1";
            jsonarry = "Updated";

          } // ********
          else {

            statex = "0";
            jsonarry = "Update error. Information did not pass signature test.";
          } // **

          if (update_state.equals("set_edit_block")) {
            network.icon.displayMessage(
                "Krypton", "Token updated ID (" + tokenx[0] + ")", TrayIcon.MessageType.INFO);
          } else if (update_state.equals("set_transfer_block")) {
            network.icon.displayMessage(
                "Krypton", "Token transfer ID (" + tokenx[0] + ")", TrayIcon.MessageType.INFO);
          }

          // send the update
          tokenx_buffer = tokenx;
          toolkit = Toolkit.getDefaultToolkit();
          xtimerx = new Timer();
          xtimerx.schedule(new RemindTask_send_update(), 0);
          // send the update

        } catch (Exception e) {
          e.printStackTrace();
        }

      } // if
      else {
        System.out.println("Update item error cannot find item.");
        statex = "0";
        jsonarry = "Update item error cannot find item.";
      }

    } catch (Exception e) {
      e.printStackTrace();
      statex = "0";
      jsonarry = "Error";
    } // *****************

    return jsonarry;
  } // *****************