Webserver webapplicatie

Docent uitwerking

Geschreven door Peter van Gemert

Op 21 augustus 2023


Schrijf Webapplicatie

webserver $ sudo su -
webserver # cd /remote/nfs/website

webserver # vi datacenter.php
      <?php
      
      $connection = "";
      
      try {
              $dbserver = "10.20.0.12";
              $dbport = "3306";
              $dbname = "datacenter";
              $dbuser = "datacenter";
              $dbpassword = "Deltion123!";
      
              $connection = new PDO (
                      "mysql:host=$dbserver; dbname=$dbname", $dbuser, $dbpassword,
              );
      } catch(PDOExeption $e) {
              print 'Connection failed: ' . $e->getMessage();
      }
      
      $sql = 'SELECT servernaam,osnaam,ipbeheer,ipdatabase,ipnfs,ipiscsi,ipweb,ipnat FROM servers s JOIN oses o ON s.osid = o.osid;';
      $statement = $connection->prepare($sql);
      $statement->execute();
      
      $servers = $statement->fetchAll();
      
      $table_rows="";
      foreach ( $servers as $server ) {
              $table_rows .= '<tr>
              <td>'.$server['servernaam'].'</td>
              <td>'.$server['osnaam'].'</td>
              <td>'.$server['ipbeheer'].'</td>
              <td>'.$server['ipdatabase'].'</td>
              <td>'.$server['ipnfs'].'</td>
              <td>'.$server['ipiscsi'].'</td>
              <td>'.$server['ipweb'].'</td>
              <td>'.$server['ipnat'].'</td>
              </tr>';
      }
      
      echo '<!DOCTYPE html>
          
      <html>
              <head>
              <title>Datacenter webapplicatie</title>
              <link rel="stylesheet" href="/css/opmaak.css">
              <link rel="stylesheet" href="/css/datacenter.css">
      </head>
  
      <body>
      <table>
      <thead>
      <tr>
          <td>Servernaam</td>
          <td>Osnaam</td>
          <td>Beheer</td>
          <td>Database</td>
          <td>NFS</td>
          <td>iSCSI</td>
          <td>Web</td>
          <td>NAT</td>
      </tr>
      </thead>
      <tbody>
      ' . $table_rows . '
      </tbody>
      </table>
      
      </body>
      </html>';
      ?>
  webserver # php datacenter.php

Schrijf CSS bestand

  webserver # vi css/datacenter.css
      thead tr td {
              background-color: red;
              color: white;
              margin: 0;
              padding: 5;
      }