mirror of https://github.com/noisymime/Arduino.git
updated commons-codec
introduced password authorization dialog actual sketch posting
This commit is contained in:
parent
4cbd1cf9fe
commit
078a6f5630
Binary file not shown.
Binary file not shown.
|
@ -829,6 +829,13 @@ public class Preferences {
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean has(String key) {
|
||||||
|
return table.containsKey(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void remove(String key) {
|
||||||
|
table.remove(key);
|
||||||
|
}
|
||||||
|
|
||||||
static public String getDefault(String attribute) {
|
static public String getDefault(String attribute) {
|
||||||
return (String) defaults.get(attribute);
|
return (String) defaults.get(attribute);
|
||||||
|
|
|
@ -23,8 +23,10 @@
|
||||||
|
|
||||||
package processing.app;
|
package processing.app;
|
||||||
|
|
||||||
|
import org.apache.commons.codec.digest.DigestUtils;
|
||||||
import processing.app.debug.*;
|
import processing.app.debug.*;
|
||||||
import processing.app.debug.Compiler;
|
import processing.app.debug.Compiler;
|
||||||
|
import processing.app.forms.PasswordAuthorizationDialog;
|
||||||
import processing.app.helpers.PreferencesMap;
|
import processing.app.helpers.PreferencesMap;
|
||||||
import processing.app.packages.Library;
|
import processing.app.packages.Library;
|
||||||
import processing.app.packages.LibraryList;
|
import processing.app.packages.LibraryList;
|
||||||
|
@ -1598,9 +1600,9 @@ public class Sketch {
|
||||||
// }
|
// }
|
||||||
|
|
||||||
editor.status.progressNotice(_("Uploading..."));
|
editor.status.progressNotice(_("Uploading..."));
|
||||||
upload(appletPath, foundName, usingProgrammer);
|
boolean success = upload(appletPath, foundName, usingProgrammer);
|
||||||
editor.status.progressUpdate(100);
|
editor.status.progressUpdate(100);
|
||||||
return true;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1656,16 +1658,33 @@ public class Sketch {
|
||||||
System.out.println(_("Low memory available, stability problems may occur"));
|
System.out.println(_("Low memory available, stability problems may occur"));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String upload(String buildPath, String suggestedClassName, boolean usingProgrammer) throws RunnerException, SerialException {
|
protected boolean upload(String buildPath, String suggestedClassName, boolean usingProgrammer) throws RunnerException, SerialException {
|
||||||
|
|
||||||
TargetPlatform target = Base.getTargetPlatform();
|
TargetPlatform target = Base.getTargetPlatform();
|
||||||
String board = Preferences.get("board");
|
String board = Preferences.get("board");
|
||||||
|
|
||||||
Uploader uploader = new UploaderFactory().newUploader(target.getBoards().get(board), Preferences.get("serial.port"));
|
Uploader uploader = new UploaderFactory().newUploader(target.getBoards().get(board), Preferences.get("serial.port"));
|
||||||
|
|
||||||
|
if (uploader.requiresAuthorization() && !Preferences.has(uploader.getAuthorizationKey())) {
|
||||||
|
PasswordAuthorizationDialog dialog = new PasswordAuthorizationDialog(editor);
|
||||||
|
dialog.setLocationRelativeTo(editor);
|
||||||
|
dialog.setVisible(true);
|
||||||
|
|
||||||
|
if (dialog.isCancelled()) {
|
||||||
|
editor.statusNotice(_("Upload cancelled"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Preferences.set(uploader.getAuthorizationKey(), DigestUtils.sha512Hex(dialog.getPassword()));
|
||||||
|
}
|
||||||
|
|
||||||
boolean success = uploader.uploadUsingPreferences(buildPath, suggestedClassName, usingProgrammer);
|
boolean success = uploader.uploadUsingPreferences(buildPath, suggestedClassName, usingProgrammer);
|
||||||
|
|
||||||
return success ? suggestedClassName : null;
|
if (uploader.requiresAuthorization() && !success) {
|
||||||
|
Preferences.remove(uploader.getAuthorizationKey());
|
||||||
|
}
|
||||||
|
|
||||||
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import org.apache.commons.httpclient.methods.PostMethod;
|
||||||
import org.apache.commons.httpclient.methods.multipart.FilePart;
|
import org.apache.commons.httpclient.methods.multipart.FilePart;
|
||||||
import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
|
import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
|
||||||
import org.apache.commons.httpclient.methods.multipart.Part;
|
import org.apache.commons.httpclient.methods.multipart.Part;
|
||||||
|
import processing.app.Preferences;
|
||||||
import processing.app.SerialException;
|
import processing.app.SerialException;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -32,6 +33,14 @@ public class HttpUploader extends Uploader {
|
||||||
this.ipAddress = matcher.group(1);
|
this.ipAddress = matcher.group(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean requiresAuthorization() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAuthorizationKey() {
|
||||||
|
return "pwd." + ipAddress;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean uploadUsingPreferences(String buildPath, String className, boolean usingProgrammer) throws RunnerException, SerialException {
|
public boolean uploadUsingPreferences(String buildPath, String className, boolean usingProgrammer) throws RunnerException, SerialException {
|
||||||
if (usingProgrammer) {
|
if (usingProgrammer) {
|
||||||
|
@ -41,13 +50,14 @@ public class HttpUploader extends Uploader {
|
||||||
|
|
||||||
FilePart filePart;
|
FilePart filePart;
|
||||||
try {
|
try {
|
||||||
filePart = new FilePart("sketch.hex", new File(buildPath, className + ".hex"));
|
filePart = new FilePart("sketch", new File(buildPath, className + ".hex"));
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
throw new RunnerException(e);
|
throw new RunnerException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
Part[] parts = {filePart};
|
Part[] parts = {filePart};
|
||||||
PostMethod post = newPostMethod();
|
PostMethod post = newPostMethod();
|
||||||
|
post.setRequestHeader("Cookie", "pwd=" + Preferences.get(getAuthorizationKey()));
|
||||||
post.setRequestEntity(new MultipartRequestEntity(parts, post.getParams()));
|
post.setRequestEntity(new MultipartRequestEntity(parts, post.getParams()));
|
||||||
|
|
||||||
int statusCode;
|
int statusCode;
|
||||||
|
@ -58,7 +68,6 @@ public class HttpUploader extends Uploader {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (statusCode == HttpStatus.SC_OK) {
|
if (statusCode == HttpStatus.SC_OK) {
|
||||||
System.out.println(_("Sketch uploaded"));
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,7 +80,7 @@ public class HttpUploader extends Uploader {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected PostMethod newPostMethod() {
|
protected PostMethod newPostMethod() {
|
||||||
return new PostMethod("http://" + ipAddress + ":8000/upload");
|
return new PostMethod("http://" + ipAddress + ":6571/upload");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -56,6 +56,14 @@ public abstract class Uploader implements MessageConsumer {
|
||||||
|
|
||||||
public abstract boolean burnBootloader() throws RunnerException;
|
public abstract boolean burnBootloader() throws RunnerException;
|
||||||
|
|
||||||
|
public boolean requiresAuthorization() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAuthorizationKey() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
protected void flushSerialBuffer() throws RunnerException, SerialException {
|
protected void flushSerialBuffer() throws RunnerException, SerialException {
|
||||||
// Cleanup the serial buffer
|
// Cleanup the serial buffer
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -0,0 +1,127 @@
|
||||||
|
package processing.app.forms;
|
||||||
|
|
||||||
|
import processing.app.Base;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import static processing.app.I18n._;
|
||||||
|
|
||||||
|
public class PasswordAuthorizationDialog extends JDialog {
|
||||||
|
|
||||||
|
protected final JButton uploadButton;
|
||||||
|
protected final JButton cancelButton;
|
||||||
|
protected final JLabel typePasswordLabel;
|
||||||
|
protected final JLabel passwordLabel;
|
||||||
|
protected final JLabel icon;
|
||||||
|
protected final JPasswordField passwordField;
|
||||||
|
|
||||||
|
protected boolean cancelled;
|
||||||
|
protected String password;
|
||||||
|
|
||||||
|
public PasswordAuthorizationDialog(Frame parent) {
|
||||||
|
super(parent, true);
|
||||||
|
|
||||||
|
this.cancelled = false;
|
||||||
|
this.password = null;
|
||||||
|
|
||||||
|
typePasswordLabel = new JLabel();
|
||||||
|
icon = new JLabel();
|
||||||
|
passwordLabel = new JLabel();
|
||||||
|
passwordField = new JPasswordField();
|
||||||
|
uploadButton = new JButton();
|
||||||
|
cancelButton = new JButton();
|
||||||
|
|
||||||
|
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
|
||||||
|
|
||||||
|
typePasswordLabel.setText(_("Type board password to upload a new sketch"));
|
||||||
|
|
||||||
|
icon.setIcon(new ImageIcon(new File(Base.getContentFile("lib"), "theme/lock.png").getAbsolutePath()));
|
||||||
|
|
||||||
|
passwordLabel.setText(_("Password:"));
|
||||||
|
|
||||||
|
passwordField.setText("");
|
||||||
|
passwordField.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent evt) {
|
||||||
|
uploadButtonPressed(evt);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
uploadButton.setText(_("Upload"));
|
||||||
|
uploadButton.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent evt) {
|
||||||
|
uploadButtonPressed(evt);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
cancelButton.setText(_("Cancel"));
|
||||||
|
cancelButton.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent evt) {
|
||||||
|
cancelButtonPressed(evt);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
GroupLayout layout = new GroupLayout(getContentPane());
|
||||||
|
getContentPane().setLayout(layout);
|
||||||
|
layout.setHorizontalGroup(
|
||||||
|
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
|
||||||
|
.addGroup(layout.createSequentialGroup()
|
||||||
|
.addContainerGap()
|
||||||
|
.addComponent(icon, GroupLayout.PREFERRED_SIZE, 66, GroupLayout.PREFERRED_SIZE)
|
||||||
|
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
|
||||||
|
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
|
||||||
|
.addComponent(typePasswordLabel)
|
||||||
|
.addGroup(layout.createSequentialGroup()
|
||||||
|
.addComponent(passwordLabel)
|
||||||
|
.addGap(4, 4, 4)
|
||||||
|
.addComponent(passwordField, GroupLayout.PREFERRED_SIZE, 300, GroupLayout.PREFERRED_SIZE)))
|
||||||
|
.addContainerGap(20, Short.MAX_VALUE))
|
||||||
|
.addGroup(GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||||
|
.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||||
|
.addComponent(cancelButton)
|
||||||
|
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
|
||||||
|
.addComponent(uploadButton)
|
||||||
|
.addContainerGap())
|
||||||
|
);
|
||||||
|
layout.setVerticalGroup(
|
||||||
|
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
|
||||||
|
.addGroup(layout.createSequentialGroup()
|
||||||
|
.addContainerGap()
|
||||||
|
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
|
||||||
|
.addComponent(icon)
|
||||||
|
.addComponent(typePasswordLabel))
|
||||||
|
.addGap(5, 5, 5)
|
||||||
|
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
|
||||||
|
.addComponent(passwordLabel)
|
||||||
|
.addComponent(passwordField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
|
||||||
|
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
|
||||||
|
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
|
||||||
|
.addComponent(cancelButton)
|
||||||
|
.addComponent(uploadButton))
|
||||||
|
.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
||||||
|
);
|
||||||
|
|
||||||
|
pack();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void cancelButtonPressed(ActionEvent event) {
|
||||||
|
this.cancelled = true;
|
||||||
|
this.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void uploadButtonPressed(ActionEvent event) {
|
||||||
|
this.password = new String(passwordField.getPassword());
|
||||||
|
this.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPassword() {
|
||||||
|
return this.password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isCancelled() {
|
||||||
|
return cancelled;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue