- Started WIP on firewall
This commit is contained in:
		
							parent
							
								
									55f5071475
								
							
						
					
					
						commit
						fd51903a8a
					
				@ -26,6 +26,7 @@ class Console {
 | 
				
			|||||||
        new FormHandler($request, $git = new Form\Update\Git(getenv('PROJECT_PATH')));
 | 
					        new FormHandler($request, $git = new Form\Update\Git(getenv('PROJECT_PATH')));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $status = iterator_to_array($git->run("/usr/bin/git status -s"));
 | 
					        $status = iterator_to_array($git->run("/usr/bin/git status -s"));
 | 
				
			||||||
 | 
					        $diff = iterator_to_array($git->run("/usr/bin/git diff"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return $this->renderView("lean-console/page/update/index", get_defined_vars());
 | 
					        return $this->renderView("lean-console/page/update/index", get_defined_vars());
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										31
									
								
								src/Entity/Firewall/BannedIp.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								src/Entity/Firewall/BannedIp.php
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,31 @@
 | 
				
			|||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace Lean\Console\Entity\Firewall;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use Ulmus\Attribute\Obj\Table;
 | 
				
			||||||
 | 
					use Ulmus\Attribute\Property\Field;
 | 
				
			||||||
 | 
					use Ulmus\Entity\Field\Datetime;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#[Table(name:"firewall_banned_ips", adapter: "lean.console")]
 | 
				
			||||||
 | 
					class BannedIp implements \JsonSerializable
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    use \Ulmus\EntityTrait;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    #[Field\Id]
 | 
				
			||||||
 | 
					    public string $id;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    #[Field\ForeignKey(name: "connection_id")]
 | 
				
			||||||
 | 
					    public ? int $connectionId;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    #[Field(length: 12)]
 | 
				
			||||||
 | 
					    public ? string $ipv4;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    #[Field(length: 40)]
 | 
				
			||||||
 | 
					    public ? string $ipv6;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    #[Field\Datetime(name: "banned_until")]
 | 
				
			||||||
 | 
					    public Datetime $bannedUntil;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    #[Field\Datetime(name: "created_at")]
 | 
				
			||||||
 | 
					    public Datetime $createdAt;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -15,17 +15,17 @@ class Connection implements \JsonSerializable
 | 
				
			|||||||
    public string $id;
 | 
					    public string $id;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    #[Field(length: 12)]
 | 
					    #[Field(length: 12)]
 | 
				
			||||||
    public string $ipv4;
 | 
					    public ? string $ipv4;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    #[Field(length: 40)]
 | 
					    #[Field(length: 40)]
 | 
				
			||||||
    public string $ipv6;
 | 
					    public ? string $ipv6;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    #[Field]
 | 
					    #[Field]
 | 
				
			||||||
    public bool $success;
 | 
					    public bool $success;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    #[Field(length: 255)]
 | 
					    #[Field(length: 255, name: "error_message")]
 | 
				
			||||||
    public ? string $errorMessage;
 | 
					    public ? string $errorMessage;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    #[Field\Datetime]
 | 
					    #[Field\Datetime(name: "created_at")]
 | 
				
			||||||
    public Datetime $createdAt;
 | 
					    public Datetime $createdAt;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -73,7 +73,7 @@ class DatabaseMigration implements FormInterface
 | 
				
			|||||||
                if ( $alter->count() ) {
 | 
					                if ( $alter->count() ) {
 | 
				
			||||||
                    if ( $adapter->splitAlterQuery() ) {
 | 
					                    if ( $adapter->splitAlterQuery() ) {
 | 
				
			||||||
                        $query = $alter->map(fn(Lib\Database\Definition $map) => $entity::repository()
 | 
					                        $query = $alter->map(fn(Lib\Database\Definition $map) => $entity::repository()
 | 
				
			||||||
                            ->alterSqlQuery([$map->toArray()])
 | 
					                            ->alterSqlQuery([ $map->toArray() ])
 | 
				
			||||||
                            ->getSqlQuery(true));
 | 
					                            ->getSqlQuery(true));
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                    else {
 | 
					                    else {
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										27
									
								
								src/Middleware/FirewallMiddleware.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								src/Middleware/FirewallMiddleware.php
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,27 @@
 | 
				
			|||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace Ulmus\User\Middleware;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use Psr\Http\{
 | 
				
			||||||
 | 
					    Message\ResponseInterface,
 | 
				
			||||||
 | 
					    Message\ServerRequestInterface,
 | 
				
			||||||
 | 
					    Server\MiddlewareInterface,
 | 
				
			||||||
 | 
					    Server\RequestHandlerInterface
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					use Ulmus\User\Entity\UserInterface;
 | 
				
			||||||
 | 
					use Ulmus\User\Authorize\HeaderAuthentication;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class HeaderAuthenticationMiddleware implements MiddlewareInterface
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    protected HeaderAuthentication $authenticator;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function __construct() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return $handler->handle($request);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -12,4 +12,15 @@
 | 
				
			|||||||
    <section>
 | 
					    <section>
 | 
				
			||||||
        <article>Welcome into your Lean Console section. Select the appropriate menu item from the sidebar.</article>
 | 
					        <article>Welcome into your Lean Console section. Select the appropriate menu item from the sidebar.</article>
 | 
				
			||||||
    </section>
 | 
					    </section>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <section style="margin-top:1rem;">
 | 
				
			||||||
 | 
					        <article>
 | 
				
			||||||
 | 
					            <div>Firewall</div>
 | 
				
			||||||
 | 
					            <br>
 | 
				
			||||||
 | 
					            <b>@todo</b>
 | 
				
			||||||
 | 
					            <u>latest 50 connections</u>
 | 
				
			||||||
 | 
					            <u>banned users / IP !</u>
 | 
				
			||||||
 | 
					            <u>fail2ban integration</u>
 | 
				
			||||||
 | 
					        </article>
 | 
				
			||||||
 | 
					    </section>
 | 
				
			||||||
{% endsection %}
 | 
					{% endsection %}
 | 
				
			||||||
@ -20,6 +20,20 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
                <code style="white-space:normal;font-size:120%">
 | 
					                <code style="white-space:normal;font-size:120%">
 | 
				
			||||||
                    {% foreach $status as $line %}
 | 
					                    {% foreach $status as $line %}
 | 
				
			||||||
 | 
					                    <div>
 | 
				
			||||||
 | 
					                        {% if $line %}
 | 
				
			||||||
 | 
					                        {{ $line }}
 | 
				
			||||||
 | 
					                        {% endif %}
 | 
				
			||||||
 | 
					                    </div>
 | 
				
			||||||
 | 
					                    {% endforeach %}
 | 
				
			||||||
 | 
					                </code>
 | 
				
			||||||
 | 
					            </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            <div class="git-diff" style="margin-top:2rem">
 | 
				
			||||||
 | 
					                <strong style="display:block;margin-bottom:7px">'git diff' output</strong>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                <code style="white-space:normal;font-size:120%">
 | 
				
			||||||
 | 
					                    {% foreach $diff as $line %}
 | 
				
			||||||
                        <div>
 | 
					                        <div>
 | 
				
			||||||
                            {% if $line %}
 | 
					                            {% if $line %}
 | 
				
			||||||
                                {{ $line }}
 | 
					                                {{ $line }}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user