PageRenderTime 210ms CodeModel.GetById 49ms app.highlight 120ms RepoModel.GetById 17ms app.codeStats 1ms

/src/mpv5/ui/dialogs/subcomponents/ControlPanel_WebShopManager.java

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 588 lines | 512 code | 64 blank | 12 comment | 22 complexity | 30a7ea2f02df2cb54912894ff599021f MD5 | raw file
  1package mpv5.ui.dialogs.subcomponents;
  2
  3import java.awt.Component;
  4import java.awt.event.ActionEvent;
  5import java.awt.event.ActionListener;
  6import java.io.File;
  7import java.io.IOException;
  8import java.net.MalformedURLException;
  9import java.net.URL;
 10import java.security.NoSuchAlgorithmException;
 11import java.util.ArrayList;
 12import java.util.logging.Level;
 13import java.util.logging.Logger;
 14import javax.swing.DefaultListModel;
 15import javax.swing.JMenuItem;
 16import javax.swing.JPopupMenu;
 17import javax.swing.SwingUtilities;
 18import mpv5.data.PropertyStore;
 19import mpv5.db.common.Context;
 20import mpv5.db.common.DatabaseObject;
 21import mpv5.db.common.NodataFoundException;
 22import mpv5.db.objects.WebShop;
 23import mpv5.globals.Messages;
 24import mpv5.logging.Log;
 25import mpv5.ui.dialogs.ControlApplet;
 26import mpv5.ui.dialogs.DialogForFile;
 27import mpv5.ui.dialogs.Notificator;
 28import mpv5.ui.dialogs.Popup;
 29import mpv5.usermanagement.MPSecurityManager;
 30import mpv5.utils.files.FileDirectoryHandler;
 31import mpv5.utils.files.FileReaderWriter;
 32import mpv5.utils.files.Zip;
 33import mpv5.utils.models.MPComboBoxModelItem;
 34import mpv5.utils.text.Base64Encoder;
 35import mpv5.utils.text.RandomStringUtils;
 36import mpv5.utils.text.RandomText;
 37import mpv5.webshopinterface.NoCompatibleHostFoundException;
 38import mpv5.webshopinterface.WSConnectionClient;
 39import mpv5.webshopinterface.WSDaemon;
 40import mpv5.webshopinterface.WSIManager;
 41import mpv5.webshopinterface.wsdjobs.*;
 42import org.bouncycastle.util.encoders.Base64;
 43
 44
 45/**
 46 *
 47 * 
 48 */
 49public class ControlPanel_WebShopManager extends javax.swing.JPanel implements ControlApplet {
 50
 51    private static final long serialVersionUID = 1L;
 52    /**
 53     * This unique name identifies this control applet
 54     */
 55    public final String UNAME = "webshops";
 56    private PropertyStore oldvalues;
 57    private static ControlPanel_WebShopManager ident;
 58    private JPopupMenu popup;
 59
 60    public ControlPanel_WebShopManager() {
 61        initComponents();
 62        addPopupMenu();
 63
 64        groupselect.setSearchEnabled(true);
 65        groupselect.setContext(Context.getGroup());
 66        refresh();
 67
 68        setVisible(true);
 69    }
 70
 71    private void addPopupMenu() {
 72        popup = new JPopupMenu();
 73        JMenuItem jmi1;
 74        popup.add(jmi1 = new JMenuItem(Messages.ACTION_DELETE.toString()));
 75        popup.add(new JPopupMenu.Separator());
 76        JMenuItem jmi2;
 77        popup.add(jmi2 = new JMenuItem(Messages.ACTION_TEST.toString()));
 78        popup.add(new JPopupMenu.Separator());
 79
 80        jmi1.addActionListener(new ActionListener() {
 81
 82            @Override
 83            public void actionPerformed(ActionEvent e) {
 84                if (MPSecurityManager.checkAdminAccess()) {
 85                    WebShop gin = (WebShop) list.getSelectedValue();
 86                    gin.delete();
 87                    WSIManager.instanceOf().reset();
 88                    WSIManager.instanceOf().start();
 89                    refresh();
 90                }
 91            }
 92        });
 93
 94        jmi2.addActionListener(new ActionListener() {
 95
 96            @Override
 97            public void actionPerformed(ActionEvent e) {
 98                WebShop gin = (WebShop) list.getSelectedValue();
 99                try {
100                    if (jCheckBox1.isSelected()) {
101                        mpv5.ui.dialogs.Popup.notice(new WSConnectionClient(new URL(gin.__getUrl()), isrequestCompression.isSelected(), jTextField1.getText(), new String(jPasswordField1.getPassword())).test());
102                    } else {
103                        mpv5.ui.dialogs.Popup.notice(new WSConnectionClient(new URL(gin.__getUrl()), isrequestCompression.isSelected(), null, null).test());
104                    }
105
106                } catch (Exception x) {
107                    Log.Debug(x);
108                    mpv5.ui.dialogs.Popup.error(x);
109                }
110            }
111        });
112    }
113
114    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
115    private void initComponents() {
116
117        jPanel5 = new javax.swing.JPanel();
118        jButton3 = new javax.swing.JButton();
119        urls = new mpv5.ui.beans.LabeledTextField();
120        jScrollPane2 = new javax.swing.JScrollPane();
121        descr = new javax.swing.JTextArea();
122        jLabel1 = new javax.swing.JLabel();
123        intervals = new mpv5.ui.beans.LabeledSpinner();
124        groupselect = new mpv5.ui.beans.LabeledCombobox();
125        isrequestCompression = new javax.swing.JCheckBox();
126        jCheckBox1 = new javax.swing.JCheckBox();
127        jTextField1 = new javax.swing.JTextField();
128        jPasswordField1 = new javax.swing.JPasswordField();
129        jLabel4 = new javax.swing.JLabel();
130        jLabel5 = new javax.swing.JLabel();
131        jPanel3 = new javax.swing.JPanel();
132        jLabel3 = new javax.swing.JLabel();
133        jScrollPane1 = new javax.swing.JScrollPane();
134        list = new javax.swing.JList();
135        jPanel2 = new javax.swing.JPanel();
136        jButton2 = new javax.swing.JButton();
137        jButton5 = new javax.swing.JButton();
138        jButton4 = new javax.swing.JButton();
139        jButton1 = new javax.swing.JButton();
140
141        setBackground(new java.awt.Color(255, 255, 255));
142        java.util.ResourceBundle bundle = mpv5.i18n.LanguageManager.getBundle(); // NOI18N
143        setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("ControlPanel_WebShopManager.border.title"))); // NOI18N
144        setName("Form"); // NOI18N
145        setPreferredSize(new java.awt.Dimension(300, 300));
146        setLayout(new java.awt.BorderLayout());
147
148        jPanel5.setBorder(javax.swing.BorderFactory.createEtchedBorder());
149        jPanel5.setMaximumSize(new java.awt.Dimension(32767, 250));
150        jPanel5.setName("jPanel5"); // NOI18N
151        jPanel5.setPreferredSize(new java.awt.Dimension(453, 250));
152
153        jButton3.setText(bundle.getString("ControlPanel_WebShopManager.jButton3.text")); // NOI18N
154        jButton3.setName("jButton3"); // NOI18N
155        jButton3.addActionListener(new java.awt.event.ActionListener() {
156            public void actionPerformed(java.awt.event.ActionEvent evt) {
157                jButton3ActionPerformed(evt);
158            }
159        });
160
161        urls.set_Label(bundle.getString("ControlPanel_WebShopManager.urls._Label")); // NOI18N
162        urls.setName("urls"); // NOI18N
163
164        jScrollPane2.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
165        jScrollPane2.setName("jScrollPane2"); // NOI18N
166
167        descr.setColumns(20);
168        descr.setLineWrap(true);
169        descr.setRows(5);
170        descr.setWrapStyleWord(true);
171        descr.setName("descr"); // NOI18N
172        jScrollPane2.setViewportView(descr);
173
174        jLabel1.setText(bundle.getString("ControlPanel_WebShopManager.jLabel1.text")); // NOI18N
175        jLabel1.setName("jLabel1"); // NOI18N
176
177        intervals.set_Label(bundle.getString("ControlPanel_WebShopManager.intervals._Label")); // NOI18N
178        intervals.setName("intervals"); // NOI18N
179
180        groupselect.set_Label(bundle.getString("ControlPanel_WebShopManager.groupselect._Label")); // NOI18N
181        groupselect.setName("groupselect"); // NOI18N
182
183        isrequestCompression.setText(bundle.getString("ControlPanel_WebShopManager.isrequestCompression.text")); // NOI18N
184        isrequestCompression.setName("isrequestCompression"); // NOI18N
185
186        jCheckBox1.setText(bundle.getString("ControlPanel_WebShopManager.jCheckBox1.text")); // NOI18N
187        jCheckBox1.setName("jCheckBox1"); // NOI18N
188        jCheckBox1.addItemListener(new java.awt.event.ItemListener() {
189            public void itemStateChanged(java.awt.event.ItemEvent evt) {
190                jCheckBox1ItemStateChanged(evt);
191            }
192        });
193
194        jTextField1.setText(bundle.getString("ControlPanel_WebShopManager.jTextField1.text")); // NOI18N
195        jTextField1.setEnabled(false);
196        jTextField1.setName("jTextField1"); // NOI18N
197
198        jPasswordField1.setText(bundle.getString("ControlPanel_WebShopManager.jPasswordField1.text")); // NOI18N
199        jPasswordField1.setEnabled(false);
200        jPasswordField1.setName("jPasswordField1"); // NOI18N
201
202        jLabel4.setText(bundle.getString("ControlPanel_WebShopManager.jLabel4.text")); // NOI18N
203        jLabel4.setEnabled(false);
204        jLabel4.setName("jLabel4"); // NOI18N
205
206        jLabel5.setText(bundle.getString("ControlPanel_WebShopManager.jLabel5.text")); // NOI18N
207        jLabel5.setEnabled(false);
208        jLabel5.setName("jLabel5"); // NOI18N
209
210        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
211        jPanel5.setLayout(jPanel5Layout);
212        jPanel5Layout.setHorizontalGroup(
213            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
214            .addGroup(jPanel5Layout.createSequentialGroup()
215                .addContainerGap()
216                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
217                    .addComponent(groupselect, javax.swing.GroupLayout.PREFERRED_SIZE, 343, javax.swing.GroupLayout.PREFERRED_SIZE)
218                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
219                        .addComponent(urls, javax.swing.GroupLayout.DEFAULT_SIZE, 413, Short.MAX_VALUE)
220                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
221                        .addComponent(jButton3))
222                    .addGroup(jPanel5Layout.createSequentialGroup()
223                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
224                            .addGroup(jPanel5Layout.createSequentialGroup()
225                                .addComponent(isrequestCompression)
226                                .addGap(18, 18, 18)
227                                .addComponent(intervals, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
228                            .addComponent(jCheckBox1))
229                        .addGap(110, 110, 110))
230                    .addGroup(jPanel5Layout.createSequentialGroup()
231                        .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
232                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
233                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
234                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
235                        .addComponent(jLabel5)
236                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
237                        .addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE))
238                    .addGroup(jPanel5Layout.createSequentialGroup()
239                        .addComponent(jLabel1)
240                        .addGap(18, 18, 18)
241                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 326, javax.swing.GroupLayout.PREFERRED_SIZE)))
242                .addContainerGap())
243        );
244        jPanel5Layout.setVerticalGroup(
245            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
246            .addGroup(jPanel5Layout.createSequentialGroup()
247                .addContainerGap()
248                .addComponent(groupselect, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
249                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
250                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
251                    .addComponent(jButton3, javax.swing.GroupLayout.Alignment.LEADING, 0, 0, Short.MAX_VALUE)
252                    .addComponent(urls, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
253                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
254                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
255                    .addGroup(jPanel5Layout.createSequentialGroup()
256                        .addComponent(isrequestCompression)
257                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
258                        .addComponent(jCheckBox1))
259                    .addComponent(intervals, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
260                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
261                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
262                    .addComponent(jLabel4)
263                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
264                    .addComponent(jLabel5)
265                    .addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
266                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
267                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
268                    .addGroup(jPanel5Layout.createSequentialGroup()
269                        .addComponent(jLabel1)
270                        .addGap(56, 56, 56))
271                    .addGroup(jPanel5Layout.createSequentialGroup()
272                        .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 59, Short.MAX_VALUE)
273                        .addContainerGap())))
274        );
275
276        add(jPanel5, java.awt.BorderLayout.NORTH);
277
278        jPanel3.setBorder(javax.swing.BorderFactory.createEtchedBorder());
279        jPanel3.setName("jPanel3"); // NOI18N
280        jPanel3.setPreferredSize(new java.awt.Dimension(605, 400));
281
282        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 12));
283        jLabel3.setText(bundle.getString("ControlPanel_WebShopManager.jLabel3.text")); // NOI18N
284        jLabel3.setName("jLabel3"); // NOI18N
285
286        jScrollPane1.setName("jScrollPane1"); // NOI18N
287
288        list.setToolTipText(bundle.getString("ControlPanel_WebShopManager.list.toolTipText")); // NOI18N
289        list.setName("list"); // NOI18N
290        list.addMouseListener(new java.awt.event.MouseAdapter() {
291            public void mouseClicked(java.awt.event.MouseEvent evt) {
292                listMouseClicked(evt);
293            }
294        });
295        jScrollPane1.setViewportView(list);
296
297        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
298        jPanel3.setLayout(jPanel3Layout);
299        jPanel3Layout.setHorizontalGroup(
300            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
301            .addGroup(jPanel3Layout.createSequentialGroup()
302                .addContainerGap()
303                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
304                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 456, Short.MAX_VALUE)
305                    .addComponent(jLabel3))
306                .addContainerGap())
307        );
308        jPanel3Layout.setVerticalGroup(
309            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
310            .addGroup(jPanel3Layout.createSequentialGroup()
311                .addContainerGap()
312                .addComponent(jLabel3)
313                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
314                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 56, Short.MAX_VALUE)
315                .addContainerGap())
316        );
317
318        add(jPanel3, java.awt.BorderLayout.CENTER);
319
320        jPanel2.setBackground(new java.awt.Color(255, 255, 255));
321        jPanel2.setName("jPanel2"); // NOI18N
322        jPanel2.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));
323
324        jButton2.setText(bundle.getString("ControlPanel_WebShopManager.jButton2.text")); // NOI18N
325        jButton2.setEnabled(false);
326        jButton2.setName("jButton2"); // NOI18N
327        jButton2.addActionListener(new java.awt.event.ActionListener() {
328            public void actionPerformed(java.awt.event.ActionEvent evt) {
329                jButton2ActionPerformed(evt);
330            }
331        });
332        jPanel2.add(jButton2);
333
334        jButton5.setText(bundle.getString("ControlPanel_WebShopManager.jButton5.text")); // NOI18N
335        jButton5.setName("jButton5"); // NOI18N
336        jButton5.addActionListener(new java.awt.event.ActionListener() {
337            public void actionPerformed(java.awt.event.ActionEvent evt) {
338                jButton5ActionPerformed(evt);
339            }
340        });
341        jPanel2.add(jButton5);
342
343        jButton4.setText(bundle.getString("ControlPanel_WebShopManager.jButton4.text")); // NOI18N
344        jButton4.setName("jButton4"); // NOI18N
345        jButton4.addActionListener(new java.awt.event.ActionListener() {
346            public void actionPerformed(java.awt.event.ActionEvent evt) {
347                jButton4ActionPerformed(evt);
348            }
349        });
350        jPanel2.add(jButton4);
351
352        jButton1.setText(bundle.getString("ControlPanel_WebShopManager.jButton1.text")); // NOI18N
353        jButton1.setName("jButton1"); // NOI18N
354        jButton1.addActionListener(new java.awt.event.ActionListener() {
355            public void actionPerformed(java.awt.event.ActionEvent evt) {
356                jButton1ActionPerformed(evt);
357            }
358        });
359        jPanel2.add(jButton1);
360
361        add(jPanel2, java.awt.BorderLayout.SOUTH);
362    }// </editor-fold>//GEN-END:initComponents
363
364    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
365        if (list.getSelectedValue() != null) {
366            try {
367                save((WebShop) list.getSelectedValue());
368                refresh();
369                WSIManager.instanceOf().reset();
370                WSIManager.instanceOf().start();
371            } catch (Exception x) {
372                Log.Debug(x);
373                mpv5.ui.dialogs.Popup.error(x);
374            }
375        }
376
377}//GEN-LAST:event_jButton1ActionPerformed
378
379    private void listMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_listMouseClicked
380
381        if (SwingUtilities.isRightMouseButton(evt) && !list.isSelectionEmpty() && list.locationToIndex(evt.getPoint()) == list.getSelectedIndex()) {
382            popup.show(list, evt.getX(), evt.getY());
383        } else if (evt.getClickCount() >= 1) {
384            if (list.getSelectedValue() != null) {
385                WebShop ws = (WebShop) list.getSelectedValue();
386                intervals.set_Value(Integer.valueOf(ws.__getInterv()));
387                descr.setText(ws.__getDescription());
388                urls.setText(ws.__getUrl());
389                groupselect.setSelectedIndex(MPComboBoxModelItem.getItemID(String.valueOf(ws.__getGroupsids()), groupselect.getModel()));
390                isrequestCompression.setSelected(ws.__getIsrequestCompression());
391                jCheckBox1.setSelected(ws.__getIsauthenticated());
392                jTextField1.setText(ws.__getUsername());
393                jPasswordField1.setText(ws.__getPassw());
394            }
395        }
396}//GEN-LAST:event_listMouseClicked
397
398    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
399        try {
400            if (jCheckBox1.isSelected()) {
401                mpv5.ui.dialogs.Popup.notice(new WSConnectionClient(new URL(urls.getText()), isrequestCompression.isSelected(), jTextField1.getText(), new String(jPasswordField1.getPassword())).test());
402            } else {
403                mpv5.ui.dialogs.Popup.notice(new WSConnectionClient(new URL(urls.getText()), isrequestCompression.isSelected(), null, null).test());
404            }
405        } catch (Exception x) {
406            Log.Debug(x);
407            mpv5.ui.dialogs.Popup.error(x);
408        }
409}//GEN-LAST:event_jButton3ActionPerformed
410
411    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
412
413        try {
414            WebShop ws = new WebShop();
415            save(ws);
416            WSIManager.instanceOf().reset();
417            WSIManager.instanceOf().start();
418        } catch (Exception x) {
419//            Log.Debug(x);
420            mpv5.ui.dialogs.Popup.error(x);
421        }
422}//GEN-LAST:event_jButton4ActionPerformed
423
424    private void jCheckBox1ItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jCheckBox1ItemStateChanged
425        jPasswordField1.setEnabled(jCheckBox1.isSelected());
426        jTextField1.setEnabled(jCheckBox1.isSelected());
427        jLabel5.setEnabled(jCheckBox1.isSelected());
428        jLabel4.setEnabled(jCheckBox1.isSelected());
429        jButton2.setEnabled(jCheckBox1.isSelected());
430    }//GEN-LAST:event_jCheckBox1ItemStateChanged
431
432    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
433        try {
434            generate();
435        } catch (Exception ex) {
436            Log.Debug(ex);
437        }
438    }//GEN-LAST:event_jButton2ActionPerformed
439
440    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
441        try {
442            WebShop ws = (WebShop) list.getSelectedValue();
443            WSDaemon d = new WSDaemon(ws);
444            d.addJob(new newContactsJob(d));
445            d.addJob(new newOrdersJob(d));
446            d.addJob(new newSystemMessages(d));
447            d.addJob(new updatedContactsJob(d));
448            d.addJob(new updatedOrdersJob(d));
449            d.addJob(new addContactJob(d));
450            d.start();
451        } catch (Exception ex) {
452            Notificator.raiseNotification(ex, true);
453        }
454    }//GEN-LAST:event_jButton5ActionPerformed
455
456    @Override
457    public void setValues(PropertyStore values) {
458        oldvalues = values;
459    }
460
461    @Override
462    public String getUname() {
463        return UNAME;
464    }
465
466    @Override
467    public void reset() {
468        setValues(oldvalues);
469    }
470    // Variables declaration - do not modify//GEN-BEGIN:variables
471    private javax.swing.JTextArea descr;
472    private mpv5.ui.beans.LabeledCombobox groupselect;
473    private mpv5.ui.beans.LabeledSpinner intervals;
474    private javax.swing.JCheckBox isrequestCompression;
475    private javax.swing.JButton jButton1;
476    private javax.swing.JButton jButton2;
477    private javax.swing.JButton jButton3;
478    private javax.swing.JButton jButton4;
479    private javax.swing.JButton jButton5;
480    private javax.swing.JCheckBox jCheckBox1;
481    private javax.swing.JLabel jLabel1;
482    private javax.swing.JLabel jLabel3;
483    private javax.swing.JLabel jLabel4;
484    private javax.swing.JLabel jLabel5;
485    private javax.swing.JPanel jPanel2;
486    private javax.swing.JPanel jPanel3;
487    private javax.swing.JPanel jPanel5;
488    private javax.swing.JPasswordField jPasswordField1;
489    private javax.swing.JScrollPane jScrollPane1;
490    private javax.swing.JScrollPane jScrollPane2;
491    private javax.swing.JTextField jTextField1;
492    private javax.swing.JList list;
493    private mpv5.ui.beans.LabeledTextField urls;
494    // End of variables declaration//GEN-END:variables
495
496    private void refresh() {
497        groupselect.triggerSearch();
498        intervals.setValue(300);
499        list.setModel(new DefaultListModel());
500        list.validate();
501        try {
502            ArrayList<DatabaseObject> data = DatabaseObject.getObjects(Context.getWebShop());
503            DefaultListModel xl = new DefaultListModel();
504            Log.Debug(this, "Shops found: " + data.size());
505            for (int i = 0; i < data.size(); i++) {
506                DatabaseObject databaseObject = data.get(i);
507                xl.addElement((WebShop) databaseObject);
508            }
509            list.setModel(xl);
510        } catch (NodataFoundException nodataFoundException) {
511            Log.Debug(this, nodataFoundException.getMessage());
512        }
513    }
514
515    @Override
516    public Component getAndRemoveActionPanel() {
517        this.remove(jPanel2);
518        validate();
519        return jPanel2;
520    }
521
522    private void save(WebShop ws) throws MalformedURLException {
523        new URL(urls.getText());//test 
524        ws.setUrl(urls.getText());
525        ws.setDescription(descr.getText());
526        ws.setInterv(Integer.valueOf(intervals.getSpinner().getValue().toString()));
527        ws.setIsrequestCompression(isrequestCompression.isSelected());
528        ws.setIsauthenticated(jCheckBox1.isSelected());
529        ws.setUsername(jTextField1.getText());
530        ws.setPassw(new String(jPasswordField1.getPassword()));
531        if (groupselect.getSelectedItem() != null) {
532            ws.setGroupsids(Integer.valueOf((groupselect.getSelectedItem()).getId()));
533        } else {
534            ws.setGroupsids(1);
535        }
536        ws.save();
537        refresh();
538    }
539
540    @SuppressWarnings("Deprecated")
541    private void generate() throws NoSuchAlgorithmException, IOException {
542        try {
543            String pwdir = new RandomText(8).getString();
544            String user = new RandomText(8).getString();
545            String password = new RandomText(8).getString();
546            Log.Debug(this, "The SUPER SECRET password for the generated .htaccess file is: " + password);
547            //apache codec base64encoder produces wrong values here
548            String crypt = "{SHA}" + Base64.encode(java.security.MessageDigest.getInstance("SHA1").digest(password.getBytes()));
549            String content1 =
550                    "AuthUserFile " + pwdir + "/.htpasswd\n" +
551                    "AuthGroupFile /dev/null\n" +
552                    "AuthName \"" + user + "\"\n" +
553                    "AuthType Basic\n" +
554                    "<Limit GET POST>\n" +
555                    "require valid-user\n" +
556                    "</Limit>\n" +
557                    "<Files *.ini>\n" +
558                    "Order Deny,Allow\n" +
559                    "Deny from all\n" +
560                    "</Files>\n";
561
562            String content2 = user + ":" + crypt;
563            String tmp = FileDirectoryHandler.getTempDir() + RandomText.getText();
564            File f1 = new File(tmp + File.separator + ".htaccess");
565            f1.getParentFile().mkdirs();
566            f1.createNewFile();
567            File f2 = new File(tmp + File.separator + pwdir + File.separator + ".htpasswd");
568            f2.getParentFile().mkdirs();
569            f2.createNewFile();
570            FileReaderWriter htacc = new FileReaderWriter(f1);
571            FileReaderWriter htpw = new FileReaderWriter(f2);
572
573            if (htacc.write0(content1) && htpw.write0(content2)) {
574                DialogForFile d = new DialogForFile(DialogForFile.FILES_ONLY);
575                d.setSelectedFile(new File("generated.zip"));
576                if (d.saveFile()) {
577                    Zip.zip(tmp, d.getFile().getPath());
578                }
579
580                jTextField1.setText(user);
581                jPasswordField1.setText(password);
582            }
583        } catch (Exception e) {
584            Popup.error(e);
585            Log.Debug(e);
586        }
587    }
588}