403Webshell
Server IP : 3.96.16.70  /  Your IP : 216.73.216.15
Web Server : Apache
System : Linux ip-172-31-26-103.ca-central-1.compute.internal 6.1.163-186.299.amzn2023.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Feb 24 16:35:42 UTC 2026 x86_64
User : ec2-user ( 1000)
PHP Version : 8.4.18
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /var/www/html/estimakr.com/estimakr/node/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/estimakr.com/estimakr/node/index.js
const config = require('../config/node_config');

const { Configuration, OpenAIApi } = require("openai");
const fs = require('fs');
const https = require('https');

const options = {
	key: fs.readFileSync('/etc/letsencrypt/live/estimakr.com/privkey.pem'),
	cert: fs.readFileSync('/etc/letsencrypt/live/estimakr.com/fullchain.pem'),
};

// Create https server
const server = https.createServer(options, function (request, response) { });
server.listen(config.serverPORT, function () {
	console.log('listening on *:' + config.serverPORT);
});

// Socket.io
const io = require('socket.io')(server,  {
	transports: ['websocket'],
	cors: {
		origin: config.corsURL,
		methods: ["GET", "POST"],
		credentials: true
	}
});

// OpenAI
const configuration = new Configuration({
	apiKey: config.openAI_API_Key
});
const openai = new OpenAIApi(configuration);


const generate = async function (textprompt) {
	
	console.log('generate:', textprompt);
	
	const response = await openai.createImage({
		prompt: textprompt,
		
		model: config.model,
		quality: config.quality,
		style: config.style,
		size: config.imageSize,
		
		n: 1,
		response_format: 'b64_json',
	});

	return response.data;

}

io.on('connection', function (socket) {

	var origin = socket.handshake.headers.origin;
	console.log('Connection accepted from ' + origin);

	socket.on('disconnect', function () {
		console.log('Client disconnected');
	});

	socket.on('openAI:generate', function (msg) {
		
		generate(msg.prompt).then(
						
			response => {
				const now = Date.now();
				for (let i = 0; i < response.data.length; i++) {
					const b64 = response.data[i]['b64_json'];
					const buffer = Buffer.from(b64, "base64");
					const filename = `image_${now}_${i}.png`;
					console.log("Writing image " + filename);
					fs.writeFileSync(config.imgOutputDir + config.dirSeparator + filename, buffer);
					socket.emit('openAI:result', {image: filename});
				}
			}
			
		).catch( e => {
			//console.error(e);
			console.log (e.response.data);
		});
		
	});
});

Youez - 2016 - github.com/yon3zu
LinuXploit