@@ -100,9 +100,12 @@ discard block |
||
| 100 | 100 | AND table_name = '$tablename'" |
| 101 | 101 | ); |
| 102 | 102 | |
| 103 | - if ($res > 0) return true; |
|
| 104 | - else return false; |
|
| 105 | -} |
|
| 103 | + if ($res > 0) { |
|
| 104 | + return true; |
|
| 105 | + } else { |
|
| 106 | + return false; |
|
| 107 | + } |
|
| 108 | + } |
|
| 106 | 109 | |
| 107 | 110 | //define pbkdf2 iteration count |
| 108 | 111 | @define('ITCOUNT', '2072'); |
@@ -852,7 +855,7 @@ discard block |
||
| 852 | 855 | } |
| 853 | 856 | if(($r+1) == $row_count || ($r % 400) == 399){ |
| 854 | 857 | $contents .= ");\n\n"; |
| 855 | - }else{ |
|
| 858 | + } else{ |
|
| 856 | 859 | $contents .= "),\n"; |
| 857 | 860 | } |
| 858 | 861 | $r++; |
@@ -19,7 +19,9 @@ discard block |
||
| 19 | 19 | $Nr = count($w)/$Nb - 1; // no of rounds: 10/12/14 for 128/192/256-bit keys |
| 20 | 20 | |
| 21 | 21 | $state = array(); // initialise 4xNb byte-array 'state' with input [é3.4] |
| 22 | - for ($i=0; $i<4*$Nb; $i++) $state[$i%4][floor($i/4)] = $input[$i]; |
|
| 22 | + for ($i=0; $i<4*$Nb; $i++) { |
|
| 23 | + $state[$i%4][floor($i/4)] = $input[$i]; |
|
| 24 | + } |
|
| 23 | 25 | |
| 24 | 26 | $state = self::addRoundKey($state, $w, 0, $Nb); |
| 25 | 27 | |
@@ -35,14 +37,18 @@ discard block |
||
| 35 | 37 | $state = self::addRoundKey($state, $w, $Nr, $Nb); |
| 36 | 38 | |
| 37 | 39 | $output = array(4*$Nb); // convert state to 1-d array before returning [é3.4] |
| 38 | - for ($i=0; $i<4*$Nb; $i++) $output[$i] = $state[$i%4][floor($i/4)]; |
|
| 40 | + for ($i=0; $i<4*$Nb; $i++) { |
|
| 41 | + $output[$i] = $state[$i%4][floor($i/4)]; |
|
| 42 | + } |
|
| 39 | 43 | |
| 40 | 44 | return $output; |
| 41 | 45 | } |
| 42 | 46 | |
| 43 | 47 | private static function addRoundKey($state, $w, $rnd, $Nb) { // xor Round Key into state S [é5.1.4] |
| 44 | 48 | for ($r=0; $r<4; $r++) { |
| 45 | - for ($c=0; $c<$Nb; $c++) $state[$r][$c] ^= $w[$rnd*4+$c][$r]; |
|
| 49 | + for ($c=0; $c<$Nb; $c++) { |
|
| 50 | + $state[$r][$c] ^= $w[$rnd*4+$c][$r]; |
|
| 51 | + } |
|
| 46 | 52 | } |
| 47 | 53 | |
| 48 | 54 | return $state; |
@@ -50,7 +56,9 @@ discard block |
||
| 50 | 56 | |
| 51 | 57 | private static function subBytes($s, $Nb) { // apply SBox to state S [é5.1.1] |
| 52 | 58 | for ($r=0; $r<4; $r++) { |
| 53 | - for ($c=0; $c<$Nb; $c++) $s[$r][$c] = self::$sBox[$s[$r][$c]]; |
|
| 59 | + for ($c=0; $c<$Nb; $c++) { |
|
| 60 | + $s[$r][$c] = self::$sBox[$s[$r][$c]]; |
|
| 61 | + } |
|
| 54 | 62 | } |
| 55 | 63 | |
| 56 | 64 | return $s; |
@@ -59,8 +67,14 @@ discard block |
||
| 59 | 67 | private static function shiftRows($s, $Nb) { // shift row r of state S left by r bytes [é5.1.2] |
| 60 | 68 | $t = array(4); |
| 61 | 69 | for ($r=1; $r<4; $r++) { |
| 62 | - for ($c=0; $c<4; $c++) $t[$c] = $s[$r][($c+$r)%$Nb]; // shift into temp copy |
|
| 63 | - for ($c=0; $c<4; $c++) $s[$r][$c] = $t[$c]; // and copy back |
|
| 70 | + for ($c=0; $c<4; $c++) { |
|
| 71 | + $t[$c] = $s[$r][($c+$r)%$Nb]; |
|
| 72 | + } |
|
| 73 | + // shift into temp copy |
|
| 74 | + for ($c=0; $c<4; $c++) { |
|
| 75 | + $s[$r][$c] = $t[$c]; |
|
| 76 | + } |
|
| 77 | + // and copy back |
|
| 64 | 78 | } // note that this will work for Nb=4,5,6, but not 7,8 (always 4 for AES): |
| 65 | 79 | return $s; // see fp.gladman.plus.com/cryptography_technology/rijndael/aes.spec.311.pdf |
| 66 | 80 | } |
@@ -105,28 +119,38 @@ discard block |
||
| 105 | 119 | |
| 106 | 120 | for ($i=$Nk; $i<($Nb*($Nr+1)); $i++) { |
| 107 | 121 | $w[$i] = array(); |
| 108 | - for ($t=0; $t<4; $t++) $temp[$t] = $w[$i-1][$t]; |
|
| 122 | + for ($t=0; $t<4; $t++) { |
|
| 123 | + $temp[$t] = $w[$i-1][$t]; |
|
| 124 | + } |
|
| 109 | 125 | if ($i % $Nk == 0) { |
| 110 | 126 | $temp = self::subWord(self::rotWord($temp)); |
| 111 | - for ($t=0; $t<4; $t++) $temp[$t] ^= self::$rCon[$i/$Nk][$t]; |
|
| 127 | + for ($t=0; $t<4; $t++) { |
|
| 128 | + $temp[$t] ^= self::$rCon[$i/$Nk][$t]; |
|
| 129 | + } |
|
| 112 | 130 | } elseif ($Nk > 6 && $i%$Nk == 4) { |
| 113 | 131 | $temp = self::subWord($temp); |
| 114 | 132 | } |
| 115 | - for ($t=0; $t<4; $t++) $w[$i][$t] = $w[$i-$Nk][$t] ^ $temp[$t]; |
|
| 133 | + for ($t=0; $t<4; $t++) { |
|
| 134 | + $w[$i][$t] = $w[$i-$Nk][$t] ^ $temp[$t]; |
|
| 135 | + } |
|
| 116 | 136 | } |
| 117 | 137 | |
| 118 | 138 | return $w; |
| 119 | 139 | } |
| 120 | 140 | |
| 121 | 141 | private static function subWord($w) { // apply SBox to 4-byte word w |
| 122 | - for ($i=0; $i<4; $i++) $w[$i] = self::$sBox[$w[$i]]; |
|
| 142 | + for ($i=0; $i<4; $i++) { |
|
| 143 | + $w[$i] = self::$sBox[$w[$i]]; |
|
| 144 | + } |
|
| 123 | 145 | |
| 124 | 146 | return $w; |
| 125 | 147 | } |
| 126 | 148 | |
| 127 | 149 | private static function rotWord($w) { // rotate 4-byte word w left by one byte |
| 128 | 150 | $tmp = $w[0]; |
| 129 | - for ($i=0; $i<3; $i++) $w[$i] = $w[$i+1]; |
|
| 151 | + for ($i=0; $i<3; $i++) { |
|
| 152 | + $w[$i] = $w[$i+1]; |
|
| 153 | + } |
|
| 130 | 154 | $w[3] = $tmp; |
| 131 | 155 | |
| 132 | 156 | return $w; |
@@ -21,14 +21,19 @@ discard block |
||
| 21 | 21 | public static function encrypt($plaintext, $password, $nBits) |
| 22 | 22 | { |
| 23 | 23 | $blockSize = 16; // block size fixed at 16 bytes / 128 bits (Nb=4) for AES |
| 24 | - if (!($nBits==128 || $nBits==192 || $nBits==256)) return ''; // standard allows 128/192/256 bit keys |
|
| 24 | + if (!($nBits==128 || $nBits==192 || $nBits==256)) { |
|
| 25 | + return ''; |
|
| 26 | + } |
|
| 27 | + // standard allows 128/192/256 bit keys |
|
| 25 | 28 | // note PHP (5) gives us plaintext and password in UTF8 encoding! |
| 26 | 29 | |
| 27 | 30 | // use AES itself to encrypt password to get cipher key (using plain password as source for |
| 28 | 31 | // key expansion) - gives us well encrypted key |
| 29 | 32 | $nBytes = $nBits/8; // no bytes in key |
| 30 | 33 | $pwBytes = array(); |
| 31 | - for ($i=0; $i<$nBytes; $i++) $pwBytes[$i] = ord(substr($password,$i,1)) & 0xff; |
|
| 34 | + for ($i=0; $i<$nBytes; $i++) { |
|
| 35 | + $pwBytes[$i] = ord(substr($password,$i,1)) & 0xff; |
|
| 36 | + } |
|
| 32 | 37 | $key = Aes::cipher($pwBytes, Aes::keyExpansion($pwBytes)); |
| 33 | 38 | $key = array_merge($key, array_slice($key, 0, $nBytes-16)); // expand key to 16/24/32 bytes long |
| 34 | 39 | |
@@ -39,11 +44,17 @@ discard block |
||
| 39 | 44 | $nonceSec = floor($nonce/1000); |
| 40 | 45 | $nonceMs = $nonce%1000; |
| 41 | 46 | // encode nonce with seconds in 1st 4 bytes, and (repeated) ms part filling 2nd 4 bytes |
| 42 | - for ($i=0; $i<4; $i++) $counterBlock[$i] = self::urs($nonceSec, $i*8) & 0xff; |
|
| 43 | - for ($i=0; $i<4; $i++) $counterBlock[$i+4] = $nonceMs & 0xff; |
|
| 47 | + for ($i=0; $i<4; $i++) { |
|
| 48 | + $counterBlock[$i] = self::urs($nonceSec, $i*8) & 0xff; |
|
| 49 | + } |
|
| 50 | + for ($i=0; $i<4; $i++) { |
|
| 51 | + $counterBlock[$i+4] = $nonceMs & 0xff; |
|
| 52 | + } |
|
| 44 | 53 | // and convert it to a string to go on the front of the ciphertext |
| 45 | 54 | $ctrTxt = ''; |
| 46 | - for ($i=0; $i<8; $i++) $ctrTxt .= chr($counterBlock[$i]); |
|
| 55 | + for ($i=0; $i<8; $i++) { |
|
| 56 | + $ctrTxt .= chr($counterBlock[$i]); |
|
| 57 | + } |
|
| 47 | 58 | |
| 48 | 59 | // generate key schedule - an expansion of the key into distinct Key Rounds for each round |
| 49 | 60 | $keySchedule = Aes::keyExpansion($key); |
@@ -55,8 +66,12 @@ discard block |
||
| 55 | 66 | for ($b=0; $b<$blockCount; $b++) { |
| 56 | 67 | // set counter (block #) in last 8 bytes of counter block (leaving nonce in 1st 8 bytes) |
| 57 | 68 | // done in two stages for 32-bit ops: using two words allows us to go past 2^32 blocks (68GB) |
| 58 | - for ($c=0; $c<4; $c++) $counterBlock[15-$c] = self::urs($b, $c*8) & 0xff; |
|
| 59 | - for ($c=0; $c<4; $c++) $counterBlock[15-$c-4] = self::urs($b/0x100000000, $c*8); |
|
| 69 | + for ($c=0; $c<4; $c++) { |
|
| 70 | + $counterBlock[15-$c] = self::urs($b, $c*8) & 0xff; |
|
| 71 | + } |
|
| 72 | + for ($c=0; $c<4; $c++) { |
|
| 73 | + $counterBlock[15-$c-4] = self::urs($b/0x100000000, $c*8); |
|
| 74 | + } |
|
| 60 | 75 | |
| 61 | 76 | $cipherCntr = Aes::cipher($counterBlock, $keySchedule); // -- encrypt counter block -- |
| 62 | 77 | |
@@ -89,20 +104,27 @@ discard block |
||
| 89 | 104 | public static function decrypt($ciphertext, $password, $nBits) |
| 90 | 105 | { |
| 91 | 106 | $blockSize = 16; // block size fixed at 16 bytes / 128 bits (Nb=4) for AES |
| 92 | - if (!($nBits==128 || $nBits==192 || $nBits==256)) return ''; // standard allows 128/192/256 bit keys |
|
| 107 | + if (!($nBits==128 || $nBits==192 || $nBits==256)) { |
|
| 108 | + return ''; |
|
| 109 | + } |
|
| 110 | + // standard allows 128/192/256 bit keys |
|
| 93 | 111 | $ciphertext = base64_decode($ciphertext); |
| 94 | 112 | |
| 95 | 113 | // use AES to encrypt password (mirroring encrypt routine) |
| 96 | 114 | $nBytes = $nBits/8; // no bytes in key |
| 97 | 115 | $pwBytes = array(); |
| 98 | - for ($i=0; $i<$nBytes; $i++) $pwBytes[$i] = ord(substr($password,$i,1)) & 0xff; |
|
| 116 | + for ($i=0; $i<$nBytes; $i++) { |
|
| 117 | + $pwBytes[$i] = ord(substr($password,$i,1)) & 0xff; |
|
| 118 | + } |
|
| 99 | 119 | $key = Aes::cipher($pwBytes, Aes::keyExpansion($pwBytes)); |
| 100 | 120 | $key = array_merge($key, array_slice($key, 0, $nBytes-16)); // expand key to 16/24/32 bytes long |
| 101 | 121 | |
| 102 | 122 | // recover nonce from 1st element of ciphertext |
| 103 | 123 | $counterBlock = array(); |
| 104 | 124 | $ctrTxt = substr($ciphertext, 0, 8); |
| 105 | - for ($i=0; $i<8; $i++) $counterBlock[$i] = ord(substr($ctrTxt,$i,1)); |
|
| 125 | + for ($i=0; $i<8; $i++) { |
|
| 126 | + $counterBlock[$i] = ord(substr($ctrTxt,$i,1)); |
|
| 127 | + } |
|
| 106 | 128 | |
| 107 | 129 | // generate key schedule |
| 108 | 130 | $keySchedule = Aes::keyExpansion($key); |
@@ -110,7 +132,9 @@ discard block |
||
| 110 | 132 | // separate ciphertext into blocks (skipping past initial 8 bytes) |
| 111 | 133 | $nBlocks = ceil((strlen($ciphertext)-8) / $blockSize); |
| 112 | 134 | $ct = array(); |
| 113 | - for ($b=0; $b<$nBlocks; $b++) $ct[$b] = substr($ciphertext, 8+$b*$blockSize, 16); |
|
| 135 | + for ($b=0; $b<$nBlocks; $b++) { |
|
| 136 | + $ct[$b] = substr($ciphertext, 8+$b*$blockSize, 16); |
|
| 137 | + } |
|
| 114 | 138 | $ciphertext = $ct; // ciphertext is now array of block-length strings |
| 115 | 139 | |
| 116 | 140 | // plaintext will get generated block-by-block into array of block-length strings |
@@ -118,8 +142,12 @@ discard block |
||
| 118 | 142 | |
| 119 | 143 | for ($b=0; $b<$nBlocks; $b++) { |
| 120 | 144 | // set counter (block #) in last 8 bytes of counter block (leaving nonce in 1st 8 bytes) |
| 121 | - for ($c=0; $c<4; $c++) $counterBlock[15-$c] = self::urs($b, $c*8) & 0xff; |
|
| 122 | - for ($c=0; $c<4; $c++) $counterBlock[15-$c-4] = self::urs(($b+1)/0x100000000-1, $c*8) & 0xff; |
|
| 145 | + for ($c=0; $c<4; $c++) { |
|
| 146 | + $counterBlock[15-$c] = self::urs($b, $c*8) & 0xff; |
|
| 147 | + } |
|
| 148 | + for ($c=0; $c<4; $c++) { |
|
| 149 | + $counterBlock[15-$c-4] = self::urs(($b+1)/0x100000000-1, $c*8) & 0xff; |
|
| 150 | + } |
|
| 123 | 151 | |
| 124 | 152 | $cipherCntr = Aes::cipher($counterBlock, $keySchedule); // encrypt counter block |
| 125 | 153 | |
@@ -23,14 +23,16 @@ discard block |
||
| 23 | 23 | $dp = opendir($dir); |
| 24 | 24 | $res = true; |
| 25 | 25 | while($file = readdir($dp)) { |
| 26 | - if (($file == ".") || ($file == "..")) |
|
| 27 | - continue; |
|
| 26 | + if (($file == ".") || ($file == "..")) { |
|
| 27 | + continue; |
|
| 28 | + } |
|
| 28 | 29 | |
| 29 | 30 | $fullPath = $dir."/".$file; |
| 30 | 31 | |
| 31 | 32 | if(is_dir($fullPath)) { |
| 32 | - if ($res = @chmod($fullPath, $dirPermissions)) |
|
| 33 | - $res = @chmod_r($fullPath, $dirPermissions, $filePermissions); |
|
| 33 | + if ($res = @chmod($fullPath, $dirPermissions)) { |
|
| 34 | + $res = @chmod_r($fullPath, $dirPermissions, $filePermissions); |
|
| 35 | + } |
|
| 34 | 36 | } else { |
| 35 | 37 | $res = chmod($fullPath, $filePermissions); |
| 36 | 38 | } |
@@ -40,8 +42,9 @@ discard block |
||
| 40 | 42 | } |
| 41 | 43 | } |
| 42 | 44 | closedir($dp); |
| 43 | - if (is_dir($dir) && $res) |
|
| 44 | - $res = @chmod($dir, $dirPermissions); |
|
| 45 | + if (is_dir($dir) && $res) { |
|
| 46 | + $res = @chmod($dir, $dirPermissions); |
|
| 47 | + } |
|
| 45 | 48 | |
| 46 | 49 | return $res; |
| 47 | 50 | } |
@@ -995,10 +998,12 @@ discard block |
||
| 995 | 998 | if (strtoupper(substr(PHP_OS, 0, 3)) != 'WIN') { |
| 996 | 999 | // Change directory permissions |
| 997 | 1000 | $result = chmod_r($_SESSION['abspath'], 0770, 0740); |
| 998 | - if ($result ) |
|
| 999 | - $result = chmod_r($_SESSION['abspath'].'/files', 0770, 0770); |
|
| 1000 | - if ($result) |
|
| 1001 | - $result = chmod_r($_SESSION['abspath'].'/upload', 0770, 0770); |
|
| 1001 | + if ($result ) { |
|
| 1002 | + $result = chmod_r($_SESSION['abspath'].'/files', 0770, 0770); |
|
| 1003 | + } |
|
| 1004 | + if ($result) { |
|
| 1005 | + $result = chmod_r($_SESSION['abspath'].'/upload', 0770, 0770); |
|
| 1006 | + } |
|
| 1002 | 1007 | } |
| 1003 | 1008 | |
| 1004 | 1009 | if ($result === false) { |
@@ -89,9 +89,12 @@ |
||
| 89 | 89 | AND table_name = '$tablename'" |
| 90 | 90 | ); |
| 91 | 91 | |
| 92 | - if ($res > 0) return true; |
|
| 93 | - else return false; |
|
| 94 | -} |
|
| 92 | + if ($res > 0) { |
|
| 93 | + return true; |
|
| 94 | + } else { |
|
| 95 | + return false; |
|
| 96 | + } |
|
| 97 | + } |
|
| 95 | 98 | |
| 96 | 99 | //define pbkdf2 iteration count |
| 97 | 100 | @define('ITCOUNT', '2072'); |
@@ -101,8 +101,12 @@ |
||
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | // temp data |
| 104 | - if (!isset($record['login'])) $record['login'] = ""; |
|
| 105 | - if (!isset($resNT['renewal_period'])) $resNT['renewal_period'] = "0"; |
|
| 104 | + if (!isset($record['login'])) { |
|
| 105 | + $record['login'] = ""; |
|
| 106 | + } |
|
| 107 | + if (!isset($resNT['renewal_period'])) { |
|
| 108 | + $resNT['renewal_period'] = "0"; |
|
| 109 | + } |
|
| 106 | 110 | |
| 107 | 111 | // store data |
| 108 | 112 | $res = mysqli_query($dbTmp, |
@@ -83,16 +83,27 @@ |
||
| 83 | 83 | AND table_name = '$tablename'" |
| 84 | 84 | ); |
| 85 | 85 | |
| 86 | - if ($res > 0) return true; |
|
| 87 | - else return false; |
|
| 88 | -} |
|
| 86 | + if ($res > 0) { |
|
| 87 | + return true; |
|
| 88 | + } else { |
|
| 89 | + return false; |
|
| 90 | + } |
|
| 91 | + } |
|
| 89 | 92 | |
| 90 | 93 | function cleanFields($txt) { |
| 91 | 94 | $tmp = str_replace(",", ";", trim($txt)); |
| 92 | - if (empty($tmp)) return $tmp; |
|
| 93 | - if ($tmp === ";") return ""; |
|
| 94 | - if (strpos($tmp, ';') === 0) $tmp = substr($tmp, 1); |
|
| 95 | - if (substr($tmp, -1) !== ";") $tmp = $tmp.";"; |
|
| 95 | + if (empty($tmp)) { |
|
| 96 | + return $tmp; |
|
| 97 | + } |
|
| 98 | + if ($tmp === ";") { |
|
| 99 | + return ""; |
|
| 100 | + } |
|
| 101 | + if (strpos($tmp, ';') === 0) { |
|
| 102 | + $tmp = substr($tmp, 1); |
|
| 103 | + } |
|
| 104 | + if (substr($tmp, -1) !== ";") { |
|
| 105 | + $tmp = $tmp.";"; |
|
| 106 | + } |
|
| 96 | 107 | return $tmp; |
| 97 | 108 | } |
| 98 | 109 | |
@@ -2,7 +2,7 @@ |
||
| 2 | 2 | //DUTCH |
| 3 | 3 | if (!isset($_SESSION['settings']['cpassman_url'])) { |
| 4 | 4 | $TeamPass_url = ''; |
| 5 | -}else{ |
|
| 5 | +} else{ |
|
| 6 | 6 | $TeamPass_url = $_SESSION['settings']['cpassman_url']; |
| 7 | 7 | } |
| 8 | 8 | |
@@ -2,7 +2,7 @@ |
||
| 2 | 2 | //CHINESE |
| 3 | 3 | if (!isset($_SESSION['settings']['cpassman_url'])) { |
| 4 | 4 | $TeamPass_url = ''; |
| 5 | -}else{ |
|
| 5 | +} else{ |
|
| 6 | 6 | $TeamPass_url = $_SESSION['settings']['cpassman_url']; |
| 7 | 7 | } |
| 8 | 8 | |