5 import java.util.ArrayList;
6 import javax.swing.table.DefaultTableModel;
19 private static boolean macro =
true;
27 private static String
dbp2p =
"";
29 public static Thread
t1;
30 public static Thread
t2;
44 @SuppressWarnings({
"static-access",
"static-access"})
64 again = javax.swing.JOptionPane.showConfirmDialog(null,
"Error in DBMS connection. Try again?",
"DBMS error", javax.swing.JOptionPane.YES_NO_OPTION);
65 if(again != javax.swing.JOptionPane.YES_OPTION)
96 @SuppressWarnings(
"unchecked")
101 jTable1 =
new javax.swing.JTable();
102 jLabel1 =
new javax.swing.JLabel();
103 jLabel3 =
new javax.swing.JLabel();
105 jTable2 =
new javax.swing.JTable();
106 jButton1 =
new javax.swing.JButton();
107 jButton2 =
new javax.swing.JButton();
108 jLabel2 =
new javax.swing.JLabel();
109 jButton3 =
new javax.swing.JButton();
111 jTable3 =
new javax.swing.JTable();
113 jTable4 =
new javax.swing.JTable();
114 jButton4 =
new javax.swing.JButton();
116 jMenu1 =
new javax.swing.JMenu();
118 jMenu2 =
new javax.swing.JMenu();
124 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
125 setTitle(
"P2PFileSystem - Server");
126 setName(
"ServerFrame");
127 addWindowListener(
new java.awt.event.WindowAdapter() {
128 public void windowClosing(java.awt.event.WindowEvent evt) {
133 jTable1.setModel(
new javax.swing.table.DefaultTableModel(
138 "ID",
"IP",
"USERNAME",
"PASSWORD" 141 Class[] types =
new Class [] {
142 java.lang.Integer.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
145 public Class getColumnClass(
int columnIndex) {
146 return types [columnIndex];
149 jTable1.setCellSelectionEnabled(
true);
150 jTable1.getTableHeader().setReorderingAllowed(
false);
152 jTable1.getColumnModel().getColumn(0).setPreferredWidth(20);
153 jTable1.getColumnModel().getColumn(1).setPreferredWidth(20);
155 jLabel1.setFont(
new java.awt.Font(
"Tahoma", 1, 12));
156 jLabel1.setText(
"Connected clients");
158 jLabel3.setFont(
new java.awt.Font(
"Tahoma", 1, 12));
159 jLabel3.setText(
"Client's files");
161 jTable2.setModel(
new javax.swing.table.DefaultTableModel(
166 "Nome File",
"ID nodo proprietario",
"ID nodo in accesso",
"Tipo di accesso" 169 Class[] types =
new Class [] {
170 java.lang.String.class, java.lang.Integer.class, java.lang.String.class, java.lang.String.class
172 boolean[] canEdit =
new boolean [] {
173 false,
false,
false,
false 176 public Class getColumnClass(
int columnIndex) {
177 return types [columnIndex];
180 public boolean isCellEditable(
int rowIndex,
int columnIndex) {
181 return canEdit [columnIndex];
186 jButton1.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/icons/LogOut_ico.png")));
188 jButton1.addActionListener(
new java.awt.event.ActionListener() {
189 public void actionPerformed(java.awt.event.ActionEvent evt) {
194 jButton2.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/icons/Refresh_ico.png")));
195 jButton2.setText(
"Update file list");
196 jButton2.addActionListener(
new java.awt.event.ActionListener() {
197 public void actionPerformed(java.awt.event.ActionEvent evt) {
202 jLabel2.setFont(
new java.awt.Font(
"Tahoma", 1, 12));
203 jLabel2.setText(
"P2P File System ");
205 jButton3.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/icons/disconnectIcon.png")));
206 jButton3.setText(
"Disconnect client");
207 jButton3.addActionListener(
new java.awt.event.ActionListener() {
208 public void actionPerformed(java.awt.event.ActionEvent evt) {
213 jTable3.setModel(
new javax.swing.table.DefaultTableModel(
218 "ID",
"IP",
"USERNAME",
"PASSWORD" 221 Class[] types =
new Class [] {
222 java.lang.Integer.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
224 boolean[] canEdit =
new boolean [] {
225 false,
false,
false,
false 228 public Class getColumnClass(
int columnIndex) {
229 return types [columnIndex];
232 public boolean isCellEditable(
int rowIndex,
int columnIndex) {
233 return canEdit [columnIndex];
236 jTable3.getTableHeader().setReorderingAllowed(
false);
238 jTable3.getColumnModel().getColumn(0).setPreferredWidth(20);
239 jTable3.getColumnModel().getColumn(1).setPreferredWidth(20);
241 jTable4.setModel(
new javax.swing.table.DefaultTableModel(
246 "File ID",
"Name",
"Path",
"Client ID",
"Size",
"Date",
"Rights",
"Insertion time" 249 Class[] types =
new Class [] {
250 java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
252 boolean[] canEdit =
new boolean [] {
253 false,
false,
false,
false,
false,
false,
false,
false 256 public Class getColumnClass(
int columnIndex) {
257 return types [columnIndex];
260 public boolean isCellEditable(
int rowIndex,
int columnIndex) {
261 return canEdit [columnIndex];
266 jButton4.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/icons/Refresh_ico.png")));
267 jButton4.setText(
"Update Client List");
268 jButton4.addActionListener(
new java.awt.event.ActionListener() {
269 public void actionPerformed(java.awt.event.ActionEvent evt) {
276 jMenuItem1.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/icons/LogOut_ico.png")));
278 jMenuItem1.addActionListener(
new java.awt.event.ActionListener() {
279 public void actionPerformed(java.awt.event.ActionEvent evt) {
289 jMenuItem2.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/icons/Refresh_ico.png")));
291 jMenuItem2.addActionListener(
new java.awt.event.ActionListener() {
292 public void actionPerformed(java.awt.event.ActionEvent evt) {
298 jMenuItem3.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/icons/disconnectIcon.png")));
301 jMenuItem3.addActionListener(
new java.awt.event.ActionListener() {
302 public void actionPerformed(java.awt.event.ActionEvent evt) {
309 jMenuItem4.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/icons/Refresh_ico.png")));
311 jMenuItem4.addActionListener(
new java.awt.event.ActionListener() {
312 public void actionPerformed(java.awt.event.ActionEvent evt) {
322 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(getContentPane());
323 getContentPane().setLayout(layout);
324 layout.setHorizontalGroup(
325 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
326 .addGroup(layout.createSequentialGroup()
328 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
329 .addGroup(layout.createSequentialGroup()
330 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING,
false)
331 .addComponent(
jScrollPane3, javax.swing.GroupLayout.Alignment.LEADING, 0, 0, Short.MAX_VALUE)
332 .addComponent(
jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING, 0, 0, Short.MAX_VALUE))
333 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
334 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
335 .addComponent(
jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 770, Short.MAX_VALUE)
337 .addGroup(layout.createSequentialGroup()
338 .addGap(456, 456, 456)
340 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 63, Short.MAX_VALUE)
341 .addComponent(
jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE))
342 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
343 .addComponent(
jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 594, javax.swing.GroupLayout.PREFERRED_SIZE)
344 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 31, Short.MAX_VALUE)
345 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
346 .addComponent(
jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, 145, Short.MAX_VALUE)
352 layout.setVerticalGroup(
353 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
354 .addGroup(layout.createSequentialGroup()
359 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
360 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
361 .addGroup(layout.createSequentialGroup()
362 .addComponent(
jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
363 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
364 .addComponent(
jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE))
365 .addComponent(
jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE))
366 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
367 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
369 .addComponent(
jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
371 .addComponent(
jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE))
372 .addGroup(layout.createSequentialGroup()
375 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
376 .addComponent(
jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 221, javax.swing.GroupLayout.PREFERRED_SIZE)
377 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
378 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,
false)
379 .addComponent(
jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
380 .addComponent(
jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, 44, Short.MAX_VALUE))
395 l.setLocationRelativeTo(null);
406 l.setLocationRelativeTo(null);
436 ServerFrame.
IDB.delFileListBy(null, null, null, null, null, null, null, null, null, null);
445 Frame[] f = Frame.getFrames();
446 for(
int i =0; i< f.length; i++){
447 if(((f[i].getName()).equals(
"MainFrame")&&(!f[i].isVisible()))&&(!
Config.
r_clientOpen()))
524 javax.swing.JLabel label1 =
new javax.swing.JLabel(
"Insert <root> username:");
525 javax.swing.JTextField juf =
new javax.swing.JTextField();
526 javax.swing.JLabel label2 =
new javax.swing.JLabel(
"Insert <root> password:");
527 javax.swing.JPasswordField jpf =
new javax.swing.JPasswordField();
528 javax.swing.JLabel label3 =
new javax.swing.JLabel(
"Insert <root> default DB:");
529 javax.swing.JTextField jdf =
new javax.swing.JTextField();
530 javax.swing.JOptionPane.showConfirmDialog(null,
new Object[]{label1,juf , label2, jpf, label3, jdf},
"DBMS <root> Password:", javax.swing.JOptionPane.OK_CANCEL_OPTION,1);
531 pswdroot = jpf.getText();
532 userroot = juf.getText();
533 dbroot = jdf.getText();
534 jpf.setText(
"*****");
552 String charok =
"QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm1234567890";
554 int len = minlen + (int)(java.lang.Math.round(java.lang.Math.random()*(maxlen-minlen)));
556 for(
int i=0;i<len;i++)
557 pswdp2p += charok.charAt((
int)(java.lang.Math.round(java.lang.Math.random()*(charok.length()-1))));
565 DefaultTableModel model1 = (DefaultTableModel)
jTable3.getModel();
566 model1.setRowCount(0);
567 ArrayList listUser =
IDB.getUserList(null);
569 Object [] obj=
new Object [10];
571 for(
int i=0; i< listUser.size(); i++){
573 ArrayList temp = (ArrayList)listUser.get(i);
574 obj[++k] = Integer.parseInt(temp.get(++j).toString());
575 obj[++k] = temp.get(++j).toString();
576 obj[++k] = temp.get(++j).toString();
577 obj[++k] = temp.get(++j).toString();
580 model1.fireTableRowsInserted(0, listUser.size()-1);
588 DefaultTableModel model2 = (DefaultTableModel)
jTable4.getModel();
589 model2.setRowCount(0);
590 ArrayList listFile =
IDB.getFileList(
"");
592 Object [] obj=
new Object [10];
594 for(
int i=0; i< listFile.size(); i++){
596 ArrayList temp = (ArrayList)listFile.get(i);
597 obj[++k] = temp.get(++j).toString();
598 obj[++k] = temp.get(++j).toString();
599 obj[++k] = temp.get(++j).toString();
600 obj[++k] = temp.get(++j).toString();
602 obj[++k] = temp.get(++j).toString();
603 obj[++k] = temp.get(++j).toString();
604 obj[++k] = temp.get(++j).toString();
606 obj[++k] = temp.get(++j).toString();
609 model2.fireTableRowsInserted(0, listFile.size()-1);
620 int indexToRemove =
jTable3.getSelectedRow();
621 String
id =
jTable3.getModel().getValueAt(indexToRemove, 0).toString();
622 String ip =
jTable3.getModel().getValueAt(indexToRemove, 1).toString();
623 String user =
jTable3.getModel().getValueAt(indexToRemove, 2).toString();
624 String pswd =
jTable3.getModel().getValueAt(indexToRemove, 3).toString();
626 IDB.delUserListBy(
id, ip, user, pswd);
628 DefaultTableModel model = (DefaultTableModel)
jTable3.getModel();
629 model.removeRow(indexToRemove);
630 model.fireTableRowsDeleted(indexToRemove, indexToRemove);
632 IDB.delFileListBy(null, null, null,
id, null, null, null, null,
"0", null);
static void w_serverOpen(boolean value)
Permette la scrittura della varibile relativa in modo sicuro.
void initComponents()
Metodo chiamato dal costruttore per inizializzare la form WARNING: Do NOT modify this code...
Classe che mette a disposizione funzioni per interfacciarsi al DBMS in modo rapido ed eventualmente s...
static p2pserver.InquireDB IDB
javax.swing.JMenuItem jMenuItem3
javax.swing.JScrollPane jScrollPane5
Classe che permette la configurazione di tutto il programma in base alle specifiche esigenze dell'ute...
static void getP2pData()
Metodo che crea una password random per il nuovo utente che accede al db.
Classe che implementa metodi vari di utilita' generale.
void jButton2ActionPerformed(java.awt.event.ActionEvent evt)
Azione effettuata in seguito alla pressione del bottone di Update file list: creazione di un istanza ...
javax.swing.JButton jButton1
javax.swing.JMenuItem jMenuItem2
javax.swing.JMenuItem jMenuItem1
javax.swing.JTable jTable2
Classe che implementa il servizio Server.
static String r_userp2p()
Permette la lettura della varibile relativa in modo sicuro.
javax.swing.JScrollPane jScrollPane2
javax.swing.JMenuBar jMenuBar1
Classe che genera graficamente la finestra di LogOut dal frame Server.
void getFileList()
Metodo che tramite IDB ottiene la lista dei file condivisi e li inserisce nella tabella jTable4...
void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt)
Azione effettuata in seguito alla pressione del bottone di LogOut dal JMenu: creazione di un istanza ...
javax.swing.JButton jButton4
javax.swing.JLabel jLabel2
javax.swing.JTable jTable1
javax.swing.JButton jButton3
Classe che permette la preparazione delle tabelle accessibili dall'utente specificato in configurazio...
void disconnectClient()
Metodo che disconnette il client selezionato dalla jTable3, eliminando il suo report dallo userDB e t...
static void logGeneric(String data)
Scrive i dati in input sul file di log Generico (se questo esiste valido)
void formWindowClosing(java.awt.event.WindowEvent evt)
Azioni da effettuare alla chiusura della finestra: cancellazione delle tabelle dal db...
static String r_dbp2p()
Permette la lettura della varibile relativa in modo sicuro.
javax.swing.JButton jButton2
Classe che mette a disposizione funzioni per interfacciarsi al DBMS in modo rapido ed eventualmente s...
javax.swing.JTable jTable3
void jButton1ActionPerformed(java.awt.event.ActionEvent evt)
Azione effettuata in seguito alla pressione del bottone di LogOut: creazione di un istanza di LogOutF...
javax.swing.JLabel jLabel1
Classe che permette la preparazione del DBMS in modo da renderlo accessibile in modo sicuro da un ute...
javax.swing.JTable jTable4
javax.swing.JSeparator jSeparator1
static void getRootData()
Metodo che crea una form in cui inserire username e password di root del dbms, e il nome del db di de...
ServerFrame()
Costruttore che crea la form ServerFrame, prepara i DB, crea un istanza di InquireDB, attiva ServerListener e ServerRMI invocando due thread.
void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt)
Azioni effettuata in seguito alla pressione del bottone Disconnect Client dal JMenu: disconnessione d...
static Connection connect(boolean speak, String dbms, String user, String pswd)
Restituisce una connessione (Connection) al DB selezionato.
javax.swing.JScrollPane jScrollPane4
javax.swing.JScrollPane jScrollPane3
void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt)
Azione effettuata in seguito alla pressione del bottone di Update user list dal JMenu: creazione di u...
Classe implementata a Thread che permette di lanciare un processo batch/bash che esegue il comando RM...
void getUserList()
Metodo che tramite IDB ottiene la lista degli utenti collegati e li inserisce nella tabella jTable3...
javax.swing.JLabel jLabel3
void jButton4ActionPerformed(java.awt.event.ActionEvent evt)
Azione effettuata in seguito alla pressione del bottone di Update user list: creazione di un istanza ...
static boolean r_clientOpen()
Permette la lettura della varibile relativa in modo sicuro.
Classe che implementa il metodo run dell'interfaccia Runnable e crea un'istanza di ServerListener...
void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt)
Azione effettuata in seguito alla pressione del bottone di Update file list dal JMenu: creazione di u...
javax.swing.JMenuItem jMenuItem4
void jButton3ActionPerformed(java.awt.event.ActionEvent evt)
Azioni effettuata in seguito alla pressione del bottone Disconnect Client: disconnessione del client ...