Skip to content

Instantly share code, notes, and snippets.

@csanz
Created December 15, 2010 06:53
Show Gist options
  • Select an option

  • Save csanz/741708 to your computer and use it in GitHub Desktop.

Select an option

Save csanz/741708 to your computer and use it in GitHub Desktop.
I wrote this a long time ago during my time at Disney Online... Nothing secret about, just a proxy changer I wrote for the devs.
/*************************************
load libraries
*************************************/
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <fstream>
using namespace std;
/*************************************
initialize functions
*************************************/
int getRandom();
/*************************************/*****************************
load libraries
*****************************/
#include <iostream>
#include <string>
#include <algorithm>
#include <fstream>
#include <cmath>
#include <conio.h>
//#include<iostream.h>
#include<windows.h>
using namespace std;
/*****************************
decalre functions
*****************************/
void displayCurrencies(string []);
int convertCurrency(double, int);
int main()
{
/*****************************
constructor
*****************************/
//declare arrays
string cur[16] = {"ITL", //italian
"MXN", //mexican pesos
"EUR", //european
"FRF", //france
"BRL", //brazilian
"CLP", //chilean
"JPY", //japan
"DZD", //algeria dinars
"BGL", //bulgaria leva
"IEP", //ireland pounds
"VEB", //venezuelan escudos
"RUR", //russia rubles
"ESP", //spain
"VEB", //venezuela bolivares
"SAR", //Saudi Arabia Riyals
"ZAR"}; //South Africa Rand
double conv[16] = {0.9888,
0.0977326,
0.9888,
0.150741,
0.257732,
0.00133156,
0.00809138,
0.0130526,
0.503018,
1.25468,
0.00493214,
0.0317859,
0.00594307,
0.000675676,
0.266658,
0.0956437};
/*****************************
declare variables
*****************************/
string searchFor = ""; //currency to locate
int amount = 0; //amount entered by user
double i = 0.0;
/*****************************
create data file
*****************************/
//initialize the file object
ofstream outFile;
//create file in c drive
outFile.open("c:/currencies.dat");
outFile << "*************" << endl; //write header
outFile << "** RESULTS **" << endl; //write header
outFile << "*************" << endl; //write header
outFile << endl;
/*****************************
output
*****************************/
//display table of currencies
displayCurrencies(cur);
//get currency and convert to uppercase
cout << "Enter currency (X to exit program and display results): ";
cin >> searchFor;
transform(searchFor.begin(), searchFor.end(),
searchFor.begin(), toupper);
if(searchFor != "X"){
cout << " >> Convert " << searchFor << " to USD" << endl;
cout << endl;
cout << "Enter amount: ";
cin >> amount;
}
/*****************************
start loop
*****************************/
while (searchFor != "X")
{
//---------------------------------
// Step (1)
//---------------------------------
//locate position of currency inside array
int y = 0; //counter
while (y < 16 && cur[y] != searchFor)
y = y + 1; //end while
//if currency was found, display conversion
//otherwise, display error message
//---------------------------------
// Step (2)
//---------------------------------
if (y < 16){
i = conv[y]*amount;
cout << endl;
cout << "***** RESULTS ******" << endl;
cout << "Convertion: $" << i << endl;
cout << "1 " << searchFor << "= " << conv[y] << " USD"<< endl;
cout << "********************" << endl;
cout << endl;
outFile << amount << " ";
outFile << searchFor << " = $" << i << " USD" << endl; //enter data to file
}else{
cout << endl;
cout << "***** Currency " << searchFor <<" is not valid, please enter again!! *****" << endl;
cout << endl;
}
//end if
//---------------------------------
// Step (3) - start over
//---------------------------------
//get currency and convert to uppercase
cout << "Enter currency (X to exit program and display results): ";
cin >> searchFor;
transform(searchFor.begin(), searchFor.end(),
searchFor.begin(), toupper);
if(searchFor != "X"){
cout << " >> Convert " << searchFor << " to USD" << endl;
cout << endl;
cout << "Enter amount: ";
cin >> amount;
}
} //end while
/*****************************
close file and open notepad
*****************************/
outFile.close();
system("c:\\WINDOWS\\system32\\notepad.exe c:\\currencies.dat");
//end function
return 0;
}
void displayCurrencies(string cur3[]){
cout << "**********************************" << endl; //write to screen
cout << "** Universal Currency Converter **" << endl; //write to scree/*
* ProxyManager.Exe
*
* Copyright (c) 2003 Walt Disney Internet Group. All Rights Reserved.
*
* Original author: Christian Sanz
*
* Ref: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wininet/wininet/internet_per_conn_option_list.asp
*/
/*********************************************************************************
* INCLUDE LIBS
*********************************************************************************/
#include "stdafx.h"
#include <windows.h>
#include <wininet.h>
#include <iostream>
#include <fstream.h>
#include <stdlib.h>
#include <cstdlib>
#define countof( array ) ( sizeof( array )/sizeof( array[0] ) )/*
* ProxyManager.Exe
*
* Copyright (c) 2003 Walt Disney Internet Group. All Rights Reserved.
*
* Original author: Christian Sanz
*
* Ref: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wininet/wininet/internet_per_conn_option_list.asp
*/
/*********************************************************************************
* INCLUDE LIBS
*********************************************************************************/
#include "stdafx.h"
#include <windows.h>
#include <wininet.h>
#include <iostream>
#include <fstream.h>
#include <stdlib.h>
#include <cstdlib>
#define countof( array ) ( sizeof( array )/sizeof( array[0] ) )
//using namespace std;
BOOL SetConnectionOptions(LPCTSTR conn_name,LPCTSTR proxy_full_addr);
void GetList(char* options[],int count);
void DisplayMessageWrapper(LPCTSTR s);
/*********************************************************************************
* MAIN
*********************************************************************************/
int main(int argc, char* argv[])
{
char* options[] = {"ts-proxy.online.disney.com:7080",
"ts-proxy.online.disney.com:9080",
"web-proxy.disney.com:8080",
"ts-proxy.online.disney.com:7081",
"ts-proxy.online.disney.com:9081",
"dnhdisprxy01.online.disney.com:7080",
"qnhdisprxy01.online.disney.com:9080",
"PROXYPAC_MODE",
"DIRECT"};
int valueIn;
int intValueIn;
const char* connection_name="DefaultConnectionSettings";
BOOL GOAGAIN=true;
//if arguments are pass by pass the while loop
if(argc != 2)
{
std::cout << "==================================\n";
std::cout << " C++ Proxy Manager \n";
std::cout << "==================================\n\n";
GetList(options, countof(options));
//repeat standard output for user entry
while(GOAGAIN)
{
std::cout << "\n\nEnter option:";
std::cin >> valueIn;
intValueIn = (int)valueIn;
LPSTR proxy = (LPSTR)options[valueIn];
if((NULL == proxy) || (intValueIn>(countof(options)-1))){
std::cout << "Invalid... Please try again\n";
}else{
if(proxy=="PROXYPAC_MODE")
{
DisplayMessageWrapper("Turning PROXY PAC ON");
}
else if(proxy=="DIRECT")
{
DisplayMessageWrapper("Turning all proxies off GO DIRECT");
}
else
{
DisplayMessageWrapper(proxy);
}
SetConnectionOptions(connection_name,proxy); //commit changes
GetList(options, countof(options)); //display list
}
}
}
else
{
//std::cout << argv[1];
//int intValueIn2 = (int)argv[1];
////LPSTR proxy = (LPSTR)options[intValueIn];
// std::cout << intValueIn2;
////SetConnectionOptions(connection_name,proxy);
}
return 0;
}
void GetList(char* o[], int c)
{
for(int i =0;i<=c-1;i++)
std::cout << "[" << i << "] - " << o[i] << "\n";
}
void DisplayMessageWrapper(LPCTSTR s)
{
std::cout << "-----------------------------------------------------\n";
std::cout << ">>" << " Setting proxy to: " << s <<"\n";
std::cout << "-----------------------------------------------------\n";
}
/*********************************************************************************
*** SET CONNECTION OPTION
*********************************************************************************/
//#pragma comment(lib,"wininet")
//http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wininet/wininet/internet_per_conn_option_list.asp
BOOL SetConnectionOptions(LPCTSTR conn_name,LPCTSTR proxy_full_addr)
{
int numOfOptions = 2;
if(proxy_full_addr=="PROXYPAC_MODE" || proxy_full_addr=="DIRECT")
numOfOptions = 1;
//winnet structure
INTERNET_PER_CONN_OPTION_LIST list;
BOOL bReturn;
DWORD dwBufSize = sizeof(list);
// Fill out list struct.
list.dwSize = sizeof(list);
// NULL == LAN, otherwise connectoid name.
list.pszConnection = (LPTSTR)conn_name;
// Set three options.
list.dwOptionCount = numOfOptions;
list.pOptions = new INTERNET_PER_CONN_OPTION[numOfOptions];
// Make sure the memory was allocated.
if(NULL == list.pOptions)
{
// Return FALSE if the memory wasn't allocated.
OutputDebugString("failed to allocat memory in SetConnectionOptions()");
return FALSE;
}
// Set flags.
list.pOptions[0].dwOption = INTERNET_PER_CONN_FLAGS;
if(proxy_full_addr=="PROXYPAC_MODE"){
list.pOptions[0].Value.dwValue = PROXY_TYPE_AUTO_PROXY_URL;
}
else if(proxy_full_addr=="DIRECT")
{
list.pOptions[0].Value.dwValue = PROXY_TYPE_DIRECT;
}
else
{
list.pOptions[0].Value.dwValue = PROXY_TYPE_DIRECT | PROXY_TYPE_PROXY;
// Set proxy name.
list.pOptions[1].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
list.pOptions[1].Value.pszValue = (LPTSTR)proxy_full_addr;
}
// Set proxy override.
//list.pOptions[2].dwOption = INTERNET_PER_CONN_PROXY_BYPASS;
// list.pOptions[2].Value.pszValue = list.pOptions[2].Value.pszValue;
//INTERNET_PROXY_INFO pinfo;
//pinfo.dwAccessType = INTERNET_OPEN_TYPE_DIRECT;
// Set the options on the connection.
bReturn = InternetSetOption(NULL,
INTERNET_OPTION_PER_CONNECTION_OPTION, &list, dwBufSize);
// Free the allocated memory.
delete [] list.pOptions;
InternetSetOption(NULL, INTERNET_OPTION_SETTINGS_CHANGED, NULL, 0);
InternetSetOption(NULL, INTERNET_OPTION_REFRESH , NULL, 0);
//DeleteUrlCacheEntry("go.com");
return bReturn;
}
/*********************************************************************************
*** DISABLE CONNECTION
*********************************************************************************/
BOOL DisableConnectionProxy(LPCTSTR conn_name)
{
//conn_name: active connection name.
INTERNET_PER_CONN_OPTION_LIST list;
BOOL bReturn;
DWORD dwBufSize = sizeof(list);
// Fill out list struct.
list.dwSize = sizeof(list);
// NULL == LAN, otherwise connectoid name.
list.pszConnection = (LPTSTR)conn_name;
// Set three options.
list.dwOptionCount = 1;
list.pOptions = new INTERNET_PER_CONN_OPTION[list.dwOptionCount];
// Make sure the memory was allocated.
if(NULL == list.pOptions)
{
// Return FALSE if the memory wasn't allocated.
OutputDebugString("failed to allocat memory in DisableConnectionProxy()");
return FALSE;
}
// Set flags.
list.pOptions[0].dwOption = INTERNET_PER_CONN_FLAGS;
list.pOptions[0].Value.dwValue = PROXY_TYPE_DIRECT ;
// Set the options on the connection.
bReturn = InternetSetOption(NULL,
INTERNET_OPTION_PER_CONNECTION_OPTION, &list, dwBufSize);
// Free the allocated memory.
delete [] list.pOptions;
InternetSetOption(NULL, INTERNET_OPTION_SETTINGS_CHANGED, NULL, 0);
InternetSetOption(NULL, INTERNET_OPTION_REFRESH , NULL, 0);
return bReturn;
}
//using namespace std;
BOOL SetConnectionOptions(LPCTSTR conn_name,LPCTSTR proxy_full_addr);
void GetList(char* options[],int count);
void DisplayMessageWrapper(LPCTSTR s);
/*********************************************************************************
* MAIN
*********************************************************************************/
int main(int argc, char* argv[])
{
char* options[] = {"ts-proxy.online.disney.com:7080",
"ts-proxy.online.disney.com:9080",
"web-proxy.disney.com:8080",
"ts-proxy.online.disney.com:7081",
"ts-proxy.online.disney.com:9081",
"dnhdisprxy01.online.disney.com:7080",
"qnhdisprxy01.online.disney.com:9080",
"PROXYPAC_MODE",
"DIRECT"};
int valueIn;
int intValueIn;
const char* connection_name="DefaultConnectionSettings";
BOOL GOAGAIN=true;
//if arguments are pass by pass the while loop
if(argc != 2)
{
std::cout << "==================================\n";
std::cout << " C++ Proxy Manager \n";
std::cout << "==================================\n\n";
GetList(options, countof(options));
//repeat standard output for user entry
while(GOAGAIN)
{
std::cout << "\n\nEnter option:";
std::cin >> valueIn;
intValueIn = (int)valueIn;
LPSTR proxy = (LPSTR)options[valueIn];
if((NULL == proxy) || (intValueIn>(countof(options)-1))){
std::cout << "Invalid... Please try again\n";
}else{
if(proxy=="PROXYPAC_MODE")
{
DisplayMessageWrapper("Turning PROXY PAC ON");
}
else if(proxy=="DIRECT")
{
DisplayMessageWrapper("Turning all proxies off GO DIRECT");
}
else
{
DisplayMessageWrapper(proxy);
}
SetConnectionOptions(connection_name,proxy); //commit changes
GetList(options, countof(options)); //display list
}
}
}
else
{
//std::cout << argv[1];
//int intValueIn2 = (int)argv[1];
////LPSTR proxy = (LPSTR)options[intValueIn];
// std::cout << intValueIn2;
////SetConnectionOptions(connection_name,proxy);
}
return 0;
}
void GetList(char* o[], int c)
{
for(int i =0;i<=c-1;i++)
std::cout << "[" << i << "] - " << o[i] << "\n";
}
void DisplayMessageWrapper(LPCTSTR s)
{
std::cout << "-----------------------------------------------------\n";
std::cout << ">>" << " Setting proxy to: " << s <<"\n";
std::cout << "-----------------------------------------------------\n";
}
/*********************************************************************************
*** SET CONNECTION OPTION
*********************************************************************************/
//#pragma comment(lib,"wininet")
//http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wininet/wininet/internet_per_conn_option_list.asp
BOOL SetConnectionOptions(LPCTSTR conn_name,LPCTSTR proxy_full_addr)
{
int numOfOptions = 2;
if(proxy_full_addr=="PROXYPAC_MODE" || proxy_full_addr=="DIRECT")
numOfOptions = 1;
//winnet structure
INTERNET_PER_CONN_OPTION_LIST list;
BOOL bReturn;
DWORD dwBufSize = sizeof(list);
// Fill out list struct.
list.dwSize = sizeof(list);
// NULL == LAN, otherwise connectoid name.
list.pszConnection = (LPTSTR)conn_name;
// Set three options.
list.dwOptionCount = numOfOptions;
list.pOptions = new INTERNET_PER_CONN_OPTION[numOfOptions];
// Make sure the memory was allocated.
if(NULL == list.pOptions)
{
// Return FALSE if the memory wasn't allocated.
OutputDebugString("failed to allocat memory in SetConnectionOptions()");
return FALSE;
}
// Set flags.
list.pOptions[0].dwOption = INTERNET_PER_CONN_FLAGS;
if(proxy_full_addr=="PROXYPAC_MODE"){
list.pOptions[0].Value.dwValue = PROXY_TYPE_AUTO_PROXY_URL;
}
else if(proxy_full_addr=="DIRECT")
{
list.pOptions[0].Value.dwValue = PROXY_TYPE_DIRECT;
}
else
{
list.pOptions[0].Value.dwValue = PROXY_TYPE_DIRECT | PROXY_TYPE_PROXY;
// Set proxy name.
list.pOptions[1].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
list.pOptions[1].Value.pszValue = (LPTSTR)proxy_full_addr;
}
// Set proxy override.
//list.pOptions[2].dwOption = INTERNET_PER_CONN_PROXY_BYPASS;
// list.pOptions[2].Value.pszValue = list.pOptions[2].Value.pszValue;
//INTERNET_PROXY_INFO pinfo;
//pinfo.dwAccessType = INTERNET_OPEN_TYPE_DIRECT;
// Set the options on the connection.
bReturn = InternetSetOption(NULL,
INTERNET_OPTION_PER_CONNECTION_OPTION, &list, dwBufSize);
// Free the allocated memory.
delete [] list.pOptions;
InternetSetOption(NULL, INTERNET_OPTION_SETTINGS_CHANGED, NULL, 0);
InternetSetOption(NULL, INTERNET_OPTION_REFRESH , NULL, 0);
//DeleteUrlCacheEntry("go.com");
return bReturn;
}
/*********************************************************************************
*** DISABLE CONNECTION
*********************************************************************************/
BOOL DisableConnectionProxy(LPCTSTR conn_name)
{
//conn_name: active connection name.
INTERNET_PER_CONN_OPTION_LIST list;
BOOL bReturn;
DWORD dwBufSize = sizeof(list);
// Fill out list struct.
list.dwSize = sizeof(list);
// NULL == LAN, otherwise connectoid name.
list.pszConnection = (LPTSTR)conn_name;
// Set three options.
list.dwOptionCount = 1;
list.pOptions = new INTERNET_PER_CONN_OPTION[list.dwOptionCount];
// Make sure the memory was allocated.
if(NULL == list.pOptions)
{
// Return FALSE if the memory wasn't allocated.
OutputDebugString("failed to allocat memory in DisableConnectionProxy()");
return FALSE;
}
// Set flags.
list.pOptions[0].dwOption = INTERNET_PER_CONN_FLAGS;
list.pOptions[0].Value.dwValue = PROXY_TYPE_DIRECT ;
// Set the options on the connection.
bReturn = InternetSetOption(NULL,
INTERNET_OPTION_PER_CONNECTION_OPTION, &list, dwBufSize);
// Free the allocated memory.
delete [] list.pOptions;
InternetSetOption(NULL, INTERNET_OPTION_SETTINGS_CHANGED, NULL, 0);
InternetSetOption(NULL, INTERNET_OPTION_REFRESH , NULL, 0);
return bReturn;
}
n
cout << "**********************************" << endl; //write to screen
cout << endl;
int row = 0; //row counter
int col = 0; //column counter
while(row < 16){
cout << " (" << cur3[row] << ") ";
if(col==3){
cout << endl;
col = 0;
}else{
col = col++;
}
row = row++;
}
cout << endl;
}
int convertCurrency(double currency, int amount){
currency = currency * amount;
return currency;
}
start executing
*************************************/
int main()
{
/*************************************
declare variables
*************************************/
srand(time(NULL)); //this prevents duplicate numbers on each row
int debug = 1;
int row = 0;
int col = 0;
int rnd = 0;
int y[50][6]; //declare two dimensional array
/*************************************
open/create data file
*************************************/
ofstream outFile;
outFile.open("lottery_numbers.dat");
/*************************************
feed array with random values
*************************************/
while(row <= 50){
col = 0;
while(col <= 5){
rnd = getRandom();
y[row][col] = rnd;//1 + rand() % (54 - 1 +1); //call randomizer function
col = col++;
}
row = row+1;
}
/*************************************
output
*************************************/
cout << "*****************************" << endl;
cout << "**** Lottery Numbers ****" << endl;
cout << "*****************************" << endl;
row = 0; //reset rows
col = 0;
while (row < 50)
{
col = 0; //reset column
while (col <= 5)
{
rnd = y[row][col];
cout << rnd;
if(col!=5){
cout << "-";
outFile << rnd << "-"; //store data into file
}else{
outFile << rnd << endl; //store data into file
}
col = col + 1; //update column
}
cout << endl;
row = row + 1; //update row
} //end while
outFile.close();
return 0;
} //end of main function
int getRandom()
{
int value=0;
value = 1 + rand() % (54 - 1 +1);
return value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment