📄 ftpusermanager.java
字号:
package com.gforce.gfoa;
import com.gforce.currency.database.*;
import com.gforce.currency.*;
import java.util.*;
import java.io.*;
/**
* <p>Title: 吉力科技办公自动化系统</p>
* <p>Description: 吉力科技办公自动化系统</p>
* <p>Copyright: 版权所有 2003 (c) 西安吉力科技发展有限公司 Copyright (c) 2003 GForce Sceince & Technology</p>
* <p>Company: 西安吉力科技发展有限公司 (GForce Sceince & Technology)</p>
* @author 马登军
* @version 1.0
*/
public class FTPUserManager
extends RecordManager
{
public FTPUserManager()
{
}
protected final static String TableName = "npUserInfo"; //定义声明本类操作表名称为“UserInfo”
protected final static String IDFieldName = "ID"; //定义声明主键或者可以确定唯一记录的字段名称为“ID”,必须为自增整型
protected final static String[] NumericFieldsName =
{
"Enabled", "QuotaMax"}; //声明数值型字段名称
protected final static String[] StringFieldsName =
{
"UserId", "Pass","HomePath"}; //声明字符型字段名称
protected final static String[] DatetimeFieldsName =
{"CreateDateTime"}; //声明日期时间型字段名称
protected final static String[] TextFieldsName =
{}; //声明大字符串型字段名称
/**
* 根据字段名称获取插入数据时表单元素名称
* @param strFieldName 字段名称
* @return 表单素名称
*/
protected String InsertParament(String strFieldName)
{
return "" + strFieldName + ""; //可以根据需要加前缀、后缀
}
/**
* 根据字段名称获取修改数据时表单元素名称
* @param strFieldName 字段名称
* @return 表单素名称
*/
protected String UpdateParament(String strFieldName)
{
return "" + strFieldName + ""; //可以根据需要加前缀、后缀
}
/**
* 获取本类操作表名称
* @return 表名称
*/
public String getTableName()
{ //获取本类操作表名称
return TableName;
}
protected String getIDFieldName()
{ //获取主键或者可以确定唯一记录的字段名称
return IDFieldName;
}
protected String[] getNumericFieldsName()
{ //获取数值型字段名称
return NumericFieldsName;
}
protected String[] getStringFieldsName()
{ //获取字符型字段名称
return StringFieldsName;
}
protected String[] getDatetimeFieldsName()
{ //获取日期时间型字段名称
return DatetimeFieldsName;
}
protected String[] getTextFieldsName()
{ //获取大字符串型字段名称
return TextFieldsName;
}
/**
* 修改用户密码
* @param strUserName 用户名
* @param strNewPassword 新密码
* @return 错误代码
*/
public static int changeUserPassword(String strUserName, String strNewPassword)
{
return SQLManager.ExcuteSQL("Update " + TableName + " set Pass='" + strNewPassword + "' where UserID='"
+ strUserName + "'");
}
/**
* 获取指定用户的FTP用户名、密码
* @param iUserID 用户ID
* @return 指定用户的FTP用户名、密码
*/
public static Vector getUserFTPData(int iUserID)
{
return SQLManager.GetResultSet("Select UserID,Pass,ServerPort from " + TableName + " where UserID=(Select top 1 UserName from UserInfo where ID=" + iUserID + ")");
}
/**
* 删除指定用户ID的FTP用户及FTP用户目录
* @param iUserID 用户ID
* @return 错误代码
*/
public static int deleteByUserID(int iUserID)
{
Vector vt = getUserFTPData(iUserID);
int iReturnValue=0;
if (vt.size() > 0)
{
String strPersonName = UserManager.getPersonnelNameByUserID(iUserID);
iReturnValue = SQLManager.ExcuteSQL("Delete from npUserComm where GroupID like '%→" + strPersonName + "'");
iReturnValue = SQLManager.ExcuteSQL("Delete from npGroupPath where GroupID like '%→" + strPersonName + "'");
iReturnValue = SQLManager.ExcuteSQL("Delete from npUserPath where UserID='" + ((Vector)vt.get(0)).get(0).toString() + "'");
iReturnValue = SQLManager.ExcuteSQL("Delete from " + TableName + " where UserID='" + ((Vector)vt.get(0)).get(0).toString() + "'");
}
else
{
/**
* 该用户不存在
*/
return -1;
}
return iReturnValue;
}
/**
* 设置指定用户ID的FTP用户是否可用
* @param iUserID 用户ID
* @param iEnabled
* @return 错误代码
*/
public static int setUserEnabled(int iUserID,int iEnabled)
{
Vector vt = getUserFTPData(iUserID);
int iReturnValue=0;
if (vt.size() > 0)
{
iReturnValue = SQLManager.ExcuteSQL("update " + TableName + " set Enabled=" + iEnabled + " where UserID='" + ((Vector)vt.get(0)).get(0).toString() + "'");
}
else
{
/**
* 该用户不存在
*/
return -1;
}
return iReturnValue;
}
/**
* 创建指定用户ID的FTP用户及FTP用户默认目录
* @param iUserID 用户ID
* @return 错误代码
*/
public static int createByUserID(int iUserID)
{
Vector vt = UserManager.getUserInfoByID(iUserID);
String strPersonName = UserManager.getPersonnelNameByUserID(iUserID);
int iReturnValue=0;
if (vt.size() > 0)
{
int iDepartmentID = 0;
try
{
iDepartmentID=Integer.parseInt(((Vector)vt.get(0)).get(5).toString(),10);
}
catch(Exception err){SystemOut.OutPrintLine(err.toString());}
String strDepartmentPath = DepartmentManager.getDepartFullName(iDepartmentID).replaceAll("→","\\\\");
if(strDepartmentPath.length()>0)strDepartmentPath = "\\" + strDepartmentPath;
String strPersonFullPath = strDepartmentPath + "\\" + strPersonName;
makeDirs(SystemParament.getParament("ftpomepath") + strPersonFullPath);
iReturnValue = SQLManager.ExcuteSQL("Insert into npUserPath (UserID,UserPath,Permissions) values ('" + ((Vector)vt.get(0)).get(1).toString() + "','" + SystemParament.getParament("ftpomepath") + strPersonFullPath + "','RWAMECDLP')");
String strGroupname = strPersonFullPath.replaceAll("\\\\","→") + "→" + strPersonName;
String strGroupNames = strGroupname;
String strReadOnlyGroupname = "";
String strFullGroupname = "";
iReturnValue = SQLManager.ExcuteSQL("Insert into npGroupPath (GroupID,GroupPath,Permissions) values ('" + strGroupname + "','" + SystemParament.getParament("ftpomepath") + strPersonFullPath + "','RWAMECDLP')");
iReturnValue = SQLManager.ExcuteSQL("Insert into npUserComm (GroupID,HomePath,ServerPort) values ('" + strGroupname + "','" + SystemParament.getParament("ftpomepath") + strPersonFullPath + "',21)");
while(strPersonFullPath.length()>0)
{
strPersonFullPath = strPersonFullPath.substring(0,strPersonFullPath.lastIndexOf("\\"));
makeDirs(SystemParament.getParament("ftpomepath") + strPersonFullPath);
makeDirs(SystemParament.getParament("ftpomepath") + strPersonFullPath + "\\只读共享");
makeDirs(SystemParament.getParament("ftpomepath") + strPersonFullPath + "\\完全共享");
strGroupname = strPersonFullPath.replaceAll("\\\\","→") + "→" + strPersonName;
strReadOnlyGroupname = strPersonFullPath.replaceAll("\\\\","→") + "→只读共享→" + strPersonName;
strFullGroupname = strPersonFullPath.replaceAll("\\\\","→") + "→完全共享→" + strPersonName;
strGroupNames += "|" + strReadOnlyGroupname + "|" + strFullGroupname + "|" + strGroupname;
iReturnValue = SQLManager.ExcuteSQL("Insert into npGroupPath (GroupID,GroupPath,Permissions) values ('" + strReadOnlyGroupname + "','" + SystemParament.getParament("ftpomepath") + strPersonFullPath + "\\只读共享','RWA--C-LP')");
iReturnValue = SQLManager.ExcuteSQL("Insert into npUserComm (GroupID,HomePath,ServerPort) values ('" + strReadOnlyGroupname + "','" + SystemParament.getParament("ftpomepath") + strPersonFullPath + "\\只读共享',21)");
iReturnValue = SQLManager.ExcuteSQL("Insert into npGroupPath (GroupID,GroupPath,Permissions) values ('" + strFullGroupname + "','" + SystemParament.getParament("ftpomepath") + strPersonFullPath + "\\完全共享','RWAMECDLP')");
iReturnValue = SQLManager.ExcuteSQL("Insert into npUserComm (GroupID,HomePath,ServerPort) values ('" + strFullGroupname + "','" + SystemParament.getParament("ftpomepath") + strPersonFullPath + "\\完全共享',21)");
iReturnValue = SQLManager.ExcuteSQL("Insert into npGroupPath (GroupID,GroupPath,Permissions) values ('" + strGroupname + "','" + SystemParament.getParament("ftpomepath") + strPersonFullPath + "','R------L-')");
iReturnValue = SQLManager.ExcuteSQL("Insert into npUserComm (GroupID,HomePath,ServerPort) values ('" + strGroupname + "','" + SystemParament.getParament("ftpomepath") + strPersonFullPath + "',21)");
}
iReturnValue = SQLManager.ExcuteSQL("insert into " + TableName + " (UserID,Pass,Enabled,ServerPort,Expire,HomePath,GroupId) values ('" + ((Vector)vt.get(0)).get(1).toString() + "','" + StringNew.getDisencodePassword(((Vector)vt.get(0)).get(2).toString()) + "',1,21,0,'" + SystemParament.getParament("ftpomepath") + "','" + strGroupNames + "')");
}
else
{
/**
* 该用户不存在
*/
return -1;
}
return iReturnValue;
}
/**
* 创建指定多级目录
* @param strDirsPath String 目录实际路径
*/
private static void makeDirs(String strDirsPath)
{
File file = new File(strDirsPath);
try
{
if (!file.exists())
{
file.mkdirs();
}
}
catch (Exception ex)
{
SystemOut.OutPrintLine(ex.toString());
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -