Php batch set IIS Directory instance code

Source: Internet
Author: User
Tags foreach iis
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/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = utf-8"/>
<Title> batch setting of IIS directories </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 = "invert"/>
</Div>
</Div>
</Fieldset>
</Div>
<Div>
<Fieldset>
<Legend> execution permission </legend>
<Div>
<Select name = "Execute" onchange = "Warning (this. value)">
<Option value = "0" selected = "selected"> none </option>
<Option value = "1"> pure script </option>
<Option value = "2"> script and executable </option>
</Select>
</Div>
</Fieldset>
</Div>
<Div>
<Fieldset>
<Legend> Site Information </legend>
<Div>
Site ID: <input name = "SiteId" id = "SiteId" 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 SiteId = document. getElementById ("SiteId"); // 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 Warning (value ){
If (value = 2 ){
Alert ('directory has "script and executable" permissions, which can be very dangerous. Please choose carefully! ')
        }
    }
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 (SiteId. value = ""){
Alert ('Enter the site ID! ');
Return false;
        }
Return true;
    }
</Script>
<? Php
} Else {
$ Directorys = @ $ _ POST ['Directory'];
$ Execute = @ $ _ POST ['execute '];
$ SiteId = @ $ _ POST ['siteid'];
$ SiteId = trim ($ SiteId );
If ($ Execute = 0 ){
$ ExecutePermission = "AccessRead ";
    }
If ($ Execute = 1 ){
$ ExecutePermission = "AccessRead | AccessScript ";
    }
If ($ Execute = 1 ){
$ ExecutePermission = "AccessExecute | AccessRead | AccessScript ";
    }
?>
<Div>
<Pre>
<? Php
If (is_array ($ directorys )){
Foreach ($ directorys as $ directory ){
Echo <EOF
& Lt; IIsWebDirectory Location = "/LM/W3SVC/{$ SiteId}/root/{$ directory }"
AccessFlags = "{$ ExecutePermission }"
& Gt;
& Lt;/IIsWebDirectory & gt; rn
EOF;
    }
}
?>
</Pre>
</Div>
<? Php
}
?>
</Body>
</Html>
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

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.