Subversion-Projekte lars-tiefland.content-management

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
 
3
    /**
4
     * @package   Kein Projekt geladen
5
     * @author    Lars Tiefland <tiefland@weban.de>
6
     * @copyright 2010 Webagentur Niewerth
7
     * @license   propietary http://www.weban.de
8
     * @version   $Rev: 3931 $
9
     * @filesource
10
     *
11
     */
12
 
13
    /**
14
     *  Verwaltet Benutzer für Linux Domain buero.weban.de
15
     *
16
     * @package   Kein Projekt geladen
17
     * @author    Lars Tiefland <tiefland@weban.de>
18
     * @copyright 2010 Webagentur Niewerth
19
     */
20
 
21
    // SVN: $Id: samba.php 3931 2011-09-16 08:17:57Z tiefland $
22
 
23
    require_once  "PEAR5.php";
24
    require_once  "File/Passwd/Unix.php";
25
    require_once  "common.php";
26
 
27
    $shells = file_get_contents( "/etc/shells" );
28
    $shells = explode( "\n", $shells );
29
    unset( $shells[0], $shells[count( $shells )] );
30
    $shells[] = "/bin/false";
31
 
32
    if ( !empty( $_GET["action"] ) )
33
    {
34
        $action = $_GET["action"];
35
    } elseif ( !empty( $_POST["action"] ) )
36
    {
37
        $action = $_POST["action"];
38
    }
39
 
40
    if ( $_POST["action"] == "edit" || $_POST["action"] == "new" )
41
    {
42
        $gid = $_POST["gid"];
43
        $gecos = $_POST["gecos"];
44
        $shell = $_POST["shell"];
45
        $home = $_POST["home"];
46
        $old_gid = $_POST["old_gid"];
47
        $old_gecos = $_POST["old_gecos"];
48
        $old_shell = $_POST["old_shell"];
49
        $old_home = $_POST["old_home"];
50
        $name = $_POST["name"];
51
 
52
        if ( $_POST["action"] == "new" )
53
        {
54
            $smb_params[] = "-a";
55
        }
56
        if ( $_POST["action"] == "edit" && $_POST["old_gid"] != $_POST["gid"] )
57
        {
58
            $params[] = "-g $gid";
59
        }
60
        if ( $old_gecos != $gecos )
61
        {
62
            $params[] = "-c '$gecos'";
63
        }
64
        if ( $old_home != $home )
65
        {
66
            $params[] = "-d '$home' -m";
67
        }
68
        if ( $old_shell != $shell )
69
        {
70
            $params[] = "-s '$shell'";
71
        }
72
        if ( !empty( $_POST["passwd"] ) && $_POST["passwd"] == $_POST["passwd_confirm"] )
73
        {
74
            $params[] = "-p '" . addslashes( crypt( $_POST["passwd"] ) ) .
75
                "'";
76
            if ( $name[strlen( $name ) - 1] != "$" )
77
            {
78
                $smb_params[] = "-s";
79
                $smb_params[] = $name;
80
                $smb_params[] = "<<EOM\n" . $_POST["passwd"] . "\n" . $_POST["passwd"] .
81
                    "\nEOM\n";
82
            }
83
            else
84
            {
85
                $smb_name = substr( $name, 0, strlen( $name ) - 1 );
86
                $smb_params[] = "-m $smb_name";
87
            }
88
        }
89
        else
90
        {
91
            if ( $name[strlen( $name ) - 1] != "$" )
92
            {
93
                $smb_params[] = "-s";
94
                $smb_params[] = $name;
95
                $smb_params[] = "<<EOM\n" . $_POST["passwd"] . "\n" . $_POST["passwd"] .
96
                    "\nEOM\n";
97
            }
98
            else
99
            {
100
                $smb_name = substr( $name, 0, strlen( $name ) - 1 );
101
                $smb_params[] = "-m $smb_name";
102
            }
103
        }
104
        if ( isset( $_POST["status"] ) )
105
        {
106
            switch ( $_POST["status"] )
107
            {
108
                case "lock":
109
                    $params[] = "-L";
110
                    $smb_params[] = "-d";
111
                    break;
112
                case "unlock":
113
                    $params[] = "-U";
114
                    $smb_params[] = "-e";
115
                    break;
116
            }
117
        }
118
        if ( isset( $_POST["gid"] ) )
119
        {
120
 
121
        }
122
        if ( $_POST["action"] == "edit" )
123
        {
124
            $prog = "usermod";
125
        } elseif ( $_POST["action"] == "new" )
126
        {
127
            $prog = "useradd";
128
            $smb_params[] = "-a";
129
        }
130
        //Programm moduser ausführen, um Benutzer zu ändern
131
        if ( is_array( $params ) )
132
        {
133
            $cmd = "sudo $prog " . implode( " ", $params ) . " $name\n";
134
            exec( $cmd, $ret, $code );
135
            //echo $cmd;
136
            unset( $ret );
137
        }
138
        if ( is_array( $smb_params ) && $_POST["action"] != "delete" )
139
        {
140
            $cmd = "sudo smbpasswd " . implode( " ", $smb_params );
141
            echo $cmd;
142
            exec( $cmd, $ret, $code );
143
            unset( $ret );
144
        }
145
        $action = "";
146
    } elseif ( $_POST["action"] == "delete" )
147
    {
148
        foreach ( $_POST["del"] as $user => $val )
149
        {
150
            $cmd = "sudo smpasswd -x $user";
151
            exec( $cmd, $ret, $code );
152
            unset( $ret );
153
            $cmd = "sudo userdel $user -r";
154
            exec( $cmd, $ret, $code );
155
            unset( $ret );
156
        }
157
    }
158
 
159
    $passwd = new File_Passwd_Unix( "/etc/passwd" );
160
    $passwd_out = $passwd->load();
161
    $users = $passwd->_users;
162
    ksort( $users );
163
 
164
    $g_cont = file( "/etc/group" );
165
    foreach ( $g_cont as $row )
166
    {
167
        $g_infos = explode( ":", $row );
168
        $groups[$g_infos[2]] = $g_infos[0];
169
    }
170
 
171
    $s_cont = file( "/etc/shadow" );
172
    foreach ( $s_cont as $row )
173
    {
174
        $s_infos = explode( ":", $row );
175
        $shadow[$s_infos[0]]["gesperrt"] = ( $s_infos[1][0] == "!" );
176
    }
177
 
178
    $GLOBALS["ui"]->assign( "webs", $webs );
179
    $GLOBALS["ui"]->assign( "users", $users );
180
    $GLOBALS["ui"]->assign( "groups", $groups );
181
    $GLOBALS["ui"]->assign( "shadow", $shadow );
182
    $GLOBALS["ui"]->assign( "action", $action );
183
    $GLOBALS["ui"]->assign( "shells", $shells );
184
    $GLOBALS["ui"]->display( "samba/page.tpl" );
185
?>