[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cobalt-developers] Need Help with Code to add User Email accounts



I have a program that works under redhat 6.2 just fine, But will not create
the mail accounts under cobalt, Can anyone tell me why not ? or how to fix
it ?

Thanks


----------------------------------Code  PHP
-------------------------------------------------------

// Functions for insert/update/delete users from the system
    $cfg_passwd=array();
    $cfg_shadow=array();
    function GetUsersInfo(){
        global $cfg_passwd, $cfg_shadow;
        // Backup old files
        function Backup($filename, $content){
            $fp=@fopen($filename, "w");
            @fwrite($fp, $content);
            @fclose($fp);
        }
        // Internal function for reading file
        function GetFile($filename){
            $fp=@fopen($filename, "r");
            $content=@fread($fp, @filesize($filename));
            $result=split("\n", $content);
            @fclose($fp);
            Backup("$filename.backup.cron", $content);
            return $result;
        }
        // Get "/etc/passwd" file
        $cfg_passwd=GetFile("/etc/passwd");
        // Get "/etc/shadow" file
        $cfg_shadow=GetFile("/etc/shadow");
    }
    function PutUsersInfo(){
        global $cfg_passwd, $cfg_shadow;
        // Internal function for writing file
        function PutFile($filename, $args){
            $fp=@fopen($filename, "w");
            foreach($args as $value)if(trim($value))@fwrite($fp,
"$value\n");
            @fclose($fp);
        }
        // Put "/etc/passwd" file
        PutFile("/etc/passwd", $cfg_passwd);
        // Put "/etc/shadow" file
        PutFile("/etc/shadow", $cfg_shadow);
    }
    function InsertUser($userid, $username, $password){
        global $cfg_passwd, $cfg_shadow;
        $ugid=50000+$userid;
        @array_push($cfg_passwd,
"$username:x:$ugid:$ugid::/home:/bin/date");
        $pswd=@crypt($password);
        $days=11962; /////////////////// !!!!!!!!!!!!!! TEMP !!!!!!!!!!!!!!
        @array_push($cfg_shadow, "$username:$pswd:$days:0:99999:7:::");
    }
    function UpdateUser($userid, $username){
        global $cfg_passwd, $cfg_shadow;
        $ugid=50000+$userid;
        for($i=0;$i<=sizeof($cfg_passwd);$i++){
            $line=split(":", $cfg_passwd[$i]);
            if($line[2]==$ugid){
                $tmp_username=$line[0];
                $cfg_passwd[$i]="$username:x:$ugid:$ugid::/home:/bin/date";
                break;
            }
        }
        if(empty($tmp_username))return;
        for($i=0;$i<=sizeof($cfg_shadow);$i++){
            $line=split(":", $cfg_shadow[$i]);
            if($line[0]==$tmp_username){
                $pswd=$line[1];
                $days=$line[2];
                $cfg_shadow[$i]="$username:$pswd:$days:0:99999:7:::";
                break;
            }
        }
    }
-------------------------------------------------------end PHP Code
----------------------------------------------------------------------------
--