import functools import json import urllib.parse import os class Heap: def __init__(self, *relative_path_segments: str): self.relative_path_segments = relative_path_segments def __iter__(self): return iter([Heap._decode(it[0:-5]) for it in os.listdir(self._folder()) if it.endswith('.json')]) def __setitem__(self, key, value): json.dump(value, open(self._key2path(key), 'w')) def __getitem__(self, key): return json.load(open(self._key2path(key), 'r')) @staticmethod def _encode(code): return urllib.parse.quote_plus(code, '') @staticmethod def _decode(code): return urllib.parse.unquote_plus(code) @functools.lru_cache def _folder(self): result = os.path.join(Config()['db.heap.root'], *self.relative_path_segments) if not os.path.exists(result): os.makedirs(result, True) if not os.path.isdir(result): raise Exception(f"{result} must be a folder") return result def _key2path(self, key: str): return os.path.join(self._folder(), self._encode(key) + '.json')
wget -qO- - http://host/path/ | sed -E 's/^.*href=\"(.*)\".*$/\1/g'|grep -v '/'|grep -v '>' | xargs -i wget 'http://host/path/{}'
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; } }