Beispiel #1
0
int ftp_init()
{

    if(ftp_initialized) return 1;

    netInitialize();
	netCtlInit();

    union net_ctl_info info;
	
	if(netCtlGetInfo(NET_CTL_INFO_IP_ADDRESS, &info) == 0)
	{
		// start server thread
		
        appstate = 0;
        sprintf(ftp_ip_str, "FTP active (%s:%i)", info.ip_address, 21);
		sysThreadCreate(&thread_id, listener_thread, NULL, 1500, 0x400, 0, "listener");
		
		//s32 fd;
		//u64 read = 0;
		
        /*
		if(sysLv2FsOpen(OFTP_PASSWORD_FILE, SYS_O_RDONLY | SYS_O_CREAT, &fd, 0660, NULL, 0) == 0)
		{
			sysLv2FsRead(fd, passwd, 63, &read);
		}
		
		passwd[read] = '\0';
		sysLv2FsClose(fd);
        
		
		// prevent multiline passwords
		strreplace(passwd, '\r', '\0');
		strreplace(passwd, '\n', '\0');

        */
		
		char dlgmsg[256];
		sprintf(dlgmsg, "OpenPS3FTP %s by jjolano (Twitter: @jjolano)\nWebsite: http://jjolano.dashhacks.com\nDonations: http://bit.ly/gB8CJo\nStatus: FTP Server Active (%s port 21)\n\nPress OK to exit this program.",
			OFTP_VERSION, info.ip_address);
		
		//msgDialogOpen2(mt_ok, dlgmsg, dialog_handler, NULL, NULL);
        ftp_initialized = 1;

        return 0;

	}
	else
	{
		//msgDialogOpen2(mt_ok, OFTP_ERRMSG_NETWORK, dialog_handler, NULL, NULL);

        ftp_initialized = 0;
        netDeinitialize();

	}

    return -1;
}
Beispiel #2
0
void server_loop(void)
{
    int client_connected;
    msgType              dialog_type;
    char                 *message = (char *) malloc(512);

    // did the disc change?
    if (bd_contains_sacd_disc && bd_disc_changed)
    {
        bd_contains_sacd_disc = 0;
    }

    // by default we have no user controls
    dialog_type = (MSG_DIALOG_NORMAL | MSG_DIALOG_DISABLE_CANCEL_ON);

    if (!bd_contains_sacd_disc)
    {
    	union net_ctl_info info;

    	if(netCtlGetInfo(NET_CTL_INFO_IP_ADDRESS, &info) == 0)
    	{
       		sprintf(message, "              SACD Daemon %s\n\n"
       		                 "Status: Active\n"
       		                 "IP Address: %s (port 2002)\n"
       		                 "Client: %s\n"
       		                 "Disc: %s",
    			SACD_RIPPER_VERSION_STRING, info.ip_address,
    			(is_client_connected() ? "connected" : "none"),
    			(bd_disc_changed == -1 ? "empty" : "inserted"));
    	}
    	else
    	{
    		sprintf(message, "No active network connection was detected.\n\nPress OK to refresh.");
            dialog_type |= MSG_DIALOG_BTN_TYPE_OK;
    	}
    }

    msgDialogOpen2(dialog_type, message, dialog_handler, NULL, NULL);

    dialog_action         = 0;
    bd_disc_changed       = 0;
    client_connected      = is_client_connected();
    while (!dialog_action && !user_requested_exit() && bd_disc_changed == 0 && client_connected == is_client_connected())
    {
        sysUtilCheckCallback();
        flip();
    }
    msgDialogAbort();

    free(message);
}
Beispiel #3
0
netif_t *
net_get_interfaces(void)
{
  union net_ctl_info info;

  if(netCtlGetInfo(NET_CTL_INFO_IP_ADDRESS, &info))
    return NULL;

  netif_t *ni = calloc(2, sizeof(netif_t));

  snprintf(ni[0].ifname, sizeof(ni[0].ifname), "eth");
  ni[0].ipv4 = inet_addr(info.ip_address);
  return ni;
}
Beispiel #4
0
int main(s32 argc, char* argv[])
{
	atexit(_unload);

	// Initialize graphics
	GFX = new NoRSX();
	MsgDialog MSG(GFX);

	// Release message
	MSG.Dialog(MSG_OK, "This build of OpenPS3FTP has not been tested by the author. As such, you use this software at your own risk. Please report any issues found to the OpenPS3FTP GitHub repository or send a tweet to @jjolano. See README.txt for more details.");

	// Initialize required libraries: net, netctl, io
	netInitialize();
	netCtlInit();
	ioPadInit(7);

	// Verify connection state
	s32 state;
	netCtlGetState(&state);

	if(state != NET_CTL_STATE_IPObtained)
	{
		// not connected to network - terminate program
		MSG.Dialog(MSG_OK, "Could not verify connection status. OpenPS3FTP will now exit.");
		exit(EXIT_FAILURE);
	}

	// Set application running state
	GFX->AppStart();

	// Create thread for server
	sys_ppu_thread_t id;
	sysThreadCreate(&id, ftp_main, GFX, 1001, 0x1000, THREAD_JOINABLE, const_cast<char*>("opf_ftp_main"));

	// Set up graphics
	Font F1(LATIN2, GFX);
	Background BG(GFX);
	Bitmap BM(GFX);

	NoRSX_Bitmap PCL;
	BM.GenerateBitmap(&PCL);
	BG.MonoBitmap(COLOR_BLACK, &PCL);

	// Retrieve detailed connection information (ip address)
	net_ctl_info info;
	netCtlGetInfo(NET_CTL_INFO_IP_ADDRESS, &info);

	// Draw bitmap layer
	// Not sure how this will actually look.
	F1.PrintfToBitmap(50, 50, &PCL, COLOR_WHITE, "OpenPS3FTP version %s", OFTP_VERSION);
	F1.PrintfToBitmap(50, 100, &PCL, COLOR_WHITE, "Written by John Olano (twitter: @jjolano)");

	F1.PrintfToBitmap(50, 200, &PCL, COLOR_WHITE, "IP Address: %s (port 21)", info.ip_address);

	F1.PrintfToBitmap(50, 300, &PCL, COLOR_WHITE, "SELECT: Execute dev_blind");
	F1.PrintfToBitmap(50, 350, &PCL, COLOR_WHITE, "START: Exit OpenPS3FTP");

	// Pad IO variables
	padInfo padinfo;
	padData paddata;
	padData paddata_old[MAX_PADS];

	// Main thread loop
	while(GFX->GetAppStatus() != APP_EXIT)
	{
		// Get Pad Status
		ioPadGetInfo(&padinfo);

		for(unsigned int i = 0; i < MAX_PADS; i++)
		{
			if(padinfo.status[i])
			{
				// Get Pad Data
				ioPadGetData(i, &paddata);

				// Parse Pad Data
				if(Pad_onPress(paddata, paddata_old[i], BTN_SELECT))
				{
					// dev_blind stuff
					sysFSStat stat;
					s32 ret = sysFsStat("/dev_blind", &stat);

					if(ret == 0)
					{
						// dev_blind exists - ask to unmount
						MSG.Dialog(MSG_YESNO, "Do you want to unmount dev_blind?");

						if(MSG.GetResponse(MSG_DIALOG_BTN_YES) == 1)
						{
							// syscall unmount
							lv2syscall1(838, (u64)"/dev_blind");

							// display success
							MSG.Dialog(MSG_OK, "dev_blind was successfully unmounted.");
						}
					}
					else
					{
						// dev_blind does not exist - ask to mount
						MSG.Dialog(MSG_YESNO, "Do you want to mount dev_blind?");

						if(MSG.GetResponse(MSG_DIALOG_BTN_YES) == 1)
						{
							// syscall mount
							lv2syscall8(837, (u64)"CELL_FS_IOS:BUILTIN_FLSH1", (u64)"CELL_FS_FAT", (u64)"/dev_blind", 0, 0 /* readonly */, 0, 0, 0);

							// display success with info
							MSG.Dialog(MSG_OK, "dev_blind was successfully mounted. Please note that dev_blind will not automatically unmount upon exiting OpenPS3FTP.");
						}
					}
				}

				if(Pad_onPress(paddata, paddata_old[i], BTN_START))
				{
					// Exit application
					GFX->AppExit();
				}

				paddata_old[i] = paddata;
			}
		}

		// Draw bitmap->screenbuffer
		BM.DrawBitmap(&PCL);
		GFX->Flip();
	}

	BM.ClearBitmap(&PCL);

	// Wait for server thread to complete
	u64 retval;
	sysThreadJoin(id, &retval);

	// Parse thread return value if application is not exiting
	if(GFX->ExitSignalStatus() == NO_SIGNAL && retval != 0)
	{
		// Error - see ftp.cpp
		MSG.ErrorDialog((u32)retval);
		exit(EXIT_FAILURE);
	}

	return 0;
}