LEPTON CMS 7.2.0
feel free to keep it strictly simple...
Loading...
Searching...
No Matches
function.extract_permission.php
Go to the documentation of this file.
1<?php
2
18// include secure.php to protect this file and the whole CMS!
19if(!defined("SEC_FILE")){define("SEC_FILE",'/framework/secure.php' );}
20if (defined('LEPTON_PATH')) {
21 include LEPTON_PATH.SEC_FILE;
22} else {
23 $oneback = "../";
24 $root = $oneback;
25 $level = 1;
26 while (($level < 10) && (!file_exists($root.SEC_FILE))) {
27 $root .= $oneback;
28 $level += 1;
29 }
30 if (file_exists($root.SEC_FILE)) {
31 include $root.SEC_FILE;
32 } else {
33 trigger_error(sprintf("[ <b>%s</b> ] Can't include secure.php!", $_SERVER['SCRIPT_NAME']), E_USER_ERROR);
34 }
35}
36// end include secure file
37
38
39/*
40 * Function to work-out a single part of an octal permission value
41 *
42 * @param mixed $octal_value: an octal value as string (i.e. '0777') or real octal integer (i.e. 0777 | 777)
43 * @param string $who: char or string for whom the permission is asked( U[ser] / G[roup] / O[thers] )
44 * @param string $action: char or string with the requested action( r[ead..] / w[rite..] / e|x[ecute..] )
45 * @return boolean
46 */
47function extract_permission( $octal_value, $who, $action )
48{
49 // @DEPRECATED_TEMP 20240415, seems this function is not used anywhere
50 echo LEPTON_tools::display_dev("Where is this one used?", "pre", "ui message red");
51
52 // Make sure that all arguments are set and $octal_value is a real octal-integer
53 if ( ( $who == '' ) || ( $action == '' ) || ( preg_match( '/[^0-7]/', (string) $octal_value ) ) )
54 {
55 // invalid argument, so return false
56 return false;
57 }
58 // convert into a decimal-integer to be sure having a valid value
59 $right_mask = octdec( $octal_value );
60 switch ( strtolower( $action[ 0 ] ) )
61 {
62 // get action from first char of $action, set the $action related bit in $action_mask
63 case 'r':
64 // set read-bit only (2^2)
65 $action_mask = 4;
66 break;
67 case 'w':
68 // set write-bit only (2^1)
69 $action_mask = 2;
70 break;
71 case 'e':
72 case 'x':
73 // set execute-bit only (2^0)
74 $action_mask = 1;
75 break;
76 default:
77 // undefined action name, so return false
78 return false;
79 }
80 switch ( strtolower( $who[ 0 ] ) )
81 {
82 // get who from first char of $who, shift action-mask into the right position
83 case 'u':
84 // shift left 3 bits
85 $action_mask <<= 3;
86 case 'g':
87 // shift left 3 bits
88 $action_mask <<= 3;
89 case 'o':
90 /* NOP */
91 break;
92 default:
93 // undefined who, so return false
94 return false;
95 }
96 // return result of binary-AND
97 return ( ( $right_mask & $action_mask ) != 0 );
98}
static display_dev(mixed $something_to_display="", string $tag="pre", string|null $css_class=null, bool|null $useVarDump=null)
extract_permission( $octal_value, $who, $action)