php-chmod is a PHP library for easily changing permissions recursively.

Related tags

Security php-chmod
Overview

PHP chmod

Packagist Version Packagist Downloads CI status Contributors Forks Stargazers Issues MIT License

php-chmod is a PHP library for easily changing the permissions recursively.

Versions & Dependencies

Version PHP Documentation
^1.1 ^7.4 current

Requirements

  • PHP >= 7.4
  • php-extension ext-mbstring

Installation

Run composer require MathiasReker/php-chmod

Examples

Dry run:



use MathiasReker\PhpChmod\Scanner;

require __DIR__ . '/vendor/autoload.php';

$result = (new Scanner())
    ->setDefaultFileMode(0644)
    ->setDefaultDirectoryMode(0755)
    ->setExcludedFileModes([0400, 0444, 0640])
    ->setExcludedDirectoryModes([0750])
    ->scan([__DIR__])
    ->dryRun();

var_dump($result); // string[]

Fix:



use MathiasReker\PhpChmod\Scanner;

require __DIR__ . '/vendor/autoload.php';

(new Scanner())
    ->setDefaultFileMode(0644)
    ->setDefaultDirectoryMode(0755)
    ->setExcludedFileModes([0400, 0444, 0640])
    ->setExcludedDirectoryModes([0750])
    ->scan([__DIR__])
    ->fix();

Documentation

$result = new Scanner();

setDefaultFileMode sets the default file permission:

$result->setDefaultFileMode(0644);

setDefaultDirectoryMode sets the default directory permission:

$result->setDefaultDirectoryMode(0755);

setExcludedFileModes sets the allowed permissions for files. Files with these permissions will be skipped:

$result->setExcludedFileModes([0400, 0444, 0640]);

setExcludedDirectoryModes sets the allowed permissions for directories. Directories with these permissions will be skipped:

$result->setExcludedDirectoryModes([0750]);

setExcludedNames exclude files by a custom pattern. Glob and RegEx are supported:

$result->setExcludedNames(['*.rb', '*.py']);

setNames includes files by a custom pattern and exclude any other files. Glob and RegEx are supported:

$result->setNames(['*.php']);

setExcludedPaths excludes a list of file/directory paths:

$result->setExcludedPaths(['first/dir', 'other/dir']);

scan finds all the concerned files/directories:

$result->scan([__DIR__]);

setPaths sets paths of files/directories manually. This is an alternative to the scanner if you want to use a custom scanner:

$result->setPaths($paths);

dryRun returns an array of the concerned files/directories:

$result->dryRun();

fix changes the concerned files/directories permissions to the default permission:

$result->fix();

Roadmap

See the open issues for a complete list of proposed features (and known issues).

Contributing

If you have a suggestion to improve this, please fork the repo and create a pull request. You can also open an issue with the tag "enhancement". Finally, don't forget to give the project a star! Thanks again!

License

It is distributed under the MIT License. See LICENSE for more information.

You might also like...
A library for generating random numbers and strings

RandomLib A library for generating random numbers and strings of various strengths. This library is useful in security contexts. Install Via Composer

Fast, general Elliptic Curve Cryptography library. Supports curves used in Bitcoin, Ethereum and other cryptocurrencies (secp256k1, ed25519, ..)

Fast Elliptic Curve Cryptography in PHP Information This library is a PHP port of elliptic, a great JavaScript ECC library. Supported curve types: Sho

A multitool library offering access to recommended security related libraries, standardised implementations of security defences, and secure implementations of commonly performed tasks.

SecurityMultiTool A multitool library offering access to recommended security related libraries, standardised implementations of security defences, an

A modern, portable, easy to use crypto library.
A modern, portable, easy to use crypto library.

Sodium is a new, easy-to-use software library for encryption, decryption, signatures, password hashing and more. It is a portable, cross-compilable, i

A cryptography API wrapping the Sodium library, providing a simple object interface for symmetrical and asymmetrical encryption, decryption, digital signing and message authentication.

PHP Encryption A cryptography API wrapping the Sodium library, providing a simple object interface for symmetrical and asymmetrical encryption, decryp

PHPIDS (PHP-Intrusion Detection System) is a simple to use, well structured, fast and state-of-the-art security layer for your PHP based web application

PHPIDS PHPIDS (PHP-Intrusion Detection System) is a simple to use, well structured, fast and state-of-the-art security layer for your PHP based web ap

PHP 5.x support for random_bytes() and random_int()

random_compat PHP 5.x polyfill for random_bytes() and random_int() created and maintained by Paragon Initiative Enterprises. Although this library sho

Simple Encryption in PHP.

php-encryption composer require defuse/php-encryption This is a library for encrypting data with a key or password in PHP. It requires PHP 5.6 or new

Standards compliant HTML filter written in PHP

HTML Purifier HTML Purifier is an HTML filtering solution that uses a unique combination of robust whitelists and aggressive parsing to ensure that no

Comments
  • Restructuring objects

    Restructuring objects

    1. Now most classes are called "FilePerm" which is redundant and non-informative in a package with the very same name. kép I do not really know how to come up with the final solution but "top-down programming" - how I call it - is a good starting point: starting with what users have to type to use this package.

    2. The Danish OperativeSystem is OperatingSystem in English.

    3. Iterator is really a trait.

    enhancement 
    opened by szepeviktor 9
  • Viktor here 👋🏻

    Viktor here 👋🏻

    1. https://github.com/MathiasReker/php-file-permissions -> https://github.com/MathiasReker/file-permissions or "php-chmod" or a real name like "file-shepherd"
    2. "MathiasReker\": "src/" we are missing the package name from namespace: it will collide with your other packages ⚡

    That is all for the first glance.

    enhancement 
    opened by szepeviktor 2
Releases(2.1.3)
Owner
Mathias Reker ⚡️
Full-stack web developer. I love IT Security. I believe in sharing knowledge, tools and value open source software development. (He/Him)
Mathias Reker ⚡️
Quickly and easily secure HTML text.

Larasane Quickly sanitize text into safe-HTML using fluid methods. Requirements PHP 7.4, 8.0 or later. Laravel 7.x, 8.x or later. Installation Just fi

Italo 40 Jul 20, 2021
Security provides an infrastructure for sophisticated authorization systems, which makes it possible to easily separate the actual authorization logic from so called user providers that hold the users credentials.

Security provides an infrastructure for sophisticated authorization systems, which makes it possible to easily separate the actual authorization logic from so called user providers that hold the users credentials. It is inspired by the Java Spring framework.

Symfony 1.5k Dec 28, 2022
Easily anonymize sensitive data through eloquent queries

Laravel Encryptable This package allows you to anonymize sensitive data (like the name, surname and email address of a user) similarly to Laravel's En

H-FARM Innovation 93 Sep 6, 2022
PHP Secure Communications Library

phpseclib - PHP Secure Communications Library Supporting phpseclib Become a backer or sponsor on Patreon One-time donation via PayPal or crypto-curren

null 4.9k Jan 7, 2023
TCrypto is a simple and flexible PHP 5.3+ in-memory key-value storage library

About TCrypto is a simple and flexible PHP 5.3+ in-memory key-value storage library. By default, a cookie will be used as a storage backend. TCrypto h

timoh 57 Dec 2, 2022
PHPGGC is a library of PHP unserialize() payloads along with a tool to generate them, from command line or programmatically.

PHPGGC: PHP Generic Gadget Chains PHPGGC is a library of unserialize() payloads along with a tool to generate them, from command line or programmatica

Ambionics Security 2.5k Jan 4, 2023
A petite library of encryption functions for PHP

?? dcrypt A petite library of essential encryption functions for PHP 7.1+. For legacy PHP version support, look here. If you need a dcrypt inspired en

null 96 Oct 6, 2022
Sodium Compat is a pure PHP polyfill for the Sodium cryptography library (libsodium)

Sodium Compat is a pure PHP polyfill for the Sodium cryptography library (libsodium), a core extension in PHP 7.2.0+ and otherwise available in PECL.

Paragon Initiative Enterprises 817 Dec 26, 2022
JSON Object Signing and Encryption library for PHP.

NAMSHI | JOSE Deprecation notice Hi there, as much as we'd like to be able to work on all of the OSS in the world, we don't actively use this library

Namshi 1.7k Dec 22, 2022
A PHP library for counting short DNA sequences for use in Bioinformatics

Helix A PHP library for counting short DNA sequences for use in Bioinformatics. Helix consists of tools for data extraction as well as an ultra-low me

Andrew DalPino 2 Jan 25, 2022