Browse Source

Edited token function for wizard
Added new paths for wizard
Added copy paths for wizard
Added info boxes to wizard
Fixed wide issue on hash key #817

causefx 8 years ago
parent
commit
46d887a3fe
3 changed files with 194 additions and 135 deletions
  1. 135 130
      api/functions/token-functions.php
  2. 30 5
      api/pages/wizard.php
  3. 29 0
      css/organizr.css

+ 135 - 130
api/functions/token-functions.php

@@ -1,142 +1,147 @@
 <?php
-
 function jwtParse($token)
 {
-    try {
-        $result = array();
-        $result['valid'] = false;
-        // Check Token with JWT
-        // Set key
-        if (!isset($GLOBALS['organizrHash'])) {
-            return null;
-        }
-        $key = $GLOBALS['organizrHash'];
-        // SHA256 Encryption
-        $signer = new Lcobucci\JWT\Signer\Hmac\Sha256();
-        $jwttoken = (new Lcobucci\JWT\Parser())->parse((string) $token); // Parses from a string
-        $jwttoken->getHeaders(); // Retrieves the token header
-        $jwttoken->getClaims(); // Retrieves the token claims
-        // Start Validation
-        if ($jwttoken->verify($signer, $key)) {
-            $data = new Lcobucci\JWT\ValidationData(); // It will use the current time to validate (iat, nbf and exp)
-            $data->setIssuer('Organizr');
-            $data->setAudience('Organizr');
-            if ($jwttoken->validate($data)) {
-                $result['valid'] = true;
-                $result['username'] = $jwttoken->getClaim('username');
-                $result['group'] = $jwttoken->getClaim('group');
-                $result['groupID'] = $jwttoken->getClaim('groupID');
-                $result['userID'] = $jwttoken->getClaim('userID');
-                $result['email'] = $jwttoken->getClaim('email');
-                $result['image'] = $jwttoken->getClaim('image');
-                $result['tokenExpire'] = $jwttoken->getClaim('exp');
-                $result['tokenDate'] = $jwttoken->getClaim('iat');
-                $result['token'] = $jwttoken->getClaim('exp');
-            }
-        }
-        if ($result['valid'] == true) {
-            return $result;
-        } else {
-            return false;
-        }
-    } catch (\RunException $e) {
-        return false;
-    } catch (\OutOfBoundsException $e) {
-        return false;
-    } catch (\RunTimeException $e) {
-        return false;
-    } catch (\InvalidArgumentException $e) {
-        return false;
-    }
+	try {
+		$result = array();
+		$result['valid'] = false;
+		// Check Token with JWT
+		// Set key
+		if (!isset($GLOBALS['organizrHash'])) {
+			return null;
+		}
+		$key = $GLOBALS['organizrHash'];
+		// SHA256 Encryption
+		$signer = new Lcobucci\JWT\Signer\Hmac\Sha256();
+		$jwttoken = (new Lcobucci\JWT\Parser())->parse((string)$token); // Parses from a string
+		$jwttoken->getHeaders(); // Retrieves the token header
+		$jwttoken->getClaims(); // Retrieves the token claims
+		// Start Validation
+		if ($jwttoken->verify($signer, $key)) {
+			$data = new Lcobucci\JWT\ValidationData(); // It will use the current time to validate (iat, nbf and exp)
+			$data->setIssuer('Organizr');
+			$data->setAudience('Organizr');
+			if ($jwttoken->validate($data)) {
+				$result['valid'] = true;
+				$result['username'] = $jwttoken->getClaim('username');
+				$result['group'] = $jwttoken->getClaim('group');
+				$result['groupID'] = $jwttoken->getClaim('groupID');
+				$result['userID'] = $jwttoken->getClaim('userID');
+				$result['email'] = $jwttoken->getClaim('email');
+				$result['image'] = $jwttoken->getClaim('image');
+				$result['tokenExpire'] = $jwttoken->getClaim('exp');
+				$result['tokenDate'] = $jwttoken->getClaim('iat');
+				$result['token'] = $jwttoken->getClaim('exp');
+			}
+		}
+		if ($result['valid'] == true) {
+			return $result;
+		} else {
+			return false;
+		}
+	} catch (\RunException $e) {
+		return false;
+	} catch (\OutOfBoundsException $e) {
+		return false;
+	} catch (\RunTimeException $e) {
+		return false;
+	} catch (\InvalidArgumentException $e) {
+		return false;
+	}
 }
+
 function createToken($username, $email, $image, $group, $groupID, $key, $days = 1)
 {
-    //Quick get user ID
-    try {
-        $database = new Dibi\Connection([
-            'driver' => 'sqlite3',
-            'database' => $GLOBALS['dbLocation'].$GLOBALS['dbName'],
-        ]);
-        $result = $database->fetch('SELECT * FROM users WHERE username = ? COLLATE NOCASE OR email = ? COLLATE NOCASE', $username, $email);
-        // Create JWT
-        // Set key
-        // SHA256 Encryption
-        $signer = new Lcobucci\JWT\Signer\Hmac\Sha256();
-        // Start Builder
-        $jwttoken = (new Lcobucci\JWT\Builder())->setIssuer('Organizr') // Configures the issuer (iss claim)
-                                    ->setAudience('Organizr') // Configures the audience (aud claim)
-                                    ->setId('4f1g23a12aa', true) // Configures the id (jti claim), replicating as a header item
-                                    ->setIssuedAt(time()) // Configures the time that the token was issue (iat claim)
-                                    ->setExpiration(time() + (86400 * $days)) // Configures the expiration time of the token (exp claim)
-                                    ->set('username', $result['username']) // Configures a new claim, called "username"
-                                    ->set('group', $result['group']) // Configures a new claim, called "group"
-                                    ->set('groupID', $result['group_id']) // Configures a new claim, called "groupID"
-                                    ->set('email', $result['email']) // Configures a new claim, called "email"
-                                    ->set('image', $result['image']) // Configures a new claim, called "image"
-                                    ->set('userID', $result['id']) // Configures a new claim, called "image"
-                                    ->sign($signer, $key) // creates a signature using "testing" as key
-                                    ->getToken(); // Retrieves the generated token
-        $jwttoken->getHeaders(); // Retrieves the token headers
-        $jwttoken->getClaims(); // Retrieves the token claims
-        coookie('set', 'organizrToken', $jwttoken, $days);
-        return $jwttoken;
-    } catch (Dibi\Exception $e) {
-        return false;
-    }
+	if (!isset($GLOBALS['dbLocation']) || !isset($GLOBALS['dbName'])) {
+		return false;
+	}
+	//Quick get user ID
+	try {
+		$database = new Dibi\Connection([
+			'driver' => 'sqlite3',
+			'database' => $GLOBALS['dbLocation'] . $GLOBALS['dbName'],
+		]);
+		$result = $database->fetch('SELECT * FROM users WHERE username = ? COLLATE NOCASE OR email = ? COLLATE NOCASE', $username, $email);
+		// Create JWT
+		// Set key
+		// SHA256 Encryption
+		$signer = new Lcobucci\JWT\Signer\Hmac\Sha256();
+		// Start Builder
+		$jwttoken = (new Lcobucci\JWT\Builder())->setIssuer('Organizr')// Configures the issuer (iss claim)
+		->setAudience('Organizr')// Configures the audience (aud claim)
+		->setId('4f1g23a12aa', true)// Configures the id (jti claim), replicating as a header item
+		->setIssuedAt(time())// Configures the time that the token was issue (iat claim)
+		->setExpiration(time() + (86400 * $days))// Configures the expiration time of the token (exp claim)
+		->set('username', $result['username'])// Configures a new claim, called "username"
+		->set('group', $result['group'])// Configures a new claim, called "group"
+		->set('groupID', $result['group_id'])// Configures a new claim, called "groupID"
+		->set('email', $result['email'])// Configures a new claim, called "email"
+		->set('image', $result['image'])// Configures a new claim, called "image"
+		->set('userID', $result['id'])// Configures a new claim, called "image"
+		->sign($signer, $key)// creates a signature using "testing" as key
+		->getToken(); // Retrieves the generated token
+		$jwttoken->getHeaders(); // Retrieves the token headers
+		$jwttoken->getClaims(); // Retrieves the token claims
+		coookie('set', 'organizrToken', $jwttoken, $days);
+		return $jwttoken;
+	} catch (Dibi\Exception $e) {
+		return false;
+	}
 }
-function validateToken($token, $global=false)
+
+function validateToken($token, $global = false)
 {
-    // Validate script
-    $userInfo = jwtParse($token);
-    $validated = $userInfo ? true : false;
-    if ($validated == true) {
-        if ($global == true) {
-            try {
-                $database = new Dibi\Connection([
-                    'driver' => 'sqlite3',
-                    'database' => $GLOBALS['dbLocation'].$GLOBALS['dbName'],
-                ]);
-                $result = $database->fetch('SELECT * FROM users WHERE id = ?', $userInfo['userID']);
-                $GLOBALS['organizrUser'] = array(
-                    "token"=>$token,
-                    "tokenDate"=>$userInfo['tokenDate'],
-                    "tokenExpire"=>$userInfo['tokenExpire'],
-                    "username"=>$result['username'],
-                    "group"=>$result['group'],
-                    "groupID"=>$result['group_id'],
-                    "email"=>$result['email'],
-                    "image"=>$result['image'],
-                    "userID"=>$result['id'],
-                    "loggedin"=>true,
-                );
-            } catch (Dibi\Exception $e) {
-                $GLOBALS['organizrUser'] = false;
-            }
-        }
-    } else {
-        // Delete cookie & reload page
-        coookie('delete', 'organizrToken');
-        $GLOBALS['organizrUser'] = false;
-    }
+	// Validate script
+	$userInfo = jwtParse($token);
+	$validated = $userInfo ? true : false;
+	if ($validated == true) {
+		if ($global == true) {
+			try {
+				$database = new Dibi\Connection([
+					'driver' => 'sqlite3',
+					'database' => $GLOBALS['dbLocation'] . $GLOBALS['dbName'],
+				]);
+				$result = $database->fetch('SELECT * FROM users WHERE id = ?', $userInfo['userID']);
+				$GLOBALS['organizrUser'] = array(
+					"token" => $token,
+					"tokenDate" => $userInfo['tokenDate'],
+					"tokenExpire" => $userInfo['tokenExpire'],
+					"username" => $result['username'],
+					"group" => $result['group'],
+					"groupID" => $result['group_id'],
+					"email" => $result['email'],
+					"image" => $result['image'],
+					"userID" => $result['id'],
+					"loggedin" => true,
+				);
+			} catch (Dibi\Exception $e) {
+				$GLOBALS['organizrUser'] = false;
+			}
+		}
+	} else {
+		// Delete cookie & reload page
+		coookie('delete', 'organizrToken');
+		$GLOBALS['organizrUser'] = false;
+	}
 }
+
 function getOrganizrUserToken()
 {
-    if (isset($_COOKIE['organizrToken'])) {
-        // Get token form cookie and validate
-        validateToken($_COOKIE['organizrToken'], true);
-    } else {
-        $GLOBALS['organizrUser'] = array(
-            "token"=>null,
-            "tokenDate"=>null,
-            "tokenExpire"=>null,
-            "username"=>"Guest",
-            "group"=>getGuest()['group'],
-            "groupID"=>getGuest()['group_id'],
-            "email"=>null,
-            //"groupImage"=>getGuest()['image'],
-            "image"=>getGuest()['image'],
-            "userID"=>null,
-            "loggedin"=>false
-        );
-    }
+	if (isset($_COOKIE['organizrToken'])) {
+		// Get token form cookie and validate
+		validateToken($_COOKIE['organizrToken'], true);
+	} else {
+		$GLOBALS['organizrUser'] = array(
+			"token" => null,
+			"tokenDate" => null,
+			"tokenExpire" => null,
+			"username" => "Guest",
+			"group" => getGuest()['group'],
+			"groupID" => getGuest()['group_id'],
+			"email" => null,
+			//"groupImage"=>getGuest()['image'],
+			"image" => getGuest()['image'],
+			"userID" => null,
+			"loggedin" => false
+		);
+	}
 }

+ 30 - 5
api/pages/wizard.php

@@ -1,5 +1,4 @@
 <?php
-
 $pageWizard = '
 <script>
     (function() {
@@ -188,6 +187,18 @@ $pageWizard = '
                     <form class="form-horizontal" id="validation" name="validation" onsubmit="return false;">
                         <div class="wizard-content">
                             <div class="wizard-pane active" role="tabpanel">
+	                            <div class="panel panel-info">
+                                    <div class="panel-heading">
+                                        <i class="ti-alert fa-fw"></i> <span lang="en">Notice</span>
+                                        <div class="pull-right"><a href="#" data-perform="panel-collapse"><i class="ti-minus"></i></a> <a href="#" data-perform="panel-dismiss"><i class="ti-close"></i></a> </div>
+                                    </div>
+                                    <div class="panel-wrapper collapse in" aria-expanded="true">
+                                        <div class="panel-body">
+                                            <p lang="en">Personal has everything unlocked - no restrictions</p>
+                                            <p lang="en">Business has Media items hidden [Plex, Emby etc...]</p>
+                                        </div>
+                                    </div>
+                                </div>
                                 <div class="form-group">
                                     <label for="license" lang="en">Install Type</label>
                                     <div class="input-group">
@@ -201,6 +212,17 @@ $pageWizard = '
                                 </div>
                             </div>
                             <div class="wizard-pane" role="tabpanel">
+                                <div class="panel panel-info">
+                                    <div class="panel-heading">
+                                        <i class="ti-alert fa-fw"></i> <span lang="en">Notice</span>
+                                        <div class="pull-right"><a href="#" data-perform="panel-collapse"><i class="ti-minus"></i></a> <a href="#" data-perform="panel-dismiss"><i class="ti-close"></i></a> </div>
+                                    </div>
+                                    <div class="panel-wrapper collapse in" aria-expanded="true">
+                                        <div class="panel-body">
+                                            <p lang="en">If using Plex or Emby - It is suggested that you use the username and email of the Admin account.</p>
+                                        </div>
+                                    </div>
+                                </div>
                                 <div class="form-group">
                                     <label for="username" lang="en">Username</label>
                                     <div class="input-group">
@@ -231,7 +253,8 @@ $pageWizard = '
                                     </div>
                                     <div class="panel-wrapper collapse in" aria-expanded="true">
                                         <div class="panel-body">
-                                            <p lang="en">The Hash Key will be used to decrypt all passwords etc... on the server.</p>
+                                            <p lang="en">The Hash Key will be used to decrypt all passwords etc... on the server. {User-Generated]</p>
+                                            <p lang="en">The Registration Password will lockout the registration field with this password. {User-Generated]</p>
                                             <p lang="en">The API Key will be used for all calls to organizr for the UI. [Auto-Generated]</p>
                                         </div>
                                     </div>
@@ -267,7 +290,9 @@ $pageWizard = '
                                     <div class="panel-wrapper collapse in" aria-expanded="true">
                                         <div class="panel-body">
                                             <p lang="en">The Database will contain sensitive information.  Please place in directory outside of root Web Directory.</p>
-                                            <p lang="en">Parent Directory: <code>'.dirname(__DIR__, 3).'</code>
+                                            <p lang="en">Suggested Directory: <code>' . dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'db</code> <a class="btn default btn-outline clipboard p-5" data-clipboard-text="' . dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'db" href="javascript:void(0);"><i class="ti-clipboard"></i></a></p>
+                                            <p lang="en">Current Directory: <code>' . dirname(__DIR__, 2) . '</code> <a class="btn default btn-outline clipboard p-5" data-clipboard-text="' . dirname(__DIR__, 2) . '" href="javascript:void(0);"><i class="ti-clipboard"></i></a></p>
+                                            <p lang="en">Parent Directory: <code>' . dirname(__DIR__, 3) . '</code> <a class="btn default btn-outline clipboard p-5" data-clipboard-text="' . dirname(__DIR__, 3) . '" href="javascript:void(0);"><i class="ti-clipboard"></i></a></p>
                                         </div>
                                     </div>
                                 </div>
@@ -282,8 +307,8 @@ $pageWizard = '
                                     <label for="location" lang="en">Database Location</label>
                                     <div class="input-group">
                                         <div class="input-group-addon"><i class="ti-server"></i></div>
-                                        <input type="text" class="form-control wizardInput" name="location" id="form-location" placeholder="'.dirname(__DIR__, 3).'">
-                                        <span class="input-group-btn"><button class="btn btn-info testPath" lang="en" type="button">Test</button></span>
+                                        <input type="text" class="form-control wizardInput" name="location" id="form-location" placeholder="Enter path or copy from above">
+                                        <span class="input-group-btn"><button class="btn btn-info testPath" lang="en" type="button">Test / Create Path</button></span>
                                     </div>
                                 </div>
                             </div>

+ 29 - 0
css/organizr.css

@@ -818,4 +818,33 @@ input.has-success {
 }
 .recent-items .owl-item {
     height: 225px;
+}
+.tooltip-content5 {
+    position: absolute;
+    z-index: 9999;
+    min-width: 300px;
+    max-width: 350px;
+    left: 50%;
+    bottom: 100%;
+    font-size: 20px;
+    line-height: 1.4;
+    text-align: center;
+    font-weight: 400;
+    color: #fff;
+    background: 0 0;
+    opacity: 0;
+    margin: 0 0 20px -150px;
+    cursor: default;
+    pointer-events: none;
+    -webkit-font-smoothing: antialiased;
+    -webkit-transition: opacity .3s .3s;
+    transition: opacity .3s .3s;
+}
+.tooltip-inner2 {
+    background: #2b2b2b;
+    padding: 40px 0px;
+    -webkit-transform: translate3d(0,100%,0);
+    transform: translate3d(0,100%,0);
+    webkit-transition: -webkit-transform .3s;
+    transition: transform .3s;
 }