public class UpDownload implements Serializable{ static SCPClient scp= new SCPClient(host, port, user, pass); public void download(String remote, String local) throws IOException { boolean cacheInMemory = false; if (cacheInMemory) { byte[] data = scp.download(remote); new File(local).getParentFile().mkdirs(); FileOutputStream fos = new FileOutputStream(local); fos.write(data); fos.close(); } else { new File(local).getParentFile().mkdirs(); FileOutputStream fos = new FileOutputStream(local); scp.downloadToStream(remote, fos); fos.close(); } } public static void upload(String remote, String local) throws IOException { File file = new File(local); FileInputStream fis = new FileInputStream(file); byte[] data = new byte[(int) file.length()]; for (int i = 0; i < data.length;) i += fis.read(data, i, data.length - i); fis.close(); scp.upload(remote, data); } public static void main(String[] args) throws IOException { upload("user:pass@host/path/to/file","c:\\local\\path"); download("user:pass@host/path/to/file","c:\\local\\path"); } public static void download(String fullPath) throws IOException { String[] components = fullPath.split("\\/"); String user = components[0].split("@")[0].split(":")[0]; String pass = components[0].split("@")[0].split(":")[1]; String host = components[0].split("@")[1]; String fileName = components[components.length - 1]; String folder = ""; for (int i = 1; i < components.length - 1; i++) folder += "/" + components[i]; UpDownload ud = new UpDownload(host, 22, user, pass); ud.download(folder + "/" + fileName, "j:/scp/" + host + "/" + folder + "/" + fileName); } public static void upload(String fullPath) throws IOException { String[] components = fullPath.split("\\/"); String user = components[0].split("@")[0].split(":")[0]; String pass = components[0].split("@")[0].split(":")[1]; String host = components[0].split("@")[1]; String fileName = components[components.length - 1]; String folder = ""; for (int i = 1; i < components.length - 1; i++) folder += "/" + components[i]; UpDownload ud = new UpDownload(host, 22, user, pass); ud.upload(folder + "/" + fileName, "j:/scp/" + host + "/" + folder + "/" + fileName); } }
URL url = new URL( "ssh://user:password@host?ksh -c ls"); URLConnection c=url.openConnection(); c.connect(); InputStream is=c.getInputStream(); for(;;) { int i=is.read(); if(i<0)break; // System.out.print((char)i); }
package dms.xml; import java.io.ByteArrayOutputStream; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import javax.xml.transform.OutputKeys; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerConfigurationException; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; public class XSLT{ private Transformer transformer; public XSLT(InputStream xslt) throws TransformerConfigurationException{ System.setProperty("javax.xml.transform.TransformerFactory","net.sf.saxon.TransformerFactoryImpl"); TransformerFactory tfactory=TransformerFactory.newInstance(); // tfactory.setAttribute("http://saxon.sf.net/feature/outputURIResolver",new UserOutputResolver()); tfactory.setAttribute("http://saxon.sf.net/feature/allow-external-functions",Boolean.TRUE); tfactory.setAttribute("http://saxon.sf.net/feature/timing",Boolean.TRUE); transformer=tfactory.newTransformer(new StreamSource(xslt)); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); } public void setParameter(String name,Object value){ transformer.setParameter(name,value); } public byte[] transform(InputStream xml) throws TransformerException{ ByteArrayOutputStream baos=new ByteArrayOutputStream(); transformer.transform(new StreamSource(xml),new StreamResult(baos)); return baos.toByteArray(); } public static void main(String argv[]) throws TransformerException,IOException{ System.out.println("!!!!!!!"); System.out.println("-----------------------"); XSLT xslt=new XSLT(new FileInputStream("J:\\http\\applications\\WSDLConnector\\wsdl2xml.xsl")); byte[] result=xslt.transform(new FileInputStream("j:\\http\\applications\\WSDLConnector\\SelfCareWebServicePort.wsdl")); // FileOutputStream output=new FileOutputStream("J:\\DS\\qpass\\MediaMall\\storefrontpurchasewebservice.html"); // OutputStream output=System.out; // output.write(result); // output.close(); // System.out.println(new String(result)); System.out.println(result.length); } // private static class UserOutputResolver implements OutputURIResolver{ // public Result resolve(String href,String base) throws TransformerException{ // if(href.endsWith(".out")){ // StreamResult res=new StreamResult(System.out); // res.setSystemId(href); // return res; // } // return null; // } // public void close(Result result) throws TransformerException{} // } }
package dms.xml; import java.io.ByteArrayInputStream; import java.io.File; import java.io.IOException; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.Source; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamSource; import javax.xml.validation.Schema; import javax.xml.validation.SchemaFactory; import javax.xml.validation.Validator; import javax.xml.XMLConstants; import org.w3c.dom.DOMImplementation; import org.w3c.dom.Document; import org.w3c.dom.Node; import org.xml.sax.EntityResolver; import org.xml.sax.ErrorHandler; import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; public class XSD { public static void main(String[] args) throws SAXException, ParserConfigurationException, IOException { SchemaFactory schemaFactory = SchemaFactory .newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schemaXSD = schemaFactory .newSchema(new File( "j:\\scsjcm\\v15\\scripts\\templates\\CustomerDetailsVO.xsd")); Validator validator = schemaXSD.newValidator(); validator.setErrorHandler(new ErrorHandler() { @Override public void warning(SAXParseException exception) throws SAXException { System.out.println(3); } @Override public void fatalError(SAXParseException exception) throws SAXException { System.out.println(1); } @Override public void error(SAXParseException exception) throws SAXException { System.out.println(exception); } }); validator.validate(new StreamSource(new File( "j:\\scsjcm\\v15\\scripts\\templates\\AMSPFeed.xml"))); } public static void validate(String xml, File xsd) throws SAXException, ParserConfigurationException, IOException { SchemaFactory schemaFactory = SchemaFactory .newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schemaXSD = schemaFactory.newSchema(xsd); Validator validator = schemaXSD.newValidator(); validator.validate(new StreamSource(new ByteArrayInputStream(xml.getBytes()))); } }
public static void main(String[] args) throws IOException { TelnetClient tc = new TelnetClient("illin441", 23); System.out.println(tc.readKeysUntil("ogin:")); tc.println("text11"); System.out.println(tc.readKeysForUntil(1000, "assword:")); tc.println("Unix11!"); System.out.println(tc.readKeysFor(2000)); }
package dms.os; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.security.KeyManagementException; import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; import java.security.UnrecoverableKeyException; import java.security.cert.CertificateException; import javax.net.ssl.HttpsURLConnection; import sun.org.mozilla.javascript.internal.NativeObject; public class Boot { public static NativeObject cache = new NativeObject(); static { SSLUtil.class.getClass(); System.setProperty("proxyHost", "genproxy"); System.setProperty("proxyHost", "8080"); } public static void main(String[] args) throws KeyManagementException, UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, CertificateException, IOException { // SSLmain(); } public static void SSLmain() throws IOException, KeyManagementException, UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, CertificateException { System.out.println("Starting"); File file = new File( "j:\\Certificates\\c_qseng7.p12"); FileInputStream fis = new FileInputStream(file); byte[] data = new byte[(int) file.length()]; for (int pos = 0; pos < data.length;) pos += fis.read(data, pos, data.length - pos); fis.close(); SSLUtil.addClientCertificate(data, "password"); } private static void SSLdownloadUrl(String urlValue) throws IOException { URL url = new URL(urlValue); HttpsURLConnection connection = (HttpsURLConnection) url .openConnection(); try { System.out .println("IS: " + SSLcalcUrl(connection.getInputStream())); } catch (Throwable t) { } try { System.out .println("ES: " + SSLcalcUrl(connection.getErrorStream())); } catch (Throwable t) { } } private static int SSLcalcUrl(InputStream is) throws IOException { int count = 0; for (;;) { int i = is.read(); if (i < 0) break; count++; } return count; } }
package dms.os.ie; import java.awt.BorderLayout; import java.awt.Component; import java.awt.Graphics; import java.awt.Insets; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.net.MalformedURLException; import java.net.URL; import javax.swing.Icon; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JTabbedPane; import javax.swing.JTextArea; import javax.swing.JTextField; import javax.swing.UIManager; import javax.swing.border.Border; import org.jdesktop.jdic.browser.WebBrowser; import dms.vm.Environment; import dms.vm.VM; public class TabbedBrowser extends JFrame { public static void main(String[] args) throws MalformedURLException { TabbedBrowser w = new TabbedBrowser(); } private static JTabbedPane pane = new JTabbedPane(JTabbedPane.BOTTOM, JTabbedPane.WRAP_TAB_LAYOUT); public TabbedBrowser() throws MalformedURLException { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Throwable t) { } this.setVisible(true); this.setSize(800, 600); this.setDefaultCloseOperation(EXIT_ON_CLOSE); this.add(pane); pane.setBorder(new Border() { @Override public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { } @Override public boolean isBorderOpaque() { return false; } @Override public Insets getBorderInsets(Component c) { return new Insets(0, 0, 0, 0); } }); WebBrowser w1 = new WebBrowser(new URL("http://www.google.com")); w1.setLocation(0, -100); JPanel console = new JPanel(new BorderLayout()); final JTextArea outp=new JTextArea(); console.add(outp); JPanel inp = new JPanel(new BorderLayout()); console.add(inp, BorderLayout.SOUTH); final JTextField field = new JTextField(); inp.add(field); JButton run = new JButton("Run"); // final VM vm = new VM(); Environment.getInstance().put("TabbedBrowser", Environment.getInstance(), this); run.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { Object result=null; try { result = VM.eval(field.getText(), "console"); } catch (Throwable t) { result=t; } outp.append(""+result+"\n"); } }); inp.add(run, BorderLayout.EAST); pane.add("Console", console); // pane.add("QQQQQQQQQQQQQQQQQQQ12", w1); // pane.add("3WWWWWWWWWWWWWWWWWWWW4", new WebBrowser(new URL( // "http://www.yahoo.com"))); } public void addTab(String title, String url) throws MalformedURLException { pane.add(title, new WebBrowser(new URL(url))); } public void closeTab(int i) { pane.remove(i); } public void renameTab(int i,String name) { pane.setTitleAt(i,name); } }
package dms.net.smtp; import java.awt.AWTException; import java.awt.Robot; import java.io.ByteArrayOutputStream; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStreamWriter; import java.io.Writer; import java.net.Socket; import java.net.UnknownHostException; import java.util.Date; import java.util.HashMap; public class SmtpClient { private static String SMTPServerLocation = "myserver.com"; public String subject = ""; public String from = "test1@jcom.com"; public String to = ""; public HashMap<String, String> headers = new HashMap<String, String>(); public String message = "Date: " + new Date(); public static void main(String[] args) throws UnknownHostException, IOException, AWTException { SmtpClient client = new SmtpClient(); // client.headers.put("From", "dsorescu@domain.com");//Test Dragos-Matei // Sorescu for short header contents"); client.headers.put("Content-Type", "text/plain"); client.headers.put("To", "support@domain.com");// JCOM Support email test // for short header // contents"); client.subject = "[Veera, Dragos, and Ruth in BCC] Test subject long headers " + new Date(); client.to = "support@domain.com"; client.from = "dsorescu@domain.com"; int headers = 2; for (int i = 0; i < headers; i++) client.headers .put("h" + i, "THIS IS A DUMMY HEADER RECORD TO SIMULATE inbound mails 2568/UT_01244"); String longCC = "\"d1011051059@dsorescu03.corp.domain.com;d1011051100@dsorescu03.corp.domain.com;d1011051101@dsorescu03.corp.domain.com;d1011051102@dsorescu03.corp.domain.com;d1011051103@dsorescu03.corp.domain.com;d1011051104@dsorescu03.corp.domain.com;d1011051105@dsorescu03.corp.domain.com\""; // client.headers.put("Cc", longCC); // client.headers.put("To", longCC); // client.headers.put("Bcc", longCC); // client.headers.put("Subject", "Subject_"+longCC); client.message = "CASE_START\r\n" +"CONTACT_EMAIL: \r\n"//+test@dsorescu03.corp.domain.com \r\n" + "CASE_SUMMARY: (Check how this mail works - it has extra line broken) we have here a very long summary that is more than let's say 80 characters,\r\nwhich may alter the email parser, if lines are tokenized prior to the EM worker.\r\n" + "CALL_TYPE: Change Service of\r\n" + "CALL_TYPE_2: Downgrade\r\n" + "CALL_TYPE_3: Construction-free\r\n" + "SEVERITY: NO-SEVerity\r\n" + "PRIORITY: NO-priority\r\n" + "CASE_DESCRIPTION: Veera, Dragos, and Ruth in BCC - description " + new Date() + "\r\n" + " PRIORITY: no priority\r\n" //+ "CONTACT_EMAIL: "+//DSORESCU@domain.COM" + "\r\n" + "CASE_END"; client.message = "Hello, did you receive the mail? It has " + headers + " headers... " + new Date(); // client.message=readFile("j:\\sample.txt"); client.sendToVia("dsorescu@domain.com", "server.domain.com"); send("test1@domain.com","support@domain.com","Test Subject","Mail-creation-test"); } private Writer output; private String rcpt_to; public static void send(String to, String subject, String body) throws UnknownHostException, IOException, AWTException { sun.org.mozilla.javascript.internal.Scriptable s; sun.org.mozilla.javascript.internal.Scriptable ss; SmtpClient client = new SmtpClient(); client.to = to; client.subject = subject; client.message = body; client.send(); } public static void send(String from, String to, String subject, String body) throws UnknownHostException, IOException, AWTException { SmtpClient client = new SmtpClient(); client.from = from; client.to = to; client.subject = subject; client.message = body; client.send(); } public void send() throws UnknownHostException, IOException, AWTException { sendTo(this.to); } public void sendToVia(String recipient, String via) throws UnknownHostException, IOException, AWTException { SMTPServerLocation = via; sendTo(recipient); } public void sendTo(String recipient) throws UnknownHostException, IOException, AWTException { Socket socket = new Socket(SMTPServerLocation, 25); this.output = new OutputStreamWriter(socket.getOutputStream()); InputStream inp = socket.getInputStream(); new CC(inp); Robot r = new Robot(); println("HELO " + socket.getLocalAddress().getHostName()); r.delay(1000); println("MAIL FROM: " + this.from); r.delay(1000); println("RCPT TO: " + recipient); r.delay(1000); println("DATA"); r.delay(1000); if (!headers.containsKey("MIME-Version")) headers.put("MIME-Version", "1.0"); if (!headers.containsKey("Content-Type")) headers.put("Content-Type", "text/html"); if (!headers.containsKey("From")) headers.put("From", this.from); if (!headers.containsKey("To")) headers.put("To", this.to); if (!headers.containsKey("Subject")) headers.put("Subject", this.subject); for (String s : headers.keySet()) println(s + ": " + headers.get(s)); r.delay(1000); // println("MIME-Version: 1.0"); // println("Content-Type: text/html"); // println("From: " + this.from); // println("To: " + this.to); // println("Subject: " + this.subject); println(""); r.delay(1000); println(this.message); r.delay(1000); println("."); r.delay(1000); println("QUIT"); r.delay(1000); System.out.println(); } public static void $sendRaw(String to, String rawText) throws UnknownHostException, IOException, AWTException { Socket socket = new Socket(SMTPServerLocation, 25); OutputStreamWriter output = new OutputStreamWriter(socket .getOutputStream()); InputStream inp = socket.getInputStream(); new CC(inp); output.write("HELO " + socket.getLocalAddress().getHostName()); output.write("\r\n"); output.flush(); new Robot().delay(200); output.write("MAIL FROM: auto-forwarder@dsorescu03.corp.domain.com"); output.write("\r\n"); output.flush(); new Robot().delay(200); output.write("RCPT TO: " + to); output.write("\r\n"); output.flush(); new Robot().delay(200); output.write("DATA"); output.write("\r\n"); output.flush(); new Robot().delay(2000); output.write(rawText); output.write("\r\n"); output.flush(); output.write("."); output.write("\r\n"); output.flush(); output.write("QUIT"); output.write("\r\n"); output.flush(); } private void println(Object what) throws IOException { this.output.write(what + "\r\n"); this.output.flush(); System.out.println(what); } private static String readFile(String name) throws IOException { FileInputStream fis = new FileInputStream(name); ByteArrayOutputStream baos = new ByteArrayOutputStream(); for (;;) { int i = fis.read(); if (i < 0) break; baos.write(i); } fis.close(); return new String(baos.toByteArray()); } } class CC extends Thread { InputStream i; public CC(InputStream inp) { this.i = inp; start(); } @Override public void run() { try { for (;;) { int c = this.i.read(); if (c < 0) break; System.out.print((char) c); } } catch (IOException e) { e.printStackTrace(); } } }