Commits - Yash-777/MyWorld GitHub Wiki

IPv4 vs IPV6 https://www.youtube.com/watch?v=ThdO9beHhpA&ab_channel=PowerCertAnimatedVideos

Public vs Private IP Address (NAT{Network address translation} - is what that translates a set of ip adress to another set of ip address) https://www.youtube.com/watch?v=po8ZFG0Xc4Q&ab_channel=PowerCertAnimatedVideos

Subnet Mask - Explained (CIDR classless inter domain routing with slash notation) 192.168.1.0/24 or /8 https://www.youtube.com/watch?v=s_Ntt6eTn94&ab_channel=PowerCertAnimatedVideos

Telugu: Learn AWS VPC in 30 minutes || VPC Introduction || AWS Networking || In Telugu || Rakesh Taninki https://www.youtube.com/watch?v=bh0bi7ot414&list=PLCo6vu1MhylYJC-uBOeEif2HDSEocTpOl&ab_channel=RakeshTaninki

https://www.youtube.com/watch?v=g2lPI_ab_aM&ab_channel=RakeshTaninki

AWS Network Firewall : https://www.youtube.com/watch?v=j599Irl_kn0 https://www.youtube.com/watch?v=sLnXHOkaNTk

How to use AWS WAF (Web application firewall)/Web ACL? : https://www.youtube.com/watch?v=FHRXXrQ765M Mastering AWS: NAT Gateway Setup in Your VPC : https://www.youtube.com/watch?v=ydxEeVAqVdo


chrome.exe --disable-web-security --user-data-dir=D:\Vorwork_DSPRO\Chrome_Disabled_Security
package com.github.yash777.myworld.api.online;

import java.security.SecureRandom;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.github.yash777.security.crypto.CipherKeyEncryptDecrypt;

import io.swagger.v3.oas.annotations.Parameter;

@RestController
@RequestMapping("/pswd")
public class PasswordController {
	
	private static final String UPPERCASE = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	private static final String LOWERCASE = "abcdefghijklmnopqrstuvwxyz";
	private static final String DIGITS = "0123456789";
	private static final String SPECIAL_CHARS = "!@#$%^&*()-_+=";
	
	private static final SecureRandom random = new SecureRandom();
	
	@GetMapping("/generate/default")
	public String generatePassword(
			@RequestParam int length,
			@Parameter(
					description = "UPPERCASE = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\""
					)
			@RequestParam(required = false, defaultValue = "true") boolean useUppercase,
			@Parameter(
					description = "LOWERCASE = \"abcdefghijklmnopqrstuvwxyz\""
					)
			@RequestParam(required = false, defaultValue = "true") boolean useLowercase,
			@Parameter(
					description = "DIGITS = \"0123456789\""
					)
			@RequestParam(required = false, defaultValue = "true") boolean useDigits,
			@Parameter(
					description = "SPECIAL_CHARS = \"!@#$%^&*()-_+=\""
					)
			@RequestParam(required = false, defaultValue = "true") boolean useSpecial
			) {
		if (length < 4) {
			return "Password length must be at least 4";
		}
		
		StringBuilder characterPool = new StringBuilder();
		List<Character> passwordChars = new ArrayList<>();
		
		if (useUppercase) {
			characterPool.append(UPPERCASE);
			passwordChars.add(UPPERCASE.charAt(random.nextInt(UPPERCASE.length())));
		}
		
		if (useLowercase) {
			characterPool.append(LOWERCASE);
			passwordChars.add(LOWERCASE.charAt(random.nextInt(LOWERCASE.length())));
		}
		
		if (useDigits) {
			characterPool.append(DIGITS);
			passwordChars.add(DIGITS.charAt(random.nextInt(DIGITS.length())));
		}
		
		if (useSpecial) {
			characterPool.append(SPECIAL_CHARS);
			passwordChars.add(SPECIAL_CHARS.charAt(random.nextInt(SPECIAL_CHARS.length())));
		}
		
		if (characterPool.length() == 0) {
			return "At least one character type must be selected.";
		}
		
		while (passwordChars.size() < length) {
			char ch = characterPool.charAt(random.nextInt(characterPool.length()));
			passwordChars.add(ch);
		}
		
		Collections.shuffle(passwordChars);
		
		StringBuilder finalPassword = new StringBuilder();
		for (char c : passwordChars) {
			finalPassword.append(c);
		}
		
		return finalPassword.toString();
	}
	
	@GetMapping("/encode")
	public String encodePassword(
			@Parameter(
					description = "Salted user identifier (e.g., email)",
					example = "[email protected]"
					)
			@RequestParam String salt_UserName,
			
			@Parameter(
					description = "Raw password string",
					example = "Y@sh^0@dm!n%)"
					)
			@RequestParam String raw_Password,
			
			@Parameter(
					description = "Creation date in format yyyy-MM-dd HH:mm:ss (optional)",
					example = "2025-09-27 10:07:37"
					)
			@RequestParam(required = false)
			String creationDate,
			
			@Parameter(
					description = "Custom character set for encryption (optional)",
					example = "B&^0QUV^?^SQ.{D|]C[[(+hm'^e7|FJ}Ga-4$T54:(bgpyD,)K{fpE8~M,YMzvu"
					)
			@RequestParam(required = false)
			String customChars
			) throws Exception {
		
		CipherKeyEncryptDecrypt chiper = new CipherKeyEncryptDecrypt();
		
		// ✅ Handle creationDate parsing and validation
		LocalDateTime parsedDate = null;
		if (creationDate != null && !creationDate.isBlank()) {
			try {
				parsedDate = LocalDateTime.parse(creationDate, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
			} catch (DateTimeParseException e) {
				throw new IllegalArgumentException("Invalid creationDate format. Use 'yyyy-MM-dd HH:mm:ss'");
			}
		}
		
		// ✅ Handle customChars fallback
		if (customChars != null && !customChars.isBlank()) {
			CipherKeyEncryptDecrypt.secretPasswordKey = customChars;
		} else {
			CipherKeyEncryptDecrypt.secretPasswordKey = CipherKeyEncryptDecrypt.ENCRYPT_PASS_DB;
		}
		
		if (parsedDate != null) {
			Date dateFrom = CipherKeyEncryptDecrypt.getDateFrom(creationDate);
			
			String encodeWithDate = chiper.encode(raw_Password, salt_UserName, dateFrom);
			System.out.println("encodeWithDate : "+encodeWithDate);
			String doecodedPassDate = chiper.decode(encodeWithDate, salt_UserName, dateFrom);
			System.out.println("doecodedPassDate : "+doecodedPassDate);
			
			return encodeWithDate;
		} else {
			String encoded = chiper.encode(raw_Password, salt_UserName, null);
			System.out.println("encode : "+encoded);
			String decoded = chiper.decode(encoded, salt_UserName, null);
			System.out.println("decoded : "+decoded);
			
			return encoded;
		}
	}
	
	@GetMapping("/decode")
	public String decodePassword(
			@Parameter(
					description = "Salted user identifier (e.g., email)",
					example = "[email protected]"
					)
			@RequestParam String salt_UserName,
			
			@Parameter(
					description = "encoded password string",
					example = "eWFzaEBteXdvcmxkLmNvbTIwMjUtMDktMjcgMTA6MDdA11S9NKT1QWP0n93JC682"
					)
			@RequestParam String encoded_Password,
			
			@Parameter(
					description = "Creation date in format yyyy-MM-dd HH:mm:ss (optional)",
					example = "2025-09-27 10:07:37"
					)
			@RequestParam(required = false)
			String creationDate,
			
			@Parameter(
					description = "Custom character set for encryption (optional)",
					example = "B&^0QUV^?^SQ.{D|]C[[(+hm'^e7|FJ}Ga-4$T54:(bgpyD,)K{fpE8~M,YMzvu"
					)
			@RequestParam(required = false)
			String customChars
			) throws Exception {
		
		CipherKeyEncryptDecrypt chiper = new CipherKeyEncryptDecrypt();
		
		// ✅ Handle creationDate parsing and validation
		LocalDateTime parsedDate = null;
		if (creationDate != null && !creationDate.isBlank()) {
			try {
				parsedDate = LocalDateTime.parse(creationDate, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
			} catch (DateTimeParseException e) {
				throw new IllegalArgumentException("Invalid creationDate format. Use 'yyyy-MM-dd HH:mm:ss'");
			}
		}
		
		// ✅ Handle customChars fallback
		if (customChars != null && !customChars.isBlank()) {
			CipherKeyEncryptDecrypt.secretPasswordKey = customChars;
		} else {
			CipherKeyEncryptDecrypt.secretPasswordKey = CipherKeyEncryptDecrypt.ENCRYPT_PASS_DB;
		}
		
		if (parsedDate != null) {
			Date dateFrom = CipherKeyEncryptDecrypt.getDateFrom(creationDate);
			
			String doecodedPassDate = chiper.decode(encoded_Password, salt_UserName, dateFrom);
			System.out.println("DoecodedPassDate : "+doecodedPassDate);
			
			return doecodedPassDate;
		} else {
			String decoded = chiper.decode(encoded_Password, salt_UserName, null);
			System.out.println("decoded : "+decoded);
			
			return decoded;
		}
	}

}
package com.github.yash777.myworld.api.online;

import java.lang.management.ManagementFactory;
import java.net.Inet4Address;
import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.nio.file.FileStore;
import java.nio.file.FileSystems;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;

import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.github.yash777.basic.JsonUtil;
import com.sun.management.OperatingSystemMXBean;

/**
 * REST API for exposing system and network information.
 *
 * Endpoints:
 *  - GET /system-info/basic   : Returns CPU, memory, disk, Java, OS info
 *  - GET /system-info/network : Returns network details (hostname, IPs, etc.)
 */
@RestController
@RequestMapping("/system-info")
@SpringBootApplication
public class SystemInfoController {
    public static void main(String[] args) {
    	System.out.println("System Properties   Info:\n"+ System.getProperties());
    	System.out.println("System Properties   Info:\n"+ JsonUtil.toPrettyJson(System.getProperties()));
    	SystemInfoController obj = new SystemInfoController();
    	System.out.println("System Basic   Info:\n"+ obj.getBasicSystemInfo());
    	System.out.println("System Basic   Info:\n"+ JsonUtil.toPrettyJson(obj.getBasicSystemInfo()));
    	System.out.println("System Network Info:\n"+ obj.getNetworkInfo());
    	System.out.println("System Network Info:\n"+ JsonUtil.toPrettyJson(obj.getNetworkInfo()));
    }

    /**
     * Endpoint to fetch basic system information.
     *
     * @return A map containing system-level information (CPU, memory, OS, disk, etc.)
     */
    @GetMapping("/basic")
    public Map<String, Object> getBasicSystemInfo() {
        Map<String, Object> info = new LinkedHashMap<>();

        try {
            String hostname = InetAddress.getLocalHost().getHostName();
            String username = System.getProperty("user.name");
            String javaVersion = System.getProperty("java.version");
            String pid = ManagementFactory.getRuntimeMXBean().getName().split("@")[0];

            Properties props = System.getProperties();
            String osName = props.getProperty("os.name");
            String osArch = props.getProperty("os.arch");
            String osVersion = props.getProperty("os.version");

            int cpuCores = Runtime.getRuntime().availableProcessors();
            long heapMax = Runtime.getRuntime().maxMemory();

            OperatingSystemMXBean osBean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
            long totalPhysicalMemory = osBean.getTotalPhysicalMemorySize();
            long freePhysicalMemory = osBean.getFreePhysicalMemorySize();
            long diskCache = (long) (totalPhysicalMemory * 0.6);

            info.put("hostname", hostname);
            info.put("user", username);
            info.put("pid", pid);
            info.put("javaVersion", javaVersion);
            info.put("osName", osName);
            info.put("osVersion", osVersion);
            info.put("osArch", osArch);
            info.put("cpuCores", cpuCores);

            info.put("heapMemoryMax", formatBytes(heapMax));
            info.put("physicalMemoryTotal", formatBytes(totalPhysicalMemory));
            info.put("physicalMemoryFree", formatBytes(freePhysicalMemory));
            info.put("diskCacheAutoConfig", formatBytes(diskCache));

            List<Map<String, Object>> disks = new ArrayList<>();
            for (FileStore store : FileSystems.getDefault().getFileStores()) {
                try {
                    Map<String, Object> disk = new LinkedHashMap<>();
                    disk.put("disk", store.toString());
                    disk.put("type", store.type());
                    disk.put("total", formatBytesSafe(store.getTotalSpace()));
                    disk.put("usable", formatBytesSafe(store.getUsableSpace()));
                    disks.add(disk);
                } catch (Exception e) {
                    // Some filesystems may not support getUsableSpace
                }
            }
            info.put("disks", disks);

        } catch (Exception e) {
            info.put("error", e.getMessage());
        }

        return info;
    }

    /**
     * Endpoint to fetch network-related information.
     *
     * @return A map containing IPv4, IPv6, hostname, and (placeholder) ISP data
     */
    @GetMapping("/network")
    public Map<String, Object> getNetworkInfo() {
        Map<String, Object> netInfo = new LinkedHashMap<>();
        try {
            InetAddress localHost = InetAddress.getLocalHost();
            netInfo.put("hostname", localHost.getHostName());
            netInfo.put("ipv4", localHost.getHostAddress());

            List<String> ipv6List = new ArrayList<>();
            List<String> ipv4List = new ArrayList<>();

            Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
            while (interfaces.hasMoreElements()) {
                NetworkInterface ni = interfaces.nextElement();
                if (!ni.isUp() || ni.isLoopback() || ni.isVirtual()) continue;

                Enumeration<InetAddress> addresses = ni.getInetAddresses();
                while (addresses.hasMoreElements()) {
                    InetAddress addr = addresses.nextElement();
                    if (addr instanceof Inet6Address) {
                        ipv6List.add(addr.getHostAddress());
                    } else if (addr instanceof Inet4Address) {
                        ipv4List.add(addr.getHostAddress());
                    }
                }
            }

            netInfo.put("ipv4List", ipv4List);
            netInfo.put("ipv6List", ipv6List);
            netInfo.put("networkInterfaces", NetworkInterface.getNetworkInterfaces().toString());

            // Placeholder for ISP
            netInfo.put("internetProvider", "N/A (requires external IP lookup service)");

        } catch (Exception e) {
            netInfo.put("error", e.getMessage());
        }

        return netInfo;
    }

    /**
     * Converts byte values into human-readable MB/GB representation.
     *
     * @param bytes number of bytes
     * @return formatted map with bytes, MB, GB
     */
    private Map<String, Object> formatBytes(long bytes) {
        Map<String, Object> result = new LinkedHashMap<>();
        result.put("bytes", bytes);
        result.put("MB", bytes / (1024 * 1024));
        result.put("GB", bytes / (1024 * 1024 * 1024));
        return result;
    }

    /**
     * Safe wrapper for byte formatting in case file store access fails.
     */
    private Map<String, Object> formatBytesSafe(long bytes) {
        try {
            return formatBytes(bytes);
        } catch (Exception e) {
            return Map.of("error", e.getMessage());
        }
    }
}
⚠️ **GitHub.com Fallback** ⚠️