#include "var.h" int main () { //Cor verde system("color a"); //strings do nome do computador string patri = ""; string buffer = ""; //dados do arquivo de configuracao do wifi string file_wifi_adm_data = ""; file_wifi_adm_data = ""+SSID_WIFI_ADM+"49464D532D50502D4D4151"+SSID_WIFI_ADM+"trueESSautoWPA2PSKAESfalsepassPhrasefalse"+PASSWORD_WIFI_ADM+"false3251268096"; string file_wifi_acad_data = ""; file_wifi_acad_data = ""+SSID_WIFI_ACAD+"49464D532D50502D4D4151"+SSID_WIFI_ACAD+"trueESSautoWPA2PSKAESfalsepassPhrasefalse"+PASSWORD_WIFI_ACAD+"false879094211"; //variavel que armazena o diretorio temp const string path_temp = getenv("TEMP"); //caminho do arquivo de configuracao do wifi adm string path_wifi_adm = path_temp; path_wifi_adm += "\\IFMS-PP-MAQ.xml"; //caminho do arquivo de configuracao do wifi acad string path_wifi_acad = path_temp; path_wifi_acad += "\\IFMS-PP-ACADEMICO.xml"; //caminho do script string path_ps1 = path_temp; path_ps1 += "\\joinDomain.ps1"; int opt, cont; int connect = 0; int ping = 0; //ativando e alterando a senha dos usuarios locais printf("Ativando o usuario ADMINISTRADOR!\n"); string str_user_adm_local_active = ""; str_user_adm_local_active = "cmd /c net user "+USER_ADM_LOCAL+" /active:yes"; system(str_user_adm_local_active.c_str()); printf("Alterando a senha do usuario ADMINISTRADOR!\n"); string str_pw_adm_local_set = ""; str_pw_adm_local_set = "cmd /c net user "+USER_ADM_LOCAL+" "+PASSWORD_ADM_LOCAL; system(str_pw_adm_local_set.c_str()); printf("Alterando a senha do usuario SERTI!\n"); string str_pw_serti_local_set = ""; str_pw_serti_local_set = "cmd /c net user "+USER_SERTI_LOCAL+" "+PASSWORD_SERTI_LOCAL; system(str_pw_serti_local_set.c_str()); printf("\nDeseja ingressar o PC em qual Dominio?\n1-ADMINISTRATIVO\n2-ACADEMICO\n0-NENHUM\nOpcao: "); scanf("%d", &opt); if(opt == 1){ printf("Adicionando a rede WI-FI %s\n", SSID_WIFI_ADM.c_str()); //cria o arquivo perfil xml ofstream outfile (path_wifi_adm.c_str()); outfile << file_wifi_adm_data << endl; outfile.close(); //conecta na rede wifi string str_wifi_adm = ""; str_wifi_adm = "cmd /c netsh wlan add profile filename="+path_wifi_adm+" user=all"; system(str_wifi_adm.c_str()); //tenta conectar e testa a conexao com o ping cont = 0; string str_connect = ""; string str_ping = ""; do{ str_connect = "cmd /c netsh wlan connect "+SSID_WIFI_ADM; connect = system(str_connect.c_str()); str_ping = "cmd /c ping -n 1 "+PING_ADM; ping = system(str_ping.c_str()); printf("\nTentativa %d de 5", cont+1); Sleep(3000); if(cont == 4){ printf("\nNAO FOI POSSIVEL SE CONECTAR!\n"); system("pause"); return 0; } cont++; }while(connect != 0 && ping != 0); //exclui o arquivo xml remove(path_wifi_adm.c_str()); printf("\nConectado com sucesso! Abra o navegador e acesse cp.pp.ifms.edu.br para autenticar!"); printf("\nAdicione ao domínio MANUALMENTE!"); //solicita ao usuario o numero de patrimonio /*printf("\nAdicione o Numero do Patrimonio (Sem os 0s A ESQUERDA) ou Nome do Computador: "); do{ cin >> buffer; //verifica o tamanho do numero de patrimonio para completar if(buffer.length() > 8){ printf("\nNo Maximo 8 digitos!!!\n"); }else{ patri = "PP-"; for(int i=0; i < 8-buffer.length(); i++){ patri += "0"; } } }while(buffer.length() > 8); patri += buffer; //ativa script powershell system("powershell Set-ExecutionPolicy RemoteSigned"); //cria o script powershell adm string str_ps_adm = ""; str_ps_adm = "$usr = '"+USER_AD_ADM+"@"+DOMAIN_AD_ADM+"'\n$pw = '"+PASSWORD_AD_ADM+"' | ConvertTo-SecureString -asPlainText -Force\n$creds = New-Object System.Management.Automation.PSCredential($usr,$pw)\nif ( $hostname -eq '"+patri+"' ){\nAdd-Computer -DomainName "+DOMAIN_AD_ADM+" -Credential $creds -Force -Options JoinWithNewName,AccountCreate -OUPath 'OU=PP-Administrativo,OU=PP-Computadores,OU=PP-Outros,OU=IFMS-Outros,DC=ifms,DC=edu,DC=br'\n}else {\nRename-Computer -NewName '"+patri+"'\nSleep 5\nAdd-Computer -DomainName "+DOMAIN_AD_ADM+" -Credential $creds -Force -Options JoinWithNewName,AccountCreate -OUPath 'OU=PP-Administrativo,OU=PP-Computadores,OU=PP-Outros,OU=IFMS-Outros,DC=ifms,DC=edu,DC=br'}"; //cria arquivo powershell ofstream outfile1 (path_ps1.c_str()); outfile1 << str_ps_adm << endl; outfile1.close(); //executa powershell // string execPs = "powershell " + path_ps1; // system(execPs.c_str()); //deleta arquivo powershell // remove(path_ps1.c_str()); */ }else if(opt == 2){ printf("Adicionando a rede WI-FI %s\n", SSID_WIFI_ACAD.c_str()); //cria o arquivo perfil xml ofstream outfile (path_wifi_acad.c_str()); outfile << file_wifi_acad_data << endl; outfile.close(); //conecta na rede wifi string str_wifi_acad = ""; str_wifi_acad = "cmd /c netsh wlan add profile filename="+path_wifi_acad+" user=all"; system(str_wifi_acad.c_str()); //tenta conectar e testa a conexao com o ping cont = 0; string str_connect = ""; string str_ping = ""; do{ str_connect = "cmd /c netsh wlan connect "+SSID_WIFI_ACAD; connect = system(str_connect.c_str()); str_ping = "cmd /c ping -n 1 "+PING_ACAD; ping = system(str_ping.c_str()); printf("\nTentativa %d de 5", cont+1); Sleep(3000); if(cont == 4){ printf("\nNAO FOI POSSIVEL SE CONECTAR!\n"); system("pause"); return 0; } cont++; }while(connect != 0 && ping != 0); printf("\nConectado com sucesso! Abra o navegador e acesse pa.pp.ifms.edu.br para autenticar!"); //exclui o arquivo xml remove(path_wifi_acad.c_str()); //solicita ao usuario o numero de patrimonio printf("\nAdicione o Numero do Patrimonio ou Numero de Serie (SEM OS 0s A ESQUERDA e COM NO MAXIMO 8 DIGITOS): "); do{ cin >> buffer; //verifica o tamanho do numero de patrimonio para completar if(buffer.length() > 8){ printf("\nNo Maximo 8 digitos!!!\n"); }else{ patri = "PP-"; for(int i=0; i < 8-buffer.length(); i++){ patri += "0"; } } }while(buffer.length() > 8); patri += buffer; cout << "\nNovo nome do computador: " << patri << endl; //ativa script powershell system("powershell Set-ExecutionPolicy RemoteSigned"); //cria o script powershell acad string str_ps_acad = ""; str_ps_acad = "$computerName = '" + patri+ "'\n$hostname = hostname \n$domain = '"+DOMAIN_AD_ACAD+"' \n$username = \"$domain"+ "\\" +USER_AD_ACAD+"\"\n$password = '"+PASSWORD_AD_ACAD+"' \n$securePassword = ConvertTo-SecureString $password -AsPlainText -Force\n$credential = New-Object System.Management.Automation.PSCredential($username, $securePassword)\n$ldapConn = New-Object DirectoryServices.DirectoryEntry (\"LDAP://$domain\", $username, $password)\n$searcher = New-Object DirectoryServices.DirectorySearcher\n$searcher.SearchRoot = $ldapConn\n$searcher.Filter = \"(&(objectCategory=computer)(cn=$computerName))\"\n$result = $searcher.FindOne()\nif ($result) {\n$computerObject = $result.GetDirectoryEntry()\ntry {\n$computerObject.DeleteTree()\n$computerObject.CommitChanges()\n Write-Host 'Computador '$computerName' deletado com sucesso.'\n} catch {\nWrite-Host 'Erro ao deletar o computador: $_'\n}\n}\nelse{\nWrite-Host 'Computador '$computerName' não encontrado.'\n}\nif ( $hostname -eq '"+patri+"' ){\nAdd-Computer -DomainName $domain -Credential $credential -Force\n}else {\nRename-Computer -NewName '"+patri+"'\nSleep 5\nAdd-Computer -DomainName $domain -Credential $credential -Force}"; //str_ps_acad = "$hostname = hostname \n$domain = '"+DOMAIN_AD_ACAD+"' \n$username = '$domain"+ "\\" +USER_AD_ACAD+"'\n$password = '"+PASSWORD_AD_ACAD+"' \n$securePassword = ConvertTo-SecureString $password -AsPlainText -Force\n$credential = New-Object System.Management.Automation.PSCredential($username, $securePassword)\nif ( $hostname -eq '"+patri+"' ){\nAdd-Computer -DomainName $domain -Credential $credential -Force -OUPath 'OU=Computadores,OU=IFMS-PP,DC=acad,DC=pp,DC=ifms,DC=edu,DC=br'\n}else {\nRename-Computer -NewName '"+patri+"'\nSleep 5\nAdd-Computer -DomainName $domain -Credential $credential -Force -Options JoinWithNewName,AccountCreate -OUPath 'OU=Computadores,OU=IFMS-PP,DC=acad,DC=pp,DC=ifms,DC=edu,DC=br'}"; //str_ps_acad = "Rename-Computer -NewName "+ patri +"\n$domain = '"+DOMAIN_AD_ACAD+"'\n$username = '$domain"+ "\\" +USER_AD_ACAD+"'\n$password = '"+PASSWORD_AD_ACAD+"'\n$securePassword = ConvertTo-SecureString $password -AsPlainText -Force\n$credential = New-Object System.Management.Automation.PSCredential($username, $securePassword)\nAdd-Computer -DomainName $domain -Credential $credential -Force -Restart"; //cria arquivo powershell ofstream outfile1 (path_ps1.c_str()); outfile1 << str_ps_acad << endl; outfile1.close(); //executa powershell string execPs = "powershell " + path_ps1; system(execPs.c_str()); //deleta arquivo powershell remove(path_ps1.c_str()); //reiniciar pc system("c:\\WINDOWS\\System32\\shutdown /r /t 0"); } system("pause"); return 0; }