Subversion Repositories web_pages

Rev

Rev 12 | Rev 14 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 12 Rev 13
Line 30... Line 30...
30
 
30
 
31
    Assumes csv file and qr image created by processOPNSense.pl.
31
    Assumes csv file and qr image created by processOPNSense.pl.
32
 
32
 
33
    Version 1.0.0 RWR 2025-09-21
33
    Version 1.0.0 RWR 2025-09-21
34
       Initial Release
34
       Initial Release
-
 
35
    Version 1.1.0 RWR 2025-09-27
-
 
36
       Added capability of downloading VPN configuration file
35
 
37
 
36
 */
38
 */
37
 
39
 
38
// Define the path to the CSV file
40
// Define the path to the CSV file
39
$csvFile = 'users.csv';
41
$csvFile = 'users.csv';
-
 
42
// Define the path to the .ovpn files, if applicable
-
 
43
$ovpnDir = 'ovpn_files/';
-
 
44
$ovpnRegex = 'mcnoc_([a-z0-9]+)\.ovpn';
-
 
45
$ovpnFileName = '';
40
// name of image file
46
// name of image file
41
$imageFileName = '';
47
$imageFileName = '';
42
// topt code
48
// topt code
43
$code = '';
49
$code = '';
-
 
50
 
-
 
51
 
44
function csvToArray( $csvFile, $delimiter = "\t" ) {
52
function csvToArray( $csvFile, $delimiter = "\t" ) {
45
   // Initialize an array to hold the data
53
   // Initialize an array to hold the data
46
   $dataArray = [];
54
   $dataArray = [];
47
 
55
 
48
   // Open the CSV file for reading
56
   // Open the CSV file for reading
Line 60... Line 68...
60
       fclose($handle);
68
       fclose($handle);
61
   } else {
69
   } else {
62
       echo "Could not open the CSV file for reading.";
70
       echo "Could not open the CSV file for reading.";
63
   }
71
   }
64
   return $dataArray;
72
   return $dataArray;
-
 
73
} // csvToArray
-
 
74
 
65
}
75
 
-
 
76
function ovpnFile ( $path, $username, $ovpnRegex ) {
-
 
77
   if ( $files = scandir( $path ) ) {
-
 
78
      foreach ($files as $key => $value ) {
-
 
79
         if ( preg_match( "/$ovpnRegex/", $value, $matches ) ) {
-
 
80
            if ( $matches[1] == $username ) {
-
 
81
               return $path . $matches[0];
-
 
82
            }
-
 
83
         }
-
 
84
      }
-
 
85
   } else {
-
 
86
      die( "Error trying to scan directory $path\n" );
-
 
87
   }
-
 
88
   return '';
-
 
89
} // ovpnFile
66
 
90
 
67
// Check if the form is submitted
91
// Check if the form is submitted
68
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
92
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
69
    // Get the username and password from the form
93
    // Get the username and password from the form
70
    $username = $_POST['username'];
94
    $username = $_POST['username'];
Line 78... Line 102...
78
          if ( $data['name'] === $username && $data['router'] === $router ) {
102
          if ( $data['name'] === $username && $data['router'] === $router ) {
79
             if ( password_verify( $password, $data['password'] ) ) {
103
             if ( password_verify( $password, $data['password'] ) ) {
80
                $code = $data['otp'];
104
                $code = $data['otp'];
81
                $imageFileName = $data['filename'];
105
                $imageFileName = $data['filename'];
82
                $isValidUser = true;
106
                $isValidUser = true;
-
 
107
                $ovpnFileName = ovpnFile( $ovpnDir, $data['name'], $ovpnRegex );
-
 
108
                $log = date("Y-m-d H:i:s") . "\t" . $_SERVER['REMOTE_ADDR'] . "\t" .
-
 
109
                  "Success\t" . $username."\t" .PHP_EOL;
-
 
110
                file_put_contents( './log_'.date("j.n.Y").'.log', $log, FILE_APPEND );
83
             }
111
             }
84
             break;
112
             break;
85
         }
113
         }
86
      }
114
      }
87
      if ( ! $isValidUser )
115
      if ( ! $isValidUser )
88
         echo "<h1>Password wrong, or invalid user $username for router $router</h1>";
116
         echo "<h1>Password wrong, or invalid user $username for router $router</h1>";
89
    } else {
117
    } else {
90
        echo '<h1>Could not open the CSV file.</h1>';
118
        echo '<h1>Could not open the CSV file.</h1>';
91
    }
119
    }
92
}
120
}
-
 
121
 
93
?>
122
?>
94
 
123
 
95
<!DOCTYPE html>
124
<!DOCTYPE html>
96
<html lang="en">
125
<html lang="en">
97
<head>
126
<head>
Line 103... Line 132...
103
    <?php
132
    <?php
104
       if ( ! empty( $imageFileName ) && ! empty( $code ) ) {
133
       if ( ! empty( $imageFileName ) && ! empty( $code ) ) {
105
          echo "<div style='text-align: center;'>";
134
          echo "<div style='text-align: center;'>";
106
          echo "<img src='$imageFileName' alt='$code'>";
135
          echo "<img src='$imageFileName' alt='$code'>";
107
          echo "<br />Your code for $router is<br /><b>$code</b>";
136
          echo "<br />Your code for $router is<br /><b>$code</b>";
-
 
137
          if ( !empty( $ovpnFileName ) ) {
-
 
138
             echo "<br /><a href='$ovpnFileName' download>Download your OpenVPN Config File</a>";
-
 
139
          }
108
          echo '</div>';
140
          echo '</div>';
109
       }
141
       }
110
    ?>
142
    ?>
111
 
-
 
-
 
143
    <p>This page is updated hourly. If change your password, it will not be reflected here for an hour</p>
112
    <form method="POST" action="">
144
    <form method="POST" action="">
113
        <label for="username">Username:</label>
145
        <label for="username">Username:</label>
114
        <input type="text" id="username" name="username" required>
146
        <input type="text" id="username" name="username" required>
115
        <br>
147
        <br>
116
        <label for="password">Password:</label>
148
        <label for="password">Password:</label>