summaryrefslogtreecommitdiff
path: root/www/pages/index.php
diff options
context:
space:
mode:
Diffstat (limited to 'www/pages/index.php')
-rw-r--r--www/pages/index.php136
1 files changed, 136 insertions, 0 deletions
diff --git a/www/pages/index.php b/www/pages/index.php
new file mode 100644
index 0000000..3dcb684
--- /dev/null
+++ b/www/pages/index.php
@@ -0,0 +1,136 @@
+<?php
+// Include config file
+
+$cmd = "/usr/sbin/mts-io-sysfs show product-id";
+$handle = popen($cmd, 'r');
+$product = fread($handle,4192);
+pclose($handle);
+$cmd = "/usr/sbin/mts-io-sysfs show device-id";
+$handle = popen($cmd, 'r');
+$device = fread($handle,4192);
+pclose($handle);
+$conftxt = "Password";
+$finished = "";
+$pwdscore = "";
+$status = 0;
+$save_password = "";
+
+// Define variables and initialize with empty values
+$username = $password = $save_password = "";
+$username_err = $password_err = $confirm_password_err = "";
+
+openlog("Commision:", LOG_PID | LOG_PERROR, LOG_LOCAL0);
+
+// Processing form data when form is submitted
+if($_SERVER["REQUEST_METHOD"] == "POST"){
+ $mismatch = 1; // We have two different passwords
+
+ $save_password = trim($_POST["save_password"]);
+
+ syslog(LOG_ALERT, "Enter post: save_password = $save_password");
+
+ // Validate username
+ if(empty(trim($_POST["username"]))){
+ $username_err = "Please enter a username.";
+ } else
+ $username = trim($_POST["username"]);
+ // Validate password
+ if(empty(trim($_POST["password"]))){
+ $password_err = "Please enter a password.";
+ $mismatch = 0;
+ } else {
+ $password = trim($_POST["password"]);
+ if (empty($save_password)) {
+ $mismatch = 0;
+ $cmd = "echo '" . $password . "' | /usr/bin/pwscore";
+ $handle = popen($cmd, 'r');
+ $result = fread($handle,4192);
+ if (pclose($handle) === 0) {
+ $pwdscore = "Password score: " . $result;
+ $save_password = $password;
+ $password = "";
+ $conftxt = "Re-Enter";
+ } else {
+ $password_err = $result;
+ $password = "";
+ syslog(LOG_ALERT, "Need password confirmation");
+ }
+ syslog(LOG_ALERT, "pwscore: score: $pwdscore msg = $password_err");
+ }
+ }
+
+ if (!empty($password) && ($password === $save_password) && ! empty($username)) {
+ syslog(LOG_ALERT, "Have password: $password username: $password");
+ if(empty($username_err) && empty($password_err) && empty($confirm_password_err)){
+ // Create user in sudo group
+ $cmd = "/usr/sbin/useradd -U -m -G sudo,dialout,disk -s /bin/bash " . $username . " 2>&1";
+ syslog(LOG_ALERT, "useradd cmd: $cmd");
+ $handle = popen($cmd, 'r');
+ $result = fread($handle, 4192);
+ $status = pclose($handle);
+ syslog(LOG_ALERT, "useradd: status: $status result: $result");
+ $cmd = "/usr/bin/passwd" . $username . " 2>&1";
+ $handle = popen($cmd, 'r');
+ $pwdtxt = $password . "\n" . $password;
+ $result = fwrite($handle, $pwdtxt);
+ pclose($handle);
+ syslog(LOG_ALERT, "passwd: status: $status result: $result");
+ $finished = "Commisioning Complete";
+ }
+ } else if ($mismatch === 1) {
+ $save_password = "";
+ $password_err = "Mismatch";
+ }
+ syslog(LOG_ALERT, "Leave post: save_password = $save_password");
+}
+?>
+
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <title>Commision Multi-Tech mLinux</title>
+ <link rel="stylesheet" href="http://127.0.0.1/css/bootstrap.css">
+ <style type="text/css">
+ body{ font: 14px sans-serif; }
+ .wrapper{ width: 350px; padding: 20px; }
+ </style>
+</head>
+<body>
+ <div class="wrapper">
+ <h2>Commision Multi-Tech mLinux</h2>
+
+ <p><label><?php echo $finished; ?></label></p>
+ Product-ID:
+ <?php
+ echo $product;
+ ?>
+ <br>
+ Device-ID:
+ <?php
+ echo $device;
+ ?>
+ </h3>
+ <br>
+
+ <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
+ <input type="hidden" name="save_password" value="<?php echo $save_password; ?>">
+ <div class="form-group <?php echo (!empty($username_err)) ? 'has-error' : ''; ?>">
+ <label>Username</label>
+ <input type="text" name="username" class="form-control" value="<?php echo $username; ?>">
+ <span class="help-block"><?php echo $username_err; ?></span>
+ </div>
+ <div class="form-group <?php echo (!empty($password_err)) ? 'has-error' : ''; ?>">
+ <label><?php echo $conftxt; ?></label>
+ <input type="password" name="password" class="form-control" value="<?php echo $password; ?>">
+ <span class="help-block"><?php echo $password_err; ?></span>
+ </div>
+ <p><label><?php echo $pwdscore; ?></label></p>
+ <div class="form-group">
+ <input type="submit" class="btn btn-primary" value="Submit">
+ <input type="reset" class="btn btn-default" value="Reset">
+ </div>
+ </form>
+ </div>
+</body>
+</html>