Php batch modify windows directory permission program

Source: Internet
Author: User
The code is as follows: Copy code

<? Php
// Obtain the file directory list. This method returns an array.
Function getDir ($ dir = "){
$ Dir = empty ($ dir )? Getcwd (): $ dir;
$ DirArray [] = NULL;
If (false! = ($ Handle = opendir ($ dir ))){
$ I = 0;
While (false! ==( $ File = readdir ($ handle ))){
// Remove ".", "..", and files with the suffix ". xxx"
If ($ file! = "." & $ File! = "..." &! Strpos ($ file ,".")){
$ DirArray [$ I] = $ file;
$ I ++;
            }
        }
// Close the handle
Closedir ($ handle );
    }
Return $ dirArray;
}
?>
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/5o/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = utf-8 & Prime;/>
<Title> batch set directory permissions </title>
<Style>
Body {
Font: 12px/22px "Microsoft YaHei", SimSun;
}
Input, select, texteare, button {
Font-family: "Microsoft YaHei", SimSun;
}
</Style>
</Head>
<Body>
<? Php
If (empty ($ _ POST )){
?>
<Form action = "" method = "post" onsubmit = "return check ();">
<H2> Current Directory: <? Php echo getcwd ();?> </H2>
<Div>
<Fieldset>
<Legend> website directory </legend>
<Div>
<Ul>
<? Php
$ DirArr = getDir ();
If (is_array ($ dirArr )){
Foreach ($ dirArr as $ dir ){
?>
<Li>
<Label>
<Input name = "directory []" type = "checkbox" value = "<? Php echo $ dir;?>" />
<? Php echo $ dir;?> </Label>
</Li>
<? Php
          }
      }
?>
</Ul>
<Div>
<Input id = "CheckALL" type = "button" onclick = "checkAll ();" value = "select all"/>
<Input id = "NoCheckAll" type = "button" onclick = "noCheckAll ();" value = "none"/>
<Input id = "inverse" type = "button" onclick = "inverseCheck ()" value = "reselect"/>
</Div>
</Div>
</Fieldset>
</Div>
<Div>
<Fieldset>
<Legend> directory permission </legend>
<Div>
<Select name = "Perm">
<Option value = "N" selected = "selected"> N-none </option>
<Option value = "R"> R-read </option>
<Option value = "W"> W-write </option>
<Option value = "C"> C-Change (write) </option>
<Option value = "F"> F-full control </option>
</Select>
<! -
/G user: perm grants the specified user access permission.
Perm can be: R read
W write
C change (write)
F full control

/P user: perm replaces the access permission of the specified user.
Perm can be: N None
R read
W write
C change (write)
F full control
->
</Div>
</Fieldset>
</Div>
<Div>
<Fieldset>
<Legend> guest account </legend>
<Div>
Internet guest account: <input name = "User" id = "User" type = "text" value = ""/>
</Div>
</Fieldset>
</Div>
<Div style = "margin-top: 20px; padding-left: 20px;">
<Input type = "submit" value = "submit"/>
</Div>
</Form>
<Script type = "text/javascript">
Var all = document. getElementById ("CheckALL"); // Select all
Var single = document. getElementsByName ("directory []"); // option
Var noAll = document. getElementById ("NoCheckAll"); // not all
Var inverse = document. getElementById ("inverse"); // reselect
Var User = document. getElementById ("User"); // SiteId
Function checkTrue (){
For (var I = 0; I <single. length; I ++ ){
Single [I]. checked = true;
        }
    }
Function checkFalse (){
For (var I = 0; I <single. length; I ++ ){
Single [I]. checked = false;
        }
    }
// Select All
Function checkAll (){
If (all. disabled = false ){
NoAll. disabled = false;
CheckTrue ();
        }
Else {
NoAll. disabled = true;
CheckFalse ();
        }
All. disabled = true;
    }
// None
Function noCheckAll (){
If (noAll. disabled = false ){
All. disabled = false;
CheckFalse ();
        }
Else {
All. checked = true;
CheckTrue ();
        }
NoAll. disabled = true;
    }
// Invert selection
Function inverseCheck (){
NoAll. disabled = false;
All. disabled = false;
For (var I = 0; I <single. length; I ++ ){
Single [I]. checked =! Single [I]. checked;
        }
    }
Function check (){
Var checkd_sum;
Checkd_sum = 0;
For (var I = 0; I <single. length; I ++ ){
If (single [I]. checked = true ){
Checkd_sum ++;
            }
        }
If (checkd_sum = 0 ){
Alert ('select the directory first! ');
Return false;
        }
If (User. value = ""){
Alert ('Enter an Internet guest account! ');
Return false;
        }
Return true;
    }
</Script>
<? Php
} Else {
$ Directorys = @ $ _ POST ['Directory'];
$ Perm = trim (@ $ _ POST ['perm']);
$ User = trim (@ $ _ POST ['user']);
?>
<Div>
<Pre>
@ Echo off
<? Php
$ BASE_DIR = getcwd ();
If (is_array ($ directorys )){
Foreach ($ directorys as $ directory ){
Echo <EOF
Echo Y | cacls {$ BASE_DIR }\{$ directory}/T/E/C/G {$ User }:{$ Perm} <br/>
EOF;
    }
}
?>
Pause
</Pre>
</Div>
<? Php
}
?>
</Body>
</Html>

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

11.11 Big Sale for Cloud

Get Unbeatable Offers with up to 90% Off,Oct.24-Nov.13 (UTC+8)

Get It Now >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.