Commit f386613f f386613f0813c17ffb49bb3f20d7a5a743f593bf by root

save

1 parent 73816ef7
......@@ -12,8 +12,6 @@ import org.emercit.xmldbmanager.service.Db;
import org.emercit.projecttools.constants.Paths;
public enum ProxyService {
INSTANCE;
......@@ -21,8 +19,6 @@ public enum ProxyService {
private ProxyLinux proxy=new ProxyLinux();
private Db db=new Db(Paths.BEAN_PROXY);
private Vector<String> vStr;
private Vector<ProxyBean> vPb;
......@@ -30,8 +26,6 @@ public enum ProxyService {
return (Vector<ProxyBean> )db.select();
}
public boolean Upd(Vector<ProxyBean> beans) {
......
......@@ -12,6 +12,7 @@ import org.emercit.devinfo.model.DevInfoBean;
import org.emercit.xmldbmanager.service.Db;
import org.emercit.projecttools.constants.Paths;
import org.emercit.projecttools.constants.Msg;
public class DevInfo implements IDevInfo {
......@@ -21,22 +22,24 @@ public class DevInfo implements IDevInfo {
private DevInfoBean devinfobean;
public boolean set(DevInfoBean m) {
public Msg set(DevInfoBean m) {
return db.create(m);
}
public DevInfoBean get() {
return (DevInfoBean)db.select();
}
public void init() {
public Msg init() {
devinfobean=new DevInfoBean();
devinfobean.setDescription("Описание устройства");
devinfobean.setGuid("00000000-0000-0000-0000-000000000000");
set(devinfobean);
return set(devinfobean);
}
}
......
......@@ -7,14 +7,16 @@ import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import org.emercit.projecttools.constants.Msg;
import org.emercit.devinfo.model.DevInfoBean;
public interface IDevInfo {
public boolean set(DevInfoBean m);
public Msg set(DevInfoBean m);
public DevInfoBean get();
public void init();
public Msg init();
}
......
package org.emercit.displaycalibrator.service;
import org.emercit.projecttools.constants.Msg;
public interface DCalibrator {
public void Run(String cmd);
public Msg Run(String cmd);
}
......
......@@ -7,16 +7,21 @@ import java.io.FileWriter;
import java.io.InputStreamReader;
import java.util.Vector;
import org.apache.log4j.Logger;
import org.emercit.devinfo.service.DevInfo;
import org.emercit.pckutils.cmd.CmdExec;
import org.emercit.projecttools.constants.Msg;
public class DCalibratorBB implements DCalibrator {
private static final Logger log = Logger.getLogger(DCalibratorBB.class);
private CmdExec cmdExec=new CmdExec();
//Run("/home/debian/start-xinput-config.sh");
public void Run(String cmd) {
public Msg Run(String cmd) {
try {
Vector<String> params=cmdExec.Run(cmd);
......@@ -39,8 +44,12 @@ public class DCalibratorBB implements DCalibrator {
}
bw.close();
log.info(Msg.CalibrSucc);
return Msg.CalibrSucc;
}catch(Exception e) {
log.error(Msg.CalibrError);
return Msg.CalibrError;
}
}
......
package org.emercit.ethmanager.model;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.List;
import java.util.ArrayList;
import java.util.Random;
import java.util.Vector;
public class CommandExecutor {
public Vector<String> Run(String cmd) throws Exception {
Vector<String> v=new Vector<String>();
Runtime run = Runtime.getRuntime();
Process proc = run.exec(new String[]{"/bin/sh", "-c",cmd});
proc.waitFor();
BufferedReader br = new BufferedReader(new InputStreamReader(proc.getInputStream()));
while(br.ready()) {
v.add(br.readLine());
}
return v;
}
}
\ No newline at end of file
......@@ -11,19 +11,16 @@ import java.io.FileWriter;
import java.io.BufferedWriter;
import java.io.IOException;
import org.emercit.ethmanager.model.CommandExecutor;
import org.emercit.xmldbmanager.service.Db;
import org.emercit.projecttools.constants.Paths;
import org.emercit.pckutils.cmd.CmdExec;
public class EthLinux implements IEth {
private static final Logger log = Logger.getLogger(EthLinux.class);
private CommandExecutor ce=new CommandExecutor();
private CmdExec cmdexec=new CmdExec();
private Vector<EthBean> ebs=new Vector<EthBean>();
......@@ -34,7 +31,7 @@ public class EthLinux implements IEth {
private String mac;
private EthBean emp;
......@@ -54,7 +51,7 @@ public class EthLinux implements IEth {
Vector<String> result=new Vector<String>();
try {
Vector<String> buff=ce.Run("ifconfig | grep eth | awk '{print $1}'");
Vector<String> buff=cmdexec.Run("ifconfig | grep eth | awk '{print $1}'");
ebs=(Vector<EthBean>)db.select();
......@@ -90,18 +87,18 @@ public class EthLinux implements IEth {
if(eb.getName().equals(name)) {
try {
extinfo=ce.Run("ifconfig"+" "+eb.getName());
extinfo=cmdexec.Run("ifconfig"+" "+eb.getName());
mac=ce.Run("ifconfig"+" "+eb.getName()+" | grep HWaddr | awk '{ print $5}' ").firstElement();
mac=cmdexec.Run("ifconfig"+" "+eb.getName()+" | grep HWaddr | awk '{ print $5}' ").firstElement();
eb.setInfo(extinfo);
eb.setMac(mac);
if (eb.getDhcp()) {
String addr=ce.Run("ifconfig"+" "+eb.getName()+" "+"| grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'").firstElement();
String mask=ce.Run("ifconfig"+" "+eb.getName()+" "+"| grep 'inet addr:' | cut -d: -f4 | awk '{ print $1}'").firstElement();
String gateway=ce.Run("/sbin/route -n | grep 'UG' | awk '{print $2}'").firstElement();
String addr=cmdexec.Run("ifconfig"+" "+eb.getName()+" "+"| grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'").firstElement();
String mask=cmdexec.Run("ifconfig"+" "+eb.getName()+" "+"| grep 'inet addr:' | cut -d: -f4 | awk '{ print $1}'").firstElement();
String gateway=cmdexec.Run("/sbin/route -n | grep 'UG' | awk '{print $2}'").firstElement();
eb.setIp(addr);
eb.setNetmask(mask);
......
package org.emercit.projecttools.constants;
import java.util.Vector;
public class DefSettings {
//DevInfo
public static final String DevInfo_Guid="00000000-0000-0000-0000-000000000000";
public static final String DevInfo_Description="Описание устройства";
//Dns
public static final String Dns_host="8.8.8.8";
//Ntp
public static final String Ntp_host="127.0.0.1";
//Eth0
public static final int Eth0_id=0;
public static final String Eth0_name="eth0";
public static final String Eth0_mac="";
public static final boolean Eth0_dhcp=false;
public static final String Eth0_ip="192.168.99.1";
public static final String Eth0_netmask="255.255.255.0";
public static final String Eth0_gateway="192.168.99.2";
public static final String Eth0_broadcast="";
public static final String Eth0_extinfo="";
//Eth1
public static final int Eth1_id=1;
public static final String Eth1_name="eth1";
public static final String Eth1_mac="";
public static final boolean Eth1_dhcp=true;
public static final String Eth1_ip="";
public static final String Eth1_netmask="";
public static final String Eth1_gateway="";
public static final String Eth1_broadcast="";
public static final String Eth1_extinfo="";
//GSM
public static final String gsm_operator="megafon";
}
package org.emercit.projecttools.constants;
import org.emercit.projecttools.constants.TypeMsg;
public enum Msg {
SaveFileSucc(1,TypeMsg.INFO,"Выполнено сохранение файла"),
SaveFileError(2,TypeMsg.ERROR,"Сохранение файла не выполнено"),
LoadFileSucc(3,TypeMsg.INFO,"Чтение файла выполнено"),
LoadFileError(4,TypeMsg.ERROR,"Ошибка чтения файла"),
UpdSuccess(5,TypeMsg.INFO,"Конфигурация выполнена успешно"),
UpdError(6,TypeMsg.ERROR,"Ошибка при конфигурации"),
CalibrSucc(7,TypeMsg.INFO,"Выполнена калибровка экрана"),
CalibrError(8,TypeMsg.ERROR,"Калибровка экрана не выполнена"),
InitSucc(9,TypeMsg.INFO,"Выполнена инициализация"),
InitError(10,TypeMsg.ERROR,"Инициализация не выполнена");
private int code;
private TypeMsg type;
private String description;
private Msg(int code, TypeMsg type, String description ) {
this.code = code;
this.type = type;
this.description=description;
}
static public Msg getCode(int code) {
for (Msg v: Msg.values()) {
if (v.getCode()==code) {
return v;
}
}
return null;
}
public int getCode() {
return this.code;
}
public TypeMsg getTypeVariable() {
return this.type;
}
public TypeMsg getDescription() {
return this.type;
}
/*
public static final String msgUpdSucc="Выполнено обновление";
public static final String msgUpdErr="Обновление не выполнено";
public static final String mdgCalibratorSucc="Выполнена калибровка экрана";
public static final String msgCalibratorError="Калибровка экрана не выполнена";
*/
}
package org.emercit.projecttools.constants;
public enum MsgError {
}
package org.emercit.projecttools.constants;
public enum MsgInfo {
}
package org.emercit.projecttools.constants;
public enum TypeMsg implements TypeVariable {
INFO(1,"Уведомление"),
ERROR(2,"Ошибка");
private int code;
private String description;
private TypeMsg(int code, String description) {
this.code=code;
this.description=description;
}
static public TypeMsg getByCode(int code) {
for (TypeMsg v: TypeMsg.values()) {
if (v.getCode()==code) {
return v;
}
}
throw new RuntimeException("Неизвестный тип");
}
public int getCode() {
return this.code;
}
public String getDescription(){
return this.description;
}
}
\ No newline at end of file
package org.emercit.projecttools.constants;
public interface TypeVariable {};
\ No newline at end of file
......@@ -4,11 +4,13 @@ import java.util.Vector;
import org.emercit.utilstools.model.SettingsBean;
import org.emercit.projecttools.constants.Msg;
public interface ISettings {
//public SettingsBean get();
public boolean set(SettingsBean bean);
public Msg set(SettingsBean bean);
public boolean configuring(SettingsBean model);
......
......@@ -20,6 +20,7 @@ import org.emercit.proxymanager.service.ProxyLinux;
import org.emercit.servers.service.Servers;
import org.emercit.svmanager.service.Sv;
import org.emercit.projecttools.constants.Msg;
public class Settings implements ISettings {
......@@ -53,7 +54,7 @@ public class Settings implements ISettings {
}
*/
public boolean set(SettingsBean bean) {
public Msg set(SettingsBean bean) {
return db.create(bean);
}
......
......@@ -7,11 +7,14 @@ import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import org.apache.log4j.Logger;
import org.emercit.devinfo.service.DevInfo;
import org.emercit.projecttools.constants.Paths;
import org.emercit.projecttools.constants.Msg;
public class Db implements IDb {
private static final Logger log = Logger.getLogger(Db.class);
private String pathfile=null;
......@@ -23,7 +26,7 @@ public class Db implements IDb {
* Создает или перезаписывает сущетсвующий файл
* @see org.emercit.xmldbmanager.service.IDb#create(java.lang.Object)
*/
public boolean create(Object o) {
public Msg create(Object o) {
boolean result=true;
try {
......@@ -33,9 +36,9 @@ public class Db implements IDb {
xmlEncoder.writeObject(o);
xmlEncoder.close();
}catch(Exception e) {
result=false;
return Msg.SaveFileError;
}
return result;
return Msg.SaveFileSucc;
}
......@@ -50,14 +53,12 @@ public class Db implements IDb {
new FileInputStream(pathfile)));
Object result=(Object)d.readObject();
d.close();
log.error(Msg.LoadFileSucc);
return result;
}catch(Exception e) {
log.error(Msg.LoadFileError);
return null;
}
}
......
package org.emercit.xmldbmanager.service;
import org.emercit.projecttools.constants.Msg;
public interface IDb {
public boolean create(Object obj);
public Msg create(Object obj);
public Object select();
......