Skip to content

Instantly share code, notes, and snippets.

@moabi
Last active September 16, 2015 07:47
Show Gist options
  • Save moabi/04c31b35fa813fb425e9 to your computer and use it in GitHub Desktop.
Save moabi/04c31b35fa813fb425e9 to your computer and use it in GitHub Desktop.
lockdown wordpress rights

Synopsis

At the top of the file there should be a short introduction and/ or overview that explains what the project is. This description should match descriptions added for package managers (Gemspec, package.json, etc.)

Code Example

Show what the library does as concisely as possible, developers should be able to figure out how your project solves their problem by looking at the code example. Make sure the API you are showing off is obvious, and that your code is short and concise.

Motivation

A short description of the motivation behind the creation and maintenance of the project. This should explain why the project exists.

Installation

Provide code examples and explanations of how to get the project.

API Reference

Depending on the size of the project, if it is small and simple enough the reference docs can be added to the README. For medium size to larger projects it is important to at least provide a link to where the API reference docs live.

Tests

Describe and show how to run the tests with code examples.

Contributors

Let people know how they can dive into the project, include important links to things like issue trackers, irc, twitter accounts if applicable.

License

A short snippet describing the license (MIT, Apache, etc.)

<?php
/**
*
* Description : lockdown wordpress rights
* version 1.0
*
*/
$mode = '';
$path_rights = array(
array(
'name' => 'php wordpress root',
'path' => './*.php',
'option' => '',
'lock' => '400',
'unlock' => '600',
),
array(
'name' => 'php wordpress admin, include',
'path' => './wp-admin/ ./wp-includes/',//
'option' => '-R',
'lock' => '555',//500 for production
'unlock' => '755',//700
),
array(
'name' => 'php wordpress admin, include',
'path' => './wp-admin/*.php ./wp-includes/*.php',//
'option' => '-R',
'lock' => '400',
'unlock' => '600',
),
array(
'name' => 'php wordpress wp-content',
'path' => './wp-content/ ',//
'option' => '',
'lock' => '555', // 500
'unlock' => '755', // 700
),
array(
'name' => 'php wordpress wp-content',
'path' => './wp-content/uploads ',//
'option' => '',
'lock' => '755', // 700
'unlock' => '755', // 700
),
);
if (!testOpt())
exit();
$res = executeCmd('whoami ');
if( $res != 'root'){
msg('knon user !');
exit();
}
msg('mode ' .$mode."\n");
foreach ( $path_rights as $rights ){
msg('Process ' . $rights['name']);
$mod = $rights[$mode];
$file = $rights['path'];
$option = $rights['option'];
$cmd = 'chmod ' .$option .' ' . $mod . ' ' . $file;
$res = executeCmd($cmd);
if ($res){
msg( '--' . $cmd . '--');
msg($res);
}
}
/**
*
* F U N C T I O N S
*
*/
function executeCmd($cmd){
msg("Execution de \n " . $cmd);
exec( $cmd, $res, $return );
$resCmd = join("\r", $res);
if ( $return ){
msg("return : $return");## return 0 = ok
throw new Exception("failed execute " . $cmd);
}
return $resCmd;
}
function msg($msg){
echo $msg . "\n";
}
/**
*
* @global type $mode
* @return boolean
*/
function testOpt(){
global $mode;
$opt = getopt('LUhH');
if ( isset( $opt['L']) && isset( $opt['U']) )
usage();
if ( isset( $opt['L']) ) {
$mode = 'lock';
return true;
}
if ( isset( $opt['U']) ) {
$mode = 'unlock';
return true;
}
//var_dump($opt);exit();
if ( isset( $opt['h']) || isset($opt['H']) )
usage();
if ( $mode != 'lock' && $mode != 'unlock')
usage ();
}
/**
* affiche l'aide pour l'usage de ce script
*/
function usage($msg =''){
/*
if (IS_WEB){
echo <<<EOF
<div>
usage php maj_eventRules.php?[I=NOM_INTANCE]|[L=yes]<br/>
-H, -h cet écran<br/>
</div>
EOF;
}else{
*/
$myname = basename(__FILE__);
$usage = <<<EOF
usage php $myname -[L/U]
-L verouillage des fichiers dossiers de worPress
-U déverouillage des fichier pour permettre la maj
-H, -h cet écran
EOF;
if ($msg)
msg($msg);
msg($usage);
exit;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment