Beispiel #1
0
bool hasRights(const string& who, int i, bool msg)
{
    user* u = yace->users().getUser(who);
    if (u == NULL) {
        return false;
    }
    if (u->igetProp("rights") < i) {
        if(msg) {
            ostringstream os;
            os << "R_" << i << "_R";
            string status = yace->sql().getText(os.str());

            if(status == "")
                sendUser(who, yace->sql().getString("no_rights_alt"));
            else
                sendUser(who, replace(yace->sql().getString("no_rights"), "%STATUS%", status));

            u->DecRef();
            return false;
        }
    }
    else {
        u->DecRef();
        return true;
    }
    return false;
}
Beispiel #2
0
void MainWindow::on_pushButton_clicked()
{
	QSqlQuery q;
	q.exec("SELECT user.id, usertype.typeuser FROM user, usertype\
			WHERE usertype.id = user.type_user AND user.id = '"\
			+ ui->user->currentData().toString() + "' AND user.pass = '******'");

	q.next();
	int userID = q.value("id").toInt();
	QString typeUser = q.value(1).toString();
	qDebug()<<userID<<" "<<typeUser;
	qDebug()<<q.lastError();

	/*db.close();
	db = QSqlDatabase::addDatabase("QMYSQL");
	db.setHostName("127.0.0.1");
	db.setPort(3306);
	db.setDatabaseName("gkhdb");*/

	this->hide();	
	if(typeUser == "администратор")
	{
		/*db.setUserName("root");
		db.setPassword("qwer");
		db.open();*/
		Admin* a = new Admin;
		a->showMaximized();
		connect(this,SIGNAL(sendUser(int)),a,SLOT(recieveUserID(int)));
		emit sendUser(userID);
		a->exec();
		a->deleteLater();
	}
/**
 * Отправка команды FTP-серверу.
 * 
 * @param command FTP-команда.
 * 
 * @return Флаг успешности выполнения (0 - не успешно, другое - успешно).
 */
int ProtocolInterpreter::sendCommand(string command) {
    int success;
    
    if (command == "USER") {
        success = sendUser();
    } else if (command == "PASS") {
        success = sendPass();
    } else if (command == "TYPE") {
        success = sendType();
    } else if (command == "MODE") {
        success = sendMode();
    } else if (command == "STRU") {
        success = sendStru();
    } else if (command == "PORT") {
        success = sendPort();
    } else if (command == "PASV") {
        success = sendPasv();
    } else if (command == "NLST") {
        success = sendNlst();
    } else if (command == "LIST") {
        success = sendList();
    } else if (command == "RETR") {
        success = sendRetr();
    } else if (command == "STOR") {
        success = sendStor();
    } else if (command == "RNTO") {
        success = sendRnto();
    } else if (command == "RNFR") {
        success = sendRnfr();
    } else if (command == "DELE") {
        success = sendDele();
    } else if (command == "MKD") {
        success = sendMkd();
    } else if (command == "RMD") {
        success = sendRmd();
    } else if (command == "CWD") {
        success = sendCwd();
    } else if (command == "CDUP") {
        success = sendCdup();
    } else if (command == "PWD") {
        success = sendPwd();
    } else if (command == "ABOR") {
        success = sendAbor();
    } else if (command == "REIN") {
        success = sendRein();
    } else if (command == "QUIT") {
        success = sendQuit();
    } else if (command == "SYST") {
        success = sendSyst();
    } else if (command == "STAT") {
        success = sendStat();
    } else if (command == "NOOP") {
        success = sendNoop();
    } else {
        service->printMessage(1, "Unknown command!");
    }
    
    return success;
}
Beispiel #4
0
createUsers::createUsers(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::createUsers)
{
    ui->setupUi(this);
    connect(ui->exitButton, SIGNAL(clicked()), this, SLOT(hide()));
    connect(ui->okButton, SIGNAL(clicked()), this, SLOT(sendUser()));
}
Beispiel #5
0
bool sameRoom(const string& caller, const string& target)
{
    if(roomof(caller) == roomof(target))
        return true;

    sendUser(caller, replaceUser(target, yace->sql().getString("not_sameroom")));

    return false;
}
Beispiel #6
0
bool canJoin(const string& room, const string& who)
{
    if(!locked(room))
        return true;
    if(isInvited(room, who))
        return true;

    sendUser(who, replace(yace->sql().getString("locked"),"%TEXT%",room));
    return false;
}
Beispiel #7
0
bool exists(const string& who, const string& errorto)
{
    if(yace->users().existsUser(who))
        return true;

    if(errorto != "")
        sendUser(errorto, yace->sql().getString("no_target"));

    return false;
}
Beispiel #8
0
bool POP3Client::login() {
    if (state_ == Transaction)
        return true;
    if (!sendUser(email_))
        return false;
    if (!sendPasswd(password_))
        return false;
    state_ = Transaction;
    return true;
}
Beispiel #9
0
/*
sendJson["sendUser"] = Json::Value(CStringUtil::getStdString(user.m_userName));
sendJson["group"] = json["name"];
sendJson["msg"] = json["msg"];
*/
bool CUserService::getMsgFromGroup(const Json::Value& json)
{
	CString sendUser(json["sendUser"].asCString());
	CString group(json["group"].asCString());
	CString msg(json["msg"].asCString());

	CMFCUtil::getActiveDoc()->updateGroupHtml(group, sendUser, msg);
	CMFCUtil::getActiveView()->flushChat();

	return true;
}
Beispiel #10
0
void sendRoomI(const string& user, const string& what, bool raw)
{
    ::user* u = yace->users().getUser(user);
    if(u == NULL)
        return;

    room* r = yace->rooms().getRoom(u->getRoom());
    if(r == NULL) {
        u->DecRef();
        return;
    }

    string modsend = yace->sql().getString("modsend");

    set<string> members = r->getAllUsers();

    if(!u->igetProp("gag")) {

        bool cantalk = (u->igetProp("rights")) >= (r->igetProp("modtalk"));

        for(set<string>::iterator it = members.begin(); it != members.end(); ++it) {
            ::user* act = yace->users().getUser(*it);
            if(!ignores(*it, user)) {
                if(cantalk) {
                    sendUser(*it, what, raw);
                }
                else if(((act->igetProp("rights")) >= (r->igetProp("modhear"))) || (act == u)) {
                    sendUser(*it, replace(modsend, "%TEXT%", what), raw);
                }
            }
            act->DecRef();
        }
    }

    u->DecRef();
    r->DecRef();
}
void main(){

  int sockfd;
  struct sockaddr_in destination;

  sockfd = createsocket();
  create(&destination,DEST_PORT,IP);

  conn(sockfd,&destination); 

  struct reply r; // struct hold replies from server
	

  printf("Please enter your email id: ");
  scanf("%s",u.username);

  printf("Please enter your password: "******"%s",u.password);
   
  start(sockfd,AUTH); //notify auth
  sendUser(sockfd,u); //send user credentials to server
  r = recieveReply(sockfd);

  if(r.status == SUCCESS){
	//auth success
    printf("\n Authenticated Successfully. \n");
    menu(sockfd);

  }else{
	//auth error
    printf("\n Invalid Username or Password. \n");
    
  }

  close(sockfd);

}
void *run(void *arg){
	pthread_detach(pthread_self());
	vector<string>tok;
	Account currentUser;
	int n;
	char  mesg[MAXLINE], sendline[MAXLINE], recvline[MAXLINE];
	ClientSock clientSock=*(ClientSock*)arg;
	int connfd=clientSock.connfd;
	struct sockaddr_in cliaddr=clientSock.addr;
	free(arg);

	while((n=receive(connfd, recvline)) >0) {

		recvline[n]=0; /* null terminate */
		printf("from client IP %s port %d\n", getIP(cliaddr), getPort(cliaddr));
		printf("connfd = %d\n", connfd);
		tok.clear();
		tok=parse(recvline);
		

		if(userAccount.find(User(getIP(cliaddr), getPort(cliaddr), cliaddr))==userAccount.end()){
			if(tok[0][0]=='R'){
				writeRecv(connfd, recvline, strlen(recvline));// send to client
				//register
				currentUser=Account(tok[1], tok[2]);
				currentUser.state=Normal;
				userAccount[User(getIP(cliaddr), getPort(cliaddr), cliaddr, connfd)]=currentUser;
				accountUser[currentUser]=User(getIP(cliaddr), getPort(cliaddr), cliaddr, connfd);
				
				if(insertUser(currentUser)){
					puts("register sucess");
					write(connfd, SUCCESS, strlen(SUCCESS));

					// update filelist
					recvFilelist(connfd, currentUser.ID);


				}
				else{
					puts("register fail");

					write(connfd, FAIL, strlen(FAIL));
				}
			}
			else if(tok[0][0]=='L'){
				writeRecv(connfd, recvline, strlen(recvline));// send to client
				if(login(Account(tok[1], tok[2]))){
					currentUser=Account(tok[1], tok[2]);
					currentUser.state=Normal;
					userAccount[User(getIP(cliaddr), getPort(cliaddr), cliaddr, connfd)]=currentUser;
					accountUser[currentUser]=User(getIP(cliaddr), getPort(cliaddr), cliaddr, connfd);
					puts("login sucess");
					write(connfd, SUCCESS, strlen(SUCCESS));	
					// update filelist
					recvFilelist(connfd, currentUser.ID);

				}
				else{
					puts("login fail");
					write(connfd, FAIL, strlen(FAIL));
				}
			}
		}
		else{ // login already
			currentUser=userAccount[User(getIP(cliaddr), getPort(cliaddr), cliaddr)];
			accountUser[currentUser]=User(getIP(cliaddr), getPort(cliaddr), cliaddr);
			if(currentUser.state==Normal){
				if(tok[0]=="Del"){// delete account
					writeRecv(connfd, recvline, strlen(recvline));// send to client
					puts("Delete account");
					deleteUser(currentUser);// delete in db
					userAccount.erase(User(getIP(cliaddr), getPort(cliaddr), cliaddr));
					accountUser.erase(currentUser);
					
					write(connfd, SUCCESS, strlen(SUCCESS));
				}
				else if(tok[0]=="L"){// logout
					writeRecv(connfd, recvline, strlen(recvline));// send to client
					puts("Logout");
					userAccount.erase(User(getIP(cliaddr), getPort(cliaddr), cliaddr));
					accountUser.erase(currentUser);
					deleteFile(currentUser.ID);
					write(connfd, SUCCESS, strlen(SUCCESS));
				}
			
				//------------------------------------------------
				// show filelist/ show user
				else if(tok[0]=="SU"){// show user
					writeRecv(connfd, recvline, strlen(recvline));// send to client
					writeRecv(connfd, SUCCESS, strlen(SUCCESS));
					sendUser(connfd);
				}
				else if(tok[0]=="SF"){// show filelist
					writeRecv(connfd, recvline, strlen(recvline));// send to client
					writeRecv(connfd, SUCCESS, strlen(SUCCESS));
					showFilelist();
					sendResult(connfd, 2, result);
				}
				//------------------------------------------------
				// upload download
				else if(tok[0]=="D"){// download
					writeRecv(connfd, recvline, strlen(recvline));// send to client
					int numFile=existNumFile(tok[1]);
					printf("number of file = %d\n", numFile);
					
					// total authors
					if(numFile){
						vector<string>author=getFileAuthor();
						writeRecv(connfd, SUCCESS, strlen(SUCCESS));
						string str=toString((int)author.size());
						// how many author
						write(connfd, str.c_str(), str.length());
						// to user A
						recvWrite(connfd, recvline);// tell B connect to "port"
						// to user A
						User userA=accountUser[currentUser];
						for(int i=0;i<author.size();i++){
							cout<<author[i]<<endl;

							
							User userB=accountUser[Account(author[i])];
							
							// user B
							str=string(DOWNLOAD)+" "+userA.IP+" "+recvline+" "+tok[1]+" "+toString(i)+" "+toString((int)author.size());
							write(userB.connfd, str.c_str(), str.length());// tell B :(A's) IP port path idx total

						}

						// update filelist
						puts("update filelist");
						addFile(currentUser.ID, tok[1]);
					}
					else{
						write(connfd, FAIL, strlen(FAIL));
					}
					


				}
				else if(tok[0]=="U"){// upload
					writeRecv(connfd, recvline, strlen(recvline));// send to client
					if(accountUser.find(Account(tok[1]))!=accountUser.end()){
						// to user A
						write(connfd, SUCCESS, strlen(SUCCESS));
						User userA=accountUser[currentUser];
						User userB=accountUser[Account(tok[1])];
						string str;
						// to user A
						recvWrite(connfd, recvline);// tell B connect to "port"
						// user B
						str=string(UPLOAD)+" "+userA.IP+" "+recvline+" "+tok[2];
						write(userB.connfd, str.c_str(), str.length());// tell B :(A's) IP port

						// update B's filelist
						addFile(tok[1], tok[2]);
					}
					else{
						write(connfd, FAIL, strlen(FAIL));
					}
					
				}
				//------------------------------------------------
				else if(tok[0]=="T"){// A tell B
					writeRecv(connfd, recvline, strlen(recvline));// send to client
					if(accountUser.find(Account(tok[1]))!=accountUser.end()){
						currentUser.state=Tell;
						userAccount[User(getIP(cliaddr), getPort(cliaddr), cliaddr, connfd)]=currentUser;
						// to user A
						write(connfd, SUCCESS, strlen(SUCCESS));
						User userA=accountUser[currentUser];
						User userB=accountUser[Account(tok[1])];
						Account accountB=userAccount[userB];
						accountB.state=Tell;
						userAccount[userB]=accountB;
						
						string str;
						// to user A
						recvWrite(connfd, recvline);// tell B connect to "port"
						// user B
						printf("user B connfd = %d\n", userB.connfd);
						str=string(TALK)+" "+userA.IP+" "+recvline;
						// write(userB.connfd, TALK, strlen(TALK));
						
						
						write(userB.connfd, str.c_str(), str.length());// tell B :(A's) IP port

						// string str=userB.IP+" "+toString(userB.port);
						// writeWithSleep(connfd, str.c_str(), str.length());

					}
					else{
						write(connfd, FAIL, strlen(FAIL));
					}
					
				}
			
			}
			else if(currentUser.state==Tell){
				if(tok[0]=="EXIT"){
					printf("%s EXIT~\n", currentUser.ID.c_str());
					currentUser.state=Normal;
					userAccount[User(getIP(cliaddr), getPort(cliaddr), cliaddr, connfd)]=currentUser;
				}
				else{
					printf("%s tell~\n", currentUser.ID.c_str());
				}
			}		
		}
		puts(recvline);
		
		
		// write(connfd, recvline, strlen(recvline));
	}
	close(connfd);

	return NULL;
}
Beispiel #13
0
void sendUserI(const string& who, const string& whom, const string& what, bool raw)
{
    if(!ignores(whom, who))
        sendUser(whom, what, raw);
}