Subversion-Projekte lars-tiefland.content-management

Revision

Blame | Letzte Änderung | Log anzeigen | RSS feed

<?php

    /**
     * @package   Kein Projekt geladen
     * @author    Lars Tiefland <tiefland@weban.de>
     * @copyright 2010 Webagentur Niewerth
     * @license   propietary http://www.weban.de
     * @version   $Rev: 3931 $
     * @filesource
     * 
     */

    /**
     *  Verwaltet Benutzer für Linux Domain buero.weban.de
     *  
     * @package   Kein Projekt geladen
     * @author    Lars Tiefland <tiefland@weban.de>
     * @copyright 2010 Webagentur Niewerth
     */

    // SVN: $Id: samba.php 3931 2011-09-16 08:17:57Z tiefland $

    require_once  "PEAR5.php";
    require_once  "File/Passwd/Unix.php";
    require_once  "common.php";

    $shells = file_get_contents( "/etc/shells" );
    $shells = explode( "\n", $shells );
    unset( $shells[0], $shells[count( $shells )] );
    $shells[] = "/bin/false";

    if ( !empty( $_GET["action"] ) )
    {
        $action = $_GET["action"];
    } elseif ( !empty( $_POST["action"] ) )
    {
        $action = $_POST["action"];
    }

    if ( $_POST["action"] == "edit" || $_POST["action"] == "new" )
    {
        $gid = $_POST["gid"];
        $gecos = $_POST["gecos"];
        $shell = $_POST["shell"];
        $home = $_POST["home"];
        $old_gid = $_POST["old_gid"];
        $old_gecos = $_POST["old_gecos"];
        $old_shell = $_POST["old_shell"];
        $old_home = $_POST["old_home"];
        $name = $_POST["name"];

        if ( $_POST["action"] == "new" )
        {
            $smb_params[] = "-a";
        }
        if ( $_POST["action"] == "edit" && $_POST["old_gid"] != $_POST["gid"] )
        {
            $params[] = "-g $gid";
        }
        if ( $old_gecos != $gecos )
        {
            $params[] = "-c '$gecos'";
        }
        if ( $old_home != $home )
        {
            $params[] = "-d '$home' -m";
        }
        if ( $old_shell != $shell )
        {
            $params[] = "-s '$shell'";
        }
        if ( !empty( $_POST["passwd"] ) && $_POST["passwd"] == $_POST["passwd_confirm"] )
        {
            $params[] = "-p '" . addslashes( crypt( $_POST["passwd"] ) ) .
                "'";
            if ( $name[strlen( $name ) - 1] != "$" )
            {
                $smb_params[] = "-s";
                $smb_params[] = $name;
                $smb_params[] = "<<EOM\n" . $_POST["passwd"] . "\n" . $_POST["passwd"] .
                    "\nEOM\n";
            }
            else
            {
                $smb_name = substr( $name, 0, strlen( $name ) - 1 );
                $smb_params[] = "-m $smb_name";
            }
        }
        else
        {
            if ( $name[strlen( $name ) - 1] != "$" )
            {
                $smb_params[] = "-s";
                $smb_params[] = $name;
                $smb_params[] = "<<EOM\n" . $_POST["passwd"] . "\n" . $_POST["passwd"] .
                    "\nEOM\n";
            }
            else
            {
                $smb_name = substr( $name, 0, strlen( $name ) - 1 );
                $smb_params[] = "-m $smb_name";
            }
        }
        if ( isset( $_POST["status"] ) )
        {
            switch ( $_POST["status"] )
            {
                case "lock":
                    $params[] = "-L";
                    $smb_params[] = "-d";
                    break;
                case "unlock":
                    $params[] = "-U";
                    $smb_params[] = "-e";
                    break;
            }
        }
        if ( isset( $_POST["gid"] ) )
        {

        }
        if ( $_POST["action"] == "edit" )
        {
            $prog = "usermod";
        } elseif ( $_POST["action"] == "new" )
        {
            $prog = "useradd";
            $smb_params[] = "-a";
        }
        //Programm moduser ausführen, um Benutzer zu ändern
        if ( is_array( $params ) )
        {
            $cmd = "sudo $prog " . implode( " ", $params ) . " $name\n";
            exec( $cmd, $ret, $code );
            //echo $cmd;
            unset( $ret );
        }
        if ( is_array( $smb_params ) && $_POST["action"] != "delete" )
        {
            $cmd = "sudo smbpasswd " . implode( " ", $smb_params );
            echo $cmd;
            exec( $cmd, $ret, $code );
            unset( $ret );
        }
        $action = "";
    } elseif ( $_POST["action"] == "delete" )
    {
        foreach ( $_POST["del"] as $user => $val )
        {
            $cmd = "sudo smpasswd -x $user";
            exec( $cmd, $ret, $code );
            unset( $ret );
            $cmd = "sudo userdel $user -r";
            exec( $cmd, $ret, $code );
            unset( $ret );
        }
    }

    $passwd = new File_Passwd_Unix( "/etc/passwd" );
    $passwd_out = $passwd->load();
    $users = $passwd->_users;
    ksort( $users );

    $g_cont = file( "/etc/group" );
    foreach ( $g_cont as $row )
    {
        $g_infos = explode( ":", $row );
        $groups[$g_infos[2]] = $g_infos[0];
    }

    $s_cont = file( "/etc/shadow" );
    foreach ( $s_cont as $row )
    {
        $s_infos = explode( ":", $row );
        $shadow[$s_infos[0]]["gesperrt"] = ( $s_infos[1][0] == "!" );
    }

    $GLOBALS["ui"]->assign( "webs", $webs );
    $GLOBALS["ui"]->assign( "users", $users );
    $GLOBALS["ui"]->assign( "groups", $groups );
    $GLOBALS["ui"]->assign( "shadow", $shadow );
    $GLOBALS["ui"]->assign( "action", $action );
    $GLOBALS["ui"]->assign( "shells", $shells );
    $GLOBALS["ui"]->display( "samba/page.tpl" );
?>